]>
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; |
34d6798f | 142 | int idx_vrf = 0, idx_inst = 0; |
b5a8894d CS |
143 | const char *vrf_name = NULL; |
144 | ||
34d6798f CS |
145 | *instance = 0; |
146 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) | |
147 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); | |
148 | ||
b5a8894d | 149 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
b5a8894d | 150 | vrf_name = argv[idx_vrf + 1]->arg; |
43b8d1d8 | 151 | if (enable) { |
43b8d1d8 CS |
152 | /* Allocate VRF aware instance */ |
153 | ospf = ospf_get(*instance, vrf_name); | |
154 | } else { | |
43b8d1d8 CS |
155 | ospf = ospf_lookup_by_inst_name(*instance, vrf_name); |
156 | } | |
b5a8894d | 157 | } else { |
43b8d1d8 | 158 | if (enable) { |
34d6798f | 159 | ospf = ospf_get(*instance, NULL); |
43b8d1d8 | 160 | } else { |
43b8d1d8 | 161 | ospf = ospf_lookup_instance(*instance); |
b5a8894d | 162 | } |
d62a17ae | 163 | } |
34d6798f | 164 | |
43b8d1d8 CS |
165 | return ospf; |
166 | } | |
167 | ||
52d0c099 | 168 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
b1c3ae8c | 169 | json_object *json, u_char use_vrf) |
52d0c099 | 170 | { |
b1c3ae8c CS |
171 | if (use_vrf) { |
172 | if (json) { | |
173 | if (ospf->vrf_id == VRF_DEFAULT) | |
174 | json_object_string_add(json, "vrfName", | |
175 | "default"); | |
176 | else | |
177 | json_object_string_add(json, "vrfName", | |
178 | ospf->name); | |
179 | json_object_int_add(json, "vrfId", ospf->vrf_id); | |
180 | } else { | |
181 | if (ospf->vrf_id == VRF_DEFAULT) | |
182 | vty_out(vty, "VRF Name: %s\n", "default"); | |
183 | else if (ospf->name) | |
184 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
185 | } | |
52d0c099 | 186 | } |
52d0c099 CS |
187 | } |
188 | ||
43b8d1d8 CS |
189 | #ifndef VTYSH_EXTRACT_PL |
190 | #include "ospf_vty_clippy.c" | |
191 | #endif | |
192 | ||
193 | DEFUN_NOSH (router_ospf, | |
194 | router_ospf_cmd, | |
195 | "router ospf [{(1-65535)|vrf NAME}]", | |
196 | "Enable a routing process\n" | |
197 | "Start OSPF configuration\n" | |
198 | "Instance ID\n" | |
199 | VRF_CMD_HELP_STR) | |
200 | { | |
201 | struct ospf *ospf = NULL; | |
202 | int ret = CMD_SUCCESS; | |
203 | u_short instance = 0; | |
204 | ||
205 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance); | |
206 | if (!ospf) | |
207 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 208 | |
d62a17ae | 209 | /* The following logic to set the vty qobj index is in place to be able |
210 | to ignore the commands which dont belong to this instance. */ | |
64ac44f6 | 211 | if (ospf->instance != instance) { |
d62a17ae | 212 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
64ac44f6 CS |
213 | ret = CMD_NOT_MY_INSTANCE; |
214 | } else { | |
b5a8894d CS |
215 | if (ospf->vrf_id != VRF_UNKNOWN) |
216 | ospf->oi_running = 1; | |
d62a17ae | 217 | if (IS_DEBUG_OSPF_EVENT) |
b5a8894d CS |
218 | zlog_debug("Config command 'router ospf %d' received, vrf %s id %d oi_running %u", |
219 | instance, ospf->name ? ospf->name : "NIL", | |
220 | ospf->vrf_id, ospf->oi_running); | |
d62a17ae | 221 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); |
222 | ospf_router_id_update(ospf); | |
223 | } | |
224 | ||
64ac44f6 | 225 | return ret; |
718e3744 | 226 | } |
227 | ||
228 | DEFUN (no_router_ospf, | |
229 | no_router_ospf_cmd, | |
43b8d1d8 | 230 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 231 | NO_STR |
232 | "Enable a routing process\n" | |
7a7be519 | 233 | "Start OSPF configuration\n" |
b5a8894d CS |
234 | "Instance ID\n" |
235 | VRF_CMD_HELP_STR) | |
718e3744 | 236 | { |
d62a17ae | 237 | struct ospf *ospf; |
238 | u_short instance = 0; | |
b5a8894d | 239 | |
43b8d1d8 CS |
240 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); |
241 | if (ospf == NULL) { | |
242 | if (instance) | |
b5a8894d | 243 | return CMD_NOT_MY_INSTANCE; |
43b8d1d8 CS |
244 | else |
245 | return CMD_WARNING; | |
b5a8894d | 246 | } |
d62a17ae | 247 | ospf_finish(ospf); |
718e3744 | 248 | |
d62a17ae | 249 | return CMD_SUCCESS; |
718e3744 | 250 | } |
251 | ||
7c8ff89e | 252 | |
43b8d1d8 | 253 | DEFPY (ospf_router_id, |
718e3744 | 254 | ospf_router_id_cmd, |
255 | "ospf router-id A.B.C.D", | |
256 | "OSPF specific commands\n" | |
257 | "router-id for the OSPF process\n" | |
258 | "OSPF router-id in IP address format\n") | |
259 | { | |
a3d826f0 | 260 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 261 | |
d62a17ae | 262 | struct listnode *node; |
263 | struct ospf_area *area; | |
d62a17ae | 264 | |
265 | ospf->router_id_static = router_id; | |
266 | ||
267 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
268 | if (area->full_nbrs) { | |
269 | vty_out(vty, | |
270 | "For this router-id change to take effect," | |
271 | " save config and restart ospfd\n"); | |
272 | return CMD_SUCCESS; | |
273 | } | |
274 | ||
275 | ospf_router_id_update(ospf); | |
276 | ||
277 | return CMD_SUCCESS; | |
718e3744 | 278 | } |
279 | ||
7a7be519 | 280 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
281 | ospf_router_id_old_cmd, |
282 | "router-id A.B.C.D", | |
283 | "router-id for the OSPF process\n" | |
284 | "OSPF router-id in IP address format\n") | |
7a7be519 | 285 | { |
a3d826f0 | 286 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 287 | int idx_ipv4 = 1; |
288 | struct listnode *node; | |
289 | struct ospf_area *area; | |
290 | struct in_addr router_id; | |
291 | int ret; | |
292 | ||
293 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
294 | if (!ret) { | |
295 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
296 | return CMD_WARNING_CONFIG_FAILED; | |
297 | } | |
7a7be519 | 298 | |
d62a17ae | 299 | ospf->router_id_static = router_id; |
300 | ||
301 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
302 | if (area->full_nbrs) { | |
303 | vty_out(vty, | |
304 | "For this router-id change to take effect," | |
305 | " save config and restart ospfd\n"); | |
306 | return CMD_SUCCESS; | |
307 | } | |
308 | ||
309 | ospf_router_id_update(ospf); | |
310 | ||
311 | return CMD_SUCCESS; | |
7a7be519 | 312 | } |
747e489c | 313 | |
43b8d1d8 | 314 | DEFPY (no_ospf_router_id, |
718e3744 | 315 | no_ospf_router_id_cmd, |
7a7be519 | 316 | "no ospf router-id [A.B.C.D]", |
718e3744 | 317 | NO_STR |
318 | "OSPF specific commands\n" | |
7a7be519 | 319 | "router-id for the OSPF process\n" |
320 | "OSPF router-id in IP address format\n") | |
718e3744 | 321 | { |
a3d826f0 | 322 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 323 | struct listnode *node; |
324 | struct ospf_area *area; | |
68980084 | 325 | |
43b8d1d8 CS |
326 | if (router_id_str) { |
327 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
328 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
329 | return CMD_WARNING_CONFIG_FAILED; | |
330 | } | |
331 | } | |
332 | ||
d62a17ae | 333 | ospf->router_id_static.s_addr = 0; |
718e3744 | 334 | |
d62a17ae | 335 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
336 | if (area->full_nbrs) { | |
337 | vty_out(vty, | |
338 | "For this router-id change to take effect," | |
339 | " save config and restart ospfd\n"); | |
340 | return CMD_SUCCESS; | |
341 | } | |
2c19a6ec | 342 | |
d62a17ae | 343 | ospf_router_id_update(ospf); |
718e3744 | 344 | |
d62a17ae | 345 | return CMD_SUCCESS; |
718e3744 | 346 | } |
347 | ||
718e3744 | 348 | |
d62a17ae | 349 | static void ospf_passive_interface_default(struct ospf *ospf, u_char newval) |
350 | { | |
f4e14fdb | 351 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 352 | struct listnode *ln; |
353 | struct interface *ifp; | |
354 | struct ospf_interface *oi; | |
355 | ||
356 | ospf->passive_interface_default = newval; | |
357 | ||
451fda4f | 358 | FOR_ALL_INTERFACES (vrf, ifp) { |
9d303b37 DL |
359 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
360 | passive_interface)) | |
d62a17ae | 361 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); |
362 | } | |
363 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
364 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
365 | UNSET_IF_PARAM(oi->params, passive_interface); | |
366 | /* update multicast memberships */ | |
367 | ospf_if_set_multicast(oi); | |
368 | } | |
369 | } | |
370 | ||
371 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
372 | struct interface *ifp, | |
373 | struct ospf_if_params *params, | |
374 | u_char value, | |
375 | struct in_addr addr) | |
376 | { | |
377 | u_char dflt; | |
378 | ||
379 | params->passive_interface = value; | |
380 | if (params != IF_DEF_PARAMS(ifp)) { | |
381 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
382 | passive_interface)) | |
383 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
384 | else | |
385 | dflt = ospf->passive_interface_default; | |
386 | ||
387 | if (value != dflt) | |
388 | SET_IF_PARAM(params, passive_interface); | |
389 | else | |
390 | UNSET_IF_PARAM(params, passive_interface); | |
391 | ||
392 | ospf_free_if_params(ifp, addr); | |
393 | ospf_if_update_params(ifp, addr); | |
394 | } | |
395 | } | |
396 | ||
397 | static void ospf_passive_interface_update(struct ospf *ospf, | |
398 | struct interface *ifp, | |
399 | struct ospf_if_params *params, | |
400 | u_char value) | |
401 | { | |
402 | params->passive_interface = value; | |
403 | if (params == IF_DEF_PARAMS(ifp)) { | |
404 | if (value != ospf->passive_interface_default) | |
405 | SET_IF_PARAM(params, passive_interface); | |
406 | else | |
407 | UNSET_IF_PARAM(params, passive_interface); | |
408 | } | |
7ffa8fa2 PJ |
409 | } |
410 | ||
a2c62831 | 411 | DEFUN (ospf_passive_interface, |
412 | ospf_passive_interface_addr_cmd, | |
7a7be519 | 413 | "passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 414 | "Suppress routing updates on an interface\n" |
7a7be519 | 415 | "Interface's name\n" |
3a2d747c | 416 | "IPv4 address\n" |
7a7be519 | 417 | "Suppress routing updates on interfaces by default\n") |
718e3744 | 418 | { |
a3d826f0 | 419 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 420 | int idx_ipv4 = 2; |
421 | struct interface *ifp; | |
422 | struct in_addr addr = {.s_addr = INADDR_ANY}; | |
423 | int ret; | |
424 | struct ospf_if_params *params; | |
425 | struct route_node *rn; | |
426 | ||
427 | if (strmatch(argv[1]->text, "default")) { | |
428 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
429 | return CMD_SUCCESS; | |
430 | } | |
431 | ||
bcc24579 | 432 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, 0); |
b5a8894d CS |
433 | if (ifp == NULL) { |
434 | vty_out(vty, "interface %s not found.\n", | |
435 | (char *)argv[1]->arg); | |
436 | return CMD_WARNING; | |
437 | } | |
d62a17ae | 438 | |
439 | params = IF_DEF_PARAMS(ifp); | |
440 | ||
441 | if (argc == 3) { | |
442 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
443 | if (!ret) { | |
444 | vty_out(vty, | |
445 | "Please specify interface address by A.B.C.D\n"); | |
446 | return CMD_WARNING_CONFIG_FAILED; | |
447 | } | |
448 | ||
449 | params = ospf_get_if_params(ifp, addr); | |
450 | ospf_if_update_params(ifp, addr); | |
451 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
452 | OSPF_IF_PASSIVE, addr); | |
453 | } | |
454 | ||
455 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
456 | ||
457 | /* XXX We should call ospf_if_set_multicast on exactly those | |
458 | * interfaces for which the passive property changed. It is too much | |
459 | * work to determine this set, so we do this for every interface. | |
460 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
461 | * record of joined groups to avoid systems calls if the desired | |
462 | * memberships match the current memership. | |
463 | */ | |
464 | ||
465 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
466 | struct ospf_interface *oi = rn->info; | |
467 | ||
9d303b37 DL |
468 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) |
469 | == OSPF_IF_PASSIVE)) | |
d62a17ae | 470 | ospf_if_set_multicast(oi); |
471 | } | |
472 | /* | |
473 | * XXX It is not clear what state transitions the interface needs to | |
474 | * undergo when going from active to passive. Fixing this will | |
475 | * require precise identification of interfaces having such a | |
476 | * transition. | |
477 | */ | |
478 | ||
479 | return CMD_SUCCESS; | |
718e3744 | 480 | } |
481 | ||
a2c62831 | 482 | DEFUN (no_ospf_passive_interface, |
483 | no_ospf_passive_interface_addr_cmd, | |
7a7be519 | 484 | "no passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 485 | NO_STR |
486 | "Allow routing updates on an interface\n" | |
7a7be519 | 487 | "Interface's name\n" |
3a2d747c | 488 | "IPv4 address\n" |
7a7be519 | 489 | "Allow routing updates on interfaces by default\n") |
718e3744 | 490 | { |
a3d826f0 | 491 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 492 | int idx_ipv4 = 3; |
493 | struct interface *ifp; | |
494 | struct in_addr addr = {.s_addr = INADDR_ANY}; | |
495 | struct ospf_if_params *params; | |
496 | int ret; | |
497 | struct route_node *rn; | |
498 | ||
499 | if (strmatch(argv[2]->text, "default")) { | |
500 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
501 | return CMD_SUCCESS; | |
43540886 AS |
502 | } |
503 | ||
bcc24579 | 504 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, 0); |
b5a8894d CS |
505 | if (ifp == NULL) { |
506 | vty_out(vty, "interface %s not found.\n", | |
507 | (char *)argv[1]->arg); | |
508 | return CMD_WARNING; | |
509 | } | |
ba6454ec | 510 | |
d62a17ae | 511 | params = IF_DEF_PARAMS(ifp); |
512 | ||
513 | if (argc == 4) { | |
514 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
515 | if (!ret) { | |
516 | vty_out(vty, | |
517 | "Please specify interface address by A.B.C.D\n"); | |
518 | return CMD_WARNING_CONFIG_FAILED; | |
519 | } | |
520 | ||
521 | params = ospf_lookup_if_params(ifp, addr); | |
522 | if (params == NULL) | |
523 | return CMD_SUCCESS; | |
524 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
525 | OSPF_IF_ACTIVE, addr); | |
526 | } | |
527 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
528 | ||
529 | /* XXX We should call ospf_if_set_multicast on exactly those | |
530 | * interfaces for which the passive property changed. It is too much | |
531 | * work to determine this set, so we do this for every interface. | |
532 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
533 | * record of joined groups to avoid systems calls if the desired | |
534 | * memberships match the current memership. | |
535 | */ | |
536 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
537 | struct ospf_interface *oi = rn->info; | |
538 | ||
539 | if (oi | |
540 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
541 | ospf_if_set_multicast(oi); | |
542 | } | |
543 | ||
544 | return CMD_SUCCESS; | |
718e3744 | 545 | } |
546 | ||
718e3744 | 547 | |
a2c62831 | 548 | DEFUN (ospf_network_area, |
549 | ospf_network_area_cmd, | |
6147e2c6 | 550 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 551 | "Enable routing on an IP network\n" |
552 | "OSPF network prefix\n" | |
553 | "Set the OSPF area ID\n" | |
554 | "OSPF area ID in IP address format\n" | |
555 | "OSPF area ID as a decimal value\n") | |
556 | { | |
a3d826f0 | 557 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 558 | int idx_ipv4_prefixlen = 1; |
559 | int idx_ipv4_number = 3; | |
560 | struct prefix_ipv4 p; | |
561 | struct in_addr area_id; | |
562 | int ret, format; | |
563 | ||
564 | if (ospf->instance) { | |
565 | vty_out(vty, | |
566 | "The network command is not supported in multi-instance ospf\n"); | |
567 | return CMD_WARNING_CONFIG_FAILED; | |
568 | } | |
718e3744 | 569 | |
d62a17ae | 570 | if (ospf->if_ospf_cli_count > 0) { |
571 | vty_out(vty, | |
572 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
573 | return CMD_WARNING_CONFIG_FAILED; | |
574 | } | |
575 | ||
576 | /* Get network prefix and Area ID. */ | |
577 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
578 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
579 | ||
580 | ret = ospf_network_set(ospf, &p, area_id, format); | |
581 | if (ret == 0) { | |
582 | vty_out(vty, "There is already same network statement.\n"); | |
851fcbae | 583 | return CMD_WARNING; |
d62a17ae | 584 | } |
585 | ||
586 | return CMD_SUCCESS; | |
718e3744 | 587 | } |
588 | ||
a2c62831 | 589 | DEFUN (no_ospf_network_area, |
590 | no_ospf_network_area_cmd, | |
6147e2c6 | 591 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 592 | NO_STR |
593 | "Enable routing on an IP network\n" | |
594 | "OSPF network prefix\n" | |
595 | "Set the OSPF area ID\n" | |
596 | "OSPF area ID in IP address format\n" | |
597 | "OSPF area ID as a decimal value\n") | |
598 | { | |
a3d826f0 | 599 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 600 | int idx_ipv4_prefixlen = 2; |
601 | int idx_ipv4_number = 4; | |
602 | struct prefix_ipv4 p; | |
603 | struct in_addr area_id; | |
604 | int ret, format; | |
605 | ||
606 | if (ospf->instance) { | |
607 | vty_out(vty, | |
608 | "The network command is not supported in multi-instance ospf\n"); | |
609 | return CMD_WARNING_CONFIG_FAILED; | |
610 | } | |
718e3744 | 611 | |
d62a17ae | 612 | /* Get network prefix and Area ID. */ |
613 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
614 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
615 | ||
616 | ret = ospf_network_unset(ospf, &p, area_id); | |
617 | if (ret == 0) { | |
618 | vty_out(vty, | |
619 | "Can't find specified network area configuration.\n"); | |
620 | return CMD_WARNING_CONFIG_FAILED; | |
621 | } | |
622 | ||
623 | return CMD_SUCCESS; | |
718e3744 | 624 | } |
625 | ||
a2c62831 | 626 | DEFUN (ospf_area_range, |
627 | ospf_area_range_cmd, | |
7a7be519 | 628 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 629 | "OSPF area parameters\n" |
630 | "OSPF area ID in IP address format\n" | |
631 | "OSPF area ID as a decimal value\n" | |
632 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 633 | "Area range prefix\n" |
634 | "Advertise this range (default)\n" | |
635 | "User specified metric for this range\n" | |
636 | "Advertised metric for this range\n") | |
718e3744 | 637 | { |
a3d826f0 | 638 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 639 | int idx_ipv4_number = 1; |
640 | int idx_ipv4_prefixlen = 3; | |
641 | int idx_cost = 6; | |
642 | struct prefix_ipv4 p; | |
643 | struct in_addr area_id; | |
644 | int format; | |
645 | u_int32_t cost; | |
646 | ||
647 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
648 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
649 | ||
650 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
651 | if (argc > 5) { | |
652 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
653 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
654 | } | |
718e3744 | 655 | |
d62a17ae | 656 | return CMD_SUCCESS; |
718e3744 | 657 | } |
658 | ||
7a7be519 | 659 | DEFUN (ospf_area_range_cost, |
660 | ospf_area_range_cost_cmd, | |
661 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
662 | "OSPF area parameters\n" | |
663 | "OSPF area ID in IP address format\n" | |
664 | "OSPF area ID as a decimal value\n" | |
665 | "Summarize routes matching address/mask (border routers only)\n" | |
666 | "Area range prefix\n" | |
667 | "User specified metric for this range\n" | |
668 | "Advertised metric for this range\n") | |
669 | { | |
a3d826f0 | 670 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 671 | int idx_ipv4_number = 1; |
672 | int idx_ipv4_prefixlen = 3; | |
673 | int idx_cost = 5; | |
674 | struct prefix_ipv4 p; | |
675 | struct in_addr area_id; | |
676 | int format; | |
677 | u_int32_t cost; | |
7a7be519 | 678 | |
d62a17ae | 679 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
680 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 681 | |
d62a17ae | 682 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
683 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
684 | format); | |
718e3744 | 685 | |
d62a17ae | 686 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
687 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 688 | |
d62a17ae | 689 | return CMD_SUCCESS; |
7a7be519 | 690 | } |
718e3744 | 691 | |
a2c62831 | 692 | DEFUN (ospf_area_range_not_advertise, |
693 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 694 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 695 | "OSPF area parameters\n" |
696 | "OSPF area ID in IP address format\n" | |
697 | "OSPF area ID as a decimal value\n" | |
698 | "Summarize routes matching address/mask (border routers only)\n" | |
699 | "Area range prefix\n" | |
700 | "DoNotAdvertise this range\n") | |
701 | { | |
a3d826f0 | 702 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 703 | int idx_ipv4_number = 1; |
704 | int idx_ipv4_prefixlen = 3; | |
705 | struct prefix_ipv4 p; | |
706 | struct in_addr area_id; | |
707 | int format; | |
718e3744 | 708 | |
d62a17ae | 709 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
710 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 711 | |
d62a17ae | 712 | ospf_area_range_set(ospf, area_id, &p, 0); |
713 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
714 | format); | |
718e3744 | 715 | |
d62a17ae | 716 | return CMD_SUCCESS; |
718e3744 | 717 | } |
718 | ||
a2c62831 | 719 | DEFUN (no_ospf_area_range, |
720 | no_ospf_area_range_cmd, | |
3a2d747c | 721 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 722 | NO_STR |
723 | "OSPF area parameters\n" | |
724 | "OSPF area ID in IP address format\n" | |
725 | "OSPF area ID as a decimal value\n" | |
726 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 727 | "Area range prefix\n" |
3a2d747c QY |
728 | "User specified metric for this range\n" |
729 | "Advertised metric for this range\n" | |
7a7be519 | 730 | "Advertise this range (default)\n" |
3a2d747c QY |
731 | "User specified metric for this range\n" |
732 | "Advertised metric for this range\n" | |
7a7be519 | 733 | "DoNotAdvertise this range\n") |
718e3744 | 734 | { |
a3d826f0 | 735 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 736 | int idx_ipv4_number = 2; |
737 | int idx_ipv4_prefixlen = 4; | |
738 | struct prefix_ipv4 p; | |
739 | struct in_addr area_id; | |
740 | int format; | |
718e3744 | 741 | |
d62a17ae | 742 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
743 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 744 | |
d62a17ae | 745 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 746 | |
d62a17ae | 747 | return CMD_SUCCESS; |
718e3744 | 748 | } |
749 | ||
a2c62831 | 750 | DEFUN (ospf_area_range_substitute, |
751 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 752 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 753 | "OSPF area parameters\n" |
754 | "OSPF area ID in IP address format\n" | |
755 | "OSPF area ID as a decimal value\n" | |
756 | "Summarize routes matching address/mask (border routers only)\n" | |
757 | "Area range prefix\n" | |
758 | "Announce area range as another prefix\n" | |
759 | "Network prefix to be announced instead of range\n") | |
760 | { | |
a3d826f0 | 761 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 762 | int idx_ipv4_number = 1; |
763 | int idx_ipv4_prefixlen = 3; | |
764 | int idx_ipv4_prefixlen_2 = 5; | |
765 | struct prefix_ipv4 p, s; | |
766 | struct in_addr area_id; | |
767 | int format; | |
718e3744 | 768 | |
d62a17ae | 769 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
770 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
771 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 772 | |
d62a17ae | 773 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
774 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
775 | format); | |
718e3744 | 776 | |
d62a17ae | 777 | return CMD_SUCCESS; |
718e3744 | 778 | } |
779 | ||
a2c62831 | 780 | DEFUN (no_ospf_area_range_substitute, |
781 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 782 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 783 | NO_STR |
784 | "OSPF area parameters\n" | |
785 | "OSPF area ID in IP address format\n" | |
786 | "OSPF area ID as a decimal value\n" | |
787 | "Summarize routes matching address/mask (border routers only)\n" | |
788 | "Area range prefix\n" | |
789 | "Announce area range as another prefix\n" | |
790 | "Network prefix to be announced instead of range\n") | |
791 | { | |
a3d826f0 | 792 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 793 | int idx_ipv4_number = 2; |
794 | int idx_ipv4_prefixlen = 4; | |
795 | int idx_ipv4_prefixlen_2 = 6; | |
796 | struct prefix_ipv4 p, s; | |
797 | struct in_addr area_id; | |
798 | int format; | |
718e3744 | 799 | |
d62a17ae | 800 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
801 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
802 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 803 | |
d62a17ae | 804 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 805 | |
d62a17ae | 806 | return CMD_SUCCESS; |
718e3744 | 807 | } |
808 | ||
6b0655a2 | 809 | |
718e3744 | 810 | /* Command Handler Logic in VLink stuff is delicate!! |
811 | ||
812 | ALTER AT YOUR OWN RISK!!!! | |
813 | ||
814 | Various dummy values are used to represent 'NoChange' state for | |
815 | VLink configuration NOT being changed by a VLink command, and | |
816 | special syntax is used within the command strings so that the | |
817 | typed in command verbs can be seen in the configuration command | |
818 | bacckend handler. This is to drastically reduce the verbeage | |
819 | required to coe up with a reasonably compatible Cisco VLink command | |
820 | ||
d62a17ae | 821 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 822 | Wed, 21 Feb 2001 15:13:52 +1300 |
823 | */ | |
824 | ||
d62a17ae | 825 | /* Configuration data for virtual links |
826 | */ | |
718e3744 | 827 | struct ospf_vl_config_data { |
d62a17ae | 828 | struct vty *vty; /* vty stuff */ |
829 | struct in_addr area_id; /* area ID from command line */ | |
830 | int area_id_fmt; /* command line area ID format */ | |
831 | struct in_addr vl_peer; /* command line vl_peer */ | |
832 | int auth_type; /* Authehntication type, if given */ | |
833 | char *auth_key; /* simple password if present */ | |
834 | int crypto_key_id; /* Cryptographic key ID */ | |
835 | char *md5_key; /* MD5 authentication key */ | |
836 | int hello_interval; /* Obvious what these are... */ | |
837 | int retransmit_interval; | |
838 | int transmit_delay; | |
839 | int dead_interval; | |
718e3744 | 840 | }; |
841 | ||
d62a17ae | 842 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
843 | struct vty *vty) | |
718e3744 | 844 | { |
d62a17ae | 845 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
846 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
847 | vl_config->vty = vty; | |
718e3744 | 848 | } |
849 | ||
4dadc291 | 850 | static struct ospf_vl_data * |
d62a17ae | 851 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
852 | { | |
853 | struct ospf_area *area; | |
854 | struct ospf_vl_data *vl_data; | |
855 | struct vty *vty; | |
856 | struct in_addr area_id; | |
857 | ||
858 | vty = vl_config->vty; | |
859 | area_id = vl_config->area_id; | |
860 | ||
861 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
862 | vty_out(vty, | |
863 | "Configuring VLs over the backbone is not allowed\n"); | |
864 | return NULL; | |
865 | } | |
866 | area = ospf_area_get(ospf, area_id); | |
867 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
868 | ||
869 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
870 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
871 | vty_out(vty, "Area %s is %s\n", inet_ntoa(area_id), | |
872 | area->external_routing == OSPF_AREA_NSSA | |
873 | ? "nssa" | |
874 | : "stub"); | |
875 | else | |
876 | vty_out(vty, "Area %ld is %s\n", | |
877 | (u_long)ntohl(area_id.s_addr), | |
878 | area->external_routing == OSPF_AREA_NSSA | |
879 | ? "nssa" | |
880 | : "stub"); | |
881 | return NULL; | |
882 | } | |
883 | ||
884 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
885 | == NULL) { | |
886 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
887 | if (vl_data->vl_oi == NULL) { | |
888 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
889 | ospf_vl_add(ospf, vl_data); | |
890 | ospf_spf_calculate_schedule(ospf, | |
891 | SPF_FLAG_CONFIG_CHANGE); | |
892 | } | |
718e3744 | 893 | } |
d62a17ae | 894 | return vl_data; |
718e3744 | 895 | } |
896 | ||
897 | ||
d62a17ae | 898 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
899 | struct ospf_vl_config_data *vl_config) | |
900 | { | |
901 | struct crypt_key *ck; | |
902 | struct vty *vty; | |
903 | struct interface *ifp = vl_data->vl_oi->ifp; | |
904 | ||
905 | vty = vl_config->vty; | |
906 | ||
907 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
908 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
909 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 910 | } |
718e3744 | 911 | |
d62a17ae | 912 | if (vl_config->auth_key) { |
913 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
914 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
915 | strncpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, | |
916 | vl_config->auth_key, OSPF_AUTH_SIMPLE_SIZE); | |
917 | } else if (vl_config->md5_key) { | |
918 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
919 | vl_config->crypto_key_id) | |
920 | != NULL) { | |
921 | vty_out(vty, "OSPF: Key %d already exists\n", | |
922 | vl_config->crypto_key_id); | |
851fcbae | 923 | return CMD_WARNING; |
d62a17ae | 924 | } |
925 | ck = ospf_crypt_key_new(); | |
926 | ck->key_id = vl_config->crypto_key_id; | |
927 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
928 | strncpy((char *)ck->auth_key, vl_config->md5_key, | |
929 | OSPF_AUTH_MD5_SIZE); | |
930 | ||
931 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
932 | } else if (vl_config->crypto_key_id != 0) { | |
933 | /* Delete a key */ | |
934 | ||
935 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
936 | vl_config->crypto_key_id) | |
937 | == NULL) { | |
938 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
939 | vl_config->crypto_key_id); | |
940 | return CMD_WARNING_CONFIG_FAILED; | |
941 | } | |
942 | ||
943 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
944 | vl_config->crypto_key_id); | |
945 | } | |
946 | ||
947 | return CMD_SUCCESS; | |
718e3744 | 948 | } |
949 | ||
d62a17ae | 950 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
951 | struct ospf_vl_config_data *vl_config) | |
952 | { | |
953 | struct interface *ifp = vl_data->vl_oi->ifp; | |
954 | /* Virtual Link data initialised to defaults, so only set | |
955 | if a value given */ | |
956 | if (vl_config->hello_interval) { | |
957 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
958 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
959 | } | |
960 | ||
961 | if (vl_config->dead_interval) { | |
962 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
963 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
964 | } | |
965 | ||
966 | if (vl_config->retransmit_interval) { | |
967 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
968 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
969 | vl_config->retransmit_interval; | |
970 | } | |
971 | ||
972 | if (vl_config->transmit_delay) { | |
973 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
974 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
975 | } | |
976 | ||
977 | return CMD_SUCCESS; | |
718e3744 | 978 | } |
979 | ||
980 | ||
718e3744 | 981 | /* The business end of all of the above */ |
d62a17ae | 982 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
983 | { | |
984 | struct ospf_vl_data *vl_data; | |
985 | int ret; | |
718e3744 | 986 | |
d62a17ae | 987 | vl_data = ospf_find_vl_data(ospf, vl_config); |
988 | if (!vl_data) | |
989 | return CMD_WARNING_CONFIG_FAILED; | |
990 | ||
991 | /* Process this one first as it can have a fatal result, which can | |
992 | only logically occur if the virtual link exists already | |
993 | Thus a command error does not result in a change to the | |
994 | running configuration such as unexpectedly altered timer | |
995 | values etc.*/ | |
996 | ret = ospf_vl_set_security(vl_data, vl_config); | |
997 | if (ret != CMD_SUCCESS) | |
998 | return ret; | |
999 | ||
1000 | /* Set any time based parameters, these area already range checked */ | |
1001 | ||
1002 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1003 | if (ret != CMD_SUCCESS) | |
1004 | return ret; | |
718e3744 | 1005 | |
d62a17ae | 1006 | return CMD_SUCCESS; |
718e3744 | 1007 | } |
1008 | ||
1009 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1010 | */ | |
d62a17ae | 1011 | #define VLINK_HELPSTR_IPADDR \ |
1012 | "OSPF area parameters\n" \ | |
1013 | "OSPF area ID in IP address format\n" \ | |
1014 | "OSPF area ID as a decimal value\n" \ | |
1015 | "Configure a virtual link\n" \ | |
1016 | "Router ID of the remote ABR\n" | |
1017 | ||
1018 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1019 | "Enable authentication on this virtual link\n" \ | |
1020 | "dummy string \n" | |
1021 | ||
1022 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1023 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1024 | "Use null authentication\n" \ | |
1025 | "Use message-digest authentication\n" | |
1026 | ||
1027 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1028 | "Time between HELLO packets\n" \ | |
1029 | "Seconds\n" \ | |
1030 | "Time between retransmitting lost link state advertisements\n" \ | |
1031 | "Seconds\n" \ | |
1032 | "Link state transmit delay\n" \ | |
1033 | "Seconds\n" \ | |
1034 | "Interval time after which a neighbor is declared down\n" \ | |
1035 | "Seconds\n" | |
1036 | ||
1037 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1038 | "Authentication password (key)\n" \ | |
baf9eaad | 1039 | "The OSPF password (key)\n" |
d62a17ae | 1040 | |
1041 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1042 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1043 | "Key ID\n" \ |
1044 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1045 | "The OSPF password (key)\n" |
718e3744 | 1046 | |
a2c62831 | 1047 | DEFUN (ospf_area_vlink, |
1048 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1049 | "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 | 1050 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1051 | "Enable authentication on this virtual link\n" |
7a7be519 | 1052 | "Use message-digest authentication\n" |
3d1c6dc2 | 1053 | "Use null authentication\n" |
baf9eaad CS |
1054 | VLINK_HELPSTR_AUTH_MD5 |
1055 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1056 | { |
a3d826f0 | 1057 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1058 | int idx_ipv4_number = 1; |
1059 | int idx_ipv4 = 3; | |
1060 | struct ospf_vl_config_data vl_config; | |
1061 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1062 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1063 | int ret; |
55d1da24 | 1064 | int idx = 0; |
d62a17ae | 1065 | |
1066 | ospf_vl_config_data_init(&vl_config, vty); | |
1067 | ||
1068 | /* Read off first 2 parameters and check them */ | |
1069 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1070 | &vl_config.area_id_fmt); | |
1071 | if (ret < 0) { | |
1072 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1073 | return CMD_WARNING_CONFIG_FAILED; | |
1074 | } | |
718e3744 | 1075 | |
d62a17ae | 1076 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1077 | if (!ret) { | |
1078 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1079 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1080 | } |
7a7be519 | 1081 | |
d62a17ae | 1082 | if (argc <= 4) { |
1083 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1084 | |
d62a17ae | 1085 | return ospf_vl_set(ospf, &vl_config); |
1086 | } | |
1087 | ||
3d1c6dc2 CS |
1088 | if (argv_find(argv, argc, "authentication", &idx)) { |
1089 | /* authentication - this option can only occur | |
1090 | at start of command line */ | |
1091 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1092 | } | |
1093 | ||
3d1c6dc2 | 1094 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1095 | /* authentication message-digest */ |
3d1c6dc2 CS |
1096 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1097 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1098 | /* "authentication null" */ | |
1099 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1100 | } |
7a7be519 | 1101 | |
3d1c6dc2 | 1102 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1103 | vl_config.md5_key = NULL; |
cbb9b53d | 1104 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1105 | if (vl_config.crypto_key_id < 0) |
1106 | return CMD_WARNING_CONFIG_FAILED; | |
1107 | ||
3d1c6dc2 | 1108 | memset(md5_key, 0, OSPF_AUTH_MD5_SIZE + 1); |
cbb9b53d | 1109 | strncpy(md5_key, argv[idx + 3]->arg, OSPF_AUTH_MD5_SIZE); |
3d1c6dc2 CS |
1110 | vl_config.md5_key = md5_key; |
1111 | } | |
1112 | ||
3d1c6dc2 | 1113 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
3d1c6dc2 | 1114 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
cbb9b53d | 1115 | strncpy(auth_key, argv[idx + 1]->arg, OSPF_AUTH_SIMPLE_SIZE); |
3d1c6dc2 CS |
1116 | vl_config.auth_key = auth_key; |
1117 | } | |
7a7be519 | 1118 | |
d62a17ae | 1119 | /* Action configuration */ |
1120 | ||
1121 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1122 | } |
1123 | ||
a2c62831 | 1124 | DEFUN (no_ospf_area_vlink, |
1125 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1126 | "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 | 1127 | NO_STR |
7a7be519 | 1128 | VLINK_HELPSTR_IPADDR |
1129 | "Enable authentication on this virtual link\n" \ | |
3d1c6dc2 | 1130 | "Use message-digest authentication\n" \ |
7a7be519 | 1131 | "Use null authentication\n" \ |
baf9eaad CS |
1132 | VLINK_HELPSTR_AUTH_MD5 |
1133 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1134 | { |
a3d826f0 | 1135 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1136 | int idx_ipv4_number = 2; |
1137 | int idx_ipv4 = 4; | |
1138 | struct ospf_area *area; | |
1139 | struct ospf_vl_config_data vl_config; | |
1140 | struct ospf_vl_data *vl_data = NULL; | |
1141 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1142 | int idx = 0; |
d62a17ae | 1143 | int ret, format; |
1144 | ||
1145 | ospf_vl_config_data_init(&vl_config, vty); | |
1146 | ||
1147 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1148 | &format); | |
1149 | if (ret < 0) { | |
1150 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1151 | return CMD_WARNING_CONFIG_FAILED; | |
1152 | } | |
1153 | ||
1154 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1155 | if (!area) { | |
1156 | vty_out(vty, "Area does not exist\n"); | |
1157 | return CMD_WARNING_CONFIG_FAILED; | |
1158 | } | |
1159 | ||
1160 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1161 | if (!ret) { | |
1162 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1163 | return CMD_WARNING_CONFIG_FAILED; | |
1164 | } | |
718e3744 | 1165 | |
d62a17ae | 1166 | if (argc <= 5) { |
1167 | /* Basic VLink no command */ | |
1168 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
1169 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer))) | |
1170 | ospf_vl_delete(ospf, vl_data); | |
1171 | ||
1172 | ospf_area_check_free(ospf, vl_config.area_id); | |
1173 | ||
1174 | return CMD_SUCCESS; | |
1175 | } | |
1176 | ||
1177 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1178 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1179 | |
1180 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1181 | /* authentication - this option can only occur | |
1182 | at start of command line */ | |
1183 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1184 | } | |
1185 | ||
3d1c6dc2 | 1186 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1187 | vl_config.md5_key = NULL; |
cbb9b53d | 1188 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1189 | if (vl_config.crypto_key_id < 0) |
1190 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1191 | } |
1192 | ||
3d1c6dc2 | 1193 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1194 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1195 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1196 | vl_config.auth_key = auth_key; | |
1197 | } | |
d62a17ae | 1198 | |
1199 | /* Action configuration */ | |
1200 | ||
1201 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1202 | } |
1203 | ||
b1c02cec QY |
1204 | DEFUN (ospf_area_vlink_intervals, |
1205 | ospf_area_vlink_intervals_cmd, | |
1206 | "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)}", | |
1207 | VLINK_HELPSTR_IPADDR | |
1208 | VLINK_HELPSTR_TIME_PARAM) | |
1209 | { | |
a3d826f0 | 1210 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1211 | struct ospf_vl_config_data vl_config; |
1212 | int ret = 0; | |
1213 | ||
1214 | ospf_vl_config_data_init(&vl_config, vty); | |
1215 | ||
1216 | char *area_id = argv[1]->arg; | |
1217 | char *router_id = argv[3]->arg; | |
1218 | ||
1219 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1220 | if (ret < 0) { | |
1221 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1222 | return CMD_WARNING_CONFIG_FAILED; | |
1223 | } | |
1224 | ||
1225 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1226 | if (!ret) { | |
1227 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1228 | return CMD_WARNING_CONFIG_FAILED; | |
1229 | } | |
1230 | ||
1231 | for (int idx = 4; idx < argc; idx++) { | |
1232 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1233 | vl_config.hello_interval = | |
1234 | strtol(argv[++idx]->arg, NULL, 10); | |
1235 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1236 | vl_config.retransmit_interval = | |
1237 | strtol(argv[++idx]->arg, NULL, 10); | |
1238 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1239 | vl_config.transmit_delay = | |
1240 | strtol(argv[++idx]->arg, NULL, 10); | |
1241 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1242 | vl_config.dead_interval = | |
1243 | strtol(argv[++idx]->arg, NULL, 10); | |
1244 | } | |
1245 | ||
1246 | /* Action configuration */ | |
1247 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1248 | } |
1249 | ||
7a7be519 | 1250 | DEFUN (no_ospf_area_vlink_intervals, |
1251 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1252 | "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 | 1253 | NO_STR |
7a7be519 | 1254 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1255 | VLINK_HELPSTR_TIME_PARAM) |
1256 | { | |
a3d826f0 | 1257 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1258 | struct ospf_vl_config_data vl_config; |
1259 | int ret = 0; | |
1260 | ||
1261 | ospf_vl_config_data_init(&vl_config, vty); | |
1262 | ||
1263 | char *area_id = argv[2]->arg; | |
1264 | char *router_id = argv[4]->arg; | |
1265 | ||
1266 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1267 | if (ret < 0) { | |
1268 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1269 | return CMD_WARNING_CONFIG_FAILED; | |
1270 | } | |
1271 | ||
1272 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1273 | if (!ret) { | |
1274 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1275 | return CMD_WARNING_CONFIG_FAILED; | |
1276 | } | |
1277 | ||
1278 | for (int idx = 5; idx < argc; idx++) { | |
1279 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1280 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1281 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1282 | vl_config.retransmit_interval = | |
1283 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1284 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1285 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1286 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1287 | vl_config.dead_interval = | |
1288 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1289 | } | |
1290 | ||
1291 | /* Action configuration */ | |
1292 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1293 | } |
1294 | ||
a2c62831 | 1295 | DEFUN (ospf_area_shortcut, |
1296 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1297 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1298 | "OSPF area parameters\n" |
1299 | "OSPF area ID in IP address format\n" | |
1300 | "OSPF area ID as a decimal value\n" | |
1301 | "Configure the area's shortcutting mode\n" | |
1302 | "Set default shortcutting behavior\n" | |
1303 | "Enable shortcutting through the area\n" | |
1304 | "Disable shortcutting through the area\n") | |
1305 | { | |
a3d826f0 | 1306 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1307 | int idx_ipv4_number = 1; |
1308 | int idx_enable_disable = 3; | |
1309 | struct ospf_area *area; | |
1310 | struct in_addr area_id; | |
1311 | int mode; | |
1312 | int format; | |
1313 | ||
1314 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1315 | argv[idx_ipv4_number]->arg); | |
1316 | ||
1317 | area = ospf_area_get(ospf, area_id); | |
1318 | ospf_area_display_format_set(ospf, area, format); | |
1319 | ||
1320 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1321 | mode = OSPF_SHORTCUT_DEFAULT; | |
1322 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1323 | mode = OSPF_SHORTCUT_DISABLE; | |
1324 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1325 | mode = OSPF_SHORTCUT_ENABLE; | |
1326 | else | |
1327 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1328 | |
d62a17ae | 1329 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1330 | |
d62a17ae | 1331 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1332 | vty_out(vty, | |
1333 | "Shortcut area setting will take effect " | |
1334 | "only when the router is configured as Shortcut ABR\n"); | |
718e3744 | 1335 | |
d62a17ae | 1336 | return CMD_SUCCESS; |
718e3744 | 1337 | } |
1338 | ||
a2c62831 | 1339 | DEFUN (no_ospf_area_shortcut, |
1340 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1341 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1342 | NO_STR |
1343 | "OSPF area parameters\n" | |
1344 | "OSPF area ID in IP address format\n" | |
1345 | "OSPF area ID as a decimal value\n" | |
1346 | "Deconfigure the area's shortcutting mode\n" | |
1347 | "Deconfigure enabled shortcutting through the area\n" | |
1348 | "Deconfigure disabled shortcutting through the area\n") | |
1349 | { | |
a3d826f0 | 1350 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1351 | int idx_ipv4_number = 2; |
1352 | struct ospf_area *area; | |
1353 | struct in_addr area_id; | |
1354 | int format; | |
718e3744 | 1355 | |
d62a17ae | 1356 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1357 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1358 | |
d62a17ae | 1359 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1360 | if (!area) | |
1361 | return CMD_SUCCESS; | |
718e3744 | 1362 | |
d62a17ae | 1363 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1364 | |
d62a17ae | 1365 | return CMD_SUCCESS; |
718e3744 | 1366 | } |
1367 | ||
6b0655a2 | 1368 | |
a2c62831 | 1369 | DEFUN (ospf_area_stub, |
1370 | ospf_area_stub_cmd, | |
6147e2c6 | 1371 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1372 | "OSPF area parameters\n" |
1373 | "OSPF area ID in IP address format\n" | |
1374 | "OSPF area ID as a decimal value\n" | |
1375 | "Configure OSPF area as stub\n") | |
1376 | { | |
a3d826f0 | 1377 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1378 | int idx_ipv4_number = 1; |
1379 | struct in_addr area_id; | |
1380 | int ret, format; | |
1381 | ||
1382 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1383 | argv[idx_ipv4_number]->arg); | |
1384 | ||
1385 | ret = ospf_area_stub_set(ospf, area_id); | |
1386 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1387 | format); | |
1388 | if (ret == 0) { | |
1389 | vty_out(vty, | |
1390 | "First deconfigure all virtual link through this area\n"); | |
1391 | return CMD_WARNING_CONFIG_FAILED; | |
1392 | } | |
718e3744 | 1393 | |
d62a17ae | 1394 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1395 | |
d62a17ae | 1396 | return CMD_SUCCESS; |
718e3744 | 1397 | } |
1398 | ||
a2c62831 | 1399 | DEFUN (ospf_area_stub_no_summary, |
1400 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1401 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1402 | "OSPF stub parameters\n" |
1403 | "OSPF area ID in IP address format\n" | |
1404 | "OSPF area ID as a decimal value\n" | |
1405 | "Configure OSPF area as stub\n" | |
1406 | "Do not inject inter-area routes into stub\n") | |
1407 | { | |
a3d826f0 | 1408 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1409 | int idx_ipv4_number = 1; |
1410 | struct in_addr area_id; | |
1411 | int ret, format; | |
1412 | ||
1413 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1414 | argv[idx_ipv4_number]->arg); | |
1415 | ||
1416 | ret = ospf_area_stub_set(ospf, area_id); | |
1417 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1418 | format); | |
1419 | if (ret == 0) { | |
1420 | vty_out(vty, | |
1421 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1422 | return CMD_WARNING_CONFIG_FAILED; | |
1423 | } | |
718e3744 | 1424 | |
d62a17ae | 1425 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1426 | |
d62a17ae | 1427 | return CMD_SUCCESS; |
718e3744 | 1428 | } |
1429 | ||
a2c62831 | 1430 | DEFUN (no_ospf_area_stub, |
1431 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1432 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1433 | NO_STR |
1434 | "OSPF area parameters\n" | |
1435 | "OSPF area ID in IP address format\n" | |
1436 | "OSPF area ID as a decimal value\n" | |
1437 | "Configure OSPF area as stub\n") | |
1438 | { | |
a3d826f0 | 1439 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1440 | int idx_ipv4_number = 2; |
1441 | struct in_addr area_id; | |
1442 | int format; | |
718e3744 | 1443 | |
d62a17ae | 1444 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1445 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1446 | |
d62a17ae | 1447 | ospf_area_stub_unset(ospf, area_id); |
1448 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1449 | |
d62a17ae | 1450 | return CMD_SUCCESS; |
718e3744 | 1451 | } |
1452 | ||
a2c62831 | 1453 | DEFUN (no_ospf_area_stub_no_summary, |
1454 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1455 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1456 | NO_STR |
1457 | "OSPF area parameters\n" | |
1458 | "OSPF area ID in IP address format\n" | |
1459 | "OSPF area ID as a decimal value\n" | |
1460 | "Configure OSPF area as stub\n" | |
1461 | "Do not inject inter-area routes into area\n") | |
1462 | { | |
a3d826f0 | 1463 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1464 | int idx_ipv4_number = 2; |
1465 | struct in_addr area_id; | |
1466 | int format; | |
718e3744 | 1467 | |
d62a17ae | 1468 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1469 | argv[idx_ipv4_number]->arg); | |
1470 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1471 | |
d62a17ae | 1472 | return CMD_SUCCESS; |
718e3744 | 1473 | } |
1474 | ||
d62a17ae | 1475 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1476 | struct cmd_token **argv, int cfg_nosum, |
1477 | int nosum) | |
718e3744 | 1478 | { |
a3d826f0 | 1479 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1480 | struct in_addr area_id; |
1481 | int ret, format; | |
1482 | ||
1483 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1484 | ||
1485 | ret = ospf_area_nssa_set(ospf, area_id); | |
1486 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1487 | format); | |
1488 | if (ret == 0) { | |
1489 | vty_out(vty, | |
1490 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1491 | return CMD_WARNING_CONFIG_FAILED; | |
1492 | } | |
1493 | ||
1494 | if (argc > 3) { | |
1495 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1496 | ospf_area_nssa_translator_role_set( | |
1497 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1498 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1499 | ospf_area_nssa_translator_role_set( | |
1500 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1501 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1502 | ospf_area_nssa_translator_role_set( | |
1503 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1504 | } else { | |
1505 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1506 | OSPF_NSSA_ROLE_CANDIDATE); | |
1507 | } | |
1508 | ||
7ef56a73 CS |
1509 | if (cfg_nosum) { |
1510 | if (nosum) | |
1511 | ospf_area_no_summary_set(ospf, area_id); | |
1512 | else | |
1513 | ospf_area_no_summary_unset(ospf, area_id); | |
1514 | } | |
d62a17ae | 1515 | |
1516 | ospf_schedule_abr_task(ospf); | |
1517 | ||
1518 | return CMD_SUCCESS; | |
718e3744 | 1519 | } |
1520 | ||
718e3744 | 1521 | |
b0a053be | 1522 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1523 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1524 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1525 | "OSPF area parameters\n" |
1526 | "OSPF area ID in IP address format\n" | |
1527 | "OSPF area ID as a decimal value\n" | |
1528 | "Configure OSPF area as nssa\n" | |
1529 | "Configure NSSA-ABR for translate election (default)\n" | |
1530 | "Configure NSSA-ABR to never translate\n" | |
1531 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1532 | { |
7ef56a73 | 1533 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1534 | } |
1535 | ||
1536 | DEFUN (ospf_area_nssa, | |
1537 | ospf_area_nssa_cmd, | |
6147e2c6 | 1538 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1539 | "OSPF area parameters\n" |
1540 | "OSPF area ID in IP address format\n" | |
1541 | "OSPF area ID as a decimal value\n" | |
1542 | "Configure OSPF area as nssa\n") | |
1543 | { | |
7ef56a73 | 1544 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 1, 0); |
b0a053be | 1545 | } |
718e3744 | 1546 | |
a2c62831 | 1547 | DEFUN (ospf_area_nssa_no_summary, |
1548 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1549 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1550 | "OSPF area parameters\n" |
1551 | "OSPF area ID in IP address format\n" | |
1552 | "OSPF area ID as a decimal value\n" | |
1553 | "Configure OSPF area as nssa\n" | |
1554 | "Do not inject inter-area routes into nssa\n") | |
1555 | { | |
7ef56a73 CS |
1556 | int idx_ipv4_number = 1; |
1557 | struct in_addr area_id; | |
1558 | int format; | |
1559 | ||
1560 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1561 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1562 | argv[idx_ipv4_number]->arg); | |
1563 | ||
1564 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1565 | format); | |
1566 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1567 | ||
1568 | ospf_schedule_abr_task(ospf); | |
1569 | ||
1570 | return CMD_SUCCESS; | |
1571 | } | |
1572 | ||
1573 | DEFUN (no_ospf_area_nssa_no_summary, | |
1574 | no_ospf_area_nssa_no_summary_cmd, | |
1575 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1576 | NO_STR | |
1577 | "OSPF area parameters\n" | |
1578 | "OSPF area ID in IP address format\n" | |
1579 | "OSPF area ID as a decimal value\n" | |
1580 | "Configure OSPF area as nssa\n" | |
1581 | "Do not inject inter-area routes into nssa\n") | |
1582 | { | |
1583 | int idx_ipv4_number = 2; | |
1584 | struct in_addr area_id; | |
1585 | int format; | |
1586 | ||
1587 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1588 | ||
1589 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1590 | argv[idx_ipv4_number]->arg); | |
1591 | ||
1592 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1593 | format); | |
1594 | ospf_area_no_summary_unset(ospf, area_id); | |
1595 | ||
1596 | ospf_schedule_abr_task(ospf); | |
1597 | ||
1598 | return CMD_SUCCESS; | |
718e3744 | 1599 | } |
1600 | ||
a2c62831 | 1601 | DEFUN (no_ospf_area_nssa, |
1602 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1603 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1604 | NO_STR |
1605 | "OSPF area parameters\n" | |
1606 | "OSPF area ID in IP address format\n" | |
1607 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1608 | "Configure OSPF area as nssa\n" |
1609 | "Configure NSSA-ABR for translate election (default)\n" | |
1610 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1611 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1612 | { |
a3d826f0 | 1613 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1614 | int idx_ipv4_number = 2; |
1615 | struct in_addr area_id; | |
1616 | int format; | |
718e3744 | 1617 | |
d62a17ae | 1618 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1619 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1620 | |
7ef56a73 | 1621 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1622 | |
d62a17ae | 1623 | ospf_schedule_abr_task(ospf); |
b0a053be | 1624 | |
d62a17ae | 1625 | return CMD_SUCCESS; |
718e3744 | 1626 | } |
1627 | ||
718e3744 | 1628 | |
a2c62831 | 1629 | DEFUN (ospf_area_default_cost, |
1630 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1631 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1632 | "OSPF area parameters\n" |
1633 | "OSPF area ID in IP address format\n" | |
1634 | "OSPF area ID as a decimal value\n" | |
1635 | "Set the summary-default cost of a NSSA or stub area\n" | |
1636 | "Stub's advertised default summary cost\n") | |
1637 | { | |
a3d826f0 | 1638 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1639 | int idx_ipv4_number = 1; |
1640 | int idx_number = 3; | |
1641 | struct ospf_area *area; | |
1642 | struct in_addr area_id; | |
1643 | u_int32_t cost; | |
1644 | int format; | |
1645 | struct prefix_ipv4 p; | |
1646 | ||
1647 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1648 | argv[idx_ipv4_number]->arg); | |
1649 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1650 | ||
1651 | area = ospf_area_get(ospf, area_id); | |
1652 | ospf_area_display_format_set(ospf, area, format); | |
1653 | ||
1654 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1655 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1656 | return CMD_WARNING_CONFIG_FAILED; | |
1657 | } | |
ba682537 | 1658 | |
d62a17ae | 1659 | area->default_cost = cost; |
1660 | ||
1661 | p.family = AF_INET; | |
1662 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1663 | p.prefixlen = 0; | |
1664 | if (IS_DEBUG_OSPF_EVENT) | |
1665 | zlog_debug( | |
1666 | "ospf_abr_announce_stub_defaults(): " | |
1667 | "announcing 0.0.0.0/0 to area %s", | |
1668 | inet_ntoa(area->area_id)); | |
1669 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
1670 | ||
1671 | return CMD_SUCCESS; | |
718e3744 | 1672 | } |
1673 | ||
a2c62831 | 1674 | DEFUN (no_ospf_area_default_cost, |
1675 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1676 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1677 | NO_STR |
1678 | "OSPF area parameters\n" | |
1679 | "OSPF area ID in IP address format\n" | |
1680 | "OSPF area ID as a decimal value\n" | |
1681 | "Set the summary-default cost of a NSSA or stub area\n" | |
1682 | "Stub's advertised default summary cost\n") | |
1683 | { | |
a3d826f0 | 1684 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1685 | int idx_ipv4_number = 2; |
1686 | struct ospf_area *area; | |
1687 | struct in_addr area_id; | |
1688 | int format; | |
1689 | struct prefix_ipv4 p; | |
718e3744 | 1690 | |
d62a17ae | 1691 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1692 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1693 | |
d62a17ae | 1694 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1695 | if (area == NULL) | |
1696 | return CMD_SUCCESS; | |
718e3744 | 1697 | |
d62a17ae | 1698 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1699 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1700 | return CMD_WARNING_CONFIG_FAILED; | |
1701 | } | |
718e3744 | 1702 | |
d62a17ae | 1703 | area->default_cost = 1; |
718e3744 | 1704 | |
d62a17ae | 1705 | p.family = AF_INET; |
1706 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1707 | p.prefixlen = 0; | |
1708 | if (IS_DEBUG_OSPF_EVENT) | |
1709 | zlog_debug( | |
1710 | "ospf_abr_announce_stub_defaults(): " | |
1711 | "announcing 0.0.0.0/0 to area %s", | |
1712 | inet_ntoa(area->area_id)); | |
1713 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
ba682537 | 1714 | |
1715 | ||
d62a17ae | 1716 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1717 | |
d62a17ae | 1718 | return CMD_SUCCESS; |
718e3744 | 1719 | } |
1720 | ||
a2c62831 | 1721 | DEFUN (ospf_area_export_list, |
1722 | ospf_area_export_list_cmd, | |
6147e2c6 | 1723 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1724 | "OSPF area parameters\n" |
1725 | "OSPF area ID in IP address format\n" | |
1726 | "OSPF area ID as a decimal value\n" | |
1727 | "Set the filter for networks announced to other areas\n" | |
1728 | "Name of the access-list\n") | |
1729 | { | |
a3d826f0 | 1730 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1731 | int idx_ipv4_number = 1; |
1732 | struct ospf_area *area; | |
1733 | struct in_addr area_id; | |
1734 | int format; | |
718e3744 | 1735 | |
d62a17ae | 1736 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1737 | |
d62a17ae | 1738 | area = ospf_area_get(ospf, area_id); |
1739 | ospf_area_display_format_set(ospf, area, format); | |
1740 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1741 | |
d62a17ae | 1742 | return CMD_SUCCESS; |
718e3744 | 1743 | } |
1744 | ||
a2c62831 | 1745 | DEFUN (no_ospf_area_export_list, |
1746 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1747 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1748 | NO_STR |
1749 | "OSPF area parameters\n" | |
1750 | "OSPF area ID in IP address format\n" | |
1751 | "OSPF area ID as a decimal value\n" | |
1752 | "Unset the filter for networks announced to other areas\n" | |
1753 | "Name of the access-list\n") | |
1754 | { | |
a3d826f0 | 1755 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1756 | int idx_ipv4_number = 2; |
1757 | struct ospf_area *area; | |
1758 | struct in_addr area_id; | |
1759 | int format; | |
718e3744 | 1760 | |
d62a17ae | 1761 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1762 | |
d62a17ae | 1763 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1764 | if (area == NULL) | |
1765 | return CMD_SUCCESS; | |
718e3744 | 1766 | |
d62a17ae | 1767 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1768 | |
d62a17ae | 1769 | return CMD_SUCCESS; |
718e3744 | 1770 | } |
1771 | ||
1772 | ||
a2c62831 | 1773 | DEFUN (ospf_area_import_list, |
1774 | ospf_area_import_list_cmd, | |
6147e2c6 | 1775 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1776 | "OSPF area parameters\n" |
1777 | "OSPF area ID in IP address format\n" | |
1778 | "OSPF area ID as a decimal value\n" | |
1779 | "Set the filter for networks from other areas announced to the specified one\n" | |
1780 | "Name of the access-list\n") | |
1781 | { | |
a3d826f0 | 1782 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1783 | int idx_ipv4_number = 1; |
1784 | struct ospf_area *area; | |
1785 | struct in_addr area_id; | |
1786 | int format; | |
718e3744 | 1787 | |
d62a17ae | 1788 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1789 | |
d62a17ae | 1790 | area = ospf_area_get(ospf, area_id); |
1791 | ospf_area_display_format_set(ospf, area, format); | |
1792 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1793 | |
d62a17ae | 1794 | return CMD_SUCCESS; |
718e3744 | 1795 | } |
1796 | ||
a2c62831 | 1797 | DEFUN (no_ospf_area_import_list, |
1798 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1799 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1800 | NO_STR |
1801 | "OSPF area parameters\n" | |
1802 | "OSPF area ID in IP address format\n" | |
1803 | "OSPF area ID as a decimal value\n" | |
1804 | "Unset the filter for networks announced to other areas\n" | |
1805 | "Name of the access-list\n") | |
1806 | { | |
a3d826f0 | 1807 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1808 | int idx_ipv4_number = 2; |
1809 | struct ospf_area *area; | |
1810 | struct in_addr area_id; | |
1811 | int format; | |
718e3744 | 1812 | |
d62a17ae | 1813 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1814 | |
d62a17ae | 1815 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1816 | if (area == NULL) | |
1817 | return CMD_SUCCESS; | |
718e3744 | 1818 | |
d62a17ae | 1819 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1820 | |
d62a17ae | 1821 | return CMD_SUCCESS; |
718e3744 | 1822 | } |
1823 | ||
a2c62831 | 1824 | DEFUN (ospf_area_filter_list, |
1825 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1826 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1827 | "OSPF area parameters\n" |
1828 | "OSPF area ID in IP address format\n" | |
1829 | "OSPF area ID as a decimal value\n" | |
1830 | "Filter networks between OSPF areas\n" | |
1831 | "Filter prefixes between OSPF areas\n" | |
1832 | "Name of an IP prefix-list\n" | |
1833 | "Filter networks sent to this area\n" | |
1834 | "Filter networks sent from this area\n") | |
1835 | { | |
a3d826f0 | 1836 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1837 | int idx_ipv4_number = 1; |
1838 | int idx_word = 4; | |
1839 | int idx_in_out = 5; | |
1840 | struct ospf_area *area; | |
1841 | struct in_addr area_id; | |
1842 | struct prefix_list *plist; | |
1843 | int format; | |
1844 | ||
1845 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1846 | ||
1847 | area = ospf_area_get(ospf, area_id); | |
1848 | ospf_area_display_format_set(ospf, area, format); | |
1849 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1850 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1851 | PREFIX_LIST_IN(area) = plist; | |
1852 | if (PREFIX_NAME_IN(area)) | |
1853 | free(PREFIX_NAME_IN(area)); | |
1854 | ||
1855 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1856 | ospf_schedule_abr_task(ospf); | |
1857 | } else { | |
1858 | PREFIX_LIST_OUT(area) = plist; | |
1859 | if (PREFIX_NAME_OUT(area)) | |
1860 | free(PREFIX_NAME_OUT(area)); | |
1861 | ||
1862 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1863 | ospf_schedule_abr_task(ospf); | |
1864 | } | |
718e3744 | 1865 | |
d62a17ae | 1866 | return CMD_SUCCESS; |
718e3744 | 1867 | } |
1868 | ||
a2c62831 | 1869 | DEFUN (no_ospf_area_filter_list, |
1870 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1871 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1872 | NO_STR |
1873 | "OSPF area parameters\n" | |
1874 | "OSPF area ID in IP address format\n" | |
1875 | "OSPF area ID as a decimal value\n" | |
1876 | "Filter networks between OSPF areas\n" | |
1877 | "Filter prefixes between OSPF areas\n" | |
1878 | "Name of an IP prefix-list\n" | |
1879 | "Filter networks sent to this area\n" | |
1880 | "Filter networks sent from this area\n") | |
1881 | { | |
a3d826f0 | 1882 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1883 | int idx_ipv4_number = 2; |
1884 | int idx_word = 5; | |
1885 | int idx_in_out = 6; | |
1886 | struct ospf_area *area; | |
1887 | struct in_addr area_id; | |
1888 | int format; | |
718e3744 | 1889 | |
d62a17ae | 1890 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1891 | |
d62a17ae | 1892 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1893 | return CMD_SUCCESS; | |
718e3744 | 1894 | |
d62a17ae | 1895 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1896 | if (PREFIX_NAME_IN(area)) | |
1897 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1898 | != 0) | |
1899 | return CMD_SUCCESS; | |
718e3744 | 1900 | |
d62a17ae | 1901 | PREFIX_LIST_IN(area) = NULL; |
1902 | if (PREFIX_NAME_IN(area)) | |
1903 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1904 | |
d62a17ae | 1905 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1906 | |
d62a17ae | 1907 | ospf_schedule_abr_task(ospf); |
1908 | } else { | |
1909 | if (PREFIX_NAME_OUT(area)) | |
1910 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1911 | != 0) | |
1912 | return CMD_SUCCESS; | |
718e3744 | 1913 | |
d62a17ae | 1914 | PREFIX_LIST_OUT(area) = NULL; |
1915 | if (PREFIX_NAME_OUT(area)) | |
1916 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1917 | |
d62a17ae | 1918 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1919 | |
d62a17ae | 1920 | ospf_schedule_abr_task(ospf); |
1921 | } | |
1922 | ||
1923 | return CMD_SUCCESS; | |
718e3744 | 1924 | } |
1925 | ||
6b0655a2 | 1926 | |
a2c62831 | 1927 | DEFUN (ospf_area_authentication_message_digest, |
1928 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1929 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1930 | NO_STR | |
718e3744 | 1931 | "OSPF area parameters\n" |
2b00515a CF |
1932 | "OSPF area ID in IP address format\n" |
1933 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1934 | "Enable authentication\n" |
1935 | "Use message-digest authentication\n") | |
1936 | { | |
a3d826f0 | 1937 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1938 | int idx_ipv4_number = 1; |
1939 | struct ospf_area *area; | |
1940 | struct in_addr area_id; | |
1941 | int format; | |
718e3744 | 1942 | |
d62a17ae | 1943 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1944 | |
d62a17ae | 1945 | area = ospf_area_get(ospf, area_id); |
1946 | ospf_area_display_format_set(ospf, area, format); | |
32573073 | 1947 | area->auth_type = strmatch(argv[0]->text, "no") ? OSPF_AUTH_NULL : OSPF_AUTH_CRYPTOGRAPHIC; |
718e3744 | 1948 | |
d62a17ae | 1949 | return CMD_SUCCESS; |
718e3744 | 1950 | } |
1951 | ||
a2c62831 | 1952 | DEFUN (ospf_area_authentication, |
1953 | ospf_area_authentication_cmd, | |
6147e2c6 | 1954 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 1955 | "OSPF area parameters\n" |
1956 | "OSPF area ID in IP address format\n" | |
1957 | "OSPF area ID as a decimal value\n" | |
1958 | "Enable authentication\n") | |
1959 | { | |
a3d826f0 | 1960 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1961 | int idx_ipv4_number = 1; |
1962 | struct ospf_area *area; | |
1963 | struct in_addr area_id; | |
1964 | int format; | |
718e3744 | 1965 | |
d62a17ae | 1966 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1967 | |
d62a17ae | 1968 | area = ospf_area_get(ospf, area_id); |
1969 | ospf_area_display_format_set(ospf, area, format); | |
1970 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 1971 | |
d62a17ae | 1972 | return CMD_SUCCESS; |
718e3744 | 1973 | } |
1974 | ||
a2c62831 | 1975 | DEFUN (no_ospf_area_authentication, |
1976 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 1977 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 1978 | NO_STR |
1979 | "OSPF area parameters\n" | |
1980 | "OSPF area ID in IP address format\n" | |
1981 | "OSPF area ID as a decimal value\n" | |
1982 | "Enable authentication\n") | |
1983 | { | |
a3d826f0 | 1984 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1985 | int idx_ipv4_number = 2; |
1986 | struct ospf_area *area; | |
1987 | struct in_addr area_id; | |
1988 | int format; | |
718e3744 | 1989 | |
d62a17ae | 1990 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1991 | |
d62a17ae | 1992 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1993 | if (area == NULL) | |
1994 | return CMD_SUCCESS; | |
718e3744 | 1995 | |
d62a17ae | 1996 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 1997 | |
d62a17ae | 1998 | ospf_area_check_free(ospf, area_id); |
1999 | ||
2000 | return CMD_SUCCESS; | |
718e3744 | 2001 | } |
2002 | ||
6b0655a2 | 2003 | |
718e3744 | 2004 | DEFUN (ospf_abr_type, |
2005 | ospf_abr_type_cmd, | |
6147e2c6 | 2006 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2007 | "OSPF specific commands\n" |
2008 | "Set OSPF ABR type\n" | |
2009 | "Alternative ABR, cisco implementation\n" | |
2010 | "Alternative ABR, IBM implementation\n" | |
2011 | "Shortcut ABR\n" | |
2012 | "Standard behavior (RFC2328)\n") | |
2013 | { | |
a3d826f0 | 2014 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2015 | int idx_vendor = 2; |
2016 | u_char abr_type = OSPF_ABR_UNKNOWN; | |
2017 | ||
2018 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2019 | abr_type = OSPF_ABR_CISCO; | |
2020 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2021 | abr_type = OSPF_ABR_IBM; | |
2022 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2023 | abr_type = OSPF_ABR_SHORTCUT; | |
2024 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2025 | abr_type = OSPF_ABR_STAND; | |
2026 | else | |
2027 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2028 | |
d62a17ae | 2029 | /* If ABR type value is changed, schedule ABR task. */ |
2030 | if (ospf->abr_type != abr_type) { | |
2031 | ospf->abr_type = abr_type; | |
2032 | ospf_schedule_abr_task(ospf); | |
2033 | } | |
2034 | ||
2035 | return CMD_SUCCESS; | |
718e3744 | 2036 | } |
2037 | ||
2038 | DEFUN (no_ospf_abr_type, | |
2039 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2040 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2041 | NO_STR |
2042 | "OSPF specific commands\n" | |
2043 | "Set OSPF ABR type\n" | |
2044 | "Alternative ABR, cisco implementation\n" | |
2045 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2046 | "Shortcut ABR\n" |
2047 | "Standard ABR\n") | |
718e3744 | 2048 | { |
a3d826f0 | 2049 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2050 | int idx_vendor = 3; |
2051 | u_char abr_type = OSPF_ABR_UNKNOWN; | |
2052 | ||
2053 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2054 | abr_type = OSPF_ABR_CISCO; | |
2055 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2056 | abr_type = OSPF_ABR_IBM; | |
2057 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2058 | abr_type = OSPF_ABR_SHORTCUT; | |
2059 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2060 | abr_type = OSPF_ABR_STAND; | |
2061 | else | |
2062 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2063 | |
d62a17ae | 2064 | /* If ABR type value is changed, schedule ABR task. */ |
2065 | if (ospf->abr_type == abr_type) { | |
2066 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2067 | ospf_schedule_abr_task(ospf); | |
2068 | } | |
2069 | ||
2070 | return CMD_SUCCESS; | |
718e3744 | 2071 | } |
2072 | ||
d7e60dd7 AS |
2073 | DEFUN (ospf_log_adjacency_changes, |
2074 | ospf_log_adjacency_changes_cmd, | |
2075 | "log-adjacency-changes", | |
2076 | "Log changes in adjacency state\n") | |
2077 | { | |
a3d826f0 | 2078 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2079 | |
d62a17ae | 2080 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2081 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2082 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2083 | } |
2084 | ||
2085 | DEFUN (ospf_log_adjacency_changes_detail, | |
2086 | ospf_log_adjacency_changes_detail_cmd, | |
2087 | "log-adjacency-changes detail", | |
2088 | "Log changes in adjacency state\n" | |
2089 | "Log all state changes\n") | |
2090 | { | |
a3d826f0 | 2091 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2092 | |
d62a17ae | 2093 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2094 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2095 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2096 | } |
2097 | ||
2098 | DEFUN (no_ospf_log_adjacency_changes, | |
2099 | no_ospf_log_adjacency_changes_cmd, | |
2100 | "no log-adjacency-changes", | |
2101 | NO_STR | |
2102 | "Log changes in adjacency state\n") | |
2103 | { | |
a3d826f0 | 2104 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2105 | |
d62a17ae | 2106 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2107 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2108 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2109 | } |
2110 | ||
2111 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2112 | no_ospf_log_adjacency_changes_detail_cmd, | |
2113 | "no log-adjacency-changes detail", | |
2114 | NO_STR | |
2115 | "Log changes in adjacency state\n" | |
2116 | "Log all state changes\n") | |
2117 | { | |
a3d826f0 | 2118 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2119 | |
d62a17ae | 2120 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2121 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2122 | } |
2123 | ||
718e3744 | 2124 | DEFUN (ospf_compatible_rfc1583, |
2125 | ospf_compatible_rfc1583_cmd, | |
2126 | "compatible rfc1583", | |
2127 | "OSPF compatibility list\n" | |
2128 | "compatible with RFC 1583\n") | |
2129 | { | |
a3d826f0 | 2130 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2131 | |
d62a17ae | 2132 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2133 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2134 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2135 | } | |
2136 | return CMD_SUCCESS; | |
718e3744 | 2137 | } |
2138 | ||
2139 | DEFUN (no_ospf_compatible_rfc1583, | |
2140 | no_ospf_compatible_rfc1583_cmd, | |
2141 | "no compatible rfc1583", | |
2142 | NO_STR | |
2143 | "OSPF compatibility list\n" | |
2144 | "compatible with RFC 1583\n") | |
2145 | { | |
a3d826f0 | 2146 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2147 | |
d62a17ae | 2148 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2149 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2150 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2151 | } | |
2152 | return CMD_SUCCESS; | |
718e3744 | 2153 | } |
2154 | ||
d62a17ae | 2155 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2156 | "ospf rfc1583compatibility", | |
2157 | "OSPF specific commands\n" | |
2158 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2159 | |
d62a17ae | 2160 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2161 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2162 | "OSPF specific commands\n" |
2163 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2164 | |
d62a17ae | 2165 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2166 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2167 | { |
a3d826f0 | 2168 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2169 | |
d62a17ae | 2170 | ospf->spf_delay = delay; |
2171 | ospf->spf_holdtime = hold; | |
2172 | ospf->spf_max_holdtime = max; | |
2173 | ||
2174 | return CMD_SUCCESS; | |
d24f6e2a | 2175 | } |
718e3744 | 2176 | |
ac7424f9 MR |
2177 | DEFUN (ospf_timers_min_ls_interval, |
2178 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2179 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2180 | "Adjust routing timers\n" |
2181 | "Throttling adaptive timer\n" | |
2182 | "LSA delay between transmissions\n" | |
813d4307 | 2183 | "All LSA types\n" |
ac7424f9 MR |
2184 | "Delay (msec) between sending LSAs\n") |
2185 | { | |
a3d826f0 | 2186 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2187 | int idx_number = 4; |
2188 | unsigned int interval; | |
ac7424f9 | 2189 | |
d62a17ae | 2190 | if (argc < 5) { |
2191 | vty_out(vty, "Insufficient arguments\n"); | |
2192 | return CMD_WARNING_CONFIG_FAILED; | |
2193 | } | |
ac7424f9 | 2194 | |
d62a17ae | 2195 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2196 | |
d62a17ae | 2197 | ospf->min_ls_interval = interval; |
ac7424f9 | 2198 | |
d62a17ae | 2199 | return CMD_SUCCESS; |
ac7424f9 MR |
2200 | } |
2201 | ||
2202 | DEFUN (no_ospf_timers_min_ls_interval, | |
2203 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2204 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2205 | NO_STR |
2206 | "Adjust routing timers\n" | |
2207 | "Throttling adaptive timer\n" | |
813d4307 | 2208 | "LSA delay between transmissions\n" |
7a7be519 | 2209 | "All LSA types\n" |
2210 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2211 | { |
a3d826f0 | 2212 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2213 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2214 | |
d62a17ae | 2215 | return CMD_SUCCESS; |
ac7424f9 MR |
2216 | } |
2217 | ||
d24f6e2a | 2218 | DEFUN (ospf_timers_throttle_spf, |
2219 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2220 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2221 | "Adjust routing timers\n" |
2222 | "Throttling adaptive timer\n" | |
2223 | "OSPF SPF timers\n" | |
2224 | "Delay (msec) from first change received till SPF calculation\n" | |
2225 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2226 | "Maximum hold time (msec)\n") | |
2227 | { | |
d62a17ae | 2228 | int idx_number = 3; |
2229 | int idx_number_2 = 4; | |
2230 | int idx_number_3 = 5; | |
2231 | unsigned int delay, hold, max; | |
2232 | ||
2233 | if (argc < 6) { | |
2234 | vty_out(vty, "Insufficient arguments\n"); | |
2235 | return CMD_WARNING_CONFIG_FAILED; | |
2236 | } | |
2237 | ||
2238 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2239 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2240 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2241 | ||
2242 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2243 | } |
2244 | ||
d24f6e2a | 2245 | DEFUN (no_ospf_timers_throttle_spf, |
2246 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2247 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2248 | NO_STR |
2249 | "Adjust routing timers\n" | |
d24f6e2a | 2250 | "Throttling adaptive timer\n" |
7a7be519 | 2251 | "OSPF SPF timers\n" |
2252 | "Delay (msec) from first change received till SPF calculation\n" | |
2253 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2254 | "Maximum hold time (msec)\n") | |
22b27e95 | 2255 | { |
d62a17ae | 2256 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2257 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2258 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2259 | } |
2260 | ||
b4a039bf | 2261 | |
0e88de35 QY |
2262 | DEFUN (ospf_timers_lsa_min_arrival, |
2263 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2264 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2265 | "Adjust routing timers\n" |
2266 | "OSPF LSA timers\n" | |
2267 | "Minimum delay in receiving new version of a LSA\n" | |
2268 | "Delay in milliseconds\n") | |
2269 | { | |
a3d826f0 | 2270 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2271 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2272 | return CMD_SUCCESS; |
b6927875 DS |
2273 | } |
2274 | ||
0e88de35 QY |
2275 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2276 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2277 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2278 | NO_STR |
2279 | "Adjust routing timers\n" | |
2280 | "OSPF LSA timers\n" | |
7a7be519 | 2281 | "Minimum delay in receiving new version of a LSA\n" |
2282 | "Delay in milliseconds\n") | |
b6927875 | 2283 | { |
a3d826f0 | 2284 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2285 | unsigned int minarrival; |
b6927875 | 2286 | |
d62a17ae | 2287 | if (argc > 4) { |
0e88de35 | 2288 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2289 | |
d62a17ae | 2290 | if (ospf->min_ls_arrival != minarrival |
2291 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2292 | return CMD_SUCCESS; | |
2293 | } | |
b6927875 | 2294 | |
d62a17ae | 2295 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2296 | |
d62a17ae | 2297 | return CMD_SUCCESS; |
b6927875 DS |
2298 | } |
2299 | ||
5d1a2ee8 QY |
2300 | #if CONFDATE > 20180708 |
2301 | CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08") | |
2302 | #endif | |
0e88de35 QY |
2303 | ALIAS_HIDDEN (ospf_timers_lsa_min_arrival, |
2304 | ospf_timers_lsa_arrival_cmd, | |
2305 | "timers lsa arrival (0-1000)", | |
2306 | "adjust routing timers\n" | |
2307 | "throttling link state advertisement delays\n" | |
2308 | "ospf minimum arrival interval delay\n" | |
2309 | "delay (msec) between accepted lsas\n"); | |
2310 | ||
5d1a2ee8 QY |
2311 | #if CONFDATE > 20180708 |
2312 | CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08") | |
2313 | #endif | |
0e88de35 QY |
2314 | ALIAS_HIDDEN (no_ospf_timers_lsa_min_arrival, |
2315 | no_ospf_timers_lsa_arrival_cmd, | |
2316 | "no timers lsa arrival (0-1000)", | |
2317 | NO_STR | |
2318 | "adjust routing timers\n" | |
2319 | "throttling link state advertisement delays\n" | |
2320 | "ospf minimum arrival interval delay\n" | |
2321 | "delay (msec) between accepted lsas\n"); | |
2322 | ||
2323 | ||
a2c62831 | 2324 | DEFUN (ospf_neighbor, |
2325 | ospf_neighbor_cmd, | |
7a7be519 | 2326 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2327 | NEIGHBOR_STR |
7a7be519 | 2328 | "Neighbor IP address\n" |
2329 | "Neighbor Priority\n" | |
2330 | "Priority\n" | |
2331 | "Dead Neighbor Polling interval\n" | |
2332 | "Seconds\n") | |
718e3744 | 2333 | { |
a3d826f0 | 2334 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2335 | int idx_ipv4 = 1; |
2336 | int idx_pri = 3; | |
2337 | int idx_poll = 5; | |
2338 | struct in_addr nbr_addr; | |
2339 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2340 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2341 | |
cc9b06ad DS |
2342 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2343 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2344 | return CMD_WARNING_CONFIG_FAILED; | |
2345 | } | |
718e3744 | 2346 | |
d62a17ae | 2347 | if (argc > 2) |
2348 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2349 | |
d62a17ae | 2350 | if (argc > 4) |
2351 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2352 | |
d62a17ae | 2353 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2354 | |
d62a17ae | 2355 | if (argc > 2) |
2356 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2357 | |
d62a17ae | 2358 | if (argc > 4) |
2359 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2360 | |
d62a17ae | 2361 | return CMD_SUCCESS; |
718e3744 | 2362 | } |
2363 | ||
a2c62831 | 2364 | DEFUN (ospf_neighbor_poll_interval, |
2365 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2366 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2367 | NEIGHBOR_STR |
2368 | "Neighbor IP address\n" | |
2369 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2370 | "Seconds\n" |
2371 | "OSPF priority of non-broadcast neighbor\n" | |
2372 | "Priority\n") | |
22b27e95 | 2373 | { |
a3d826f0 | 2374 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2375 | int idx_ipv4 = 1; |
2376 | int idx_poll = 3; | |
2377 | int idx_pri = 5; | |
2378 | struct in_addr nbr_addr; | |
2379 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2380 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2381 | |
cc9b06ad DS |
2382 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2383 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2384 | return CMD_WARNING_CONFIG_FAILED; | |
2385 | } | |
718e3744 | 2386 | |
d62a17ae | 2387 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2388 | |
d62a17ae | 2389 | if (argc > 4) |
2390 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
718e3744 | 2391 | |
d62a17ae | 2392 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2393 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2394 | |
d62a17ae | 2395 | if (argc > 4) |
2396 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2397 | |
d62a17ae | 2398 | return CMD_SUCCESS; |
718e3744 | 2399 | } |
2400 | ||
a2c62831 | 2401 | DEFUN (no_ospf_neighbor, |
2402 | no_ospf_neighbor_cmd, | |
7a7be519 | 2403 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2404 | NO_STR |
2405 | NEIGHBOR_STR | |
7a7be519 | 2406 | "Neighbor IP address\n" |
2407 | "Neighbor Priority\n" | |
2408 | "Priority\n" | |
2409 | "Dead Neighbor Polling interval\n" | |
2410 | "Seconds\n") | |
718e3744 | 2411 | { |
a3d826f0 | 2412 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2413 | int idx_ipv4 = 2; |
2414 | struct in_addr nbr_addr; | |
718e3744 | 2415 | |
cc9b06ad DS |
2416 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2417 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2418 | return CMD_WARNING_CONFIG_FAILED; | |
2419 | } | |
718e3744 | 2420 | |
d62a17ae | 2421 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2422 | |
d62a17ae | 2423 | return CMD_SUCCESS; |
718e3744 | 2424 | } |
2425 | ||
7a7be519 | 2426 | DEFUN (no_ospf_neighbor_poll, |
2427 | no_ospf_neighbor_poll_cmd, | |
2428 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2429 | NO_STR | |
2430 | NEIGHBOR_STR | |
2431 | "Neighbor IP address\n" | |
2432 | "Dead Neighbor Polling interval\n" | |
2433 | "Seconds\n" | |
2434 | "Neighbor Priority\n" | |
2435 | "Priority\n") | |
2436 | { | |
a3d826f0 | 2437 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2438 | int idx_ipv4 = 2; |
2439 | struct in_addr nbr_addr; | |
7a7be519 | 2440 | |
cc9b06ad DS |
2441 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2442 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2443 | return CMD_WARNING_CONFIG_FAILED; | |
2444 | } | |
718e3744 | 2445 | |
d62a17ae | 2446 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2447 | |
d62a17ae | 2448 | return CMD_SUCCESS; |
7a7be519 | 2449 | } |
718e3744 | 2450 | |
bf2bfafd DW |
2451 | DEFUN (ospf_refresh_timer, |
2452 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2453 | "refresh timer (10-1800)", |
718e3744 | 2454 | "Adjust refresh parameters\n" |
2455 | "Set refresh timer\n" | |
2456 | "Timer value in seconds\n") | |
2457 | { | |
a3d826f0 | 2458 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2459 | int idx_number = 2; |
2460 | unsigned int interval; | |
7c8ff89e | 2461 | |
d62a17ae | 2462 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2463 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2464 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2465 | |
d62a17ae | 2466 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2467 | |
d62a17ae | 2468 | return CMD_SUCCESS; |
718e3744 | 2469 | } |
2470 | ||
bf2bfafd DW |
2471 | DEFUN (no_ospf_refresh_timer, |
2472 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2473 | "no refresh timer [(10-1800)]", |
3a2d747c | 2474 | NO_STR |
718e3744 | 2475 | "Adjust refresh parameters\n" |
2476 | "Unset refresh timer\n" | |
2477 | "Timer value in seconds\n") | |
2478 | { | |
a3d826f0 | 2479 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2480 | int idx_number = 3; |
2481 | unsigned int interval; | |
718e3744 | 2482 | |
d62a17ae | 2483 | if (argc == 1) { |
2484 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2485 | |
d62a17ae | 2486 | if (ospf->lsa_refresh_interval != interval |
2487 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2488 | return CMD_SUCCESS; | |
2489 | } | |
2490 | ||
2491 | ospf_timers_refresh_unset(ospf); | |
2492 | ||
2493 | return CMD_SUCCESS; | |
718e3744 | 2494 | } |
2495 | ||
718e3744 | 2496 | |
a2c62831 | 2497 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2498 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2499 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2500 | "Calculate OSPF interface cost according to bandwidth\n" |
2501 | "Use reference bandwidth method to assign OSPF cost\n" | |
2502 | "The reference bandwidth in terms of Mbits per second\n") | |
2503 | { | |
a3d826f0 | 2504 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2505 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2506 | int idx_number = 2; |
2507 | u_int32_t refbw; | |
d62a17ae | 2508 | struct interface *ifp; |
2509 | ||
2510 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2511 | if (refbw < 1 || refbw > 4294967) { | |
2512 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2513 | return CMD_WARNING_CONFIG_FAILED; | |
2514 | } | |
2515 | ||
2516 | /* If reference bandwidth is changed. */ | |
2517 | if ((refbw) == ospf->ref_bandwidth) | |
2518 | return CMD_SUCCESS; | |
2519 | ||
2520 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2521 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2522 | ospf_if_recalculate_output_cost(ifp); |
2523 | ||
2524 | return CMD_SUCCESS; | |
718e3744 | 2525 | } |
2526 | ||
a2c62831 | 2527 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2528 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2529 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2530 | NO_STR |
2531 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2532 | "Use reference bandwidth method to assign OSPF cost\n" |
2533 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2534 | { |
a3d826f0 | 2535 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2536 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2537 | struct interface *ifp; |
718e3744 | 2538 | |
d62a17ae | 2539 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2540 | return CMD_SUCCESS; | |
2541 | ||
2542 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2543 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2544 | vty_out(vty, | |
2545 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2546 | ||
451fda4f | 2547 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2548 | ospf_if_recalculate_output_cost(ifp); |
2549 | ||
2550 | return CMD_SUCCESS; | |
718e3744 | 2551 | } |
2552 | ||
2f8f370e DS |
2553 | DEFUN (ospf_write_multiplier, |
2554 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2555 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2556 | "OSPF specific commands\n" |
2557 | "Write multiplier\n" | |
2558 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2559 | { |
a3d826f0 | 2560 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2561 | int idx_number; |
2562 | u_int32_t write_oi_count; | |
2563 | ||
2564 | if (argc == 3) | |
2565 | idx_number = 2; | |
2566 | else | |
2567 | idx_number = 1; | |
2568 | ||
2569 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2570 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2571 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2572 | return CMD_WARNING_CONFIG_FAILED; | |
2573 | } | |
2574 | ||
2575 | ospf->write_oi_count = write_oi_count; | |
2576 | return CMD_SUCCESS; | |
2f8f370e DS |
2577 | } |
2578 | ||
d62a17ae | 2579 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2580 | "Write multiplier\n" | |
2581 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2582 | |
2f8f370e DS |
2583 | DEFUN (no_ospf_write_multiplier, |
2584 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2585 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2586 | NO_STR |
e8f45e82 | 2587 | "OSPF specific commands\n" |
813d4307 DW |
2588 | "Write multiplier\n" |
2589 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2590 | { |
a3d826f0 | 2591 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2592 | |
d62a17ae | 2593 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2594 | return CMD_SUCCESS; | |
2f8f370e DS |
2595 | } |
2596 | ||
d62a17ae | 2597 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2598 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2599 | "Write multiplier\n" |
2600 | "Maximum number of interface serviced per write\n") | |
2601 | ||
2602 | const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)", | |
2603 | "Alternative IBM", "Alternative Cisco", | |
2604 | "Alternative Shortcut"}; | |
2605 | ||
2606 | const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"}; | |
2607 | ||
2608 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
2609 | json_object *json_areas, u_char use_json) | |
2610 | { | |
2611 | json_object *json_area = NULL; | |
2612 | ||
2613 | if (use_json) | |
2614 | json_area = json_object_new_object(); | |
2615 | ||
2616 | /* Show Area ID. */ | |
2617 | if (!use_json) | |
2618 | vty_out(vty, " Area ID: %s", inet_ntoa(area->area_id)); | |
2619 | ||
2620 | /* Show Area type/mode. */ | |
2621 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2622 | if (use_json) | |
2623 | json_object_boolean_true_add(json_area, "backbone"); | |
2624 | else | |
2625 | vty_out(vty, " (Backbone)\n"); | |
2626 | } else { | |
2627 | if (use_json) { | |
2628 | if (area->external_routing == OSPF_AREA_STUB) { | |
2629 | if (area->no_summary) | |
2630 | json_object_boolean_true_add( | |
2631 | json_area, "stubNoSummary"); | |
2632 | if (area->shortcut_configured) | |
2633 | json_object_boolean_true_add( | |
2634 | json_area, "stubShortcut"); | |
2635 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2636 | if (area->no_summary) | |
2637 | json_object_boolean_true_add( | |
2638 | json_area, "nssaNoSummary"); | |
2639 | if (area->shortcut_configured) | |
2640 | json_object_boolean_true_add( | |
2641 | json_area, "nssaShortcut"); | |
2642 | } | |
813d4307 | 2643 | |
d62a17ae | 2644 | json_object_string_add( |
2645 | json_area, "shortcuttingMode", | |
2646 | ospf_shortcut_mode_descr_str | |
2647 | [area->shortcut_configured]); | |
2648 | if (area->shortcut_capability) | |
2649 | json_object_boolean_true_add(json_area, | |
2650 | "sBitConcensus"); | |
2651 | } else { | |
2652 | if (area->external_routing == OSPF_AREA_STUB) | |
2653 | vty_out(vty, " (Stub%s%s)", | |
2654 | area->no_summary ? ", no summary" : "", | |
2655 | area->shortcut_configured ? "; " : ""); | |
2656 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2657 | vty_out(vty, " (NSSA%s%s)", | |
2658 | area->no_summary ? ", no summary" : "", | |
2659 | area->shortcut_configured ? "; " : ""); | |
2660 | ||
2661 | vty_out(vty, "\n"); | |
2662 | vty_out(vty, " Shortcutting mode: %s", | |
2663 | ospf_shortcut_mode_descr_str | |
2664 | [area->shortcut_configured]); | |
2665 | vty_out(vty, ", S-bit consensus: %s\n", | |
2666 | area->shortcut_capability ? "ok" : "no"); | |
2667 | } | |
2668 | } | |
718e3744 | 2669 | |
d62a17ae | 2670 | /* Show number of interfaces */ |
2671 | if (use_json) { | |
2672 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2673 | listcount(area->oiflist)); | |
2674 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2675 | area->act_ints); | |
2676 | } else | |
2677 | vty_out(vty, | |
2678 | " Number of interfaces in this area: Total: %d, " | |
2679 | "Active: %d\n", | |
2680 | listcount(area->oiflist), area->act_ints); | |
2681 | ||
2682 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2683 | if (use_json) { | |
2684 | json_object_boolean_true_add(json_area, "nssa"); | |
2685 | if (!IS_OSPF_ABR(area->ospf)) | |
2686 | json_object_boolean_false_add(json_area, "abr"); | |
2687 | else if (area->NSSATranslatorState) { | |
2688 | json_object_boolean_true_add(json_area, "abr"); | |
2689 | if (area->NSSATranslatorRole | |
2690 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2691 | json_object_boolean_true_add( | |
2692 | json_area, | |
2693 | "nssaTranslatorElected"); | |
2694 | else if (area->NSSATranslatorRole | |
2695 | == OSPF_NSSA_ROLE_ALWAYS) | |
2696 | json_object_boolean_true_add( | |
2697 | json_area, | |
2698 | "nssaTranslatorAlways"); | |
2699 | } else { | |
2700 | json_object_boolean_true_add(json_area, "abr"); | |
2701 | if (area->NSSATranslatorRole | |
2702 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2703 | json_object_boolean_false_add( | |
2704 | json_area, | |
2705 | "nssaTranslatorElected"); | |
2706 | else | |
2707 | json_object_boolean_true_add( | |
2708 | json_area, | |
2709 | "nssaTranslatorNever"); | |
2710 | } | |
2711 | } else { | |
2712 | vty_out(vty, | |
2713 | " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n"); | |
2714 | if (!IS_OSPF_ABR(area->ospf)) | |
2715 | vty_out(vty, | |
2716 | " It is not ABR, therefore not Translator. \n"); | |
2717 | else if (area->NSSATranslatorState) { | |
2718 | vty_out(vty, " We are an ABR and "); | |
2719 | if (area->NSSATranslatorRole | |
2720 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2721 | vty_out(vty, | |
2722 | "the NSSA Elected Translator. \n"); | |
2723 | else if (area->NSSATranslatorRole | |
2724 | == OSPF_NSSA_ROLE_ALWAYS) | |
2725 | vty_out(vty, | |
2726 | "always an NSSA Translator. \n"); | |
2727 | } else { | |
2728 | vty_out(vty, " We are an ABR, but "); | |
2729 | if (area->NSSATranslatorRole | |
2730 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2731 | vty_out(vty, | |
2732 | "not the NSSA Elected Translator. \n"); | |
2733 | else | |
2734 | vty_out(vty, | |
2735 | "never an NSSA Translator. \n"); | |
2736 | } | |
2737 | } | |
2738 | } | |
2739 | ||
2740 | /* Stub-router state for this area */ | |
2741 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2742 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2743 | ||
2744 | if (use_json) { | |
2745 | json_object_boolean_true_add( | |
2746 | json_area, "originStubMaxDistRouterLsa"); | |
2747 | if (CHECK_FLAG(area->stub_router_state, | |
2748 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2749 | json_object_boolean_true_add( | |
2750 | json_area, "indefiniteActiveAdmin"); | |
2751 | if (area->t_stub_router) { | |
2752 | long time_store; | |
2753 | time_store = | |
2754 | monotime_until( | |
2755 | &area->t_stub_router->u.sands, | |
2756 | NULL) | |
2757 | / 1000LL; | |
2758 | json_object_int_add( | |
2759 | json_area, | |
2760 | "activeStartupRemainderMsecs", | |
2761 | time_store); | |
2762 | } | |
2763 | } else { | |
2764 | vty_out(vty, | |
2765 | " Originating stub / maximum-distance Router-LSA\n"); | |
2766 | if (CHECK_FLAG(area->stub_router_state, | |
2767 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2768 | vty_out(vty, | |
2769 | " Administratively activated (indefinitely)\n"); | |
2770 | if (area->t_stub_router) | |
2771 | vty_out(vty, | |
2772 | " Active from startup, %s remaining\n", | |
2773 | ospf_timer_dump(area->t_stub_router, | |
2774 | timebuf, | |
2775 | sizeof(timebuf))); | |
2776 | } | |
2777 | } | |
2778 | ||
2779 | if (use_json) { | |
2780 | /* Show number of fully adjacent neighbors. */ | |
2781 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2782 | area->full_nbrs); | |
2783 | ||
2784 | /* Show authentication type. */ | |
2785 | if (area->auth_type == OSPF_AUTH_NULL) | |
2786 | json_object_string_add(json_area, "authentication", | |
2787 | "authenticationNone"); | |
2788 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2789 | json_object_string_add(json_area, "authentication", | |
2790 | "authenticationSimplePassword"); | |
2791 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2792 | json_object_string_add(json_area, "authentication", | |
2793 | "authenticationMessageDigest"); | |
2794 | ||
2795 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2796 | json_object_int_add(json_area, | |
2797 | "virtualAdjacenciesPassingCounter", | |
2798 | area->full_vls); | |
2799 | ||
2800 | /* Show SPF calculation times. */ | |
2801 | json_object_int_add(json_area, "spfExecutedCounter", | |
2802 | area->spf_calculation); | |
2803 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2804 | json_object_int_add( | |
2805 | json_area, "lsaRouterNumber", | |
2806 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2807 | json_object_int_add( | |
2808 | json_area, "lsaRouterChecksum", | |
2809 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2810 | json_object_int_add( | |
2811 | json_area, "lsaNetworkNumber", | |
2812 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2813 | json_object_int_add( | |
2814 | json_area, "lsaNetworkChecksum", | |
2815 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2816 | json_object_int_add( | |
2817 | json_area, "lsaSummaryNumber", | |
2818 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2819 | json_object_int_add( | |
2820 | json_area, "lsaSummaryChecksum", | |
2821 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2822 | json_object_int_add( | |
2823 | json_area, "lsaAsbrNumber", | |
2824 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2825 | json_object_int_add( | |
2826 | json_area, "lsaAsbrChecksum", | |
2827 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2828 | json_object_int_add( | |
2829 | json_area, "lsaNssaNumber", | |
2830 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2831 | json_object_int_add( | |
2832 | json_area, "lsaNssaChecksum", | |
2833 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2834 | } else { | |
2835 | /* Show number of fully adjacent neighbors. */ | |
2836 | vty_out(vty, | |
2837 | " Number of fully adjacent neighbors in this area:" | |
2838 | " %d\n", | |
2839 | area->full_nbrs); | |
2840 | ||
2841 | /* Show authentication type. */ | |
2842 | vty_out(vty, " Area has "); | |
2843 | if (area->auth_type == OSPF_AUTH_NULL) | |
2844 | vty_out(vty, "no authentication\n"); | |
2845 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2846 | vty_out(vty, "simple password authentication\n"); | |
2847 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2848 | vty_out(vty, "message digest authentication\n"); | |
2849 | ||
2850 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2851 | vty_out(vty, | |
2852 | " Number of full virtual adjacencies going through" | |
2853 | " this area: %d\n", | |
2854 | area->full_vls); | |
2855 | ||
2856 | /* Show SPF calculation times. */ | |
2857 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2858 | area->spf_calculation); | |
2859 | ||
2860 | /* Show number of LSA. */ | |
2861 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2862 | vty_out(vty, | |
2863 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2864 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2865 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2866 | vty_out(vty, | |
2867 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2868 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2869 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2870 | vty_out(vty, | |
2871 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2872 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2873 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2874 | vty_out(vty, | |
2875 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2876 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
2877 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2878 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
2879 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
2880 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2881 | } | |
2882 | ||
2883 | if (use_json) { | |
2884 | json_object_int_add( | |
2885 | json_area, "lsaOpaqueLinkNumber", | |
2886 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2887 | json_object_int_add( | |
2888 | json_area, "lsaOpaqueLinkChecksum", | |
2889 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2890 | json_object_int_add( | |
2891 | json_area, "lsaOpaqueAreaNumber", | |
2892 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2893 | json_object_int_add( | |
2894 | json_area, "lsaOpaqueAreaChecksum", | |
2895 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2896 | } else { | |
2897 | vty_out(vty, | |
2898 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
2899 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
2900 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2901 | vty_out(vty, | |
2902 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
2903 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
2904 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2905 | } | |
718e3744 | 2906 | |
d62a17ae | 2907 | if (use_json) |
2908 | json_object_object_add(json_areas, inet_ntoa(area->area_id), | |
2909 | json_area); | |
2910 | else | |
2911 | vty_out(vty, "\n"); | |
718e3744 | 2912 | } |
2913 | ||
d62a17ae | 2914 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
b1c3ae8c | 2915 | json_object *json, u_char use_vrf) |
d62a17ae | 2916 | { |
2917 | struct listnode *node, *nnode; | |
2918 | struct ospf_area *area; | |
2919 | struct timeval result; | |
2920 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
b1c3ae8c | 2921 | json_object *json_vrf = NULL; |
d62a17ae | 2922 | json_object *json_areas = NULL; |
718e3744 | 2923 | |
b1c3ae8c CS |
2924 | if (json) { |
2925 | if (use_vrf) | |
2926 | json_vrf = json_object_new_object(); | |
2927 | else | |
2928 | json_vrf = json; | |
d62a17ae | 2929 | json_areas = json_object_new_object(); |
2930 | } | |
2931 | ||
2932 | if (ospf->instance) { | |
b1c3ae8c | 2933 | if (json) { |
d62a17ae | 2934 | json_object_int_add(json, "ospfInstance", |
2935 | ospf->instance); | |
2936 | } else { | |
2937 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
2938 | } | |
2939 | } | |
2940 | ||
b1c3ae8c | 2941 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 2942 | |
d62a17ae | 2943 | /* Show Router ID. */ |
b1c3ae8c CS |
2944 | if (json) { |
2945 | json_object_string_add(json_vrf, "routerId", | |
d62a17ae | 2946 | inet_ntoa(ospf->router_id)); |
2947 | } else { | |
2948 | vty_out(vty, " OSPF Routing Process, Router ID: %s\n", | |
2949 | inet_ntoa(ospf->router_id)); | |
2950 | } | |
2951 | ||
2952 | /* Graceful shutdown */ | |
2953 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 2954 | if (json) { |
d62a17ae | 2955 | long time_store; |
2956 | time_store = | |
2957 | monotime_until( | |
2958 | &ospf->t_deferred_shutdown->u.sands, | |
2959 | NULL) | |
2960 | / 1000LL; | |
b1c3ae8c | 2961 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 2962 | time_store); |
2963 | } else { | |
2964 | vty_out(vty, | |
2965 | " Deferred shutdown in progress, %s remaining\n", | |
2966 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
2967 | timebuf, sizeof(timebuf))); | |
2968 | } | |
2969 | } | |
2970 | ||
2971 | /* Show capability. */ | |
b1c3ae8c CS |
2972 | if (json) { |
2973 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
2974 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 2975 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 2976 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 2977 | "rfc1583Compatibility"); |
2978 | } | |
2979 | } else { | |
2980 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
2981 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
2982 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
2983 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
2984 | ? "enabled" | |
2985 | : "disabled"); | |
2986 | } | |
2987 | ||
b1c3ae8c | 2988 | if (json) { |
d62a17ae | 2989 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 2990 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 2991 | } |
2992 | } else { | |
2993 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
2994 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
2995 | ? "enabled" | |
2996 | : "disabled"); | |
2997 | } | |
2998 | ||
2999 | /* Show stub-router configuration */ | |
3000 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3001 | || ospf->stub_router_shutdown_time | |
3002 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3003 | if (json) { |
3004 | json_object_boolean_true_add(json_vrf, | |
3005 | "stubAdvertisement"); | |
d62a17ae | 3006 | if (ospf->stub_router_startup_time |
3007 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3008 | json_object_int_add( | |
b1c3ae8c | 3009 | json_vrf, "postStartEnabledMsecs", |
d62a17ae | 3010 | ospf->stub_router_startup_time / 1000); |
3011 | if (ospf->stub_router_shutdown_time | |
3012 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3013 | json_object_int_add( | |
b1c3ae8c | 3014 | json_vrf, "preShutdownEnabledMsecs", |
d62a17ae | 3015 | ospf->stub_router_shutdown_time / 1000); |
3016 | } else { | |
3017 | vty_out(vty, | |
3018 | " Stub router advertisement is configured\n"); | |
3019 | if (ospf->stub_router_startup_time | |
3020 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3021 | vty_out(vty, | |
3022 | " Enabled for %us after start-up\n", | |
3023 | ospf->stub_router_startup_time); | |
3024 | if (ospf->stub_router_shutdown_time | |
3025 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3026 | vty_out(vty, | |
3027 | " Enabled for %us prior to full shutdown\n", | |
3028 | ospf->stub_router_shutdown_time); | |
3029 | } | |
3030 | } | |
3031 | ||
3032 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3033 | if (json) { |
3034 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3035 | ospf->spf_delay); |
b1c3ae8c | 3036 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3037 | ospf->spf_holdtime); |
b1c3ae8c | 3038 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3039 | ospf->spf_max_holdtime); |
b1c3ae8c | 3040 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3041 | ospf->spf_hold_multiplier); |
3042 | } else { | |
3043 | vty_out(vty, | |
3044 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3045 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3046 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3047 | " Hold time multiplier is currently %d\n", | |
3048 | ospf->spf_delay, ospf->spf_holdtime, | |
3049 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3050 | } | |
3051 | ||
b1c3ae8c | 3052 | if (json) { |
d62a17ae | 3053 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3054 | long time_store = 0; | |
3055 | ||
3056 | time_store = | |
3057 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3058 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3059 | time_store); |
3060 | ||
3061 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3062 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3063 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3064 | time_store); |
3065 | } else | |
b1c3ae8c | 3066 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3067 | } else { |
3068 | vty_out(vty, " SPF algorithm "); | |
3069 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3070 | monotime_since(&ospf->ts_spf, &result); | |
3071 | vty_out(vty, "last executed %s ago\n", | |
3072 | ospf_timeval_dump(&result, timebuf, | |
3073 | sizeof(timebuf))); | |
3074 | vty_out(vty, " Last SPF duration %s\n", | |
3075 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3076 | timebuf, sizeof(timebuf))); | |
3077 | } else | |
3078 | vty_out(vty, "has not been run\n"); | |
3079 | } | |
3080 | ||
b1c3ae8c | 3081 | if (json) { |
d62a17ae | 3082 | if (ospf->t_spf_calc) { |
3083 | long time_store; | |
3084 | time_store = | |
3085 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3086 | / 1000LL; | |
b1c3ae8c | 3087 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3088 | time_store); |
3089 | } | |
3090 | ||
b1c3ae8c | 3091 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3092 | ospf->min_ls_interval); |
b1c3ae8c | 3093 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3094 | ospf->min_ls_arrival); |
3095 | /* Show write multiplier values */ | |
b1c3ae8c | 3096 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3097 | ospf->write_oi_count); |
3098 | /* Show refresh parameters. */ | |
b1c3ae8c | 3099 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3100 | ospf->lsa_refresh_interval * 1000); |
3101 | } else { | |
3102 | vty_out(vty, " SPF timer %s%s\n", | |
3103 | (ospf->t_spf_calc ? "due in " : "is "), | |
3104 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3105 | sizeof(timebuf))); | |
3106 | ||
3107 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3108 | ospf->min_ls_interval); | |
3109 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3110 | ospf->min_ls_arrival); | |
3111 | ||
3112 | /* Show write multiplier values */ | |
3113 | vty_out(vty, " Write Multiplier set to %d \n", | |
3114 | ospf->write_oi_count); | |
3115 | ||
3116 | /* Show refresh parameters. */ | |
3117 | vty_out(vty, " Refresh timer %d secs\n", | |
3118 | ospf->lsa_refresh_interval); | |
3119 | } | |
3120 | ||
3121 | /* Show ABR/ASBR flags. */ | |
3122 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3123 | if (json) |
d62a17ae | 3124 | json_object_string_add( |
b1c3ae8c | 3125 | json_vrf, "abrType", |
d62a17ae | 3126 | ospf_abr_type_descr_str[ospf->abr_type]); |
3127 | else | |
3128 | vty_out(vty, | |
3129 | " This router is an ABR, ABR type is: %s\n", | |
3130 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3131 | } | |
3132 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3133 | if (json) |
d62a17ae | 3134 | json_object_string_add( |
b1c3ae8c | 3135 | json_vrf, "asbrRouter", |
d62a17ae | 3136 | "injectingExternalRoutingInformation"); |
3137 | else | |
3138 | vty_out(vty, | |
3139 | " This router is an ASBR " | |
3140 | "(injecting external routing information)\n"); | |
3141 | } | |
3142 | ||
3143 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3144 | if (json) { |
d62a17ae | 3145 | json_object_int_add( |
b1c3ae8c | 3146 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3147 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3148 | json_object_int_add( | |
b1c3ae8c | 3149 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3150 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3151 | } else { | |
3152 | vty_out(vty, | |
3153 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3154 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3155 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3156 | } | |
3157 | ||
b1c3ae8c | 3158 | if (json) { |
d62a17ae | 3159 | json_object_int_add( |
b1c3ae8c | 3160 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3161 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3162 | json_object_int_add( | |
b1c3ae8c | 3163 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3164 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3165 | } else { | |
3166 | vty_out(vty, | |
3167 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3168 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3169 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3170 | } | |
3171 | ||
3172 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3173 | if (json) |
3174 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3175 | listcount(ospf->areas)); |
3176 | else | |
3177 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3178 | listcount(ospf->areas)); | |
3179 | ||
3180 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3181 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3182 | if (json) |
d62a17ae | 3183 | json_object_boolean_true_add( |
b1c3ae8c | 3184 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3185 | else |
3186 | vty_out(vty, | |
3187 | " All adjacency changes are logged\n"); | |
3188 | } else { | |
b1c3ae8c | 3189 | if (json) |
d62a17ae | 3190 | json_object_boolean_true_add( |
b1c3ae8c | 3191 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3192 | else |
3193 | vty_out(vty, " Adjacency changes are logged\n"); | |
3194 | } | |
3195 | } | |
3196 | /* Show each area status. */ | |
3197 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3198 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3199 | ||
3200 | if (json) { | |
3201 | if (use_vrf) { | |
3202 | json_object_object_add(json_vrf, "areas", json_areas); | |
3203 | if (ospf->vrf_id == VRF_DEFAULT) | |
3204 | json_object_object_add(json, "default", | |
3205 | json_vrf); | |
3206 | else | |
3207 | json_object_object_add(json, ospf->name, | |
3208 | json_vrf); | |
3209 | } else { | |
3210 | json_object_object_add(json, "areas", json_areas); | |
3211 | } | |
d62a17ae | 3212 | } else |
3213 | vty_out(vty, "\n"); | |
3214 | ||
3215 | return CMD_SUCCESS; | |
718e3744 | 3216 | } |
3217 | ||
7c8ff89e DS |
3218 | DEFUN (show_ip_ospf, |
3219 | show_ip_ospf_cmd, | |
b5a8894d | 3220 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3221 | SHOW_STR |
3222 | IP_STR | |
ca08c43d | 3223 | "OSPF information\n" |
b5a8894d CS |
3224 | VRF_CMD_HELP_STR |
3225 | "All VRFs\n" | |
9973d184 | 3226 | JSON_STR) |
7c8ff89e | 3227 | { |
d62a17ae | 3228 | struct ospf *ospf; |
3229 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
3230 | struct listnode *node = NULL; |
3231 | char *vrf_name = NULL; | |
3232 | bool all_vrf = FALSE; | |
3233 | int ret = CMD_SUCCESS; | |
3234 | int inst = 0; | |
3235 | int idx_vrf = 0; | |
b1c3ae8c CS |
3236 | json_object *json = NULL; |
3237 | u_char use_vrf = 0; | |
7c8ff89e | 3238 | |
b5a8894d | 3239 | if (listcount(om->ospf) == 0) |
d62a17ae | 3240 | return CMD_SUCCESS; |
7c8ff89e | 3241 | |
43b8d1d8 | 3242 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3243 | |
b1c3ae8c CS |
3244 | if (uj) |
3245 | json = json_object_new_object(); | |
3246 | ||
b5a8894d CS |
3247 | /* vrf input is provided could be all or specific vrf*/ |
3248 | if (vrf_name) { | |
b1c3ae8c | 3249 | use_vrf = 1; |
b5a8894d CS |
3250 | if (all_vrf) { |
3251 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3252 | if (!ospf->oi_running) | |
3253 | continue; | |
b1c3ae8c CS |
3254 | ret = show_ip_ospf_common(vty, ospf, json, |
3255 | use_vrf); | |
3256 | } | |
3257 | if (uj) { | |
3258 | vty_out(vty, "%s\n", | |
3259 | json_object_to_json_string_ext(json, | |
3260 | JSON_C_TO_STRING_PRETTY)); | |
3261 | json_object_free(json); | |
b5a8894d CS |
3262 | } |
3263 | return ret; | |
3264 | } | |
3265 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
3266 | if ((ospf == NULL) || !ospf->oi_running) { |
3267 | if (uj) | |
3268 | json_object_free(json); | |
b5a8894d | 3269 | return CMD_SUCCESS; |
b1c3ae8c | 3270 | } |
b5a8894d CS |
3271 | } else { |
3272 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3273 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c CS |
3274 | if (ospf == NULL || !ospf->oi_running) { |
3275 | if (uj) | |
3276 | json_object_free(json); | |
b5a8894d | 3277 | return CMD_SUCCESS; |
b1c3ae8c | 3278 | } |
b5a8894d CS |
3279 | } |
3280 | ||
b1c3ae8c CS |
3281 | if (ospf) { |
3282 | show_ip_ospf_common(vty, ospf, json, use_vrf); | |
3283 | if (uj) | |
3284 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3285 | json, JSON_C_TO_STRING_PRETTY)); | |
3286 | } | |
3287 | ||
3288 | if (uj) | |
3289 | json_object_free(json); | |
b5a8894d CS |
3290 | |
3291 | return ret; | |
7c8ff89e DS |
3292 | } |
3293 | ||
3294 | DEFUN (show_ip_ospf_instance, | |
3295 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3296 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3297 | SHOW_STR |
3298 | IP_STR | |
3299 | "OSPF information\n" | |
ca08c43d | 3300 | "Instance ID\n" |
9973d184 | 3301 | JSON_STR) |
7c8ff89e | 3302 | { |
d62a17ae | 3303 | int idx_number = 3; |
3304 | struct ospf *ospf; | |
3305 | u_short instance = 0; | |
3306 | u_char uj = use_json(argc, argv); | |
b1c3ae8c CS |
3307 | int ret = CMD_SUCCESS; |
3308 | json_object *json = NULL; | |
d62a17ae | 3309 | |
3310 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3311 | ospf = ospf_lookup_instance(instance); |
3312 | if (ospf == NULL) | |
3313 | return CMD_NOT_MY_INSTANCE; | |
3314 | ||
3315 | if (!ospf->oi_running) | |
d62a17ae | 3316 | return CMD_SUCCESS; |
3317 | ||
b1c3ae8c CS |
3318 | if (uj) |
3319 | json = json_object_new_object(); | |
3320 | ||
3321 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3322 | ||
3323 | if (uj) { | |
3324 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
3325 | JSON_C_TO_STRING_PRETTY)); | |
3326 | json_object_free(json); | |
3327 | } | |
3328 | ||
3329 | return ret; | |
d62a17ae | 3330 | } |
3331 | ||
3332 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, | |
3333 | struct interface *ifp, | |
3334 | json_object *json_interface_sub, | |
3335 | u_char use_json) | |
3336 | { | |
3337 | int is_up; | |
3338 | struct ospf_neighbor *nbr; | |
3339 | struct route_node *rn; | |
3340 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; | |
3341 | ||
3342 | /* Is interface up? */ | |
3343 | if (use_json) { | |
3344 | is_up = if_is_operative(ifp); | |
3345 | if (is_up) | |
3346 | json_object_boolean_true_add(json_interface_sub, | |
3347 | "ifUp"); | |
3348 | else | |
3349 | json_object_boolean_false_add(json_interface_sub, | |
3350 | "ifDown"); | |
3351 | ||
3352 | json_object_int_add(json_interface_sub, "ifIndex", | |
3353 | ifp->ifindex); | |
3354 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3355 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3356 | bandwidth); | |
3357 | json_object_string_add(json_interface_sub, "ifFlags", | |
3358 | if_flag_dump(ifp->flags)); | |
3359 | } else { | |
3360 | vty_out(vty, "%s is %s\n", ifp->name, | |
3361 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3362 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3363 | ifp->ifindex, ifp->mtu, bandwidth, | |
3364 | if_flag_dump(ifp->flags)); | |
3365 | } | |
7c8ff89e | 3366 | |
d62a17ae | 3367 | /* Is interface OSPF enabled? */ |
3368 | if (use_json) { | |
3369 | if (ospf_oi_count(ifp) == 0) { | |
3370 | json_object_boolean_false_add(json_interface_sub, | |
3371 | "ospfEnabled"); | |
3372 | return; | |
3373 | } else if (!is_up) { | |
3374 | json_object_boolean_false_add(json_interface_sub, | |
3375 | "ospfRunning"); | |
3376 | return; | |
3377 | } else | |
3378 | json_object_boolean_true_add(json_interface_sub, | |
3379 | "ospfEnabled"); | |
3380 | } else { | |
3381 | if (ospf_oi_count(ifp) == 0) { | |
3382 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3383 | return; | |
3384 | } else if (!is_up) { | |
3385 | vty_out(vty, | |
3386 | " OSPF is enabled, but not running on this interface\n"); | |
3387 | return; | |
3388 | } | |
3389 | } | |
3390 | ||
3391 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3392 | struct ospf_interface *oi = rn->info; | |
3393 | ||
3394 | if (oi == NULL) | |
3395 | continue; | |
3396 | ||
3397 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3398 | if (use_json) | |
3399 | json_object_boolean_true_add(json_interface_sub, | |
3400 | "ifUnnumbered"); | |
3401 | else | |
3402 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3403 | } else { | |
3404 | /* Show OSPF interface information. */ | |
3405 | if (use_json) { | |
3406 | json_object_string_add( | |
3407 | json_interface_sub, "ipAddress", | |
3408 | inet_ntoa(oi->address->u.prefix4)); | |
3409 | json_object_int_add(json_interface_sub, | |
3410 | "ipAddressPrefixlen", | |
3411 | oi->address->prefixlen); | |
3412 | } else | |
3413 | vty_out(vty, " Internet Address %s/%d,", | |
3414 | inet_ntoa(oi->address->u.prefix4), | |
3415 | oi->address->prefixlen); | |
3416 | ||
3417 | if (oi->connected->destination | |
3418 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3419 | struct in_addr *dest; | |
3420 | const char *dstr; | |
3421 | ||
3422 | if (CONNECTED_PEER(oi->connected) | |
3423 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3424 | dstr = "Peer"; | |
3425 | else | |
3426 | dstr = "Broadcast"; | |
3427 | ||
3428 | /* For Vlinks, showing the peer address is | |
9d303b37 DL |
3429 | * probably more |
3430 | * * * * * informative than the local | |
3431 | * interface that is being used | |
3432 | * * * * */ | |
d62a17ae | 3433 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
3434 | dest = &oi->vl_data->peer_addr; | |
3435 | else | |
3436 | dest = &oi->connected->destination->u | |
3437 | .prefix4; | |
3438 | ||
3439 | if (use_json) { | |
3440 | json_object_string_add( | |
3441 | json_interface_sub, | |
3442 | "ospfIfType", dstr); | |
3443 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3444 | json_object_string_add( | |
3445 | json_interface_sub, | |
3446 | "vlinkPeer", | |
3447 | inet_ntoa(*dest)); | |
3448 | else | |
3449 | json_object_string_add( | |
3450 | json_interface_sub, | |
3451 | "localIfUsed", | |
3452 | inet_ntoa(*dest)); | |
3453 | } else | |
3454 | vty_out(vty, " %s %s,", dstr, | |
3455 | inet_ntoa(*dest)); | |
3456 | } | |
3457 | } | |
3458 | if (use_json) { | |
3459 | json_object_string_add(json_interface_sub, "area", | |
3460 | ospf_area_desc_string(oi->area)); | |
3461 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3462 | json_object_boolean_true_add( | |
3463 | json_interface_sub, | |
3464 | "mtuMismatchDetect"); | |
3465 | json_object_string_add(json_interface_sub, "routerId", | |
3466 | inet_ntoa(ospf->router_id)); | |
3467 | json_object_string_add(json_interface_sub, | |
3468 | "networkType", | |
3469 | ospf_network_type_str[oi->type]); | |
3470 | json_object_int_add(json_interface_sub, "cost", | |
3471 | oi->output_cost); | |
3472 | json_object_int_add( | |
3473 | json_interface_sub, "transmitDelayMsecs", | |
3474 | 1000 / OSPF_IF_PARAM(oi, transmit_delay)); | |
3475 | json_object_string_add(json_interface_sub, "state", | |
3476 | lookup_msg(ospf_ism_state_msg, | |
3477 | oi->state, NULL)); | |
3478 | json_object_int_add(json_interface_sub, "priority", | |
3479 | PRIORITY(oi)); | |
3480 | } else { | |
3481 | vty_out(vty, " Area %s\n", | |
3482 | ospf_area_desc_string(oi->area)); | |
3483 | ||
3484 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3485 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3486 | : "enabled"); | |
3487 | ||
3488 | vty_out(vty, | |
3489 | " Router ID %s, Network Type %s, Cost: %d\n", | |
3490 | inet_ntoa(ospf->router_id), | |
3491 | ospf_network_type_str[oi->type], | |
3492 | oi->output_cost); | |
3493 | ||
3494 | vty_out(vty, | |
3495 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3496 | OSPF_IF_PARAM(oi, transmit_delay), | |
3497 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3498 | PRIORITY(oi)); | |
3499 | } | |
3500 | ||
3501 | /* Show DR information. */ | |
3502 | if (DR(oi).s_addr == 0) { | |
3503 | if (!use_json) | |
3504 | vty_out(vty, | |
3505 | " No backup designated router on this network\n"); | |
3506 | } else { | |
3507 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3508 | if (nbr == NULL) { | |
3509 | if (!use_json) | |
3510 | vty_out(vty, | |
3511 | " No backup designated router on this network\n"); | |
3512 | } else { | |
3513 | if (use_json) { | |
3514 | json_object_string_add( | |
3515 | json_interface_sub, "bdrId", | |
3516 | inet_ntoa(nbr->router_id)); | |
3517 | json_object_string_add( | |
3518 | json_interface_sub, | |
3519 | "bdrAddress", | |
3520 | inet_ntoa(nbr->address.u | |
3521 | .prefix4)); | |
3522 | } else { | |
3523 | vty_out(vty, | |
3524 | " Backup Designated Router (ID) %s,", | |
3525 | inet_ntoa(nbr->router_id)); | |
3526 | vty_out(vty, " Interface Address %s\n", | |
3527 | inet_ntoa(nbr->address.u | |
3528 | .prefix4)); | |
3529 | } | |
3530 | } | |
3531 | } | |
3532 | ||
3533 | /* Next network-LSA sequence number we'll use, if we're elected | |
3534 | * DR */ | |
3535 | if (oi->params | |
3536 | && ntohl(oi->params->network_lsa_seqnum) | |
3537 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3538 | if (use_json) | |
3539 | json_object_int_add( | |
3540 | json_interface_sub, | |
3541 | "networkLsaSequence", | |
3542 | ntohl(oi->params->network_lsa_seqnum)); | |
3543 | else | |
3544 | vty_out(vty, | |
3545 | " Saved Network-LSA sequence number 0x%x\n", | |
3546 | ntohl(oi->params->network_lsa_seqnum)); | |
3547 | } | |
3548 | ||
3549 | if (use_json) { | |
3550 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3551 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3552 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3553 | json_object_boolean_true_add( | |
3554 | json_interface_sub, | |
3555 | "mcastMemberOspfAllRouters"); | |
3556 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3557 | json_object_boolean_true_add( | |
3558 | json_interface_sub, | |
3559 | "mcastMemberOspfDesignatedRouters"); | |
3560 | } | |
3561 | } else { | |
3562 | vty_out(vty, " Multicast group memberships:"); | |
3563 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3564 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3565 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3566 | vty_out(vty, " OSPFAllRouters"); | |
3567 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3568 | vty_out(vty, " OSPFDesignatedRouters"); | |
3569 | } else | |
3570 | vty_out(vty, " <None>"); | |
3571 | vty_out(vty, "\n"); | |
3572 | } | |
3573 | ||
3574 | if (use_json) { | |
3575 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3576 | json_object_int_add( | |
3577 | json_interface_sub, "timerMsecs", | |
3578 | 1000 / OSPF_IF_PARAM(oi, v_hello)); | |
3579 | else | |
3580 | json_object_int_add( | |
3581 | json_interface_sub, "timerMsecs", | |
3582 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3583 | json_object_int_add(json_interface_sub, | |
3584 | "timerDeadMsecs", | |
3585 | 1000 / OSPF_IF_PARAM(oi, v_wait)); | |
3586 | json_object_int_add(json_interface_sub, | |
3587 | "timerWaitMsecs", | |
3588 | 1000 / OSPF_IF_PARAM(oi, v_wait)); | |
3589 | json_object_int_add( | |
3590 | json_interface_sub, "timerRetransmit", | |
3591 | 1000 / OSPF_IF_PARAM(oi, retransmit_interval)); | |
3592 | } else { | |
3593 | vty_out(vty, " Timer intervals configured,"); | |
3594 | vty_out(vty, " Hello "); | |
3595 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3596 | vty_out(vty, "%ds,", | |
3597 | OSPF_IF_PARAM(oi, v_hello)); | |
3598 | else | |
3599 | vty_out(vty, "%dms,", | |
3600 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3601 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3602 | OSPF_IF_PARAM(oi, v_wait), | |
3603 | OSPF_IF_PARAM(oi, v_wait), | |
3604 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3605 | } | |
3606 | ||
3607 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3608 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3609 | if (use_json) { | |
3610 | long time_store = 0; | |
3611 | if (oi->t_hello) | |
3612 | time_store = | |
3613 | monotime_until( | |
3614 | &oi->t_hello->u.sands, | |
3615 | NULL) | |
3616 | / 1000LL; | |
3617 | json_object_int_add(json_interface_sub, | |
3618 | "timerHelloInMsecs", | |
3619 | time_store); | |
3620 | } else | |
3621 | vty_out(vty, " Hello due in %s\n", | |
3622 | ospf_timer_dump(oi->t_hello, timebuf, | |
3623 | sizeof(timebuf))); | |
3624 | } else /* passive-interface is set */ | |
3625 | { | |
3626 | if (use_json) | |
3627 | json_object_boolean_true_add( | |
3628 | json_interface_sub, | |
3629 | "timerPassiveIface"); | |
3630 | else | |
3631 | vty_out(vty, | |
3632 | " No Hellos (Passive interface)\n"); | |
3633 | } | |
7c8ff89e | 3634 | |
d62a17ae | 3635 | if (use_json) { |
3636 | json_object_int_add(json_interface_sub, "nbrCount", | |
3637 | ospf_nbr_count(oi, 0)); | |
3638 | json_object_int_add(json_interface_sub, | |
3639 | "nbrAdjacentCount", | |
3640 | ospf_nbr_count(oi, NSM_Full)); | |
3641 | } else | |
3642 | vty_out(vty, | |
3643 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3644 | ospf_nbr_count(oi, 0), | |
3645 | ospf_nbr_count(oi, NSM_Full)); | |
3646 | ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json); | |
3647 | } | |
718e3744 | 3648 | } |
3649 | ||
d62a17ae | 3650 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
b1c3ae8c CS |
3651 | char *intf_name, u_char use_vrf, |
3652 | json_object *json, u_char use_json) | |
d62a17ae | 3653 | { |
3654 | struct interface *ifp; | |
f4e14fdb | 3655 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
b1c3ae8c | 3656 | json_object *json_vrf = NULL; |
d62a17ae | 3657 | json_object *json_interface_sub = NULL; |
7c8ff89e | 3658 | |
d62a17ae | 3659 | if (use_json) { |
b1c3ae8c CS |
3660 | if (use_vrf) |
3661 | json_vrf = json_object_new_object(); | |
3662 | else | |
3663 | json_vrf = json; | |
d62a17ae | 3664 | } |
3665 | ||
3666 | if (ospf->instance) { | |
3667 | if (use_json) | |
3668 | json_object_int_add(json, "ospfInstance", | |
3669 | ospf->instance); | |
3670 | else | |
3671 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3672 | } | |
3673 | ||
b1c3ae8c CS |
3674 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3675 | ||
3676 | if (intf_name == NULL) { | |
d62a17ae | 3677 | /* Show All Interfaces.*/ |
451fda4f | 3678 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3679 | if (ospf_oi_count(ifp)) { |
3680 | if (use_json) | |
3681 | json_interface_sub = | |
3682 | json_object_new_object(); | |
3683 | ||
3684 | show_ip_ospf_interface_sub(vty, ospf, ifp, | |
3685 | json_interface_sub, | |
3686 | use_json); | |
3687 | ||
3688 | if (use_json) | |
3689 | json_object_object_add( | |
b1c3ae8c | 3690 | json_vrf, ifp->name, |
d62a17ae | 3691 | json_interface_sub); |
3692 | } | |
3693 | } | |
3694 | } else { | |
3695 | /* Interface name is specified. */ | |
b1c3ae8c CS |
3696 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
3697 | if (ifp == NULL) { | |
d62a17ae | 3698 | if (use_json) |
b1c3ae8c | 3699 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3700 | "noSuchIface"); |
3701 | else | |
3702 | vty_out(vty, "No such interface name\n"); | |
3703 | } else { | |
3704 | if (use_json) | |
3705 | json_interface_sub = json_object_new_object(); | |
3706 | ||
3707 | show_ip_ospf_interface_sub( | |
3708 | vty, ospf, ifp, json_interface_sub, use_json); | |
3709 | ||
3710 | if (use_json) | |
b1c3ae8c | 3711 | json_object_object_add(json_vrf, ifp->name, |
d62a17ae | 3712 | json_interface_sub); |
3713 | } | |
3714 | } | |
3715 | ||
3716 | if (use_json) { | |
b1c3ae8c CS |
3717 | if (use_vrf) { |
3718 | if (ospf->vrf_id == VRF_DEFAULT) | |
3719 | json_object_object_add(json, "default", | |
3720 | json_vrf); | |
3721 | else | |
3722 | json_object_object_add(json, ospf->name, | |
3723 | json_vrf); | |
3724 | } | |
d62a17ae | 3725 | } else |
3726 | vty_out(vty, "\n"); | |
3727 | ||
3728 | return CMD_SUCCESS; | |
718e3744 | 3729 | } |
3730 | ||
c9339663 CS |
3731 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3732 | struct ospf_interface *oi, | |
3733 | json_object *json_interface_sub, | |
3734 | u_char use_json) | |
3735 | { | |
3736 | if (use_json) { | |
3737 | json_object_int_add(json_interface_sub, | |
3738 | "ifIndex", | |
3739 | oi->ifp->ifindex); | |
3740 | json_object_int_add(json_interface_sub, | |
3741 | "helloIn", | |
3742 | oi->hello_in); | |
3743 | json_object_int_add(json_interface_sub, | |
3744 | "helloOut", | |
3745 | oi->hello_out); | |
3746 | json_object_int_add(json_interface_sub, | |
3747 | "dbDescIn", | |
3748 | oi->db_desc_in); | |
3749 | json_object_int_add(json_interface_sub, | |
3750 | "dbDescOut", | |
3751 | oi->db_desc_out); | |
3752 | json_object_int_add(json_interface_sub, | |
3753 | "lsReqIn", | |
3754 | oi->ls_req_in); | |
3755 | json_object_int_add(json_interface_sub, | |
3756 | "lsReqOut", | |
3757 | oi->ls_req_out); | |
3758 | json_object_int_add(json_interface_sub, | |
3759 | "lsUpdIn", | |
3760 | oi->ls_upd_in); | |
3761 | json_object_int_add(json_interface_sub, | |
3762 | "lsUpdOut", | |
3763 | oi->ls_upd_out); | |
3764 | json_object_int_add(json_interface_sub, | |
3765 | "lsAckIn", | |
3766 | oi->ls_ack_in); | |
3767 | json_object_int_add(json_interface_sub, | |
3768 | "lsAckOut", | |
3769 | oi->ls_ack_out); | |
3770 | } else { | |
3771 | vty_out(vty, | |
3772 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
3773 | oi->ifp->name, oi->hello_in, | |
3774 | oi->hello_out, | |
3775 | oi->db_desc_in, oi->db_desc_out, | |
3776 | oi->ls_req_in, oi->ls_req_out, | |
3777 | oi->ls_upd_in, oi->ls_upd_out, | |
3778 | oi->ls_ack_in, oi->ls_ack_out); | |
3779 | } | |
3780 | } | |
3781 | ||
3782 | /* OSPFv2 Packet Counters */ | |
3783 | static int show_ip_ospf_interface_traffic_common(struct vty *vty, | |
3784 | struct ospf *ospf, | |
3785 | char *intf_name, | |
b1c3ae8c | 3786 | json_object *json, |
c9339663 | 3787 | int display_once, |
b1c3ae8c | 3788 | u_char use_vrf, |
c9339663 CS |
3789 | u_char use_json) |
3790 | { | |
3791 | struct vrf *vrf = NULL; | |
3792 | struct interface *ifp = NULL; | |
b1c3ae8c | 3793 | json_object *json_vrf = NULL; |
c9339663 CS |
3794 | json_object *json_interface_sub = NULL; |
3795 | ||
3796 | if (!use_json && !display_once) { | |
3797 | vty_out(vty, "\n"); | |
3798 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", | |
3799 | "Interface", " HELLO", " DB-Desc", " LS-Req", | |
3800 | " LS-Update", " LS-Ack"); | |
3801 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", | |
3802 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx"); | |
3803 | vty_out(vty, | |
3804 | "--------------------------------------------------------------------------------------------\n"); | |
3805 | } else if (use_json) { | |
b1c3ae8c CS |
3806 | if (use_vrf) |
3807 | json_vrf = json_object_new_object(); | |
3808 | else | |
3809 | json_vrf = json; | |
c9339663 CS |
3810 | } |
3811 | ||
b1c3ae8c CS |
3812 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3813 | ||
c9339663 CS |
3814 | if (intf_name == NULL) { |
3815 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
3816 | FOR_ALL_INTERFACES (vrf, ifp) { | |
3817 | struct route_node *rn; | |
3818 | struct ospf_interface *oi; | |
3819 | ||
3820 | if (ospf_oi_count(ifp) == 0) | |
3821 | continue; | |
3822 | ||
3823 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3824 | rn = route_next(rn)) { | |
3825 | oi = rn->info; | |
3826 | ||
3827 | if (oi == NULL) | |
3828 | continue; | |
3829 | ||
3830 | if (use_json) { | |
3831 | json_interface_sub = | |
3832 | json_object_new_object(); | |
3833 | } | |
3834 | ||
3835 | show_ip_ospf_interface_traffic_sub(vty, oi, | |
3836 | json_interface_sub, | |
3837 | use_json); | |
3838 | if (use_json) { | |
b1c3ae8c CS |
3839 | json_object_object_add(json_vrf, |
3840 | ifp->name, | |
3841 | json_interface_sub); | |
c9339663 CS |
3842 | } |
3843 | } | |
3844 | } | |
3845 | } else { | |
3846 | /* Interface name is specified. */ | |
3847 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); | |
3848 | if (ifp != NULL) { | |
3849 | struct route_node *rn; | |
3850 | struct ospf_interface *oi; | |
3851 | ||
3852 | if (ospf_oi_count(ifp) == 0) { | |
3853 | vty_out(vty, " OSPF not enabled on this interface %s\n", | |
3854 | ifp->name); | |
3855 | return CMD_SUCCESS; | |
3856 | } | |
3857 | ||
3858 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3859 | rn = route_next(rn)) { | |
3860 | oi = rn->info; | |
3861 | ||
3862 | if (use_json) { | |
3863 | json_interface_sub = | |
3864 | json_object_new_object(); | |
3865 | } | |
3866 | ||
3867 | show_ip_ospf_interface_traffic_sub(vty, oi, | |
3868 | json_interface_sub, | |
3869 | use_json); | |
3870 | if (use_json) { | |
b1c3ae8c CS |
3871 | json_object_object_add(json_vrf, |
3872 | ifp->name, | |
3873 | json_interface_sub); | |
c9339663 CS |
3874 | } |
3875 | } | |
3876 | } | |
3877 | } | |
3878 | ||
3879 | if (use_json) { | |
b1c3ae8c CS |
3880 | if (use_vrf) { |
3881 | if (ospf->vrf_id == VRF_DEFAULT) | |
3882 | json_object_object_add(json, "default", | |
3883 | json_vrf); | |
3884 | else | |
3885 | json_object_object_add(json, ospf->name, | |
3886 | json_vrf); | |
3887 | } | |
3888 | } else | |
3889 | vty_out(vty, "\n"); | |
c9339663 CS |
3890 | |
3891 | return CMD_SUCCESS; | |
3892 | } | |
3893 | ||
7c8ff89e DS |
3894 | DEFUN (show_ip_ospf_interface, |
3895 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 3896 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
3897 | SHOW_STR |
3898 | IP_STR | |
3899 | "OSPF information\n" | |
b5a8894d | 3900 | VRF_CMD_HELP_STR |
43b8d1d8 | 3901 | "All VRFs\n" |
7c8ff89e | 3902 | "Interface information\n" |
7ec4159b | 3903 | "Interface name\n" |
9973d184 | 3904 | JSON_STR) |
7c8ff89e | 3905 | { |
d62a17ae | 3906 | struct ospf *ospf; |
3907 | u_char uj = use_json(argc, argv); | |
b5a8894d | 3908 | struct listnode *node = NULL; |
b1c3ae8c | 3909 | char *vrf_name = NULL, *intf_name = NULL; |
b5a8894d CS |
3910 | bool all_vrf = FALSE; |
3911 | int ret = CMD_SUCCESS; | |
3912 | int inst = 0; | |
b1c3ae8c CS |
3913 | int idx_vrf = 0, idx_intf = 0; |
3914 | u_char use_vrf = 0; | |
3915 | json_object *json = NULL; | |
7c8ff89e | 3916 | |
43b8d1d8 CS |
3917 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
3918 | ||
b1c3ae8c CS |
3919 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
3920 | intf_name = argv[idx_intf]->arg; | |
3921 | ||
d62a17ae | 3922 | if (uj) |
b1c3ae8c | 3923 | json = json_object_new_object(); |
6be4da3d | 3924 | |
b5a8894d CS |
3925 | /* vrf input is provided could be all or specific vrf*/ |
3926 | if (vrf_name) { | |
b1c3ae8c | 3927 | use_vrf = 1; |
b5a8894d CS |
3928 | if (all_vrf) { |
3929 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3930 | if (!ospf->oi_running) | |
3931 | continue; | |
3932 | ret = show_ip_ospf_interface_common(vty, | |
b1c3ae8c CS |
3933 | ospf, |
3934 | intf_name, | |
3935 | use_vrf, | |
3936 | json, | |
b5a8894d CS |
3937 | uj); |
3938 | } | |
b1c3ae8c CS |
3939 | |
3940 | if (uj) { | |
3941 | vty_out(vty, "%s\n", | |
3942 | json_object_to_json_string_ext(json, | |
3943 | JSON_C_TO_STRING_PRETTY)); | |
3944 | json_object_free(json); | |
3945 | } | |
3946 | ||
b5a8894d CS |
3947 | return ret; |
3948 | } | |
3949 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
3950 | if (ospf == NULL || !ospf->oi_running) { |
3951 | if (uj) | |
3952 | json_object_free(json); | |
b5a8894d | 3953 | return CMD_SUCCESS; |
b1c3ae8c CS |
3954 | } |
3955 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
3956 | use_vrf, json, uj); | |
b5a8894d CS |
3957 | |
3958 | } else { | |
3959 | /* Display default ospf (instance 0) info */ | |
3960 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
3961 | if (ospf == NULL || !ospf->oi_running) { |
3962 | if (uj) | |
3963 | json_object_free(json); | |
b5a8894d | 3964 | return CMD_SUCCESS; |
b1c3ae8c CS |
3965 | } |
3966 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
3967 | use_vrf, json, uj); | |
3968 | } | |
3969 | ||
3970 | if (uj) { | |
3971 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
3972 | JSON_C_TO_STRING_PRETTY)); | |
3973 | json_object_free(json); | |
b5a8894d CS |
3974 | } |
3975 | ||
3976 | return ret; | |
7c8ff89e DS |
3977 | } |
3978 | ||
3979 | DEFUN (show_ip_ospf_instance_interface, | |
3980 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 3981 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
3982 | SHOW_STR |
3983 | IP_STR | |
3984 | "OSPF information\n" | |
3985 | "Instance ID\n" | |
3986 | "Interface information\n" | |
7ec4159b | 3987 | "Interface name\n" |
9973d184 | 3988 | JSON_STR) |
7c8ff89e | 3989 | { |
d62a17ae | 3990 | int idx_number = 3; |
b1c3ae8c | 3991 | int idx_intf = 0; |
d62a17ae | 3992 | struct ospf *ospf; |
3993 | u_short instance = 0; | |
3994 | u_char uj = use_json(argc, argv); | |
b1c3ae8c CS |
3995 | char *intf_name = NULL; |
3996 | int ret = CMD_SUCCESS; | |
3997 | json_object *json = NULL; | |
d62a17ae | 3998 | |
3999 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
4000 | ospf = ospf_lookup_instance(instance); |
4001 | if (ospf == NULL) | |
4002 | return CMD_NOT_MY_INSTANCE; | |
4003 | ||
4004 | if (!ospf->oi_running) | |
d62a17ae | 4005 | return CMD_SUCCESS; |
4006 | ||
4007 | if (uj) | |
b1c3ae8c CS |
4008 | json = json_object_new_object(); |
4009 | ||
4010 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4011 | intf_name = argv[idx_intf]->arg; | |
4012 | ||
4013 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4014 | ||
4015 | if (uj) { | |
4016 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
4017 | JSON_C_TO_STRING_PRETTY)); | |
4018 | json_object_free(json); | |
4019 | } | |
d62a17ae | 4020 | |
b1c3ae8c | 4021 | return ret; |
d62a17ae | 4022 | } |
4023 | ||
c9339663 CS |
4024 | DEFUN (show_ip_ospf_interface_traffic, |
4025 | show_ip_ospf_interface_traffic_cmd, | |
4026 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4027 | SHOW_STR | |
4028 | IP_STR | |
4029 | "OSPF information\n" | |
4030 | VRF_CMD_HELP_STR | |
4031 | "All VRFs\n" | |
4032 | "Interface information\n" | |
4033 | "Protocol Packet counters\n" | |
4034 | "Interface name\n" | |
4035 | JSON_STR) | |
4036 | { | |
4037 | struct ospf *ospf = NULL; | |
4038 | struct listnode *node = NULL; | |
4039 | char *vrf_name = NULL, *intf_name = NULL; | |
4040 | bool all_vrf = FALSE; | |
4041 | int inst = 0; | |
4042 | int idx_vrf = 0, idx_intf = 0; | |
4043 | u_char uj = use_json(argc, argv); | |
b1c3ae8c | 4044 | json_object *json = NULL; |
c9339663 CS |
4045 | int ret = CMD_SUCCESS; |
4046 | int display_once = 0; | |
b1c3ae8c | 4047 | u_char use_vrf = 0; |
c9339663 CS |
4048 | |
4049 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4050 | ||
4051 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4052 | intf_name = argv[idx_intf]->arg; | |
4053 | ||
b1c3ae8c CS |
4054 | if (uj) |
4055 | json = json_object_new_object(); | |
4056 | ||
c9339663 | 4057 | if (vrf_name) { |
b1c3ae8c | 4058 | use_vrf = 1; |
c9339663 CS |
4059 | if (all_vrf) { |
4060 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4061 | if (!ospf->oi_running) | |
4062 | continue; | |
4063 | ||
4064 | ret = show_ip_ospf_interface_traffic_common(vty, | |
4065 | ospf, intf_name, | |
b1c3ae8c | 4066 | json, |
c9339663 | 4067 | display_once, |
b1c3ae8c | 4068 | use_vrf, |
c9339663 CS |
4069 | uj); |
4070 | display_once = 1; | |
4071 | } | |
b1c3ae8c CS |
4072 | |
4073 | if (uj) { | |
4074 | vty_out(vty, "%s\n", | |
4075 | json_object_to_json_string_ext(json, | |
4076 | JSON_C_TO_STRING_PRETTY)); | |
4077 | json_object_free(json); | |
4078 | } | |
4079 | ||
c9339663 CS |
4080 | return ret; |
4081 | } | |
4082 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4083 | if (ospf == NULL || !ospf->oi_running) { |
4084 | if (uj) | |
4085 | json_object_free(json); | |
c9339663 | 4086 | return CMD_SUCCESS; |
b1c3ae8c CS |
4087 | } |
4088 | ||
c9339663 | 4089 | ret = show_ip_ospf_interface_traffic_common(vty, ospf, |
b1c3ae8c CS |
4090 | intf_name, json, |
4091 | display_once, | |
4092 | use_vrf, uj); | |
c9339663 CS |
4093 | } else { |
4094 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4095 | if (ospf == NULL || !ospf->oi_running) { |
4096 | if (uj) | |
4097 | json_object_free(json); | |
c9339663 | 4098 | return CMD_SUCCESS; |
b1c3ae8c CS |
4099 | } |
4100 | ||
c9339663 | 4101 | ret = show_ip_ospf_interface_traffic_common(vty, ospf, |
b1c3ae8c CS |
4102 | intf_name, json, |
4103 | display_once, | |
4104 | use_vrf, uj); | |
4105 | } | |
4106 | ||
4107 | if (uj) { | |
4108 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
4109 | JSON_C_TO_STRING_PRETTY)); | |
4110 | json_object_free(json); | |
c9339663 CS |
4111 | } |
4112 | ||
4113 | return ret; | |
4114 | } | |
4115 | ||
4116 | ||
d62a17ae | 4117 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4118 | { | |
4119 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n", | |
4120 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", | |
4121 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4122 | } | |
4123 | ||
4124 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4125 | struct ospf_interface *oi, | |
4126 | json_object *json, u_char use_json) | |
4127 | { | |
4128 | struct route_node *rn; | |
cef262c3 | 4129 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4130 | char msgbuf[16]; |
4131 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cef262c3 | 4132 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4133 | |
4134 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4135 | if ((nbr = rn->info)) { | |
4136 | /* Do not show myself. */ | |
cef262c3 CS |
4137 | if (nbr == oi->nbr_self) |
4138 | continue; | |
4139 | /* Down state is not shown. */ | |
4140 | if (nbr->state == NSM_Down) | |
4141 | continue; | |
4142 | if (use_json) { | |
4143 | char neigh_str[INET_ADDRSTRLEN]; | |
4144 | ||
4145 | if (prev_nbr && | |
4146 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
4147 | /* Start new neigh list */ | |
4148 | json_neigh_array = NULL; | |
4149 | } | |
4150 | ||
4151 | if (nbr->state == NSM_Attempt && | |
4152 | nbr->router_id.s_addr == 0) | |
6021c6c0 CS |
4153 | strlcpy(neigh_str, "neighbor", |
4154 | sizeof(neigh_str)); | |
cef262c3 | 4155 | else |
6021c6c0 | 4156 | strlcpy(neigh_str, |
cef262c3 | 4157 | inet_ntoa(nbr->router_id), |
6021c6c0 | 4158 | sizeof(neigh_str)); |
cef262c3 CS |
4159 | |
4160 | json_object_object_get_ex(json, neigh_str, | |
4161 | &json_neigh_array); | |
4162 | ||
4163 | if (!json_neigh_array) { | |
4164 | json_neigh_array = json_object_new_array(); | |
4165 | json_object_object_add(json, neigh_str, | |
4166 | json_neigh_array); | |
d62a17ae | 4167 | } |
cef262c3 CS |
4168 | |
4169 | json_neighbor = | |
4170 | json_object_new_object(); | |
4171 | ||
4172 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4173 | ||
4174 | long time_store; | |
4175 | ||
4176 | time_store = monotime_until( | |
4177 | &nbr->t_inactivity->u.sands, | |
4178 | NULL) / 1000LL; | |
4179 | ||
4180 | json_object_int_add(json_neighbor, | |
4181 | "priority", | |
4182 | nbr->priority); | |
4183 | json_object_string_add(json_neighbor, "state", | |
4184 | msgbuf); | |
4185 | json_object_int_add(json_neighbor, | |
4186 | "deadTimeMsecs", | |
4187 | time_store); | |
4188 | json_object_string_add(json_neighbor, | |
4189 | "address", | |
4190 | inet_ntoa(nbr->src)); | |
4191 | json_object_string_add(json_neighbor, | |
4192 | "ifaceName", | |
4193 | IF_NAME(oi)); | |
4194 | json_object_int_add(json_neighbor, | |
4195 | "retransmitCounter", | |
4196 | ospf_ls_retransmit_count(nbr)); | |
4197 | json_object_int_add(json_neighbor, | |
4198 | "requestCounter", | |
4199 | ospf_ls_request_count(nbr)); | |
4200 | json_object_int_add(json_neighbor, | |
4201 | "dbSummaryCounter", | |
4202 | ospf_db_summary_count(nbr)); | |
4203 | ||
4204 | json_object_array_add(json_neigh_array, | |
4205 | json_neighbor); | |
4206 | } else { | |
4207 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4208 | ||
4209 | if (nbr->state == NSM_Attempt && | |
4210 | nbr->router_id.s_addr == 0) | |
4211 | vty_out(vty, | |
4212 | "%-15s %3d %-15s ", | |
4213 | "-", | |
4214 | nbr->priority, | |
4215 | msgbuf); | |
4216 | else | |
4217 | vty_out(vty, | |
4218 | "%-15s %3d %-15s ", | |
4219 | inet_ntoa(nbr->router_id), | |
4220 | nbr->priority, | |
4221 | msgbuf); | |
4222 | ||
4223 | vty_out(vty, "%9s ", | |
4224 | ospf_timer_dump(nbr->t_inactivity, | |
4225 | timebuf, | |
4226 | sizeof(timebuf))); | |
4227 | vty_out(vty, "%-15s ", inet_ntoa(nbr->src)); | |
4228 | vty_out(vty, | |
4229 | "%-20s %5ld %5ld %5d\n", | |
4230 | IF_NAME(oi), | |
4231 | ospf_ls_retransmit_count(nbr), | |
4232 | ospf_ls_request_count(nbr), | |
4233 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4234 | } |
cef262c3 | 4235 | prev_nbr = nbr; |
d62a17ae | 4236 | } |
4237 | } | |
4238 | } | |
4239 | ||
4240 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
b1c3ae8c CS |
4241 | json_object *json, u_char use_json, |
4242 | u_char use_vrf) | |
d62a17ae | 4243 | { |
4244 | struct ospf_interface *oi; | |
4245 | struct listnode *node; | |
b1c3ae8c | 4246 | json_object *json_vrf = NULL; |
7c8ff89e | 4247 | |
b1c3ae8c CS |
4248 | if (use_json) { |
4249 | if (use_vrf) | |
4250 | json_vrf = json_object_new_object(); | |
4251 | else | |
4252 | json_vrf = json; | |
4253 | } | |
d62a17ae | 4254 | |
4255 | if (ospf->instance) { | |
4256 | if (use_json) | |
4257 | json_object_int_add(json, "ospfInstance", | |
4258 | ospf->instance); | |
4259 | else | |
4260 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4261 | } | |
7c8ff89e | 4262 | |
b1c3ae8c CS |
4263 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4264 | if (!use_json) | |
4265 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4266 | |
d62a17ae | 4267 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) |
b1c3ae8c | 4268 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
718e3744 | 4269 | |
d62a17ae | 4270 | if (use_json) { |
b1c3ae8c CS |
4271 | if (use_vrf) { |
4272 | if (ospf->vrf_id == VRF_DEFAULT) | |
4273 | json_object_object_add(json, "default", | |
4274 | json_vrf); | |
4275 | else | |
4276 | json_object_object_add(json, ospf->name, | |
4277 | json_vrf); | |
4278 | } | |
d62a17ae | 4279 | } else |
4280 | vty_out(vty, "\n"); | |
7c8ff89e | 4281 | |
d62a17ae | 4282 | return CMD_SUCCESS; |
718e3744 | 4283 | } |
4284 | ||
7c8ff89e DS |
4285 | DEFUN (show_ip_ospf_neighbor, |
4286 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4287 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4288 | SHOW_STR |
4289 | IP_STR | |
4290 | "OSPF information\n" | |
b5a8894d CS |
4291 | VRF_CMD_HELP_STR |
4292 | "All VRFs\n" | |
91756b38 | 4293 | "Neighbor list\n" |
9973d184 | 4294 | JSON_STR) |
718e3744 | 4295 | { |
d62a17ae | 4296 | struct ospf *ospf; |
4297 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4298 | struct listnode *node = NULL; |
4299 | char *vrf_name = NULL; | |
4300 | bool all_vrf = FALSE; | |
4301 | int ret = CMD_SUCCESS; | |
4302 | int inst = 0; | |
4303 | int idx_vrf = 0; | |
b1c3ae8c CS |
4304 | u_char use_vrf = 0; |
4305 | json_object *json = NULL; | |
718e3744 | 4306 | |
43b8d1d8 | 4307 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4308 | |
b1c3ae8c CS |
4309 | if (uj) |
4310 | json = json_object_new_object(); | |
b5a8894d CS |
4311 | |
4312 | /* vrf input is provided could be all or specific vrf*/ | |
4313 | if (vrf_name) { | |
b1c3ae8c | 4314 | use_vrf = 1; |
b5a8894d CS |
4315 | if (all_vrf) { |
4316 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4317 | if (!ospf->oi_running) | |
4318 | continue; | |
4319 | ret = show_ip_ospf_neighbor_common(vty, ospf, | |
b1c3ae8c CS |
4320 | json, uj, |
4321 | use_vrf); | |
4322 | } | |
4323 | ||
4324 | if (uj) { | |
4325 | vty_out(vty, "%s\n", | |
4326 | json_object_to_json_string_ext(json, | |
4327 | JSON_C_TO_STRING_PRETTY)); | |
4328 | json_object_free(json); | |
b5a8894d | 4329 | } |
b1c3ae8c | 4330 | |
b5a8894d CS |
4331 | return ret; |
4332 | } | |
b1c3ae8c | 4333 | |
b5a8894d | 4334 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4335 | if (ospf == NULL || !ospf->oi_running) { |
4336 | if (uj) | |
4337 | json_object_free(json); | |
b5a8894d | 4338 | return CMD_SUCCESS; |
b1c3ae8c | 4339 | } |
b5a8894d CS |
4340 | } else { |
4341 | /* Display default ospf (instance 0) info */ | |
4342 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4343 | if (ospf == NULL || !ospf->oi_running) { |
4344 | if (uj) | |
4345 | json_object_free(json); | |
b5a8894d | 4346 | return CMD_SUCCESS; |
b1c3ae8c | 4347 | } |
b5a8894d CS |
4348 | } |
4349 | ||
b1c3ae8c CS |
4350 | if (ospf) { |
4351 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4352 | use_vrf); | |
4353 | ||
4354 | if (uj) { | |
4355 | vty_out(vty, "%s\n", | |
4356 | json_object_to_json_string_ext(json, | |
4357 | JSON_C_TO_STRING_PRETTY)); | |
4358 | } | |
4359 | } | |
4360 | ||
4361 | if (uj) | |
4362 | json_object_free(json); | |
b5a8894d CS |
4363 | |
4364 | return ret; | |
7c8ff89e DS |
4365 | } |
4366 | ||
4367 | ||
4368 | DEFUN (show_ip_ospf_instance_neighbor, | |
4369 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4370 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4371 | SHOW_STR |
4372 | IP_STR | |
4373 | "OSPF information\n" | |
4374 | "Instance ID\n" | |
91756b38 | 4375 | "Neighbor list\n" |
9973d184 | 4376 | JSON_STR) |
7c8ff89e | 4377 | { |
d62a17ae | 4378 | int idx_number = 3; |
4379 | struct ospf *ospf; | |
4380 | u_short instance = 0; | |
4381 | u_char uj = use_json(argc, argv); | |
b1c3ae8c CS |
4382 | json_object *json = NULL; |
4383 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4384 | |
d62a17ae | 4385 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4386 | ospf = ospf_lookup_instance(instance); |
4387 | if (ospf == NULL) | |
4388 | return CMD_NOT_MY_INSTANCE; | |
4389 | ||
4390 | if (!ospf->oi_running) | |
d62a17ae | 4391 | return CMD_SUCCESS; |
7c8ff89e | 4392 | |
b1c3ae8c CS |
4393 | if (uj) |
4394 | json = json_object_new_object(); | |
b5a8894d | 4395 | |
b1c3ae8c CS |
4396 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4397 | ||
4398 | if (uj) { | |
4399 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
4400 | JSON_C_TO_STRING_PRETTY)); | |
4401 | json_object_free(json); | |
4402 | } | |
4403 | ||
4404 | return ret; | |
7c8ff89e DS |
4405 | } |
4406 | ||
d62a17ae | 4407 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
b1c3ae8c CS |
4408 | json_object *json, |
4409 | u_char use_json, | |
4410 | u_char use_vrf) | |
d62a17ae | 4411 | { |
4412 | struct listnode *node; | |
4413 | struct ospf_interface *oi; | |
b1c3ae8c | 4414 | json_object *json_vrf = NULL; |
d62a17ae | 4415 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4416 | |
d62a17ae | 4417 | if (use_json) { |
b1c3ae8c CS |
4418 | if (use_vrf) |
4419 | json_vrf = json_object_new_object(); | |
4420 | else | |
4421 | json_vrf = json; | |
d62a17ae | 4422 | json_neighbor_sub = json_object_new_object(); |
b5a8894d | 4423 | } |
d62a17ae | 4424 | |
b1c3ae8c CS |
4425 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4426 | if (!use_json) | |
4427 | show_ip_ospf_neighbour_header(vty); | |
4428 | ||
d62a17ae | 4429 | if (ospf->instance) { |
4430 | if (use_json) | |
b1c3ae8c | 4431 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4432 | ospf->instance); |
4433 | else | |
4434 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4435 | } | |
4436 | ||
4437 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4438 | struct listnode *nbr_node; | |
4439 | struct ospf_nbr_nbma *nbr_nbma; | |
4440 | ||
b1c3ae8c | 4441 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4442 | |
4443 | /* print Down neighbor status */ | |
4444 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4445 | if (nbr_nbma->nbr == NULL | |
4446 | || nbr_nbma->nbr->state == NSM_Down) { | |
4447 | if (use_json) { | |
4448 | json_object_int_add(json_neighbor_sub, | |
4449 | "nbrNbmaPriority", | |
4450 | nbr_nbma->priority); | |
4451 | json_object_boolean_true_add( | |
4452 | json_neighbor_sub, | |
4453 | "nbrNbmaDown"); | |
4454 | json_object_string_add( | |
4455 | json_neighbor_sub, | |
4456 | "nbrNbmaIfaceName", | |
4457 | IF_NAME(oi)); | |
4458 | json_object_int_add( | |
4459 | json_neighbor_sub, | |
4460 | "nbrNbmaRetransmitCounter", 0); | |
4461 | json_object_int_add( | |
4462 | json_neighbor_sub, | |
4463 | "nbrNbmaRequestCounter", 0); | |
4464 | json_object_int_add( | |
4465 | json_neighbor_sub, | |
4466 | "nbrNbmaDbSummaryCounter", 0); | |
4467 | json_object_object_add( | |
b1c3ae8c CS |
4468 | json_vrf, |
4469 | inet_ntoa(nbr_nbma->addr), | |
d62a17ae | 4470 | json_neighbor_sub); |
4471 | } else { | |
4472 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4473 | "-", nbr_nbma->priority, "Down", | |
4474 | "-"); | |
4475 | vty_out(vty, | |
4476 | "%-15s %-20s %5d %5d %5d\n", | |
4477 | inet_ntoa(nbr_nbma->addr), | |
4478 | IF_NAME(oi), 0, 0, 0); | |
4479 | } | |
4480 | } | |
4481 | } | |
4482 | } | |
4483 | ||
4484 | if (use_json) { | |
b1c3ae8c CS |
4485 | if (use_vrf) { |
4486 | if (ospf->vrf_id == VRF_DEFAULT) | |
4487 | json_object_object_add(json, "default", | |
4488 | json_vrf); | |
4489 | else | |
4490 | json_object_object_add(json, ospf->name, | |
4491 | json_vrf); | |
4492 | } | |
d62a17ae | 4493 | } else |
4494 | vty_out(vty, "\n"); | |
4495 | ||
4496 | return CMD_SUCCESS; | |
718e3744 | 4497 | } |
4498 | ||
7c8ff89e DS |
4499 | DEFUN (show_ip_ospf_neighbor_all, |
4500 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4501 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4502 | SHOW_STR |
4503 | IP_STR | |
4504 | "OSPF information\n" | |
b5a8894d CS |
4505 | VRF_CMD_HELP_STR |
4506 | "All VRFs\n" | |
718e3744 | 4507 | "Neighbor list\n" |
91756b38 | 4508 | "include down status neighbor\n" |
9973d184 | 4509 | JSON_STR) |
7c8ff89e | 4510 | { |
d62a17ae | 4511 | struct ospf *ospf; |
4512 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4513 | struct listnode *node = NULL; |
4514 | char *vrf_name = NULL; | |
4515 | bool all_vrf = FALSE; | |
4516 | int ret = CMD_SUCCESS; | |
4517 | int inst = 0; | |
4518 | int idx_vrf = 0; | |
b1c3ae8c CS |
4519 | u_char use_vrf = 0; |
4520 | json_object *json = NULL; | |
7c8ff89e | 4521 | |
43b8d1d8 | 4522 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4523 | |
b1c3ae8c CS |
4524 | if (uj) |
4525 | json = json_object_new_object(); | |
b5a8894d CS |
4526 | |
4527 | /* vrf input is provided could be all or specific vrf*/ | |
4528 | if (vrf_name) { | |
b1c3ae8c | 4529 | use_vrf = 1; |
b5a8894d CS |
4530 | if (all_vrf) { |
4531 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4532 | if (!ospf->oi_running) | |
4533 | continue; | |
4534 | ret = show_ip_ospf_neighbor_all_common(vty, | |
4535 | ospf, | |
b1c3ae8c CS |
4536 | json, |
4537 | uj, | |
4538 | use_vrf); | |
4539 | } | |
4540 | ||
4541 | if (uj) { | |
4542 | vty_out(vty, "%s\n", | |
4543 | json_object_to_json_string_ext(json, | |
4544 | JSON_C_TO_STRING_PRETTY)); | |
4545 | json_object_free(json); | |
b5a8894d | 4546 | } |
b1c3ae8c | 4547 | |
b5a8894d CS |
4548 | return ret; |
4549 | } | |
b1c3ae8c | 4550 | |
b5a8894d | 4551 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4552 | if (ospf == NULL || !ospf->oi_running) { |
4553 | if (uj) | |
4554 | json_object_free(json); | |
b5a8894d | 4555 | return CMD_SUCCESS; |
b1c3ae8c | 4556 | } |
b5a8894d CS |
4557 | } else { |
4558 | /* Display default ospf (instance 0) info */ | |
4559 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4560 | if (ospf == NULL || !ospf->oi_running) { |
4561 | if (uj) | |
4562 | json_object_free(json); | |
b5a8894d | 4563 | return CMD_SUCCESS; |
b1c3ae8c | 4564 | } |
b5a8894d CS |
4565 | } |
4566 | ||
b1c3ae8c CS |
4567 | if (ospf) { |
4568 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4569 | use_vrf); | |
4570 | if (uj) { | |
4571 | vty_out(vty, "%s\n", | |
4572 | json_object_to_json_string_ext(json, | |
4573 | JSON_C_TO_STRING_PRETTY)); | |
4574 | } | |
4575 | } | |
4576 | ||
4577 | if (uj) | |
4578 | json_object_free(json); | |
b5a8894d CS |
4579 | |
4580 | return ret; | |
7c8ff89e DS |
4581 | } |
4582 | ||
4583 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4584 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4585 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4586 | SHOW_STR |
4587 | IP_STR | |
4588 | "OSPF information\n" | |
4589 | "Instance ID\n" | |
4590 | "Neighbor list\n" | |
91756b38 | 4591 | "include down status neighbor\n" |
9973d184 | 4592 | JSON_STR) |
718e3744 | 4593 | { |
d62a17ae | 4594 | int idx_number = 3; |
4595 | struct ospf *ospf; | |
4596 | u_short instance = 0; | |
4597 | u_char uj = use_json(argc, argv); | |
b1c3ae8c CS |
4598 | json_object *json = NULL; |
4599 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4600 | |
d62a17ae | 4601 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4602 | ospf = ospf_lookup_instance(instance); |
4603 | if (ospf == NULL) | |
4604 | return CMD_NOT_MY_INSTANCE; | |
4605 | ||
4606 | if (!ospf->oi_running) | |
d62a17ae | 4607 | return CMD_SUCCESS; |
b1c3ae8c CS |
4608 | if (uj) |
4609 | json = json_object_new_object(); | |
4610 | ||
4611 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4612 | ||
4613 | if (uj) { | |
4614 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4615 | json, JSON_C_TO_STRING_PRETTY)); | |
4616 | json_object_free(json); | |
4617 | } | |
7c8ff89e | 4618 | |
b1c3ae8c | 4619 | return ret; |
7c8ff89e DS |
4620 | } |
4621 | ||
d62a17ae | 4622 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4623 | int arg_base, | |
4624 | struct cmd_token **argv, | |
b1c3ae8c | 4625 | u_char use_json, u_char use_vrf) |
d62a17ae | 4626 | { |
4627 | struct interface *ifp; | |
4628 | struct route_node *rn; | |
4629 | json_object *json = NULL; | |
91756b38 | 4630 | |
d62a17ae | 4631 | if (use_json) |
4632 | json = json_object_new_object(); | |
d62a17ae | 4633 | |
4634 | if (ospf->instance) { | |
4635 | if (use_json) | |
4636 | json_object_int_add(json, "ospfInstance", | |
4637 | ospf->instance); | |
4638 | else | |
4639 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4640 | } | |
4641 | ||
b1c3ae8c | 4642 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4643 | |
b5a8894d CS |
4644 | /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/ |
4645 | ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); | |
d62a17ae | 4646 | if (!ifp) { |
4647 | if (use_json) | |
4648 | json_object_boolean_true_add(json, "noSuchIface"); | |
4649 | else | |
4650 | vty_out(vty, "No such interface.\n"); | |
4651 | return CMD_WARNING; | |
4652 | } | |
4653 | ||
4654 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4655 | struct ospf_interface *oi = rn->info; | |
4656 | ||
4657 | if (oi == NULL) | |
4658 | continue; | |
4659 | ||
4660 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4661 | } | |
4662 | ||
4663 | if (use_json) { | |
9d303b37 DL |
4664 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4665 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4666 | json_object_free(json); |
4667 | } else | |
4668 | vty_out(vty, "\n"); | |
4669 | ||
4670 | return CMD_SUCCESS; | |
718e3744 | 4671 | } |
4672 | ||
7c8ff89e DS |
4673 | DEFUN (show_ip_ospf_neighbor_int, |
4674 | show_ip_ospf_neighbor_int_cmd, | |
b162fa78 | 4675 | "show ip ospf neighbor IFNAME [json]", |
7c8ff89e DS |
4676 | SHOW_STR |
4677 | IP_STR | |
4678 | "OSPF information\n" | |
4679 | "Neighbor list\n" | |
91756b38 | 4680 | "Interface name\n" |
9973d184 | 4681 | JSON_STR) |
7c8ff89e | 4682 | { |
d62a17ae | 4683 | struct ospf *ospf; |
b4e84315 | 4684 | int idx_ifname = 4; |
d62a17ae | 4685 | u_char uj = use_json(argc, argv); |
b5a8894d CS |
4686 | struct listnode *node = NULL; |
4687 | int ret = CMD_SUCCESS; | |
4688 | struct interface *ifp = NULL; | |
7c8ff89e | 4689 | |
b5a8894d CS |
4690 | if (!uj) |
4691 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4692 | |
b5a8894d CS |
4693 | ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg); |
4694 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4695 | if (!ospf->oi_running) | |
4696 | continue; | |
4697 | if (!ifp || ifp->vrf_id != ospf->vrf_id) | |
4698 | continue; | |
4699 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, | |
b1c3ae8c | 4700 | idx_ifname, argv, uj, 0); |
b5a8894d CS |
4701 | } |
4702 | ||
4703 | return ret; | |
7c8ff89e DS |
4704 | } |
4705 | ||
4706 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4707 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4708 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4709 | SHOW_STR |
4710 | IP_STR | |
4711 | "OSPF information\n" | |
4712 | "Instance ID\n" | |
4713 | "Neighbor list\n" | |
91756b38 | 4714 | "Interface name\n" |
9973d184 | 4715 | JSON_STR) |
7c8ff89e | 4716 | { |
d62a17ae | 4717 | int idx_number = 3; |
b4e84315 | 4718 | int idx_ifname = 5; |
d62a17ae | 4719 | struct ospf *ospf; |
4720 | u_short instance = 0; | |
4721 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4722 | |
b5a8894d CS |
4723 | if (!uj) |
4724 | show_ip_ospf_neighbour_header(vty); | |
4725 | ||
d62a17ae | 4726 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4727 | ospf = ospf_lookup_instance(instance); |
4728 | if (ospf == NULL) | |
4729 | return CMD_NOT_MY_INSTANCE; | |
4730 | ||
4731 | if (!ospf->oi_running) | |
d62a17ae | 4732 | return CMD_SUCCESS; |
7c8ff89e | 4733 | |
b5a8894d CS |
4734 | if (!uj) |
4735 | show_ip_ospf_neighbour_header(vty); | |
4736 | ||
b1c3ae8c CS |
4737 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, |
4738 | argv, uj, 0); | |
718e3744 | 4739 | } |
4740 | ||
d62a17ae | 4741 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
4742 | struct ospf_interface *oi, | |
4743 | struct ospf_nbr_nbma *nbr_nbma, | |
4744 | u_char use_json, json_object *json) | |
4745 | { | |
4746 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4747 | json_object *json_sub = NULL; | |
718e3744 | 4748 | |
d62a17ae | 4749 | if (use_json) |
4750 | json_sub = json_object_new_object(); | |
4751 | else /* Show neighbor ID. */ | |
4752 | vty_out(vty, " Neighbor %s,", "-"); | |
4753 | ||
4754 | /* Show interface address. */ | |
4755 | if (use_json) | |
4756 | json_object_string_add(json_sub, "ifaceAddress", | |
4757 | inet_ntoa(nbr_nbma->addr)); | |
4758 | else | |
4759 | vty_out(vty, " interface address %s\n", | |
4760 | inet_ntoa(nbr_nbma->addr)); | |
4761 | ||
4762 | /* Show Area ID. */ | |
4763 | if (use_json) { | |
4764 | json_object_string_add(json_sub, "areaId", | |
4765 | ospf_area_desc_string(oi->area)); | |
4766 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
4767 | } else | |
4768 | vty_out(vty, " In the area %s via interface %s\n", | |
4769 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
4770 | ||
4771 | /* Show neighbor priority and state. */ | |
4772 | if (use_json) { | |
4773 | json_object_int_add(json_sub, "nbrPriority", | |
4774 | nbr_nbma->priority); | |
4775 | json_object_string_add(json_sub, "nbrState", "down"); | |
4776 | } else | |
4777 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4778 | nbr_nbma->priority, "Down"); | |
4779 | ||
4780 | /* Show state changes. */ | |
4781 | if (use_json) | |
4782 | json_object_int_add(json_sub, "stateChangeCounter", | |
4783 | nbr_nbma->state_change); | |
4784 | else | |
4785 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
4786 | ||
4787 | /* Show PollInterval */ | |
4788 | if (use_json) | |
4789 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
4790 | else | |
4791 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
4792 | ||
4793 | /* Show poll-interval timer. */ | |
4794 | if (use_json) { | |
4795 | long time_store; | |
4796 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, NULL) | |
4797 | / 1000LL; | |
4798 | json_object_int_add(json_sub, "pollIntervalTimerDueMsec", | |
4799 | time_store); | |
4800 | } else | |
4801 | vty_out(vty, " Poll timer due in %s\n", | |
4802 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
4803 | sizeof(timebuf))); | |
4804 | ||
4805 | /* Show poll-interval timer thread. */ | |
4806 | if (use_json) { | |
4807 | if (nbr_nbma->t_poll != NULL) | |
4808 | json_object_string_add(json_sub, | |
4809 | "pollIntervalTimerThread", "on"); | |
4810 | } else | |
4811 | vty_out(vty, " Thread Poll Timer %s\n", | |
4812 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
4813 | ||
4814 | if (use_json) | |
4815 | json_object_object_add(json, "noNbrId", json_sub); | |
4816 | } | |
4817 | ||
4818 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
4819 | struct ospf_interface *oi, | |
4820 | struct ospf_neighbor *nbr, | |
b1c3ae8c CS |
4821 | json_object *json, |
4822 | u_char use_json) | |
d62a17ae | 4823 | { |
4824 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4825 | json_object *json_sub = NULL; | |
4826 | ||
4827 | if (use_json) | |
4828 | json_sub = json_object_new_object(); | |
4829 | else { | |
4830 | /* Show neighbor ID. */ | |
4831 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
4832 | vty_out(vty, " Neighbor %s,", "-"); | |
4833 | else | |
4834 | vty_out(vty, " Neighbor %s,", | |
4835 | inet_ntoa(nbr->router_id)); | |
4836 | } | |
4837 | ||
4838 | /* Show interface address. */ | |
4839 | if (use_json) | |
4840 | json_object_string_add(json_sub, "ifaceAddress", | |
4841 | inet_ntoa(nbr->address.u.prefix4)); | |
4842 | else | |
4843 | vty_out(vty, " interface address %s\n", | |
4844 | inet_ntoa(nbr->address.u.prefix4)); | |
4845 | ||
4846 | /* Show Area ID. */ | |
4847 | if (use_json) { | |
4848 | json_object_string_add(json_sub, "areaId", | |
4849 | ospf_area_desc_string(oi->area)); | |
4850 | json_object_string_add(json_sub, "ifaceName", oi->ifp->name); | |
4851 | } else | |
4852 | vty_out(vty, " In the area %s via interface %s\n", | |
4853 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
4854 | ||
4855 | /* Show neighbor priority and state. */ | |
4856 | if (use_json) { | |
4857 | json_object_int_add(json_sub, "nbrPriority", nbr->priority); | |
4858 | json_object_string_add( | |
4859 | json_sub, "nbrState", | |
4860 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4861 | } else | |
4862 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4863 | nbr->priority, | |
4864 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4865 | ||
4866 | /* Show state changes. */ | |
4867 | if (use_json) | |
4868 | json_object_int_add(json_sub, "stateChangeCounter", | |
4869 | nbr->state_change); | |
4870 | else | |
4871 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
4872 | ||
4873 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
4874 | struct timeval res; | |
4875 | long time_store; | |
4876 | ||
4877 | time_store = | |
4878 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
4879 | if (use_json) { | |
4880 | json_object_int_add(json_sub, "lastPrgrsvChangeMsec", | |
4881 | time_store); | |
4882 | } else { | |
4883 | vty_out(vty, | |
4884 | " Most recent state change statistics:\n"); | |
4885 | vty_out(vty, " Progressive change %s ago\n", | |
4886 | ospf_timeval_dump(&res, timebuf, | |
4887 | sizeof(timebuf))); | |
4888 | } | |
4889 | } | |
4890 | ||
4891 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
4892 | struct timeval res; | |
4893 | long time_store; | |
4894 | ||
4895 | time_store = | |
4896 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
4897 | if (use_json) { | |
4898 | json_object_int_add(json_sub, | |
4899 | "lastRegressiveChangeMsec", | |
4900 | time_store); | |
4901 | if (nbr->last_regress_str) | |
4902 | json_object_string_add( | |
4903 | json_sub, "lastRegressiveChangeReason", | |
4904 | nbr->last_regress_str); | |
4905 | } else { | |
4906 | vty_out(vty, | |
4907 | " Regressive change %s ago, due to %s\n", | |
4908 | ospf_timeval_dump(&res, timebuf, | |
4909 | sizeof(timebuf)), | |
4910 | (nbr->last_regress_str ? nbr->last_regress_str | |
4911 | : "??")); | |
4912 | } | |
4913 | } | |
4914 | ||
4915 | /* Show Designated Rotuer ID. */ | |
4916 | if (use_json) | |
4917 | json_object_string_add(json_sub, "routerDesignatedId", | |
4918 | inet_ntoa(nbr->d_router)); | |
4919 | else | |
4920 | vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router)); | |
4921 | ||
4922 | /* Show Backup Designated Rotuer ID. */ | |
4923 | if (use_json) | |
4924 | json_object_string_add(json_sub, "routerDesignatedBackupId", | |
4925 | inet_ntoa(nbr->bd_router)); | |
4926 | else | |
4927 | vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router)); | |
4928 | ||
4929 | /* Show options. */ | |
4930 | if (use_json) { | |
4931 | json_object_int_add(json_sub, "optionsCounter", nbr->options); | |
4932 | json_object_string_add(json_sub, "optionsList", | |
4933 | ospf_options_dump(nbr->options)); | |
4934 | } else | |
4935 | vty_out(vty, " Options %d %s\n", nbr->options, | |
4936 | ospf_options_dump(nbr->options)); | |
4937 | ||
4938 | /* Show Router Dead interval timer. */ | |
4939 | if (use_json) { | |
4940 | if (nbr->t_inactivity) { | |
4941 | long time_store; | |
4942 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
4943 | NULL) | |
4944 | / 1000LL; | |
4945 | json_object_int_add(json_sub, | |
4946 | "routerDeadIntervalTimerDueMsec", | |
4947 | time_store); | |
4948 | } else | |
4949 | json_object_int_add( | |
4950 | json_sub, "routerDeadIntervalTimerDueMsec", -1); | |
4951 | } else | |
4952 | vty_out(vty, " Dead timer due in %s\n", | |
4953 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
4954 | sizeof(timebuf))); | |
4955 | ||
4956 | /* Show Database Summary list. */ | |
4957 | if (use_json) | |
4958 | json_object_int_add(json_sub, "databaseSummaryListCounter", | |
4959 | ospf_db_summary_count(nbr)); | |
4960 | else | |
4961 | vty_out(vty, " Database Summary List %d\n", | |
4962 | ospf_db_summary_count(nbr)); | |
4963 | ||
4964 | /* Show Link State Request list. */ | |
4965 | if (use_json) | |
4966 | json_object_int_add(json_sub, "linkStateRequestListCounter", | |
4967 | ospf_ls_request_count(nbr)); | |
4968 | else | |
4969 | vty_out(vty, " Link State Request List %ld\n", | |
4970 | ospf_ls_request_count(nbr)); | |
4971 | ||
4972 | /* Show Link State Retransmission list. */ | |
4973 | if (use_json) | |
4974 | json_object_int_add(json_sub, | |
4975 | "linkStateRetransmissionListCounter", | |
4976 | ospf_ls_retransmit_count(nbr)); | |
4977 | else | |
4978 | vty_out(vty, " Link State Retransmission List %ld\n", | |
4979 | ospf_ls_retransmit_count(nbr)); | |
4980 | ||
4981 | /* Show inactivity timer thread. */ | |
4982 | if (use_json) { | |
4983 | if (nbr->t_inactivity != NULL) | |
4984 | json_object_string_add(json_sub, | |
4985 | "threadInactivityTimer", "on"); | |
4986 | } else | |
4987 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
4988 | nbr->t_inactivity != NULL ? "on" : "off"); | |
4989 | ||
4990 | /* Show Database Description retransmission thread. */ | |
4991 | if (use_json) { | |
4992 | if (nbr->t_db_desc != NULL) | |
4993 | json_object_string_add( | |
4994 | json_sub, | |
4995 | "threadDatabaseDescriptionRetransmission", | |
4996 | "on"); | |
4997 | } else | |
4998 | vty_out(vty, | |
4999 | " Thread Database Description Retransmision %s\n", | |
5000 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5001 | ||
5002 | /* Show Link State Request Retransmission thread. */ | |
5003 | if (use_json) { | |
5004 | if (nbr->t_ls_req != NULL) | |
5005 | json_object_string_add( | |
5006 | json_sub, | |
5007 | "threadLinkStateRequestRetransmission", "on"); | |
5008 | } else | |
5009 | vty_out(vty, | |
5010 | " Thread Link State Request Retransmission %s\n", | |
5011 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5012 | ||
5013 | /* Show Link State Update Retransmission thread. */ | |
5014 | if (use_json) { | |
5015 | if (nbr->t_ls_upd != NULL) | |
5016 | json_object_string_add( | |
5017 | json_sub, "threadLinkStateUpdateRetransmission", | |
5018 | "on"); | |
5019 | } else | |
5020 | vty_out(vty, | |
5021 | " Thread Link State Update Retransmission %s\n\n", | |
5022 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5023 | ||
5024 | if (use_json) { | |
5025 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
5026 | json_object_object_add(json, "noNbrId", json_sub); | |
5027 | else | |
5028 | json_object_object_add(json, inet_ntoa(nbr->router_id), | |
5029 | json_sub); | |
5030 | } | |
5031 | ||
5032 | ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0); | |
5033 | } | |
5034 | ||
5035 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
5036 | int arg_base, | |
5037 | struct cmd_token **argv, | |
b1c3ae8c CS |
5038 | u_char use_json, |
5039 | u_char use_vrf) | |
d62a17ae | 5040 | { |
5041 | struct listnode *node; | |
5042 | struct ospf_neighbor *nbr; | |
5043 | struct ospf_interface *oi; | |
5044 | struct in_addr router_id; | |
5045 | int ret; | |
5046 | json_object *json = NULL; | |
5047 | ||
5048 | if (use_json) | |
5049 | json = json_object_new_object(); | |
5050 | ||
5051 | if (ospf->instance) { | |
5052 | if (use_json) | |
5053 | json_object_int_add(json, "ospfInstance", | |
5054 | ospf->instance); | |
5055 | else | |
5056 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5057 | } | |
5058 | ||
b1c3ae8c | 5059 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5060 | |
d62a17ae | 5061 | ret = inet_aton(argv[arg_base]->arg, &router_id); |
5062 | if (!ret) { | |
5063 | if (!use_json) | |
5064 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
16307668 RW |
5065 | else { |
5066 | vty_out(vty, "{}\n"); | |
5067 | json_object_free(json); | |
5068 | } | |
d62a17ae | 5069 | return CMD_WARNING; |
5070 | } | |
5071 | ||
5072 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
5073 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &router_id))) { | |
b1c3ae8c CS |
5074 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json, |
5075 | use_json); | |
d62a17ae | 5076 | } |
5077 | } | |
5078 | ||
5079 | if (use_json) { | |
9d303b37 DL |
5080 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5081 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5082 | json_object_free(json); |
5083 | } else | |
5084 | vty_out(vty, "\n"); | |
5085 | ||
5086 | return CMD_SUCCESS; | |
718e3744 | 5087 | } |
5088 | ||
7c8ff89e DS |
5089 | DEFUN (show_ip_ospf_neighbor_id, |
5090 | show_ip_ospf_neighbor_id_cmd, | |
b162fa78 | 5091 | "show ip ospf neighbor A.B.C.D [json]", |
718e3744 | 5092 | SHOW_STR |
5093 | IP_STR | |
5094 | "OSPF information\n" | |
5095 | "Neighbor list\n" | |
3ac237f8 | 5096 | "Neighbor ID\n" |
9973d184 | 5097 | JSON_STR) |
718e3744 | 5098 | { |
d62a17ae | 5099 | struct ospf *ospf; |
5100 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
5101 | struct listnode *node = NULL; |
5102 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5103 | |
b5a8894d CS |
5104 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5105 | if (!ospf->oi_running) | |
5106 | continue; | |
b1c3ae8c CS |
5107 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, 0, |
5108 | argv, uj, 0); | |
b5a8894d | 5109 | } |
7c8ff89e | 5110 | |
b5a8894d | 5111 | return ret; |
7c8ff89e DS |
5112 | } |
5113 | ||
5114 | DEFUN (show_ip_ospf_instance_neighbor_id, | |
5115 | show_ip_ospf_instance_neighbor_id_cmd, | |
6147e2c6 | 5116 | "show ip ospf (1-65535) neighbor A.B.C.D [json]", |
7c8ff89e DS |
5117 | SHOW_STR |
5118 | IP_STR | |
5119 | "OSPF information\n" | |
5120 | "Instance ID\n" | |
5121 | "Neighbor list\n" | |
3ac237f8 | 5122 | "Neighbor ID\n" |
9973d184 | 5123 | JSON_STR) |
7c8ff89e | 5124 | { |
d62a17ae | 5125 | int idx_number = 3; |
b4e84315 | 5126 | int idx_router_id = 5; |
d62a17ae | 5127 | struct ospf *ospf; |
5128 | u_short instance = 0; | |
5129 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 5130 | |
d62a17ae | 5131 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5132 | ospf = ospf_lookup_instance(instance); |
5133 | if (ospf == NULL) | |
5134 | return CMD_NOT_MY_INSTANCE; | |
5135 | ||
5136 | if (!ospf->oi_running) | |
d62a17ae | 5137 | return CMD_SUCCESS; |
7c8ff89e | 5138 | |
b1c3ae8c CS |
5139 | return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv, |
5140 | uj, 0); | |
7c8ff89e DS |
5141 | } |
5142 | ||
d62a17ae | 5143 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5144 | struct ospf *ospf, | |
b1c3ae8c CS |
5145 | json_object *json, |
5146 | u_char use_json, | |
5147 | u_char use_vrf) | |
d62a17ae | 5148 | { |
5149 | struct ospf_interface *oi; | |
5150 | struct listnode *node; | |
b1c3ae8c | 5151 | json_object *json_vrf = NULL; |
d62a17ae | 5152 | |
b1c3ae8c CS |
5153 | if (use_json) { |
5154 | if (use_vrf) | |
5155 | json_vrf = json_object_new_object(); | |
5156 | else | |
5157 | json_vrf = json; | |
5158 | } | |
d62a17ae | 5159 | if (ospf->instance) { |
5160 | if (use_json) | |
b1c3ae8c | 5161 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 5162 | ospf->instance); |
5163 | else | |
5164 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5165 | } | |
5166 | ||
b1c3ae8c | 5167 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5168 | |
d62a17ae | 5169 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5170 | struct route_node *rn; | |
5171 | struct ospf_neighbor *nbr; | |
5172 | ||
5173 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5174 | if ((nbr = rn->info)) { | |
5175 | if (nbr != oi->nbr_self) { | |
5176 | if (nbr->state != NSM_Down) { | |
5177 | show_ip_ospf_neighbor_detail_sub( | |
b1c3ae8c CS |
5178 | vty, oi, nbr, json_vrf, |
5179 | use_json); | |
d62a17ae | 5180 | } |
5181 | } | |
5182 | } | |
5183 | } | |
5184 | } | |
5185 | ||
5186 | if (use_json) { | |
b1c3ae8c CS |
5187 | if (use_vrf) { |
5188 | if (ospf->vrf_id == VRF_DEFAULT) | |
5189 | json_object_object_add(json, "default", | |
5190 | json_vrf); | |
5191 | else | |
5192 | json_object_object_add(json, ospf->name, | |
5193 | json_vrf); | |
5194 | } | |
d62a17ae | 5195 | } else |
5196 | vty_out(vty, "\n"); | |
5197 | ||
5198 | return CMD_SUCCESS; | |
718e3744 | 5199 | } |
5200 | ||
7c8ff89e DS |
5201 | DEFUN (show_ip_ospf_neighbor_detail, |
5202 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5203 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5204 | SHOW_STR |
5205 | IP_STR | |
5206 | "OSPF information\n" | |
b5a8894d CS |
5207 | VRF_CMD_HELP_STR |
5208 | "All VRFs\n" | |
718e3744 | 5209 | "Neighbor list\n" |
3ac237f8 | 5210 | "detail of all neighbors\n" |
9973d184 | 5211 | JSON_STR) |
718e3744 | 5212 | { |
d62a17ae | 5213 | struct ospf *ospf; |
5214 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
5215 | struct listnode *node = NULL; |
5216 | char *vrf_name = NULL; | |
5217 | bool all_vrf = FALSE; | |
5218 | int ret = CMD_SUCCESS; | |
5219 | int inst = 0; | |
5220 | int idx_vrf = 0; | |
b1c3ae8c CS |
5221 | u_char use_vrf = 0; |
5222 | json_object *json = NULL; | |
7c8ff89e | 5223 | |
43b8d1d8 | 5224 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5225 | |
b1c3ae8c CS |
5226 | if (uj) |
5227 | json = json_object_new_object(); | |
5228 | ||
b5a8894d CS |
5229 | /* vrf input is provided could be all or specific vrf*/ |
5230 | if (vrf_name) { | |
b1c3ae8c | 5231 | use_vrf = 1; |
b5a8894d CS |
5232 | if (all_vrf) { |
5233 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5234 | if (!ospf->oi_running) | |
5235 | continue; | |
5236 | ret = show_ip_ospf_neighbor_detail_common(vty, | |
b1c3ae8c CS |
5237 | ospf, |
5238 | json, | |
5239 | uj, | |
5240 | use_vrf); | |
5241 | } | |
5242 | if (uj) { | |
5243 | vty_out(vty, "%s\n", | |
5244 | json_object_to_json_string_ext(json, | |
5245 | JSON_C_TO_STRING_PRETTY)); | |
5246 | json_object_free(json); | |
b5a8894d | 5247 | } |
b1c3ae8c | 5248 | |
b5a8894d CS |
5249 | return ret; |
5250 | } | |
5251 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5252 | if (ospf == NULL || !ospf->oi_running) { |
5253 | if (uj) | |
5254 | json_object_free(json); | |
b5a8894d | 5255 | return CMD_SUCCESS; |
b1c3ae8c | 5256 | } |
b5a8894d CS |
5257 | } else { |
5258 | /* Display default ospf (instance 0) info */ | |
5259 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5260 | if (ospf == NULL || !ospf->oi_running) { |
5261 | if (uj) | |
5262 | json_object_free(json); | |
b5a8894d | 5263 | return CMD_SUCCESS; |
b1c3ae8c | 5264 | } |
b5a8894d CS |
5265 | } |
5266 | ||
b1c3ae8c CS |
5267 | if (ospf) { |
5268 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5269 | use_vrf); | |
5270 | if (uj) { | |
5271 | vty_out(vty, "%s\n", | |
5272 | json_object_to_json_string_ext(json, | |
5273 | JSON_C_TO_STRING_PRETTY)); | |
5274 | } | |
5275 | } | |
5276 | ||
5277 | if (uj) | |
5278 | json_object_free(json); | |
b5a8894d CS |
5279 | |
5280 | return ret; | |
7c8ff89e DS |
5281 | } |
5282 | ||
5283 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5284 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5285 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5286 | SHOW_STR |
5287 | IP_STR | |
5288 | "OSPF information\n" | |
5289 | "Instance ID\n" | |
5290 | "Neighbor list\n" | |
3ac237f8 | 5291 | "detail of all neighbors\n" |
9973d184 | 5292 | JSON_STR) |
7c8ff89e | 5293 | { |
d62a17ae | 5294 | int idx_number = 3; |
5295 | struct ospf *ospf; | |
5296 | u_short instance = 0; | |
5297 | u_char uj = use_json(argc, argv); | |
b1c3ae8c CS |
5298 | json_object *json = NULL; |
5299 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5300 | |
d62a17ae | 5301 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5302 | ospf = ospf_lookup_instance(instance); |
5303 | if (ospf == NULL) | |
5304 | return CMD_NOT_MY_INSTANCE; | |
5305 | ||
5306 | if (!ospf->oi_running) | |
d62a17ae | 5307 | return CMD_SUCCESS; |
7c8ff89e | 5308 | |
b1c3ae8c CS |
5309 | if (uj) |
5310 | json = json_object_new_object(); | |
5311 | ||
5312 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5313 | ||
5314 | if (uj) { | |
5315 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5316 | json, JSON_C_TO_STRING_PRETTY)); | |
5317 | json_object_free(json); | |
5318 | } | |
5319 | ||
5320 | return ret; | |
7c8ff89e DS |
5321 | } |
5322 | ||
d62a17ae | 5323 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5324 | struct ospf *ospf, | |
b1c3ae8c CS |
5325 | json_object *json, |
5326 | u_char use_json, | |
5327 | u_char use_vrf) | |
d62a17ae | 5328 | { |
5329 | struct listnode *node; | |
5330 | struct ospf_interface *oi; | |
b1c3ae8c | 5331 | json_object *json_vrf = NULL; |
718e3744 | 5332 | |
b1c3ae8c CS |
5333 | if (use_json) { |
5334 | if (use_vrf) | |
5335 | json_vrf = json_object_new_object(); | |
5336 | else | |
5337 | json_vrf = json; | |
5338 | } | |
d62a17ae | 5339 | |
5340 | if (ospf->instance) { | |
5341 | if (use_json) | |
5342 | json_object_int_add(json, "ospfInstance", | |
5343 | ospf->instance); | |
5344 | else | |
5345 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5346 | } | |
5347 | ||
b1c3ae8c | 5348 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5349 | |
d62a17ae | 5350 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5351 | struct route_node *rn; | |
5352 | struct ospf_neighbor *nbr; | |
5353 | struct ospf_nbr_nbma *nbr_nbma; | |
5354 | ||
5355 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) | |
5356 | if ((nbr = rn->info)) | |
5357 | if (nbr != oi->nbr_self) | |
5358 | if (nbr->state != NSM_Down) | |
5359 | show_ip_ospf_neighbor_detail_sub( | |
5360 | vty, oi, rn->info, | |
b1c3ae8c | 5361 | json_vrf, use_json); |
d62a17ae | 5362 | |
5363 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5364 | struct listnode *nd; | |
5365 | ||
5366 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5367 | if (nbr_nbma->nbr == NULL | |
5368 | || nbr_nbma->nbr->state == NSM_Down) | |
5369 | show_ip_ospf_nbr_nbma_detail_sub( | |
5370 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5371 | json_vrf); |
d62a17ae | 5372 | } |
5373 | } | |
5374 | } | |
5375 | ||
5376 | if (use_json) { | |
b1c3ae8c CS |
5377 | if (use_vrf) { |
5378 | if (ospf->vrf_id == VRF_DEFAULT) | |
5379 | json_object_object_add(json, "default", | |
5380 | json_vrf); | |
5381 | else | |
5382 | json_object_object_add(json, ospf->name, | |
5383 | json_vrf); | |
5384 | } | |
d62a17ae | 5385 | } else { |
5386 | vty_out(vty, "\n"); | |
5387 | } | |
5388 | ||
5389 | return CMD_SUCCESS; | |
718e3744 | 5390 | } |
5391 | ||
7c8ff89e DS |
5392 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5393 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5394 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5395 | SHOW_STR |
5396 | IP_STR | |
5397 | "OSPF information\n" | |
b5a8894d CS |
5398 | VRF_CMD_HELP_STR |
5399 | "All VRFs\n" | |
718e3744 | 5400 | "Neighbor list\n" |
7c8ff89e | 5401 | "detail of all neighbors\n" |
3ac237f8 | 5402 | "include down status neighbor\n" |
9973d184 | 5403 | JSON_STR) |
718e3744 | 5404 | { |
d62a17ae | 5405 | struct ospf *ospf; |
5406 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
5407 | struct listnode *node = NULL; |
5408 | char *vrf_name = NULL; | |
5409 | bool all_vrf = FALSE; | |
5410 | int ret = CMD_SUCCESS; | |
5411 | int inst = 0; | |
5412 | int idx_vrf = 0; | |
b1c3ae8c CS |
5413 | u_char use_vrf = 0; |
5414 | json_object *json = NULL; | |
7c8ff89e | 5415 | |
43b8d1d8 | 5416 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5417 | |
b1c3ae8c CS |
5418 | if (uj) |
5419 | json = json_object_new_object(); | |
5420 | ||
b5a8894d CS |
5421 | /* vrf input is provided could be all or specific vrf*/ |
5422 | if (vrf_name) { | |
b1c3ae8c | 5423 | use_vrf = 1; |
b5a8894d CS |
5424 | if (all_vrf) { |
5425 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5426 | if (!ospf->oi_running) | |
5427 | continue; | |
5428 | ret = show_ip_ospf_neighbor_detail_all_common(vty, | |
b1c3ae8c CS |
5429 | ospf, |
5430 | json, | |
5431 | uj, | |
5432 | use_vrf); | |
b5a8894d | 5433 | } |
b1c3ae8c CS |
5434 | |
5435 | if (uj) { | |
5436 | vty_out(vty, "%s\n", | |
5437 | json_object_to_json_string_ext(json, | |
5438 | JSON_C_TO_STRING_PRETTY)); | |
5439 | json_object_free(json); | |
5440 | } | |
5441 | ||
b5a8894d CS |
5442 | return ret; |
5443 | } | |
5444 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5445 | if (ospf == NULL || !ospf->oi_running) { |
5446 | if (uj) | |
5447 | json_object_free(json); | |
b5a8894d | 5448 | return CMD_SUCCESS; |
b1c3ae8c | 5449 | } |
b5a8894d CS |
5450 | } else { |
5451 | /* Display default ospf (instance 0) info */ | |
5452 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5453 | if (ospf == NULL || !ospf->oi_running) { |
5454 | if (uj) | |
5455 | json_object_free(json); | |
b5a8894d | 5456 | return CMD_SUCCESS; |
b1c3ae8c | 5457 | } |
b5a8894d CS |
5458 | } |
5459 | ||
b1c3ae8c CS |
5460 | if (ospf) { |
5461 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5462 | uj, use_vrf); | |
5463 | if (uj) { | |
5464 | vty_out(vty, "%s\n", | |
5465 | json_object_to_json_string_ext(json, | |
5466 | JSON_C_TO_STRING_PRETTY)); | |
5467 | } | |
5468 | } | |
5469 | ||
5470 | if (uj) | |
5471 | json_object_free(json); | |
b5a8894d CS |
5472 | |
5473 | return ret; | |
7c8ff89e DS |
5474 | } |
5475 | ||
5476 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5477 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5478 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5479 | SHOW_STR |
5480 | IP_STR | |
5481 | "OSPF information\n" | |
5482 | "Instance ID\n" | |
5483 | "Neighbor list\n" | |
5484 | "detail of all neighbors\n" | |
3ac237f8 | 5485 | "include down status neighbor\n" |
9973d184 | 5486 | JSON_STR) |
7c8ff89e | 5487 | { |
d62a17ae | 5488 | int idx_number = 3; |
5489 | struct ospf *ospf; | |
5490 | u_short instance = 0; | |
5491 | u_char uj = use_json(argc, argv); | |
b1c3ae8c CS |
5492 | json_object *json = NULL; |
5493 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5494 | |
d62a17ae | 5495 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5496 | ospf = ospf_lookup_instance(instance); |
5497 | if (ospf == NULL) | |
5498 | return CMD_NOT_MY_INSTANCE; | |
5499 | ||
5500 | if (!ospf->oi_running) | |
d62a17ae | 5501 | return CMD_SUCCESS; |
7c8ff89e | 5502 | |
b1c3ae8c CS |
5503 | if (uj) |
5504 | json = json_object_new_object(); | |
5505 | ||
5506 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5507 | ||
5508 | if (uj) { | |
5509 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
5510 | JSON_C_TO_STRING_PRETTY)); | |
5511 | json_object_free(json); | |
5512 | } | |
5513 | ||
5514 | return ret; | |
7c8ff89e DS |
5515 | } |
5516 | ||
d62a17ae | 5517 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5518 | struct ospf *ospf, | |
5519 | int arg_base, | |
5520 | struct cmd_token **argv, | |
5521 | u_char use_json) | |
5522 | { | |
5523 | struct ospf_interface *oi; | |
5524 | struct interface *ifp; | |
5525 | struct route_node *rn, *nrn; | |
5526 | struct ospf_neighbor *nbr; | |
5527 | json_object *json = NULL; | |
718e3744 | 5528 | |
d62a17ae | 5529 | if (use_json) |
5530 | json = json_object_new_object(); | |
5531 | ||
5532 | if (ospf->instance) { | |
5533 | if (use_json) | |
5534 | json_object_int_add(json, "ospfInstance", | |
5535 | ospf->instance); | |
5536 | else | |
5537 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5538 | } | |
5539 | ||
b5a8894d | 5540 | ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); |
d62a17ae | 5541 | if (!ifp) { |
5542 | if (!use_json) | |
5543 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5544 | else { |
5545 | vty_out(vty, "{}\n"); | |
5546 | json_object_free(json); | |
5547 | } | |
d62a17ae | 5548 | return CMD_WARNING; |
5549 | } | |
5550 | ||
5551 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5552 | if ((oi = rn->info)) { | |
5553 | for (nrn = route_top(oi->nbrs); nrn; | |
5554 | nrn = route_next(nrn)) { | |
5555 | if ((nbr = nrn->info)) { | |
5556 | if (nbr != oi->nbr_self) { | |
5557 | if (nbr->state != NSM_Down) | |
5558 | show_ip_ospf_neighbor_detail_sub( | |
5559 | vty, oi, nbr, | |
b1c3ae8c | 5560 | json, use_json); |
d62a17ae | 5561 | } |
5562 | } | |
5563 | } | |
5564 | } | |
5565 | } | |
5566 | ||
5567 | if (use_json) { | |
9d303b37 DL |
5568 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5569 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5570 | json_object_free(json); |
5571 | } else | |
5572 | vty_out(vty, "\n"); | |
5573 | ||
5574 | return CMD_SUCCESS; | |
718e3744 | 5575 | } |
5576 | ||
7c8ff89e DS |
5577 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5578 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5579 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5580 | SHOW_STR |
5581 | IP_STR | |
5582 | "OSPF information\n" | |
5583 | "Neighbor list\n" | |
5584 | "Interface name\n" | |
3ac237f8 | 5585 | "detail of all neighbors\n" |
9973d184 | 5586 | JSON_STR) |
7c8ff89e | 5587 | { |
d62a17ae | 5588 | struct ospf *ospf; |
5589 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
5590 | struct listnode *node = NULL; |
5591 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5592 | |
b5a8894d CS |
5593 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5594 | if (!ospf->oi_running) | |
5595 | continue; | |
5596 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0, | |
5597 | argv, uj); | |
5598 | } | |
7c8ff89e | 5599 | |
b5a8894d | 5600 | return ret; |
7c8ff89e DS |
5601 | } |
5602 | ||
5603 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5604 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5605 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5606 | SHOW_STR |
5607 | IP_STR | |
5608 | "OSPF information\n" | |
5609 | "Instance ID\n" | |
5610 | "Neighbor list\n" | |
5611 | "Interface name\n" | |
3ac237f8 | 5612 | "detail of all neighbors\n" |
9973d184 | 5613 | JSON_STR) |
7c8ff89e | 5614 | { |
d62a17ae | 5615 | int idx_number = 3; |
b4e84315 | 5616 | int idx_ifname = 5; |
d62a17ae | 5617 | struct ospf *ospf; |
5618 | u_short instance = 0; | |
5619 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 5620 | |
d62a17ae | 5621 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5622 | ospf = ospf_lookup_instance(instance); |
5623 | if (ospf == NULL) | |
5624 | return CMD_NOT_MY_INSTANCE; | |
5625 | ||
5626 | if (!ospf->oi_running) | |
d62a17ae | 5627 | return CMD_SUCCESS; |
7c8ff89e | 5628 | |
b4e84315 | 5629 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, argv, uj); |
7c8ff89e | 5630 | } |
6b0655a2 | 5631 | |
718e3744 | 5632 | /* Show functions */ |
d62a17ae | 5633 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) |
5634 | { | |
5635 | struct router_lsa *rl; | |
5636 | struct summary_lsa *sl; | |
5637 | struct as_external_lsa *asel; | |
5638 | struct prefix_ipv4 p; | |
5639 | ||
5640 | if (lsa != NULL) | |
5641 | /* If self option is set, check LSA self flag. */ | |
5642 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
5643 | /* LSA common part show. */ | |
5644 | vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id)); | |
5645 | vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", | |
5646 | inet_ntoa(lsa->data->adv_router), LS_AGE(lsa), | |
5647 | (u_long)ntohl(lsa->data->ls_seqnum), | |
5648 | ntohs(lsa->data->checksum)); | |
5649 | /* LSA specific part show. */ | |
5650 | switch (lsa->data->type) { | |
5651 | case OSPF_ROUTER_LSA: | |
5652 | rl = (struct router_lsa *)lsa->data; | |
5653 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5654 | break; | |
5655 | case OSPF_SUMMARY_LSA: | |
5656 | sl = (struct summary_lsa *)lsa->data; | |
5657 | ||
5658 | p.family = AF_INET; | |
5659 | p.prefix = sl->header.id; | |
5660 | p.prefixlen = ip_masklen(sl->mask); | |
5661 | apply_mask_ipv4(&p); | |
5662 | ||
5663 | vty_out(vty, " %s/%d", inet_ntoa(p.prefix), | |
5664 | p.prefixlen); | |
5665 | break; | |
5666 | case OSPF_AS_EXTERNAL_LSA: | |
5667 | case OSPF_AS_NSSA_LSA: | |
5668 | asel = (struct as_external_lsa *)lsa->data; | |
5669 | ||
5670 | p.family = AF_INET; | |
5671 | p.prefix = asel->header.id; | |
5672 | p.prefixlen = ip_masklen(asel->mask); | |
5673 | apply_mask_ipv4(&p); | |
5674 | ||
5675 | vty_out(vty, " %s %s/%d [0x%lx]", | |
5676 | IS_EXTERNAL_METRIC(asel->e[0].tos) | |
5677 | ? "E2" | |
5678 | : "E1", | |
5679 | inet_ntoa(p.prefix), p.prefixlen, | |
5680 | (u_long)ntohl(asel->e[0].route_tag)); | |
5681 | break; | |
5682 | case OSPF_NETWORK_LSA: | |
5683 | case OSPF_ASBR_SUMMARY_LSA: | |
5684 | case OSPF_OPAQUE_LINK_LSA: | |
5685 | case OSPF_OPAQUE_AREA_LSA: | |
5686 | case OSPF_OPAQUE_AS_LSA: | |
5687 | default: | |
5688 | break; | |
5689 | } | |
5690 | vty_out(vty, "\n"); | |
5691 | } | |
718e3744 | 5692 | |
d62a17ae | 5693 | return 0; |
5694 | } | |
5695 | ||
5696 | static const char *show_database_desc[] = { | |
5697 | "unknown", | |
5698 | "Router Link States", | |
5699 | "Net Link States", | |
5700 | "Summary Link States", | |
5701 | "ASBR-Summary Link States", | |
5702 | "AS External Link States", | |
5703 | "Group Membership LSA", | |
5704 | "NSSA-external Link States", | |
5705 | "Type-8 LSA", | |
5706 | "Link-Local Opaque-LSA", | |
5707 | "Area-Local Opaque-LSA", | |
5708 | "AS-external Opaque-LSA", | |
718e3744 | 5709 | }; |
5710 | ||
d62a17ae | 5711 | static const char *show_database_header[] = { |
5712 | "", | |
5713 | "Link ID ADV Router Age Seq# CkSum Link count", | |
5714 | "Link ID ADV Router Age Seq# CkSum", | |
5715 | "Link ID ADV Router Age Seq# CkSum Route", | |
5716 | "Link ID ADV Router Age Seq# CkSum", | |
5717 | "Link ID ADV Router Age Seq# CkSum Route", | |
5718 | " --- header for Group Member ----", | |
5719 | "Link ID ADV Router Age Seq# CkSum Route", | |
5720 | " --- type-8 ---", | |
5721 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5722 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5723 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 5724 | }; |
5725 | ||
d62a17ae | 5726 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa) |
5727 | { | |
5728 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
5729 | ||
5730 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
5731 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
5732 | ospf_options_dump(lsa->data->options)); | |
5733 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
5734 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" | |
5735 | : "")); | |
5736 | ||
5737 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
5738 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
5739 | ||
5740 | if (rlsa->flags) | |
5741 | vty_out(vty, " :%s%s%s%s", | |
5742 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "", | |
5743 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "", | |
5744 | IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint" | |
5745 | : "", | |
5746 | IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut" | |
5747 | : ""); | |
5748 | ||
5749 | vty_out(vty, "\n"); | |
5750 | } | |
5751 | vty_out(vty, " LS Type: %s\n", | |
5752 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
5753 | vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id), | |
5754 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL)); | |
5755 | vty_out(vty, " Advertising Router: %s\n", | |
5756 | inet_ntoa(lsa->data->adv_router)); | |
5757 | vty_out(vty, " LS Seq Number: %08lx\n", | |
5758 | (u_long)ntohl(lsa->data->ls_seqnum)); | |
5759 | vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum)); | |
5760 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
5761 | } | |
5762 | ||
5763 | const char *link_type_desc[] = { | |
5764 | "(null)", | |
5765 | "another Router (point-to-point)", | |
5766 | "a Transit Network", | |
5767 | "Stub Network", | |
5768 | "a Virtual Link", | |
718e3744 | 5769 | }; |
5770 | ||
d62a17ae | 5771 | const char *link_id_desc[] = { |
5772 | "(null)", "Neighboring Router ID", "Designated Router address", | |
5773 | "Net", "Neighboring Router ID", | |
718e3744 | 5774 | }; |
5775 | ||
d62a17ae | 5776 | const char *link_data_desc[] = { |
5777 | "(null)", "Router Interface address", "Router Interface address", | |
5778 | "Network Mask", "Router Interface address", | |
718e3744 | 5779 | }; |
5780 | ||
5781 | /* Show router-LSA each Link information. */ | |
d62a17ae | 5782 | static void show_ip_ospf_database_router_links(struct vty *vty, |
5783 | struct router_lsa *rl) | |
5784 | { | |
5785 | int len, type; | |
5786 | unsigned int i; | |
5787 | ||
5788 | len = ntohs(rl->header.length) - 4; | |
5789 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
5790 | type = rl->link[i].type; | |
5791 | ||
5792 | vty_out(vty, " Link connected to: %s\n", | |
5793 | link_type_desc[type]); | |
5794 | vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type], | |
5795 | inet_ntoa(rl->link[i].link_id)); | |
5796 | vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type], | |
5797 | inet_ntoa(rl->link[i].link_data)); | |
5798 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
5799 | vty_out(vty, " TOS 0 Metric: %d\n", | |
5800 | ntohs(rl->link[i].metric)); | |
5801 | vty_out(vty, "\n"); | |
5802 | } | |
718e3744 | 5803 | } |
5804 | ||
5805 | /* Show router-LSA detail information. */ | |
d62a17ae | 5806 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5807 | { |
d62a17ae | 5808 | if (lsa != NULL) { |
5809 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 5810 | |
d62a17ae | 5811 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5812 | |
d62a17ae | 5813 | vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links)); |
718e3744 | 5814 | |
d62a17ae | 5815 | show_ip_ospf_database_router_links(vty, rl); |
5816 | vty_out(vty, "\n"); | |
5817 | } | |
5818 | ||
5819 | return 0; | |
718e3744 | 5820 | } |
5821 | ||
5822 | /* Show network-LSA detail information. */ | |
d62a17ae | 5823 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5824 | { |
d62a17ae | 5825 | int length, i; |
718e3744 | 5826 | |
d62a17ae | 5827 | if (lsa != NULL) { |
5828 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
718e3744 | 5829 | |
d62a17ae | 5830 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5831 | |
d62a17ae | 5832 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask)); |
718e3744 | 5833 | |
d62a17ae | 5834 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; |
718e3744 | 5835 | |
d62a17ae | 5836 | for (i = 0; length > 0; i++, length -= 4) |
5837 | vty_out(vty, " Attached Router: %s\n", | |
5838 | inet_ntoa(nl->routers[i])); | |
718e3744 | 5839 | |
d62a17ae | 5840 | vty_out(vty, "\n"); |
5841 | } | |
718e3744 | 5842 | |
d62a17ae | 5843 | return 0; |
718e3744 | 5844 | } |
5845 | ||
5846 | /* Show summary-LSA detail information. */ | |
d62a17ae | 5847 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5848 | { |
d62a17ae | 5849 | if (lsa != NULL) { |
5850 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5851 | |
d62a17ae | 5852 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5853 | |
d62a17ae | 5854 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5855 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5856 | GET_METRIC(sl->metric)); | |
5857 | vty_out(vty, "\n"); | |
5858 | } | |
718e3744 | 5859 | |
d62a17ae | 5860 | return 0; |
718e3744 | 5861 | } |
5862 | ||
5863 | /* Show summary-ASBR-LSA detail information. */ | |
d62a17ae | 5864 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5865 | { |
d62a17ae | 5866 | if (lsa != NULL) { |
5867 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5868 | |
d62a17ae | 5869 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5870 | |
d62a17ae | 5871 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5872 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5873 | GET_METRIC(sl->metric)); | |
5874 | vty_out(vty, "\n"); | |
5875 | } | |
718e3744 | 5876 | |
d62a17ae | 5877 | return 0; |
718e3744 | 5878 | } |
5879 | ||
5880 | /* Show AS-external-LSA detail information. */ | |
d62a17ae | 5881 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5882 | { | |
5883 | if (lsa != NULL) { | |
5884 | struct as_external_lsa *al = | |
5885 | (struct as_external_lsa *)lsa->data; | |
5886 | ||
5887 | show_ip_ospf_database_header(vty, lsa); | |
5888 | ||
5889 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5890 | vty_out(vty, " Metric Type: %s\n", | |
5891 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5892 | ? "2 (Larger than any link state path)" | |
5893 | : "1"); | |
5894 | vty_out(vty, " TOS: 0\n"); | |
5895 | vty_out(vty, " Metric: %d\n", | |
5896 | GET_METRIC(al->e[0].metric)); | |
5897 | vty_out(vty, " Forward Address: %s\n", | |
5898 | inet_ntoa(al->e[0].fwd_addr)); | |
5899 | ||
5900 | vty_out(vty, | |
5901 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5902 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5903 | } | |
718e3744 | 5904 | |
d62a17ae | 5905 | return 0; |
718e3744 | 5906 | } |
075e12f5 | 5907 | #if 0 |
4dadc291 | 5908 | static int |
718e3744 | 5909 | show_as_external_lsa_stdvty (struct ospf_lsa *lsa) |
5910 | { | |
5911 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; | |
5912 | ||
5913 | /* show_ip_ospf_database_header (vty, lsa); */ | |
5914 | ||
2a42e285 | 5915 | zlog_debug( " Network Mask: /%d%s", |
718e3744 | 5916 | ip_masklen (al->mask), "\n"); |
2a42e285 | 5917 | zlog_debug( " Metric Type: %s%s", |
718e3744 | 5918 | IS_EXTERNAL_METRIC (al->e[0].tos) ? |
5919 | "2 (Larger than any link state path)" : "1", "\n"); | |
2a42e285 | 5920 | zlog_debug( " TOS: 0%s", "\n"); |
5921 | zlog_debug( " Metric: %d%s", | |
718e3744 | 5922 | GET_METRIC (al->e[0].metric), "\n"); |
2a42e285 | 5923 | zlog_debug( " Forward Address: %s%s", |
718e3744 | 5924 | inet_ntoa (al->e[0].fwd_addr), "\n"); |
5925 | ||
dc9ffce8 CF |
5926 | zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s", |
5927 | (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n"); | |
718e3744 | 5928 | |
5929 | return 0; | |
5930 | } | |
075e12f5 | 5931 | #endif |
718e3744 | 5932 | /* Show AS-NSSA-LSA detail information. */ |
d62a17ae | 5933 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5934 | { | |
5935 | if (lsa != NULL) { | |
5936 | struct as_external_lsa *al = | |
5937 | (struct as_external_lsa *)lsa->data; | |
5938 | ||
5939 | show_ip_ospf_database_header(vty, lsa); | |
5940 | ||
5941 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5942 | vty_out(vty, " Metric Type: %s\n", | |
5943 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5944 | ? "2 (Larger than any link state path)" | |
5945 | : "1"); | |
5946 | vty_out(vty, " TOS: 0\n"); | |
5947 | vty_out(vty, " Metric: %d\n", | |
5948 | GET_METRIC(al->e[0].metric)); | |
5949 | vty_out(vty, " NSSA: Forward Address: %s\n", | |
5950 | inet_ntoa(al->e[0].fwd_addr)); | |
5951 | ||
5952 | vty_out(vty, | |
5953 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5954 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5955 | } | |
718e3744 | 5956 | |
d62a17ae | 5957 | return 0; |
718e3744 | 5958 | } |
5959 | ||
d62a17ae | 5960 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5961 | { |
d62a17ae | 5962 | return 0; |
718e3744 | 5963 | } |
5964 | ||
d62a17ae | 5965 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5966 | { |
d62a17ae | 5967 | if (lsa != NULL) { |
5968 | show_ip_ospf_database_header(vty, lsa); | |
5969 | show_opaque_info_detail(vty, lsa); | |
718e3744 | 5970 | |
d62a17ae | 5971 | vty_out(vty, "\n"); |
5972 | } | |
5973 | return 0; | |
5974 | } | |
5975 | ||
5976 | int (*show_function[])(struct vty *, struct ospf_lsa *) = { | |
5977 | NULL, | |
5978 | show_router_lsa_detail, | |
5979 | show_network_lsa_detail, | |
5980 | show_summary_lsa_detail, | |
5981 | show_summary_asbr_lsa_detail, | |
5982 | show_as_external_lsa_detail, | |
5983 | show_func_dummy, | |
5984 | show_as_nssa_lsa_detail, /* almost same as external */ | |
5985 | NULL, /* type-8 */ | |
5986 | show_opaque_lsa_detail, | |
5987 | show_opaque_lsa_detail, | |
5988 | show_opaque_lsa_detail, | |
5989 | }; | |
5990 | ||
5991 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
5992 | struct in_addr *id, struct in_addr *adv_router) | |
5993 | { | |
5994 | memset(lp, 0, sizeof(struct prefix_ls)); | |
5995 | lp->family = 0; | |
5996 | if (id == NULL) | |
5997 | lp->prefixlen = 0; | |
5998 | else if (adv_router == NULL) { | |
5999 | lp->prefixlen = 32; | |
6000 | lp->id = *id; | |
6001 | } else { | |
6002 | lp->prefixlen = 64; | |
6003 | lp->id = *id; | |
6004 | lp->adv_router = *adv_router; | |
6005 | } | |
718e3744 | 6006 | } |
718e3744 | 6007 | |
d62a17ae | 6008 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
6009 | struct in_addr *id, struct in_addr *adv_router) | |
6010 | { | |
6011 | struct prefix_ls lp; | |
6012 | struct route_node *rn, *start; | |
6013 | struct ospf_lsa *lsa; | |
718e3744 | 6014 | |
d62a17ae | 6015 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6016 | start = route_node_get(rt, (struct prefix *)&lp); | |
6017 | if (start) { | |
6018 | route_lock_node(start); | |
6019 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6020 | if ((lsa = rn->info)) { | |
6021 | if (show_function[lsa->data->type] != NULL) | |
6022 | show_function[lsa->data->type](vty, | |
6023 | lsa); | |
6024 | } | |
6025 | route_unlock_node(start); | |
6026 | } | |
718e3744 | 6027 | } |
6028 | ||
6029 | /* Show detail LSA information | |
6030 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6031 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
6032 | struct in_addr *id, struct in_addr *adv_router) | |
6033 | { | |
6034 | struct listnode *node; | |
6035 | struct ospf_area *area; | |
6036 | ||
6037 | switch (type) { | |
6038 | case OSPF_AS_EXTERNAL_LSA: | |
6039 | case OSPF_OPAQUE_AS_LSA: | |
6040 | vty_out(vty, " %s \n\n", | |
6041 | show_database_desc[type]); | |
6042 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router); | |
6043 | break; | |
6044 | default: | |
6045 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6046 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6047 | show_database_desc[type], | |
6048 | ospf_area_desc_string(area)); | |
6049 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, | |
6050 | adv_router); | |
6051 | } | |
6052 | break; | |
718e3744 | 6053 | } |
6054 | } | |
6055 | ||
d62a17ae | 6056 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6057 | struct route_table *rt, | |
6058 | struct in_addr *adv_router) | |
6059 | { | |
6060 | struct route_node *rn; | |
6061 | struct ospf_lsa *lsa; | |
6062 | ||
6063 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
6064 | if ((lsa = rn->info)) | |
6065 | if (IPV4_ADDR_SAME(adv_router, | |
6066 | &lsa->data->adv_router)) { | |
6067 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6068 | continue; | |
6069 | if (show_function[lsa->data->type] != NULL) | |
6070 | show_function[lsa->data->type](vty, | |
6071 | lsa); | |
6072 | } | |
6073 | } | |
6074 | ||
718e3744 | 6075 | /* Show detail LSA information. */ |
d62a17ae | 6076 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
6077 | int type, struct in_addr *adv_router) | |
6078 | { | |
6079 | struct listnode *node; | |
6080 | struct ospf_area *area; | |
6081 | ||
6082 | switch (type) { | |
6083 | case OSPF_AS_EXTERNAL_LSA: | |
6084 | case OSPF_OPAQUE_AS_LSA: | |
6085 | vty_out(vty, " %s \n\n", | |
6086 | show_database_desc[type]); | |
6087 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), | |
6088 | adv_router); | |
6089 | break; | |
6090 | default: | |
6091 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6092 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6093 | show_database_desc[type], | |
6094 | ospf_area_desc_string(area)); | |
6095 | show_lsa_detail_adv_router_proc( | |
6096 | vty, AREA_LSDB(area, type), adv_router); | |
6097 | } | |
6098 | break; | |
6099 | } | |
6100 | } | |
6101 | ||
6102 | static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, | |
6103 | int self) | |
6104 | { | |
6105 | struct ospf_lsa *lsa; | |
6106 | struct route_node *rn; | |
6107 | struct ospf_area *area; | |
6108 | struct listnode *node; | |
6109 | int type; | |
6110 | ||
6111 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6112 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6113 | switch (type) { | |
6114 | case OSPF_AS_EXTERNAL_LSA: | |
6115 | case OSPF_OPAQUE_AS_LSA: | |
6116 | continue; | |
6117 | default: | |
6118 | break; | |
6119 | } | |
6120 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6121 | || (!self | |
6122 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
6123 | vty_out(vty, " %s (Area %s)\n\n", | |
6124 | show_database_desc[type], | |
6125 | ospf_area_desc_string(area)); | |
6126 | vty_out(vty, "%s\n", | |
6127 | show_database_header[type]); | |
6128 | ||
6129 | LSDB_LOOP(AREA_LSDB(area, type), rn, lsa) | |
6130 | show_lsa_summary(vty, lsa, self); | |
6131 | ||
6132 | vty_out(vty, "\n"); | |
6133 | } | |
6134 | } | |
6135 | } | |
6136 | ||
6137 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6138 | switch (type) { | |
6139 | case OSPF_AS_EXTERNAL_LSA: | |
6140 | case OSPF_OPAQUE_AS_LSA: | |
6141 | break; | |
6142 | default: | |
6143 | continue; | |
6144 | } | |
6145 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6146 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
6147 | vty_out(vty, " %s\n\n", | |
6148 | show_database_desc[type]); | |
6149 | vty_out(vty, "%s\n", show_database_header[type]); | |
6150 | ||
6151 | LSDB_LOOP(AS_LSDB(ospf, type), rn, lsa) | |
6152 | show_lsa_summary(vty, lsa, self); | |
6153 | ||
6154 | vty_out(vty, "\n"); | |
6155 | } | |
6156 | } | |
6157 | ||
6158 | vty_out(vty, "\n"); | |
6159 | } | |
6160 | ||
6161 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) | |
6162 | { | |
6163 | struct route_node *rn; | |
6164 | ||
6165 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6166 | ||
6167 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6168 | struct ospf_lsa *lsa; | |
6169 | ||
6170 | if ((lsa = rn->info) != NULL) { | |
6171 | vty_out(vty, "Link type: %d\n", lsa->data->type); | |
6172 | vty_out(vty, "Link State ID: %s\n", | |
6173 | inet_ntoa(lsa->data->id)); | |
6174 | vty_out(vty, "Advertising Router: %s\n", | |
6175 | inet_ntoa(lsa->data->adv_router)); | |
6176 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6177 | vty_out(vty, "\n"); | |
6178 | } | |
91e6a0e5 | 6179 | } |
718e3744 | 6180 | } |
6181 | ||
718e3744 | 6182 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6183 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6184 | |
718e3744 | 6185 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6186 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6187 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6188 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6189 | |
d62a17ae | 6190 | #define OSPF_LSA_TYPES_DESC \ |
6191 | "ASBR summary link states\n" \ | |
6192 | "External link states\n" \ | |
6193 | "Network link states\n" \ | |
6194 | "Router link states\n" \ | |
6195 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6196 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6197 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6198 | ||
6199 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6200 | int arg_base, int argc, | |
b1c3ae8c CS |
6201 | struct cmd_token **argv, |
6202 | u_char use_vrf) | |
d62a17ae | 6203 | { |
6204 | int idx_type = 4; | |
6205 | int type, ret; | |
6206 | struct in_addr id, adv_router; | |
6207 | ||
6208 | if (ospf->instance) | |
6209 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6210 | ||
b1c3ae8c | 6211 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 6212 | |
d62a17ae | 6213 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6214 | inet_ntoa(ospf->router_id)); | |
6215 | ||
6216 | /* Show all LSA. */ | |
6217 | if (argc == arg_base + 4) { | |
6218 | show_ip_ospf_database_summary(vty, ospf, 0); | |
6219 | return CMD_SUCCESS; | |
6220 | } | |
718e3744 | 6221 | |
d62a17ae | 6222 | /* Set database type to show. */ |
6223 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6224 | type = OSPF_ROUTER_LSA; | |
6225 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6226 | type = OSPF_NETWORK_LSA; | |
6227 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6228 | type = OSPF_AS_NSSA_LSA; | |
6229 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
6230 | type = OSPF_SUMMARY_LSA; | |
6231 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6232 | type = OSPF_ASBR_SUMMARY_LSA; | |
6233 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6234 | type = OSPF_AS_EXTERNAL_LSA; | |
6235 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
6236 | show_ip_ospf_database_summary(vty, ospf, 1); | |
6237 | return CMD_SUCCESS; | |
6238 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
6239 | show_ip_ospf_database_maxage(vty, ospf); | |
6240 | return CMD_SUCCESS; | |
6241 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6242 | type = OSPF_OPAQUE_LINK_LSA; | |
6243 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6244 | type = OSPF_OPAQUE_AREA_LSA; | |
6245 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6246 | type = OSPF_OPAQUE_AS_LSA; | |
6247 | else | |
718e3744 | 6248 | return CMD_WARNING; |
d62a17ae | 6249 | |
6250 | /* `show ip ospf database LSA'. */ | |
6251 | if (argc == arg_base + 5) | |
6252 | show_lsa_detail(vty, ospf, type, NULL, NULL); | |
6253 | else if (argc >= arg_base + 6) { | |
6254 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
6255 | if (!ret) | |
6256 | return CMD_WARNING; | |
6257 | ||
6258 | /* `show ip ospf database LSA ID'. */ | |
6259 | if (argc == arg_base + 6) | |
6260 | show_lsa_detail(vty, ospf, type, &id, NULL); | |
6261 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ | |
6262 | else if (argc == arg_base + 7) { | |
6263 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) | |
6264 | adv_router = ospf->router_id; | |
6265 | else { | |
6266 | ret = inet_aton(argv[arg_base + 7]->arg, | |
6267 | &adv_router); | |
6268 | if (!ret) | |
6269 | return CMD_WARNING; | |
6270 | } | |
6271 | show_lsa_detail(vty, ospf, type, &id, &adv_router); | |
6272 | } | |
718e3744 | 6273 | } |
718e3744 | 6274 | |
d62a17ae | 6275 | return CMD_SUCCESS; |
718e3744 | 6276 | } |
6277 | ||
7a7be519 | 6278 | DEFUN (show_ip_ospf_database_max, |
6279 | show_ip_ospf_database_max_cmd, | |
b5a8894d | 6280 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>", |
7a7be519 | 6281 | SHOW_STR |
6282 | IP_STR | |
6283 | "OSPF information\n" | |
b5a8894d CS |
6284 | VRF_CMD_HELP_STR |
6285 | "All VRFs\n" | |
7a7be519 | 6286 | "Database summary\n" |
6287 | "LSAs in MaxAge list\n" | |
6288 | "Self-originated link states\n") | |
6289 | { | |
b5a8894d CS |
6290 | struct ospf *ospf = NULL; |
6291 | struct listnode *node = NULL; | |
6292 | char *vrf_name = NULL; | |
6293 | bool all_vrf = FALSE; | |
6294 | int ret = CMD_SUCCESS; | |
6295 | int inst = 0; | |
6296 | int idx_vrf = 0; | |
b1c3ae8c | 6297 | u_char use_vrf = 0; |
f412b39a | 6298 | |
43b8d1d8 | 6299 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 6300 | |
b5a8894d | 6301 | if (vrf_name) { |
b1c3ae8c | 6302 | use_vrf = 1; |
b5a8894d CS |
6303 | if (all_vrf) { |
6304 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6305 | if (!ospf->oi_running) | |
6306 | continue; | |
6307 | ret = show_ip_ospf_database_common(vty, ospf, | |
6308 | idx_vrf ? 2 | |
6309 | : 0, argc, | |
b1c3ae8c CS |
6310 | argv, |
6311 | use_vrf); | |
b5a8894d CS |
6312 | } |
6313 | } else { | |
6314 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
6315 | if (ospf == NULL || !ospf->oi_running) | |
6316 | return CMD_SUCCESS; | |
6317 | ret = (show_ip_ospf_database_common(vty, ospf, idx_vrf ? | |
b1c3ae8c CS |
6318 | 2 : 0, argc, argv, |
6319 | use_vrf)); | |
b5a8894d CS |
6320 | } |
6321 | } else { | |
6322 | /* Display default ospf (instance 0) info */ | |
6323 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
6324 | if (ospf == NULL || !ospf->oi_running) | |
6325 | return CMD_SUCCESS; | |
b1c3ae8c CS |
6326 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
6327 | use_vrf); | |
b5a8894d CS |
6328 | } |
6329 | ||
6330 | return ret; | |
7a7be519 | 6331 | } |
f412b39a | 6332 | |
f412b39a DW |
6333 | DEFUN (show_ip_ospf_instance_database, |
6334 | show_ip_ospf_instance_database_cmd, | |
43b8d1d8 | 6335 | "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 | 6336 | SHOW_STR |
6337 | IP_STR | |
6338 | "OSPF information\n" | |
7c8ff89e | 6339 | "Instance ID\n" |
b5a8894d | 6340 | VRF_CMD_HELP_STR |
7a7be519 | 6341 | "Database summary\n" |
6342 | OSPF_LSA_TYPES_DESC | |
6343 | "Link State ID (as an IP address)\n" | |
6344 | "Self-originated link states\n" | |
6345 | "Advertising Router link states\n" | |
6346 | "Advertising Router (as an IP address)\n") | |
7c8ff89e | 6347 | { |
d62a17ae | 6348 | struct ospf *ospf; |
6349 | u_short instance = 0; | |
b5a8894d CS |
6350 | struct listnode *node = NULL; |
6351 | char *vrf_name = NULL; | |
6352 | bool all_vrf = FALSE; | |
6353 | int ret = CMD_SUCCESS; | |
6354 | int inst = 0; | |
d62a17ae | 6355 | int idx = 0; |
b1c3ae8c | 6356 | u_char use_vrf = 0; |
b5a8894d | 6357 | |
d62a17ae | 6358 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6359 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6360 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6361 | if (ospf == NULL) |
6362 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
6363 | if (!ospf->oi_running) |
6364 | return CMD_SUCCESS; | |
6365 | ||
6366 | return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, | |
b1c3ae8c | 6367 | argc, argv, use_vrf)); |
b5a8894d CS |
6368 | } else if (argv_find(argv, argc, "vrf", &idx)) { |
6369 | vrf_name = argv[++idx]->arg; | |
6370 | all_vrf = strmatch(vrf_name, "all"); | |
d62a17ae | 6371 | } |
7c8ff89e | 6372 | |
b5a8894d | 6373 | if (vrf_name) { |
b1c3ae8c | 6374 | use_vrf = 1; |
b5a8894d CS |
6375 | if (all_vrf) { |
6376 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6377 | if (!ospf->oi_running) | |
6378 | continue; | |
6379 | ret = (show_ip_ospf_database_common(vty, ospf, | |
6380 | idx ? 2 : 0, | |
b1c3ae8c CS |
6381 | argc, argv, |
6382 | use_vrf)); | |
b5a8894d CS |
6383 | } |
6384 | } else { | |
6385 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
6386 | if ((ospf == NULL) || !ospf->oi_running) | |
6387 | return CMD_SUCCESS; | |
6388 | ret = (show_ip_ospf_database_common(vty, ospf, idx ? 2 : | |
b1c3ae8c CS |
6389 | 0, argc, argv, |
6390 | use_vrf)); | |
b5a8894d CS |
6391 | } |
6392 | } else { | |
6393 | /* Display default ospf (instance 0) info */ | |
6394 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
6395 | if (ospf == NULL || !ospf->oi_running) | |
6396 | return CMD_SUCCESS; | |
b1c3ae8c CS |
6397 | ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
6398 | use_vrf)); | |
b5a8894d | 6399 | } |
7c8ff89e | 6400 | |
b5a8894d | 6401 | return ret; |
7c8ff89e DS |
6402 | } |
6403 | ||
7a7be519 | 6404 | DEFUN (show_ip_ospf_instance_database_max, |
6405 | show_ip_ospf_instance_database_max_cmd, | |
6406 | "show ip ospf (1-65535) database <max-age|self-originate>", | |
6407 | SHOW_STR | |
6408 | IP_STR | |
6409 | "OSPF information\n" | |
6410 | "Instance ID\n" | |
6411 | "Database summary\n" | |
6412 | "LSAs in MaxAge list\n" | |
6413 | "Self-originated link states\n") | |
6414 | { | |
d62a17ae | 6415 | int idx_number = 3; |
6416 | struct ospf *ospf; | |
6417 | u_short instance = 0; | |
6418 | ||
6419 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
6420 | ||
ac28e4ec CS |
6421 | ospf = ospf_lookup_instance(instance); |
6422 | if (ospf == NULL) | |
6423 | return CMD_NOT_MY_INSTANCE; | |
6424 | ||
6425 | if (!ospf->oi_running) | |
d62a17ae | 6426 | return CMD_SUCCESS; |
6427 | ||
b1c3ae8c | 6428 | return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0); |
d62a17ae | 6429 | } |
6430 | ||
6431 | ||
6432 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
6433 | struct ospf *ospf, | |
6434 | int arg_base, int argc, | |
b1c3ae8c CS |
6435 | struct cmd_token **argv, |
6436 | u_char use_vrf) | |
d62a17ae | 6437 | { |
6438 | int idx_type = 4; | |
6439 | int type, ret; | |
6440 | struct in_addr adv_router; | |
6441 | ||
6442 | if (ospf->instance) | |
6443 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6444 | ||
b1c3ae8c | 6445 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 6446 | |
d62a17ae | 6447 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6448 | inet_ntoa(ospf->router_id)); | |
6449 | ||
6450 | /* Set database type to show. */ | |
6451 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6452 | type = OSPF_ROUTER_LSA; | |
6453 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6454 | type = OSPF_NETWORK_LSA; | |
6455 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6456 | type = OSPF_AS_NSSA_LSA; | |
6457 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
6458 | type = OSPF_SUMMARY_LSA; | |
6459 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6460 | type = OSPF_ASBR_SUMMARY_LSA; | |
6461 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6462 | type = OSPF_AS_EXTERNAL_LSA; | |
6463 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6464 | type = OSPF_OPAQUE_LINK_LSA; | |
6465 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6466 | type = OSPF_OPAQUE_AREA_LSA; | |
6467 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6468 | type = OSPF_OPAQUE_AS_LSA; | |
6469 | else | |
6470 | return CMD_WARNING; | |
7c8ff89e | 6471 | |
d62a17ae | 6472 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
6473 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
6474 | adv_router = ospf->router_id; | |
6475 | else { | |
6476 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
6477 | if (!ret) | |
6478 | return CMD_WARNING; | |
6479 | } | |
7c8ff89e | 6480 | |
d62a17ae | 6481 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router); |
7c8ff89e | 6482 | |
d62a17ae | 6483 | return CMD_SUCCESS; |
7c8ff89e DS |
6484 | } |
6485 | ||
7c8ff89e DS |
6486 | DEFUN (show_ip_ospf_instance_database_type_adv_router, |
6487 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
43b8d1d8 | 6488 | "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 |
6489 | SHOW_STR |
6490 | IP_STR | |
6491 | "OSPF information\n" | |
6492 | "Instance ID\n" | |
b5a8894d | 6493 | VRF_CMD_HELP_STR |
7c8ff89e DS |
6494 | "Database summary\n" |
6495 | OSPF_LSA_TYPES_DESC | |
6496 | "Advertising Router link states\n" | |
3a2d747c QY |
6497 | "Advertising Router (as an IP address)\n" |
6498 | "Self-originated link states\n") | |
7c8ff89e | 6499 | { |
b5a8894d | 6500 | struct ospf *ospf = NULL; |
d62a17ae | 6501 | u_short instance = 0; |
b5a8894d CS |
6502 | struct listnode *node = NULL; |
6503 | char *vrf_name = NULL; | |
6504 | bool all_vrf = FALSE; | |
6505 | int ret = CMD_SUCCESS; | |
6506 | int inst = 0; | |
43b8d1d8 | 6507 | int idx = 0, idx_vrf = 0; |
b1c3ae8c | 6508 | u_char use_vrf = 0; |
7c8ff89e | 6509 | |
d62a17ae | 6510 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6511 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6512 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6513 | if (ospf == NULL) |
6514 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
6515 | if (!ospf->oi_running) |
6516 | return CMD_SUCCESS; | |
6517 | return (show_ip_ospf_database_type_adv_router_common(vty, ospf, | |
6518 | idx ? 1 : 0, | |
6519 | argc, | |
b1c3ae8c CS |
6520 | argv, |
6521 | use_vrf)); | |
b5a8894d | 6522 | } |
43b8d1d8 CS |
6523 | |
6524 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
6525 | ||
b5a8894d | 6526 | if (vrf_name) { |
b1c3ae8c | 6527 | use_vrf = 1; |
b5a8894d CS |
6528 | if (all_vrf) { |
6529 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6530 | if (!ospf->oi_running) | |
6531 | continue; | |
6532 | ret = show_ip_ospf_database_type_adv_router_common(vty, | |
b1c3ae8c CS |
6533 | ospf, idx ? 1 : 0, argc, argv, |
6534 | use_vrf); | |
b5a8894d CS |
6535 | } |
6536 | } else { | |
6537 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
6538 | if ((ospf == NULL) || !ospf->oi_running) | |
6539 | return CMD_SUCCESS; | |
6540 | ret = show_ip_ospf_database_type_adv_router_common(vty, | |
b1c3ae8c CS |
6541 | ospf, idx ? 1 : 0, argc, argv, |
6542 | use_vrf); | |
b5a8894d CS |
6543 | } |
6544 | } else { | |
6545 | /* Display default ospf (instance 0) info */ | |
6546 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
6547 | if (ospf == NULL || !ospf->oi_running) | |
6548 | return CMD_SUCCESS; | |
6549 | ret = show_ip_ospf_database_type_adv_router_common(vty, ospf, | |
6550 | idx ? 1 : 0, | |
b1c3ae8c CS |
6551 | argc, argv, |
6552 | use_vrf); | |
b5a8894d CS |
6553 | } |
6554 | return ret; | |
6555 | /*return (show_ip_ospf_database_type_adv_router_common( | |
6556 | vty, ospf, idx ? 1 : 0, argc, argv));*/ | |
718e3744 | 6557 | } |
6558 | ||
718e3744 | 6559 | DEFUN (ip_ospf_authentication_args, |
6560 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6561 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 6562 | "IP Information\n" |
6563 | "OSPF interface commands\n" | |
6564 | "Enable authentication on this interface\n" | |
6565 | "Use null authentication\n" | |
6566 | "Use message-digest authentication\n" | |
7a7be519 | 6567 | "Address of interface\n") |
718e3744 | 6568 | { |
d62a17ae | 6569 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6570 | int idx_encryption = 3; | |
6571 | int idx_ipv4 = 4; | |
6572 | struct in_addr addr; | |
6573 | int ret; | |
6574 | struct ospf_if_params *params; | |
6575 | ||
6576 | params = IF_DEF_PARAMS(ifp); | |
6577 | ||
6578 | if (argc == 5) { | |
6579 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6580 | if (!ret) { | |
6581 | vty_out(vty, | |
6582 | "Please specify interface address by A.B.C.D\n"); | |
6583 | return CMD_WARNING_CONFIG_FAILED; | |
6584 | } | |
718e3744 | 6585 | |
d62a17ae | 6586 | params = ospf_get_if_params(ifp, addr); |
6587 | ospf_if_update_params(ifp, addr); | |
6588 | } | |
718e3744 | 6589 | |
d62a17ae | 6590 | /* Handle null authentication */ |
6591 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6592 | SET_IF_PARAM(params, auth_type); | |
6593 | params->auth_type = OSPF_AUTH_NULL; | |
6594 | return CMD_SUCCESS; | |
6595 | } | |
718e3744 | 6596 | |
d62a17ae | 6597 | /* Handle message-digest authentication */ |
6598 | if (argv[idx_encryption]->arg[0] == 'm') { | |
6599 | SET_IF_PARAM(params, auth_type); | |
6600 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6601 | return CMD_SUCCESS; | |
6602 | } | |
718e3744 | 6603 | |
d62a17ae | 6604 | vty_out(vty, "You shouldn't get here!\n"); |
6605 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 6606 | } |
6607 | ||
718e3744 | 6608 | DEFUN (ip_ospf_authentication, |
6609 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6610 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 6611 | "IP Information\n" |
6612 | "OSPF interface commands\n" | |
6613 | "Enable authentication on this interface\n" | |
efd7904e | 6614 | "Address of interface\n") |
718e3744 | 6615 | { |
d62a17ae | 6616 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6617 | int idx_ipv4 = 3; | |
6618 | struct in_addr addr; | |
6619 | int ret; | |
6620 | struct ospf_if_params *params; | |
6621 | ||
6622 | params = IF_DEF_PARAMS(ifp); | |
6623 | ||
6624 | if (argc == 4) { | |
6625 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6626 | if (!ret) { | |
6627 | vty_out(vty, | |
6628 | "Please specify interface address by A.B.C.D\n"); | |
6629 | return CMD_WARNING_CONFIG_FAILED; | |
6630 | } | |
6631 | ||
6632 | params = ospf_get_if_params(ifp, addr); | |
6633 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6634 | } |
6635 | ||
d62a17ae | 6636 | SET_IF_PARAM(params, auth_type); |
6637 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 6638 | |
d62a17ae | 6639 | return CMD_SUCCESS; |
718e3744 | 6640 | } |
6641 | ||
b4a039bf DS |
6642 | DEFUN (no_ip_ospf_authentication_args, |
6643 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6644 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
6645 | NO_STR |
6646 | "IP Information\n" | |
6647 | "OSPF interface commands\n" | |
6648 | "Enable authentication on this interface\n" | |
6649 | "Use null authentication\n" | |
6650 | "Use message-digest authentication\n" | |
efd7904e | 6651 | "Address of interface\n") |
b4a039bf | 6652 | { |
d62a17ae | 6653 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6654 | int idx_encryption = 4; | |
6655 | int idx_ipv4 = 5; | |
6656 | struct in_addr addr; | |
6657 | int ret; | |
6658 | struct ospf_if_params *params; | |
6659 | struct route_node *rn; | |
6660 | int auth_type; | |
6661 | ||
6662 | params = IF_DEF_PARAMS(ifp); | |
6663 | ||
6664 | if (argc == 6) { | |
6665 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6666 | if (!ret) { | |
6667 | vty_out(vty, | |
6668 | "Please specify interface address by A.B.C.D\n"); | |
6669 | return CMD_WARNING_CONFIG_FAILED; | |
6670 | } | |
b4a039bf | 6671 | |
d62a17ae | 6672 | params = ospf_lookup_if_params(ifp, addr); |
6673 | if (params == NULL) { | |
6674 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6675 | return CMD_WARNING_CONFIG_FAILED; | |
6676 | } | |
6677 | params->auth_type = OSPF_AUTH_NOTSET; | |
6678 | UNSET_IF_PARAM(params, auth_type); | |
6679 | if (params != IF_DEF_PARAMS(ifp)) { | |
6680 | ospf_free_if_params(ifp, addr); | |
6681 | ospf_if_update_params(ifp, addr); | |
6682 | } | |
6683 | } else { | |
6684 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6685 | auth_type = OSPF_AUTH_NULL; | |
6686 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
6687 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6688 | } else { | |
6689 | vty_out(vty, "Unexpected input encountered\n"); | |
6690 | return CMD_WARNING_CONFIG_FAILED; | |
6691 | } | |
6692 | /* | |
6693 | * Here we have a case where the user has entered | |
6694 | * 'no ip ospf authentication (null | message_digest )' | |
6695 | * we need to find if we have any ip addresses underneath it | |
6696 | * that | |
6697 | * correspond to the associated type. | |
6698 | */ | |
6699 | if (params->auth_type == auth_type) { | |
6700 | params->auth_type = OSPF_AUTH_NOTSET; | |
6701 | UNSET_IF_PARAM(params, auth_type); | |
6702 | } | |
6703 | ||
6704 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
6705 | rn = route_next(rn)) { | |
6706 | if ((params = rn->info)) { | |
6707 | if (params->auth_type == auth_type) { | |
6708 | params->auth_type = OSPF_AUTH_NOTSET; | |
6709 | UNSET_IF_PARAM(params, auth_type); | |
6710 | if (params != IF_DEF_PARAMS(ifp)) { | |
6711 | ospf_free_if_params( | |
6712 | ifp, rn->p.u.prefix4); | |
6713 | ospf_if_update_params( | |
6714 | ifp, rn->p.u.prefix4); | |
6715 | } | |
6716 | } | |
6717 | } | |
b4a039bf | 6718 | } |
b4a039bf | 6719 | } |
b4a039bf | 6720 | |
d62a17ae | 6721 | return CMD_SUCCESS; |
b4a039bf DS |
6722 | } |
6723 | ||
718e3744 | 6724 | DEFUN (no_ip_ospf_authentication, |
6725 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6726 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 6727 | NO_STR |
6728 | "IP Information\n" | |
6729 | "OSPF interface commands\n" | |
6730 | "Enable authentication on this interface\n" | |
efd7904e | 6731 | "Address of interface\n") |
718e3744 | 6732 | { |
d62a17ae | 6733 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6734 | int idx_ipv4 = 4; | |
6735 | struct in_addr addr; | |
6736 | int ret; | |
6737 | struct ospf_if_params *params; | |
6738 | struct route_node *rn; | |
6739 | ||
6740 | params = IF_DEF_PARAMS(ifp); | |
6741 | ||
6742 | if (argc == 5) { | |
6743 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6744 | if (!ret) { | |
6745 | vty_out(vty, | |
6746 | "Please specify interface address by A.B.C.D\n"); | |
6747 | return CMD_WARNING_CONFIG_FAILED; | |
6748 | } | |
718e3744 | 6749 | |
d62a17ae | 6750 | params = ospf_lookup_if_params(ifp, addr); |
6751 | if (params == NULL) { | |
6752 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6753 | return CMD_WARNING_CONFIG_FAILED; | |
6754 | } | |
718e3744 | 6755 | |
d62a17ae | 6756 | params->auth_type = OSPF_AUTH_NOTSET; |
6757 | UNSET_IF_PARAM(params, auth_type); | |
6758 | if (params != IF_DEF_PARAMS(ifp)) { | |
6759 | ospf_free_if_params(ifp, addr); | |
6760 | ospf_if_update_params(ifp, addr); | |
6761 | } | |
6762 | } else { | |
6763 | /* | |
6764 | * When a user enters 'no ip ospf authentication' | |
6765 | * We should remove all authentication types from | |
6766 | * the interface. | |
6767 | */ | |
6768 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6769 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
6770 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
6771 | params->auth_type = OSPF_AUTH_NOTSET; | |
6772 | UNSET_IF_PARAM(params, auth_type); | |
6773 | } | |
813d4307 | 6774 | |
d62a17ae | 6775 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
6776 | rn = route_next(rn)) { | |
6777 | if ((params = rn->info)) { | |
6778 | ||
6779 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6780 | || (params->auth_type | |
6781 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
6782 | || (params->auth_type | |
6783 | == OSPF_AUTH_SIMPLE)) { | |
6784 | params->auth_type = OSPF_AUTH_NOTSET; | |
6785 | UNSET_IF_PARAM(params, auth_type); | |
6786 | if (params != IF_DEF_PARAMS(ifp)) { | |
6787 | ospf_free_if_params( | |
6788 | ifp, rn->p.u.prefix4); | |
6789 | ospf_if_update_params( | |
6790 | ifp, rn->p.u.prefix4); | |
6791 | } | |
6792 | } | |
6793 | } | |
b4a039bf | 6794 | } |
b4a039bf | 6795 | } |
d62a17ae | 6796 | |
6797 | return CMD_SUCCESS; | |
718e3744 | 6798 | } |
6799 | ||
0d829fa7 | 6800 | |
718e3744 | 6801 | DEFUN (ip_ospf_authentication_key, |
6802 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 6803 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 6804 | "IP Information\n" |
6805 | "OSPF interface commands\n" | |
6806 | "Authentication password (key)\n" | |
6807 | "The OSPF password (key)\n" | |
efd7904e | 6808 | "Address of interface\n") |
718e3744 | 6809 | { |
d62a17ae | 6810 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6811 | int idx = 0; | |
6812 | struct in_addr addr; | |
6813 | struct ospf_if_params *params; | |
718e3744 | 6814 | |
d62a17ae | 6815 | params = IF_DEF_PARAMS(ifp); |
6816 | ||
6817 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6818 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6819 | vty_out(vty, | |
6820 | "Please specify interface address by A.B.C.D\n"); | |
6821 | return CMD_WARNING_CONFIG_FAILED; | |
6822 | } | |
718e3744 | 6823 | |
d62a17ae | 6824 | params = ospf_get_if_params(ifp, addr); |
6825 | ospf_if_update_params(ifp, addr); | |
6826 | } | |
718e3744 | 6827 | |
d62a17ae | 6828 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
6829 | strncpy((char *)params->auth_simple, argv[3]->arg, | |
6830 | OSPF_AUTH_SIMPLE_SIZE); | |
6831 | SET_IF_PARAM(params, auth_simple); | |
718e3744 | 6832 | |
d62a17ae | 6833 | return CMD_SUCCESS; |
718e3744 | 6834 | } |
6835 | ||
7a7be519 | 6836 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 6837 | ospf_authentication_key_cmd, |
0d829fa7 | 6838 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 6839 | "OSPF interface commands\n" |
baf9eaad | 6840 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 6841 | "Address of interface\n") |
718e3744 | 6842 | { |
d62a17ae | 6843 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 6844 | } |
6845 | ||
7a7be519 | 6846 | DEFUN (no_ip_ospf_authentication_key, |
6847 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
6848 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6849 | NO_STR | |
6850 | "IP Information\n" | |
6851 | "OSPF interface commands\n" | |
baf9eaad CS |
6852 | VLINK_HELPSTR_AUTH_SIMPLE |
6853 | "Address of interface\n") | |
7a7be519 | 6854 | { |
d62a17ae | 6855 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6856 | int idx = 0; | |
6857 | struct in_addr addr; | |
6858 | struct ospf_if_params *params; | |
6859 | params = IF_DEF_PARAMS(ifp); | |
6860 | ||
6861 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6862 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6863 | vty_out(vty, | |
6864 | "Please specify interface address by A.B.C.D\n"); | |
6865 | return CMD_WARNING_CONFIG_FAILED; | |
6866 | } | |
7a7be519 | 6867 | |
d62a17ae | 6868 | params = ospf_lookup_if_params(ifp, addr); |
6869 | if (params == NULL) | |
6870 | return CMD_SUCCESS; | |
7a7be519 | 6871 | } |
813d4307 | 6872 | |
d62a17ae | 6873 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
6874 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 6875 | |
d62a17ae | 6876 | if (params != IF_DEF_PARAMS(ifp)) { |
6877 | ospf_free_if_params(ifp, addr); | |
6878 | ospf_if_update_params(ifp, addr); | |
6879 | } | |
813d4307 | 6880 | |
d62a17ae | 6881 | return CMD_SUCCESS; |
7a7be519 | 6882 | } |
813d4307 | 6883 | |
0d829fa7 QY |
6884 | DEFUN_HIDDEN (no_ospf_authentication_key, |
6885 | no_ospf_authentication_key_authkey_addr_cmd, | |
6886 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6887 | NO_STR | |
6888 | "OSPF interface commands\n" | |
baf9eaad CS |
6889 | VLINK_HELPSTR_AUTH_SIMPLE |
6890 | "Address of interface\n") | |
0d829fa7 | 6891 | { |
d62a17ae | 6892 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
6893 | } |
6894 | ||
718e3744 | 6895 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 6896 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 6897 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 6898 | "IP Information\n" |
6899 | "OSPF interface commands\n" | |
6900 | "Message digest authentication password (key)\n" | |
6901 | "Key ID\n" | |
6902 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
6903 | "The OSPF password (key)\n" |
6904 | "Address of interface\n") | |
718e3744 | 6905 | { |
d62a17ae | 6906 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6907 | struct crypt_key *ck; | |
6908 | u_char key_id; | |
6909 | struct in_addr addr; | |
6910 | struct ospf_if_params *params; | |
6911 | ||
6912 | params = IF_DEF_PARAMS(ifp); | |
6913 | int idx = 0; | |
6914 | ||
6915 | argv_find(argv, argc, "(1-255)", &idx); | |
6916 | char *keyid = argv[idx]->arg; | |
6917 | argv_find(argv, argc, "KEY", &idx); | |
6918 | char *cryptkey = argv[idx]->arg; | |
6919 | ||
6920 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6921 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6922 | vty_out(vty, | |
6923 | "Please specify interface address by A.B.C.D\n"); | |
6924 | return CMD_WARNING_CONFIG_FAILED; | |
6925 | } | |
6926 | ||
6927 | params = ospf_get_if_params(ifp, addr); | |
6928 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6929 | } |
6930 | ||
d62a17ae | 6931 | key_id = strtol(keyid, NULL, 10); |
6932 | if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) { | |
6933 | vty_out(vty, "OSPF: Key %d already exists\n", key_id); | |
851fcbae | 6934 | return CMD_WARNING; |
d62a17ae | 6935 | } |
718e3744 | 6936 | |
d62a17ae | 6937 | ck = ospf_crypt_key_new(); |
6938 | ck->key_id = (u_char)key_id; | |
6939 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
6940 | strncpy((char *)ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE); | |
718e3744 | 6941 | |
d62a17ae | 6942 | ospf_crypt_key_add(params->auth_crypt, ck); |
6943 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 6944 | |
d62a17ae | 6945 | return CMD_SUCCESS; |
718e3744 | 6946 | } |
6947 | ||
7a7be519 | 6948 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 6949 | ospf_message_digest_key_cmd, |
0d829fa7 | 6950 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
6951 | "OSPF interface commands\n" |
6952 | "Message digest authentication password (key)\n" | |
6953 | "Key ID\n" | |
6954 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
6955 | "The OSPF password (key)\n" |
6956 | "Address of interface\n") | |
7a7be519 | 6957 | { |
d62a17ae | 6958 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 6959 | } |
718e3744 | 6960 | |
537eae3f QY |
6961 | DEFUN (no_ip_ospf_message_digest_key, |
6962 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 6963 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
6964 | NO_STR |
6965 | "IP Information\n" | |
6966 | "OSPF interface commands\n" | |
6967 | "Message digest authentication password (key)\n" | |
6968 | "Key ID\n" | |
6969 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
6970 | "The OSPF password (key)\n" |
6971 | "Address of interface\n") | |
813d4307 | 6972 | { |
d62a17ae | 6973 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6974 | int idx = 0; | |
6975 | struct crypt_key *ck; | |
6976 | int key_id; | |
6977 | struct in_addr addr; | |
6978 | struct ospf_if_params *params; | |
6979 | params = IF_DEF_PARAMS(ifp); | |
6980 | ||
6981 | argv_find(argv, argc, "(1-255)", &idx); | |
6982 | char *keyid = argv[idx]->arg; | |
6983 | ||
6984 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6985 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6986 | vty_out(vty, | |
6987 | "Please specify interface address by A.B.C.D\n"); | |
6988 | return CMD_WARNING_CONFIG_FAILED; | |
6989 | } | |
7a7be519 | 6990 | |
d62a17ae | 6991 | params = ospf_lookup_if_params(ifp, addr); |
6992 | if (params == NULL) | |
6993 | return CMD_SUCCESS; | |
7a7be519 | 6994 | } |
6995 | ||
d62a17ae | 6996 | key_id = strtol(keyid, NULL, 10); |
6997 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
6998 | if (ck == NULL) { | |
6999 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7000 | return CMD_WARNING_CONFIG_FAILED; | |
7001 | } | |
7a7be519 | 7002 | |
d62a17ae | 7003 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7004 | |
d62a17ae | 7005 | if (params != IF_DEF_PARAMS(ifp)) { |
7006 | ospf_free_if_params(ifp, addr); | |
7007 | ospf_if_update_params(ifp, addr); | |
7008 | } | |
7a7be519 | 7009 | |
d62a17ae | 7010 | return CMD_SUCCESS; |
7a7be519 | 7011 | } |
813d4307 | 7012 | |
0d829fa7 | 7013 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7014 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7015 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7016 | NO_STR | |
7017 | "OSPF interface commands\n" | |
7018 | "Message digest authentication password (key)\n" | |
7019 | "Key ID\n" | |
efd7904e RW |
7020 | "Use MD5 algorithm\n" |
7021 | "The OSPF password (key)\n" | |
7022 | "Address of interface\n") | |
718e3744 | 7023 | { |
d62a17ae | 7024 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7025 | } |
7026 | ||
718e3744 | 7027 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7028 | ip_ospf_cost_cmd, |
7a7be519 | 7029 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7030 | "IP Information\n" |
7031 | "OSPF interface commands\n" | |
7032 | "Interface cost\n" | |
7033 | "Cost\n" | |
5c2fc921 | 7034 | "Address of interface\n") |
718e3744 | 7035 | { |
d62a17ae | 7036 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7037 | int idx = 0; | |
35955c14 | 7038 | u_int32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7039 | struct in_addr addr; |
7040 | struct ospf_if_params *params; | |
7041 | params = IF_DEF_PARAMS(ifp); | |
7042 | ||
7043 | // get arguments | |
7044 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7045 | |
c31a793b VJ |
7046 | argv_find(argv, argc, "(1-65535)", &idx); |
7047 | coststr = argv[idx]->arg; | |
d62a17ae | 7048 | cost = strtol(coststr, NULL, 10); |
7049 | ||
c31a793b | 7050 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7051 | if (ifaddr) { |
7052 | if (!inet_aton(ifaddr, &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_get_if_params(ifp, addr); |
7059 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7060 | } |
7061 | ||
d62a17ae | 7062 | SET_IF_PARAM(params, output_cost_cmd); |
7063 | params->output_cost_cmd = cost; | |
718e3744 | 7064 | |
d62a17ae | 7065 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 7066 | |
d62a17ae | 7067 | return CMD_SUCCESS; |
718e3744 | 7068 | } |
7069 | ||
7a7be519 | 7070 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
7071 | ospf_cost_cmd, |
7072 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
7073 | "OSPF interface commands\n" |
7074 | "Interface cost\n" | |
7075 | "Cost\n" | |
5c2fc921 | 7076 | "Address of interface\n") |
7a7be519 | 7077 | { |
d62a17ae | 7078 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 7079 | } |
9eff36b3 | 7080 | |
718e3744 | 7081 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
7082 | no_ip_ospf_cost_cmd, |
7083 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 7084 | NO_STR |
efd7904e | 7085 | "IP Information\n" |
718e3744 | 7086 | "OSPF interface commands\n" |
7087 | "Interface cost\n" | |
efd7904e RW |
7088 | "Cost\n" |
7089 | "Address of interface\n") | |
718e3744 | 7090 | { |
d62a17ae | 7091 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7092 | int idx = 0; | |
7093 | struct in_addr addr; | |
7094 | struct ospf_if_params *params; | |
7a7be519 | 7095 | |
d62a17ae | 7096 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7097 | |
d62a17ae | 7098 | // get arguments |
7099 | char *ifaddr = NULL; | |
7100 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 7101 | |
d62a17ae | 7102 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
7103 | * always treated as "no ip ospf cost" regardless of the actual value | |
7104 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 7105 | |
d62a17ae | 7106 | if (ifaddr) { |
7107 | if (!inet_aton(ifaddr, &addr)) { | |
7108 | vty_out(vty, | |
7109 | "Please specify interface address by A.B.C.D\n"); | |
7110 | return CMD_WARNING_CONFIG_FAILED; | |
7111 | } | |
7a7be519 | 7112 | |
d62a17ae | 7113 | params = ospf_lookup_if_params(ifp, addr); |
7114 | if (params == NULL) | |
7115 | return CMD_SUCCESS; | |
7116 | } | |
7a7be519 | 7117 | |
d62a17ae | 7118 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 7119 | |
d62a17ae | 7120 | if (params != IF_DEF_PARAMS(ifp)) { |
7121 | ospf_free_if_params(ifp, addr); | |
7122 | ospf_if_update_params(ifp, addr); | |
7123 | } | |
7a7be519 | 7124 | |
d62a17ae | 7125 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 7126 | |
d62a17ae | 7127 | return CMD_SUCCESS; |
7a7be519 | 7128 | } |
9eff36b3 | 7129 | |
5c2fc921 QY |
7130 | DEFUN_HIDDEN (no_ospf_cost, |
7131 | no_ospf_cost_cmd, | |
7132 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
7133 | NO_STR | |
7134 | "OSPF interface commands\n" | |
7135 | "Interface cost\n" | |
7136 | "Cost\n" | |
7137 | "Address of interface\n") | |
827341b7 | 7138 | { |
d62a17ae | 7139 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
7140 | } |
7141 | ||
d62a17ae | 7142 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 7143 | { |
d62a17ae | 7144 | struct route_node *rn; |
7145 | struct ospf_neighbor *nbr; | |
718e3744 | 7146 | |
d62a17ae | 7147 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
7148 | if ((nbr = rn->info)) { | |
7149 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
7150 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
7151 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
7152 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
7153 | } | |
718e3744 | 7154 | } |
7155 | ||
d62a17ae | 7156 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
7157 | const char *nbr_str, | |
7158 | const char *fast_hello_str) | |
7159 | { | |
7160 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7161 | u_int32_t seconds; | |
7162 | u_char hellomult; | |
7163 | struct in_addr addr; | |
7164 | int ret; | |
7165 | struct ospf_if_params *params; | |
7166 | struct ospf_interface *oi; | |
7167 | struct route_node *rn; | |
718e3744 | 7168 | |
d62a17ae | 7169 | params = IF_DEF_PARAMS(ifp); |
7170 | ||
7171 | if (nbr_str) { | |
7172 | ret = inet_aton(nbr_str, &addr); | |
7173 | if (!ret) { | |
7174 | vty_out(vty, | |
7175 | "Please specify interface address by A.B.C.D\n"); | |
7176 | return CMD_WARNING_CONFIG_FAILED; | |
7177 | } | |
7178 | ||
7179 | params = ospf_get_if_params(ifp, addr); | |
7180 | ospf_if_update_params(ifp, addr); | |
7181 | } | |
7182 | ||
7183 | if (interval_str) { | |
7184 | seconds = strtoul(interval_str, NULL, 10); | |
7185 | ||
7186 | /* reset fast_hello too, just to be sure */ | |
7187 | UNSET_IF_PARAM(params, fast_hello); | |
7188 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7189 | } else if (fast_hello_str) { | |
7190 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
7191 | /* 1s dead-interval with sub-second hellos desired */ | |
7192 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
7193 | SET_IF_PARAM(params, fast_hello); | |
7194 | params->fast_hello = hellomult; | |
7195 | } else { | |
7196 | vty_out(vty, | |
7197 | "Please specify dead-interval or hello-multiplier\n"); | |
7198 | return CMD_WARNING_CONFIG_FAILED; | |
7199 | } | |
7200 | ||
7201 | SET_IF_PARAM(params, v_wait); | |
7202 | params->v_wait = seconds; | |
7203 | ||
7204 | /* Update timer values in neighbor structure. */ | |
7205 | if (nbr_str) { | |
b5a8894d CS |
7206 | struct ospf *ospf = NULL; |
7207 | ||
7208 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7209 | if (ospf) { | |
d62a17ae | 7210 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7211 | if (oi) | |
7212 | ospf_nbr_timer_update(oi); | |
7213 | } | |
7214 | } else { | |
7215 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7216 | if ((oi = rn->info)) | |
7217 | ospf_nbr_timer_update(oi); | |
7218 | } | |
7219 | ||
7220 | return CMD_SUCCESS; | |
718e3744 | 7221 | } |
7222 | ||
f9ad937f | 7223 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 7224 | ip_ospf_dead_interval_cmd, |
7a7be519 | 7225 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 7226 | "IP Information\n" |
7227 | "OSPF interface commands\n" | |
99a522c7 | 7228 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7229 | "Seconds\n" |
7230 | "Address of interface\n") | |
7231 | { | |
d62a17ae | 7232 | int idx = 0; |
7233 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
7234 | ? argv[idx]->arg | |
7235 | : NULL; | |
7236 | char *ifaddr = | |
7237 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
7238 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 7239 | } |
7240 | ||
718e3744 | 7241 | |
7a7be519 | 7242 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 7243 | ospf_dead_interval_cmd, |
0d829fa7 | 7244 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 7245 | "OSPF interface commands\n" |
99a522c7 | 7246 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
7247 | "Seconds\n" |
7248 | "Address of interface\n") | |
7a7be519 | 7249 | { |
d62a17ae | 7250 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 7251 | } |
718e3744 | 7252 | |
f9ad937f | 7253 | DEFUN (ip_ospf_dead_interval_minimal, |
7254 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 7255 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 7256 | "IP Information\n" |
7257 | "OSPF interface commands\n" | |
99a522c7 | 7258 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7259 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7260 | "Hello multiplier factor\n" | |
7261 | "Number of Hellos to send each second\n" | |
7262 | "Address of interface\n") | |
7263 | { | |
d62a17ae | 7264 | int idx_number = 5; |
7265 | int idx_ipv4 = 6; | |
7266 | if (argc == 7) | |
7267 | return ospf_vty_dead_interval_set( | |
7268 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
7269 | else | |
7270 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
7271 | argv[idx_number]->arg); | |
f9ad937f | 7272 | } |
7273 | ||
718e3744 | 7274 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 7275 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 7276 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 7277 | NO_STR |
7278 | "IP Information\n" | |
7279 | "OSPF interface commands\n" | |
99a522c7 | 7280 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 7281 | "Seconds\n" |
efd7904e RW |
7282 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7283 | "Hello multiplier factor\n" | |
7284 | "Number of Hellos to send each second\n" | |
7285 | "Address of interface\n") | |
718e3744 | 7286 | { |
d62a17ae | 7287 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7288 | int idx_ipv4 = argc - 1; | |
7289 | struct in_addr addr = {.s_addr = 0L}; | |
7290 | int ret; | |
7291 | struct ospf_if_params *params; | |
7292 | struct ospf_interface *oi; | |
7293 | struct route_node *rn; | |
7294 | ||
7295 | params = IF_DEF_PARAMS(ifp); | |
7296 | ||
7297 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
7298 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7299 | if (!ret) { | |
7300 | vty_out(vty, | |
7301 | "Please specify interface address by A.B.C.D\n"); | |
7302 | return CMD_WARNING_CONFIG_FAILED; | |
7303 | } | |
020709f9 | 7304 | |
d62a17ae | 7305 | params = ospf_lookup_if_params(ifp, addr); |
7306 | if (params == NULL) | |
7307 | return CMD_SUCCESS; | |
7308 | } | |
718e3744 | 7309 | |
d62a17ae | 7310 | UNSET_IF_PARAM(params, v_wait); |
7311 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
7312 | ||
7313 | UNSET_IF_PARAM(params, fast_hello); | |
7314 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7315 | ||
7316 | if (params != IF_DEF_PARAMS(ifp)) { | |
7317 | ospf_free_if_params(ifp, addr); | |
7318 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7319 | } |
7320 | ||
d62a17ae | 7321 | /* Update timer values in neighbor structure. */ |
7322 | if (argc == 1) { | |
b5a8894d | 7323 | struct ospf *ospf = NULL; |
718e3744 | 7324 | |
b5a8894d CS |
7325 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
7326 | if (ospf) { | |
d62a17ae | 7327 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7328 | if (oi) | |
7329 | ospf_nbr_timer_update(oi); | |
7330 | } | |
7331 | } else { | |
7332 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7333 | if ((oi = rn->info)) | |
7334 | ospf_nbr_timer_update(oi); | |
7335 | } | |
7336 | ||
7337 | return CMD_SUCCESS; | |
718e3744 | 7338 | } |
7339 | ||
0d829fa7 QY |
7340 | DEFUN_HIDDEN (no_ospf_dead_interval, |
7341 | no_ospf_dead_interval_cmd, | |
7342 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
7343 | NO_STR | |
7344 | "OSPF interface commands\n" | |
99a522c7 | 7345 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 7346 | "Seconds\n" |
efd7904e RW |
7347 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7348 | "Hello multiplier factor\n" | |
7349 | "Number of Hellos to send each second\n" | |
7350 | "Address of interface\n") | |
0d829fa7 | 7351 | { |
d62a17ae | 7352 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
7353 | } |
7354 | ||
718e3744 | 7355 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 7356 | ip_ospf_hello_interval_cmd, |
7a7be519 | 7357 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 7358 | "IP Information\n" |
7359 | "OSPF interface commands\n" | |
7360 | "Time between HELLO packets\n" | |
7361 | "Seconds\n" | |
0d829fa7 | 7362 | "Address of interface\n") |
718e3744 | 7363 | { |
d62a17ae | 7364 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7365 | int idx = 0; | |
7366 | struct in_addr addr; | |
7367 | struct ospf_if_params *params; | |
7368 | params = IF_DEF_PARAMS(ifp); | |
7369 | u_int32_t seconds = 0; | |
7370 | ||
7371 | argv_find(argv, argc, "(1-65535)", &idx); | |
7372 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7373 | ||
7374 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7375 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7376 | vty_out(vty, | |
7377 | "Please specify interface address by A.B.C.D\n"); | |
7378 | return CMD_WARNING_CONFIG_FAILED; | |
7379 | } | |
718e3744 | 7380 | |
d62a17ae | 7381 | params = ospf_get_if_params(ifp, addr); |
7382 | ospf_if_update_params(ifp, addr); | |
7383 | } | |
718e3744 | 7384 | |
d62a17ae | 7385 | SET_IF_PARAM(params, v_hello); |
7386 | params->v_hello = seconds; | |
718e3744 | 7387 | |
d62a17ae | 7388 | return CMD_SUCCESS; |
718e3744 | 7389 | } |
7390 | ||
7a7be519 | 7391 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 7392 | ospf_hello_interval_cmd, |
0d829fa7 | 7393 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
7394 | "OSPF interface commands\n" |
7395 | "Time between HELLO packets\n" | |
0d829fa7 QY |
7396 | "Seconds\n" |
7397 | "Address of interface\n") | |
7a7be519 | 7398 | { |
d62a17ae | 7399 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 7400 | } |
718e3744 | 7401 | |
7402 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
7403 | no_ip_ospf_hello_interval_cmd, |
7404 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 7405 | NO_STR |
7406 | "IP Information\n" | |
7407 | "OSPF interface commands\n" | |
0d829fa7 | 7408 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 7409 | "Seconds\n" |
0d829fa7 | 7410 | "Address of interface\n") |
718e3744 | 7411 | { |
d62a17ae | 7412 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7413 | int idx = 0; | |
7414 | struct in_addr addr; | |
7415 | struct ospf_if_params *params; | |
df581cd3 | 7416 | |
d62a17ae | 7417 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7418 | |
d62a17ae | 7419 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7420 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7421 | vty_out(vty, | |
7422 | "Please specify interface address by A.B.C.D\n"); | |
7423 | return CMD_WARNING_CONFIG_FAILED; | |
7424 | } | |
718e3744 | 7425 | |
d62a17ae | 7426 | params = ospf_lookup_if_params(ifp, addr); |
7427 | if (params == NULL) | |
7428 | return CMD_SUCCESS; | |
7429 | } | |
718e3744 | 7430 | |
d62a17ae | 7431 | UNSET_IF_PARAM(params, v_hello); |
7432 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 7433 | |
d62a17ae | 7434 | if (params != IF_DEF_PARAMS(ifp)) { |
7435 | ospf_free_if_params(ifp, addr); | |
7436 | ospf_if_update_params(ifp, addr); | |
7437 | } | |
718e3744 | 7438 | |
d62a17ae | 7439 | return CMD_SUCCESS; |
718e3744 | 7440 | } |
7441 | ||
0d829fa7 QY |
7442 | DEFUN_HIDDEN (no_ospf_hello_interval, |
7443 | no_ospf_hello_interval_cmd, | |
7444 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
7445 | NO_STR | |
7446 | "OSPF interface commands\n" | |
7447 | "Time between HELLO packets\n" // ignored | |
7448 | "Seconds\n" | |
7449 | "Address of interface\n") | |
7450 | { | |
d62a17ae | 7451 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 7452 | } |
718e3744 | 7453 | |
7454 | DEFUN (ip_ospf_network, | |
7455 | ip_ospf_network_cmd, | |
6147e2c6 | 7456 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
718e3744 | 7457 | "IP Information\n" |
7458 | "OSPF interface commands\n" | |
7459 | "Network type\n" | |
7460 | "Specify OSPF broadcast multi-access network\n" | |
7461 | "Specify OSPF NBMA network\n" | |
7462 | "Specify OSPF point-to-multipoint network\n" | |
7463 | "Specify OSPF point-to-point network\n") | |
7464 | { | |
d62a17ae | 7465 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7466 | int idx = 0; | |
7467 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7468 | struct route_node *rn; | |
718e3744 | 7469 | |
d62a17ae | 7470 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
7471 | vty_out(vty, | |
7472 | "This is a loopback interface. Can't set network type.\n"); | |
7473 | return CMD_WARNING_CONFIG_FAILED; | |
7474 | } | |
718e3744 | 7475 | |
d62a17ae | 7476 | if (argv_find(argv, argc, "broadcast", &idx)) |
7477 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
7478 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
7479 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
7480 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
7481 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
7482 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
7483 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
718e3744 | 7484 | |
d62a17ae | 7485 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7486 | return CMD_SUCCESS; | |
7487 | ||
7488 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
7489 | ||
7490 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7491 | struct ospf_interface *oi = rn->info; | |
7492 | ||
7493 | if (!oi) | |
7494 | continue; | |
7495 | ||
7496 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
7497 | ||
7498 | if (oi->state > ISM_Down) { | |
7499 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7500 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7501 | } | |
7a7be519 | 7502 | } |
7a7be519 | 7503 | |
d62a17ae | 7504 | return CMD_SUCCESS; |
7a7be519 | 7505 | } |
7506 | ||
7507 | DEFUN_HIDDEN (ospf_network, | |
7508 | ospf_network_cmd, | |
e83a9414 | 7509 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 7510 | "OSPF interface commands\n" |
7511 | "Network type\n" | |
7512 | "Specify OSPF broadcast multi-access network\n" | |
7513 | "Specify OSPF NBMA network\n" | |
7514 | "Specify OSPF point-to-multipoint network\n" | |
7515 | "Specify OSPF point-to-point network\n") | |
7516 | { | |
d62a17ae | 7517 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 7518 | } |
7519 | ||
7520 | DEFUN (no_ip_ospf_network, | |
7521 | no_ip_ospf_network_cmd, | |
7522 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7523 | NO_STR | |
7524 | "IP Information\n" | |
7525 | "OSPF interface commands\n" | |
7526 | "Network type\n" | |
7527 | "Specify OSPF broadcast multi-access network\n" | |
7528 | "Specify OSPF NBMA network\n" | |
7529 | "Specify OSPF point-to-multipoint network\n" | |
7530 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 7531 | { |
d62a17ae | 7532 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7533 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7534 | struct route_node *rn; | |
7a7be519 | 7535 | |
d62a17ae | 7536 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
7a7be519 | 7537 | |
d62a17ae | 7538 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7539 | return CMD_SUCCESS; | |
7a7be519 | 7540 | |
d62a17ae | 7541 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7542 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7543 | |
d62a17ae | 7544 | if (!oi) |
7545 | continue; | |
7a7be519 | 7546 | |
d62a17ae | 7547 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 7548 | |
d62a17ae | 7549 | if (oi->state > ISM_Down) { |
7550 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7551 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7552 | } | |
7a7be519 | 7553 | } |
7a7be519 | 7554 | |
d62a17ae | 7555 | return CMD_SUCCESS; |
7a7be519 | 7556 | } |
7557 | ||
0d829fa7 QY |
7558 | DEFUN_HIDDEN (no_ospf_network, |
7559 | no_ospf_network_cmd, | |
7560 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7561 | NO_STR | |
7562 | "OSPF interface commands\n" | |
7563 | "Network type\n" | |
7564 | "Specify OSPF broadcast multi-access network\n" | |
7565 | "Specify OSPF NBMA network\n" | |
7566 | "Specify OSPF point-to-multipoint network\n" | |
7567 | "Specify OSPF point-to-point network\n") | |
7568 | { | |
d62a17ae | 7569 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
7570 | } |
7571 | ||
7a7be519 | 7572 | DEFUN (ip_ospf_priority, |
537eae3f | 7573 | ip_ospf_priority_cmd, |
7a7be519 | 7574 | "ip ospf priority (0-255) [A.B.C.D]", |
7575 | "IP Information\n" | |
7576 | "OSPF interface commands\n" | |
7577 | "Router priority\n" | |
7578 | "Priority\n" | |
efd7904e | 7579 | "Address of interface\n") |
7a7be519 | 7580 | { |
d62a17ae | 7581 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7582 | int idx = 0; | |
7583 | long priority; | |
7584 | struct route_node *rn; | |
7585 | struct in_addr addr; | |
7586 | struct ospf_if_params *params; | |
7587 | params = IF_DEF_PARAMS(ifp); | |
7588 | ||
7589 | argv_find(argv, argc, "(0-255)", &idx); | |
7590 | priority = strtol(argv[idx]->arg, NULL, 10); | |
7591 | ||
7592 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7593 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7594 | vty_out(vty, | |
7595 | "Please specify interface address by A.B.C.D\n"); | |
7596 | return CMD_WARNING_CONFIG_FAILED; | |
7597 | } | |
7a7be519 | 7598 | |
d62a17ae | 7599 | params = ospf_get_if_params(ifp, addr); |
7600 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 7601 | } |
7602 | ||
d62a17ae | 7603 | SET_IF_PARAM(params, priority); |
7604 | params->priority = priority; | |
7a7be519 | 7605 | |
d62a17ae | 7606 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7607 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7608 | |
d62a17ae | 7609 | if (!oi) |
7610 | continue; | |
7a7be519 | 7611 | |
d62a17ae | 7612 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
7613 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7614 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7615 | } | |
718e3744 | 7616 | } |
718e3744 | 7617 | |
d62a17ae | 7618 | return CMD_SUCCESS; |
718e3744 | 7619 | } |
7620 | ||
7a7be519 | 7621 | DEFUN_HIDDEN (ospf_priority, |
7622 | ospf_priority_cmd, | |
0d829fa7 | 7623 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 7624 | "OSPF interface commands\n" |
7625 | "Router priority\n" | |
3a2d747c | 7626 | "Priority\n" |
efd7904e | 7627 | "Address of interface\n") |
718e3744 | 7628 | { |
d62a17ae | 7629 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 7630 | } |
7631 | ||
718e3744 | 7632 | DEFUN (no_ip_ospf_priority, |
537eae3f | 7633 | no_ip_ospf_priority_cmd, |
7a7be519 | 7634 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 7635 | NO_STR |
7636 | "IP Information\n" | |
7637 | "OSPF interface commands\n" | |
0d829fa7 | 7638 | "Router priority\n" // ignored |
813d4307 | 7639 | "Priority\n" |
efd7904e | 7640 | "Address of interface\n") |
718e3744 | 7641 | { |
d62a17ae | 7642 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7643 | int idx = 0; | |
7644 | struct route_node *rn; | |
7645 | struct in_addr addr; | |
7646 | struct ospf_if_params *params; | |
7647 | ||
7648 | params = IF_DEF_PARAMS(ifp); | |
7649 | ||
7650 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7651 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7652 | vty_out(vty, | |
7653 | "Please specify interface address by A.B.C.D\n"); | |
7654 | return CMD_WARNING_CONFIG_FAILED; | |
7655 | } | |
7656 | ||
7657 | params = ospf_lookup_if_params(ifp, addr); | |
7658 | if (params == NULL) | |
7659 | return CMD_SUCCESS; | |
718e3744 | 7660 | } |
7661 | ||
d62a17ae | 7662 | UNSET_IF_PARAM(params, priority); |
7663 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
7664 | ||
7665 | if (params != IF_DEF_PARAMS(ifp)) { | |
7666 | ospf_free_if_params(ifp, addr); | |
7667 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7668 | } |
d62a17ae | 7669 | |
7670 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7671 | struct ospf_interface *oi = rn->info; | |
7672 | ||
7673 | if (!oi) | |
7674 | continue; | |
7675 | ||
7676 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7677 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7678 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7679 | } | |
7680 | } | |
7681 | ||
7682 | return CMD_SUCCESS; | |
718e3744 | 7683 | } |
7684 | ||
0d829fa7 | 7685 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 7686 | no_ospf_priority_cmd, |
0d829fa7 QY |
7687 | "no ospf priority [(0-255) [A.B.C.D]]", |
7688 | NO_STR | |
7689 | "OSPF interface commands\n" | |
7690 | "Router priority\n" | |
7691 | "Priority\n" | |
efd7904e | 7692 | "Address of interface\n") |
0d829fa7 | 7693 | { |
d62a17ae | 7694 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 7695 | } |
a1afa410 | 7696 | |
718e3744 | 7697 | DEFUN (ip_ospf_retransmit_interval, |
7698 | ip_ospf_retransmit_interval_addr_cmd, | |
7a7be519 | 7699 | "ip ospf retransmit-interval (3-65535) [A.B.C.D]", |
718e3744 | 7700 | "IP Information\n" |
7701 | "OSPF interface commands\n" | |
7702 | "Time between retransmitting lost link state advertisements\n" | |
7703 | "Seconds\n" | |
efd7904e | 7704 | "Address of interface\n") |
718e3744 | 7705 | { |
d62a17ae | 7706 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7707 | int idx = 0; | |
7708 | u_int32_t seconds; | |
7709 | struct in_addr addr; | |
7710 | struct ospf_if_params *params; | |
7711 | params = IF_DEF_PARAMS(ifp); | |
7712 | ||
7713 | argv_find(argv, argc, "(3-65535)", &idx); | |
7714 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7715 | ||
7716 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7717 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7718 | vty_out(vty, | |
7719 | "Please specify interface address by A.B.C.D\n"); | |
7720 | return CMD_WARNING_CONFIG_FAILED; | |
7721 | } | |
718e3744 | 7722 | |
d62a17ae | 7723 | params = ospf_get_if_params(ifp, addr); |
7724 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7725 | } |
7726 | ||
d62a17ae | 7727 | SET_IF_PARAM(params, retransmit_interval); |
7728 | params->retransmit_interval = seconds; | |
718e3744 | 7729 | |
d62a17ae | 7730 | return CMD_SUCCESS; |
718e3744 | 7731 | } |
7732 | ||
7a7be519 | 7733 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 7734 | ospf_retransmit_interval_cmd, |
0d829fa7 | 7735 | "ospf retransmit-interval (3-65535) [A.B.C.D]", |
747e489c DW |
7736 | "OSPF interface commands\n" |
7737 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 7738 | "Seconds\n" |
efd7904e | 7739 | "Address of interface\n") |
7a7be519 | 7740 | { |
d62a17ae | 7741 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 7742 | } |
718e3744 | 7743 | |
7744 | DEFUN (no_ip_ospf_retransmit_interval, | |
7745 | no_ip_ospf_retransmit_interval_addr_cmd, | |
0d829fa7 | 7746 | "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]", |
718e3744 | 7747 | NO_STR |
7748 | "IP Information\n" | |
7749 | "OSPF interface commands\n" | |
3a2d747c QY |
7750 | "Time between retransmitting lost link state advertisements\n" |
7751 | "Seconds\n" | |
0d829fa7 | 7752 | "Address of interface\n") |
718e3744 | 7753 | { |
d62a17ae | 7754 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7755 | int idx = 0; | |
7756 | struct in_addr addr; | |
7757 | struct ospf_if_params *params; | |
47b91972 | 7758 | |
d62a17ae | 7759 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7760 | |
d62a17ae | 7761 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7762 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7763 | vty_out(vty, | |
7764 | "Please specify interface address by A.B.C.D\n"); | |
7765 | return CMD_WARNING_CONFIG_FAILED; | |
7766 | } | |
718e3744 | 7767 | |
d62a17ae | 7768 | params = ospf_lookup_if_params(ifp, addr); |
7769 | if (params == NULL) | |
7770 | return CMD_SUCCESS; | |
7771 | } | |
718e3744 | 7772 | |
d62a17ae | 7773 | UNSET_IF_PARAM(params, retransmit_interval); |
7774 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 7775 | |
d62a17ae | 7776 | if (params != IF_DEF_PARAMS(ifp)) { |
7777 | ospf_free_if_params(ifp, addr); | |
7778 | ospf_if_update_params(ifp, addr); | |
7779 | } | |
718e3744 | 7780 | |
d62a17ae | 7781 | return CMD_SUCCESS; |
718e3744 | 7782 | } |
7783 | ||
0d829fa7 QY |
7784 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
7785 | no_ospf_retransmit_interval_cmd, | |
7786 | "no ospf retransmit-interval [(3-65535)] [A.B.C.D]", | |
7787 | NO_STR | |
7788 | "OSPF interface commands\n" | |
3a2d747c QY |
7789 | "Time between retransmitting lost link state advertisements\n" |
7790 | "Seconds\n" | |
7791 | "Address of interface\n") | |
0d829fa7 | 7792 | { |
d62a17ae | 7793 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 7794 | } |
813d4307 | 7795 | |
718e3744 | 7796 | DEFUN (ip_ospf_transmit_delay, |
7797 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 7798 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 7799 | "IP Information\n" |
7800 | "OSPF interface commands\n" | |
7801 | "Link state transmit delay\n" | |
7802 | "Seconds\n" | |
efd7904e | 7803 | "Address of interface\n") |
718e3744 | 7804 | { |
d62a17ae | 7805 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7806 | int idx = 0; | |
7807 | u_int32_t seconds; | |
7808 | struct in_addr addr; | |
7809 | struct ospf_if_params *params; | |
7810 | ||
7811 | params = IF_DEF_PARAMS(ifp); | |
7812 | argv_find(argv, argc, "(1-65535)", &idx); | |
7813 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7814 | ||
7815 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7816 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7817 | vty_out(vty, | |
7818 | "Please specify interface address by A.B.C.D\n"); | |
7819 | return CMD_WARNING_CONFIG_FAILED; | |
7820 | } | |
718e3744 | 7821 | |
d62a17ae | 7822 | params = ospf_get_if_params(ifp, addr); |
7823 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7824 | } |
7825 | ||
d62a17ae | 7826 | SET_IF_PARAM(params, transmit_delay); |
7827 | params->transmit_delay = seconds; | |
718e3744 | 7828 | |
d62a17ae | 7829 | return CMD_SUCCESS; |
718e3744 | 7830 | } |
7831 | ||
7a7be519 | 7832 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 7833 | ospf_transmit_delay_cmd, |
0d829fa7 | 7834 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
7835 | "OSPF interface commands\n" |
7836 | "Link state transmit delay\n" | |
3a2d747c | 7837 | "Seconds\n" |
efd7904e | 7838 | "Address of interface\n") |
7a7be519 | 7839 | { |
d62a17ae | 7840 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 7841 | } |
718e3744 | 7842 | |
7843 | DEFUN (no_ip_ospf_transmit_delay, | |
7844 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 7845 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 7846 | NO_STR |
7847 | "IP Information\n" | |
7848 | "OSPF interface commands\n" | |
7849 | "Link state transmit delay\n" | |
efd7904e RW |
7850 | "Seconds\n" |
7851 | "Address of interface\n") | |
718e3744 | 7852 | { |
d62a17ae | 7853 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7854 | int idx = 0; | |
7855 | struct in_addr addr; | |
7856 | struct ospf_if_params *params; | |
718e3744 | 7857 | |
d62a17ae | 7858 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7859 | |
d62a17ae | 7860 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7861 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7862 | vty_out(vty, | |
7863 | "Please specify interface address by A.B.C.D\n"); | |
7864 | return CMD_WARNING_CONFIG_FAILED; | |
7865 | } | |
718e3744 | 7866 | |
d62a17ae | 7867 | params = ospf_lookup_if_params(ifp, addr); |
7868 | if (params == NULL) | |
7869 | return CMD_SUCCESS; | |
7870 | } | |
718e3744 | 7871 | |
d62a17ae | 7872 | UNSET_IF_PARAM(params, transmit_delay); |
7873 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 7874 | |
d62a17ae | 7875 | if (params != IF_DEF_PARAMS(ifp)) { |
7876 | ospf_free_if_params(ifp, addr); | |
7877 | ospf_if_update_params(ifp, addr); | |
7878 | } | |
7879 | ||
7880 | return CMD_SUCCESS; | |
718e3744 | 7881 | } |
7882 | ||
813d4307 | 7883 | |
0d829fa7 QY |
7884 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
7885 | no_ospf_transmit_delay_cmd, | |
32573073 | 7886 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
7887 | NO_STR |
7888 | "OSPF interface commands\n" | |
32573073 QY |
7889 | "Link state transmit delay\n" |
7890 | "Seconds\n" | |
efd7904e | 7891 | "Address of interface\n") |
813d4307 | 7892 | { |
d62a17ae | 7893 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
7894 | } |
7895 | ||
e723861d DS |
7896 | DEFUN (ip_ospf_area, |
7897 | ip_ospf_area_cmd, | |
52c62ab8 | 7898 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
7899 | "IP Information\n" |
7900 | "OSPF interface commands\n" | |
7a7be519 | 7901 | "Instance ID\n" |
e723861d DS |
7902 | "Enable OSPF on this interface\n" |
7903 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
7904 | "OSPF area ID as a decimal value\n" |
7905 | "Address of interface\n") | |
e723861d | 7906 | { |
d62a17ae | 7907 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7908 | int idx = 0; | |
7909 | int format, ret; | |
7910 | struct in_addr area_id; | |
7911 | struct in_addr addr; | |
35955c14 | 7912 | struct ospf_if_params *params = NULL; |
d62a17ae | 7913 | struct route_node *rn; |
b5a8894d | 7914 | struct ospf *ospf = NULL; |
d62a17ae | 7915 | u_short instance = 0; |
7916 | char *areaid; | |
7917 | ||
7918 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
7919 | instance = strtol(argv[idx]->arg, NULL, 10); | |
7920 | ||
7921 | argv_find(argv, argc, "area", &idx); | |
7922 | areaid = argv[idx + 1]->arg; | |
7923 | ||
b5a8894d CS |
7924 | if (ifp->vrf_id && !instance) |
7925 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7926 | else | |
7927 | ospf = ospf_lookup_instance(instance); | |
7928 | ||
d62a17ae | 7929 | if (ospf == NULL) { |
7930 | params = IF_DEF_PARAMS(ifp); | |
7931 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7932 | UNSET_IF_PARAM(params, if_area); | |
b5a8894d CS |
7933 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
7934 | ospf_interface_area_unset(ospf, ifp); | |
d62a17ae | 7935 | ospf->if_ospf_cli_count--; |
7936 | } | |
ac28e4ec | 7937 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 7938 | } |
e723861d | 7939 | |
d62a17ae | 7940 | ret = str2area_id(areaid, &area_id, &format); |
7941 | if (ret < 0) { | |
7942 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
7943 | return CMD_WARNING_CONFIG_FAILED; | |
7944 | } | |
7945 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
7946 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
7947 | return CMD_WARNING_CONFIG_FAILED; | |
7948 | } | |
7949 | ||
7950 | params = IF_DEF_PARAMS(ifp); | |
7951 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
7952 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
7953 | vty_out(vty, | |
7954 | "Must remove previous area config before changing ospf area \n"); | |
7955 | return CMD_WARNING_CONFIG_FAILED; | |
7956 | } | |
7957 | ||
7958 | // Check if we have an address arg and proccess it | |
7959 | if (argc == idx + 3) { | |
cc9b06ad DS |
7960 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
7961 | vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); | |
7962 | return CMD_WARNING_CONFIG_FAILED; | |
7963 | } | |
d62a17ae | 7964 | // update/create address-level params |
7965 | params = ospf_get_if_params((ifp), (addr)); | |
7966 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7967 | vty_out(vty, | |
7968 | "Must remove previous area/address config before changing ospf area"); | |
7969 | return CMD_WARNING_CONFIG_FAILED; | |
7970 | } | |
7971 | ospf_if_update_params((ifp), (addr)); | |
7972 | } | |
7973 | ||
7974 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
7975 | if (rn->info != NULL) { | |
7976 | vty_out(vty, | |
7977 | "Please remove all network commands first.\n"); | |
7978 | return CMD_WARNING_CONFIG_FAILED; | |
7979 | } | |
7980 | } | |
7981 | ||
7982 | /* enable ospf on this interface with area_id */ | |
35955c14 CS |
7983 | if (params) { |
7984 | SET_IF_PARAM(params, if_area); | |
7985 | params->if_area = area_id; | |
7986 | params->if_area_id_fmt = format; | |
7987 | } | |
b5a8894d | 7988 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 7989 | ospf->if_ospf_cli_count++; |
7990 | ||
7991 | return CMD_SUCCESS; | |
e723861d DS |
7992 | } |
7993 | ||
7994 | DEFUN (no_ip_ospf_area, | |
7995 | no_ip_ospf_area_cmd, | |
52c62ab8 | 7996 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
7997 | NO_STR |
7998 | "IP Information\n" | |
7999 | "OSPF interface commands\n" | |
3a2d747c | 8000 | "Instance ID\n" |
7a7be519 | 8001 | "Disable OSPF on this interface\n" |
8002 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8003 | "OSPF area ID as a decimal value\n" |
8004 | "Address of interface\n") | |
e723861d | 8005 | { |
d62a17ae | 8006 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8007 | int idx = 0; | |
8008 | struct ospf *ospf; | |
8009 | struct ospf_if_params *params; | |
8010 | u_short instance = 0; | |
8011 | struct in_addr addr; | |
8012 | ||
8013 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8014 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8015 | ||
b5a8894d CS |
8016 | if (ifp->vrf_id && !instance) |
8017 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
8018 | else | |
8019 | ospf = ospf_lookup_instance(instance); | |
8020 | ||
ac28e4ec CS |
8021 | if (ospf == NULL) |
8022 | return CMD_NOT_MY_INSTANCE; | |
d62a17ae | 8023 | |
8024 | argv_find(argv, argc, "area", &idx); | |
8025 | ||
8026 | // Check if we have an address arg and proccess it | |
8027 | if (argc == idx + 3) { | |
cc9b06ad DS |
8028 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
8029 | vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); | |
8030 | return CMD_WARNING_CONFIG_FAILED; | |
8031 | } | |
d62a17ae | 8032 | params = ospf_lookup_if_params(ifp, addr); |
8033 | if ((params) == NULL) | |
8034 | return CMD_SUCCESS; | |
8035 | } else | |
8036 | params = IF_DEF_PARAMS(ifp); | |
8037 | ||
8038 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8039 | vty_out(vty, | |
8040 | "Can't find specified interface area configuration.\n"); | |
8041 | return CMD_WARNING_CONFIG_FAILED; | |
8042 | } | |
813d4307 | 8043 | |
d62a17ae | 8044 | UNSET_IF_PARAM(params, if_area); |
8045 | if (params != IF_DEF_PARAMS((ifp))) { | |
8046 | ospf_free_if_params((ifp), (addr)); | |
8047 | ospf_if_update_params((ifp), (addr)); | |
8048 | } | |
8049 | ||
b5a8894d | 8050 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8051 | ospf->if_ospf_cli_count--; |
8052 | return CMD_SUCCESS; | |
813d4307 DW |
8053 | } |
8054 | ||
6f2a6703 CF |
8055 | DEFUN (ospf_redistribute_source, |
8056 | ospf_redistribute_source_cmd, | |
40d1cbfb | 8057 | "redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
d1c65c21 | 8058 | REDIST_STR |
ab0181ee | 8059 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 8060 | "Metric for redistributed routes\n" |
8061 | "OSPF default metric\n" | |
8062 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8063 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8064 | "Route map reference\n" |
8065 | "Pointer to route-map entries\n") | |
8066 | { | |
a3d826f0 | 8067 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8068 | int idx_protocol = 1; |
8069 | int source; | |
8070 | int type = -1; | |
8071 | int metric = -1; | |
8072 | struct ospf_redist *red; | |
8073 | int idx = 0; | |
6f2a6703 | 8074 | |
d62a17ae | 8075 | if (!ospf) |
8076 | return CMD_SUCCESS; | |
8077 | ||
8078 | /* Get distribute source. */ | |
8079 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
8080 | if (source < 0) | |
8081 | return CMD_WARNING_CONFIG_FAILED; | |
8082 | ||
8083 | red = ospf_redist_add(ospf, source, 0); | |
8084 | ||
8085 | /* Get metric value. */ | |
8086 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
8087 | if (!str2metric(argv[idx]->arg, &metric)) | |
8088 | return CMD_WARNING_CONFIG_FAILED; | |
8089 | } | |
8090 | /* Get metric type. */ | |
8091 | else if (argv_find(argv, argc, "(1-2)", &idx)) { | |
8092 | if (!str2metric_type(argv[idx]->arg, &type)) | |
8093 | return CMD_WARNING_CONFIG_FAILED; | |
8094 | } | |
8095 | /* Get route-map */ | |
8096 | else if (argv_find(argv, argc, "WORD", &idx)) { | |
8097 | ospf_routemap_set(red, argv[idx]->arg); | |
8098 | } else | |
8099 | ospf_routemap_unset(red); | |
7c8ff89e | 8100 | |
d62a17ae | 8101 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 8102 | } |
8103 | ||
718e3744 | 8104 | DEFUN (no_ospf_redistribute_source, |
8105 | no_ospf_redistribute_source_cmd, | |
40d1cbfb | 8106 | "no redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 8107 | NO_STR |
d1c65c21 | 8108 | REDIST_STR |
ab0181ee | 8109 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
8110 | "Metric for redistributed routes\n" |
8111 | "OSPF default metric\n" | |
8112 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8113 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8114 | "Route map reference\n" |
8115 | "Pointer to route-map entries\n") | |
718e3744 | 8116 | { |
a3d826f0 | 8117 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8118 | int idx_protocol = 2; |
8119 | int source; | |
8120 | struct ospf_redist *red; | |
718e3744 | 8121 | |
d62a17ae | 8122 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
8123 | if (source < 0) | |
8124 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8125 | |
d62a17ae | 8126 | red = ospf_redist_lookup(ospf, source, 0); |
8127 | if (!red) | |
8128 | return CMD_SUCCESS; | |
7c8ff89e | 8129 | |
d62a17ae | 8130 | ospf_routemap_unset(red); |
8131 | return ospf_redistribute_unset(ospf, source, 0); | |
7c8ff89e DS |
8132 | } |
8133 | ||
8134 | DEFUN (ospf_redistribute_instance_source, | |
8135 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8136 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8137 | REDIST_STR |
8138 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8139 | "Non-main Kernel Routing Table\n" |
8140 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
8141 | "Metric for redistributed routes\n" |
8142 | "OSPF default metric\n" | |
8143 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8144 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8145 | "Route map reference\n" |
8146 | "Pointer to route-map entries\n") | |
8147 | { | |
a3d826f0 | 8148 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8149 | int idx_ospf_table = 1; |
8150 | int idx_number = 2; | |
8151 | int idx = 3; | |
8152 | int source; | |
8153 | int type = -1; | |
8154 | int metric = -1; | |
8155 | u_short instance; | |
8156 | struct ospf_redist *red; | |
7c8ff89e | 8157 | |
d62a17ae | 8158 | if (!ospf) |
8159 | return CMD_SUCCESS; | |
d8f70b86 | 8160 | |
d62a17ae | 8161 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 8162 | |
d62a17ae | 8163 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 8164 | |
d62a17ae | 8165 | if (!ospf) |
8166 | return CMD_SUCCESS; | |
7c8ff89e | 8167 | |
d62a17ae | 8168 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8169 | vty_out(vty, | |
8170 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8171 | return CMD_WARNING_CONFIG_FAILED; | |
8172 | } | |
7c8ff89e | 8173 | |
d62a17ae | 8174 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
8175 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8176 | return CMD_WARNING_CONFIG_FAILED; | |
8177 | } | |
7c8ff89e | 8178 | |
d62a17ae | 8179 | /* Get metric value. */ |
8180 | if (argv_find(argv, argc, "metric", &idx)) | |
8181 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
8182 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 8183 | |
d62a17ae | 8184 | idx = 3; |
8185 | /* Get metric type. */ | |
8186 | if (argv_find(argv, argc, "metric-type", &idx)) | |
8187 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
8188 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 8189 | |
d62a17ae | 8190 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 8191 | |
d62a17ae | 8192 | idx = 3; |
8193 | if (argv_find(argv, argc, "route-map", &idx)) | |
8194 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
8195 | else | |
8196 | ospf_routemap_unset(red); | |
7c8ff89e | 8197 | |
d62a17ae | 8198 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
8199 | } |
8200 | ||
8201 | DEFUN (no_ospf_redistribute_instance_source, | |
8202 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8203 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8204 | NO_STR |
8205 | REDIST_STR | |
8206 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8207 | "Non-main Kernel Routing Table\n" |
8208 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
8209 | "Metric for redistributed routes\n" |
8210 | "OSPF default metric\n" | |
8211 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8212 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8213 | "Route map reference\n" |
8214 | "Pointer to route-map entries\n") | |
8215 | { | |
a3d826f0 | 8216 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8217 | int idx_ospf_table = 2; |
8218 | int idx_number = 3; | |
8219 | u_int instance; | |
8220 | struct ospf_redist *red; | |
8221 | int source; | |
8222 | ||
8223 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
8224 | source = ZEBRA_ROUTE_OSPF; | |
8225 | else | |
8226 | source = ZEBRA_ROUTE_TABLE; | |
8227 | ||
8228 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 8229 | |
d62a17ae | 8230 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8231 | vty_out(vty, | |
8232 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8233 | return CMD_WARNING_CONFIG_FAILED; | |
8234 | } | |
8235 | ||
8236 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
8237 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8238 | return CMD_WARNING_CONFIG_FAILED; | |
8239 | } | |
8240 | ||
8241 | red = ospf_redist_lookup(ospf, source, instance); | |
8242 | if (!red) | |
8243 | return CMD_SUCCESS; | |
8244 | ||
8245 | ospf_routemap_unset(red); | |
8246 | return ospf_redistribute_unset(ospf, source, instance); | |
718e3744 | 8247 | } |
8248 | ||
8249 | DEFUN (ospf_distribute_list_out, | |
8250 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 8251 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 8252 | "Filter networks in routing updates\n" |
6f2a6703 CF |
8253 | "Access-list name\n" |
8254 | OUT_STR | |
ab0181ee | 8255 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 8256 | { |
a3d826f0 | 8257 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8258 | int idx_word = 1; |
8259 | int source; | |
718e3744 | 8260 | |
d62a17ae | 8261 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 8262 | |
d62a17ae | 8263 | /* Get distribute source. */ |
8264 | source = proto_redistnum(AFI_IP, proto); | |
8265 | if (source < 0) | |
8266 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8267 | |
d62a17ae | 8268 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 8269 | } |
8270 | ||
6f2a6703 CF |
8271 | DEFUN (no_ospf_distribute_list_out, |
8272 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 8273 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
8274 | NO_STR |
8275 | "Filter networks in routing updates\n" | |
8276 | "Access-list name\n" | |
8277 | OUT_STR | |
ab0181ee | 8278 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 8279 | { |
a3d826f0 | 8280 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8281 | int idx_word = 2; |
8282 | int source; | |
020709f9 | 8283 | |
d62a17ae | 8284 | char *proto = argv[argc - 1]->text; |
8285 | source = proto_redistnum(AFI_IP, proto); | |
8286 | if (source < 0) | |
8287 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8288 | |
d62a17ae | 8289 | return ospf_distribute_list_out_unset(ospf, source, |
8290 | argv[idx_word]->arg); | |
718e3744 | 8291 | } |
8292 | ||
6f2a6703 CF |
8293 | /* Default information originate. */ |
8294 | DEFUN (ospf_default_information_originate, | |
8295 | ospf_default_information_originate_cmd, | |
e83a9414 | 8296 | "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 8297 | "Control distribution of default information\n" |
8298 | "Distribute a default route\n" | |
8299 | "Always advertise default route\n" | |
6f2a6703 CF |
8300 | "OSPF default metric\n" |
8301 | "OSPF metric\n" | |
718e3744 | 8302 | "OSPF metric type for default routes\n" |
7111c1a0 | 8303 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8304 | "Route map reference\n" |
8305 | "Pointer to route-map entries\n") | |
8306 | { | |
a3d826f0 | 8307 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8308 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
8309 | int type = -1; | |
8310 | int metric = -1; | |
8311 | struct ospf_redist *red; | |
8312 | int idx = 0; | |
8313 | ||
8314 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
8315 | ||
8316 | /* Check whether "always" was specified */ | |
8317 | if (argv_find(argv, argc, "always", &idx)) | |
8318 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
8319 | /* Get metric value */ | |
8320 | else if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
8321 | if (!str2metric(argv[idx]->arg, &metric)) | |
8322 | return CMD_WARNING_CONFIG_FAILED; | |
8323 | } | |
8324 | /* Get metric type. */ | |
8325 | else if (argv_find(argv, argc, "(1-2)", &idx)) { | |
8326 | if (!str2metric_type(argv[idx]->arg, &type)) | |
8327 | return CMD_WARNING_CONFIG_FAILED; | |
8328 | } | |
8329 | /* Get route-map */ | |
8330 | else if (argv_find(argv, argc, "WORD", &idx)) | |
8331 | ospf_routemap_set(red, argv[idx]->arg); | |
8332 | else | |
8333 | ospf_routemap_unset(red); | |
8334 | ||
8335 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
8336 | metric); | |
718e3744 | 8337 | } |
8338 | ||
8339 | DEFUN (no_ospf_default_information_originate, | |
8340 | no_ospf_default_information_originate_cmd, | |
12dcf78e | 8341 | "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 8342 | NO_STR |
8343 | "Control distribution of default information\n" | |
813d4307 DW |
8344 | "Distribute a default route\n" |
8345 | "Always advertise default route\n" | |
8346 | "OSPF default metric\n" | |
8347 | "OSPF metric\n" | |
8348 | "OSPF metric type for default routes\n" | |
7111c1a0 | 8349 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8350 | "Route map reference\n" |
8351 | "Pointer to route-map entries\n") | |
718e3744 | 8352 | { |
a3d826f0 | 8353 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8354 | struct prefix_ipv4 p; |
8355 | struct ospf_external *ext; | |
8356 | struct ospf_redist *red; | |
7c8ff89e | 8357 | |
d62a17ae | 8358 | p.family = AF_INET; |
8359 | p.prefix.s_addr = 0; | |
8360 | p.prefixlen = 0; | |
718e3744 | 8361 | |
d62a17ae | 8362 | ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0); |
718e3744 | 8363 | |
d62a17ae | 8364 | if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0)) |
8365 | && EXTERNAL_INFO(ext)) { | |
8366 | ospf_external_info_delete(DEFAULT_ROUTE, 0, p); | |
8367 | ospf_external_del(DEFAULT_ROUTE, 0); | |
8368 | } | |
718e3744 | 8369 | |
d62a17ae | 8370 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
8371 | if (!red) | |
8372 | return CMD_SUCCESS; | |
7c8ff89e | 8373 | |
d62a17ae | 8374 | ospf_routemap_unset(red); |
8375 | return ospf_redistribute_default_unset(ospf); | |
718e3744 | 8376 | } |
8377 | ||
8378 | DEFUN (ospf_default_metric, | |
8379 | ospf_default_metric_cmd, | |
6147e2c6 | 8380 | "default-metric (0-16777214)", |
718e3744 | 8381 | "Set metric of redistributed routes\n" |
8382 | "Default metric\n") | |
8383 | { | |
a3d826f0 | 8384 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8385 | int idx_number = 1; |
8386 | int metric = -1; | |
718e3744 | 8387 | |
d62a17ae | 8388 | if (!str2metric(argv[idx_number]->arg, &metric)) |
8389 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8390 | |
d62a17ae | 8391 | ospf->default_metric = metric; |
718e3744 | 8392 | |
d62a17ae | 8393 | return CMD_SUCCESS; |
718e3744 | 8394 | } |
8395 | ||
8396 | DEFUN (no_ospf_default_metric, | |
8397 | no_ospf_default_metric_cmd, | |
7a7be519 | 8398 | "no default-metric [(0-16777214)]", |
718e3744 | 8399 | NO_STR |
7a7be519 | 8400 | "Set metric of redistributed routes\n" |
8401 | "Default metric\n") | |
718e3744 | 8402 | { |
a3d826f0 | 8403 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8404 | |
d62a17ae | 8405 | ospf->default_metric = -1; |
68980084 | 8406 | |
d62a17ae | 8407 | return CMD_SUCCESS; |
718e3744 | 8408 | } |
8409 | ||
718e3744 | 8410 | |
8411 | DEFUN (ospf_distance, | |
8412 | ospf_distance_cmd, | |
6147e2c6 | 8413 | "distance (1-255)", |
eaa1ae0d | 8414 | "Administrative distance\n" |
718e3744 | 8415 | "OSPF Administrative distance\n") |
8416 | { | |
a3d826f0 | 8417 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8418 | int idx_number = 1; |
68980084 | 8419 | |
d62a17ae | 8420 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 8421 | |
d62a17ae | 8422 | return CMD_SUCCESS; |
718e3744 | 8423 | } |
8424 | ||
8425 | DEFUN (no_ospf_distance, | |
8426 | no_ospf_distance_cmd, | |
6147e2c6 | 8427 | "no distance (1-255)", |
718e3744 | 8428 | NO_STR |
eaa1ae0d | 8429 | "Administrative distance\n" |
718e3744 | 8430 | "OSPF Administrative distance\n") |
8431 | { | |
a3d826f0 | 8432 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8433 | |
d62a17ae | 8434 | ospf->distance_all = 0; |
68980084 | 8435 | |
d62a17ae | 8436 | return CMD_SUCCESS; |
718e3744 | 8437 | } |
8438 | ||
8439 | DEFUN (no_ospf_distance_ospf, | |
8440 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 8441 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 8442 | NO_STR |
eaa1ae0d QY |
8443 | "Administrative distance\n" |
8444 | "OSPF administrative distance\n" | |
718e3744 | 8445 | "Intra-area routes\n" |
813d4307 | 8446 | "Distance for intra-area routes\n" |
718e3744 | 8447 | "Inter-area routes\n" |
813d4307 DW |
8448 | "Distance for inter-area routes\n" |
8449 | "External routes\n" | |
8450 | "Distance for external routes\n") | |
718e3744 | 8451 | { |
a3d826f0 | 8452 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8453 | int idx = 0; |
718e3744 | 8454 | |
d62a17ae | 8455 | if (!ospf) |
8456 | return CMD_SUCCESS; | |
7c8ff89e | 8457 | |
d62a17ae | 8458 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
8459 | idx = ospf->distance_intra = 0; | |
8460 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
8461 | idx = ospf->distance_inter = 0; | |
8462 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
8463 | ospf->distance_external = 0; | |
718e3744 | 8464 | |
d62a17ae | 8465 | return CMD_SUCCESS; |
718e3744 | 8466 | } |
8467 | ||
6f2a6703 CF |
8468 | DEFUN (ospf_distance_ospf, |
8469 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
8470 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
8471 | "Administrative distance\n" | |
8472 | "OSPF administrative distance\n" | |
718e3744 | 8473 | "Intra-area routes\n" |
8474 | "Distance for intra-area routes\n" | |
718e3744 | 8475 | "Inter-area routes\n" |
8476 | "Distance for inter-area routes\n" | |
8477 | "External routes\n" | |
718e3744 | 8478 | "Distance for external routes\n") |
8479 | { | |
a3d826f0 | 8480 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8481 | int idx = 0; |
68980084 | 8482 | |
d62a17ae | 8483 | if (argv_find(argv, argc, "intra-area", &idx)) |
8484 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
8485 | idx = 0; | |
8486 | if (argv_find(argv, argc, "inter-area", &idx)) | |
8487 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
8488 | idx = 0; | |
8489 | if (argv_find(argv, argc, "external", &idx)) | |
8490 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 8491 | |
d62a17ae | 8492 | return CMD_SUCCESS; |
718e3744 | 8493 | } |
8494 | ||
d7d73ffc | 8495 | #if 0 |
718e3744 | 8496 | DEFUN (ospf_distance_source, |
8497 | ospf_distance_source_cmd, | |
6147e2c6 | 8498 | "distance (1-255) A.B.C.D/M", |
718e3744 | 8499 | "Administrative distance\n" |
8500 | "Distance value\n" | |
8501 | "IP source prefix\n") | |
8502 | { | |
cdc2d765 | 8503 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8504 | int idx_number = 1; |
8505 | int idx_ipv4_prefixlen = 2; | |
020709f9 | 8506 | |
7c8ff89e DS |
8507 | if (!ospf) |
8508 | return CMD_SUCCESS; | |
8509 | ||
8d769265 | 8510 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
68980084 | 8511 | |
718e3744 | 8512 | return CMD_SUCCESS; |
8513 | } | |
8514 | ||
8515 | DEFUN (no_ospf_distance_source, | |
8516 | no_ospf_distance_source_cmd, | |
6147e2c6 | 8517 | "no distance (1-255) A.B.C.D/M", |
718e3744 | 8518 | NO_STR |
8519 | "Administrative distance\n" | |
8520 | "Distance value\n" | |
8521 | "IP source prefix\n") | |
8522 | { | |
cdc2d765 | 8523 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8524 | int idx_number = 2; |
8525 | int idx_ipv4_prefixlen = 3; | |
020709f9 | 8526 | |
7c8ff89e DS |
8527 | if (!ospf) |
8528 | return CMD_SUCCESS; | |
8529 | ||
8d769265 | 8530 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
020709f9 | 8531 | |
718e3744 | 8532 | return CMD_SUCCESS; |
8533 | } | |
8534 | ||
8535 | DEFUN (ospf_distance_source_access_list, | |
8536 | ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8537 | "distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8538 | "Administrative distance\n" |
8539 | "Distance value\n" | |
8540 | "IP source prefix\n" | |
8541 | "Access list name\n") | |
8542 | { | |
cdc2d765 | 8543 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8544 | int idx_number = 1; |
8545 | int idx_ipv4_prefixlen = 2; | |
8546 | int idx_word = 3; | |
020709f9 | 8547 | |
7c8ff89e DS |
8548 | if (!ospf) |
8549 | return CMD_SUCCESS; | |
8550 | ||
8d769265 | 8551 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8552 | |
718e3744 | 8553 | return CMD_SUCCESS; |
8554 | } | |
8555 | ||
8556 | DEFUN (no_ospf_distance_source_access_list, | |
8557 | no_ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8558 | "no distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8559 | NO_STR |
8560 | "Administrative distance\n" | |
8561 | "Distance value\n" | |
8562 | "IP source prefix\n" | |
8563 | "Access list name\n") | |
8564 | { | |
cdc2d765 | 8565 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8566 | int idx_number = 2; |
8567 | int idx_ipv4_prefixlen = 3; | |
8568 | int idx_word = 4; | |
020709f9 | 8569 | |
7c8ff89e DS |
8570 | if (!ospf) |
8571 | return CMD_SUCCESS; | |
8572 | ||
8d769265 | 8573 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8574 | |
718e3744 | 8575 | return CMD_SUCCESS; |
8576 | } | |
d7d73ffc | 8577 | #endif |
718e3744 | 8578 | |
ba682537 | 8579 | DEFUN (ip_ospf_mtu_ignore, |
8580 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8581 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 8582 | "IP Information\n" |
8583 | "OSPF interface commands\n" | |
99a522c7 | 8584 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8585 | "Address of interface\n") |
ba682537 | 8586 | { |
d62a17ae | 8587 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8588 | int idx_ipv4 = 3; | |
8589 | struct in_addr addr; | |
8590 | int ret; | |
8591 | ||
8592 | struct ospf_if_params *params; | |
8593 | params = IF_DEF_PARAMS(ifp); | |
8594 | ||
8595 | if (argc == 4) { | |
8596 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8597 | if (!ret) { | |
8598 | vty_out(vty, | |
8599 | "Please specify interface address by A.B.C.D\n"); | |
8600 | return CMD_WARNING_CONFIG_FAILED; | |
8601 | } | |
8602 | params = ospf_get_if_params(ifp, addr); | |
8603 | ospf_if_update_params(ifp, addr); | |
8604 | } | |
8605 | params->mtu_ignore = 1; | |
8606 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8607 | SET_IF_PARAM(params, mtu_ignore); | |
8608 | else { | |
8609 | UNSET_IF_PARAM(params, mtu_ignore); | |
8610 | if (params != IF_DEF_PARAMS(ifp)) { | |
8611 | ospf_free_if_params(ifp, addr); | |
8612 | ospf_if_update_params(ifp, addr); | |
8613 | } | |
8614 | } | |
8615 | return CMD_SUCCESS; | |
ba682537 | 8616 | } |
8617 | ||
ba682537 | 8618 | DEFUN (no_ip_ospf_mtu_ignore, |
8619 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8620 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 8621 | NO_STR |
ba682537 | 8622 | "IP Information\n" |
8623 | "OSPF interface commands\n" | |
99a522c7 | 8624 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8625 | "Address of interface\n") |
ba682537 | 8626 | { |
d62a17ae | 8627 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8628 | int idx_ipv4 = 4; | |
8629 | struct in_addr addr; | |
8630 | int ret; | |
8631 | ||
8632 | struct ospf_if_params *params; | |
8633 | params = IF_DEF_PARAMS(ifp); | |
8634 | ||
8635 | if (argc == 5) { | |
8636 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8637 | if (!ret) { | |
8638 | vty_out(vty, | |
8639 | "Please specify interface address by A.B.C.D\n"); | |
8640 | return CMD_WARNING_CONFIG_FAILED; | |
8641 | } | |
8642 | params = ospf_get_if_params(ifp, addr); | |
8643 | ospf_if_update_params(ifp, addr); | |
8644 | } | |
8645 | params->mtu_ignore = 0; | |
8646 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8647 | SET_IF_PARAM(params, mtu_ignore); | |
8648 | else { | |
8649 | UNSET_IF_PARAM(params, mtu_ignore); | |
8650 | if (params != IF_DEF_PARAMS(ifp)) { | |
8651 | ospf_free_if_params(ifp, addr); | |
8652 | ospf_if_update_params(ifp, addr); | |
8653 | } | |
8654 | } | |
8655 | return CMD_SUCCESS; | |
ba682537 | 8656 | } |
8657 | ||
6b0655a2 | 8658 | |
88d6cf37 | 8659 | DEFUN (ospf_max_metric_router_lsa_admin, |
8660 | ospf_max_metric_router_lsa_admin_cmd, | |
8661 | "max-metric router-lsa administrative", | |
8662 | "OSPF maximum / infinite-distance metric\n" | |
8663 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8664 | "Administratively applied, for an indefinite period\n") | |
8665 | { | |
a3d826f0 | 8666 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8667 | struct listnode *ln; |
8668 | struct ospf_area *area; | |
7c8ff89e | 8669 | |
d62a17ae | 8670 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
8671 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 8672 | |
d62a17ae | 8673 | if (!CHECK_FLAG(area->stub_router_state, |
8674 | OSPF_AREA_IS_STUB_ROUTED)) | |
8675 | ospf_router_lsa_update_area(area); | |
8676 | } | |
4ba4fc85 | 8677 | |
d62a17ae | 8678 | /* Allows for areas configured later to get the property */ |
8679 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
8680 | ||
8681 | return CMD_SUCCESS; | |
88d6cf37 | 8682 | } |
8683 | ||
8684 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
8685 | no_ospf_max_metric_router_lsa_admin_cmd, | |
8686 | "no max-metric router-lsa administrative", | |
8687 | NO_STR | |
8688 | "OSPF maximum / infinite-distance metric\n" | |
8689 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8690 | "Administratively applied, for an indefinite period\n") | |
8691 | { | |
a3d826f0 | 8692 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8693 | struct listnode *ln; |
8694 | struct ospf_area *area; | |
8695 | ||
8696 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8697 | UNSET_FLAG(area->stub_router_state, | |
8698 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
8699 | ||
8700 | /* Don't trample on the start-up stub timer */ | |
8701 | if (CHECK_FLAG(area->stub_router_state, | |
8702 | OSPF_AREA_IS_STUB_ROUTED) | |
8703 | && !area->t_stub_router) { | |
8704 | UNSET_FLAG(area->stub_router_state, | |
8705 | OSPF_AREA_IS_STUB_ROUTED); | |
8706 | ospf_router_lsa_update_area(area); | |
8707 | } | |
8708 | } | |
8709 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
8710 | return CMD_SUCCESS; | |
88d6cf37 | 8711 | } |
8712 | ||
8713 | DEFUN (ospf_max_metric_router_lsa_startup, | |
8714 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 8715 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 8716 | "OSPF maximum / infinite-distance metric\n" |
8717 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8718 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8719 | "Time (seconds) to advertise self as stub-router\n") | |
8720 | { | |
a3d826f0 | 8721 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8722 | int idx_number = 3; |
8723 | unsigned int seconds; | |
8724 | ||
b5a8894d | 8725 | if (argc < 4) { |
d62a17ae | 8726 | vty_out(vty, "%% Must supply stub-router period"); |
8727 | return CMD_WARNING_CONFIG_FAILED; | |
8728 | } | |
8729 | ||
8730 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8731 | ||
8732 | ospf->stub_router_startup_time = seconds; | |
8733 | ||
8734 | return CMD_SUCCESS; | |
88d6cf37 | 8735 | } |
8736 | ||
8737 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
8738 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 8739 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 8740 | NO_STR |
8741 | "OSPF maximum / infinite-distance metric\n" | |
8742 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8743 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
8744 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 8745 | { |
a3d826f0 | 8746 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8747 | struct listnode *ln; |
8748 | struct ospf_area *area; | |
8749 | ||
8750 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8751 | ||
8752 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8753 | SET_FLAG(area->stub_router_state, | |
8754 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
8755 | OSPF_TIMER_OFF(area->t_stub_router); | |
8756 | ||
8757 | /* Don't trample on admin stub routed */ | |
8758 | if (!CHECK_FLAG(area->stub_router_state, | |
8759 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8760 | UNSET_FLAG(area->stub_router_state, | |
8761 | OSPF_AREA_IS_STUB_ROUTED); | |
8762 | ospf_router_lsa_update_area(area); | |
8763 | } | |
8764 | } | |
8765 | return CMD_SUCCESS; | |
88d6cf37 | 8766 | } |
8767 | ||
a1afa410 | 8768 | |
88d6cf37 | 8769 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
8770 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 8771 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 8772 | "OSPF maximum / infinite-distance metric\n" |
8773 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8774 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8775 | "Time (seconds) to wait till full shutdown\n") | |
8776 | { | |
a3d826f0 | 8777 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8778 | int idx_number = 3; |
8779 | unsigned int seconds; | |
8780 | ||
b5a8894d | 8781 | if (argc < 4) { |
d62a17ae | 8782 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
8783 | return CMD_WARNING_CONFIG_FAILED; | |
8784 | } | |
8785 | ||
8786 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8787 | ||
8788 | ospf->stub_router_shutdown_time = seconds; | |
8789 | ||
8790 | return CMD_SUCCESS; | |
88d6cf37 | 8791 | } |
8792 | ||
8793 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
8794 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 8795 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 8796 | NO_STR |
8797 | "OSPF maximum / infinite-distance metric\n" | |
8798 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8799 | "Advertise stub-router prior to full shutdown of OSPF\n" |
8800 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 8801 | { |
a3d826f0 | 8802 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 8803 | |
d62a17ae | 8804 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
8805 | ||
8806 | return CMD_SUCCESS; | |
88d6cf37 | 8807 | } |
8808 | ||
d62a17ae | 8809 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
8810 | { | |
8811 | struct listnode *ln; | |
8812 | struct ospf_area *area; | |
8813 | ||
8814 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8815 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
8816 | ospf->stub_router_startup_time); | |
8817 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8818 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
8819 | ospf->stub_router_shutdown_time); | |
8820 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8821 | if (CHECK_FLAG(area->stub_router_state, | |
8822 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8823 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
8824 | break; | |
8825 | } | |
8826 | } | |
8827 | return; | |
8828 | } | |
8829 | ||
b5a8894d CS |
8830 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
8831 | struct route_table *rt) | |
d62a17ae | 8832 | { |
8833 | struct route_node *rn; | |
8834 | struct ospf_route * or ; | |
8835 | struct listnode *pnode, *pnnode; | |
8836 | struct ospf_path *path; | |
8837 | ||
8838 | vty_out(vty, "============ OSPF network routing table ============\n"); | |
8839 | ||
8840 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
8841 | if ((or = rn->info) != NULL) { | |
8842 | char buf1[19]; | |
8843 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
8844 | rn->p.prefixlen); | |
8845 | ||
8846 | switch (or->path_type) { | |
8847 | case OSPF_PATH_INTER_AREA: | |
8848 | if (or->type == OSPF_DESTINATION_NETWORK) | |
8849 | vty_out(vty, | |
8850 | "N IA %-18s [%d] area: %s\n", | |
8851 | buf1, or->cost, | |
8852 | inet_ntoa(or->u.std.area_id)); | |
8853 | else if (or->type == OSPF_DESTINATION_DISCARD) | |
8854 | vty_out(vty, | |
8855 | "D IA %-18s Discard entry\n", | |
8856 | buf1); | |
8857 | break; | |
8858 | case OSPF_PATH_INTRA_AREA: | |
8859 | vty_out(vty, "N %-18s [%d] area: %s\n", | |
8860 | buf1, or->cost, | |
8861 | inet_ntoa(or->u.std.area_id)); | |
8862 | break; | |
8863 | default: | |
8864 | break; | |
8865 | } | |
8866 | ||
8867 | if (or->type == OSPF_DESTINATION_NETWORK) | |
8868 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, | |
8869 | path)) { | |
8870 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8871 | ospf->vrf_id)) { |
d62a17ae | 8872 | if (path->nexthop.s_addr == 0) |
8873 | vty_out(vty, | |
8874 | "%24s directly attached to %s\n", | |
8875 | "", | |
8876 | ifindex2ifname( | |
8877 | path->ifindex, | |
b5a8894d | 8878 | ospf->vrf_id)); |
d62a17ae | 8879 | else |
8880 | vty_out(vty, | |
8881 | "%24s via %s, %s\n", | |
8882 | "", | |
8883 | inet_ntoa( | |
8884 | path->nexthop), | |
8885 | ifindex2ifname( | |
8886 | path->ifindex, | |
b5a8894d | 8887 | ospf->vrf_id)); |
d62a17ae | 8888 | } |
8889 | } | |
8890 | } | |
8891 | vty_out(vty, "\n"); | |
8892 | } | |
8893 | ||
b5a8894d CS |
8894 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
8895 | struct route_table *rtrs) | |
d62a17ae | 8896 | { |
8897 | struct route_node *rn; | |
8898 | struct ospf_route * or ; | |
8899 | struct listnode *pnode; | |
8900 | struct listnode *node; | |
8901 | struct ospf_path *path; | |
8902 | ||
c0f3f7cd | 8903 | vty_out(vty, "============ OSPF router routing table =============\n"); |
d62a17ae | 8904 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) |
8905 | if (rn->info) { | |
8906 | int flag = 0; | |
8907 | ||
8908 | vty_out(vty, "R %-15s ", | |
8909 | inet_ntoa(rn->p.u.prefix4)); | |
8910 | ||
8911 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, | |
8912 | or)) { | |
8913 | if (flag++) | |
8914 | vty_out(vty, "%24s", ""); | |
8915 | ||
8916 | /* Show path. */ | |
8917 | vty_out(vty, "%s [%d] area: %s", | |
8918 | (or->path_type == OSPF_PATH_INTER_AREA | |
8919 | ? "IA" | |
8920 | : " "), | |
8921 | or->cost, inet_ntoa(or->u.std.area_id)); | |
8922 | /* Show flags. */ | |
8923 | vty_out(vty, "%s%s\n", | |
8924 | (or->u.std.flags & ROUTER_LSA_BORDER | |
8925 | ? ", ABR" | |
8926 | : ""), | |
8927 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
8928 | ? ", ASBR" | |
8929 | : "")); | |
8930 | ||
8931 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, | |
8932 | path)) { | |
8933 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8934 | ospf->vrf_id)) { |
d62a17ae | 8935 | if (path->nexthop.s_addr == 0) |
8936 | vty_out(vty, | |
8937 | "%24s directly attached to %s\n", | |
8938 | "", | |
8939 | ifindex2ifname( | |
8940 | path->ifindex, | |
b5a8894d | 8941 | ospf->vrf_id)); |
d62a17ae | 8942 | else |
8943 | vty_out(vty, | |
8944 | "%24s via %s, %s\n", | |
8945 | "", | |
8946 | inet_ntoa( | |
8947 | path->nexthop), | |
8948 | ifindex2ifname( | |
8949 | path->ifindex, | |
b5a8894d | 8950 | ospf->vrf_id)); |
d62a17ae | 8951 | } |
8952 | } | |
8953 | } | |
8954 | } | |
8955 | vty_out(vty, "\n"); | |
8956 | } | |
8957 | ||
b5a8894d CS |
8958 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
8959 | struct route_table *rt) | |
d62a17ae | 8960 | { |
8961 | struct route_node *rn; | |
8962 | struct ospf_route *er; | |
8963 | struct listnode *pnode, *pnnode; | |
8964 | struct ospf_path *path; | |
8965 | ||
8966 | vty_out(vty, "============ OSPF external routing table ===========\n"); | |
8967 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
8968 | if ((er = rn->info) != NULL) { | |
8969 | char buf1[19]; | |
8970 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
8971 | rn->p.prefixlen); | |
8972 | ||
8973 | switch (er->path_type) { | |
8974 | case OSPF_PATH_TYPE1_EXTERNAL: | |
8975 | vty_out(vty, | |
8976 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI | |
8977 | "\n", | |
8978 | buf1, er->cost, er->u.ext.tag); | |
8979 | break; | |
8980 | case OSPF_PATH_TYPE2_EXTERNAL: | |
8981 | vty_out(vty, | |
8982 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI | |
8983 | "\n", | |
8984 | buf1, er->cost, er->u.ext.type2_cost, | |
8985 | er->u.ext.tag); | |
8986 | break; | |
8987 | } | |
8988 | ||
8989 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, | |
8990 | path)) { | |
8991 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8992 | ospf->vrf_id)) { |
d62a17ae | 8993 | if (path->nexthop.s_addr == 0) |
8994 | vty_out(vty, | |
8995 | "%24s directly attached to %s\n", | |
8996 | "", | |
8997 | ifindex2ifname( | |
8998 | path->ifindex, | |
b5a8894d | 8999 | ospf->vrf_id)); |
d62a17ae | 9000 | else |
9001 | vty_out(vty, | |
9002 | "%24s via %s, %s\n", | |
9003 | "", | |
9004 | inet_ntoa( | |
9005 | path->nexthop), | |
9006 | ifindex2ifname( | |
9007 | path->ifindex, | |
b5a8894d | 9008 | ospf->vrf_id)); |
d62a17ae | 9009 | } |
54bedb55 | 9010 | } |
d62a17ae | 9011 | } |
9012 | vty_out(vty, "\n"); | |
718e3744 | 9013 | } |
9014 | ||
d62a17ae | 9015 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
b1c3ae8c CS |
9016 | struct ospf *ospf, |
9017 | u_char use_vrf) | |
718e3744 | 9018 | { |
d62a17ae | 9019 | if (ospf->instance) |
9020 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 9021 | |
b1c3ae8c | 9022 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 9023 | |
d62a17ae | 9024 | if (ospf->new_table == NULL) { |
9025 | vty_out(vty, "No OSPF routing information exist\n"); | |
9026 | return CMD_SUCCESS; | |
9027 | } | |
718e3744 | 9028 | |
d62a17ae | 9029 | /* Show Network routes. |
9030 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 9031 | |
d62a17ae | 9032 | /* Show Router routes. */ |
b5a8894d | 9033 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs); |
718e3744 | 9034 | |
d62a17ae | 9035 | vty_out(vty, "\n"); |
7c8ff89e | 9036 | |
d62a17ae | 9037 | return CMD_SUCCESS; |
718e3744 | 9038 | } |
718e3744 | 9039 | |
7c8ff89e DS |
9040 | DEFUN (show_ip_ospf_border_routers, |
9041 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 9042 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 9043 | SHOW_STR |
9044 | IP_STR | |
9045 | "OSPF information\n" | |
b5a8894d CS |
9046 | VRF_CMD_HELP_STR |
9047 | "All VRFs\n" | |
7c8ff89e | 9048 | "Show all the ABR's and ASBR's\n") |
718e3744 | 9049 | { |
b5a8894d CS |
9050 | struct ospf *ospf = NULL; |
9051 | struct listnode *node = NULL; | |
9052 | char *vrf_name = NULL; | |
9053 | bool all_vrf = FALSE; | |
9054 | int ret = CMD_SUCCESS; | |
9055 | int inst = 0; | |
9056 | int idx_vrf = 0; | |
b1c3ae8c | 9057 | u_char use_vrf = 0; |
68980084 | 9058 | |
43b8d1d8 | 9059 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 9060 | |
b5a8894d | 9061 | if (vrf_name) { |
b1c3ae8c | 9062 | use_vrf = 1; |
b5a8894d CS |
9063 | if (all_vrf) { |
9064 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9065 | if (!ospf->oi_running) | |
9066 | continue; | |
b5a8894d CS |
9067 | |
9068 | ret = show_ip_ospf_border_routers_common(vty, | |
b1c3ae8c CS |
9069 | ospf, |
9070 | use_vrf); | |
b5a8894d CS |
9071 | } |
9072 | } else { | |
9073 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9074 | if (ospf == NULL || !ospf->oi_running) | |
9075 | return CMD_SUCCESS; | |
9076 | ||
b1c3ae8c CS |
9077 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
9078 | use_vrf); | |
b5a8894d CS |
9079 | } |
9080 | } else { | |
9081 | /* Display default ospf (instance 0) info */ | |
9082 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9083 | if (ospf == NULL || !ospf->oi_running) | |
9084 | return CMD_SUCCESS; | |
b1c3ae8c | 9085 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
9086 | } |
9087 | ||
9088 | return ret; | |
7c8ff89e DS |
9089 | } |
9090 | ||
9091 | DEFUN (show_ip_ospf_instance_border_routers, | |
9092 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 9093 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
9094 | SHOW_STR |
9095 | IP_STR | |
9096 | "OSPF information\n" | |
9097 | "Instance ID\n" | |
9098 | "Show all the ABR's and ASBR's\n") | |
9099 | { | |
d62a17ae | 9100 | int idx_number = 3; |
9101 | struct ospf *ospf; | |
9102 | u_short instance = 0; | |
7c8ff89e | 9103 | |
d62a17ae | 9104 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
9105 | ospf = ospf_lookup_instance(instance); |
9106 | if (ospf == NULL) | |
9107 | return CMD_NOT_MY_INSTANCE; | |
9108 | ||
9109 | if (!ospf->oi_running) | |
d62a17ae | 9110 | return CMD_SUCCESS; |
7c8ff89e | 9111 | |
b1c3ae8c | 9112 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
9113 | } |
9114 | ||
b1c3ae8c CS |
9115 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
9116 | u_char use_vrf) | |
7c8ff89e | 9117 | { |
d62a17ae | 9118 | if (ospf->instance) |
9119 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 9120 | |
b1c3ae8c | 9121 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 9122 | |
d62a17ae | 9123 | if (ospf->new_table == NULL) { |
9124 | vty_out(vty, "No OSPF routing information exist\n"); | |
9125 | return CMD_SUCCESS; | |
9126 | } | |
718e3744 | 9127 | |
d62a17ae | 9128 | /* Show Network routes. */ |
b5a8894d | 9129 | show_ip_ospf_route_network(vty, ospf, ospf->new_table); |
718e3744 | 9130 | |
d62a17ae | 9131 | /* Show Router routes. */ |
b5a8894d | 9132 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs); |
718e3744 | 9133 | |
d62a17ae | 9134 | /* Show AS External routes. */ |
b5a8894d | 9135 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route); |
718e3744 | 9136 | |
d62a17ae | 9137 | vty_out(vty, "\n"); |
7c8ff89e | 9138 | |
d62a17ae | 9139 | return CMD_SUCCESS; |
718e3744 | 9140 | } |
9141 | ||
7c8ff89e DS |
9142 | DEFUN (show_ip_ospf_route, |
9143 | show_ip_ospf_route_cmd, | |
b5a8894d CS |
9144 | "show ip ospf [vrf <NAME|all>] route", |
9145 | SHOW_STR | |
9146 | IP_STR | |
9147 | "OSPF information\n" | |
9148 | VRF_CMD_HELP_STR | |
9149 | "All VRFs\n" | |
9150 | "OSPF routing table\n") | |
9151 | { | |
9152 | struct ospf *ospf = NULL; | |
9153 | struct listnode *node = NULL; | |
9154 | char *vrf_name = NULL; | |
9155 | bool all_vrf = FALSE; | |
9156 | int ret = CMD_SUCCESS; | |
9157 | int inst = 0; | |
9158 | int idx_vrf = 0; | |
b1c3ae8c | 9159 | u_char use_vrf = 0; |
7c8ff89e | 9160 | |
43b8d1d8 | 9161 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 9162 | |
b5a8894d CS |
9163 | /* vrf input is provided could be all or specific vrf*/ |
9164 | if (vrf_name) { | |
b1c3ae8c | 9165 | use_vrf = 1; |
b5a8894d CS |
9166 | if (all_vrf) { |
9167 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9168 | if (!ospf->oi_running) | |
9169 | continue; | |
b1c3ae8c CS |
9170 | ret = show_ip_ospf_route_common(vty, ospf, |
9171 | use_vrf); | |
b5a8894d CS |
9172 | } |
9173 | return ret; | |
9174 | } | |
9175 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9176 | if (ospf == NULL || !ospf->oi_running) | |
9177 | return CMD_SUCCESS; | |
9178 | } else { | |
9179 | /* Display default ospf (instance 0) info */ | |
9180 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9181 | if (ospf == NULL || !ospf->oi_running) | |
9182 | return CMD_SUCCESS; | |
9183 | } | |
9184 | ||
9185 | if (ospf) | |
b1c3ae8c | 9186 | ret = show_ip_ospf_route_common(vty, ospf, use_vrf); |
b5a8894d CS |
9187 | |
9188 | return ret; | |
7c8ff89e DS |
9189 | } |
9190 | ||
9191 | DEFUN (show_ip_ospf_instance_route, | |
9192 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 9193 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
9194 | SHOW_STR |
9195 | IP_STR | |
9196 | "OSPF information\n" | |
9197 | "Instance ID\n" | |
9198 | "OSPF routing table\n") | |
9199 | { | |
d62a17ae | 9200 | int idx_number = 3; |
9201 | struct ospf *ospf; | |
9202 | u_short instance = 0; | |
7c8ff89e | 9203 | |
d62a17ae | 9204 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
9205 | ospf = ospf_lookup_instance(instance); |
9206 | if (ospf == NULL) | |
9207 | return CMD_NOT_MY_INSTANCE; | |
9208 | ||
9209 | if (!ospf->oi_running) | |
d62a17ae | 9210 | return CMD_SUCCESS; |
7c8ff89e | 9211 | |
b1c3ae8c | 9212 | return show_ip_ospf_route_common(vty, ospf, 0); |
7c8ff89e | 9213 | } |
6b0655a2 | 9214 | |
b5a8894d CS |
9215 | |
9216 | DEFUN (show_ip_ospf_vrfs, | |
9217 | show_ip_ospf_vrfs_cmd, | |
9218 | "show ip ospf vrfs [json]", | |
9219 | SHOW_STR | |
9220 | IP_STR | |
9221 | "OSPF information\n" | |
9222 | "Show OSPF VRFs \n" | |
9223 | JSON_STR) | |
9224 | { | |
9225 | u_char uj = use_json(argc, argv); | |
9226 | json_object *json = NULL; | |
9227 | json_object *json_vrfs = NULL; | |
9228 | struct ospf *ospf = NULL; | |
9229 | struct listnode *node = NULL; | |
9230 | int count = 0; | |
9231 | static char header[] = "Name Id RouterId "; | |
9232 | ||
9233 | if (uj) { | |
9234 | json = json_object_new_object(); | |
9235 | json_vrfs = json_object_new_object(); | |
9236 | } | |
9237 | ||
9238 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9239 | json_object *json_vrf = NULL; | |
9240 | const char *name = NULL; | |
9241 | int vrf_id_ui = 0; | |
9242 | ||
9243 | count++; | |
9244 | ||
9245 | if (!uj && count == 1) | |
9246 | vty_out(vty, "%s\n", header); | |
9247 | if (uj) | |
9248 | json_vrf = json_object_new_object(); | |
9249 | ||
9250 | if (ospf->vrf_id == 0) | |
9251 | name = VRF_DEFAULT_NAME; | |
9252 | else | |
9253 | name = ospf->name; | |
9254 | ||
9255 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) ? -1 : ospf->vrf_id; | |
9256 | ||
9257 | if (uj) { | |
9258 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
9259 | json_object_string_add(json_vrf, "routerId", | |
9260 | inet_ntoa(ospf->router_id)); | |
9261 | ||
9262 | json_object_object_add(json_vrfs, name, json_vrf); | |
9263 | ||
9264 | } else { | |
9265 | vty_out(vty, "%-25s %-5d %-16s \n", | |
9266 | name, ospf->vrf_id, inet_ntoa(ospf->router_id)); | |
9267 | } | |
9268 | } | |
9269 | ||
9270 | if (uj) { | |
9271 | json_object_object_add(json, "vrfs", json_vrfs); | |
9272 | json_object_int_add(json, "totalVrfs", count); | |
9273 | ||
9274 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
9275 | JSON_C_TO_STRING_PRETTY)); | |
9276 | json_object_free(json); | |
9277 | } else { | |
9278 | if (count) | |
34d6798f | 9279 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
9280 | count); |
9281 | } | |
9282 | ||
9283 | return CMD_SUCCESS; | |
9284 | } | |
9285 | ||
d62a17ae | 9286 | const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco", |
9287 | "shortcut"}; | |
718e3744 | 9288 | |
d62a17ae | 9289 | const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"}; |
718e3744 | 9290 | |
d62a17ae | 9291 | const char *ospf_int_type_str[] = {"unknown", /* should never be used. */ |
9292 | "point-to-point", "broadcast", | |
9293 | "non-broadcast", "point-to-multipoint", | |
9294 | "virtual-link", /* should never be used. */ | |
9295 | "loopback"}; | |
718e3744 | 9296 | |
43b8d1d8 | 9297 | static int config_write_interface_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 9298 | { |
f4e14fdb RW |
9299 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
9300 | struct listnode *node; | |
d62a17ae | 9301 | struct interface *ifp; |
9302 | struct crypt_key *ck; | |
d62a17ae | 9303 | struct route_node *rn = NULL; |
9304 | struct ospf_if_params *params; | |
43b8d1d8 | 9305 | int write = 0; |
d62a17ae | 9306 | |
451fda4f | 9307 | FOR_ALL_INTERFACES (vrf, ifp) { |
35955c14 CS |
9308 | struct vrf *vrf = NULL; |
9309 | ||
43b8d1d8 CS |
9310 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
9311 | continue; | |
d62a17ae | 9312 | |
35955c14 CS |
9313 | vrf = vrf_lookup_by_id(ifp->vrf_id); |
9314 | ||
43b8d1d8 | 9315 | vty_frame(vty, "!\n"); |
35955c14 CS |
9316 | if (ifp->vrf_id == VRF_DEFAULT || vrf == NULL) |
9317 | vty_frame(vty, "interface %s\n", ifp->name); | |
9318 | else | |
9319 | vty_frame(vty, "interface %s vrf %s\n", | |
9320 | ifp->name, vrf->name); | |
43b8d1d8 CS |
9321 | if (ifp->desc) |
9322 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 9323 | |
43b8d1d8 CS |
9324 | write++; |
9325 | ||
9326 | params = IF_DEF_PARAMS(ifp); | |
9327 | ||
9328 | do { | |
9329 | /* Interface Network print. */ | |
9330 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
9331 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
9332 | if (params->type != ospf_default_iftype(ifp)) { | |
9333 | vty_out(vty, " ip ospf network %s", | |
9334 | ospf_int_type_str | |
9335 | [params->type]); | |
9336 | if (params != IF_DEF_PARAMS(ifp)) | |
9337 | vty_out(vty, " %s", | |
d62a17ae | 9338 | inet_ntoa( |
43b8d1d8 CS |
9339 | rn->p.u.prefix4)); |
9340 | vty_out(vty, "\n"); | |
d62a17ae | 9341 | } |
43b8d1d8 | 9342 | } |
d62a17ae | 9343 | |
43b8d1d8 CS |
9344 | /* OSPF interface authentication print */ |
9345 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
9346 | && params->auth_type != OSPF_AUTH_NOTSET) { | |
9347 | const char *auth_str; | |
d62a17ae | 9348 | |
43b8d1d8 CS |
9349 | /* Translation tables are not that much help |
9350 | * here due to syntax | |
9351 | * of the simple option */ | |
9352 | switch (params->auth_type) { | |
d62a17ae | 9353 | |
43b8d1d8 CS |
9354 | case OSPF_AUTH_NULL: |
9355 | auth_str = " null"; | |
9356 | break; | |
d62a17ae | 9357 | |
43b8d1d8 CS |
9358 | case OSPF_AUTH_SIMPLE: |
9359 | auth_str = ""; | |
9360 | break; | |
d62a17ae | 9361 | |
43b8d1d8 CS |
9362 | case OSPF_AUTH_CRYPTOGRAPHIC: |
9363 | auth_str = " message-digest"; | |
9364 | break; | |
b5a8894d | 9365 | |
43b8d1d8 CS |
9366 | default: |
9367 | auth_str = ""; | |
9368 | break; | |
d62a17ae | 9369 | } |
9370 | ||
43b8d1d8 CS |
9371 | vty_out(vty, " ip ospf authentication%s", |
9372 | auth_str); | |
9373 | if (params != IF_DEF_PARAMS(ifp)) | |
9374 | vty_out(vty, " %s", | |
9375 | inet_ntoa(rn->p.u.prefix4)); | |
9376 | vty_out(vty, "\n"); | |
9377 | } | |
d62a17ae | 9378 | |
43b8d1d8 CS |
9379 | /* Simple Authentication Password print. */ |
9380 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
9381 | && params->auth_simple[0] != '\0') { | |
9382 | vty_out(vty, " ip ospf authentication-key %s", | |
9383 | params->auth_simple); | |
9384 | if (params != IF_DEF_PARAMS(ifp)) | |
9385 | vty_out(vty, " %s", | |
9386 | inet_ntoa(rn->p.u.prefix4)); | |
9387 | vty_out(vty, "\n"); | |
9388 | } | |
d62a17ae | 9389 | |
43b8d1d8 | 9390 | /* Cryptographic Authentication Key print. */ |
35955c14 CS |
9391 | if (params && params->auth_crypt) { |
9392 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, | |
f4e14fdb | 9393 | node, ck)) { |
35955c14 CS |
9394 | vty_out(vty, |
9395 | " ip ospf message-digest-key %d md5 %s", | |
9396 | ck->key_id, ck->auth_key); | |
9397 | if (params != IF_DEF_PARAMS(ifp)) | |
9398 | vty_out(vty, " %s", | |
9399 | inet_ntoa(rn->p.u.prefix4)); | |
9400 | vty_out(vty, "\n"); | |
9401 | } | |
43b8d1d8 | 9402 | } |
d62a17ae | 9403 | |
43b8d1d8 CS |
9404 | /* Interface Output Cost print. */ |
9405 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
9406 | output_cost_cmd)) { | |
9407 | vty_out(vty, " ip ospf cost %u", | |
9408 | params->output_cost_cmd); | |
9409 | if (params != IF_DEF_PARAMS(ifp)) | |
9410 | vty_out(vty, " %s", | |
9411 | inet_ntoa(rn->p.u.prefix4)); | |
9412 | vty_out(vty, "\n"); | |
9413 | } | |
d62a17ae | 9414 | |
43b8d1d8 CS |
9415 | /* Hello Interval print. */ |
9416 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
9417 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { | |
9418 | vty_out(vty, " ip ospf hello-interval %u", | |
9419 | params->v_hello); | |
9420 | if (params != IF_DEF_PARAMS(ifp)) | |
9421 | vty_out(vty, " %s", | |
9422 | inet_ntoa(rn->p.u.prefix4)); | |
9423 | vty_out(vty, "\n"); | |
9424 | } | |
d62a17ae | 9425 | |
9426 | ||
43b8d1d8 CS |
9427 | /* Router Dead Interval print. */ |
9428 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
9429 | && params->v_wait | |
9430 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
9431 | vty_out(vty, " ip ospf dead-interval "); | |
d62a17ae | 9432 | |
43b8d1d8 CS |
9433 | /* fast hello ? */ |
9434 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
9435 | fast_hello)) | |
9436 | vty_out(vty, | |
9437 | "minimal hello-multiplier %d", | |
9438 | params->fast_hello); | |
9439 | else | |
9440 | vty_out(vty, "%u", params->v_wait); | |
d62a17ae | 9441 | |
43b8d1d8 CS |
9442 | if (params != IF_DEF_PARAMS(ifp)) |
9443 | vty_out(vty, " %s", | |
9444 | inet_ntoa(rn->p.u.prefix4)); | |
9445 | vty_out(vty, "\n"); | |
9446 | } | |
d62a17ae | 9447 | |
43b8d1d8 CS |
9448 | /* Router Priority print. */ |
9449 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
9450 | && params->priority | |
9451 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
9452 | vty_out(vty, " ip ospf priority %u", | |
9453 | params->priority); | |
9454 | if (params != IF_DEF_PARAMS(ifp)) | |
9455 | vty_out(vty, " %s", | |
9456 | inet_ntoa(rn->p.u.prefix4)); | |
9457 | vty_out(vty, "\n"); | |
9458 | } | |
d62a17ae | 9459 | |
43b8d1d8 CS |
9460 | /* Retransmit Interval print. */ |
9461 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
9462 | retransmit_interval) | |
9463 | && params->retransmit_interval | |
9464 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
9465 | vty_out(vty, " ip ospf retransmit-interval %u", | |
9466 | params->retransmit_interval); | |
9467 | if (params != IF_DEF_PARAMS(ifp)) | |
9468 | vty_out(vty, " %s", | |
9469 | inet_ntoa(rn->p.u.prefix4)); | |
9470 | vty_out(vty, "\n"); | |
9471 | } | |
d62a17ae | 9472 | |
43b8d1d8 CS |
9473 | /* Transmit Delay print. */ |
9474 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) | |
9475 | && params->transmit_delay | |
9476 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
9477 | vty_out(vty, " ip ospf transmit-delay %u", | |
9478 | params->transmit_delay); | |
9479 | if (params != IF_DEF_PARAMS(ifp)) | |
9480 | vty_out(vty, " %s", | |
9481 | inet_ntoa(rn->p.u.prefix4)); | |
9482 | vty_out(vty, "\n"); | |
9483 | } | |
d62a17ae | 9484 | |
43b8d1d8 CS |
9485 | /* Area print. */ |
9486 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
9487 | if (ospf->instance) | |
9488 | vty_out(vty, " ip ospf %d", | |
9489 | ospf->instance); | |
9490 | else | |
9491 | vty_out(vty, " ip ospf"); | |
d62a17ae | 9492 | |
d62a17ae | 9493 | |
43b8d1d8 CS |
9494 | size_t buflen = MAX(strlen("4294967295"), |
9495 | strlen("255.255.255.255")); | |
9496 | char buf[buflen]; | |
d62a17ae | 9497 | |
43b8d1d8 CS |
9498 | area_id2str(buf, sizeof(buf), |
9499 | ¶ms->if_area, | |
9500 | params->if_area_id_fmt); | |
9501 | vty_out(vty, " area %s", buf); | |
9502 | if (params != IF_DEF_PARAMS(ifp)) | |
9503 | vty_out(vty, " %s", | |
9504 | inet_ntoa(rn->p.u.prefix4)); | |
9505 | vty_out(vty, "\n"); | |
9506 | } | |
d62a17ae | 9507 | |
43b8d1d8 CS |
9508 | /* bfd print. */ |
9509 | ospf_bfd_write_config(vty, params); | |
d62a17ae | 9510 | |
43b8d1d8 CS |
9511 | /* MTU ignore print. */ |
9512 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
9513 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { | |
9514 | if (params->mtu_ignore == 0) | |
9515 | vty_out(vty, " no ip ospf mtu-ignore"); | |
9516 | else | |
9517 | vty_out(vty, " ip ospf mtu-ignore"); | |
9518 | if (params != IF_DEF_PARAMS(ifp)) | |
9519 | vty_out(vty, " %s", | |
9520 | inet_ntoa(rn->p.u.prefix4)); | |
9521 | vty_out(vty, "\n"); | |
9522 | } | |
d62a17ae | 9523 | |
a8b828f3 | 9524 | |
43b8d1d8 CS |
9525 | while (1) { |
9526 | if (rn == NULL) | |
9527 | rn = route_top(IF_OIFS_PARAMS(ifp)); | |
9528 | else | |
9529 | rn = route_next(rn); | |
d62a17ae | 9530 | |
43b8d1d8 CS |
9531 | if (rn == NULL) |
9532 | break; | |
9533 | params = rn->info; | |
9534 | if (params != NULL) | |
9535 | break; | |
9536 | } | |
9537 | } while (rn); | |
9538 | ||
9539 | ospf_opaque_config_write_if(vty, ifp); | |
9540 | ||
9541 | vty_endframe(vty, NULL); | |
b5a8894d | 9542 | } |
d62a17ae | 9543 | return write; |
718e3744 | 9544 | } |
9545 | ||
43b8d1d8 CS |
9546 | /* Configuration write function for ospfd. */ |
9547 | static int config_write_interface(struct vty *vty) | |
9548 | { | |
9549 | int write = 0; | |
9550 | struct ospf *ospf = NULL; | |
9551 | struct listnode *node = NULL; | |
9552 | ||
9553 | /* Traverse all ospf [vrf] instances */ | |
9554 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) | |
9555 | write += config_write_interface_one(vty, ospf); | |
9556 | ||
9557 | return write; | |
9558 | } | |
9559 | ||
d62a17ae | 9560 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 9561 | { |
d62a17ae | 9562 | struct route_node *rn; |
9563 | u_char buf[INET_ADDRSTRLEN]; | |
718e3744 | 9564 | |
d62a17ae | 9565 | /* `network area' print. */ |
9566 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
9567 | if (rn->info) { | |
9568 | struct ospf_network *n = rn->info; | |
718e3744 | 9569 | |
d62a17ae | 9570 | memset(buf, 0, INET_ADDRSTRLEN); |
718e3744 | 9571 | |
d62a17ae | 9572 | /* Create Area ID string by specified Area ID format. */ |
9573 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
9574 | strncpy((char *)buf, inet_ntoa(n->area_id), | |
9575 | INET_ADDRSTRLEN); | |
9576 | else | |
9577 | sprintf((char *)buf, "%lu", | |
9578 | (unsigned long int)ntohl( | |
9579 | n->area_id.s_addr)); | |
718e3744 | 9580 | |
d62a17ae | 9581 | /* Network print. */ |
9582 | vty_out(vty, " network %s/%d area %s\n", | |
9583 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen, | |
9584 | buf); | |
9585 | } | |
718e3744 | 9586 | |
d62a17ae | 9587 | return 0; |
718e3744 | 9588 | } |
9589 | ||
d62a17ae | 9590 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 9591 | { |
d62a17ae | 9592 | struct listnode *node; |
9593 | struct ospf_area *area; | |
9594 | u_char buf[INET_ADDRSTRLEN]; | |
718e3744 | 9595 | |
d62a17ae | 9596 | /* Area configuration print. */ |
9597 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
9598 | struct route_node *rn1; | |
718e3744 | 9599 | |
d62a17ae | 9600 | area_id2str((char *)buf, INET_ADDRSTRLEN, &area->area_id, |
9601 | area->area_id_fmt); | |
718e3744 | 9602 | |
d62a17ae | 9603 | if (area->auth_type != OSPF_AUTH_NULL) { |
9604 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
9605 | vty_out(vty, " area %s authentication\n", buf); | |
9606 | else | |
9607 | vty_out(vty, | |
9608 | " area %s authentication message-digest\n", | |
9609 | buf); | |
9610 | } | |
718e3744 | 9611 | |
d62a17ae | 9612 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
9613 | vty_out(vty, " area %s shortcut %s\n", buf, | |
9614 | ospf_shortcut_mode_str | |
9615 | [area->shortcut_configured]); | |
9616 | ||
9617 | if ((area->external_routing == OSPF_AREA_STUB) | |
9618 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 9619 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 9620 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
9621 | if (area->no_summary) |
9622 | vty_out(vty, " no-summary\n"); | |
9623 | vty_out(vty, "\n"); | |
9624 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 9625 | switch (area->NSSATranslatorRole) { |
9626 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
9627 | vty_out(vty, |
9628 | " area %s nssa translate-never\n", | |
9629 | buf); | |
d62a17ae | 9630 | break; |
9631 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
9632 | vty_out(vty, |
9633 | " area %s nssa translate-always\n", | |
9634 | buf); | |
d62a17ae | 9635 | break; |
d62a17ae | 9636 | } |
7ef56a73 CS |
9637 | if (area->no_summary) |
9638 | vty_out(vty, | |
9639 | " area %s nssa no-summary\n", | |
9640 | buf); | |
d62a17ae | 9641 | } |
718e3744 | 9642 | |
d62a17ae | 9643 | if (area->default_cost != 1) |
9644 | vty_out(vty, " area %s default-cost %d\n", buf, | |
9645 | area->default_cost); | |
9646 | } | |
718e3744 | 9647 | |
d62a17ae | 9648 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
9649 | if (rn1->info) { | |
9650 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 9651 | |
d62a17ae | 9652 | vty_out(vty, " area %s range %s/%d", buf, |
9653 | inet_ntoa(rn1->p.u.prefix4), | |
9654 | rn1->p.prefixlen); | |
718e3744 | 9655 | |
d62a17ae | 9656 | if (range->cost_config |
9657 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
9658 | vty_out(vty, " cost %d", | |
9659 | range->cost_config); | |
718e3744 | 9660 | |
d62a17ae | 9661 | if (!CHECK_FLAG(range->flags, |
9662 | OSPF_AREA_RANGE_ADVERTISE)) | |
9663 | vty_out(vty, " not-advertise"); | |
718e3744 | 9664 | |
d62a17ae | 9665 | if (CHECK_FLAG(range->flags, |
9666 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
9667 | vty_out(vty, " substitute %s/%d", | |
9668 | inet_ntoa(range->subst_addr), | |
9669 | range->subst_masklen); | |
9670 | ||
9671 | vty_out(vty, "\n"); | |
9672 | } | |
9673 | ||
9674 | if (EXPORT_NAME(area)) | |
9675 | vty_out(vty, " area %s export-list %s\n", buf, | |
9676 | EXPORT_NAME(area)); | |
9677 | ||
9678 | if (IMPORT_NAME(area)) | |
9679 | vty_out(vty, " area %s import-list %s\n", buf, | |
9680 | IMPORT_NAME(area)); | |
9681 | ||
9682 | if (PREFIX_NAME_IN(area)) | |
9683 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
9684 | PREFIX_NAME_IN(area)); | |
9685 | ||
9686 | if (PREFIX_NAME_OUT(area)) | |
9687 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
9688 | buf, PREFIX_NAME_OUT(area)); | |
9689 | } | |
9690 | ||
9691 | return 0; | |
718e3744 | 9692 | } |
9693 | ||
d62a17ae | 9694 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 9695 | { |
d62a17ae | 9696 | struct ospf_nbr_nbma *nbr_nbma; |
9697 | struct route_node *rn; | |
718e3744 | 9698 | |
d62a17ae | 9699 | /* Static Neighbor configuration print. */ |
9700 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
9701 | if ((nbr_nbma = rn->info)) { | |
9702 | vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr)); | |
718e3744 | 9703 | |
d62a17ae | 9704 | if (nbr_nbma->priority |
9705 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
9706 | vty_out(vty, " priority %d", | |
9707 | nbr_nbma->priority); | |
718e3744 | 9708 | |
d62a17ae | 9709 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
9710 | vty_out(vty, " poll-interval %d", | |
9711 | nbr_nbma->v_poll); | |
9712 | ||
9713 | vty_out(vty, "\n"); | |
9714 | } | |
9715 | ||
9716 | return 0; | |
9717 | } | |
9718 | ||
9719 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
9720 | { | |
9721 | struct listnode *node; | |
9722 | struct ospf_vl_data *vl_data; | |
9723 | char buf[INET_ADDRSTRLEN]; | |
9724 | ||
9725 | /* Virtual-Link print */ | |
9726 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
9727 | struct listnode *n2; | |
9728 | struct crypt_key *ck; | |
9729 | struct ospf_interface *oi; | |
9730 | ||
9731 | if (vl_data != NULL) { | |
9732 | memset(buf, 0, INET_ADDRSTRLEN); | |
9733 | ||
9734 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, | |
9735 | vl_data->vl_area_id_fmt); | |
9736 | oi = vl_data->vl_oi; | |
9737 | ||
9738 | /* timers */ | |
9739 | if (OSPF_IF_PARAM(oi, v_hello) | |
9740 | != OSPF_HELLO_INTERVAL_DEFAULT | |
9741 | || OSPF_IF_PARAM(oi, v_wait) | |
9742 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
9743 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
9744 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
9745 | || OSPF_IF_PARAM(oi, transmit_delay) | |
9746 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
9747 | vty_out(vty, | |
9748 | " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", | |
9749 | buf, inet_ntoa(vl_data->vl_peer), | |
9750 | OSPF_IF_PARAM(oi, v_hello), | |
9751 | OSPF_IF_PARAM(oi, retransmit_interval), | |
9752 | OSPF_IF_PARAM(oi, transmit_delay), | |
9753 | OSPF_IF_PARAM(oi, v_wait)); | |
9754 | else | |
9755 | vty_out(vty, " area %s virtual-link %s\n", buf, | |
9756 | inet_ntoa(vl_data->vl_peer)); | |
9757 | /* Auth key */ | |
9758 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
9759 | != '\0') | |
9760 | vty_out(vty, | |
9761 | " area %s virtual-link %s authentication-key %s\n", | |
9762 | buf, inet_ntoa(vl_data->vl_peer), | |
9763 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
9764 | ->auth_simple); | |
9765 | /* md5 keys */ | |
9766 | for (ALL_LIST_ELEMENTS_RO( | |
9767 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
9768 | ->auth_crypt, | |
9769 | n2, ck)) | |
9770 | vty_out(vty, | |
9771 | " area %s virtual-link %s" | |
9772 | " message-digest-key %d md5 %s\n", | |
9773 | buf, inet_ntoa(vl_data->vl_peer), | |
9774 | ck->key_id, ck->auth_key); | |
9775 | } | |
9776 | } | |
9777 | ||
9778 | return 0; | |
718e3744 | 9779 | } |
9780 | ||
6b0655a2 | 9781 | |
d62a17ae | 9782 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 9783 | { |
d62a17ae | 9784 | int type; |
718e3744 | 9785 | |
d62a17ae | 9786 | /* redistribute print. */ |
9787 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
9788 | struct list *red_list; | |
9789 | struct listnode *node; | |
9790 | struct ospf_redist *red; | |
718e3744 | 9791 | |
d62a17ae | 9792 | red_list = ospf->redist[type]; |
9793 | if (!red_list) | |
9794 | continue; | |
7c8ff89e | 9795 | |
d62a17ae | 9796 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
9797 | vty_out(vty, " redistribute %s", | |
9798 | zebra_route_string(type)); | |
9799 | if (red->instance) | |
9800 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 9801 | |
d62a17ae | 9802 | if (red->dmetric.value >= 0) |
9803 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 9804 | |
d62a17ae | 9805 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
9806 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 9807 | |
d62a17ae | 9808 | if (ROUTEMAP_NAME(red)) |
9809 | vty_out(vty, " route-map %s", | |
9810 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 9811 | |
d62a17ae | 9812 | vty_out(vty, "\n"); |
9813 | } | |
9814 | } | |
718e3744 | 9815 | |
d62a17ae | 9816 | return 0; |
718e3744 | 9817 | } |
9818 | ||
d62a17ae | 9819 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 9820 | { |
d62a17ae | 9821 | if (ospf->default_metric != -1) |
9822 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
9823 | return 0; | |
718e3744 | 9824 | } |
9825 | ||
d62a17ae | 9826 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
9827 | { | |
9828 | int type; | |
9829 | struct ospf_redist *red; | |
718e3744 | 9830 | |
d62a17ae | 9831 | if (ospf) { |
9832 | /* distribute-list print. */ | |
9833 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
9834 | if (DISTRIBUTE_NAME(ospf, type)) | |
9835 | vty_out(vty, " distribute-list %s out %s\n", | |
9836 | DISTRIBUTE_NAME(ospf, type), | |
9837 | zebra_route_string(type)); | |
7c8ff89e | 9838 | |
d62a17ae | 9839 | /* default-information print. */ |
9840 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
9841 | vty_out(vty, " default-information originate"); | |
9842 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
9843 | vty_out(vty, " always"); | |
718e3744 | 9844 | |
d62a17ae | 9845 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9846 | if (red) { | |
9847 | if (red->dmetric.value >= 0) | |
9848 | vty_out(vty, " metric %d", | |
9849 | red->dmetric.value); | |
9850 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) | |
9851 | vty_out(vty, " metric-type 1"); | |
718e3744 | 9852 | |
d62a17ae | 9853 | if (ROUTEMAP_NAME(red)) |
9854 | vty_out(vty, " route-map %s", | |
9855 | ROUTEMAP_NAME(red)); | |
9856 | } | |
9857 | ||
9858 | vty_out(vty, "\n"); | |
9859 | } | |
9860 | } | |
9861 | ||
9862 | return 0; | |
718e3744 | 9863 | } |
9864 | ||
d62a17ae | 9865 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
9866 | { | |
9867 | struct route_node *rn; | |
9868 | struct ospf_distance *odistance; | |
9869 | ||
9870 | if (ospf->distance_all) | |
9871 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
9872 | ||
9873 | if (ospf->distance_intra || ospf->distance_inter | |
9874 | || ospf->distance_external) { | |
9875 | vty_out(vty, " distance ospf"); | |
9876 | ||
9877 | if (ospf->distance_intra) | |
9878 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
9879 | if (ospf->distance_inter) | |
9880 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
9881 | if (ospf->distance_external) | |
9882 | vty_out(vty, " external %d", ospf->distance_external); | |
9883 | ||
9884 | vty_out(vty, "\n"); | |
9885 | } | |
9886 | ||
9887 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
9888 | if ((odistance = rn->info) != NULL) { | |
9889 | vty_out(vty, " distance %d %s/%d %s\n", | |
9890 | odistance->distance, inet_ntoa(rn->p.u.prefix4), | |
9891 | rn->p.prefixlen, | |
9892 | odistance->access_list ? odistance->access_list | |
9893 | : ""); | |
9894 | } | |
9895 | return 0; | |
718e3744 | 9896 | } |
9897 | ||
43b8d1d8 | 9898 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 9899 | { |
f4e14fdb | 9900 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 9901 | struct interface *ifp; |
9902 | struct ospf_interface *oi; | |
43b8d1d8 | 9903 | struct listnode *node = NULL; |
d62a17ae | 9904 | int write = 0; |
9905 | ||
43b8d1d8 CS |
9906 | /* `router ospf' print. */ |
9907 | if (ospf->instance && ospf->name) { | |
9908 | vty_out(vty, "router ospf %d vrf %s\n", | |
9909 | ospf->instance, ospf->name); | |
9910 | } else if (ospf->instance) { | |
9911 | vty_out(vty, "router ospf %d\n", | |
9912 | ospf->instance); | |
9913 | } else if (ospf->name) { | |
9914 | vty_out(vty, "router ospf vrf %s\n", | |
9915 | ospf->name); | |
9916 | } else | |
9917 | vty_out(vty, "router ospf\n"); | |
9918 | ||
9919 | if (!ospf->networks) { | |
9920 | write++; | |
b5a8894d | 9921 | return write; |
43b8d1d8 | 9922 | } |
d62a17ae | 9923 | |
43b8d1d8 CS |
9924 | /* Router ID print. */ |
9925 | if (ospf->router_id_static.s_addr != 0) | |
9926 | vty_out(vty, " ospf router-id %s\n", | |
9927 | inet_ntoa(ospf->router_id_static)); | |
d62a17ae | 9928 | |
43b8d1d8 CS |
9929 | /* ABR type print. */ |
9930 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
9931 | vty_out(vty, " ospf abr-type %s\n", | |
9932 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 9933 | |
43b8d1d8 CS |
9934 | /* log-adjacency-changes flag print. */ |
9935 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
9936 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
9937 | vty_out(vty, " log-adjacency-changes detail\n"); | |
9938 | else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
9939 | vty_out(vty, " log-adjacency-changes\n"); | |
9940 | } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { | |
9941 | vty_out(vty, " no log-adjacency-changes\n"); | |
9942 | } | |
b5a8894d | 9943 | |
43b8d1d8 CS |
9944 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
9945 | * 12.1. */ | |
9946 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
9947 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 9948 | |
43b8d1d8 CS |
9949 | /* auto-cost reference-bandwidth configuration. */ |
9950 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
9951 | vty_out(vty, | |
9952 | "! Important: ensure reference bandwidth " | |
9953 | "is consistent across all routers\n"); | |
9954 | vty_out(vty, " auto-cost reference-bandwidth %d\n", | |
9955 | ospf->ref_bandwidth); | |
9956 | } | |
d62a17ae | 9957 | |
43b8d1d8 CS |
9958 | /* SPF timers print. */ |
9959 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
9960 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
9961 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
9962 | vty_out(vty, " timers throttle spf %d %d %d\n", | |
9963 | ospf->spf_delay, ospf->spf_holdtime, | |
9964 | ospf->spf_max_holdtime); | |
9965 | ||
9966 | /* LSA timers print. */ | |
9967 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
9968 | vty_out(vty, " timers throttle lsa all %d\n", | |
9969 | ospf->min_ls_interval); | |
9970 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
9971 | vty_out(vty, " timers lsa min-arrival %d\n", | |
9972 | ospf->min_ls_arrival); | |
9973 | ||
9974 | /* Write multiplier print. */ | |
9975 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
9976 | vty_out(vty, " ospf write-multiplier %d\n", | |
9977 | ospf->write_oi_count); | |
d62a17ae | 9978 | |
43b8d1d8 CS |
9979 | /* Max-metric router-lsa print */ |
9980 | config_write_stub_router(vty, ospf); | |
d62a17ae | 9981 | |
43b8d1d8 CS |
9982 | /* SPF refresh parameters print. */ |
9983 | if (ospf->lsa_refresh_interval | |
9984 | != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
9985 | vty_out(vty, " refresh timer %d\n", | |
9986 | ospf->lsa_refresh_interval); | |
d62a17ae | 9987 | |
43b8d1d8 CS |
9988 | /* Redistribute information print. */ |
9989 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 9990 | |
43b8d1d8 CS |
9991 | /* passive-interface print. */ |
9992 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
9993 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 9994 | |
451fda4f | 9995 | FOR_ALL_INTERFACES (vrf, ifp) |
43b8d1d8 CS |
9996 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
9997 | passive_interface) | |
9998 | && IF_DEF_PARAMS(ifp)->passive_interface | |
9999 | != ospf->passive_interface_default) { | |
10000 | vty_out(vty, " %spassive-interface %s\n", | |
10001 | IF_DEF_PARAMS(ifp)->passive_interface | |
10002 | ? "" | |
10003 | : "no ", | |
10004 | ifp->name); | |
10005 | } | |
10006 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
10007 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, | |
10008 | passive_interface)) | |
10009 | continue; | |
10010 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
10011 | passive_interface)) { | |
10012 | if (oi->params->passive_interface | |
10013 | == IF_DEF_PARAMS(oi->ifp) | |
10014 | ->passive_interface) | |
10015 | continue; | |
10016 | } else if (oi->params->passive_interface | |
10017 | == ospf->passive_interface_default) | |
10018 | continue; | |
d62a17ae | 10019 | |
43b8d1d8 CS |
10020 | vty_out(vty, " %spassive-interface %s %s\n", |
10021 | oi->params->passive_interface ? "" : "no ", | |
10022 | oi->ifp->name, | |
10023 | inet_ntoa(oi->address->u.prefix4)); | |
10024 | } | |
d62a17ae | 10025 | |
43b8d1d8 CS |
10026 | /* Network area print. */ |
10027 | config_write_network_area(vty, ospf); | |
d62a17ae | 10028 | |
43b8d1d8 CS |
10029 | /* Area config print. */ |
10030 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 10031 | |
43b8d1d8 CS |
10032 | /* static neighbor print. */ |
10033 | config_write_ospf_nbr_nbma(vty, ospf); | |
10034 | ||
10035 | /* Virtual-Link print. */ | |
10036 | config_write_virtual_link(vty, ospf); | |
10037 | ||
10038 | /* Default metric configuration. */ | |
10039 | config_write_ospf_default_metric(vty, ospf); | |
10040 | ||
10041 | /* Distribute-list and default-information print. */ | |
10042 | config_write_ospf_distribute(vty, ospf); | |
10043 | ||
10044 | /* Distance configuration. */ | |
10045 | config_write_ospf_distance(vty, ospf); | |
10046 | ||
10047 | ospf_opaque_config_write_router(vty, ospf); | |
10048 | ||
10049 | write++; | |
10050 | return write; | |
10051 | } | |
10052 | ||
10053 | /* OSPF configuration write function. */ | |
10054 | static int ospf_config_write(struct vty *vty) | |
10055 | { | |
10056 | struct ospf *ospf; | |
10057 | struct listnode *ospf_node = NULL; | |
10058 | int write = 0; | |
10059 | ||
10060 | if (listcount(om->ospf) == 0) | |
10061 | return write; | |
10062 | ||
10063 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
10064 | if (ospf->oi_running) | |
10065 | write += ospf_config_write_one(vty, ospf); | |
b5a8894d | 10066 | } |
d62a17ae | 10067 | return write; |
10068 | } | |
10069 | ||
10070 | void ospf_vty_show_init(void) | |
10071 | { | |
10072 | /* "show ip ospf" commands. */ | |
10073 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
10074 | ||
10075 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
10076 | ||
10077 | /* "show ip ospf database" commands. */ | |
10078 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
10079 | ||
10080 | install_element(VIEW_NODE, | |
10081 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
10082 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
10083 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
10084 | ||
10085 | /* "show ip ospf interface" commands. */ | |
10086 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
10087 | ||
10088 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
10089 | /* "show ip ospf interface traffic */ |
10090 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 10091 | |
10092 | /* "show ip ospf neighbor" commands. */ | |
10093 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
10094 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
10095 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
10096 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
10097 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
10098 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
10099 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
10100 | ||
10101 | install_element(VIEW_NODE, | |
10102 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
10103 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
10104 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
10105 | install_element(VIEW_NODE, | |
10106 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
10107 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
10108 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
10109 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
10110 | ||
10111 | /* "show ip ospf route" commands. */ | |
10112 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
10113 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
10114 | ||
10115 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
10116 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
10117 | |
10118 | /* "show ip ospf vrfs" commands. */ | |
10119 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
718e3744 | 10120 | } |
10121 | ||
6b0655a2 | 10122 | |
718e3744 | 10123 | /* ospfd's interface node. */ |
d62a17ae | 10124 | static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1}; |
718e3744 | 10125 | |
10126 | /* Initialization of OSPF interface. */ | |
d62a17ae | 10127 | static void ospf_vty_if_init(void) |
10128 | { | |
10129 | /* Install interface node. */ | |
10130 | install_node(&interface_node, config_write_interface); | |
10131 | if_cmd_init(); | |
10132 | ||
10133 | /* "ip ospf authentication" commands. */ | |
10134 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
10135 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
10136 | install_element(INTERFACE_NODE, | |
10137 | &no_ip_ospf_authentication_args_addr_cmd); | |
10138 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
10139 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
10140 | install_element(INTERFACE_NODE, | |
10141 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
10142 | install_element(INTERFACE_NODE, | |
10143 | &no_ospf_authentication_key_authkey_addr_cmd); | |
10144 | ||
10145 | /* "ip ospf message-digest-key" commands. */ | |
10146 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
10147 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
10148 | ||
10149 | /* "ip ospf cost" commands. */ | |
10150 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
10151 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
10152 | ||
10153 | /* "ip ospf mtu-ignore" commands. */ | |
10154 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
10155 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
10156 | ||
10157 | /* "ip ospf dead-interval" commands. */ | |
10158 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
10159 | install_element(INTERFACE_NODE, | |
10160 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
10161 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
10162 | ||
10163 | /* "ip ospf hello-interval" commands. */ | |
10164 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
10165 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
10166 | ||
10167 | /* "ip ospf network" commands. */ | |
10168 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
10169 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
10170 | ||
10171 | /* "ip ospf priority" commands. */ | |
10172 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
10173 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
10174 | ||
10175 | /* "ip ospf retransmit-interval" commands. */ | |
10176 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
10177 | install_element(INTERFACE_NODE, | |
10178 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
10179 | ||
10180 | /* "ip ospf transmit-delay" commands. */ | |
10181 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
10182 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
10183 | ||
10184 | /* "ip ospf area" commands. */ | |
10185 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
10186 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
10187 | ||
10188 | /* These commands are compatibitliy for previous version. */ | |
10189 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
10190 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
10191 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
10192 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
10193 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
10194 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
10195 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
10196 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
10197 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
10198 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
10199 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
10200 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
10201 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
10202 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
10203 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
10204 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
10205 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
10206 | } | |
10207 | ||
10208 | static void ospf_vty_zebra_init(void) | |
10209 | { | |
10210 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
10211 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
10212 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
10213 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
10214 | ||
10215 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
10216 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
10217 | ||
10218 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
10219 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
10220 | ||
10221 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
10222 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
10223 | ||
10224 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
10225 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
10226 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
10227 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
718e3744 | 10228 | #if 0 |
10229 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
10230 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
10231 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
10232 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
10233 | #endif /* 0 */ | |
10234 | } | |
10235 | ||
d62a17ae | 10236 | static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1}; |
718e3744 | 10237 | |
d62a17ae | 10238 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 10239 | { |
d62a17ae | 10240 | if (!if_is_operative(ifp)) |
10241 | return; | |
09f35f8c | 10242 | |
d62a17ae | 10243 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
10244 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 10245 | |
d62a17ae | 10246 | ospf_if_reset(ifp); |
09f35f8c DS |
10247 | } |
10248 | ||
10249 | DEFUN (clear_ip_ospf_interface, | |
10250 | clear_ip_ospf_interface_cmd, | |
10251 | "clear ip ospf interface [IFNAME]", | |
10252 | CLEAR_STR | |
10253 | IP_STR | |
10254 | "OSPF information\n" | |
10255 | "Interface information\n" | |
10256 | "Interface name\n") | |
10257 | { | |
d62a17ae | 10258 | int idx_ifname = 4; |
10259 | struct interface *ifp; | |
f4e14fdb | 10260 | struct listnode *node; |
b5a8894d | 10261 | struct ospf *ospf = NULL; |
09f35f8c | 10262 | |
d62a17ae | 10263 | if (argc == 4) /* Clear all the ospfv2 interfaces. */ |
10264 | { | |
f4e14fdb RW |
10265 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
10266 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 10267 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
10268 | ospf_interface_clear(ifp); |
10269 | } | |
10270 | } else { | |
10271 | /* Interface name is specified. */ | |
10272 | ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg); | |
10273 | if (ifp == NULL) | |
d62a17ae | 10274 | vty_out(vty, "No such interface name\n"); |
10275 | else | |
10276 | ospf_interface_clear(ifp); | |
10277 | } | |
10278 | ||
10279 | return CMD_SUCCESS; | |
09f35f8c DS |
10280 | } |
10281 | ||
d62a17ae | 10282 | void ospf_vty_clear_init(void) |
09f35f8c | 10283 | { |
d62a17ae | 10284 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
09f35f8c DS |
10285 | } |
10286 | ||
6b0655a2 | 10287 | |
718e3744 | 10288 | /* Install OSPF related vty commands. */ |
d62a17ae | 10289 | void ospf_vty_init(void) |
10290 | { | |
10291 | /* Install ospf top node. */ | |
10292 | install_node(&ospf_node, ospf_config_write); | |
10293 | ||
10294 | /* "router ospf" commands. */ | |
10295 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
10296 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
10297 | ||
10298 | ||
10299 | install_default(OSPF_NODE); | |
10300 | ||
10301 | /* "ospf router-id" commands. */ | |
10302 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
10303 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
10304 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
10305 | ||
10306 | /* "passive-interface" commands. */ | |
10307 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
10308 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
10309 | ||
10310 | /* "ospf abr-type" commands. */ | |
10311 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
10312 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
10313 | ||
10314 | /* "ospf log-adjacency-changes" commands. */ | |
10315 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
10316 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
10317 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
10318 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
10319 | ||
10320 | /* "ospf rfc1583-compatible" commands. */ | |
10321 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
10322 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
10323 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
10324 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
10325 | ||
10326 | /* "network area" commands. */ | |
10327 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
10328 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
10329 | ||
10330 | /* "area authentication" commands. */ | |
10331 | install_element(OSPF_NODE, | |
10332 | &ospf_area_authentication_message_digest_cmd); | |
10333 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
10334 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
10335 | ||
10336 | /* "area range" commands. */ | |
10337 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
10338 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
10339 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
10340 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
10341 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
10342 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
10343 | ||
10344 | /* "area virtual-link" commands. */ | |
10345 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
10346 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
10347 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
10348 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
10349 | ||
10350 | ||
10351 | /* "area stub" commands. */ | |
10352 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
10353 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
10354 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
10355 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
10356 | ||
10357 | /* "area nssa" commands. */ | |
10358 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 10359 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
10360 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 10361 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
d62a17ae | 10362 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
10363 | ||
10364 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
10365 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
10366 | ||
10367 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
10368 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
10369 | ||
10370 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
10371 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
10372 | ||
10373 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
10374 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
10375 | ||
10376 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
10377 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
10378 | ||
10379 | /* SPF timer commands */ | |
10380 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
10381 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
10382 | ||
10383 | /* LSA timers commands */ | |
10384 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
10385 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
10386 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
10387 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
10388 | install_element(OSPF_NODE, &ospf_timers_lsa_arrival_cmd); | |
10389 | install_element(OSPF_NODE, &no_ospf_timers_lsa_arrival_cmd); | |
d62a17ae | 10390 | |
10391 | /* refresh timer commands */ | |
10392 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
10393 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
10394 | ||
10395 | /* max-metric commands */ | |
10396 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
10397 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
10398 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
10399 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
10400 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
10401 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
10402 | ||
10403 | /* reference bandwidth commands */ | |
10404 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
10405 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
10406 | ||
10407 | /* "neighbor" commands. */ | |
10408 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
10409 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
10410 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
10411 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
10412 | ||
10413 | /* write multiplier commands */ | |
10414 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
10415 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
10416 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
10417 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
10418 | ||
10419 | /* Init interface related vty commands. */ | |
10420 | ospf_vty_if_init(); | |
10421 | ||
10422 | /* Init zebra related vty commands. */ | |
10423 | ospf_vty_zebra_init(); | |
718e3744 | 10424 | } |