]>
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 | |
c572fbfe DL |
56 | FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES, |
57 | { .val_long = true, .match_profile = "datacenter", }, | |
58 | { .val_long = false }, | |
59 | ) | |
60 | ||
2b64873d | 61 | static const char *const ospf_network_type_str[] = { |
d62a17ae | 62 | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", |
63 | "VIRTUALLINK", "LOOPBACK"}; | |
718e3744 | 64 | |
718e3744 | 65 | /* Utility functions. */ |
d62a17ae | 66 | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) |
718e3744 | 67 | { |
d62a17ae | 68 | char *ep; |
718e3744 | 69 | |
d62a17ae | 70 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); |
71 | if (*ep && !inet_aton(str, area_id)) | |
72 | return -1; | |
718e3744 | 73 | |
d62a17ae | 74 | *area_id_fmt = |
75 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; | |
718e3744 | 76 | |
d62a17ae | 77 | return 0; |
718e3744 | 78 | } |
79 | ||
1f9d4e3d | 80 | static void area_id2str(char *buf, int length, struct in_addr *area_id, |
81 | int area_id_fmt) | |
86573dcb | 82 | { |
d62a17ae | 83 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
1f9d4e3d | 84 | inet_ntop(AF_INET, area_id, buf, length); |
d62a17ae | 85 | else |
86 | sprintf(buf, "%lu", (unsigned long)ntohl(area_id->s_addr)); | |
86573dcb | 87 | } |
6b0655a2 | 88 | |
d62a17ae | 89 | static int str2metric(const char *str, int *metric) |
718e3744 | 90 | { |
d62a17ae | 91 | /* Sanity check. */ |
92 | if (str == NULL) | |
93 | return 0; | |
718e3744 | 94 | |
d62a17ae | 95 | *metric = strtol(str, NULL, 10); |
96 | if (*metric < 0 && *metric > 16777214) { | |
97 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ | |
98 | return 0; | |
99 | } | |
718e3744 | 100 | |
d62a17ae | 101 | return 1; |
718e3744 | 102 | } |
103 | ||
d62a17ae | 104 | static int str2metric_type(const char *str, int *metric_type) |
718e3744 | 105 | { |
d62a17ae | 106 | /* Sanity check. */ |
107 | if (str == NULL) | |
108 | return 0; | |
718e3744 | 109 | |
d62a17ae | 110 | if (strncmp(str, "1", 1) == 0) |
111 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
112 | else if (strncmp(str, "2", 1) == 0) | |
113 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
114 | else | |
115 | return 0; | |
718e3744 | 116 | |
d62a17ae | 117 | return 1; |
718e3744 | 118 | } |
119 | ||
d62a17ae | 120 | int ospf_oi_count(struct interface *ifp) |
718e3744 | 121 | { |
d62a17ae | 122 | struct route_node *rn; |
123 | int i = 0; | |
718e3744 | 124 | |
d62a17ae | 125 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
126 | if (rn->info) | |
127 | i++; | |
718e3744 | 128 | |
d62a17ae | 129 | return i; |
718e3744 | 130 | } |
131 | ||
996c9314 LB |
132 | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ |
133 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ | |
134 | vrf_name = argv[idx_vrf + 1]->arg; \ | |
135 | all_vrf = strmatch(vrf_name, "all"); \ | |
43b8d1d8 CS |
136 | } |
137 | ||
138 | static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, | |
139 | struct cmd_token *argv[], | |
996c9314 | 140 | const int argc, uint32_t enable, |
d7c0a89a | 141 | unsigned short *instance) |
718e3744 | 142 | { |
b5a8894d | 143 | struct ospf *ospf = NULL; |
34d6798f | 144 | int idx_vrf = 0, idx_inst = 0; |
b5a8894d | 145 | const char *vrf_name = NULL; |
c572fbfe | 146 | bool created = false; |
b5a8894d | 147 | |
34d6798f CS |
148 | *instance = 0; |
149 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) | |
150 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); | |
151 | ||
b5a8894d | 152 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
b5a8894d | 153 | vrf_name = argv[idx_vrf + 1]->arg; |
6895b354 PG |
154 | if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME)) |
155 | vrf_name = NULL; | |
43b8d1d8 | 156 | if (enable) { |
43b8d1d8 | 157 | /* Allocate VRF aware instance */ |
c572fbfe | 158 | ospf = ospf_get(*instance, vrf_name, &created); |
43b8d1d8 | 159 | } else { |
43b8d1d8 CS |
160 | ospf = ospf_lookup_by_inst_name(*instance, vrf_name); |
161 | } | |
b5a8894d | 162 | } else { |
43b8d1d8 | 163 | if (enable) { |
c572fbfe | 164 | ospf = ospf_get(*instance, NULL, &created); |
43b8d1d8 | 165 | } else { |
43b8d1d8 | 166 | ospf = ospf_lookup_instance(*instance); |
b5a8894d | 167 | } |
d62a17ae | 168 | } |
34d6798f | 169 | |
c572fbfe DL |
170 | if (created) { |
171 | if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
172 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
173 | } | |
174 | ||
43b8d1d8 CS |
175 | return ospf; |
176 | } | |
177 | ||
52d0c099 | 178 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
d7c0a89a | 179 | json_object *json, uint8_t use_vrf) |
52d0c099 | 180 | { |
b1c3ae8c CS |
181 | if (use_vrf) { |
182 | if (json) { | |
183 | if (ospf->vrf_id == VRF_DEFAULT) | |
184 | json_object_string_add(json, "vrfName", | |
185 | "default"); | |
186 | else | |
187 | json_object_string_add(json, "vrfName", | |
188 | ospf->name); | |
189 | json_object_int_add(json, "vrfId", ospf->vrf_id); | |
190 | } else { | |
191 | if (ospf->vrf_id == VRF_DEFAULT) | |
192 | vty_out(vty, "VRF Name: %s\n", "default"); | |
193 | else if (ospf->name) | |
194 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
195 | } | |
52d0c099 | 196 | } |
52d0c099 CS |
197 | } |
198 | ||
43b8d1d8 | 199 | #ifndef VTYSH_EXTRACT_PL |
2e4c2296 | 200 | #include "ospfd/ospf_vty_clippy.c" |
43b8d1d8 CS |
201 | #endif |
202 | ||
203 | DEFUN_NOSH (router_ospf, | |
204 | router_ospf_cmd, | |
205 | "router ospf [{(1-65535)|vrf NAME}]", | |
206 | "Enable a routing process\n" | |
207 | "Start OSPF configuration\n" | |
208 | "Instance ID\n" | |
209 | VRF_CMD_HELP_STR) | |
210 | { | |
211 | struct ospf *ospf = NULL; | |
212 | int ret = CMD_SUCCESS; | |
d7c0a89a | 213 | unsigned short instance = 0; |
aed7cc62 CS |
214 | struct vrf *vrf = NULL; |
215 | struct route_node *rn; | |
216 | struct interface *ifp; | |
43b8d1d8 CS |
217 | |
218 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance); | |
219 | if (!ospf) | |
220 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 221 | |
d62a17ae | 222 | /* The following logic to set the vty qobj index is in place to be able |
223 | to ignore the commands which dont belong to this instance. */ | |
64ac44f6 | 224 | if (ospf->instance != instance) { |
d62a17ae | 225 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
64ac44f6 CS |
226 | ret = CMD_NOT_MY_INSTANCE; |
227 | } else { | |
b5a8894d CS |
228 | if (ospf->vrf_id != VRF_UNKNOWN) |
229 | ospf->oi_running = 1; | |
d62a17ae | 230 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 LB |
231 | zlog_debug( |
232 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
233 | instance, ospf->name ? ospf->name : "NIL", | |
234 | ospf->vrf_id, ospf->oi_running); | |
d62a17ae | 235 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); |
aed7cc62 CS |
236 | |
237 | /* Activate 'ip ospf area x' configured interfaces for given | |
238 | * vrf. Activate area on vrf x aware interfaces. | |
239 | * vrf_enable callback calls router_id_update which | |
240 | * internally will call ospf_if_update to trigger | |
241 | * network_run_state | |
242 | */ | |
243 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
244 | ||
245 | FOR_ALL_INTERFACES (vrf, ifp) { | |
246 | struct ospf_if_params *params; | |
247 | ||
248 | params = IF_DEF_PARAMS(ifp); | |
249 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
250 | for (rn = route_top(ospf->networks); rn; | |
251 | rn = route_next(rn)) { | |
252 | if (rn->info != NULL) { | |
253 | vty_out(vty, | |
996c9314 LB |
254 | "Interface %s has area config but please remove all network commands first.\n", |
255 | ifp->name); | |
aed7cc62 CS |
256 | return ret; |
257 | } | |
258 | } | |
e9f07a30 PG |
259 | if (!ospf_interface_area_is_already_set(ospf, |
260 | ifp)) { | |
261 | ospf_interface_area_set(ospf, ifp); | |
262 | ospf->if_ospf_cli_count++; | |
263 | } | |
aed7cc62 CS |
264 | } |
265 | } | |
266 | ||
d62a17ae | 267 | ospf_router_id_update(ospf); |
268 | } | |
269 | ||
64ac44f6 | 270 | return ret; |
718e3744 | 271 | } |
272 | ||
273 | DEFUN (no_router_ospf, | |
274 | no_router_ospf_cmd, | |
43b8d1d8 | 275 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 276 | NO_STR |
277 | "Enable a routing process\n" | |
7a7be519 | 278 | "Start OSPF configuration\n" |
b5a8894d CS |
279 | "Instance ID\n" |
280 | VRF_CMD_HELP_STR) | |
718e3744 | 281 | { |
d62a17ae | 282 | struct ospf *ospf; |
d7c0a89a | 283 | unsigned short instance = 0; |
b5a8894d | 284 | |
43b8d1d8 CS |
285 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); |
286 | if (ospf == NULL) { | |
287 | if (instance) | |
b5a8894d | 288 | return CMD_NOT_MY_INSTANCE; |
43b8d1d8 CS |
289 | else |
290 | return CMD_WARNING; | |
b5a8894d | 291 | } |
d62a17ae | 292 | ospf_finish(ospf); |
718e3744 | 293 | |
d62a17ae | 294 | return CMD_SUCCESS; |
718e3744 | 295 | } |
296 | ||
7c8ff89e | 297 | |
43b8d1d8 | 298 | DEFPY (ospf_router_id, |
718e3744 | 299 | ospf_router_id_cmd, |
300 | "ospf router-id A.B.C.D", | |
301 | "OSPF specific commands\n" | |
302 | "router-id for the OSPF process\n" | |
303 | "OSPF router-id in IP address format\n") | |
304 | { | |
a3d826f0 | 305 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 306 | |
d62a17ae | 307 | struct listnode *node; |
308 | struct ospf_area *area; | |
d62a17ae | 309 | |
310 | ospf->router_id_static = router_id; | |
311 | ||
312 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
313 | if (area->full_nbrs) { | |
314 | vty_out(vty, | |
315 | "For this router-id change to take effect," | |
316 | " save config and restart ospfd\n"); | |
317 | return CMD_SUCCESS; | |
318 | } | |
319 | ||
320 | ospf_router_id_update(ospf); | |
321 | ||
322 | return CMD_SUCCESS; | |
718e3744 | 323 | } |
324 | ||
7a7be519 | 325 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
326 | ospf_router_id_old_cmd, |
327 | "router-id A.B.C.D", | |
328 | "router-id for the OSPF process\n" | |
329 | "OSPF router-id in IP address format\n") | |
7a7be519 | 330 | { |
a3d826f0 | 331 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 332 | int idx_ipv4 = 1; |
333 | struct listnode *node; | |
334 | struct ospf_area *area; | |
335 | struct in_addr router_id; | |
336 | int ret; | |
337 | ||
338 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
339 | if (!ret) { | |
340 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
341 | return CMD_WARNING_CONFIG_FAILED; | |
342 | } | |
7a7be519 | 343 | |
d62a17ae | 344 | ospf->router_id_static = router_id; |
345 | ||
346 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
347 | if (area->full_nbrs) { | |
348 | vty_out(vty, | |
349 | "For this router-id change to take effect," | |
350 | " save config and restart ospfd\n"); | |
351 | return CMD_SUCCESS; | |
352 | } | |
353 | ||
354 | ospf_router_id_update(ospf); | |
355 | ||
356 | return CMD_SUCCESS; | |
7a7be519 | 357 | } |
747e489c | 358 | |
43b8d1d8 | 359 | DEFPY (no_ospf_router_id, |
718e3744 | 360 | no_ospf_router_id_cmd, |
7a7be519 | 361 | "no ospf router-id [A.B.C.D]", |
718e3744 | 362 | NO_STR |
363 | "OSPF specific commands\n" | |
7a7be519 | 364 | "router-id for the OSPF process\n" |
365 | "OSPF router-id in IP address format\n") | |
718e3744 | 366 | { |
a3d826f0 | 367 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 368 | struct listnode *node; |
369 | struct ospf_area *area; | |
68980084 | 370 | |
43b8d1d8 CS |
371 | if (router_id_str) { |
372 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
373 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
374 | return CMD_WARNING_CONFIG_FAILED; | |
375 | } | |
376 | } | |
377 | ||
d62a17ae | 378 | ospf->router_id_static.s_addr = 0; |
718e3744 | 379 | |
d62a17ae | 380 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
381 | if (area->full_nbrs) { | |
382 | vty_out(vty, | |
383 | "For this router-id change to take effect," | |
384 | " save config and restart ospfd\n"); | |
385 | return CMD_SUCCESS; | |
386 | } | |
2c19a6ec | 387 | |
d62a17ae | 388 | ospf_router_id_update(ospf); |
718e3744 | 389 | |
d62a17ae | 390 | return CMD_SUCCESS; |
718e3744 | 391 | } |
392 | ||
718e3744 | 393 | |
d7c0a89a | 394 | static void ospf_passive_interface_default(struct ospf *ospf, uint8_t newval) |
d62a17ae | 395 | { |
f4e14fdb | 396 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 397 | struct listnode *ln; |
398 | struct interface *ifp; | |
399 | struct ospf_interface *oi; | |
400 | ||
401 | ospf->passive_interface_default = newval; | |
402 | ||
451fda4f | 403 | FOR_ALL_INTERFACES (vrf, ifp) { |
9d303b37 DL |
404 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
405 | passive_interface)) | |
d62a17ae | 406 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); |
407 | } | |
408 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
409 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
410 | UNSET_IF_PARAM(oi->params, passive_interface); | |
411 | /* update multicast memberships */ | |
412 | ospf_if_set_multicast(oi); | |
413 | } | |
414 | } | |
415 | ||
416 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
417 | struct interface *ifp, | |
418 | struct ospf_if_params *params, | |
d7c0a89a | 419 | uint8_t value, |
d62a17ae | 420 | struct in_addr addr) |
421 | { | |
d7c0a89a | 422 | uint8_t dflt; |
d62a17ae | 423 | |
424 | params->passive_interface = value; | |
425 | if (params != IF_DEF_PARAMS(ifp)) { | |
426 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
427 | passive_interface)) | |
428 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
429 | else | |
430 | dflt = ospf->passive_interface_default; | |
431 | ||
432 | if (value != dflt) | |
433 | SET_IF_PARAM(params, passive_interface); | |
434 | else | |
435 | UNSET_IF_PARAM(params, passive_interface); | |
436 | ||
437 | ospf_free_if_params(ifp, addr); | |
438 | ospf_if_update_params(ifp, addr); | |
439 | } | |
440 | } | |
441 | ||
442 | static void ospf_passive_interface_update(struct ospf *ospf, | |
443 | struct interface *ifp, | |
444 | struct ospf_if_params *params, | |
d7c0a89a | 445 | uint8_t value) |
d62a17ae | 446 | { |
447 | params->passive_interface = value; | |
448 | if (params == IF_DEF_PARAMS(ifp)) { | |
449 | if (value != ospf->passive_interface_default) | |
450 | SET_IF_PARAM(params, passive_interface); | |
451 | else | |
452 | UNSET_IF_PARAM(params, passive_interface); | |
453 | } | |
7ffa8fa2 PJ |
454 | } |
455 | ||
a2c62831 | 456 | DEFUN (ospf_passive_interface, |
457 | ospf_passive_interface_addr_cmd, | |
7a7be519 | 458 | "passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 459 | "Suppress routing updates on an interface\n" |
7a7be519 | 460 | "Interface's name\n" |
3a2d747c | 461 | "IPv4 address\n" |
7a7be519 | 462 | "Suppress routing updates on interfaces by default\n") |
718e3744 | 463 | { |
a3d826f0 | 464 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 465 | int idx_ipv4 = 2; |
e99734f1 | 466 | struct interface *ifp = NULL; |
d62a17ae | 467 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
468 | int ret; | |
469 | struct ospf_if_params *params; | |
470 | struct route_node *rn; | |
471 | ||
472 | if (strmatch(argv[1]->text, "default")) { | |
473 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
474 | return CMD_SUCCESS; | |
475 | } | |
e99734f1 | 476 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 477 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
d62a17ae | 478 | |
b5a8894d | 479 | if (ifp == NULL) { |
996c9314 | 480 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 481 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 482 | } |
d62a17ae | 483 | |
484 | params = IF_DEF_PARAMS(ifp); | |
485 | ||
486 | if (argc == 3) { | |
487 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
488 | if (!ret) { | |
489 | vty_out(vty, | |
490 | "Please specify interface address by A.B.C.D\n"); | |
491 | return CMD_WARNING_CONFIG_FAILED; | |
492 | } | |
493 | ||
494 | params = ospf_get_if_params(ifp, addr); | |
495 | ospf_if_update_params(ifp, addr); | |
496 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
497 | OSPF_IF_PASSIVE, addr); | |
498 | } | |
499 | ||
500 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
501 | ||
502 | /* XXX We should call ospf_if_set_multicast on exactly those | |
503 | * interfaces for which the passive property changed. It is too much | |
504 | * work to determine this set, so we do this for every interface. | |
505 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
506 | * record of joined groups to avoid systems calls if the desired | |
507 | * memberships match the current memership. | |
508 | */ | |
509 | ||
510 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
511 | struct ospf_interface *oi = rn->info; | |
512 | ||
9d303b37 DL |
513 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) |
514 | == OSPF_IF_PASSIVE)) | |
d62a17ae | 515 | ospf_if_set_multicast(oi); |
516 | } | |
517 | /* | |
518 | * XXX It is not clear what state transitions the interface needs to | |
519 | * undergo when going from active to passive. Fixing this will | |
520 | * require precise identification of interfaces having such a | |
521 | * transition. | |
522 | */ | |
523 | ||
524 | return CMD_SUCCESS; | |
718e3744 | 525 | } |
526 | ||
a2c62831 | 527 | DEFUN (no_ospf_passive_interface, |
528 | no_ospf_passive_interface_addr_cmd, | |
7a7be519 | 529 | "no passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 530 | NO_STR |
531 | "Allow routing updates on an interface\n" | |
7a7be519 | 532 | "Interface's name\n" |
3a2d747c | 533 | "IPv4 address\n" |
7a7be519 | 534 | "Allow routing updates on interfaces by default\n") |
718e3744 | 535 | { |
a3d826f0 | 536 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 537 | int idx_ipv4 = 3; |
e99734f1 | 538 | struct interface *ifp = NULL; |
d62a17ae | 539 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
540 | struct ospf_if_params *params; | |
541 | int ret; | |
542 | struct route_node *rn; | |
543 | ||
544 | if (strmatch(argv[2]->text, "default")) { | |
545 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
546 | return CMD_SUCCESS; | |
43540886 AS |
547 | } |
548 | ||
e99734f1 | 549 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 550 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
e99734f1 | 551 | |
b5a8894d | 552 | if (ifp == NULL) { |
996c9314 | 553 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 554 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 555 | } |
ba6454ec | 556 | |
d62a17ae | 557 | params = IF_DEF_PARAMS(ifp); |
558 | ||
559 | if (argc == 4) { | |
560 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
561 | if (!ret) { | |
562 | vty_out(vty, | |
563 | "Please specify interface address by A.B.C.D\n"); | |
564 | return CMD_WARNING_CONFIG_FAILED; | |
565 | } | |
566 | ||
567 | params = ospf_lookup_if_params(ifp, addr); | |
568 | if (params == NULL) | |
569 | return CMD_SUCCESS; | |
570 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
571 | OSPF_IF_ACTIVE, addr); | |
572 | } | |
573 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
574 | ||
575 | /* XXX We should call ospf_if_set_multicast on exactly those | |
576 | * interfaces for which the passive property changed. It is too much | |
577 | * work to determine this set, so we do this for every interface. | |
578 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
579 | * record of joined groups to avoid systems calls if the desired | |
580 | * memberships match the current memership. | |
581 | */ | |
582 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
583 | struct ospf_interface *oi = rn->info; | |
584 | ||
585 | if (oi | |
586 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
587 | ospf_if_set_multicast(oi); | |
588 | } | |
589 | ||
590 | return CMD_SUCCESS; | |
718e3744 | 591 | } |
592 | ||
718e3744 | 593 | |
a2c62831 | 594 | DEFUN (ospf_network_area, |
595 | ospf_network_area_cmd, | |
6147e2c6 | 596 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 597 | "Enable routing on an IP network\n" |
598 | "OSPF network prefix\n" | |
599 | "Set the OSPF area ID\n" | |
600 | "OSPF area ID in IP address format\n" | |
601 | "OSPF area ID as a decimal value\n") | |
602 | { | |
a3d826f0 | 603 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 604 | int idx_ipv4_prefixlen = 1; |
605 | int idx_ipv4_number = 3; | |
606 | struct prefix_ipv4 p; | |
607 | struct in_addr area_id; | |
608 | int ret, format; | |
609 | ||
610 | if (ospf->instance) { | |
611 | vty_out(vty, | |
612 | "The network command is not supported in multi-instance ospf\n"); | |
613 | return CMD_WARNING_CONFIG_FAILED; | |
614 | } | |
718e3744 | 615 | |
d62a17ae | 616 | if (ospf->if_ospf_cli_count > 0) { |
617 | vty_out(vty, | |
618 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 619 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 LB |
620 | zlog_debug( |
621 | "%s ospf vrf %s num of %u ip osp area x config", | |
622 | __PRETTY_FUNCTION__, | |
623 | ospf->name ? ospf->name : "NIL", | |
624 | ospf->if_ospf_cli_count); | |
d62a17ae | 625 | return CMD_WARNING_CONFIG_FAILED; |
626 | } | |
627 | ||
628 | /* Get network prefix and Area ID. */ | |
629 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
630 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
631 | ||
632 | ret = ospf_network_set(ospf, &p, area_id, format); | |
633 | if (ret == 0) { | |
634 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 635 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 636 | } |
637 | ||
638 | return CMD_SUCCESS; | |
718e3744 | 639 | } |
640 | ||
a2c62831 | 641 | DEFUN (no_ospf_network_area, |
642 | no_ospf_network_area_cmd, | |
6147e2c6 | 643 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 644 | NO_STR |
645 | "Enable routing on an IP network\n" | |
646 | "OSPF network prefix\n" | |
647 | "Set the OSPF area ID\n" | |
648 | "OSPF area ID in IP address format\n" | |
649 | "OSPF area ID as a decimal value\n") | |
650 | { | |
a3d826f0 | 651 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 652 | int idx_ipv4_prefixlen = 2; |
653 | int idx_ipv4_number = 4; | |
654 | struct prefix_ipv4 p; | |
655 | struct in_addr area_id; | |
656 | int ret, format; | |
657 | ||
658 | if (ospf->instance) { | |
659 | vty_out(vty, | |
660 | "The network command is not supported in multi-instance ospf\n"); | |
661 | return CMD_WARNING_CONFIG_FAILED; | |
662 | } | |
718e3744 | 663 | |
d62a17ae | 664 | /* Get network prefix and Area ID. */ |
665 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
666 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
667 | ||
668 | ret = ospf_network_unset(ospf, &p, area_id); | |
669 | if (ret == 0) { | |
670 | vty_out(vty, | |
671 | "Can't find specified network area configuration.\n"); | |
672 | return CMD_WARNING_CONFIG_FAILED; | |
673 | } | |
674 | ||
675 | return CMD_SUCCESS; | |
718e3744 | 676 | } |
677 | ||
a2c62831 | 678 | DEFUN (ospf_area_range, |
679 | ospf_area_range_cmd, | |
7a7be519 | 680 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 681 | "OSPF area parameters\n" |
682 | "OSPF area ID in IP address format\n" | |
683 | "OSPF area ID as a decimal value\n" | |
684 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 685 | "Area range prefix\n" |
686 | "Advertise this range (default)\n" | |
687 | "User specified metric for this range\n" | |
688 | "Advertised metric for this range\n") | |
718e3744 | 689 | { |
a3d826f0 | 690 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 691 | int idx_ipv4_number = 1; |
692 | int idx_ipv4_prefixlen = 3; | |
693 | int idx_cost = 6; | |
694 | struct prefix_ipv4 p; | |
695 | struct in_addr area_id; | |
696 | int format; | |
d7c0a89a | 697 | uint32_t cost; |
d62a17ae | 698 | |
699 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
700 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
701 | ||
702 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
703 | if (argc > 5) { | |
704 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
705 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
706 | } | |
718e3744 | 707 | |
d62a17ae | 708 | return CMD_SUCCESS; |
718e3744 | 709 | } |
710 | ||
7a7be519 | 711 | DEFUN (ospf_area_range_cost, |
712 | ospf_area_range_cost_cmd, | |
713 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
714 | "OSPF area parameters\n" | |
715 | "OSPF area ID in IP address format\n" | |
716 | "OSPF area ID as a decimal value\n" | |
717 | "Summarize routes matching address/mask (border routers only)\n" | |
718 | "Area range prefix\n" | |
719 | "User specified metric for this range\n" | |
720 | "Advertised metric for this range\n") | |
721 | { | |
a3d826f0 | 722 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 723 | int idx_ipv4_number = 1; |
724 | int idx_ipv4_prefixlen = 3; | |
725 | int idx_cost = 5; | |
726 | struct prefix_ipv4 p; | |
727 | struct in_addr area_id; | |
728 | int format; | |
d7c0a89a | 729 | uint32_t cost; |
7a7be519 | 730 | |
d62a17ae | 731 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
732 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 733 | |
d62a17ae | 734 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
735 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
736 | format); | |
718e3744 | 737 | |
d62a17ae | 738 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
739 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 740 | |
d62a17ae | 741 | return CMD_SUCCESS; |
7a7be519 | 742 | } |
718e3744 | 743 | |
a2c62831 | 744 | DEFUN (ospf_area_range_not_advertise, |
745 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 746 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 747 | "OSPF area parameters\n" |
748 | "OSPF area ID in IP address format\n" | |
749 | "OSPF area ID as a decimal value\n" | |
750 | "Summarize routes matching address/mask (border routers only)\n" | |
751 | "Area range prefix\n" | |
752 | "DoNotAdvertise this range\n") | |
753 | { | |
a3d826f0 | 754 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 755 | int idx_ipv4_number = 1; |
756 | int idx_ipv4_prefixlen = 3; | |
757 | struct prefix_ipv4 p; | |
758 | struct in_addr area_id; | |
759 | int format; | |
718e3744 | 760 | |
d62a17ae | 761 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
762 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 763 | |
d62a17ae | 764 | ospf_area_range_set(ospf, area_id, &p, 0); |
765 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
766 | format); | |
990baca0 | 767 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 768 | |
d62a17ae | 769 | return CMD_SUCCESS; |
718e3744 | 770 | } |
771 | ||
a2c62831 | 772 | DEFUN (no_ospf_area_range, |
773 | no_ospf_area_range_cmd, | |
3a2d747c | 774 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 775 | NO_STR |
776 | "OSPF area parameters\n" | |
777 | "OSPF area ID in IP address format\n" | |
778 | "OSPF area ID as a decimal value\n" | |
779 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 780 | "Area range prefix\n" |
3a2d747c QY |
781 | "User specified metric for this range\n" |
782 | "Advertised metric for this range\n" | |
7a7be519 | 783 | "Advertise this range (default)\n" |
3a2d747c QY |
784 | "User specified metric for this range\n" |
785 | "Advertised metric for this range\n" | |
7a7be519 | 786 | "DoNotAdvertise this range\n") |
718e3744 | 787 | { |
a3d826f0 | 788 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 789 | int idx_ipv4_number = 2; |
790 | int idx_ipv4_prefixlen = 4; | |
791 | struct prefix_ipv4 p; | |
792 | struct in_addr area_id; | |
793 | int format; | |
718e3744 | 794 | |
d62a17ae | 795 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
796 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 797 | |
d62a17ae | 798 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 799 | |
d62a17ae | 800 | return CMD_SUCCESS; |
718e3744 | 801 | } |
802 | ||
a2c62831 | 803 | DEFUN (ospf_area_range_substitute, |
804 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 805 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 806 | "OSPF area parameters\n" |
807 | "OSPF area ID in IP address format\n" | |
808 | "OSPF area ID as a decimal value\n" | |
809 | "Summarize routes matching address/mask (border routers only)\n" | |
810 | "Area range prefix\n" | |
811 | "Announce area range as another prefix\n" | |
812 | "Network prefix to be announced instead of range\n") | |
813 | { | |
a3d826f0 | 814 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 815 | int idx_ipv4_number = 1; |
816 | int idx_ipv4_prefixlen = 3; | |
817 | int idx_ipv4_prefixlen_2 = 5; | |
818 | struct prefix_ipv4 p, s; | |
819 | struct in_addr area_id; | |
820 | int format; | |
718e3744 | 821 | |
d62a17ae | 822 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
823 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
824 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 825 | |
d62a17ae | 826 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
827 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
828 | format); | |
718e3744 | 829 | |
d62a17ae | 830 | return CMD_SUCCESS; |
718e3744 | 831 | } |
832 | ||
a2c62831 | 833 | DEFUN (no_ospf_area_range_substitute, |
834 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 835 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 836 | NO_STR |
837 | "OSPF area parameters\n" | |
838 | "OSPF area ID in IP address format\n" | |
839 | "OSPF area ID as a decimal value\n" | |
840 | "Summarize routes matching address/mask (border routers only)\n" | |
841 | "Area range prefix\n" | |
842 | "Announce area range as another prefix\n" | |
843 | "Network prefix to be announced instead of range\n") | |
844 | { | |
a3d826f0 | 845 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 846 | int idx_ipv4_number = 2; |
847 | int idx_ipv4_prefixlen = 4; | |
848 | int idx_ipv4_prefixlen_2 = 6; | |
849 | struct prefix_ipv4 p, s; | |
850 | struct in_addr area_id; | |
851 | int format; | |
718e3744 | 852 | |
d62a17ae | 853 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
854 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
855 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 856 | |
d62a17ae | 857 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 858 | |
d62a17ae | 859 | return CMD_SUCCESS; |
718e3744 | 860 | } |
861 | ||
6b0655a2 | 862 | |
718e3744 | 863 | /* Command Handler Logic in VLink stuff is delicate!! |
864 | ||
865 | ALTER AT YOUR OWN RISK!!!! | |
866 | ||
867 | Various dummy values are used to represent 'NoChange' state for | |
868 | VLink configuration NOT being changed by a VLink command, and | |
869 | special syntax is used within the command strings so that the | |
870 | typed in command verbs can be seen in the configuration command | |
871 | bacckend handler. This is to drastically reduce the verbeage | |
872 | required to coe up with a reasonably compatible Cisco VLink command | |
873 | ||
d62a17ae | 874 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 875 | Wed, 21 Feb 2001 15:13:52 +1300 |
876 | */ | |
877 | ||
d62a17ae | 878 | /* Configuration data for virtual links |
879 | */ | |
718e3744 | 880 | struct ospf_vl_config_data { |
d62a17ae | 881 | struct vty *vty; /* vty stuff */ |
882 | struct in_addr area_id; /* area ID from command line */ | |
883 | int area_id_fmt; /* command line area ID format */ | |
884 | struct in_addr vl_peer; /* command line vl_peer */ | |
885 | int auth_type; /* Authehntication type, if given */ | |
886 | char *auth_key; /* simple password if present */ | |
887 | int crypto_key_id; /* Cryptographic key ID */ | |
888 | char *md5_key; /* MD5 authentication key */ | |
889 | int hello_interval; /* Obvious what these are... */ | |
890 | int retransmit_interval; | |
891 | int transmit_delay; | |
892 | int dead_interval; | |
718e3744 | 893 | }; |
894 | ||
d62a17ae | 895 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
896 | struct vty *vty) | |
718e3744 | 897 | { |
d62a17ae | 898 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
899 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
900 | vl_config->vty = vty; | |
718e3744 | 901 | } |
902 | ||
4dadc291 | 903 | static struct ospf_vl_data * |
d62a17ae | 904 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
905 | { | |
906 | struct ospf_area *area; | |
907 | struct ospf_vl_data *vl_data; | |
908 | struct vty *vty; | |
909 | struct in_addr area_id; | |
910 | ||
911 | vty = vl_config->vty; | |
912 | area_id = vl_config->area_id; | |
913 | ||
914 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
915 | vty_out(vty, | |
916 | "Configuring VLs over the backbone is not allowed\n"); | |
917 | return NULL; | |
918 | } | |
919 | area = ospf_area_get(ospf, area_id); | |
920 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
921 | ||
922 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
923 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
924 | vty_out(vty, "Area %s is %s\n", inet_ntoa(area_id), | |
925 | area->external_routing == OSPF_AREA_NSSA | |
926 | ? "nssa" | |
927 | : "stub"); | |
928 | else | |
929 | vty_out(vty, "Area %ld is %s\n", | |
d7c0a89a | 930 | (unsigned long)ntohl(area_id.s_addr), |
d62a17ae | 931 | area->external_routing == OSPF_AREA_NSSA |
932 | ? "nssa" | |
933 | : "stub"); | |
934 | return NULL; | |
935 | } | |
936 | ||
937 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
938 | == NULL) { | |
939 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
940 | if (vl_data->vl_oi == NULL) { | |
941 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
942 | ospf_vl_add(ospf, vl_data); | |
943 | ospf_spf_calculate_schedule(ospf, | |
944 | SPF_FLAG_CONFIG_CHANGE); | |
945 | } | |
718e3744 | 946 | } |
d62a17ae | 947 | return vl_data; |
718e3744 | 948 | } |
949 | ||
950 | ||
d62a17ae | 951 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
952 | struct ospf_vl_config_data *vl_config) | |
953 | { | |
954 | struct crypt_key *ck; | |
955 | struct vty *vty; | |
956 | struct interface *ifp = vl_data->vl_oi->ifp; | |
957 | ||
958 | vty = vl_config->vty; | |
959 | ||
960 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
961 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
962 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 963 | } |
718e3744 | 964 | |
d62a17ae | 965 | if (vl_config->auth_key) { |
966 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
967 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
4d65d927 QY |
968 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
969 | vl_config->auth_key, | |
970 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
d62a17ae | 971 | } else if (vl_config->md5_key) { |
972 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
973 | vl_config->crypto_key_id) | |
974 | != NULL) { | |
975 | vty_out(vty, "OSPF: Key %d already exists\n", | |
976 | vl_config->crypto_key_id); | |
851fcbae | 977 | return CMD_WARNING; |
d62a17ae | 978 | } |
979 | ck = ospf_crypt_key_new(); | |
980 | ck->key_id = vl_config->crypto_key_id; | |
981 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
4d65d927 QY |
982 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
983 | sizeof(ck->auth_key)); | |
d62a17ae | 984 | |
985 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
986 | } else if (vl_config->crypto_key_id != 0) { | |
987 | /* Delete a key */ | |
988 | ||
989 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
990 | vl_config->crypto_key_id) | |
991 | == NULL) { | |
992 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
993 | vl_config->crypto_key_id); | |
994 | return CMD_WARNING_CONFIG_FAILED; | |
995 | } | |
996 | ||
997 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
998 | vl_config->crypto_key_id); | |
999 | } | |
1000 | ||
1001 | return CMD_SUCCESS; | |
718e3744 | 1002 | } |
1003 | ||
d62a17ae | 1004 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
1005 | struct ospf_vl_config_data *vl_config) | |
1006 | { | |
1007 | struct interface *ifp = vl_data->vl_oi->ifp; | |
1008 | /* Virtual Link data initialised to defaults, so only set | |
1009 | if a value given */ | |
1010 | if (vl_config->hello_interval) { | |
1011 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
1012 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
1013 | } | |
1014 | ||
1015 | if (vl_config->dead_interval) { | |
1016 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
1017 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
1018 | } | |
1019 | ||
1020 | if (vl_config->retransmit_interval) { | |
1021 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
1022 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
1023 | vl_config->retransmit_interval; | |
1024 | } | |
1025 | ||
1026 | if (vl_config->transmit_delay) { | |
1027 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
1028 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
1029 | } | |
1030 | ||
1031 | return CMD_SUCCESS; | |
718e3744 | 1032 | } |
1033 | ||
1034 | ||
718e3744 | 1035 | /* The business end of all of the above */ |
d62a17ae | 1036 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
1037 | { | |
1038 | struct ospf_vl_data *vl_data; | |
1039 | int ret; | |
718e3744 | 1040 | |
d62a17ae | 1041 | vl_data = ospf_find_vl_data(ospf, vl_config); |
1042 | if (!vl_data) | |
1043 | return CMD_WARNING_CONFIG_FAILED; | |
1044 | ||
1045 | /* Process this one first as it can have a fatal result, which can | |
1046 | only logically occur if the virtual link exists already | |
1047 | Thus a command error does not result in a change to the | |
1048 | running configuration such as unexpectedly altered timer | |
1049 | values etc.*/ | |
1050 | ret = ospf_vl_set_security(vl_data, vl_config); | |
1051 | if (ret != CMD_SUCCESS) | |
1052 | return ret; | |
1053 | ||
1054 | /* Set any time based parameters, these area already range checked */ | |
1055 | ||
1056 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1057 | if (ret != CMD_SUCCESS) | |
1058 | return ret; | |
718e3744 | 1059 | |
d62a17ae | 1060 | return CMD_SUCCESS; |
718e3744 | 1061 | } |
1062 | ||
1063 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1064 | */ | |
d62a17ae | 1065 | #define VLINK_HELPSTR_IPADDR \ |
1066 | "OSPF area parameters\n" \ | |
1067 | "OSPF area ID in IP address format\n" \ | |
1068 | "OSPF area ID as a decimal value\n" \ | |
1069 | "Configure a virtual link\n" \ | |
1070 | "Router ID of the remote ABR\n" | |
1071 | ||
1072 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1073 | "Enable authentication on this virtual link\n" \ | |
1074 | "dummy string \n" | |
1075 | ||
1076 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1077 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1078 | "Use null authentication\n" \ | |
1079 | "Use message-digest authentication\n" | |
1080 | ||
1081 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1082 | "Time between HELLO packets\n" \ | |
1083 | "Seconds\n" \ | |
1084 | "Time between retransmitting lost link state advertisements\n" \ | |
1085 | "Seconds\n" \ | |
1086 | "Link state transmit delay\n" \ | |
1087 | "Seconds\n" \ | |
1088 | "Interval time after which a neighbor is declared down\n" \ | |
1089 | "Seconds\n" | |
1090 | ||
1091 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1092 | "Authentication password (key)\n" \ | |
baf9eaad | 1093 | "The OSPF password (key)\n" |
d62a17ae | 1094 | |
1095 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1096 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1097 | "Key ID\n" \ |
1098 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1099 | "The OSPF password (key)\n" |
718e3744 | 1100 | |
a2c62831 | 1101 | DEFUN (ospf_area_vlink, |
1102 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1103 | "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 | 1104 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1105 | "Enable authentication on this virtual link\n" |
7a7be519 | 1106 | "Use message-digest authentication\n" |
3d1c6dc2 | 1107 | "Use null authentication\n" |
baf9eaad CS |
1108 | VLINK_HELPSTR_AUTH_MD5 |
1109 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1110 | { |
a3d826f0 | 1111 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1112 | int idx_ipv4_number = 1; |
1113 | int idx_ipv4 = 3; | |
1114 | struct ospf_vl_config_data vl_config; | |
1115 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1116 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1117 | int ret; |
55d1da24 | 1118 | int idx = 0; |
d62a17ae | 1119 | |
1120 | ospf_vl_config_data_init(&vl_config, vty); | |
1121 | ||
1122 | /* Read off first 2 parameters and check them */ | |
1123 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1124 | &vl_config.area_id_fmt); | |
1125 | if (ret < 0) { | |
1126 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1127 | return CMD_WARNING_CONFIG_FAILED; | |
1128 | } | |
718e3744 | 1129 | |
d62a17ae | 1130 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1131 | if (!ret) { | |
1132 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1133 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1134 | } |
7a7be519 | 1135 | |
d62a17ae | 1136 | if (argc <= 4) { |
1137 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1138 | |
d62a17ae | 1139 | return ospf_vl_set(ospf, &vl_config); |
1140 | } | |
1141 | ||
3d1c6dc2 CS |
1142 | if (argv_find(argv, argc, "authentication", &idx)) { |
1143 | /* authentication - this option can only occur | |
1144 | at start of command line */ | |
1145 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1146 | } | |
1147 | ||
3d1c6dc2 | 1148 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1149 | /* authentication message-digest */ |
3d1c6dc2 CS |
1150 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1151 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1152 | /* "authentication null" */ | |
1153 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1154 | } |
7a7be519 | 1155 | |
3d1c6dc2 | 1156 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1157 | vl_config.md5_key = NULL; |
cbb9b53d | 1158 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1159 | if (vl_config.crypto_key_id < 0) |
1160 | return CMD_WARNING_CONFIG_FAILED; | |
1161 | ||
4d65d927 | 1162 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
3d1c6dc2 CS |
1163 | vl_config.md5_key = md5_key; |
1164 | } | |
1165 | ||
3d1c6dc2 | 1166 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
4d65d927 | 1167 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
3d1c6dc2 CS |
1168 | vl_config.auth_key = auth_key; |
1169 | } | |
7a7be519 | 1170 | |
d62a17ae | 1171 | /* Action configuration */ |
1172 | ||
1173 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1174 | } |
1175 | ||
a2c62831 | 1176 | DEFUN (no_ospf_area_vlink, |
1177 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1178 | "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 | 1179 | NO_STR |
7a7be519 | 1180 | VLINK_HELPSTR_IPADDR |
1181 | "Enable authentication on this virtual link\n" \ | |
3d1c6dc2 | 1182 | "Use message-digest authentication\n" \ |
7a7be519 | 1183 | "Use null authentication\n" \ |
baf9eaad CS |
1184 | VLINK_HELPSTR_AUTH_MD5 |
1185 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1186 | { |
a3d826f0 | 1187 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1188 | int idx_ipv4_number = 2; |
1189 | int idx_ipv4 = 4; | |
1190 | struct ospf_area *area; | |
1191 | struct ospf_vl_config_data vl_config; | |
1192 | struct ospf_vl_data *vl_data = NULL; | |
1193 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1194 | int idx = 0; |
d62a17ae | 1195 | int ret, format; |
1196 | ||
1197 | ospf_vl_config_data_init(&vl_config, vty); | |
1198 | ||
1199 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1200 | &format); | |
1201 | if (ret < 0) { | |
1202 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1203 | return CMD_WARNING_CONFIG_FAILED; | |
1204 | } | |
1205 | ||
1206 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1207 | if (!area) { | |
1208 | vty_out(vty, "Area does not exist\n"); | |
1209 | return CMD_WARNING_CONFIG_FAILED; | |
1210 | } | |
1211 | ||
1212 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1213 | if (!ret) { | |
1214 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1215 | return CMD_WARNING_CONFIG_FAILED; | |
1216 | } | |
718e3744 | 1217 | |
188823b0 EDP |
1218 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1219 | if (!vl_data) { | |
1220 | vty_out(vty, "Virtual link does not exist\n"); | |
1221 | return CMD_WARNING_CONFIG_FAILED; | |
1222 | } | |
1223 | ||
d62a17ae | 1224 | if (argc <= 5) { |
1225 | /* Basic VLink no command */ | |
1226 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
188823b0 | 1227 | ospf_vl_delete(ospf, vl_data); |
d62a17ae | 1228 | ospf_area_check_free(ospf, vl_config.area_id); |
d62a17ae | 1229 | return CMD_SUCCESS; |
1230 | } | |
1231 | ||
1232 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1233 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1234 | |
1235 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1236 | /* authentication - this option can only occur | |
1237 | at start of command line */ | |
1238 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1239 | } | |
1240 | ||
3d1c6dc2 | 1241 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1242 | vl_config.md5_key = NULL; |
cbb9b53d | 1243 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1244 | if (vl_config.crypto_key_id < 0) |
1245 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1246 | } |
1247 | ||
3d1c6dc2 | 1248 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1249 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1250 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1251 | vl_config.auth_key = auth_key; | |
1252 | } | |
d62a17ae | 1253 | |
1254 | /* Action configuration */ | |
1255 | ||
1256 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1257 | } |
1258 | ||
b1c02cec QY |
1259 | DEFUN (ospf_area_vlink_intervals, |
1260 | ospf_area_vlink_intervals_cmd, | |
1261 | "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)}", | |
1262 | VLINK_HELPSTR_IPADDR | |
1263 | VLINK_HELPSTR_TIME_PARAM) | |
1264 | { | |
a3d826f0 | 1265 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1266 | struct ospf_vl_config_data vl_config; |
1267 | int ret = 0; | |
1268 | ||
1269 | ospf_vl_config_data_init(&vl_config, vty); | |
1270 | ||
1271 | char *area_id = argv[1]->arg; | |
1272 | char *router_id = argv[3]->arg; | |
1273 | ||
1274 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1275 | if (ret < 0) { | |
1276 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1277 | return CMD_WARNING_CONFIG_FAILED; | |
1278 | } | |
1279 | ||
1280 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1281 | if (!ret) { | |
1282 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1283 | return CMD_WARNING_CONFIG_FAILED; | |
1284 | } | |
1285 | ||
1286 | for (int idx = 4; idx < argc; idx++) { | |
1287 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1288 | vl_config.hello_interval = | |
1289 | strtol(argv[++idx]->arg, NULL, 10); | |
1290 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1291 | vl_config.retransmit_interval = | |
1292 | strtol(argv[++idx]->arg, NULL, 10); | |
1293 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1294 | vl_config.transmit_delay = | |
1295 | strtol(argv[++idx]->arg, NULL, 10); | |
1296 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1297 | vl_config.dead_interval = | |
1298 | strtol(argv[++idx]->arg, NULL, 10); | |
1299 | } | |
1300 | ||
1301 | /* Action configuration */ | |
1302 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1303 | } |
1304 | ||
7a7be519 | 1305 | DEFUN (no_ospf_area_vlink_intervals, |
1306 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1307 | "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 | 1308 | NO_STR |
7a7be519 | 1309 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1310 | VLINK_HELPSTR_TIME_PARAM) |
1311 | { | |
a3d826f0 | 1312 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1313 | struct ospf_vl_config_data vl_config; |
1314 | int ret = 0; | |
1315 | ||
1316 | ospf_vl_config_data_init(&vl_config, vty); | |
1317 | ||
1318 | char *area_id = argv[2]->arg; | |
1319 | char *router_id = argv[4]->arg; | |
1320 | ||
1321 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1322 | if (ret < 0) { | |
1323 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1324 | return CMD_WARNING_CONFIG_FAILED; | |
1325 | } | |
1326 | ||
1327 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1328 | if (!ret) { | |
1329 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1330 | return CMD_WARNING_CONFIG_FAILED; | |
1331 | } | |
1332 | ||
1333 | for (int idx = 5; idx < argc; idx++) { | |
1334 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1335 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1336 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1337 | vl_config.retransmit_interval = | |
1338 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1339 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1340 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1341 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1342 | vl_config.dead_interval = | |
1343 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1344 | } | |
1345 | ||
1346 | /* Action configuration */ | |
1347 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1348 | } |
1349 | ||
a2c62831 | 1350 | DEFUN (ospf_area_shortcut, |
1351 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1352 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1353 | "OSPF area parameters\n" |
1354 | "OSPF area ID in IP address format\n" | |
1355 | "OSPF area ID as a decimal value\n" | |
1356 | "Configure the area's shortcutting mode\n" | |
1357 | "Set default shortcutting behavior\n" | |
1358 | "Enable shortcutting through the area\n" | |
1359 | "Disable shortcutting through the area\n") | |
1360 | { | |
a3d826f0 | 1361 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1362 | int idx_ipv4_number = 1; |
1363 | int idx_enable_disable = 3; | |
1364 | struct ospf_area *area; | |
1365 | struct in_addr area_id; | |
1366 | int mode; | |
1367 | int format; | |
1368 | ||
1369 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1370 | argv[idx_ipv4_number]->arg); | |
1371 | ||
1372 | area = ospf_area_get(ospf, area_id); | |
1373 | ospf_area_display_format_set(ospf, area, format); | |
1374 | ||
1375 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1376 | mode = OSPF_SHORTCUT_DEFAULT; | |
1377 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1378 | mode = OSPF_SHORTCUT_DISABLE; | |
1379 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1380 | mode = OSPF_SHORTCUT_ENABLE; | |
1381 | else | |
1382 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1383 | |
d62a17ae | 1384 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1385 | |
d62a17ae | 1386 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1387 | vty_out(vty, | |
1388 | "Shortcut area setting will take effect " | |
1389 | "only when the router is configured as Shortcut ABR\n"); | |
718e3744 | 1390 | |
d62a17ae | 1391 | return CMD_SUCCESS; |
718e3744 | 1392 | } |
1393 | ||
a2c62831 | 1394 | DEFUN (no_ospf_area_shortcut, |
1395 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1396 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1397 | NO_STR |
1398 | "OSPF area parameters\n" | |
1399 | "OSPF area ID in IP address format\n" | |
1400 | "OSPF area ID as a decimal value\n" | |
1401 | "Deconfigure the area's shortcutting mode\n" | |
1402 | "Deconfigure enabled shortcutting through the area\n" | |
1403 | "Deconfigure disabled shortcutting through the area\n") | |
1404 | { | |
a3d826f0 | 1405 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1406 | int idx_ipv4_number = 2; |
1407 | struct ospf_area *area; | |
1408 | struct in_addr area_id; | |
1409 | int format; | |
718e3744 | 1410 | |
d62a17ae | 1411 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1412 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1413 | |
d62a17ae | 1414 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1415 | if (!area) | |
1416 | return CMD_SUCCESS; | |
718e3744 | 1417 | |
d62a17ae | 1418 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1419 | |
d62a17ae | 1420 | return CMD_SUCCESS; |
718e3744 | 1421 | } |
1422 | ||
6b0655a2 | 1423 | |
a2c62831 | 1424 | DEFUN (ospf_area_stub, |
1425 | ospf_area_stub_cmd, | |
6147e2c6 | 1426 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1427 | "OSPF area parameters\n" |
1428 | "OSPF area ID in IP address format\n" | |
1429 | "OSPF area ID as a decimal value\n" | |
1430 | "Configure OSPF area as stub\n") | |
1431 | { | |
a3d826f0 | 1432 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1433 | int idx_ipv4_number = 1; |
1434 | struct in_addr area_id; | |
1435 | int ret, format; | |
1436 | ||
1437 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1438 | argv[idx_ipv4_number]->arg); | |
1439 | ||
1440 | ret = ospf_area_stub_set(ospf, area_id); | |
1441 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1442 | format); | |
1443 | if (ret == 0) { | |
1444 | vty_out(vty, | |
1445 | "First deconfigure all virtual link through this area\n"); | |
1446 | return CMD_WARNING_CONFIG_FAILED; | |
1447 | } | |
718e3744 | 1448 | |
d62a17ae | 1449 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1450 | |
d62a17ae | 1451 | return CMD_SUCCESS; |
718e3744 | 1452 | } |
1453 | ||
a2c62831 | 1454 | DEFUN (ospf_area_stub_no_summary, |
1455 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1456 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1457 | "OSPF stub 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 stub\n") | |
1462 | { | |
a3d826f0 | 1463 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1464 | int idx_ipv4_number = 1; |
1465 | struct in_addr area_id; | |
1466 | int ret, format; | |
1467 | ||
1468 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1469 | argv[idx_ipv4_number]->arg); | |
1470 | ||
1471 | ret = ospf_area_stub_set(ospf, area_id); | |
1472 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1473 | format); | |
1474 | if (ret == 0) { | |
1475 | vty_out(vty, | |
1476 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1477 | return CMD_WARNING_CONFIG_FAILED; | |
1478 | } | |
718e3744 | 1479 | |
d62a17ae | 1480 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1481 | |
d62a17ae | 1482 | return CMD_SUCCESS; |
718e3744 | 1483 | } |
1484 | ||
a2c62831 | 1485 | DEFUN (no_ospf_area_stub, |
1486 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1487 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1488 | NO_STR |
1489 | "OSPF area parameters\n" | |
1490 | "OSPF area ID in IP address format\n" | |
1491 | "OSPF area ID as a decimal value\n" | |
1492 | "Configure OSPF area as stub\n") | |
1493 | { | |
a3d826f0 | 1494 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1495 | int idx_ipv4_number = 2; |
1496 | struct in_addr area_id; | |
1497 | int format; | |
718e3744 | 1498 | |
d62a17ae | 1499 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1500 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1501 | |
d62a17ae | 1502 | ospf_area_stub_unset(ospf, area_id); |
1503 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1504 | |
d62a17ae | 1505 | return CMD_SUCCESS; |
718e3744 | 1506 | } |
1507 | ||
a2c62831 | 1508 | DEFUN (no_ospf_area_stub_no_summary, |
1509 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1510 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1511 | NO_STR |
1512 | "OSPF area parameters\n" | |
1513 | "OSPF area ID in IP address format\n" | |
1514 | "OSPF area ID as a decimal value\n" | |
1515 | "Configure OSPF area as stub\n" | |
1516 | "Do not inject inter-area routes into area\n") | |
1517 | { | |
a3d826f0 | 1518 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1519 | int idx_ipv4_number = 2; |
1520 | struct in_addr area_id; | |
1521 | int format; | |
718e3744 | 1522 | |
d62a17ae | 1523 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1524 | argv[idx_ipv4_number]->arg); | |
1525 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1526 | |
d62a17ae | 1527 | return CMD_SUCCESS; |
718e3744 | 1528 | } |
1529 | ||
d62a17ae | 1530 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1531 | struct cmd_token **argv, int cfg_nosum, |
1532 | int nosum) | |
718e3744 | 1533 | { |
a3d826f0 | 1534 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1535 | struct in_addr area_id; |
1536 | int ret, format; | |
1537 | ||
1538 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1539 | ||
1540 | ret = ospf_area_nssa_set(ospf, area_id); | |
1541 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1542 | format); | |
1543 | if (ret == 0) { | |
1544 | vty_out(vty, | |
1545 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1546 | return CMD_WARNING_CONFIG_FAILED; | |
1547 | } | |
1548 | ||
1549 | if (argc > 3) { | |
1550 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1551 | ospf_area_nssa_translator_role_set( | |
1552 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1553 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1554 | ospf_area_nssa_translator_role_set( | |
1555 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1556 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1557 | ospf_area_nssa_translator_role_set( | |
1558 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1559 | } else { | |
1560 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1561 | OSPF_NSSA_ROLE_CANDIDATE); | |
1562 | } | |
1563 | ||
7ef56a73 CS |
1564 | if (cfg_nosum) { |
1565 | if (nosum) | |
1566 | ospf_area_no_summary_set(ospf, area_id); | |
1567 | else | |
1568 | ospf_area_no_summary_unset(ospf, area_id); | |
1569 | } | |
d62a17ae | 1570 | |
1571 | ospf_schedule_abr_task(ospf); | |
1572 | ||
1573 | return CMD_SUCCESS; | |
718e3744 | 1574 | } |
1575 | ||
718e3744 | 1576 | |
b0a053be | 1577 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1578 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1579 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1580 | "OSPF area parameters\n" |
1581 | "OSPF area ID in IP address format\n" | |
1582 | "OSPF area ID as a decimal value\n" | |
1583 | "Configure OSPF area as nssa\n" | |
1584 | "Configure NSSA-ABR for translate election (default)\n" | |
1585 | "Configure NSSA-ABR to never translate\n" | |
1586 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1587 | { |
7ef56a73 | 1588 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1589 | } |
1590 | ||
1591 | DEFUN (ospf_area_nssa, | |
1592 | ospf_area_nssa_cmd, | |
6147e2c6 | 1593 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1594 | "OSPF area parameters\n" |
1595 | "OSPF area ID in IP address format\n" | |
1596 | "OSPF area ID as a decimal value\n" | |
1597 | "Configure OSPF area as nssa\n") | |
1598 | { | |
2643b2bc | 1599 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1600 | } |
718e3744 | 1601 | |
a2c62831 | 1602 | DEFUN (ospf_area_nssa_no_summary, |
1603 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1604 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1605 | "OSPF area parameters\n" |
1606 | "OSPF area ID in IP address format\n" | |
1607 | "OSPF area ID as a decimal value\n" | |
1608 | "Configure OSPF area as nssa\n" | |
1609 | "Do not inject inter-area routes into nssa\n") | |
1610 | { | |
7ef56a73 CS |
1611 | int idx_ipv4_number = 1; |
1612 | struct in_addr area_id; | |
1613 | int format; | |
1614 | ||
1615 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1616 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1617 | argv[idx_ipv4_number]->arg); | |
1618 | ||
1619 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1620 | format); | |
1621 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1622 | ||
1623 | ospf_schedule_abr_task(ospf); | |
1624 | ||
1625 | return CMD_SUCCESS; | |
1626 | } | |
1627 | ||
1628 | DEFUN (no_ospf_area_nssa_no_summary, | |
1629 | no_ospf_area_nssa_no_summary_cmd, | |
1630 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1631 | NO_STR | |
1632 | "OSPF area parameters\n" | |
1633 | "OSPF area ID in IP address format\n" | |
1634 | "OSPF area ID as a decimal value\n" | |
1635 | "Configure OSPF area as nssa\n" | |
1636 | "Do not inject inter-area routes into nssa\n") | |
1637 | { | |
1638 | int idx_ipv4_number = 2; | |
1639 | struct in_addr area_id; | |
1640 | int format; | |
1641 | ||
1642 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1643 | ||
1644 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1645 | argv[idx_ipv4_number]->arg); | |
1646 | ||
1647 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1648 | format); | |
1649 | ospf_area_no_summary_unset(ospf, area_id); | |
1650 | ||
1651 | ospf_schedule_abr_task(ospf); | |
1652 | ||
1653 | return CMD_SUCCESS; | |
718e3744 | 1654 | } |
1655 | ||
a2c62831 | 1656 | DEFUN (no_ospf_area_nssa, |
1657 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1658 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1659 | NO_STR |
1660 | "OSPF area parameters\n" | |
1661 | "OSPF area ID in IP address format\n" | |
1662 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1663 | "Configure OSPF area as nssa\n" |
1664 | "Configure NSSA-ABR for translate election (default)\n" | |
1665 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1666 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1667 | { |
a3d826f0 | 1668 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1669 | int idx_ipv4_number = 2; |
1670 | struct in_addr area_id; | |
1671 | int format; | |
718e3744 | 1672 | |
d62a17ae | 1673 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1674 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1675 | |
7ef56a73 | 1676 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1677 | |
d62a17ae | 1678 | ospf_schedule_abr_task(ospf); |
b0a053be | 1679 | |
d62a17ae | 1680 | return CMD_SUCCESS; |
718e3744 | 1681 | } |
1682 | ||
718e3744 | 1683 | |
a2c62831 | 1684 | DEFUN (ospf_area_default_cost, |
1685 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1686 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1687 | "OSPF area parameters\n" |
1688 | "OSPF area ID in IP address format\n" | |
1689 | "OSPF area ID as a decimal value\n" | |
1690 | "Set the summary-default cost of a NSSA or stub area\n" | |
1691 | "Stub's advertised default summary cost\n") | |
1692 | { | |
a3d826f0 | 1693 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1694 | int idx_ipv4_number = 1; |
1695 | int idx_number = 3; | |
1696 | struct ospf_area *area; | |
1697 | struct in_addr area_id; | |
d7c0a89a | 1698 | uint32_t cost; |
d62a17ae | 1699 | int format; |
1700 | struct prefix_ipv4 p; | |
1701 | ||
1702 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1703 | argv[idx_ipv4_number]->arg); | |
1704 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1705 | ||
1706 | area = ospf_area_get(ospf, area_id); | |
1707 | ospf_area_display_format_set(ospf, area, format); | |
1708 | ||
1709 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1710 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1711 | return CMD_WARNING_CONFIG_FAILED; | |
1712 | } | |
ba682537 | 1713 | |
d62a17ae | 1714 | area->default_cost = cost; |
1715 | ||
1716 | p.family = AF_INET; | |
1717 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1718 | p.prefixlen = 0; | |
1719 | if (IS_DEBUG_OSPF_EVENT) | |
1720 | zlog_debug( | |
1721 | "ospf_abr_announce_stub_defaults(): " | |
1722 | "announcing 0.0.0.0/0 to area %s", | |
1723 | inet_ntoa(area->area_id)); | |
1724 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
1725 | ||
1726 | return CMD_SUCCESS; | |
718e3744 | 1727 | } |
1728 | ||
a2c62831 | 1729 | DEFUN (no_ospf_area_default_cost, |
1730 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1731 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1732 | NO_STR |
1733 | "OSPF area parameters\n" | |
1734 | "OSPF area ID in IP address format\n" | |
1735 | "OSPF area ID as a decimal value\n" | |
1736 | "Set the summary-default cost of a NSSA or stub area\n" | |
1737 | "Stub's advertised default summary cost\n") | |
1738 | { | |
a3d826f0 | 1739 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1740 | int idx_ipv4_number = 2; |
1741 | struct ospf_area *area; | |
1742 | struct in_addr area_id; | |
1743 | int format; | |
1744 | struct prefix_ipv4 p; | |
718e3744 | 1745 | |
d62a17ae | 1746 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1747 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1748 | |
d62a17ae | 1749 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1750 | if (area == NULL) | |
1751 | return CMD_SUCCESS; | |
718e3744 | 1752 | |
d62a17ae | 1753 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1754 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1755 | return CMD_WARNING_CONFIG_FAILED; | |
1756 | } | |
718e3744 | 1757 | |
d62a17ae | 1758 | area->default_cost = 1; |
718e3744 | 1759 | |
d62a17ae | 1760 | p.family = AF_INET; |
1761 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1762 | p.prefixlen = 0; | |
1763 | if (IS_DEBUG_OSPF_EVENT) | |
1764 | zlog_debug( | |
1765 | "ospf_abr_announce_stub_defaults(): " | |
1766 | "announcing 0.0.0.0/0 to area %s", | |
1767 | inet_ntoa(area->area_id)); | |
1768 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
ba682537 | 1769 | |
1770 | ||
d62a17ae | 1771 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1772 | |
d62a17ae | 1773 | return CMD_SUCCESS; |
718e3744 | 1774 | } |
1775 | ||
a2c62831 | 1776 | DEFUN (ospf_area_export_list, |
1777 | ospf_area_export_list_cmd, | |
6147e2c6 | 1778 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1779 | "OSPF area parameters\n" |
1780 | "OSPF area ID in IP address format\n" | |
1781 | "OSPF area ID as a decimal value\n" | |
1782 | "Set the filter for networks announced to other areas\n" | |
1783 | "Name of the access-list\n") | |
1784 | { | |
a3d826f0 | 1785 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1786 | int idx_ipv4_number = 1; |
1787 | struct ospf_area *area; | |
1788 | struct in_addr area_id; | |
1789 | int format; | |
718e3744 | 1790 | |
d62a17ae | 1791 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1792 | |
d62a17ae | 1793 | area = ospf_area_get(ospf, area_id); |
1794 | ospf_area_display_format_set(ospf, area, format); | |
1795 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1796 | |
d62a17ae | 1797 | return CMD_SUCCESS; |
718e3744 | 1798 | } |
1799 | ||
a2c62831 | 1800 | DEFUN (no_ospf_area_export_list, |
1801 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1802 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1803 | NO_STR |
1804 | "OSPF area parameters\n" | |
1805 | "OSPF area ID in IP address format\n" | |
1806 | "OSPF area ID as a decimal value\n" | |
1807 | "Unset the filter for networks announced to other areas\n" | |
1808 | "Name of the access-list\n") | |
1809 | { | |
a3d826f0 | 1810 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1811 | int idx_ipv4_number = 2; |
1812 | struct ospf_area *area; | |
1813 | struct in_addr area_id; | |
1814 | int format; | |
718e3744 | 1815 | |
d62a17ae | 1816 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1817 | |
d62a17ae | 1818 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1819 | if (area == NULL) | |
1820 | return CMD_SUCCESS; | |
718e3744 | 1821 | |
d62a17ae | 1822 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1823 | |
d62a17ae | 1824 | return CMD_SUCCESS; |
718e3744 | 1825 | } |
1826 | ||
1827 | ||
a2c62831 | 1828 | DEFUN (ospf_area_import_list, |
1829 | ospf_area_import_list_cmd, | |
6147e2c6 | 1830 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1831 | "OSPF area parameters\n" |
1832 | "OSPF area ID in IP address format\n" | |
1833 | "OSPF area ID as a decimal value\n" | |
1834 | "Set the filter for networks from other areas announced to the specified one\n" | |
1835 | "Name of the access-list\n") | |
1836 | { | |
a3d826f0 | 1837 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1838 | int idx_ipv4_number = 1; |
1839 | struct ospf_area *area; | |
1840 | struct in_addr area_id; | |
1841 | int format; | |
718e3744 | 1842 | |
d62a17ae | 1843 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1844 | |
d62a17ae | 1845 | area = ospf_area_get(ospf, area_id); |
1846 | ospf_area_display_format_set(ospf, area, format); | |
1847 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1848 | |
d62a17ae | 1849 | return CMD_SUCCESS; |
718e3744 | 1850 | } |
1851 | ||
a2c62831 | 1852 | DEFUN (no_ospf_area_import_list, |
1853 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1854 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1855 | NO_STR |
1856 | "OSPF area parameters\n" | |
1857 | "OSPF area ID in IP address format\n" | |
1858 | "OSPF area ID as a decimal value\n" | |
1859 | "Unset the filter for networks announced to other areas\n" | |
1860 | "Name of the access-list\n") | |
1861 | { | |
a3d826f0 | 1862 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1863 | int idx_ipv4_number = 2; |
1864 | struct ospf_area *area; | |
1865 | struct in_addr area_id; | |
1866 | int format; | |
718e3744 | 1867 | |
d62a17ae | 1868 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1869 | |
d62a17ae | 1870 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1871 | if (area == NULL) | |
1872 | return CMD_SUCCESS; | |
718e3744 | 1873 | |
d62a17ae | 1874 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1875 | |
d62a17ae | 1876 | return CMD_SUCCESS; |
718e3744 | 1877 | } |
1878 | ||
a2c62831 | 1879 | DEFUN (ospf_area_filter_list, |
1880 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1881 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1882 | "OSPF area parameters\n" |
1883 | "OSPF area ID in IP address format\n" | |
1884 | "OSPF area ID as a decimal value\n" | |
1885 | "Filter networks between OSPF areas\n" | |
1886 | "Filter prefixes between OSPF areas\n" | |
1887 | "Name of an IP prefix-list\n" | |
1888 | "Filter networks sent to this area\n" | |
1889 | "Filter networks sent from this area\n") | |
1890 | { | |
a3d826f0 | 1891 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1892 | int idx_ipv4_number = 1; |
1893 | int idx_word = 4; | |
1894 | int idx_in_out = 5; | |
1895 | struct ospf_area *area; | |
1896 | struct in_addr area_id; | |
1897 | struct prefix_list *plist; | |
1898 | int format; | |
1899 | ||
1900 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1901 | ||
1902 | area = ospf_area_get(ospf, area_id); | |
1903 | ospf_area_display_format_set(ospf, area, format); | |
1904 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1905 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1906 | PREFIX_LIST_IN(area) = plist; | |
1907 | if (PREFIX_NAME_IN(area)) | |
1908 | free(PREFIX_NAME_IN(area)); | |
1909 | ||
1910 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1911 | ospf_schedule_abr_task(ospf); | |
1912 | } else { | |
1913 | PREFIX_LIST_OUT(area) = plist; | |
1914 | if (PREFIX_NAME_OUT(area)) | |
1915 | free(PREFIX_NAME_OUT(area)); | |
1916 | ||
1917 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1918 | ospf_schedule_abr_task(ospf); | |
1919 | } | |
718e3744 | 1920 | |
d62a17ae | 1921 | return CMD_SUCCESS; |
718e3744 | 1922 | } |
1923 | ||
a2c62831 | 1924 | DEFUN (no_ospf_area_filter_list, |
1925 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1926 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1927 | NO_STR |
1928 | "OSPF area parameters\n" | |
1929 | "OSPF area ID in IP address format\n" | |
1930 | "OSPF area ID as a decimal value\n" | |
1931 | "Filter networks between OSPF areas\n" | |
1932 | "Filter prefixes between OSPF areas\n" | |
1933 | "Name of an IP prefix-list\n" | |
1934 | "Filter networks sent to this area\n" | |
1935 | "Filter networks sent from this area\n") | |
1936 | { | |
a3d826f0 | 1937 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1938 | int idx_ipv4_number = 2; |
1939 | int idx_word = 5; | |
1940 | int idx_in_out = 6; | |
1941 | struct ospf_area *area; | |
1942 | struct in_addr area_id; | |
1943 | int format; | |
718e3744 | 1944 | |
d62a17ae | 1945 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1946 | |
d62a17ae | 1947 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1948 | return CMD_SUCCESS; | |
718e3744 | 1949 | |
d62a17ae | 1950 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1951 | if (PREFIX_NAME_IN(area)) | |
1952 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1953 | != 0) | |
1954 | return CMD_SUCCESS; | |
718e3744 | 1955 | |
d62a17ae | 1956 | PREFIX_LIST_IN(area) = NULL; |
1957 | if (PREFIX_NAME_IN(area)) | |
1958 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1959 | |
d62a17ae | 1960 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1961 | |
d62a17ae | 1962 | ospf_schedule_abr_task(ospf); |
1963 | } else { | |
1964 | if (PREFIX_NAME_OUT(area)) | |
1965 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1966 | != 0) | |
1967 | return CMD_SUCCESS; | |
718e3744 | 1968 | |
d62a17ae | 1969 | PREFIX_LIST_OUT(area) = NULL; |
1970 | if (PREFIX_NAME_OUT(area)) | |
1971 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1972 | |
d62a17ae | 1973 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1974 | |
d62a17ae | 1975 | ospf_schedule_abr_task(ospf); |
1976 | } | |
1977 | ||
1978 | return CMD_SUCCESS; | |
718e3744 | 1979 | } |
1980 | ||
6b0655a2 | 1981 | |
a2c62831 | 1982 | DEFUN (ospf_area_authentication_message_digest, |
1983 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1984 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1985 | NO_STR | |
718e3744 | 1986 | "OSPF area parameters\n" |
2b00515a CF |
1987 | "OSPF area ID in IP address format\n" |
1988 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1989 | "Enable authentication\n" |
1990 | "Use message-digest authentication\n") | |
1991 | { | |
a3d826f0 | 1992 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 1993 | int idx = 0; |
d62a17ae | 1994 | struct ospf_area *area; |
1995 | struct in_addr area_id; | |
1996 | int format; | |
718e3744 | 1997 | |
ca19319b | 1998 | argv_find(argv, argc, "area", &idx); |
1999 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 2000 | |
d62a17ae | 2001 | area = ospf_area_get(ospf, area_id); |
2002 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
2003 | area->auth_type = strmatch(argv[0]->text, "no") |
2004 | ? OSPF_AUTH_NULL | |
2005 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 2006 | |
d62a17ae | 2007 | return CMD_SUCCESS; |
718e3744 | 2008 | } |
2009 | ||
a2c62831 | 2010 | DEFUN (ospf_area_authentication, |
2011 | ospf_area_authentication_cmd, | |
6147e2c6 | 2012 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2013 | "OSPF area parameters\n" |
2014 | "OSPF area ID in IP address format\n" | |
2015 | "OSPF area ID as a decimal value\n" | |
2016 | "Enable authentication\n") | |
2017 | { | |
a3d826f0 | 2018 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2019 | int idx_ipv4_number = 1; |
2020 | struct ospf_area *area; | |
2021 | struct in_addr area_id; | |
2022 | int format; | |
718e3744 | 2023 | |
d62a17ae | 2024 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2025 | |
d62a17ae | 2026 | area = ospf_area_get(ospf, area_id); |
2027 | ospf_area_display_format_set(ospf, area, format); | |
2028 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 2029 | |
d62a17ae | 2030 | return CMD_SUCCESS; |
718e3744 | 2031 | } |
2032 | ||
a2c62831 | 2033 | DEFUN (no_ospf_area_authentication, |
2034 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2035 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2036 | NO_STR |
2037 | "OSPF area parameters\n" | |
2038 | "OSPF area ID in IP address format\n" | |
2039 | "OSPF area ID as a decimal value\n" | |
2040 | "Enable authentication\n") | |
2041 | { | |
a3d826f0 | 2042 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2043 | int idx_ipv4_number = 2; |
2044 | struct ospf_area *area; | |
2045 | struct in_addr area_id; | |
2046 | int format; | |
718e3744 | 2047 | |
d62a17ae | 2048 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2049 | |
d62a17ae | 2050 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2051 | if (area == NULL) | |
2052 | return CMD_SUCCESS; | |
718e3744 | 2053 | |
d62a17ae | 2054 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2055 | |
d62a17ae | 2056 | ospf_area_check_free(ospf, area_id); |
2057 | ||
2058 | return CMD_SUCCESS; | |
718e3744 | 2059 | } |
2060 | ||
6b0655a2 | 2061 | |
718e3744 | 2062 | DEFUN (ospf_abr_type, |
2063 | ospf_abr_type_cmd, | |
6147e2c6 | 2064 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2065 | "OSPF specific commands\n" |
2066 | "Set OSPF ABR type\n" | |
2067 | "Alternative ABR, cisco implementation\n" | |
2068 | "Alternative ABR, IBM implementation\n" | |
2069 | "Shortcut ABR\n" | |
2070 | "Standard behavior (RFC2328)\n") | |
2071 | { | |
a3d826f0 | 2072 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2073 | int idx_vendor = 2; |
d7c0a89a | 2074 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2075 | |
2076 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2077 | abr_type = OSPF_ABR_CISCO; | |
2078 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2079 | abr_type = OSPF_ABR_IBM; | |
2080 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2081 | abr_type = OSPF_ABR_SHORTCUT; | |
2082 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2083 | abr_type = OSPF_ABR_STAND; | |
2084 | else | |
2085 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2086 | |
d62a17ae | 2087 | /* If ABR type value is changed, schedule ABR task. */ |
2088 | if (ospf->abr_type != abr_type) { | |
2089 | ospf->abr_type = abr_type; | |
2090 | ospf_schedule_abr_task(ospf); | |
2091 | } | |
2092 | ||
2093 | return CMD_SUCCESS; | |
718e3744 | 2094 | } |
2095 | ||
2096 | DEFUN (no_ospf_abr_type, | |
2097 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2098 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2099 | NO_STR |
2100 | "OSPF specific commands\n" | |
2101 | "Set OSPF ABR type\n" | |
2102 | "Alternative ABR, cisco implementation\n" | |
2103 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2104 | "Shortcut ABR\n" |
2105 | "Standard ABR\n") | |
718e3744 | 2106 | { |
a3d826f0 | 2107 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2108 | int idx_vendor = 3; |
d7c0a89a | 2109 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2110 | |
2111 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2112 | abr_type = OSPF_ABR_CISCO; | |
2113 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2114 | abr_type = OSPF_ABR_IBM; | |
2115 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2116 | abr_type = OSPF_ABR_SHORTCUT; | |
2117 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2118 | abr_type = OSPF_ABR_STAND; | |
2119 | else | |
2120 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2121 | |
d62a17ae | 2122 | /* If ABR type value is changed, schedule ABR task. */ |
2123 | if (ospf->abr_type == abr_type) { | |
2124 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2125 | ospf_schedule_abr_task(ospf); | |
2126 | } | |
2127 | ||
2128 | return CMD_SUCCESS; | |
718e3744 | 2129 | } |
2130 | ||
d7e60dd7 AS |
2131 | DEFUN (ospf_log_adjacency_changes, |
2132 | ospf_log_adjacency_changes_cmd, | |
2133 | "log-adjacency-changes", | |
2134 | "Log changes in adjacency state\n") | |
2135 | { | |
a3d826f0 | 2136 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2137 | |
d62a17ae | 2138 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2139 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2140 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2141 | } |
2142 | ||
2143 | DEFUN (ospf_log_adjacency_changes_detail, | |
2144 | ospf_log_adjacency_changes_detail_cmd, | |
2145 | "log-adjacency-changes detail", | |
2146 | "Log changes in adjacency state\n" | |
2147 | "Log all state changes\n") | |
2148 | { | |
a3d826f0 | 2149 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2150 | |
d62a17ae | 2151 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2152 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2153 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2154 | } |
2155 | ||
2156 | DEFUN (no_ospf_log_adjacency_changes, | |
2157 | no_ospf_log_adjacency_changes_cmd, | |
2158 | "no log-adjacency-changes", | |
2159 | NO_STR | |
2160 | "Log changes in adjacency state\n") | |
2161 | { | |
a3d826f0 | 2162 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2163 | |
d62a17ae | 2164 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2165 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2166 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2167 | } |
2168 | ||
2169 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2170 | no_ospf_log_adjacency_changes_detail_cmd, | |
2171 | "no log-adjacency-changes detail", | |
2172 | NO_STR | |
2173 | "Log changes in adjacency state\n" | |
2174 | "Log all state changes\n") | |
2175 | { | |
a3d826f0 | 2176 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2177 | |
d62a17ae | 2178 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2179 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2180 | } |
2181 | ||
718e3744 | 2182 | DEFUN (ospf_compatible_rfc1583, |
2183 | ospf_compatible_rfc1583_cmd, | |
2184 | "compatible rfc1583", | |
2185 | "OSPF compatibility list\n" | |
2186 | "compatible with RFC 1583\n") | |
2187 | { | |
a3d826f0 | 2188 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2189 | |
d62a17ae | 2190 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2191 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2192 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2193 | } | |
2194 | return CMD_SUCCESS; | |
718e3744 | 2195 | } |
2196 | ||
2197 | DEFUN (no_ospf_compatible_rfc1583, | |
2198 | no_ospf_compatible_rfc1583_cmd, | |
2199 | "no compatible rfc1583", | |
2200 | NO_STR | |
2201 | "OSPF compatibility list\n" | |
2202 | "compatible with RFC 1583\n") | |
2203 | { | |
a3d826f0 | 2204 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2205 | |
d62a17ae | 2206 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2207 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2208 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2209 | } | |
2210 | return CMD_SUCCESS; | |
718e3744 | 2211 | } |
2212 | ||
d62a17ae | 2213 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2214 | "ospf rfc1583compatibility", | |
2215 | "OSPF specific commands\n" | |
2216 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2217 | |
d62a17ae | 2218 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2219 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2220 | "OSPF specific commands\n" |
2221 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2222 | |
d62a17ae | 2223 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2224 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2225 | { |
a3d826f0 | 2226 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2227 | |
d62a17ae | 2228 | ospf->spf_delay = delay; |
2229 | ospf->spf_holdtime = hold; | |
2230 | ospf->spf_max_holdtime = max; | |
2231 | ||
2232 | return CMD_SUCCESS; | |
d24f6e2a | 2233 | } |
718e3744 | 2234 | |
ac7424f9 MR |
2235 | DEFUN (ospf_timers_min_ls_interval, |
2236 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2237 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2238 | "Adjust routing timers\n" |
2239 | "Throttling adaptive timer\n" | |
2240 | "LSA delay between transmissions\n" | |
813d4307 | 2241 | "All LSA types\n" |
ac7424f9 MR |
2242 | "Delay (msec) between sending LSAs\n") |
2243 | { | |
a3d826f0 | 2244 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2245 | int idx_number = 4; |
2246 | unsigned int interval; | |
ac7424f9 | 2247 | |
d62a17ae | 2248 | if (argc < 5) { |
2249 | vty_out(vty, "Insufficient arguments\n"); | |
2250 | return CMD_WARNING_CONFIG_FAILED; | |
2251 | } | |
ac7424f9 | 2252 | |
d62a17ae | 2253 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2254 | |
d62a17ae | 2255 | ospf->min_ls_interval = interval; |
ac7424f9 | 2256 | |
d62a17ae | 2257 | return CMD_SUCCESS; |
ac7424f9 MR |
2258 | } |
2259 | ||
2260 | DEFUN (no_ospf_timers_min_ls_interval, | |
2261 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2262 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2263 | NO_STR |
2264 | "Adjust routing timers\n" | |
2265 | "Throttling adaptive timer\n" | |
813d4307 | 2266 | "LSA delay between transmissions\n" |
7a7be519 | 2267 | "All LSA types\n" |
2268 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2269 | { |
a3d826f0 | 2270 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2271 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2272 | |
d62a17ae | 2273 | return CMD_SUCCESS; |
ac7424f9 MR |
2274 | } |
2275 | ||
d24f6e2a | 2276 | DEFUN (ospf_timers_throttle_spf, |
2277 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2278 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2279 | "Adjust routing timers\n" |
2280 | "Throttling adaptive timer\n" | |
2281 | "OSPF SPF timers\n" | |
2282 | "Delay (msec) from first change received till SPF calculation\n" | |
2283 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2284 | "Maximum hold time (msec)\n") | |
2285 | { | |
d62a17ae | 2286 | int idx_number = 3; |
2287 | int idx_number_2 = 4; | |
2288 | int idx_number_3 = 5; | |
2289 | unsigned int delay, hold, max; | |
2290 | ||
2291 | if (argc < 6) { | |
2292 | vty_out(vty, "Insufficient arguments\n"); | |
2293 | return CMD_WARNING_CONFIG_FAILED; | |
2294 | } | |
2295 | ||
2296 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2297 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2298 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2299 | ||
2300 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2301 | } |
2302 | ||
d24f6e2a | 2303 | DEFUN (no_ospf_timers_throttle_spf, |
2304 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2305 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2306 | NO_STR |
2307 | "Adjust routing timers\n" | |
d24f6e2a | 2308 | "Throttling adaptive timer\n" |
7a7be519 | 2309 | "OSPF SPF timers\n" |
2310 | "Delay (msec) from first change received till SPF calculation\n" | |
2311 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2312 | "Maximum hold time (msec)\n") | |
22b27e95 | 2313 | { |
d62a17ae | 2314 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2315 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2316 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2317 | } |
2318 | ||
b4a039bf | 2319 | |
0e88de35 QY |
2320 | DEFUN (ospf_timers_lsa_min_arrival, |
2321 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2322 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2323 | "Adjust routing timers\n" |
2324 | "OSPF LSA timers\n" | |
2325 | "Minimum delay in receiving new version of a LSA\n" | |
2326 | "Delay in milliseconds\n") | |
2327 | { | |
a3d826f0 | 2328 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2329 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2330 | return CMD_SUCCESS; |
b6927875 DS |
2331 | } |
2332 | ||
0e88de35 QY |
2333 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2334 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2335 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2336 | NO_STR |
2337 | "Adjust routing timers\n" | |
2338 | "OSPF LSA timers\n" | |
7a7be519 | 2339 | "Minimum delay in receiving new version of a LSA\n" |
2340 | "Delay in milliseconds\n") | |
b6927875 | 2341 | { |
a3d826f0 | 2342 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2343 | unsigned int minarrival; |
b6927875 | 2344 | |
d62a17ae | 2345 | if (argc > 4) { |
0e88de35 | 2346 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2347 | |
d62a17ae | 2348 | if (ospf->min_ls_arrival != minarrival |
2349 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2350 | return CMD_SUCCESS; | |
2351 | } | |
b6927875 | 2352 | |
d62a17ae | 2353 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2354 | |
d62a17ae | 2355 | return CMD_SUCCESS; |
b6927875 DS |
2356 | } |
2357 | ||
a2c62831 | 2358 | DEFUN (ospf_neighbor, |
2359 | ospf_neighbor_cmd, | |
7a7be519 | 2360 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2361 | NEIGHBOR_STR |
7a7be519 | 2362 | "Neighbor IP address\n" |
2363 | "Neighbor Priority\n" | |
2364 | "Priority\n" | |
2365 | "Dead Neighbor Polling interval\n" | |
2366 | "Seconds\n") | |
718e3744 | 2367 | { |
a3d826f0 | 2368 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2369 | int idx_ipv4 = 1; |
2370 | int idx_pri = 3; | |
2371 | int idx_poll = 5; | |
2372 | struct in_addr nbr_addr; | |
2373 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2374 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2375 | |
cc9b06ad DS |
2376 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2377 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2378 | return CMD_WARNING_CONFIG_FAILED; | |
2379 | } | |
718e3744 | 2380 | |
d62a17ae | 2381 | if (argc > 2) |
2382 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2383 | |
d62a17ae | 2384 | if (argc > 4) |
2385 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2386 | |
d62a17ae | 2387 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2388 | |
d62a17ae | 2389 | if (argc > 2) |
2390 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2391 | |
d62a17ae | 2392 | if (argc > 4) |
2393 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2394 | |
d62a17ae | 2395 | return CMD_SUCCESS; |
718e3744 | 2396 | } |
2397 | ||
a2c62831 | 2398 | DEFUN (ospf_neighbor_poll_interval, |
2399 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2400 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2401 | NEIGHBOR_STR |
2402 | "Neighbor IP address\n" | |
2403 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2404 | "Seconds\n" |
2405 | "OSPF priority of non-broadcast neighbor\n" | |
2406 | "Priority\n") | |
22b27e95 | 2407 | { |
a3d826f0 | 2408 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2409 | int idx_ipv4 = 1; |
2410 | int idx_poll = 3; | |
2411 | int idx_pri = 5; | |
2412 | struct in_addr nbr_addr; | |
a2b6e694 | 2413 | unsigned int priority; |
2414 | unsigned int interval; | |
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 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2422 | |
a2b6e694 | 2423 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2424 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2425 | |
d62a17ae | 2426 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2427 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2428 | |
d62a17ae | 2429 | if (argc > 4) |
2430 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2431 | |
d62a17ae | 2432 | return CMD_SUCCESS; |
718e3744 | 2433 | } |
2434 | ||
a2c62831 | 2435 | DEFUN (no_ospf_neighbor, |
2436 | no_ospf_neighbor_cmd, | |
7a7be519 | 2437 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2438 | NO_STR |
2439 | NEIGHBOR_STR | |
7a7be519 | 2440 | "Neighbor IP address\n" |
2441 | "Neighbor Priority\n" | |
2442 | "Priority\n" | |
2443 | "Dead Neighbor Polling interval\n" | |
2444 | "Seconds\n") | |
718e3744 | 2445 | { |
a3d826f0 | 2446 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2447 | int idx_ipv4 = 2; |
2448 | struct in_addr nbr_addr; | |
718e3744 | 2449 | |
cc9b06ad DS |
2450 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2451 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2452 | return CMD_WARNING_CONFIG_FAILED; | |
2453 | } | |
718e3744 | 2454 | |
d62a17ae | 2455 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2456 | |
d62a17ae | 2457 | return CMD_SUCCESS; |
718e3744 | 2458 | } |
2459 | ||
7a7be519 | 2460 | DEFUN (no_ospf_neighbor_poll, |
2461 | no_ospf_neighbor_poll_cmd, | |
2462 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2463 | NO_STR | |
2464 | NEIGHBOR_STR | |
2465 | "Neighbor IP address\n" | |
2466 | "Dead Neighbor Polling interval\n" | |
2467 | "Seconds\n" | |
2468 | "Neighbor Priority\n" | |
2469 | "Priority\n") | |
2470 | { | |
a3d826f0 | 2471 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2472 | int idx_ipv4 = 2; |
2473 | struct in_addr nbr_addr; | |
7a7be519 | 2474 | |
cc9b06ad DS |
2475 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2476 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2477 | return CMD_WARNING_CONFIG_FAILED; | |
2478 | } | |
718e3744 | 2479 | |
d62a17ae | 2480 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2481 | |
d62a17ae | 2482 | return CMD_SUCCESS; |
7a7be519 | 2483 | } |
718e3744 | 2484 | |
bf2bfafd DW |
2485 | DEFUN (ospf_refresh_timer, |
2486 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2487 | "refresh timer (10-1800)", |
718e3744 | 2488 | "Adjust refresh parameters\n" |
2489 | "Set refresh timer\n" | |
2490 | "Timer value in seconds\n") | |
2491 | { | |
a3d826f0 | 2492 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2493 | int idx_number = 2; |
2494 | unsigned int interval; | |
7c8ff89e | 2495 | |
d62a17ae | 2496 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2497 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2498 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2499 | |
d62a17ae | 2500 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2501 | |
d62a17ae | 2502 | return CMD_SUCCESS; |
718e3744 | 2503 | } |
2504 | ||
bf2bfafd DW |
2505 | DEFUN (no_ospf_refresh_timer, |
2506 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2507 | "no refresh timer [(10-1800)]", |
3a2d747c | 2508 | NO_STR |
718e3744 | 2509 | "Adjust refresh parameters\n" |
2510 | "Unset refresh timer\n" | |
2511 | "Timer value in seconds\n") | |
2512 | { | |
a3d826f0 | 2513 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2514 | int idx_number = 3; |
2515 | unsigned int interval; | |
718e3744 | 2516 | |
d62a17ae | 2517 | if (argc == 1) { |
2518 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2519 | |
d62a17ae | 2520 | if (ospf->lsa_refresh_interval != interval |
2521 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2522 | return CMD_SUCCESS; | |
2523 | } | |
2524 | ||
2525 | ospf_timers_refresh_unset(ospf); | |
2526 | ||
2527 | return CMD_SUCCESS; | |
718e3744 | 2528 | } |
2529 | ||
718e3744 | 2530 | |
a2c62831 | 2531 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2532 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2533 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2534 | "Calculate OSPF interface cost according to bandwidth\n" |
2535 | "Use reference bandwidth method to assign OSPF cost\n" | |
2536 | "The reference bandwidth in terms of Mbits per second\n") | |
2537 | { | |
a3d826f0 | 2538 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2539 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2540 | int idx_number = 2; |
d7c0a89a | 2541 | uint32_t refbw; |
d62a17ae | 2542 | struct interface *ifp; |
2543 | ||
2544 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2545 | if (refbw < 1 || refbw > 4294967) { | |
2546 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2547 | return CMD_WARNING_CONFIG_FAILED; | |
2548 | } | |
2549 | ||
2550 | /* If reference bandwidth is changed. */ | |
2551 | if ((refbw) == ospf->ref_bandwidth) | |
2552 | return CMD_SUCCESS; | |
2553 | ||
2554 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2555 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2556 | ospf_if_recalculate_output_cost(ifp); |
2557 | ||
2558 | return CMD_SUCCESS; | |
718e3744 | 2559 | } |
2560 | ||
a2c62831 | 2561 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2562 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2563 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2564 | NO_STR |
2565 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2566 | "Use reference bandwidth method to assign OSPF cost\n" |
2567 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2568 | { |
a3d826f0 | 2569 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2570 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2571 | struct interface *ifp; |
718e3744 | 2572 | |
d62a17ae | 2573 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2574 | return CMD_SUCCESS; | |
2575 | ||
2576 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2577 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2578 | vty_out(vty, | |
2579 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2580 | ||
451fda4f | 2581 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2582 | ospf_if_recalculate_output_cost(ifp); |
2583 | ||
2584 | return CMD_SUCCESS; | |
718e3744 | 2585 | } |
2586 | ||
2f8f370e DS |
2587 | DEFUN (ospf_write_multiplier, |
2588 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2589 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2590 | "OSPF specific commands\n" |
2591 | "Write multiplier\n" | |
2592 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2593 | { |
a3d826f0 | 2594 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2595 | int idx_number; |
d7c0a89a | 2596 | uint32_t write_oi_count; |
d62a17ae | 2597 | |
2598 | if (argc == 3) | |
2599 | idx_number = 2; | |
2600 | else | |
2601 | idx_number = 1; | |
2602 | ||
2603 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2604 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2605 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2606 | return CMD_WARNING_CONFIG_FAILED; | |
2607 | } | |
2608 | ||
2609 | ospf->write_oi_count = write_oi_count; | |
2610 | return CMD_SUCCESS; | |
2f8f370e DS |
2611 | } |
2612 | ||
d62a17ae | 2613 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2614 | "Write multiplier\n" | |
2615 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2616 | |
2f8f370e DS |
2617 | DEFUN (no_ospf_write_multiplier, |
2618 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2619 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2620 | NO_STR |
e8f45e82 | 2621 | "OSPF specific commands\n" |
813d4307 DW |
2622 | "Write multiplier\n" |
2623 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2624 | { |
a3d826f0 | 2625 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2626 | |
d62a17ae | 2627 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2628 | return CMD_SUCCESS; | |
2f8f370e DS |
2629 | } |
2630 | ||
d62a17ae | 2631 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2632 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2633 | "Write multiplier\n" |
2634 | "Maximum number of interface serviced per write\n") | |
2635 | ||
2b64873d DL |
2636 | static const char *const ospf_abr_type_descr_str[] = { |
2637 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2638 | "Alternative Cisco", "Alternative Shortcut" | |
2639 | }; | |
d62a17ae | 2640 | |
2b64873d DL |
2641 | static const char *const ospf_shortcut_mode_descr_str[] = { |
2642 | "Default", "Enabled", "Disabled" | |
2643 | }; | |
d62a17ae | 2644 | |
2645 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2646 | json_object *json_areas, bool use_json) |
d62a17ae | 2647 | { |
2648 | json_object *json_area = NULL; | |
2649 | ||
2650 | if (use_json) | |
2651 | json_area = json_object_new_object(); | |
2652 | ||
2653 | /* Show Area ID. */ | |
2654 | if (!use_json) | |
2655 | vty_out(vty, " Area ID: %s", inet_ntoa(area->area_id)); | |
2656 | ||
2657 | /* Show Area type/mode. */ | |
2658 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2659 | if (use_json) | |
2660 | json_object_boolean_true_add(json_area, "backbone"); | |
2661 | else | |
2662 | vty_out(vty, " (Backbone)\n"); | |
2663 | } else { | |
2664 | if (use_json) { | |
2665 | if (area->external_routing == OSPF_AREA_STUB) { | |
2666 | if (area->no_summary) | |
2667 | json_object_boolean_true_add( | |
2668 | json_area, "stubNoSummary"); | |
2669 | if (area->shortcut_configured) | |
2670 | json_object_boolean_true_add( | |
2671 | json_area, "stubShortcut"); | |
2672 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2673 | if (area->no_summary) | |
2674 | json_object_boolean_true_add( | |
2675 | json_area, "nssaNoSummary"); | |
2676 | if (area->shortcut_configured) | |
2677 | json_object_boolean_true_add( | |
2678 | json_area, "nssaShortcut"); | |
2679 | } | |
813d4307 | 2680 | |
d62a17ae | 2681 | json_object_string_add( |
2682 | json_area, "shortcuttingMode", | |
2683 | ospf_shortcut_mode_descr_str | |
2684 | [area->shortcut_configured]); | |
2685 | if (area->shortcut_capability) | |
2686 | json_object_boolean_true_add(json_area, | |
2687 | "sBitConcensus"); | |
2688 | } else { | |
2689 | if (area->external_routing == OSPF_AREA_STUB) | |
2690 | vty_out(vty, " (Stub%s%s)", | |
2691 | area->no_summary ? ", no summary" : "", | |
2692 | area->shortcut_configured ? "; " : ""); | |
2693 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2694 | vty_out(vty, " (NSSA%s%s)", | |
2695 | area->no_summary ? ", no summary" : "", | |
2696 | area->shortcut_configured ? "; " : ""); | |
2697 | ||
2698 | vty_out(vty, "\n"); | |
2699 | vty_out(vty, " Shortcutting mode: %s", | |
2700 | ospf_shortcut_mode_descr_str | |
2701 | [area->shortcut_configured]); | |
2702 | vty_out(vty, ", S-bit consensus: %s\n", | |
2703 | area->shortcut_capability ? "ok" : "no"); | |
2704 | } | |
2705 | } | |
718e3744 | 2706 | |
d62a17ae | 2707 | /* Show number of interfaces */ |
2708 | if (use_json) { | |
2709 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2710 | listcount(area->oiflist)); | |
2711 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2712 | area->act_ints); | |
2713 | } else | |
2714 | vty_out(vty, | |
2715 | " Number of interfaces in this area: Total: %d, " | |
2716 | "Active: %d\n", | |
2717 | listcount(area->oiflist), area->act_ints); | |
2718 | ||
2719 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2720 | if (use_json) { | |
2721 | json_object_boolean_true_add(json_area, "nssa"); | |
2722 | if (!IS_OSPF_ABR(area->ospf)) | |
2723 | json_object_boolean_false_add(json_area, "abr"); | |
2724 | else if (area->NSSATranslatorState) { | |
2725 | json_object_boolean_true_add(json_area, "abr"); | |
2726 | if (area->NSSATranslatorRole | |
2727 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2728 | json_object_boolean_true_add( | |
2729 | json_area, | |
2730 | "nssaTranslatorElected"); | |
2731 | else if (area->NSSATranslatorRole | |
2732 | == OSPF_NSSA_ROLE_ALWAYS) | |
2733 | json_object_boolean_true_add( | |
2734 | json_area, | |
2735 | "nssaTranslatorAlways"); | |
2736 | } else { | |
2737 | json_object_boolean_true_add(json_area, "abr"); | |
2738 | if (area->NSSATranslatorRole | |
2739 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2740 | json_object_boolean_false_add( | |
2741 | json_area, | |
2742 | "nssaTranslatorElected"); | |
2743 | else | |
2744 | json_object_boolean_true_add( | |
2745 | json_area, | |
2746 | "nssaTranslatorNever"); | |
2747 | } | |
2748 | } else { | |
2749 | vty_out(vty, | |
2750 | " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n"); | |
2751 | if (!IS_OSPF_ABR(area->ospf)) | |
2752 | vty_out(vty, | |
2753 | " It is not ABR, therefore not Translator. \n"); | |
2754 | else if (area->NSSATranslatorState) { | |
2755 | vty_out(vty, " We are an ABR and "); | |
2756 | if (area->NSSATranslatorRole | |
2757 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2758 | vty_out(vty, | |
2759 | "the NSSA Elected Translator. \n"); | |
2760 | else if (area->NSSATranslatorRole | |
2761 | == OSPF_NSSA_ROLE_ALWAYS) | |
2762 | vty_out(vty, | |
2763 | "always an NSSA Translator. \n"); | |
2764 | } else { | |
2765 | vty_out(vty, " We are an ABR, but "); | |
2766 | if (area->NSSATranslatorRole | |
2767 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2768 | vty_out(vty, | |
2769 | "not the NSSA Elected Translator. \n"); | |
2770 | else | |
2771 | vty_out(vty, | |
2772 | "never an NSSA Translator. \n"); | |
2773 | } | |
2774 | } | |
2775 | } | |
2776 | ||
2777 | /* Stub-router state for this area */ | |
2778 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2779 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2780 | ||
2781 | if (use_json) { | |
2782 | json_object_boolean_true_add( | |
2783 | json_area, "originStubMaxDistRouterLsa"); | |
2784 | if (CHECK_FLAG(area->stub_router_state, | |
2785 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2786 | json_object_boolean_true_add( | |
2787 | json_area, "indefiniteActiveAdmin"); | |
2788 | if (area->t_stub_router) { | |
2789 | long time_store; | |
2790 | time_store = | |
2791 | monotime_until( | |
2792 | &area->t_stub_router->u.sands, | |
2793 | NULL) | |
2794 | / 1000LL; | |
2795 | json_object_int_add( | |
2796 | json_area, | |
2797 | "activeStartupRemainderMsecs", | |
2798 | time_store); | |
2799 | } | |
2800 | } else { | |
2801 | vty_out(vty, | |
2802 | " Originating stub / maximum-distance Router-LSA\n"); | |
2803 | if (CHECK_FLAG(area->stub_router_state, | |
2804 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2805 | vty_out(vty, | |
2806 | " Administratively activated (indefinitely)\n"); | |
2807 | if (area->t_stub_router) | |
2808 | vty_out(vty, | |
2809 | " Active from startup, %s remaining\n", | |
2810 | ospf_timer_dump(area->t_stub_router, | |
2811 | timebuf, | |
2812 | sizeof(timebuf))); | |
2813 | } | |
2814 | } | |
2815 | ||
2816 | if (use_json) { | |
2817 | /* Show number of fully adjacent neighbors. */ | |
2818 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2819 | area->full_nbrs); | |
2820 | ||
2821 | /* Show authentication type. */ | |
2822 | if (area->auth_type == OSPF_AUTH_NULL) | |
2823 | json_object_string_add(json_area, "authentication", | |
2824 | "authenticationNone"); | |
2825 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2826 | json_object_string_add(json_area, "authentication", | |
2827 | "authenticationSimplePassword"); | |
2828 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2829 | json_object_string_add(json_area, "authentication", | |
2830 | "authenticationMessageDigest"); | |
2831 | ||
2832 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2833 | json_object_int_add(json_area, | |
2834 | "virtualAdjacenciesPassingCounter", | |
2835 | area->full_vls); | |
2836 | ||
2837 | /* Show SPF calculation times. */ | |
2838 | json_object_int_add(json_area, "spfExecutedCounter", | |
2839 | area->spf_calculation); | |
2840 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2841 | json_object_int_add( | |
2842 | json_area, "lsaRouterNumber", | |
2843 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2844 | json_object_int_add( | |
2845 | json_area, "lsaRouterChecksum", | |
2846 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2847 | json_object_int_add( | |
2848 | json_area, "lsaNetworkNumber", | |
2849 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2850 | json_object_int_add( | |
2851 | json_area, "lsaNetworkChecksum", | |
2852 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2853 | json_object_int_add( | |
2854 | json_area, "lsaSummaryNumber", | |
2855 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2856 | json_object_int_add( | |
2857 | json_area, "lsaSummaryChecksum", | |
2858 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2859 | json_object_int_add( | |
2860 | json_area, "lsaAsbrNumber", | |
2861 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2862 | json_object_int_add( | |
2863 | json_area, "lsaAsbrChecksum", | |
2864 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2865 | json_object_int_add( | |
2866 | json_area, "lsaNssaNumber", | |
2867 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2868 | json_object_int_add( | |
2869 | json_area, "lsaNssaChecksum", | |
2870 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2871 | } else { | |
2872 | /* Show number of fully adjacent neighbors. */ | |
2873 | vty_out(vty, | |
2874 | " Number of fully adjacent neighbors in this area:" | |
2875 | " %d\n", | |
2876 | area->full_nbrs); | |
2877 | ||
2878 | /* Show authentication type. */ | |
2879 | vty_out(vty, " Area has "); | |
2880 | if (area->auth_type == OSPF_AUTH_NULL) | |
2881 | vty_out(vty, "no authentication\n"); | |
2882 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2883 | vty_out(vty, "simple password authentication\n"); | |
2884 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2885 | vty_out(vty, "message digest authentication\n"); | |
2886 | ||
2887 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2888 | vty_out(vty, | |
2889 | " Number of full virtual adjacencies going through" | |
2890 | " this area: %d\n", | |
2891 | area->full_vls); | |
2892 | ||
2893 | /* Show SPF calculation times. */ | |
2894 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2895 | area->spf_calculation); | |
2896 | ||
2897 | /* Show number of LSA. */ | |
2898 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2899 | vty_out(vty, | |
2900 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2901 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2902 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2903 | vty_out(vty, | |
2904 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2905 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2906 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2907 | vty_out(vty, | |
2908 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2909 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2910 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2911 | vty_out(vty, | |
2912 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2913 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
2914 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2915 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
2916 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
2917 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2918 | } | |
2919 | ||
2920 | if (use_json) { | |
2921 | json_object_int_add( | |
2922 | json_area, "lsaOpaqueLinkNumber", | |
2923 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2924 | json_object_int_add( | |
2925 | json_area, "lsaOpaqueLinkChecksum", | |
2926 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2927 | json_object_int_add( | |
2928 | json_area, "lsaOpaqueAreaNumber", | |
2929 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2930 | json_object_int_add( | |
2931 | json_area, "lsaOpaqueAreaChecksum", | |
2932 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2933 | } else { | |
2934 | vty_out(vty, | |
2935 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
2936 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
2937 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2938 | vty_out(vty, | |
2939 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
2940 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
2941 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2942 | } | |
718e3744 | 2943 | |
d62a17ae | 2944 | if (use_json) |
2945 | json_object_object_add(json_areas, inet_ntoa(area->area_id), | |
2946 | json_area); | |
2947 | else | |
2948 | vty_out(vty, "\n"); | |
718e3744 | 2949 | } |
2950 | ||
d62a17ae | 2951 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 2952 | json_object *json, uint8_t use_vrf) |
d62a17ae | 2953 | { |
2954 | struct listnode *node, *nnode; | |
2955 | struct ospf_area *area; | |
2956 | struct timeval result; | |
2957 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
b1c3ae8c | 2958 | json_object *json_vrf = NULL; |
d62a17ae | 2959 | json_object *json_areas = NULL; |
718e3744 | 2960 | |
b1c3ae8c CS |
2961 | if (json) { |
2962 | if (use_vrf) | |
2963 | json_vrf = json_object_new_object(); | |
2964 | else | |
2965 | json_vrf = json; | |
d62a17ae | 2966 | json_areas = json_object_new_object(); |
2967 | } | |
2968 | ||
2969 | if (ospf->instance) { | |
b1c3ae8c | 2970 | if (json) { |
d62a17ae | 2971 | json_object_int_add(json, "ospfInstance", |
2972 | ospf->instance); | |
2973 | } else { | |
2974 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
2975 | } | |
2976 | } | |
2977 | ||
b1c3ae8c | 2978 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 2979 | |
d62a17ae | 2980 | /* Show Router ID. */ |
b1c3ae8c CS |
2981 | if (json) { |
2982 | json_object_string_add(json_vrf, "routerId", | |
d62a17ae | 2983 | inet_ntoa(ospf->router_id)); |
2984 | } else { | |
2985 | vty_out(vty, " OSPF Routing Process, Router ID: %s\n", | |
2986 | inet_ntoa(ospf->router_id)); | |
2987 | } | |
2988 | ||
2989 | /* Graceful shutdown */ | |
2990 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 2991 | if (json) { |
d62a17ae | 2992 | long time_store; |
2993 | time_store = | |
2994 | monotime_until( | |
2995 | &ospf->t_deferred_shutdown->u.sands, | |
2996 | NULL) | |
2997 | / 1000LL; | |
b1c3ae8c | 2998 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 2999 | time_store); |
3000 | } else { | |
3001 | vty_out(vty, | |
3002 | " Deferred shutdown in progress, %s remaining\n", | |
3003 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
3004 | timebuf, sizeof(timebuf))); | |
3005 | } | |
3006 | } | |
3007 | ||
3008 | /* Show capability. */ | |
b1c3ae8c CS |
3009 | if (json) { |
3010 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
3011 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 3012 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 3013 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3014 | "rfc1583Compatibility"); |
3015 | } | |
3016 | } else { | |
3017 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3018 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3019 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3020 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3021 | ? "enabled" | |
3022 | : "disabled"); | |
3023 | } | |
3024 | ||
b1c3ae8c | 3025 | if (json) { |
d62a17ae | 3026 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3027 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3028 | } |
3029 | } else { | |
3030 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3031 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3032 | ? "enabled" | |
3033 | : "disabled"); | |
3034 | } | |
3035 | ||
3036 | /* Show stub-router configuration */ | |
3037 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3038 | || ospf->stub_router_shutdown_time | |
3039 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3040 | if (json) { |
3041 | json_object_boolean_true_add(json_vrf, | |
3042 | "stubAdvertisement"); | |
d62a17ae | 3043 | if (ospf->stub_router_startup_time |
3044 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3045 | json_object_int_add( | |
50ad4b42 MS |
3046 | json_vrf, "postStartEnabledSecs", |
3047 | ospf->stub_router_startup_time); | |
d62a17ae | 3048 | if (ospf->stub_router_shutdown_time |
3049 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3050 | json_object_int_add( | |
50ad4b42 MS |
3051 | json_vrf, "preShutdownEnabledSecs", |
3052 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3053 | } else { |
3054 | vty_out(vty, | |
3055 | " Stub router advertisement is configured\n"); | |
3056 | if (ospf->stub_router_startup_time | |
3057 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3058 | vty_out(vty, | |
3059 | " Enabled for %us after start-up\n", | |
3060 | ospf->stub_router_startup_time); | |
3061 | if (ospf->stub_router_shutdown_time | |
3062 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3063 | vty_out(vty, | |
3064 | " Enabled for %us prior to full shutdown\n", | |
3065 | ospf->stub_router_shutdown_time); | |
3066 | } | |
3067 | } | |
3068 | ||
3069 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3070 | if (json) { |
3071 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3072 | ospf->spf_delay); |
b1c3ae8c | 3073 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3074 | ospf->spf_holdtime); |
b1c3ae8c | 3075 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3076 | ospf->spf_max_holdtime); |
b1c3ae8c | 3077 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3078 | ospf->spf_hold_multiplier); |
3079 | } else { | |
3080 | vty_out(vty, | |
3081 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3082 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3083 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3084 | " Hold time multiplier is currently %d\n", | |
3085 | ospf->spf_delay, ospf->spf_holdtime, | |
3086 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3087 | } | |
3088 | ||
b1c3ae8c | 3089 | if (json) { |
d62a17ae | 3090 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3091 | long time_store = 0; | |
3092 | ||
3093 | time_store = | |
3094 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3095 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3096 | time_store); |
3097 | ||
3098 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3099 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3100 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3101 | time_store); |
3102 | } else | |
b1c3ae8c | 3103 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3104 | } else { |
3105 | vty_out(vty, " SPF algorithm "); | |
3106 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3107 | monotime_since(&ospf->ts_spf, &result); | |
3108 | vty_out(vty, "last executed %s ago\n", | |
3109 | ospf_timeval_dump(&result, timebuf, | |
3110 | sizeof(timebuf))); | |
3111 | vty_out(vty, " Last SPF duration %s\n", | |
3112 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3113 | timebuf, sizeof(timebuf))); | |
3114 | } else | |
3115 | vty_out(vty, "has not been run\n"); | |
3116 | } | |
3117 | ||
b1c3ae8c | 3118 | if (json) { |
d62a17ae | 3119 | if (ospf->t_spf_calc) { |
3120 | long time_store; | |
3121 | time_store = | |
3122 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3123 | / 1000LL; | |
b1c3ae8c | 3124 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3125 | time_store); |
3126 | } | |
3127 | ||
b1c3ae8c | 3128 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3129 | ospf->min_ls_interval); |
b1c3ae8c | 3130 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3131 | ospf->min_ls_arrival); |
3132 | /* Show write multiplier values */ | |
b1c3ae8c | 3133 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3134 | ospf->write_oi_count); |
3135 | /* Show refresh parameters. */ | |
b1c3ae8c | 3136 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3137 | ospf->lsa_refresh_interval * 1000); |
3138 | } else { | |
3139 | vty_out(vty, " SPF timer %s%s\n", | |
3140 | (ospf->t_spf_calc ? "due in " : "is "), | |
3141 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3142 | sizeof(timebuf))); | |
3143 | ||
3144 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3145 | ospf->min_ls_interval); | |
3146 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3147 | ospf->min_ls_arrival); | |
3148 | ||
3149 | /* Show write multiplier values */ | |
3150 | vty_out(vty, " Write Multiplier set to %d \n", | |
3151 | ospf->write_oi_count); | |
3152 | ||
3153 | /* Show refresh parameters. */ | |
3154 | vty_out(vty, " Refresh timer %d secs\n", | |
3155 | ospf->lsa_refresh_interval); | |
3156 | } | |
3157 | ||
3158 | /* Show ABR/ASBR flags. */ | |
3159 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3160 | if (json) |
d62a17ae | 3161 | json_object_string_add( |
b1c3ae8c | 3162 | json_vrf, "abrType", |
d62a17ae | 3163 | ospf_abr_type_descr_str[ospf->abr_type]); |
3164 | else | |
3165 | vty_out(vty, | |
3166 | " This router is an ABR, ABR type is: %s\n", | |
3167 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3168 | } | |
3169 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3170 | if (json) |
d62a17ae | 3171 | json_object_string_add( |
b1c3ae8c | 3172 | json_vrf, "asbrRouter", |
d62a17ae | 3173 | "injectingExternalRoutingInformation"); |
3174 | else | |
3175 | vty_out(vty, | |
3176 | " This router is an ASBR " | |
3177 | "(injecting external routing information)\n"); | |
3178 | } | |
3179 | ||
3180 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3181 | if (json) { |
d62a17ae | 3182 | json_object_int_add( |
b1c3ae8c | 3183 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3184 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3185 | json_object_int_add( | |
b1c3ae8c | 3186 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3187 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3188 | } else { | |
3189 | vty_out(vty, | |
3190 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3191 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3192 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3193 | } | |
3194 | ||
b1c3ae8c | 3195 | if (json) { |
d62a17ae | 3196 | json_object_int_add( |
b1c3ae8c | 3197 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3198 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3199 | json_object_int_add( | |
b1c3ae8c | 3200 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3201 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3202 | } else { | |
3203 | vty_out(vty, | |
3204 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3205 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3206 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3207 | } | |
3208 | ||
3209 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3210 | if (json) |
3211 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3212 | listcount(ospf->areas)); |
3213 | else | |
3214 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3215 | listcount(ospf->areas)); | |
3216 | ||
3217 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3218 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3219 | if (json) |
d62a17ae | 3220 | json_object_boolean_true_add( |
b1c3ae8c | 3221 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3222 | else |
3223 | vty_out(vty, | |
3224 | " All adjacency changes are logged\n"); | |
3225 | } else { | |
b1c3ae8c | 3226 | if (json) |
d62a17ae | 3227 | json_object_boolean_true_add( |
b1c3ae8c | 3228 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3229 | else |
3230 | vty_out(vty, " Adjacency changes are logged\n"); | |
3231 | } | |
3232 | } | |
3233 | /* Show each area status. */ | |
3234 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3235 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3236 | ||
3237 | if (json) { | |
3238 | if (use_vrf) { | |
3239 | json_object_object_add(json_vrf, "areas", json_areas); | |
3240 | if (ospf->vrf_id == VRF_DEFAULT) | |
3241 | json_object_object_add(json, "default", | |
3242 | json_vrf); | |
3243 | else | |
3244 | json_object_object_add(json, ospf->name, | |
3245 | json_vrf); | |
3246 | } else { | |
3247 | json_object_object_add(json, "areas", json_areas); | |
3248 | } | |
d62a17ae | 3249 | } else |
3250 | vty_out(vty, "\n"); | |
3251 | ||
3252 | return CMD_SUCCESS; | |
718e3744 | 3253 | } |
3254 | ||
7c8ff89e DS |
3255 | DEFUN (show_ip_ospf, |
3256 | show_ip_ospf_cmd, | |
b5a8894d | 3257 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3258 | SHOW_STR |
3259 | IP_STR | |
ca08c43d | 3260 | "OSPF information\n" |
b5a8894d CS |
3261 | VRF_CMD_HELP_STR |
3262 | "All VRFs\n" | |
9973d184 | 3263 | JSON_STR) |
7c8ff89e | 3264 | { |
d62a17ae | 3265 | struct ospf *ospf; |
9f049418 | 3266 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3267 | struct listnode *node = NULL; |
3268 | char *vrf_name = NULL; | |
2951a7a4 | 3269 | bool all_vrf = false; |
b5a8894d CS |
3270 | int ret = CMD_SUCCESS; |
3271 | int inst = 0; | |
3272 | int idx_vrf = 0; | |
b1c3ae8c | 3273 | json_object *json = NULL; |
d7c0a89a | 3274 | uint8_t use_vrf = 0; |
7c8ff89e | 3275 | |
b5a8894d | 3276 | if (listcount(om->ospf) == 0) |
d62a17ae | 3277 | return CMD_SUCCESS; |
7c8ff89e | 3278 | |
43b8d1d8 | 3279 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3280 | |
b1c3ae8c CS |
3281 | if (uj) |
3282 | json = json_object_new_object(); | |
3283 | ||
996c9314 | 3284 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3285 | if (vrf_name) { |
2951a7a4 | 3286 | bool ospf_output = false; |
874f58d8 | 3287 | |
b1c3ae8c | 3288 | use_vrf = 1; |
94d4c685 | 3289 | |
b5a8894d CS |
3290 | if (all_vrf) { |
3291 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3292 | if (!ospf->oi_running) | |
3293 | continue; | |
2951a7a4 | 3294 | ospf_output = true; |
b1c3ae8c CS |
3295 | ret = show_ip_ospf_common(vty, ospf, json, |
3296 | use_vrf); | |
3297 | } | |
3298 | if (uj) { | |
3299 | vty_out(vty, "%s\n", | |
996c9314 LB |
3300 | json_object_to_json_string_ext( |
3301 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3302 | json_object_free(json); |
9f049418 DS |
3303 | } else if (!ospf_output) |
3304 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
3305 | return ret; |
3306 | } | |
3307 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3308 | if ((ospf == NULL) || !ospf->oi_running) { |
9f049418 DS |
3309 | if (uj) { |
3310 | vty_out(vty, "%s\n", | |
3311 | json_object_to_json_string_ext( | |
3312 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3313 | json_object_free(json); |
9f049418 | 3314 | } else |
94d4c685 | 3315 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3316 | |
b5a8894d | 3317 | return CMD_SUCCESS; |
b1c3ae8c | 3318 | } |
b5a8894d CS |
3319 | } else { |
3320 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3321 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3322 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3323 | if (uj) { |
3324 | vty_out(vty, "%s\n", | |
3325 | json_object_to_json_string_ext( | |
3326 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3327 | json_object_free(json); |
9f049418 | 3328 | } else |
94d4c685 | 3329 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3330 | |
b5a8894d | 3331 | return CMD_SUCCESS; |
b1c3ae8c | 3332 | } |
b5a8894d CS |
3333 | } |
3334 | ||
996c9314 | 3335 | if (ospf) { |
b1c3ae8c CS |
3336 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3337 | if (uj) | |
996c9314 LB |
3338 | vty_out(vty, "%s\n", |
3339 | json_object_to_json_string_ext( | |
3340 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3341 | } |
3342 | ||
3343 | if (uj) | |
3344 | json_object_free(json); | |
b5a8894d CS |
3345 | |
3346 | return ret; | |
7c8ff89e DS |
3347 | } |
3348 | ||
3349 | DEFUN (show_ip_ospf_instance, | |
3350 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3351 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3352 | SHOW_STR |
3353 | IP_STR | |
3354 | "OSPF information\n" | |
ca08c43d | 3355 | "Instance ID\n" |
9973d184 | 3356 | JSON_STR) |
7c8ff89e | 3357 | { |
d62a17ae | 3358 | int idx_number = 3; |
3359 | struct ospf *ospf; | |
d7c0a89a | 3360 | unsigned short instance = 0; |
9f049418 | 3361 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3362 | int ret = CMD_SUCCESS; |
3363 | json_object *json = NULL; | |
d62a17ae | 3364 | |
3365 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3366 | ospf = ospf_lookup_instance(instance); |
3367 | if (ospf == NULL) | |
3368 | return CMD_NOT_MY_INSTANCE; | |
3369 | ||
3370 | if (!ospf->oi_running) | |
d62a17ae | 3371 | return CMD_SUCCESS; |
3372 | ||
b1c3ae8c CS |
3373 | if (uj) |
3374 | json = json_object_new_object(); | |
3375 | ||
3376 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3377 | ||
3378 | if (uj) { | |
996c9314 LB |
3379 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3380 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3381 | json_object_free(json); |
3382 | } | |
3383 | ||
3384 | return ret; | |
d62a17ae | 3385 | } |
3386 | ||
3387 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, | |
3388 | struct interface *ifp, | |
3389 | json_object *json_interface_sub, | |
9f049418 | 3390 | bool use_json) |
d62a17ae | 3391 | { |
3392 | int is_up; | |
3393 | struct ospf_neighbor *nbr; | |
3394 | struct route_node *rn; | |
3395 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; | |
3396 | ||
3397 | /* Is interface up? */ | |
3398 | if (use_json) { | |
3399 | is_up = if_is_operative(ifp); | |
3400 | if (is_up) | |
3401 | json_object_boolean_true_add(json_interface_sub, | |
3402 | "ifUp"); | |
3403 | else | |
3404 | json_object_boolean_false_add(json_interface_sub, | |
3405 | "ifDown"); | |
3406 | ||
3407 | json_object_int_add(json_interface_sub, "ifIndex", | |
3408 | ifp->ifindex); | |
3409 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3410 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3411 | bandwidth); | |
3412 | json_object_string_add(json_interface_sub, "ifFlags", | |
3413 | if_flag_dump(ifp->flags)); | |
3414 | } else { | |
3415 | vty_out(vty, "%s is %s\n", ifp->name, | |
3416 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3417 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3418 | ifp->ifindex, ifp->mtu, bandwidth, | |
3419 | if_flag_dump(ifp->flags)); | |
3420 | } | |
7c8ff89e | 3421 | |
d62a17ae | 3422 | /* Is interface OSPF enabled? */ |
3423 | if (use_json) { | |
3424 | if (ospf_oi_count(ifp) == 0) { | |
3425 | json_object_boolean_false_add(json_interface_sub, | |
3426 | "ospfEnabled"); | |
3427 | return; | |
3428 | } else if (!is_up) { | |
3429 | json_object_boolean_false_add(json_interface_sub, | |
3430 | "ospfRunning"); | |
3431 | return; | |
3432 | } else | |
3433 | json_object_boolean_true_add(json_interface_sub, | |
3434 | "ospfEnabled"); | |
3435 | } else { | |
3436 | if (ospf_oi_count(ifp) == 0) { | |
3437 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3438 | return; | |
3439 | } else if (!is_up) { | |
3440 | vty_out(vty, | |
3441 | " OSPF is enabled, but not running on this interface\n"); | |
3442 | return; | |
3443 | } | |
3444 | } | |
3445 | ||
3446 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3447 | struct ospf_interface *oi = rn->info; | |
3448 | ||
3449 | if (oi == NULL) | |
3450 | continue; | |
3451 | ||
3452 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3453 | if (use_json) | |
3454 | json_object_boolean_true_add(json_interface_sub, | |
3455 | "ifUnnumbered"); | |
3456 | else | |
3457 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3458 | } else { | |
0f3af738 JW |
3459 | struct in_addr dest; |
3460 | const char *dstr; | |
3461 | ||
d62a17ae | 3462 | /* Show OSPF interface information. */ |
3463 | if (use_json) { | |
3464 | json_object_string_add( | |
3465 | json_interface_sub, "ipAddress", | |
3466 | inet_ntoa(oi->address->u.prefix4)); | |
3467 | json_object_int_add(json_interface_sub, | |
3468 | "ipAddressPrefixlen", | |
3469 | oi->address->prefixlen); | |
3470 | } else | |
3471 | vty_out(vty, " Internet Address %s/%d,", | |
3472 | inet_ntoa(oi->address->u.prefix4), | |
3473 | oi->address->prefixlen); | |
3474 | ||
0f3af738 JW |
3475 | /* For Vlinks, showing the peer address is |
3476 | * probably more informative than the local | |
3477 | * interface that is being used */ | |
3478 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3479 | dstr = "Peer"; | |
3480 | dest = oi->vl_data->peer_addr; | |
3481 | } else if (CONNECTED_PEER(oi->connected) | |
3482 | && oi->connected->destination) { | |
3483 | dstr = "Peer"; | |
3484 | dest = oi->connected->destination->u.prefix4; | |
3485 | } else { | |
3486 | dstr = "Broadcast"; | |
3487 | dest.s_addr = ipv4_broadcast_addr( | |
3488 | oi->connected->address->u.prefix4.s_addr, | |
3489 | oi->connected->address->prefixlen); | |
3490 | } | |
d62a17ae | 3491 | |
0f3af738 JW |
3492 | if (use_json) { |
3493 | json_object_string_add( | |
3494 | json_interface_sub, | |
3495 | "ospfIfType", dstr); | |
d62a17ae | 3496 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
0f3af738 JW |
3497 | json_object_string_add( |
3498 | json_interface_sub, | |
3499 | "vlinkPeer", | |
3500 | inet_ntoa(dest)); | |
d62a17ae | 3501 | else |
d62a17ae | 3502 | json_object_string_add( |
3503 | json_interface_sub, | |
0f3af738 JW |
3504 | "localIfUsed", |
3505 | inet_ntoa(dest)); | |
3506 | } else | |
3507 | vty_out(vty, " %s %s,", dstr, | |
3508 | inet_ntoa(dest)); | |
d62a17ae | 3509 | } |
3510 | if (use_json) { | |
3511 | json_object_string_add(json_interface_sub, "area", | |
3512 | ospf_area_desc_string(oi->area)); | |
3513 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3514 | json_object_boolean_true_add( | |
3515 | json_interface_sub, | |
3516 | "mtuMismatchDetect"); | |
3517 | json_object_string_add(json_interface_sub, "routerId", | |
3518 | inet_ntoa(ospf->router_id)); | |
3519 | json_object_string_add(json_interface_sub, | |
3520 | "networkType", | |
3521 | ospf_network_type_str[oi->type]); | |
3522 | json_object_int_add(json_interface_sub, "cost", | |
3523 | oi->output_cost); | |
3524 | json_object_int_add( | |
50ad4b42 MS |
3525 | json_interface_sub, "transmitDelaySecs", |
3526 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3527 | json_object_string_add(json_interface_sub, "state", |
3528 | lookup_msg(ospf_ism_state_msg, | |
3529 | oi->state, NULL)); | |
3530 | json_object_int_add(json_interface_sub, "priority", | |
3531 | PRIORITY(oi)); | |
3532 | } else { | |
3533 | vty_out(vty, " Area %s\n", | |
3534 | ospf_area_desc_string(oi->area)); | |
3535 | ||
3536 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3537 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3538 | : "enabled"); | |
3539 | ||
3540 | vty_out(vty, | |
3541 | " Router ID %s, Network Type %s, Cost: %d\n", | |
3542 | inet_ntoa(ospf->router_id), | |
3543 | ospf_network_type_str[oi->type], | |
3544 | oi->output_cost); | |
3545 | ||
3546 | vty_out(vty, | |
3547 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3548 | OSPF_IF_PARAM(oi, transmit_delay), | |
3549 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3550 | PRIORITY(oi)); | |
3551 | } | |
3552 | ||
3553 | /* Show DR information. */ | |
975a328e | 3554 | if (DR(oi).s_addr == INADDR_ANY) { |
d62a17ae | 3555 | if (!use_json) |
3556 | vty_out(vty, | |
3557 | " No backup designated router on this network\n"); | |
3558 | } else { | |
3559 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3560 | if (nbr == NULL) { | |
3561 | if (!use_json) | |
3562 | vty_out(vty, | |
3563 | " No backup designated router on this network\n"); | |
3564 | } else { | |
3565 | if (use_json) { | |
3566 | json_object_string_add( | |
3567 | json_interface_sub, "bdrId", | |
3568 | inet_ntoa(nbr->router_id)); | |
3569 | json_object_string_add( | |
3570 | json_interface_sub, | |
3571 | "bdrAddress", | |
3572 | inet_ntoa(nbr->address.u | |
3573 | .prefix4)); | |
3574 | } else { | |
3575 | vty_out(vty, | |
3576 | " Backup Designated Router (ID) %s,", | |
3577 | inet_ntoa(nbr->router_id)); | |
3578 | vty_out(vty, " Interface Address %s\n", | |
3579 | inet_ntoa(nbr->address.u | |
3580 | .prefix4)); | |
3581 | } | |
3582 | } | |
3583 | } | |
3584 | ||
3585 | /* Next network-LSA sequence number we'll use, if we're elected | |
3586 | * DR */ | |
3587 | if (oi->params | |
3588 | && ntohl(oi->params->network_lsa_seqnum) | |
3589 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3590 | if (use_json) | |
3591 | json_object_int_add( | |
3592 | json_interface_sub, | |
3593 | "networkLsaSequence", | |
3594 | ntohl(oi->params->network_lsa_seqnum)); | |
3595 | else | |
3596 | vty_out(vty, | |
3597 | " Saved Network-LSA sequence number 0x%x\n", | |
3598 | ntohl(oi->params->network_lsa_seqnum)); | |
3599 | } | |
3600 | ||
3601 | if (use_json) { | |
3602 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3603 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3604 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3605 | json_object_boolean_true_add( | |
3606 | json_interface_sub, | |
3607 | "mcastMemberOspfAllRouters"); | |
3608 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3609 | json_object_boolean_true_add( | |
3610 | json_interface_sub, | |
3611 | "mcastMemberOspfDesignatedRouters"); | |
3612 | } | |
3613 | } else { | |
3614 | vty_out(vty, " Multicast group memberships:"); | |
3615 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3616 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3617 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3618 | vty_out(vty, " OSPFAllRouters"); | |
3619 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3620 | vty_out(vty, " OSPFDesignatedRouters"); | |
3621 | } else | |
3622 | vty_out(vty, " <None>"); | |
3623 | vty_out(vty, "\n"); | |
3624 | } | |
3625 | ||
3626 | if (use_json) { | |
3627 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3628 | json_object_int_add( | |
3629 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3630 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3631 | else |
3632 | json_object_int_add( | |
3633 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3634 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3635 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3636 | "timerDeadSecs", |
3637 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3638 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3639 | "timerWaitSecs", |
3640 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3641 | json_object_int_add( |
50ad4b42 MS |
3642 | json_interface_sub, "timerRetransmitSecs", |
3643 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3644 | } else { |
3645 | vty_out(vty, " Timer intervals configured,"); | |
3646 | vty_out(vty, " Hello "); | |
3647 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3648 | vty_out(vty, "%ds,", | |
3649 | OSPF_IF_PARAM(oi, v_hello)); | |
3650 | else | |
3651 | vty_out(vty, "%dms,", | |
3652 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3653 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3654 | OSPF_IF_PARAM(oi, v_wait), | |
3655 | OSPF_IF_PARAM(oi, v_wait), | |
3656 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3657 | } | |
3658 | ||
3659 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3660 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3661 | if (use_json) { | |
3662 | long time_store = 0; | |
3663 | if (oi->t_hello) | |
3664 | time_store = | |
3665 | monotime_until( | |
3666 | &oi->t_hello->u.sands, | |
3667 | NULL) | |
3668 | / 1000LL; | |
3669 | json_object_int_add(json_interface_sub, | |
3670 | "timerHelloInMsecs", | |
3671 | time_store); | |
3672 | } else | |
3673 | vty_out(vty, " Hello due in %s\n", | |
3674 | ospf_timer_dump(oi->t_hello, timebuf, | |
3675 | sizeof(timebuf))); | |
3676 | } else /* passive-interface is set */ | |
3677 | { | |
3678 | if (use_json) | |
3679 | json_object_boolean_true_add( | |
3680 | json_interface_sub, | |
3681 | "timerPassiveIface"); | |
3682 | else | |
3683 | vty_out(vty, | |
3684 | " No Hellos (Passive interface)\n"); | |
3685 | } | |
7c8ff89e | 3686 | |
d62a17ae | 3687 | if (use_json) { |
3688 | json_object_int_add(json_interface_sub, "nbrCount", | |
3689 | ospf_nbr_count(oi, 0)); | |
3690 | json_object_int_add(json_interface_sub, | |
3691 | "nbrAdjacentCount", | |
3692 | ospf_nbr_count(oi, NSM_Full)); | |
3693 | } else | |
3694 | vty_out(vty, | |
3695 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3696 | ospf_nbr_count(oi, 0), | |
3697 | ospf_nbr_count(oi, NSM_Full)); | |
3698 | ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json); | |
3699 | } | |
718e3744 | 3700 | } |
3701 | ||
d62a17ae | 3702 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3703 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3704 | json_object *json, bool use_json) |
d62a17ae | 3705 | { |
3706 | struct interface *ifp; | |
f4e14fdb | 3707 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3708 | json_object *json_vrf = NULL; |
7dab10ce | 3709 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3710 | |
d62a17ae | 3711 | if (use_json) { |
b1c3ae8c CS |
3712 | if (use_vrf) |
3713 | json_vrf = json_object_new_object(); | |
3714 | else | |
3715 | json_vrf = json; | |
6282e124 | 3716 | json_interface = json_object_new_object(); |
d62a17ae | 3717 | } |
3718 | ||
3719 | if (ospf->instance) { | |
3720 | if (use_json) | |
3721 | json_object_int_add(json, "ospfInstance", | |
3722 | ospf->instance); | |
3723 | else | |
3724 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3725 | } | |
3726 | ||
b1c3ae8c CS |
3727 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3728 | ||
3729 | if (intf_name == NULL) { | |
d62a17ae | 3730 | /* Show All Interfaces.*/ |
451fda4f | 3731 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3732 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3733 | if (use_json) { |
d62a17ae | 3734 | json_interface_sub = |
3735 | json_object_new_object(); | |
7dab10ce | 3736 | } |
d62a17ae | 3737 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3738 | json_interface_sub, | |
3739 | use_json); | |
3740 | ||
7dab10ce | 3741 | if (use_json) { |
d62a17ae | 3742 | json_object_object_add( |
7dab10ce | 3743 | json_interface, ifp->name, |
d62a17ae | 3744 | json_interface_sub); |
7dab10ce | 3745 | } |
d62a17ae | 3746 | } |
3747 | } | |
6282e124 CS |
3748 | if (use_json) |
3749 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3750 | json_interface); |
d62a17ae | 3751 | } else { |
3752 | /* Interface name is specified. */ | |
a36898e7 | 3753 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3754 | if (ifp == NULL) { |
d62a17ae | 3755 | if (use_json) |
b1c3ae8c | 3756 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3757 | "noSuchIface"); |
3758 | else | |
3759 | vty_out(vty, "No such interface name\n"); | |
3760 | } else { | |
7dab10ce | 3761 | if (use_json) { |
d62a17ae | 3762 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3763 | json_interface = json_object_new_object(); |
7dab10ce | 3764 | } |
d62a17ae | 3765 | |
3766 | show_ip_ospf_interface_sub( | |
3767 | vty, ospf, ifp, json_interface_sub, use_json); | |
3768 | ||
7dab10ce | 3769 | if (use_json) { |
7dab10ce CS |
3770 | json_object_object_add(json_interface, |
3771 | ifp->name, | |
d62a17ae | 3772 | json_interface_sub); |
6282e124 CS |
3773 | json_object_object_add(json_vrf, "interfaces", |
3774 | json_interface); | |
7dab10ce | 3775 | } |
d62a17ae | 3776 | } |
3777 | } | |
3778 | ||
3779 | if (use_json) { | |
b1c3ae8c CS |
3780 | if (use_vrf) { |
3781 | if (ospf->vrf_id == VRF_DEFAULT) | |
3782 | json_object_object_add(json, "default", | |
3783 | json_vrf); | |
3784 | else | |
3785 | json_object_object_add(json, ospf->name, | |
3786 | json_vrf); | |
3787 | } | |
d62a17ae | 3788 | } else |
3789 | vty_out(vty, "\n"); | |
3790 | ||
3791 | return CMD_SUCCESS; | |
718e3744 | 3792 | } |
3793 | ||
c9339663 CS |
3794 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3795 | struct ospf_interface *oi, | |
3796 | json_object *json_interface_sub, | |
9f049418 | 3797 | bool use_json) |
c9339663 CS |
3798 | { |
3799 | if (use_json) { | |
996c9314 LB |
3800 | json_object_int_add(json_interface_sub, "ifIndex", |
3801 | oi->ifp->ifindex); | |
3802 | json_object_int_add(json_interface_sub, "helloIn", | |
3803 | oi->hello_in); | |
3804 | json_object_int_add(json_interface_sub, "helloOut", | |
3805 | oi->hello_out); | |
3806 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3807 | oi->db_desc_in); | |
3808 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3809 | oi->db_desc_out); | |
3810 | json_object_int_add(json_interface_sub, "lsReqIn", | |
3811 | oi->ls_req_in); | |
3812 | json_object_int_add(json_interface_sub, "lsReqOut", | |
3813 | oi->ls_req_out); | |
3814 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
3815 | oi->ls_upd_in); | |
3816 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
3817 | oi->ls_upd_out); | |
3818 | json_object_int_add(json_interface_sub, "lsAckIn", | |
3819 | oi->ls_ack_in); | |
3820 | json_object_int_add(json_interface_sub, "lsAckOut", | |
3821 | oi->ls_ack_out); | |
c9339663 CS |
3822 | } else { |
3823 | vty_out(vty, | |
3824 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
3825 | oi->ifp->name, oi->hello_in, oi->hello_out, |
3826 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
3827 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
3828 | oi->ls_ack_in, oi->ls_ack_out); |
3829 | } | |
3830 | } | |
3831 | ||
3832 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
3833 | static int show_ip_ospf_interface_traffic_common( |
3834 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 3835 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
3836 | { |
3837 | struct vrf *vrf = NULL; | |
3838 | struct interface *ifp = NULL; | |
b1c3ae8c | 3839 | json_object *json_vrf = NULL; |
c9339663 CS |
3840 | json_object *json_interface_sub = NULL; |
3841 | ||
3842 | if (!use_json && !display_once) { | |
3843 | vty_out(vty, "\n"); | |
996c9314 LB |
3844 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
3845 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
3846 | " LS-Ack"); | |
c9339663 | 3847 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
3848 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
3849 | " Rx/Tx"); | |
c9339663 | 3850 | vty_out(vty, |
996c9314 | 3851 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 3852 | } else if (use_json) { |
b1c3ae8c CS |
3853 | if (use_vrf) |
3854 | json_vrf = json_object_new_object(); | |
3855 | else | |
3856 | json_vrf = json; | |
c9339663 CS |
3857 | } |
3858 | ||
b1c3ae8c CS |
3859 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3860 | ||
c9339663 CS |
3861 | if (intf_name == NULL) { |
3862 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
3863 | FOR_ALL_INTERFACES (vrf, ifp) { | |
3864 | struct route_node *rn; | |
3865 | struct ospf_interface *oi; | |
3866 | ||
3867 | if (ospf_oi_count(ifp) == 0) | |
3868 | continue; | |
3869 | ||
3870 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 3871 | rn = route_next(rn)) { |
c9339663 CS |
3872 | oi = rn->info; |
3873 | ||
3874 | if (oi == NULL) | |
3875 | continue; | |
3876 | ||
3877 | if (use_json) { | |
3878 | json_interface_sub = | |
3879 | json_object_new_object(); | |
3880 | } | |
3881 | ||
996c9314 LB |
3882 | show_ip_ospf_interface_traffic_sub( |
3883 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 3884 | if (use_json) { |
996c9314 LB |
3885 | json_object_object_add( |
3886 | json_vrf, ifp->name, | |
3887 | json_interface_sub); | |
c9339663 CS |
3888 | } |
3889 | } | |
3890 | } | |
3891 | } else { | |
3892 | /* Interface name is specified. */ | |
a36898e7 | 3893 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
3894 | if (ifp != NULL) { |
3895 | struct route_node *rn; | |
3896 | struct ospf_interface *oi; | |
3897 | ||
3898 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
3899 | vty_out(vty, |
3900 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
3901 | ifp->name); |
3902 | return CMD_SUCCESS; | |
3903 | } | |
3904 | ||
3905 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3906 | rn = route_next(rn)) { | |
3907 | oi = rn->info; | |
3908 | ||
3909 | if (use_json) { | |
3910 | json_interface_sub = | |
3911 | json_object_new_object(); | |
3912 | } | |
3913 | ||
996c9314 LB |
3914 | show_ip_ospf_interface_traffic_sub( |
3915 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 3916 | if (use_json) { |
996c9314 LB |
3917 | json_object_object_add( |
3918 | json_vrf, ifp->name, | |
3919 | json_interface_sub); | |
c9339663 CS |
3920 | } |
3921 | } | |
3922 | } | |
3923 | } | |
3924 | ||
3925 | if (use_json) { | |
b1c3ae8c CS |
3926 | if (use_vrf) { |
3927 | if (ospf->vrf_id == VRF_DEFAULT) | |
3928 | json_object_object_add(json, "default", | |
3929 | json_vrf); | |
3930 | else | |
3931 | json_object_object_add(json, ospf->name, | |
3932 | json_vrf); | |
3933 | } | |
3934 | } else | |
3935 | vty_out(vty, "\n"); | |
c9339663 CS |
3936 | |
3937 | return CMD_SUCCESS; | |
3938 | } | |
3939 | ||
7c8ff89e DS |
3940 | DEFUN (show_ip_ospf_interface, |
3941 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 3942 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
3943 | SHOW_STR |
3944 | IP_STR | |
3945 | "OSPF information\n" | |
b5a8894d | 3946 | VRF_CMD_HELP_STR |
43b8d1d8 | 3947 | "All VRFs\n" |
7c8ff89e | 3948 | "Interface information\n" |
7ec4159b | 3949 | "Interface name\n" |
9973d184 | 3950 | JSON_STR) |
7c8ff89e | 3951 | { |
d62a17ae | 3952 | struct ospf *ospf; |
9f049418 | 3953 | bool uj = use_json(argc, argv); |
b5a8894d | 3954 | struct listnode *node = NULL; |
b1c3ae8c | 3955 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 3956 | bool all_vrf = false; |
b5a8894d CS |
3957 | int ret = CMD_SUCCESS; |
3958 | int inst = 0; | |
b1c3ae8c | 3959 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 3960 | uint8_t use_vrf = 0; |
b1c3ae8c | 3961 | json_object *json = NULL; |
7c8ff89e | 3962 | |
43b8d1d8 CS |
3963 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
3964 | ||
b1c3ae8c CS |
3965 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
3966 | intf_name = argv[idx_intf]->arg; | |
3967 | ||
d62a17ae | 3968 | if (uj) |
b1c3ae8c | 3969 | json = json_object_new_object(); |
6be4da3d | 3970 | |
b5a8894d CS |
3971 | /* vrf input is provided could be all or specific vrf*/ |
3972 | if (vrf_name) { | |
b1c3ae8c | 3973 | use_vrf = 1; |
b5a8894d CS |
3974 | if (all_vrf) { |
3975 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3976 | if (!ospf->oi_running) | |
3977 | continue; | |
996c9314 LB |
3978 | ret = show_ip_ospf_interface_common( |
3979 | vty, ospf, intf_name, use_vrf, json, | |
3980 | uj); | |
b5a8894d | 3981 | } |
b1c3ae8c CS |
3982 | |
3983 | if (uj) { | |
3984 | vty_out(vty, "%s\n", | |
996c9314 LB |
3985 | json_object_to_json_string_ext( |
3986 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3987 | json_object_free(json); |
9f049418 | 3988 | } else if (!ospf) |
94d4c685 | 3989 | vty_out(vty, "%% OSPF instance not found\n"); |
b1c3ae8c | 3990 | |
b5a8894d CS |
3991 | return ret; |
3992 | } | |
3993 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3994 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3995 | if (uj) { |
3996 | vty_out(vty, "%s\n", | |
3997 | json_object_to_json_string_ext( | |
3998 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3999 | json_object_free(json); |
9f049418 | 4000 | } else |
94d4c685 | 4001 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4002 | |
b5a8894d | 4003 | return CMD_SUCCESS; |
b1c3ae8c CS |
4004 | } |
4005 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4006 | use_vrf, json, uj); | |
b5a8894d CS |
4007 | |
4008 | } else { | |
4009 | /* Display default ospf (instance 0) info */ | |
4010 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4011 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4012 | if (uj) { |
4013 | vty_out(vty, "%s\n", | |
4014 | json_object_to_json_string_ext( | |
4015 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4016 | json_object_free(json); |
9f049418 | 4017 | } else |
94d4c685 | 4018 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4019 | |
b5a8894d | 4020 | return CMD_SUCCESS; |
b1c3ae8c CS |
4021 | } |
4022 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4023 | use_vrf, json, uj); | |
4024 | } | |
4025 | ||
4026 | if (uj) { | |
996c9314 LB |
4027 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4028 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4029 | json_object_free(json); |
b5a8894d CS |
4030 | } |
4031 | ||
4032 | return ret; | |
7c8ff89e DS |
4033 | } |
4034 | ||
4035 | DEFUN (show_ip_ospf_instance_interface, | |
4036 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4037 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4038 | SHOW_STR |
4039 | IP_STR | |
4040 | "OSPF information\n" | |
4041 | "Instance ID\n" | |
4042 | "Interface information\n" | |
7ec4159b | 4043 | "Interface name\n" |
9973d184 | 4044 | JSON_STR) |
7c8ff89e | 4045 | { |
d62a17ae | 4046 | int idx_number = 3; |
b1c3ae8c | 4047 | int idx_intf = 0; |
d62a17ae | 4048 | struct ospf *ospf; |
d7c0a89a | 4049 | unsigned short instance = 0; |
9f049418 | 4050 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4051 | char *intf_name = NULL; |
4052 | int ret = CMD_SUCCESS; | |
4053 | json_object *json = NULL; | |
d62a17ae | 4054 | |
4055 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
4056 | ospf = ospf_lookup_instance(instance); |
4057 | if (ospf == NULL) | |
4058 | return CMD_NOT_MY_INSTANCE; | |
4059 | ||
4060 | if (!ospf->oi_running) | |
d62a17ae | 4061 | return CMD_SUCCESS; |
4062 | ||
4063 | if (uj) | |
b1c3ae8c CS |
4064 | json = json_object_new_object(); |
4065 | ||
4066 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4067 | intf_name = argv[idx_intf]->arg; | |
4068 | ||
4069 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4070 | ||
4071 | if (uj) { | |
996c9314 LB |
4072 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4073 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4074 | json_object_free(json); |
4075 | } | |
d62a17ae | 4076 | |
b1c3ae8c | 4077 | return ret; |
d62a17ae | 4078 | } |
4079 | ||
c9339663 CS |
4080 | DEFUN (show_ip_ospf_interface_traffic, |
4081 | show_ip_ospf_interface_traffic_cmd, | |
4082 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4083 | SHOW_STR | |
4084 | IP_STR | |
4085 | "OSPF information\n" | |
4086 | VRF_CMD_HELP_STR | |
4087 | "All VRFs\n" | |
4088 | "Interface information\n" | |
4089 | "Protocol Packet counters\n" | |
4090 | "Interface name\n" | |
4091 | JSON_STR) | |
4092 | { | |
4093 | struct ospf *ospf = NULL; | |
4094 | struct listnode *node = NULL; | |
4095 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4096 | bool all_vrf = false; |
c9339663 CS |
4097 | int inst = 0; |
4098 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4099 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4100 | json_object *json = NULL; |
c9339663 CS |
4101 | int ret = CMD_SUCCESS; |
4102 | int display_once = 0; | |
d7c0a89a | 4103 | uint8_t use_vrf = 0; |
c9339663 CS |
4104 | |
4105 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4106 | ||
4107 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4108 | intf_name = argv[idx_intf]->arg; | |
4109 | ||
b1c3ae8c CS |
4110 | if (uj) |
4111 | json = json_object_new_object(); | |
4112 | ||
c9339663 | 4113 | if (vrf_name) { |
b1c3ae8c | 4114 | use_vrf = 1; |
c9339663 CS |
4115 | if (all_vrf) { |
4116 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4117 | if (!ospf->oi_running) | |
4118 | continue; | |
4119 | ||
996c9314 LB |
4120 | ret = show_ip_ospf_interface_traffic_common( |
4121 | vty, ospf, intf_name, json, | |
4122 | display_once, use_vrf, uj); | |
c9339663 CS |
4123 | display_once = 1; |
4124 | } | |
b1c3ae8c CS |
4125 | |
4126 | if (uj) { | |
4127 | vty_out(vty, "%s\n", | |
996c9314 LB |
4128 | json_object_to_json_string_ext( |
4129 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4130 | json_object_free(json); |
4131 | } | |
4132 | ||
c9339663 CS |
4133 | return ret; |
4134 | } | |
4135 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4136 | if (ospf == NULL || !ospf->oi_running) { |
4137 | if (uj) | |
4138 | json_object_free(json); | |
c9339663 | 4139 | return CMD_SUCCESS; |
b1c3ae8c CS |
4140 | } |
4141 | ||
996c9314 LB |
4142 | ret = show_ip_ospf_interface_traffic_common( |
4143 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4144 | } else { |
4145 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4146 | if (ospf == NULL || !ospf->oi_running) { |
4147 | if (uj) | |
4148 | json_object_free(json); | |
c9339663 | 4149 | return CMD_SUCCESS; |
b1c3ae8c CS |
4150 | } |
4151 | ||
996c9314 LB |
4152 | ret = show_ip_ospf_interface_traffic_common( |
4153 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4154 | } |
4155 | ||
4156 | if (uj) { | |
996c9314 LB |
4157 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4158 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4159 | json_object_free(json); |
c9339663 CS |
4160 | } |
4161 | ||
4162 | return ret; | |
4163 | } | |
4164 | ||
4165 | ||
d62a17ae | 4166 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4167 | { | |
c84355a9 | 4168 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n", |
d62a17ae | 4169 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", |
4170 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4171 | } | |
4172 | ||
4173 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4174 | struct ospf_interface *oi, | |
9f049418 | 4175 | json_object *json, bool use_json) |
d62a17ae | 4176 | { |
4177 | struct route_node *rn; | |
cef262c3 | 4178 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4179 | char msgbuf[16]; |
4180 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cef262c3 | 4181 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4182 | |
4183 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4184 | if ((nbr = rn->info)) { | |
4185 | /* Do not show myself. */ | |
cef262c3 CS |
4186 | if (nbr == oi->nbr_self) |
4187 | continue; | |
4188 | /* Down state is not shown. */ | |
4189 | if (nbr->state == NSM_Down) | |
4190 | continue; | |
4191 | if (use_json) { | |
4192 | char neigh_str[INET_ADDRSTRLEN]; | |
4193 | ||
996c9314 LB |
4194 | if (prev_nbr |
4195 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4196 | &nbr->src)) { | |
cef262c3 CS |
4197 | /* Start new neigh list */ |
4198 | json_neigh_array = NULL; | |
4199 | } | |
4200 | ||
996c9314 | 4201 | if (nbr->state == NSM_Attempt |
975a328e | 4202 | && nbr->router_id.s_addr == INADDR_ANY) |
6021c6c0 CS |
4203 | strlcpy(neigh_str, "neighbor", |
4204 | sizeof(neigh_str)); | |
cef262c3 | 4205 | else |
6021c6c0 | 4206 | strlcpy(neigh_str, |
cef262c3 | 4207 | inet_ntoa(nbr->router_id), |
6021c6c0 | 4208 | sizeof(neigh_str)); |
cef262c3 CS |
4209 | |
4210 | json_object_object_get_ex(json, neigh_str, | |
4211 | &json_neigh_array); | |
4212 | ||
4213 | if (!json_neigh_array) { | |
996c9314 LB |
4214 | json_neigh_array = |
4215 | json_object_new_array(); | |
4216 | json_object_object_add( | |
4217 | json, neigh_str, | |
4218 | json_neigh_array); | |
d62a17ae | 4219 | } |
cef262c3 | 4220 | |
996c9314 | 4221 | json_neighbor = json_object_new_object(); |
cef262c3 CS |
4222 | |
4223 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4224 | ||
4225 | long time_store; | |
4226 | ||
996c9314 LB |
4227 | time_store = |
4228 | monotime_until( | |
cef262c3 | 4229 | &nbr->t_inactivity->u.sands, |
996c9314 LB |
4230 | NULL) |
4231 | / 1000LL; | |
cef262c3 | 4232 | |
996c9314 | 4233 | json_object_int_add(json_neighbor, "priority", |
cef262c3 CS |
4234 | nbr->priority); |
4235 | json_object_string_add(json_neighbor, "state", | |
4236 | msgbuf); | |
4237 | json_object_int_add(json_neighbor, | |
4238 | "deadTimeMsecs", | |
4239 | time_store); | |
996c9314 | 4240 | json_object_string_add(json_neighbor, "address", |
cef262c3 CS |
4241 | inet_ntoa(nbr->src)); |
4242 | json_object_string_add(json_neighbor, | |
4243 | "ifaceName", | |
4244 | IF_NAME(oi)); | |
996c9314 LB |
4245 | json_object_int_add( |
4246 | json_neighbor, "retransmitCounter", | |
4247 | ospf_ls_retransmit_count(nbr)); | |
cef262c3 | 4248 | json_object_int_add(json_neighbor, |
996c9314 LB |
4249 | "requestCounter", |
4250 | ospf_ls_request_count(nbr)); | |
cef262c3 | 4251 | json_object_int_add(json_neighbor, |
996c9314 LB |
4252 | "dbSummaryCounter", |
4253 | ospf_db_summary_count(nbr)); | |
cef262c3 CS |
4254 | |
4255 | json_object_array_add(json_neigh_array, | |
4256 | json_neighbor); | |
4257 | } else { | |
4258 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4259 | ||
996c9314 | 4260 | if (nbr->state == NSM_Attempt |
975a328e | 4261 | && nbr->router_id.s_addr == INADDR_ANY) |
996c9314 LB |
4262 | vty_out(vty, "%-15s %3d %-15s ", "-", |
4263 | nbr->priority, msgbuf); | |
cef262c3 | 4264 | else |
996c9314 | 4265 | vty_out(vty, "%-15s %3d %-15s ", |
cef262c3 | 4266 | inet_ntoa(nbr->router_id), |
996c9314 | 4267 | nbr->priority, msgbuf); |
cef262c3 CS |
4268 | |
4269 | vty_out(vty, "%9s ", | |
4270 | ospf_timer_dump(nbr->t_inactivity, | |
4271 | timebuf, | |
4272 | sizeof(timebuf))); | |
4273 | vty_out(vty, "%-15s ", inet_ntoa(nbr->src)); | |
c84355a9 | 4274 | vty_out(vty, "%-32s %5ld %5ld %5d\n", |
cef262c3 CS |
4275 | IF_NAME(oi), |
4276 | ospf_ls_retransmit_count(nbr), | |
4277 | ospf_ls_request_count(nbr), | |
4278 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4279 | } |
cef262c3 | 4280 | prev_nbr = nbr; |
d62a17ae | 4281 | } |
4282 | } | |
4283 | } | |
4284 | ||
4285 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4286 | json_object *json, bool use_json, |
d7c0a89a | 4287 | uint8_t use_vrf) |
d62a17ae | 4288 | { |
4289 | struct ospf_interface *oi; | |
4290 | struct listnode *node; | |
6282e124 | 4291 | json_object *json_vrf = NULL; |
2bc7673f | 4292 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4293 | |
b1c3ae8c CS |
4294 | if (use_json) { |
4295 | if (use_vrf) | |
4296 | json_vrf = json_object_new_object(); | |
4297 | else | |
4298 | json_vrf = json; | |
6282e124 | 4299 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4300 | } |
d62a17ae | 4301 | |
4302 | if (ospf->instance) { | |
4303 | if (use_json) | |
4304 | json_object_int_add(json, "ospfInstance", | |
4305 | ospf->instance); | |
4306 | else | |
4307 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4308 | } | |
7c8ff89e | 4309 | |
b1c3ae8c CS |
4310 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4311 | if (!use_json) | |
4312 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4313 | |
2bc7673f CS |
4314 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4315 | if (ospf_interface_neighbor_count(oi) == 0) | |
4316 | continue; | |
2bc7673f CS |
4317 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4318 | } | |
718e3744 | 4319 | |
d62a17ae | 4320 | if (use_json) { |
996c9314 | 4321 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
b1c3ae8c CS |
4322 | if (use_vrf) { |
4323 | if (ospf->vrf_id == VRF_DEFAULT) | |
4324 | json_object_object_add(json, "default", | |
4325 | json_vrf); | |
4326 | else | |
4327 | json_object_object_add(json, ospf->name, | |
4328 | json_vrf); | |
4329 | } | |
d62a17ae | 4330 | } else |
4331 | vty_out(vty, "\n"); | |
7c8ff89e | 4332 | |
d62a17ae | 4333 | return CMD_SUCCESS; |
718e3744 | 4334 | } |
4335 | ||
7c8ff89e DS |
4336 | DEFUN (show_ip_ospf_neighbor, |
4337 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4338 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4339 | SHOW_STR |
4340 | IP_STR | |
4341 | "OSPF information\n" | |
b5a8894d CS |
4342 | VRF_CMD_HELP_STR |
4343 | "All VRFs\n" | |
91756b38 | 4344 | "Neighbor list\n" |
9973d184 | 4345 | JSON_STR) |
718e3744 | 4346 | { |
d62a17ae | 4347 | struct ospf *ospf; |
9f049418 | 4348 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4349 | struct listnode *node = NULL; |
4350 | char *vrf_name = NULL; | |
2951a7a4 | 4351 | bool all_vrf = false; |
b5a8894d CS |
4352 | int ret = CMD_SUCCESS; |
4353 | int inst = 0; | |
4354 | int idx_vrf = 0; | |
d7c0a89a | 4355 | uint8_t use_vrf = 0; |
b1c3ae8c | 4356 | json_object *json = NULL; |
718e3744 | 4357 | |
43b8d1d8 | 4358 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4359 | |
b1c3ae8c CS |
4360 | if (uj) |
4361 | json = json_object_new_object(); | |
b5a8894d CS |
4362 | |
4363 | /* vrf input is provided could be all or specific vrf*/ | |
4364 | if (vrf_name) { | |
b1c3ae8c | 4365 | use_vrf = 1; |
b5a8894d CS |
4366 | if (all_vrf) { |
4367 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4368 | if (!ospf->oi_running) | |
4369 | continue; | |
996c9314 LB |
4370 | ret = show_ip_ospf_neighbor_common( |
4371 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4372 | } |
4373 | ||
4374 | if (uj) { | |
4375 | vty_out(vty, "%s\n", | |
996c9314 LB |
4376 | json_object_to_json_string_ext( |
4377 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4378 | json_object_free(json); |
9f049418 DS |
4379 | } else if (!ospf) |
4380 | vty_out(vty, "OSPF instance not found\n"); | |
b1c3ae8c | 4381 | |
b5a8894d CS |
4382 | return ret; |
4383 | } | |
b1c3ae8c | 4384 | |
b5a8894d | 4385 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4386 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4387 | if (uj) { |
4388 | vty_out(vty, "%s\n", | |
4389 | json_object_to_json_string_ext( | |
4390 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4391 | json_object_free(json); |
9f049418 DS |
4392 | } else |
4393 | vty_out(vty, "%% OSPF instance not found\n"); | |
4394 | ||
b5a8894d | 4395 | return CMD_SUCCESS; |
b1c3ae8c | 4396 | } |
b5a8894d CS |
4397 | } else { |
4398 | /* Display default ospf (instance 0) info */ | |
4399 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4400 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4401 | if (uj) { |
4402 | vty_out(vty, "%s\n", | |
4403 | json_object_to_json_string_ext( | |
4404 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4405 | json_object_free(json); |
9f049418 DS |
4406 | } else |
4407 | vty_out(vty, "%% OSPF instance not found\n"); | |
4408 | ||
b5a8894d | 4409 | return CMD_SUCCESS; |
b1c3ae8c | 4410 | } |
b5a8894d CS |
4411 | } |
4412 | ||
b1c3ae8c CS |
4413 | if (ospf) { |
4414 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4415 | use_vrf); | |
4416 | ||
4417 | if (uj) { | |
4418 | vty_out(vty, "%s\n", | |
996c9314 LB |
4419 | json_object_to_json_string_ext( |
4420 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4421 | } |
4422 | } | |
4423 | ||
4424 | if (uj) | |
4425 | json_object_free(json); | |
b5a8894d CS |
4426 | |
4427 | return ret; | |
7c8ff89e DS |
4428 | } |
4429 | ||
4430 | ||
4431 | DEFUN (show_ip_ospf_instance_neighbor, | |
4432 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4433 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4434 | SHOW_STR |
4435 | IP_STR | |
4436 | "OSPF information\n" | |
4437 | "Instance ID\n" | |
91756b38 | 4438 | "Neighbor list\n" |
9973d184 | 4439 | JSON_STR) |
7c8ff89e | 4440 | { |
d62a17ae | 4441 | int idx_number = 3; |
4442 | struct ospf *ospf; | |
d7c0a89a | 4443 | unsigned short instance = 0; |
9f049418 | 4444 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4445 | json_object *json = NULL; |
4446 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4447 | |
d62a17ae | 4448 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4449 | ospf = ospf_lookup_instance(instance); |
4450 | if (ospf == NULL) | |
4451 | return CMD_NOT_MY_INSTANCE; | |
4452 | ||
4453 | if (!ospf->oi_running) | |
d62a17ae | 4454 | return CMD_SUCCESS; |
7c8ff89e | 4455 | |
b1c3ae8c CS |
4456 | if (uj) |
4457 | json = json_object_new_object(); | |
b5a8894d | 4458 | |
b1c3ae8c CS |
4459 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4460 | ||
4461 | if (uj) { | |
996c9314 LB |
4462 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4463 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4464 | json_object_free(json); |
4465 | } | |
4466 | ||
4467 | return ret; | |
7c8ff89e DS |
4468 | } |
4469 | ||
d62a17ae | 4470 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4471 | json_object *json, bool use_json, |
d7c0a89a | 4472 | uint8_t use_vrf) |
d62a17ae | 4473 | { |
4474 | struct listnode *node; | |
4475 | struct ospf_interface *oi; | |
b1c3ae8c | 4476 | json_object *json_vrf = NULL; |
d62a17ae | 4477 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4478 | |
d62a17ae | 4479 | if (use_json) { |
b1c3ae8c CS |
4480 | if (use_vrf) |
4481 | json_vrf = json_object_new_object(); | |
4482 | else | |
4483 | json_vrf = json; | |
d62a17ae | 4484 | json_neighbor_sub = json_object_new_object(); |
b5a8894d | 4485 | } |
d62a17ae | 4486 | |
b1c3ae8c CS |
4487 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4488 | if (!use_json) | |
4489 | show_ip_ospf_neighbour_header(vty); | |
4490 | ||
d62a17ae | 4491 | if (ospf->instance) { |
4492 | if (use_json) | |
b1c3ae8c | 4493 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4494 | ospf->instance); |
4495 | else | |
4496 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4497 | } | |
4498 | ||
4499 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4500 | struct listnode *nbr_node; | |
4501 | struct ospf_nbr_nbma *nbr_nbma; | |
4502 | ||
b1c3ae8c | 4503 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4504 | |
4505 | /* print Down neighbor status */ | |
4506 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4507 | if (nbr_nbma->nbr == NULL | |
4508 | || nbr_nbma->nbr->state == NSM_Down) { | |
4509 | if (use_json) { | |
4510 | json_object_int_add(json_neighbor_sub, | |
4511 | "nbrNbmaPriority", | |
4512 | nbr_nbma->priority); | |
4513 | json_object_boolean_true_add( | |
4514 | json_neighbor_sub, | |
4515 | "nbrNbmaDown"); | |
4516 | json_object_string_add( | |
4517 | json_neighbor_sub, | |
4518 | "nbrNbmaIfaceName", | |
4519 | IF_NAME(oi)); | |
4520 | json_object_int_add( | |
4521 | json_neighbor_sub, | |
4522 | "nbrNbmaRetransmitCounter", 0); | |
4523 | json_object_int_add( | |
4524 | json_neighbor_sub, | |
4525 | "nbrNbmaRequestCounter", 0); | |
4526 | json_object_int_add( | |
4527 | json_neighbor_sub, | |
4528 | "nbrNbmaDbSummaryCounter", 0); | |
4529 | json_object_object_add( | |
b1c3ae8c CS |
4530 | json_vrf, |
4531 | inet_ntoa(nbr_nbma->addr), | |
d62a17ae | 4532 | json_neighbor_sub); |
4533 | } else { | |
4534 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4535 | "-", nbr_nbma->priority, "Down", | |
4536 | "-"); | |
4537 | vty_out(vty, | |
c84355a9 | 4538 | "%-32s %-20s %5d %5d %5d\n", |
d62a17ae | 4539 | inet_ntoa(nbr_nbma->addr), |
4540 | IF_NAME(oi), 0, 0, 0); | |
4541 | } | |
4542 | } | |
4543 | } | |
4544 | } | |
4545 | ||
4546 | if (use_json) { | |
b1c3ae8c CS |
4547 | if (use_vrf) { |
4548 | if (ospf->vrf_id == VRF_DEFAULT) | |
4549 | json_object_object_add(json, "default", | |
4550 | json_vrf); | |
4551 | else | |
4552 | json_object_object_add(json, ospf->name, | |
4553 | json_vrf); | |
4554 | } | |
d62a17ae | 4555 | } else |
4556 | vty_out(vty, "\n"); | |
4557 | ||
4558 | return CMD_SUCCESS; | |
718e3744 | 4559 | } |
4560 | ||
7c8ff89e DS |
4561 | DEFUN (show_ip_ospf_neighbor_all, |
4562 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4563 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4564 | SHOW_STR |
4565 | IP_STR | |
4566 | "OSPF information\n" | |
b5a8894d CS |
4567 | VRF_CMD_HELP_STR |
4568 | "All VRFs\n" | |
718e3744 | 4569 | "Neighbor list\n" |
91756b38 | 4570 | "include down status neighbor\n" |
9973d184 | 4571 | JSON_STR) |
7c8ff89e | 4572 | { |
d62a17ae | 4573 | struct ospf *ospf; |
9f049418 | 4574 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4575 | struct listnode *node = NULL; |
4576 | char *vrf_name = NULL; | |
2951a7a4 | 4577 | bool all_vrf = false; |
b5a8894d CS |
4578 | int ret = CMD_SUCCESS; |
4579 | int inst = 0; | |
4580 | int idx_vrf = 0; | |
d7c0a89a | 4581 | uint8_t use_vrf = 0; |
b1c3ae8c | 4582 | json_object *json = NULL; |
7c8ff89e | 4583 | |
43b8d1d8 | 4584 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4585 | |
b1c3ae8c CS |
4586 | if (uj) |
4587 | json = json_object_new_object(); | |
b5a8894d CS |
4588 | |
4589 | /* vrf input is provided could be all or specific vrf*/ | |
4590 | if (vrf_name) { | |
b1c3ae8c | 4591 | use_vrf = 1; |
b5a8894d CS |
4592 | if (all_vrf) { |
4593 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4594 | if (!ospf->oi_running) | |
4595 | continue; | |
996c9314 LB |
4596 | ret = show_ip_ospf_neighbor_all_common( |
4597 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4598 | } |
4599 | ||
4600 | if (uj) { | |
4601 | vty_out(vty, "%s\n", | |
996c9314 LB |
4602 | json_object_to_json_string_ext( |
4603 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4604 | json_object_free(json); |
b5a8894d | 4605 | } |
b1c3ae8c | 4606 | |
b5a8894d CS |
4607 | return ret; |
4608 | } | |
b1c3ae8c | 4609 | |
b5a8894d | 4610 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4611 | if (ospf == NULL || !ospf->oi_running) { |
4612 | if (uj) | |
4613 | json_object_free(json); | |
b5a8894d | 4614 | return CMD_SUCCESS; |
b1c3ae8c | 4615 | } |
b5a8894d CS |
4616 | } else { |
4617 | /* Display default ospf (instance 0) info */ | |
4618 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4619 | if (ospf == NULL || !ospf->oi_running) { |
4620 | if (uj) | |
4621 | json_object_free(json); | |
b5a8894d | 4622 | return CMD_SUCCESS; |
b1c3ae8c | 4623 | } |
b5a8894d CS |
4624 | } |
4625 | ||
b1c3ae8c CS |
4626 | if (ospf) { |
4627 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4628 | use_vrf); | |
4629 | if (uj) { | |
4630 | vty_out(vty, "%s\n", | |
996c9314 LB |
4631 | json_object_to_json_string_ext( |
4632 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4633 | } |
4634 | } | |
4635 | ||
4636 | if (uj) | |
4637 | json_object_free(json); | |
b5a8894d CS |
4638 | |
4639 | return ret; | |
7c8ff89e DS |
4640 | } |
4641 | ||
4642 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4643 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4644 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4645 | SHOW_STR |
4646 | IP_STR | |
4647 | "OSPF information\n" | |
4648 | "Instance ID\n" | |
4649 | "Neighbor list\n" | |
91756b38 | 4650 | "include down status neighbor\n" |
9973d184 | 4651 | JSON_STR) |
718e3744 | 4652 | { |
d62a17ae | 4653 | int idx_number = 3; |
4654 | struct ospf *ospf; | |
d7c0a89a | 4655 | unsigned short instance = 0; |
9f049418 | 4656 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4657 | json_object *json = NULL; |
4658 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4659 | |
d62a17ae | 4660 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4661 | ospf = ospf_lookup_instance(instance); |
4662 | if (ospf == NULL) | |
4663 | return CMD_NOT_MY_INSTANCE; | |
4664 | ||
4665 | if (!ospf->oi_running) | |
d62a17ae | 4666 | return CMD_SUCCESS; |
b1c3ae8c CS |
4667 | if (uj) |
4668 | json = json_object_new_object(); | |
4669 | ||
4670 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4671 | ||
4672 | if (uj) { | |
4673 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4674 | json, JSON_C_TO_STRING_PRETTY)); | |
4675 | json_object_free(json); | |
4676 | } | |
7c8ff89e | 4677 | |
b1c3ae8c | 4678 | return ret; |
7c8ff89e DS |
4679 | } |
4680 | ||
d62a17ae | 4681 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4682 | int arg_base, | |
4683 | struct cmd_token **argv, | |
9f049418 | 4684 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4685 | { |
4686 | struct interface *ifp; | |
4687 | struct route_node *rn; | |
4688 | json_object *json = NULL; | |
91756b38 | 4689 | |
d62a17ae | 4690 | if (use_json) |
4691 | json = json_object_new_object(); | |
d62a17ae | 4692 | |
4693 | if (ospf->instance) { | |
4694 | if (use_json) | |
4695 | json_object_int_add(json, "ospfInstance", | |
4696 | ospf->instance); | |
4697 | else | |
4698 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4699 | } | |
4700 | ||
b1c3ae8c | 4701 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4702 | |
a36898e7 | 4703 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4704 | if (!ifp) { |
4705 | if (use_json) | |
4706 | json_object_boolean_true_add(json, "noSuchIface"); | |
4707 | else | |
4708 | vty_out(vty, "No such interface.\n"); | |
4709 | return CMD_WARNING; | |
4710 | } | |
4711 | ||
4712 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4713 | struct ospf_interface *oi = rn->info; | |
4714 | ||
4715 | if (oi == NULL) | |
4716 | continue; | |
4717 | ||
4718 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4719 | } | |
4720 | ||
4721 | if (use_json) { | |
9d303b37 DL |
4722 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4723 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4724 | json_object_free(json); |
4725 | } else | |
4726 | vty_out(vty, "\n"); | |
4727 | ||
4728 | return CMD_SUCCESS; | |
718e3744 | 4729 | } |
4730 | ||
7c8ff89e DS |
4731 | DEFUN (show_ip_ospf_neighbor_int, |
4732 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4733 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4734 | SHOW_STR |
4735 | IP_STR | |
4736 | "OSPF information\n" | |
03ed9f02 | 4737 | VRF_CMD_HELP_STR |
7c8ff89e | 4738 | "Neighbor list\n" |
91756b38 | 4739 | "Interface name\n" |
9973d184 | 4740 | JSON_STR) |
7c8ff89e | 4741 | { |
d62a17ae | 4742 | struct ospf *ospf; |
03ed9f02 PG |
4743 | int idx_ifname = 0; |
4744 | int idx_vrf = 0; | |
9f049418 | 4745 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4746 | int ret = CMD_SUCCESS; |
4747 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4748 | char *vrf_name = NULL; |
4749 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4750 | struct vrf *vrf = NULL; | |
4751 | ||
4752 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4753 | vrf_name = argv[idx_vrf + 1]->arg; | |
4754 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4755 | vrf_name = NULL; | |
4756 | if (vrf_name) { | |
4757 | vrf = vrf_lookup_by_name(vrf_name); | |
4758 | if (vrf) | |
4759 | vrf_id = vrf->vrf_id; | |
4760 | } | |
4761 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4762 | ||
4763 | if (!ospf || !ospf->oi_running) | |
4764 | return ret; | |
7c8ff89e | 4765 | |
b5a8894d CS |
4766 | if (!uj) |
4767 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4768 | |
03ed9f02 | 4769 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4770 | |
a36898e7 | 4771 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4772 | if (!ifp) |
4773 | return ret; | |
4774 | ||
4775 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4776 | argv, uj, 0); | |
b5a8894d | 4777 | return ret; |
7c8ff89e DS |
4778 | } |
4779 | ||
4780 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4781 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4782 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4783 | SHOW_STR |
4784 | IP_STR | |
4785 | "OSPF information\n" | |
4786 | "Instance ID\n" | |
4787 | "Neighbor list\n" | |
91756b38 | 4788 | "Interface name\n" |
9973d184 | 4789 | JSON_STR) |
7c8ff89e | 4790 | { |
d62a17ae | 4791 | int idx_number = 3; |
b4e84315 | 4792 | int idx_ifname = 5; |
d62a17ae | 4793 | struct ospf *ospf; |
d7c0a89a | 4794 | unsigned short instance = 0; |
9f049418 | 4795 | bool uj = use_json(argc, argv); |
7c8ff89e | 4796 | |
b5a8894d CS |
4797 | if (!uj) |
4798 | show_ip_ospf_neighbour_header(vty); | |
4799 | ||
d62a17ae | 4800 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4801 | ospf = ospf_lookup_instance(instance); |
4802 | if (ospf == NULL) | |
4803 | return CMD_NOT_MY_INSTANCE; | |
4804 | ||
4805 | if (!ospf->oi_running) | |
d62a17ae | 4806 | return CMD_SUCCESS; |
7c8ff89e | 4807 | |
b5a8894d CS |
4808 | if (!uj) |
4809 | show_ip_ospf_neighbour_header(vty); | |
4810 | ||
996c9314 LB |
4811 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
4812 | 0); | |
718e3744 | 4813 | } |
4814 | ||
d62a17ae | 4815 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
4816 | struct ospf_interface *oi, | |
4817 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 4818 | bool use_json, json_object *json) |
d62a17ae | 4819 | { |
4820 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4821 | json_object *json_sub = NULL; | |
718e3744 | 4822 | |
d62a17ae | 4823 | if (use_json) |
4824 | json_sub = json_object_new_object(); | |
4825 | else /* Show neighbor ID. */ | |
4826 | vty_out(vty, " Neighbor %s,", "-"); | |
4827 | ||
4828 | /* Show interface address. */ | |
4829 | if (use_json) | |
4830 | json_object_string_add(json_sub, "ifaceAddress", | |
4831 | inet_ntoa(nbr_nbma->addr)); | |
4832 | else | |
4833 | vty_out(vty, " interface address %s\n", | |
4834 | inet_ntoa(nbr_nbma->addr)); | |
4835 | ||
4836 | /* Show Area ID. */ | |
4837 | if (use_json) { | |
4838 | json_object_string_add(json_sub, "areaId", | |
4839 | ospf_area_desc_string(oi->area)); | |
4840 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
4841 | } else | |
4842 | vty_out(vty, " In the area %s via interface %s\n", | |
4843 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
4844 | ||
4845 | /* Show neighbor priority and state. */ | |
4846 | if (use_json) { | |
4847 | json_object_int_add(json_sub, "nbrPriority", | |
4848 | nbr_nbma->priority); | |
4849 | json_object_string_add(json_sub, "nbrState", "down"); | |
4850 | } else | |
4851 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4852 | nbr_nbma->priority, "Down"); | |
4853 | ||
4854 | /* Show state changes. */ | |
4855 | if (use_json) | |
4856 | json_object_int_add(json_sub, "stateChangeCounter", | |
4857 | nbr_nbma->state_change); | |
4858 | else | |
4859 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
4860 | ||
4861 | /* Show PollInterval */ | |
4862 | if (use_json) | |
4863 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
4864 | else | |
4865 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
4866 | ||
4867 | /* Show poll-interval timer. */ | |
b575a12c A |
4868 | if (nbr_nbma->t_poll) { |
4869 | if (use_json) { | |
4870 | long time_store; | |
4871 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
4872 | NULL) / 1000LL; | |
4873 | json_object_int_add(json_sub, | |
4874 | "pollIntervalTimerDueMsec", | |
4875 | time_store); | |
4876 | } else | |
4877 | vty_out(vty, " Poll timer due in %s\n", | |
4878 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
4879 | sizeof(timebuf))); | |
4880 | } | |
d62a17ae | 4881 | |
4882 | /* Show poll-interval timer thread. */ | |
4883 | if (use_json) { | |
4884 | if (nbr_nbma->t_poll != NULL) | |
4885 | json_object_string_add(json_sub, | |
4886 | "pollIntervalTimerThread", "on"); | |
4887 | } else | |
4888 | vty_out(vty, " Thread Poll Timer %s\n", | |
4889 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
4890 | ||
4891 | if (use_json) | |
4892 | json_object_object_add(json, "noNbrId", json_sub); | |
4893 | } | |
4894 | ||
4895 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
4896 | struct ospf_interface *oi, | |
4897 | struct ospf_neighbor *nbr, | |
cb0b2ac6 | 4898 | struct ospf_neighbor *prev_nbr, |
9f049418 | 4899 | json_object *json, bool use_json) |
d62a17ae | 4900 | { |
4901 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cb0b2ac6 CS |
4902 | json_object *json_neigh = NULL, *json_neigh_array = NULL; |
4903 | char neigh_str[INET_ADDRSTRLEN] = {0}; | |
d62a17ae | 4904 | |
cb0b2ac6 CS |
4905 | if (use_json) { |
4906 | if (prev_nbr && | |
4907 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
4908 | json_neigh_array = NULL; | |
4909 | } | |
4910 | ||
975a328e DA |
4911 | if (nbr->state == NSM_Attempt |
4912 | && nbr->router_id.s_addr == INADDR_ANY) | |
cb0b2ac6 CS |
4913 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
4914 | else | |
4915 | strlcpy(neigh_str, inet_ntoa(nbr->router_id), | |
4916 | sizeof(neigh_str)); | |
4917 | ||
4918 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
4919 | ||
4920 | if (!json_neigh_array) { | |
4921 | json_neigh_array = json_object_new_array(); | |
4922 | json_object_object_add(json, neigh_str, | |
4923 | json_neigh_array); | |
4924 | } | |
4925 | ||
4926 | json_neigh = json_object_new_object(); | |
4927 | ||
4928 | } else { | |
d62a17ae | 4929 | /* Show neighbor ID. */ |
975a328e DA |
4930 | if (nbr->state == NSM_Attempt |
4931 | && nbr->router_id.s_addr == INADDR_ANY) | |
d62a17ae | 4932 | vty_out(vty, " Neighbor %s,", "-"); |
4933 | else | |
4934 | vty_out(vty, " Neighbor %s,", | |
4935 | inet_ntoa(nbr->router_id)); | |
4936 | } | |
4937 | ||
4938 | /* Show interface address. */ | |
4939 | if (use_json) | |
cb0b2ac6 | 4940 | json_object_string_add(json_neigh, "ifaceAddress", |
d62a17ae | 4941 | inet_ntoa(nbr->address.u.prefix4)); |
4942 | else | |
4943 | vty_out(vty, " interface address %s\n", | |
4944 | inet_ntoa(nbr->address.u.prefix4)); | |
4945 | ||
4946 | /* Show Area ID. */ | |
4947 | if (use_json) { | |
cb0b2ac6 | 4948 | json_object_string_add(json_neigh, "areaId", |
d62a17ae | 4949 | ospf_area_desc_string(oi->area)); |
cb0b2ac6 | 4950 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
d62a17ae | 4951 | } else |
4952 | vty_out(vty, " In the area %s via interface %s\n", | |
4953 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
4954 | ||
4955 | /* Show neighbor priority and state. */ | |
4956 | if (use_json) { | |
cb0b2ac6 | 4957 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
d62a17ae | 4958 | json_object_string_add( |
cb0b2ac6 | 4959 | json_neigh, "nbrState", |
d62a17ae | 4960 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); |
4961 | } else | |
4962 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4963 | nbr->priority, | |
4964 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4965 | ||
4966 | /* Show state changes. */ | |
4967 | if (use_json) | |
cb0b2ac6 | 4968 | json_object_int_add(json_neigh, "stateChangeCounter", |
d62a17ae | 4969 | nbr->state_change); |
4970 | else | |
4971 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
4972 | ||
4973 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
4974 | struct timeval res; | |
4975 | long time_store; | |
4976 | ||
4977 | time_store = | |
4978 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
4979 | if (use_json) { | |
cb0b2ac6 | 4980 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
d62a17ae | 4981 | time_store); |
4982 | } else { | |
4983 | vty_out(vty, | |
4984 | " Most recent state change statistics:\n"); | |
4985 | vty_out(vty, " Progressive change %s ago\n", | |
4986 | ospf_timeval_dump(&res, timebuf, | |
4987 | sizeof(timebuf))); | |
4988 | } | |
4989 | } | |
4990 | ||
4991 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
4992 | struct timeval res; | |
4993 | long time_store; | |
4994 | ||
4995 | time_store = | |
4996 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
4997 | if (use_json) { | |
cb0b2ac6 | 4998 | json_object_int_add(json_neigh, |
d62a17ae | 4999 | "lastRegressiveChangeMsec", |
5000 | time_store); | |
5001 | if (nbr->last_regress_str) | |
5002 | json_object_string_add( | |
cb0b2ac6 CS |
5003 | json_neigh, |
5004 | "lastRegressiveChangeReason", | |
d62a17ae | 5005 | nbr->last_regress_str); |
5006 | } else { | |
5007 | vty_out(vty, | |
5008 | " Regressive change %s ago, due to %s\n", | |
5009 | ospf_timeval_dump(&res, timebuf, | |
5010 | sizeof(timebuf)), | |
5011 | (nbr->last_regress_str ? nbr->last_regress_str | |
5012 | : "??")); | |
5013 | } | |
5014 | } | |
5015 | ||
5016 | /* Show Designated Rotuer ID. */ | |
5017 | if (use_json) | |
cb0b2ac6 | 5018 | json_object_string_add(json_neigh, "routerDesignatedId", |
d62a17ae | 5019 | inet_ntoa(nbr->d_router)); |
5020 | else | |
5021 | vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router)); | |
5022 | ||
5023 | /* Show Backup Designated Rotuer ID. */ | |
5024 | if (use_json) | |
cb0b2ac6 | 5025 | json_object_string_add(json_neigh, "routerDesignatedBackupId", |
d62a17ae | 5026 | inet_ntoa(nbr->bd_router)); |
5027 | else | |
5028 | vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router)); | |
5029 | ||
5030 | /* Show options. */ | |
5031 | if (use_json) { | |
cb0b2ac6 CS |
5032 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5033 | json_object_string_add(json_neigh, "optionsList", | |
d62a17ae | 5034 | ospf_options_dump(nbr->options)); |
5035 | } else | |
5036 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5037 | ospf_options_dump(nbr->options)); | |
5038 | ||
5039 | /* Show Router Dead interval timer. */ | |
5040 | if (use_json) { | |
5041 | if (nbr->t_inactivity) { | |
5042 | long time_store; | |
5043 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5044 | NULL) | |
5045 | / 1000LL; | |
cb0b2ac6 | 5046 | json_object_int_add(json_neigh, |
d62a17ae | 5047 | "routerDeadIntervalTimerDueMsec", |
5048 | time_store); | |
5049 | } else | |
5050 | json_object_int_add( | |
cb0b2ac6 CS |
5051 | json_neigh, |
5052 | "routerDeadIntervalTimerDueMsec", -1); | |
d62a17ae | 5053 | } else |
5054 | vty_out(vty, " Dead timer due in %s\n", | |
5055 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5056 | sizeof(timebuf))); | |
5057 | ||
5058 | /* Show Database Summary list. */ | |
5059 | if (use_json) | |
cb0b2ac6 | 5060 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
d62a17ae | 5061 | ospf_db_summary_count(nbr)); |
5062 | else | |
5063 | vty_out(vty, " Database Summary List %d\n", | |
5064 | ospf_db_summary_count(nbr)); | |
5065 | ||
5066 | /* Show Link State Request list. */ | |
5067 | if (use_json) | |
cb0b2ac6 | 5068 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
d62a17ae | 5069 | ospf_ls_request_count(nbr)); |
5070 | else | |
5071 | vty_out(vty, " Link State Request List %ld\n", | |
5072 | ospf_ls_request_count(nbr)); | |
5073 | ||
5074 | /* Show Link State Retransmission list. */ | |
5075 | if (use_json) | |
cb0b2ac6 | 5076 | json_object_int_add(json_neigh, |
d62a17ae | 5077 | "linkStateRetransmissionListCounter", |
5078 | ospf_ls_retransmit_count(nbr)); | |
5079 | else | |
5080 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5081 | ospf_ls_retransmit_count(nbr)); | |
5082 | ||
5083 | /* Show inactivity timer thread. */ | |
5084 | if (use_json) { | |
5085 | if (nbr->t_inactivity != NULL) | |
cb0b2ac6 | 5086 | json_object_string_add(json_neigh, |
d62a17ae | 5087 | "threadInactivityTimer", "on"); |
5088 | } else | |
5089 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5090 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5091 | ||
5092 | /* Show Database Description retransmission thread. */ | |
5093 | if (use_json) { | |
5094 | if (nbr->t_db_desc != NULL) | |
5095 | json_object_string_add( | |
cb0b2ac6 | 5096 | json_neigh, |
d62a17ae | 5097 | "threadDatabaseDescriptionRetransmission", |
5098 | "on"); | |
5099 | } else | |
5100 | vty_out(vty, | |
5101 | " Thread Database Description Retransmision %s\n", | |
5102 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5103 | ||
5104 | /* Show Link State Request Retransmission thread. */ | |
5105 | if (use_json) { | |
5106 | if (nbr->t_ls_req != NULL) | |
5107 | json_object_string_add( | |
cb0b2ac6 | 5108 | json_neigh, |
d62a17ae | 5109 | "threadLinkStateRequestRetransmission", "on"); |
5110 | } else | |
5111 | vty_out(vty, | |
5112 | " Thread Link State Request Retransmission %s\n", | |
5113 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5114 | ||
5115 | /* Show Link State Update Retransmission thread. */ | |
5116 | if (use_json) { | |
5117 | if (nbr->t_ls_upd != NULL) | |
5118 | json_object_string_add( | |
cb0b2ac6 CS |
5119 | json_neigh, |
5120 | "threadLinkStateUpdateRetransmission", | |
d62a17ae | 5121 | "on"); |
5122 | } else | |
5123 | vty_out(vty, | |
5124 | " Thread Link State Update Retransmission %s\n\n", | |
5125 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5126 | ||
cb0b2ac6 CS |
5127 | ospf_bfd_show_info(vty, nbr->bfd_info, json_neigh, use_json, 0); |
5128 | ||
5129 | if (use_json) | |
5130 | json_object_array_add(json_neigh_array, json_neigh); | |
d62a17ae | 5131 | |
d62a17ae | 5132 | } |
5133 | ||
5134 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5135 | struct in_addr *router_id, |
9f049418 | 5136 | bool use_json, uint8_t use_vrf) |
d62a17ae | 5137 | { |
5138 | struct listnode *node; | |
5139 | struct ospf_neighbor *nbr; | |
5140 | struct ospf_interface *oi; | |
d62a17ae | 5141 | json_object *json = NULL; |
5142 | ||
5143 | if (use_json) | |
5144 | json = json_object_new_object(); | |
5145 | ||
5146 | if (ospf->instance) { | |
5147 | if (use_json) | |
5148 | json_object_int_add(json, "ospfInstance", | |
5149 | ospf->instance); | |
5150 | else | |
5151 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5152 | } | |
5153 | ||
b1c3ae8c | 5154 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5155 | |
d62a17ae | 5156 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5157 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
cb0b2ac6 CS |
5158 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5159 | json, use_json); | |
d62a17ae | 5160 | } |
5161 | } | |
5162 | ||
5163 | if (use_json) { | |
9d303b37 DL |
5164 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5165 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5166 | json_object_free(json); |
5167 | } else | |
5168 | vty_out(vty, "\n"); | |
5169 | ||
5170 | return CMD_SUCCESS; | |
718e3744 | 5171 | } |
5172 | ||
986b87cb | 5173 | DEFPY (show_ip_ospf_neighbor_id, |
7c8ff89e | 5174 | show_ip_ospf_neighbor_id_cmd, |
986b87cb | 5175 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", |
718e3744 | 5176 | SHOW_STR |
5177 | IP_STR | |
5178 | "OSPF information\n" | |
5179 | "Neighbor list\n" | |
3ac237f8 | 5180 | "Neighbor ID\n" |
9973d184 | 5181 | JSON_STR) |
718e3744 | 5182 | { |
d62a17ae | 5183 | struct ospf *ospf; |
986b87cb | 5184 | struct listnode *node; |
b5a8894d | 5185 | int ret = CMD_SUCCESS; |
7c8ff89e | 5186 | |
b5a8894d CS |
5187 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5188 | if (!ospf->oi_running) | |
5189 | continue; | |
986b87cb RW |
5190 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
5191 | !!json, 0); | |
b5a8894d | 5192 | } |
7c8ff89e | 5193 | |
b5a8894d | 5194 | return ret; |
7c8ff89e DS |
5195 | } |
5196 | ||
986b87cb | 5197 | DEFPY (show_ip_ospf_instance_neighbor_id, |
7c8ff89e | 5198 | show_ip_ospf_instance_neighbor_id_cmd, |
986b87cb | 5199 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", |
7c8ff89e DS |
5200 | SHOW_STR |
5201 | IP_STR | |
5202 | "OSPF information\n" | |
5203 | "Instance ID\n" | |
5204 | "Neighbor list\n" | |
3ac237f8 | 5205 | "Neighbor ID\n" |
9973d184 | 5206 | JSON_STR) |
7c8ff89e | 5207 | { |
d62a17ae | 5208 | struct ospf *ospf; |
7c8ff89e | 5209 | |
ac28e4ec CS |
5210 | ospf = ospf_lookup_instance(instance); |
5211 | if (ospf == NULL) | |
5212 | return CMD_NOT_MY_INSTANCE; | |
5213 | ||
5214 | if (!ospf->oi_running) | |
d62a17ae | 5215 | return CMD_SUCCESS; |
7c8ff89e | 5216 | |
986b87cb RW |
5217 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, |
5218 | 0); | |
7c8ff89e DS |
5219 | } |
5220 | ||
d62a17ae | 5221 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5222 | struct ospf *ospf, | |
9f049418 | 5223 | json_object *json, bool use_json, |
d7c0a89a | 5224 | uint8_t use_vrf) |
d62a17ae | 5225 | { |
5226 | struct ospf_interface *oi; | |
5227 | struct listnode *node; | |
b1c3ae8c | 5228 | json_object *json_vrf = NULL; |
cb0b2ac6 | 5229 | json_object *json_nbr_sub = NULL; |
d62a17ae | 5230 | |
b1c3ae8c CS |
5231 | if (use_json) { |
5232 | if (use_vrf) | |
5233 | json_vrf = json_object_new_object(); | |
5234 | else | |
5235 | json_vrf = json; | |
cb0b2ac6 CS |
5236 | |
5237 | json_nbr_sub = json_object_new_object(); | |
b1c3ae8c | 5238 | } |
cb0b2ac6 | 5239 | |
d62a17ae | 5240 | if (ospf->instance) { |
5241 | if (use_json) | |
cb0b2ac6 | 5242 | json_object_int_add(json, "ospfInstance", |
d62a17ae | 5243 | ospf->instance); |
5244 | else | |
5245 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5246 | } | |
5247 | ||
b1c3ae8c | 5248 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5249 | |
d62a17ae | 5250 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5251 | struct route_node *rn; | |
cb0b2ac6 | 5252 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5253 | |
5254 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5255 | if ((nbr = rn->info)) { | |
5256 | if (nbr != oi->nbr_self) { | |
5257 | if (nbr->state != NSM_Down) { | |
5258 | show_ip_ospf_neighbor_detail_sub( | |
cb0b2ac6 CS |
5259 | vty, oi, nbr, prev_nbr, |
5260 | json_nbr_sub, use_json); | |
d62a17ae | 5261 | } |
5262 | } | |
cb0b2ac6 | 5263 | prev_nbr = nbr; |
d62a17ae | 5264 | } |
5265 | } | |
5266 | } | |
5267 | ||
5268 | if (use_json) { | |
cb0b2ac6 CS |
5269 | json_object_object_add(json_vrf, "neighbors", |
5270 | json_nbr_sub); | |
b1c3ae8c CS |
5271 | if (use_vrf) { |
5272 | if (ospf->vrf_id == VRF_DEFAULT) | |
5273 | json_object_object_add(json, "default", | |
5274 | json_vrf); | |
5275 | else | |
5276 | json_object_object_add(json, ospf->name, | |
5277 | json_vrf); | |
5278 | } | |
d62a17ae | 5279 | } else |
5280 | vty_out(vty, "\n"); | |
5281 | ||
5282 | return CMD_SUCCESS; | |
718e3744 | 5283 | } |
5284 | ||
7c8ff89e DS |
5285 | DEFUN (show_ip_ospf_neighbor_detail, |
5286 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5287 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5288 | SHOW_STR |
5289 | IP_STR | |
5290 | "OSPF information\n" | |
b5a8894d CS |
5291 | VRF_CMD_HELP_STR |
5292 | "All VRFs\n" | |
718e3744 | 5293 | "Neighbor list\n" |
3ac237f8 | 5294 | "detail of all neighbors\n" |
9973d184 | 5295 | JSON_STR) |
718e3744 | 5296 | { |
d62a17ae | 5297 | struct ospf *ospf; |
9f049418 | 5298 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5299 | struct listnode *node = NULL; |
5300 | char *vrf_name = NULL; | |
2951a7a4 | 5301 | bool all_vrf = false; |
b5a8894d CS |
5302 | int ret = CMD_SUCCESS; |
5303 | int inst = 0; | |
5304 | int idx_vrf = 0; | |
d7c0a89a | 5305 | uint8_t use_vrf = 0; |
b1c3ae8c | 5306 | json_object *json = NULL; |
7c8ff89e | 5307 | |
43b8d1d8 | 5308 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5309 | |
b1c3ae8c CS |
5310 | if (uj) |
5311 | json = json_object_new_object(); | |
5312 | ||
b5a8894d CS |
5313 | /* vrf input is provided could be all or specific vrf*/ |
5314 | if (vrf_name) { | |
b1c3ae8c | 5315 | use_vrf = 1; |
b5a8894d CS |
5316 | if (all_vrf) { |
5317 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5318 | if (!ospf->oi_running) | |
5319 | continue; | |
996c9314 LB |
5320 | ret = show_ip_ospf_neighbor_detail_common( |
5321 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
5322 | } |
5323 | if (uj) { | |
5324 | vty_out(vty, "%s\n", | |
996c9314 LB |
5325 | json_object_to_json_string_ext( |
5326 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 5327 | json_object_free(json); |
b5a8894d | 5328 | } |
b1c3ae8c | 5329 | |
b5a8894d CS |
5330 | return ret; |
5331 | } | |
5332 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5333 | if (ospf == NULL || !ospf->oi_running) { |
5334 | if (uj) | |
5335 | json_object_free(json); | |
b5a8894d | 5336 | return CMD_SUCCESS; |
b1c3ae8c | 5337 | } |
b5a8894d CS |
5338 | } else { |
5339 | /* Display default ospf (instance 0) info */ | |
5340 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5341 | if (ospf == NULL || !ospf->oi_running) { |
5342 | if (uj) | |
5343 | json_object_free(json); | |
b5a8894d | 5344 | return CMD_SUCCESS; |
b1c3ae8c | 5345 | } |
b5a8894d CS |
5346 | } |
5347 | ||
b1c3ae8c CS |
5348 | if (ospf) { |
5349 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5350 | use_vrf); | |
5351 | if (uj) { | |
5352 | vty_out(vty, "%s\n", | |
996c9314 LB |
5353 | json_object_to_json_string_ext( |
5354 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5355 | } |
5356 | } | |
5357 | ||
5358 | if (uj) | |
5359 | json_object_free(json); | |
b5a8894d CS |
5360 | |
5361 | return ret; | |
7c8ff89e DS |
5362 | } |
5363 | ||
5364 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5365 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5366 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5367 | SHOW_STR |
5368 | IP_STR | |
5369 | "OSPF information\n" | |
5370 | "Instance ID\n" | |
5371 | "Neighbor list\n" | |
3ac237f8 | 5372 | "detail of all neighbors\n" |
9973d184 | 5373 | JSON_STR) |
7c8ff89e | 5374 | { |
d62a17ae | 5375 | int idx_number = 3; |
5376 | struct ospf *ospf; | |
d7c0a89a | 5377 | unsigned short instance = 0; |
9f049418 | 5378 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5379 | json_object *json = NULL; |
5380 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5381 | |
d62a17ae | 5382 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5383 | ospf = ospf_lookup_instance(instance); |
5384 | if (ospf == NULL) | |
5385 | return CMD_NOT_MY_INSTANCE; | |
5386 | ||
5387 | if (!ospf->oi_running) | |
d62a17ae | 5388 | return CMD_SUCCESS; |
7c8ff89e | 5389 | |
b1c3ae8c CS |
5390 | if (uj) |
5391 | json = json_object_new_object(); | |
5392 | ||
5393 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5394 | ||
5395 | if (uj) { | |
5396 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5397 | json, JSON_C_TO_STRING_PRETTY)); | |
5398 | json_object_free(json); | |
5399 | } | |
5400 | ||
5401 | return ret; | |
7c8ff89e DS |
5402 | } |
5403 | ||
d62a17ae | 5404 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5405 | struct ospf *ospf, | |
b1c3ae8c | 5406 | json_object *json, |
9f049418 | 5407 | bool use_json, |
d7c0a89a | 5408 | uint8_t use_vrf) |
d62a17ae | 5409 | { |
5410 | struct listnode *node; | |
5411 | struct ospf_interface *oi; | |
b1c3ae8c | 5412 | json_object *json_vrf = NULL; |
718e3744 | 5413 | |
b1c3ae8c CS |
5414 | if (use_json) { |
5415 | if (use_vrf) | |
5416 | json_vrf = json_object_new_object(); | |
5417 | else | |
5418 | json_vrf = json; | |
5419 | } | |
d62a17ae | 5420 | |
5421 | if (ospf->instance) { | |
5422 | if (use_json) | |
5423 | json_object_int_add(json, "ospfInstance", | |
5424 | ospf->instance); | |
5425 | else | |
5426 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5427 | } | |
5428 | ||
b1c3ae8c | 5429 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5430 | |
d62a17ae | 5431 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5432 | struct route_node *rn; | |
cb0b2ac6 | 5433 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5434 | struct ospf_nbr_nbma *nbr_nbma; |
5435 | ||
cb0b2ac6 CS |
5436 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5437 | if ((nbr = rn->info)) { | |
d62a17ae | 5438 | if (nbr != oi->nbr_self) |
5439 | if (nbr->state != NSM_Down) | |
5440 | show_ip_ospf_neighbor_detail_sub( | |
5441 | vty, oi, rn->info, | |
cb0b2ac6 | 5442 | prev_nbr, |
b1c3ae8c | 5443 | json_vrf, use_json); |
cb0b2ac6 CS |
5444 | prev_nbr = nbr; |
5445 | } | |
5446 | } | |
d62a17ae | 5447 | |
5448 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5449 | struct listnode *nd; | |
5450 | ||
5451 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5452 | if (nbr_nbma->nbr == NULL | |
5453 | || nbr_nbma->nbr->state == NSM_Down) | |
5454 | show_ip_ospf_nbr_nbma_detail_sub( | |
5455 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5456 | json_vrf); |
d62a17ae | 5457 | } |
5458 | } | |
5459 | } | |
5460 | ||
5461 | if (use_json) { | |
b1c3ae8c CS |
5462 | if (use_vrf) { |
5463 | if (ospf->vrf_id == VRF_DEFAULT) | |
5464 | json_object_object_add(json, "default", | |
5465 | json_vrf); | |
5466 | else | |
5467 | json_object_object_add(json, ospf->name, | |
5468 | json_vrf); | |
5469 | } | |
d62a17ae | 5470 | } else { |
5471 | vty_out(vty, "\n"); | |
5472 | } | |
5473 | ||
5474 | return CMD_SUCCESS; | |
718e3744 | 5475 | } |
5476 | ||
7c8ff89e DS |
5477 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5478 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5479 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5480 | SHOW_STR |
5481 | IP_STR | |
5482 | "OSPF information\n" | |
b5a8894d CS |
5483 | VRF_CMD_HELP_STR |
5484 | "All VRFs\n" | |
718e3744 | 5485 | "Neighbor list\n" |
7c8ff89e | 5486 | "detail of all neighbors\n" |
3ac237f8 | 5487 | "include down status neighbor\n" |
9973d184 | 5488 | JSON_STR) |
718e3744 | 5489 | { |
d62a17ae | 5490 | struct ospf *ospf; |
9f049418 | 5491 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5492 | struct listnode *node = NULL; |
5493 | char *vrf_name = NULL; | |
2951a7a4 | 5494 | bool all_vrf = false; |
b5a8894d CS |
5495 | int ret = CMD_SUCCESS; |
5496 | int inst = 0; | |
5497 | int idx_vrf = 0; | |
d7c0a89a | 5498 | uint8_t use_vrf = 0; |
b1c3ae8c | 5499 | json_object *json = NULL; |
7c8ff89e | 5500 | |
43b8d1d8 | 5501 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5502 | |
b1c3ae8c CS |
5503 | if (uj) |
5504 | json = json_object_new_object(); | |
5505 | ||
b5a8894d CS |
5506 | /* vrf input is provided could be all or specific vrf*/ |
5507 | if (vrf_name) { | |
b1c3ae8c | 5508 | use_vrf = 1; |
b5a8894d CS |
5509 | if (all_vrf) { |
5510 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5511 | if (!ospf->oi_running) | |
5512 | continue; | |
996c9314 LB |
5513 | ret = show_ip_ospf_neighbor_detail_all_common( |
5514 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5515 | } |
b1c3ae8c CS |
5516 | |
5517 | if (uj) { | |
5518 | vty_out(vty, "%s\n", | |
996c9314 LB |
5519 | json_object_to_json_string_ext( |
5520 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5521 | json_object_free(json); |
5522 | } | |
5523 | ||
b5a8894d CS |
5524 | return ret; |
5525 | } | |
5526 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5527 | if (ospf == NULL || !ospf->oi_running) { |
5528 | if (uj) | |
5529 | json_object_free(json); | |
b5a8894d | 5530 | return CMD_SUCCESS; |
b1c3ae8c | 5531 | } |
b5a8894d CS |
5532 | } else { |
5533 | /* Display default ospf (instance 0) info */ | |
5534 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5535 | if (ospf == NULL || !ospf->oi_running) { |
5536 | if (uj) | |
5537 | json_object_free(json); | |
b5a8894d | 5538 | return CMD_SUCCESS; |
b1c3ae8c | 5539 | } |
b5a8894d CS |
5540 | } |
5541 | ||
b1c3ae8c CS |
5542 | if (ospf) { |
5543 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5544 | uj, use_vrf); | |
5545 | if (uj) { | |
5546 | vty_out(vty, "%s\n", | |
996c9314 LB |
5547 | json_object_to_json_string_ext( |
5548 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5549 | } |
5550 | } | |
5551 | ||
5552 | if (uj) | |
5553 | json_object_free(json); | |
b5a8894d CS |
5554 | |
5555 | return ret; | |
7c8ff89e DS |
5556 | } |
5557 | ||
5558 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5559 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5560 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5561 | SHOW_STR |
5562 | IP_STR | |
5563 | "OSPF information\n" | |
5564 | "Instance ID\n" | |
5565 | "Neighbor list\n" | |
5566 | "detail of all neighbors\n" | |
3ac237f8 | 5567 | "include down status neighbor\n" |
9973d184 | 5568 | JSON_STR) |
7c8ff89e | 5569 | { |
d62a17ae | 5570 | int idx_number = 3; |
5571 | struct ospf *ospf; | |
d7c0a89a | 5572 | unsigned short instance = 0; |
9f049418 | 5573 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5574 | json_object *json = NULL; |
5575 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5576 | |
d62a17ae | 5577 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5578 | ospf = ospf_lookup_instance(instance); |
5579 | if (ospf == NULL) | |
5580 | return CMD_NOT_MY_INSTANCE; | |
5581 | ||
5582 | if (!ospf->oi_running) | |
d62a17ae | 5583 | return CMD_SUCCESS; |
7c8ff89e | 5584 | |
b1c3ae8c CS |
5585 | if (uj) |
5586 | json = json_object_new_object(); | |
5587 | ||
5588 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5589 | ||
5590 | if (uj) { | |
996c9314 LB |
5591 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5592 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5593 | json_object_free(json); |
5594 | } | |
5595 | ||
5596 | return ret; | |
7c8ff89e DS |
5597 | } |
5598 | ||
d62a17ae | 5599 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5600 | struct ospf *ospf, | |
5601 | int arg_base, | |
5602 | struct cmd_token **argv, | |
9f049418 | 5603 | bool use_json) |
d62a17ae | 5604 | { |
5605 | struct ospf_interface *oi; | |
5606 | struct interface *ifp; | |
5607 | struct route_node *rn, *nrn; | |
5608 | struct ospf_neighbor *nbr; | |
5609 | json_object *json = NULL; | |
718e3744 | 5610 | |
d62a17ae | 5611 | if (use_json) |
5612 | json = json_object_new_object(); | |
5613 | ||
5614 | if (ospf->instance) { | |
5615 | if (use_json) | |
5616 | json_object_int_add(json, "ospfInstance", | |
5617 | ospf->instance); | |
5618 | else | |
5619 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5620 | } | |
5621 | ||
a36898e7 | 5622 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5623 | if (!ifp) { |
5624 | if (!use_json) | |
5625 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5626 | else { |
5627 | vty_out(vty, "{}\n"); | |
5628 | json_object_free(json); | |
5629 | } | |
d62a17ae | 5630 | return CMD_WARNING; |
5631 | } | |
5632 | ||
5633 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5634 | if ((oi = rn->info)) { | |
5635 | for (nrn = route_top(oi->nbrs); nrn; | |
5636 | nrn = route_next(nrn)) { | |
5637 | if ((nbr = nrn->info)) { | |
5638 | if (nbr != oi->nbr_self) { | |
5639 | if (nbr->state != NSM_Down) | |
5640 | show_ip_ospf_neighbor_detail_sub( | |
5641 | vty, oi, nbr, | |
cb0b2ac6 | 5642 | NULL, |
b1c3ae8c | 5643 | json, use_json); |
d62a17ae | 5644 | } |
5645 | } | |
5646 | } | |
5647 | } | |
5648 | } | |
5649 | ||
5650 | if (use_json) { | |
9d303b37 DL |
5651 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5652 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5653 | json_object_free(json); |
5654 | } else | |
5655 | vty_out(vty, "\n"); | |
5656 | ||
5657 | return CMD_SUCCESS; | |
718e3744 | 5658 | } |
5659 | ||
7c8ff89e DS |
5660 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5661 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5662 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5663 | SHOW_STR |
5664 | IP_STR | |
5665 | "OSPF information\n" | |
5666 | "Neighbor list\n" | |
5667 | "Interface name\n" | |
3ac237f8 | 5668 | "detail of all neighbors\n" |
9973d184 | 5669 | JSON_STR) |
7c8ff89e | 5670 | { |
d62a17ae | 5671 | struct ospf *ospf; |
9f049418 | 5672 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5673 | struct listnode *node = NULL; |
5674 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5675 | bool ospf_output = false; |
7c8ff89e | 5676 | |
b5a8894d CS |
5677 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5678 | if (!ospf->oi_running) | |
5679 | continue; | |
2951a7a4 | 5680 | ospf_output = true; |
cb0b2ac6 | 5681 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, |
b5a8894d CS |
5682 | argv, uj); |
5683 | } | |
7c8ff89e | 5684 | |
9f049418 DS |
5685 | if (!ospf_output) |
5686 | vty_out(vty, "%% OSPF instance not found\n"); | |
5687 | ||
b5a8894d | 5688 | return ret; |
7c8ff89e DS |
5689 | } |
5690 | ||
5691 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5692 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5693 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5694 | SHOW_STR |
5695 | IP_STR | |
5696 | "OSPF information\n" | |
5697 | "Instance ID\n" | |
5698 | "Neighbor list\n" | |
5699 | "Interface name\n" | |
3ac237f8 | 5700 | "detail of all neighbors\n" |
9973d184 | 5701 | JSON_STR) |
7c8ff89e | 5702 | { |
d62a17ae | 5703 | int idx_number = 3; |
b4e84315 | 5704 | int idx_ifname = 5; |
d62a17ae | 5705 | struct ospf *ospf; |
d7c0a89a | 5706 | unsigned short instance = 0; |
9f049418 | 5707 | bool uj = use_json(argc, argv); |
7c8ff89e | 5708 | |
d62a17ae | 5709 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5710 | ospf = ospf_lookup_instance(instance); |
5711 | if (ospf == NULL) | |
5712 | return CMD_NOT_MY_INSTANCE; | |
5713 | ||
5714 | if (!ospf->oi_running) | |
d62a17ae | 5715 | return CMD_SUCCESS; |
7c8ff89e | 5716 | |
996c9314 LB |
5717 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5718 | argv, uj); | |
7c8ff89e | 5719 | } |
6b0655a2 | 5720 | |
718e3744 | 5721 | /* Show functions */ |
d62a17ae | 5722 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) |
5723 | { | |
5724 | struct router_lsa *rl; | |
5725 | struct summary_lsa *sl; | |
5726 | struct as_external_lsa *asel; | |
5727 | struct prefix_ipv4 p; | |
5728 | ||
5729 | if (lsa != NULL) | |
5730 | /* If self option is set, check LSA self flag. */ | |
5731 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
5732 | /* LSA common part show. */ | |
5733 | vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id)); | |
5734 | vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", | |
5735 | inet_ntoa(lsa->data->adv_router), LS_AGE(lsa), | |
d7c0a89a | 5736 | (unsigned long)ntohl(lsa->data->ls_seqnum), |
d62a17ae | 5737 | ntohs(lsa->data->checksum)); |
5738 | /* LSA specific part show. */ | |
5739 | switch (lsa->data->type) { | |
5740 | case OSPF_ROUTER_LSA: | |
5741 | rl = (struct router_lsa *)lsa->data; | |
5742 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5743 | break; | |
5744 | case OSPF_SUMMARY_LSA: | |
5745 | sl = (struct summary_lsa *)lsa->data; | |
5746 | ||
5747 | p.family = AF_INET; | |
5748 | p.prefix = sl->header.id; | |
5749 | p.prefixlen = ip_masklen(sl->mask); | |
5750 | apply_mask_ipv4(&p); | |
5751 | ||
5752 | vty_out(vty, " %s/%d", inet_ntoa(p.prefix), | |
5753 | p.prefixlen); | |
5754 | break; | |
5755 | case OSPF_AS_EXTERNAL_LSA: | |
5756 | case OSPF_AS_NSSA_LSA: | |
5757 | asel = (struct as_external_lsa *)lsa->data; | |
5758 | ||
5759 | p.family = AF_INET; | |
5760 | p.prefix = asel->header.id; | |
5761 | p.prefixlen = ip_masklen(asel->mask); | |
5762 | apply_mask_ipv4(&p); | |
5763 | ||
5764 | vty_out(vty, " %s %s/%d [0x%lx]", | |
5765 | IS_EXTERNAL_METRIC(asel->e[0].tos) | |
5766 | ? "E2" | |
5767 | : "E1", | |
5768 | inet_ntoa(p.prefix), p.prefixlen, | |
d7c0a89a QY |
5769 | (unsigned long)ntohl( |
5770 | asel->e[0].route_tag)); | |
d62a17ae | 5771 | break; |
5772 | case OSPF_NETWORK_LSA: | |
5773 | case OSPF_ASBR_SUMMARY_LSA: | |
5774 | case OSPF_OPAQUE_LINK_LSA: | |
5775 | case OSPF_OPAQUE_AREA_LSA: | |
5776 | case OSPF_OPAQUE_AS_LSA: | |
5777 | default: | |
5778 | break; | |
5779 | } | |
5780 | vty_out(vty, "\n"); | |
5781 | } | |
718e3744 | 5782 | |
d62a17ae | 5783 | return 0; |
5784 | } | |
5785 | ||
2b64873d | 5786 | static const char *const show_database_desc[] = { |
d62a17ae | 5787 | "unknown", |
5788 | "Router Link States", | |
5789 | "Net Link States", | |
5790 | "Summary Link States", | |
5791 | "ASBR-Summary Link States", | |
5792 | "AS External Link States", | |
5793 | "Group Membership LSA", | |
5794 | "NSSA-external Link States", | |
5795 | "Type-8 LSA", | |
5796 | "Link-Local Opaque-LSA", | |
5797 | "Area-Local Opaque-LSA", | |
5798 | "AS-external Opaque-LSA", | |
718e3744 | 5799 | }; |
5800 | ||
2b64873d | 5801 | static const char *const show_database_header[] = { |
d62a17ae | 5802 | "", |
5803 | "Link ID ADV Router Age Seq# CkSum Link count", | |
5804 | "Link ID ADV Router Age Seq# CkSum", | |
5805 | "Link ID ADV Router Age Seq# CkSum Route", | |
5806 | "Link ID ADV Router Age Seq# CkSum", | |
5807 | "Link ID ADV Router Age Seq# CkSum Route", | |
5808 | " --- header for Group Member ----", | |
5809 | "Link ID ADV Router Age Seq# CkSum Route", | |
5810 | " --- type-8 ---", | |
5811 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5812 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5813 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 5814 | }; |
5815 | ||
d62a17ae | 5816 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa) |
5817 | { | |
5818 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
5819 | ||
5820 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
5821 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
5822 | ospf_options_dump(lsa->data->options)); | |
5823 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
5824 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" | |
5825 | : "")); | |
5826 | ||
5827 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
5828 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
5829 | ||
5830 | if (rlsa->flags) | |
5831 | vty_out(vty, " :%s%s%s%s", | |
5832 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "", | |
5833 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "", | |
5834 | IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint" | |
5835 | : "", | |
5836 | IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut" | |
5837 | : ""); | |
5838 | ||
5839 | vty_out(vty, "\n"); | |
5840 | } | |
5841 | vty_out(vty, " LS Type: %s\n", | |
5842 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
5843 | vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id), | |
5844 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL)); | |
5845 | vty_out(vty, " Advertising Router: %s\n", | |
5846 | inet_ntoa(lsa->data->adv_router)); | |
5847 | vty_out(vty, " LS Seq Number: %08lx\n", | |
d7c0a89a | 5848 | (unsigned long)ntohl(lsa->data->ls_seqnum)); |
d62a17ae | 5849 | vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum)); |
5850 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
5851 | } | |
5852 | ||
2b64873d | 5853 | static const char *const link_type_desc[] = { |
d62a17ae | 5854 | "(null)", |
5855 | "another Router (point-to-point)", | |
5856 | "a Transit Network", | |
5857 | "Stub Network", | |
5858 | "a Virtual Link", | |
718e3744 | 5859 | }; |
5860 | ||
2b64873d | 5861 | static const char *const link_id_desc[] = { |
d62a17ae | 5862 | "(null)", "Neighboring Router ID", "Designated Router address", |
5863 | "Net", "Neighboring Router ID", | |
718e3744 | 5864 | }; |
5865 | ||
2b64873d | 5866 | static const char *const link_data_desc[] = { |
d62a17ae | 5867 | "(null)", "Router Interface address", "Router Interface address", |
5868 | "Network Mask", "Router Interface address", | |
718e3744 | 5869 | }; |
5870 | ||
5871 | /* Show router-LSA each Link information. */ | |
d62a17ae | 5872 | static void show_ip_ospf_database_router_links(struct vty *vty, |
5873 | struct router_lsa *rl) | |
5874 | { | |
5875 | int len, type; | |
5876 | unsigned int i; | |
5877 | ||
5878 | len = ntohs(rl->header.length) - 4; | |
5879 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
5880 | type = rl->link[i].type; | |
5881 | ||
5882 | vty_out(vty, " Link connected to: %s\n", | |
5883 | link_type_desc[type]); | |
5884 | vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type], | |
5885 | inet_ntoa(rl->link[i].link_id)); | |
5886 | vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type], | |
5887 | inet_ntoa(rl->link[i].link_data)); | |
5888 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
5889 | vty_out(vty, " TOS 0 Metric: %d\n", | |
5890 | ntohs(rl->link[i].metric)); | |
5891 | vty_out(vty, "\n"); | |
5892 | } | |
718e3744 | 5893 | } |
5894 | ||
5895 | /* Show router-LSA detail information. */ | |
d62a17ae | 5896 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5897 | { |
d62a17ae | 5898 | if (lsa != NULL) { |
5899 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 5900 | |
d62a17ae | 5901 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5902 | |
d62a17ae | 5903 | vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links)); |
718e3744 | 5904 | |
d62a17ae | 5905 | show_ip_ospf_database_router_links(vty, rl); |
5906 | vty_out(vty, "\n"); | |
5907 | } | |
5908 | ||
5909 | return 0; | |
718e3744 | 5910 | } |
5911 | ||
5912 | /* Show network-LSA detail information. */ | |
d62a17ae | 5913 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5914 | { |
d62a17ae | 5915 | int length, i; |
718e3744 | 5916 | |
d62a17ae | 5917 | if (lsa != NULL) { |
5918 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
718e3744 | 5919 | |
d62a17ae | 5920 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5921 | |
d62a17ae | 5922 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask)); |
718e3744 | 5923 | |
d62a17ae | 5924 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; |
718e3744 | 5925 | |
d62a17ae | 5926 | for (i = 0; length > 0; i++, length -= 4) |
5927 | vty_out(vty, " Attached Router: %s\n", | |
5928 | inet_ntoa(nl->routers[i])); | |
718e3744 | 5929 | |
d62a17ae | 5930 | vty_out(vty, "\n"); |
5931 | } | |
718e3744 | 5932 | |
d62a17ae | 5933 | return 0; |
718e3744 | 5934 | } |
5935 | ||
5936 | /* Show summary-LSA detail information. */ | |
d62a17ae | 5937 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5938 | { |
d62a17ae | 5939 | if (lsa != NULL) { |
5940 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5941 | |
d62a17ae | 5942 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5943 | |
d62a17ae | 5944 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5945 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5946 | GET_METRIC(sl->metric)); | |
5947 | vty_out(vty, "\n"); | |
5948 | } | |
718e3744 | 5949 | |
d62a17ae | 5950 | return 0; |
718e3744 | 5951 | } |
5952 | ||
5953 | /* Show summary-ASBR-LSA detail information. */ | |
d62a17ae | 5954 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5955 | { |
d62a17ae | 5956 | if (lsa != NULL) { |
5957 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5958 | |
d62a17ae | 5959 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5960 | |
d62a17ae | 5961 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5962 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5963 | GET_METRIC(sl->metric)); | |
5964 | vty_out(vty, "\n"); | |
5965 | } | |
718e3744 | 5966 | |
d62a17ae | 5967 | return 0; |
718e3744 | 5968 | } |
5969 | ||
5970 | /* Show AS-external-LSA detail information. */ | |
d62a17ae | 5971 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5972 | { | |
5973 | if (lsa != NULL) { | |
5974 | struct as_external_lsa *al = | |
5975 | (struct as_external_lsa *)lsa->data; | |
5976 | ||
5977 | show_ip_ospf_database_header(vty, lsa); | |
5978 | ||
5979 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5980 | vty_out(vty, " Metric Type: %s\n", | |
5981 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5982 | ? "2 (Larger than any link state path)" | |
5983 | : "1"); | |
5984 | vty_out(vty, " TOS: 0\n"); | |
5985 | vty_out(vty, " Metric: %d\n", | |
5986 | GET_METRIC(al->e[0].metric)); | |
5987 | vty_out(vty, " Forward Address: %s\n", | |
5988 | inet_ntoa(al->e[0].fwd_addr)); | |
5989 | ||
5990 | vty_out(vty, | |
5991 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5992 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5993 | } | |
718e3744 | 5994 | |
d62a17ae | 5995 | return 0; |
718e3744 | 5996 | } |
075e12f5 | 5997 | #if 0 |
4dadc291 | 5998 | static int |
718e3744 | 5999 | show_as_external_lsa_stdvty (struct ospf_lsa *lsa) |
6000 | { | |
6001 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; | |
6002 | ||
6003 | /* show_ip_ospf_database_header (vty, lsa); */ | |
6004 | ||
2a42e285 | 6005 | zlog_debug( " Network Mask: /%d%s", |
718e3744 | 6006 | ip_masklen (al->mask), "\n"); |
2a42e285 | 6007 | zlog_debug( " Metric Type: %s%s", |
718e3744 | 6008 | IS_EXTERNAL_METRIC (al->e[0].tos) ? |
6009 | "2 (Larger than any link state path)" : "1", "\n"); | |
2a42e285 | 6010 | zlog_debug( " TOS: 0%s", "\n"); |
6011 | zlog_debug( " Metric: %d%s", | |
718e3744 | 6012 | GET_METRIC (al->e[0].metric), "\n"); |
2a42e285 | 6013 | zlog_debug( " Forward Address: %s%s", |
718e3744 | 6014 | inet_ntoa (al->e[0].fwd_addr), "\n"); |
6015 | ||
dc9ffce8 CF |
6016 | zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s", |
6017 | (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n"); | |
718e3744 | 6018 | |
6019 | return 0; | |
6020 | } | |
075e12f5 | 6021 | #endif |
718e3744 | 6022 | /* Show AS-NSSA-LSA detail information. */ |
d62a17ae | 6023 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
6024 | { | |
6025 | if (lsa != NULL) { | |
6026 | struct as_external_lsa *al = | |
6027 | (struct as_external_lsa *)lsa->data; | |
6028 | ||
6029 | show_ip_ospf_database_header(vty, lsa); | |
6030 | ||
6031 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
6032 | vty_out(vty, " Metric Type: %s\n", | |
6033 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6034 | ? "2 (Larger than any link state path)" | |
6035 | : "1"); | |
6036 | vty_out(vty, " TOS: 0\n"); | |
6037 | vty_out(vty, " Metric: %d\n", | |
6038 | GET_METRIC(al->e[0].metric)); | |
6039 | vty_out(vty, " NSSA: Forward Address: %s\n", | |
6040 | inet_ntoa(al->e[0].fwd_addr)); | |
6041 | ||
6042 | vty_out(vty, | |
6043 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6044 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6045 | } | |
718e3744 | 6046 | |
d62a17ae | 6047 | return 0; |
718e3744 | 6048 | } |
6049 | ||
d62a17ae | 6050 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 6051 | { |
d62a17ae | 6052 | return 0; |
718e3744 | 6053 | } |
6054 | ||
d62a17ae | 6055 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 6056 | { |
d62a17ae | 6057 | if (lsa != NULL) { |
6058 | show_ip_ospf_database_header(vty, lsa); | |
6059 | show_opaque_info_detail(vty, lsa); | |
718e3744 | 6060 | |
d62a17ae | 6061 | vty_out(vty, "\n"); |
6062 | } | |
6063 | return 0; | |
6064 | } | |
6065 | ||
2b64873d | 6066 | int (*const show_function[])(struct vty *, struct ospf_lsa *) = { |
d62a17ae | 6067 | NULL, |
6068 | show_router_lsa_detail, | |
6069 | show_network_lsa_detail, | |
6070 | show_summary_lsa_detail, | |
6071 | show_summary_asbr_lsa_detail, | |
6072 | show_as_external_lsa_detail, | |
6073 | show_func_dummy, | |
6074 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6075 | NULL, /* type-8 */ | |
6076 | show_opaque_lsa_detail, | |
6077 | show_opaque_lsa_detail, | |
6078 | show_opaque_lsa_detail, | |
6079 | }; | |
6080 | ||
6081 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6082 | struct in_addr *id, struct in_addr *adv_router) | |
6083 | { | |
6084 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6085 | lp->family = 0; | |
6086 | if (id == NULL) | |
6087 | lp->prefixlen = 0; | |
6088 | else if (adv_router == NULL) { | |
6089 | lp->prefixlen = 32; | |
6090 | lp->id = *id; | |
6091 | } else { | |
6092 | lp->prefixlen = 64; | |
6093 | lp->id = *id; | |
6094 | lp->adv_router = *adv_router; | |
6095 | } | |
718e3744 | 6096 | } |
718e3744 | 6097 | |
d62a17ae | 6098 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
6099 | struct in_addr *id, struct in_addr *adv_router) | |
6100 | { | |
6101 | struct prefix_ls lp; | |
6102 | struct route_node *rn, *start; | |
6103 | struct ospf_lsa *lsa; | |
718e3744 | 6104 | |
d62a17ae | 6105 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6106 | start = route_node_get(rt, (struct prefix *)&lp); | |
6107 | if (start) { | |
6108 | route_lock_node(start); | |
6109 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6110 | if ((lsa = rn->info)) { | |
6111 | if (show_function[lsa->data->type] != NULL) | |
6112 | show_function[lsa->data->type](vty, | |
6113 | lsa); | |
6114 | } | |
6115 | route_unlock_node(start); | |
6116 | } | |
718e3744 | 6117 | } |
6118 | ||
6119 | /* Show detail LSA information | |
6120 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6121 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
6122 | struct in_addr *id, struct in_addr *adv_router) | |
6123 | { | |
6124 | struct listnode *node; | |
6125 | struct ospf_area *area; | |
6126 | ||
6127 | switch (type) { | |
6128 | case OSPF_AS_EXTERNAL_LSA: | |
6129 | case OSPF_OPAQUE_AS_LSA: | |
6130 | vty_out(vty, " %s \n\n", | |
6131 | show_database_desc[type]); | |
6132 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router); | |
6133 | break; | |
6134 | default: | |
6135 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6136 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6137 | show_database_desc[type], | |
6138 | ospf_area_desc_string(area)); | |
6139 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, | |
6140 | adv_router); | |
6141 | } | |
6142 | break; | |
718e3744 | 6143 | } |
6144 | } | |
6145 | ||
d62a17ae | 6146 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6147 | struct route_table *rt, | |
6148 | struct in_addr *adv_router) | |
6149 | { | |
6150 | struct route_node *rn; | |
6151 | struct ospf_lsa *lsa; | |
6152 | ||
6153 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
6154 | if ((lsa = rn->info)) | |
6155 | if (IPV4_ADDR_SAME(adv_router, | |
6156 | &lsa->data->adv_router)) { | |
6157 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6158 | continue; | |
6159 | if (show_function[lsa->data->type] != NULL) | |
6160 | show_function[lsa->data->type](vty, | |
6161 | lsa); | |
6162 | } | |
6163 | } | |
6164 | ||
718e3744 | 6165 | /* Show detail LSA information. */ |
d62a17ae | 6166 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
6167 | int type, struct in_addr *adv_router) | |
6168 | { | |
6169 | struct listnode *node; | |
6170 | struct ospf_area *area; | |
6171 | ||
6172 | switch (type) { | |
6173 | case OSPF_AS_EXTERNAL_LSA: | |
6174 | case OSPF_OPAQUE_AS_LSA: | |
6175 | vty_out(vty, " %s \n\n", | |
6176 | show_database_desc[type]); | |
6177 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), | |
6178 | adv_router); | |
6179 | break; | |
6180 | default: | |
6181 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6182 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6183 | show_database_desc[type], | |
6184 | ospf_area_desc_string(area)); | |
6185 | show_lsa_detail_adv_router_proc( | |
6186 | vty, AREA_LSDB(area, type), adv_router); | |
6187 | } | |
6188 | break; | |
6189 | } | |
6190 | } | |
6191 | ||
6192 | static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, | |
6193 | int self) | |
6194 | { | |
6195 | struct ospf_lsa *lsa; | |
6196 | struct route_node *rn; | |
6197 | struct ospf_area *area; | |
6198 | struct listnode *node; | |
6199 | int type; | |
6200 | ||
6201 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6202 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6203 | switch (type) { | |
6204 | case OSPF_AS_EXTERNAL_LSA: | |
6205 | case OSPF_OPAQUE_AS_LSA: | |
6206 | continue; | |
6207 | default: | |
6208 | break; | |
6209 | } | |
6210 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6211 | || (!self | |
6212 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
6213 | vty_out(vty, " %s (Area %s)\n\n", | |
6214 | show_database_desc[type], | |
6215 | ospf_area_desc_string(area)); | |
6216 | vty_out(vty, "%s\n", | |
6217 | show_database_header[type]); | |
6218 | ||
996c9314 | 6219 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) |
044506e7 | 6220 | show_lsa_summary(vty, lsa, self); |
d62a17ae | 6221 | |
6222 | vty_out(vty, "\n"); | |
6223 | } | |
6224 | } | |
6225 | } | |
6226 | ||
6227 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6228 | switch (type) { | |
6229 | case OSPF_AS_EXTERNAL_LSA: | |
6230 | case OSPF_OPAQUE_AS_LSA: | |
6231 | break; | |
6232 | default: | |
6233 | continue; | |
6234 | } | |
6235 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6236 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
6237 | vty_out(vty, " %s\n\n", | |
6238 | show_database_desc[type]); | |
6239 | vty_out(vty, "%s\n", show_database_header[type]); | |
6240 | ||
996c9314 | 6241 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) |
044506e7 | 6242 | show_lsa_summary(vty, lsa, self); |
d62a17ae | 6243 | |
6244 | vty_out(vty, "\n"); | |
6245 | } | |
6246 | } | |
6247 | ||
6248 | vty_out(vty, "\n"); | |
6249 | } | |
6250 | ||
6251 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) | |
6252 | { | |
6253 | struct route_node *rn; | |
6254 | ||
6255 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6256 | ||
6257 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6258 | struct ospf_lsa *lsa; | |
6259 | ||
6260 | if ((lsa = rn->info) != NULL) { | |
6261 | vty_out(vty, "Link type: %d\n", lsa->data->type); | |
6262 | vty_out(vty, "Link State ID: %s\n", | |
6263 | inet_ntoa(lsa->data->id)); | |
6264 | vty_out(vty, "Advertising Router: %s\n", | |
6265 | inet_ntoa(lsa->data->adv_router)); | |
6266 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6267 | vty_out(vty, "\n"); | |
6268 | } | |
91e6a0e5 | 6269 | } |
718e3744 | 6270 | } |
6271 | ||
718e3744 | 6272 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6273 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6274 | |
718e3744 | 6275 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6276 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6277 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6278 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6279 | |
d62a17ae | 6280 | #define OSPF_LSA_TYPES_DESC \ |
6281 | "ASBR summary link states\n" \ | |
6282 | "External link states\n" \ | |
6283 | "Network link states\n" \ | |
6284 | "Router link states\n" \ | |
6285 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6286 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6287 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6288 | ||
6289 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6290 | int arg_base, int argc, | |
d7c0a89a QY |
6291 | struct cmd_token **argv, |
6292 | uint8_t use_vrf) | |
d62a17ae | 6293 | { |
6294 | int idx_type = 4; | |
6295 | int type, ret; | |
6296 | struct in_addr id, adv_router; | |
6297 | ||
6298 | if (ospf->instance) | |
6299 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6300 | ||
b1c3ae8c | 6301 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 6302 | |
d62a17ae | 6303 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6304 | inet_ntoa(ospf->router_id)); | |
6305 | ||
6306 | /* Show all LSA. */ | |
6307 | if (argc == arg_base + 4) { | |
6308 | show_ip_ospf_database_summary(vty, ospf, 0); | |
6309 | return CMD_SUCCESS; | |
6310 | } | |
718e3744 | 6311 | |
d62a17ae | 6312 | /* Set database type to show. */ |
6313 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6314 | type = OSPF_ROUTER_LSA; | |
6315 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6316 | type = OSPF_NETWORK_LSA; | |
6317 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6318 | type = OSPF_AS_NSSA_LSA; | |
6319 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
6320 | type = OSPF_SUMMARY_LSA; | |
6321 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6322 | type = OSPF_ASBR_SUMMARY_LSA; | |
6323 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6324 | type = OSPF_AS_EXTERNAL_LSA; | |
6325 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
6326 | show_ip_ospf_database_summary(vty, ospf, 1); | |
6327 | return CMD_SUCCESS; | |
6328 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
6329 | show_ip_ospf_database_maxage(vty, ospf); | |
6330 | return CMD_SUCCESS; | |
6331 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6332 | type = OSPF_OPAQUE_LINK_LSA; | |
6333 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6334 | type = OSPF_OPAQUE_AREA_LSA; | |
6335 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6336 | type = OSPF_OPAQUE_AS_LSA; | |
6337 | else | |
718e3744 | 6338 | return CMD_WARNING; |
d62a17ae | 6339 | |
6340 | /* `show ip ospf database LSA'. */ | |
6341 | if (argc == arg_base + 5) | |
6342 | show_lsa_detail(vty, ospf, type, NULL, NULL); | |
6343 | else if (argc >= arg_base + 6) { | |
6344 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
6345 | if (!ret) | |
6346 | return CMD_WARNING; | |
6347 | ||
6348 | /* `show ip ospf database LSA ID'. */ | |
6349 | if (argc == arg_base + 6) | |
6350 | show_lsa_detail(vty, ospf, type, &id, NULL); | |
6351 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ | |
6352 | else if (argc == arg_base + 7) { | |
6353 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) | |
6354 | adv_router = ospf->router_id; | |
6355 | else { | |
6356 | ret = inet_aton(argv[arg_base + 7]->arg, | |
6357 | &adv_router); | |
6358 | if (!ret) | |
6359 | return CMD_WARNING; | |
6360 | } | |
6361 | show_lsa_detail(vty, ospf, type, &id, &adv_router); | |
6362 | } | |
718e3744 | 6363 | } |
718e3744 | 6364 | |
d62a17ae | 6365 | return CMD_SUCCESS; |
718e3744 | 6366 | } |
6367 | ||
7a7be519 | 6368 | DEFUN (show_ip_ospf_database_max, |
6369 | show_ip_ospf_database_max_cmd, | |
b5a8894d | 6370 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>", |
7a7be519 | 6371 | SHOW_STR |
6372 | IP_STR | |
6373 | "OSPF information\n" | |
b5a8894d CS |
6374 | VRF_CMD_HELP_STR |
6375 | "All VRFs\n" | |
7a7be519 | 6376 | "Database summary\n" |
6377 | "LSAs in MaxAge list\n" | |
6378 | "Self-originated link states\n") | |
6379 | { | |
b5a8894d CS |
6380 | struct ospf *ospf = NULL; |
6381 | struct listnode *node = NULL; | |
6382 | char *vrf_name = NULL; | |
2951a7a4 | 6383 | bool all_vrf = false; |
b5a8894d CS |
6384 | int ret = CMD_SUCCESS; |
6385 | int inst = 0; | |
6386 | int idx_vrf = 0; | |
d7c0a89a | 6387 | uint8_t use_vrf = 0; |
f412b39a | 6388 | |
43b8d1d8 | 6389 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 6390 | |
b5a8894d | 6391 | if (vrf_name) { |
2951a7a4 | 6392 | bool ospf_output = false; |
874f58d8 | 6393 | |
b1c3ae8c | 6394 | use_vrf = 1; |
94d4c685 | 6395 | |
b5a8894d CS |
6396 | if (all_vrf) { |
6397 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6398 | if (!ospf->oi_running) | |
6399 | continue; | |
2951a7a4 | 6400 | ospf_output = true; |
996c9314 LB |
6401 | ret = show_ip_ospf_database_common( |
6402 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
6403 | use_vrf); | |
b5a8894d | 6404 | } |
9f049418 DS |
6405 | |
6406 | if (!ospf_output) | |
6407 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
6408 | } else { |
6409 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6410 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6411 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6412 | return CMD_SUCCESS; |
9f049418 | 6413 | } |
996c9314 LB |
6414 | ret = (show_ip_ospf_database_common( |
6415 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
6416 | use_vrf)); | |
b5a8894d CS |
6417 | } |
6418 | } else { | |
6419 | /* Display default ospf (instance 0) info */ | |
6420 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6421 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6422 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6423 | return CMD_SUCCESS; |
9f049418 DS |
6424 | } |
6425 | ||
b1c3ae8c CS |
6426 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
6427 | use_vrf); | |
b5a8894d CS |
6428 | } |
6429 | ||
6430 | return ret; | |
7a7be519 | 6431 | } |
f412b39a | 6432 | |
f412b39a DW |
6433 | DEFUN (show_ip_ospf_instance_database, |
6434 | show_ip_ospf_instance_database_cmd, | |
43b8d1d8 | 6435 | "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 | 6436 | SHOW_STR |
6437 | IP_STR | |
6438 | "OSPF information\n" | |
7c8ff89e | 6439 | "Instance ID\n" |
b5a8894d | 6440 | VRF_CMD_HELP_STR |
7a7be519 | 6441 | "Database summary\n" |
6442 | OSPF_LSA_TYPES_DESC | |
6443 | "Link State ID (as an IP address)\n" | |
6444 | "Self-originated link states\n" | |
6445 | "Advertising Router link states\n" | |
6446 | "Advertising Router (as an IP address)\n") | |
7c8ff89e | 6447 | { |
d62a17ae | 6448 | struct ospf *ospf; |
d7c0a89a | 6449 | unsigned short instance = 0; |
b5a8894d CS |
6450 | struct listnode *node = NULL; |
6451 | char *vrf_name = NULL; | |
2951a7a4 | 6452 | bool all_vrf = false; |
b5a8894d CS |
6453 | int ret = CMD_SUCCESS; |
6454 | int inst = 0; | |
d62a17ae | 6455 | int idx = 0; |
d7c0a89a | 6456 | uint8_t use_vrf = 0; |
b5a8894d | 6457 | |
d62a17ae | 6458 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6459 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6460 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6461 | if (ospf == NULL) |
6462 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
6463 | if (!ospf->oi_running) |
6464 | return CMD_SUCCESS; | |
6465 | ||
6466 | return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, | |
b1c3ae8c | 6467 | argc, argv, use_vrf)); |
b5a8894d CS |
6468 | } else if (argv_find(argv, argc, "vrf", &idx)) { |
6469 | vrf_name = argv[++idx]->arg; | |
6470 | all_vrf = strmatch(vrf_name, "all"); | |
d62a17ae | 6471 | } |
7c8ff89e | 6472 | |
b5a8894d | 6473 | if (vrf_name) { |
b1c3ae8c | 6474 | use_vrf = 1; |
b5a8894d CS |
6475 | if (all_vrf) { |
6476 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6477 | if (!ospf->oi_running) | |
6478 | continue; | |
996c9314 LB |
6479 | ret = (show_ip_ospf_database_common( |
6480 | vty, ospf, idx ? 2 : 0, argc, argv, | |
6481 | use_vrf)); | |
b5a8894d CS |
6482 | } |
6483 | } else { | |
6484 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6485 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 6486 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6487 | return CMD_SUCCESS; |
9f049418 DS |
6488 | } |
6489 | ||
996c9314 LB |
6490 | ret = (show_ip_ospf_database_common( |
6491 | vty, ospf, idx ? 2 : 0, argc, argv, use_vrf)); | |
b5a8894d CS |
6492 | } |
6493 | } else { | |
6494 | /* Display default ospf (instance 0) info */ | |
6495 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6496 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6497 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6498 | return CMD_SUCCESS; |
9f049418 DS |
6499 | } |
6500 | ||
b1c3ae8c CS |
6501 | ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
6502 | use_vrf)); | |
b5a8894d | 6503 | } |
7c8ff89e | 6504 | |
b5a8894d | 6505 | return ret; |
7c8ff89e DS |
6506 | } |
6507 | ||
7a7be519 | 6508 | DEFUN (show_ip_ospf_instance_database_max, |
6509 | show_ip_ospf_instance_database_max_cmd, | |
6510 | "show ip ospf (1-65535) database <max-age|self-originate>", | |
6511 | SHOW_STR | |
6512 | IP_STR | |
6513 | "OSPF information\n" | |
6514 | "Instance ID\n" | |
6515 | "Database summary\n" | |
6516 | "LSAs in MaxAge list\n" | |
6517 | "Self-originated link states\n") | |
6518 | { | |
d62a17ae | 6519 | int idx_number = 3; |
6520 | struct ospf *ospf; | |
d7c0a89a | 6521 | unsigned short instance = 0; |
d62a17ae | 6522 | |
6523 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
6524 | ||
ac28e4ec CS |
6525 | ospf = ospf_lookup_instance(instance); |
6526 | if (ospf == NULL) | |
6527 | return CMD_NOT_MY_INSTANCE; | |
6528 | ||
9f049418 | 6529 | if (!ospf->oi_running) { |
94d4c685 | 6530 | vty_out(vty, "%% OSPF instance not found\n"); |
d62a17ae | 6531 | return CMD_SUCCESS; |
9f049418 | 6532 | } |
d62a17ae | 6533 | |
b1c3ae8c | 6534 | return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0); |
d62a17ae | 6535 | } |
6536 | ||
6537 | ||
6538 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
6539 | struct ospf *ospf, | |
6540 | int arg_base, int argc, | |
b1c3ae8c | 6541 | struct cmd_token **argv, |
d7c0a89a | 6542 | uint8_t use_vrf) |
d62a17ae | 6543 | { |
6544 | int idx_type = 4; | |
6545 | int type, ret; | |
6546 | struct in_addr adv_router; | |
6547 | ||
6548 | if (ospf->instance) | |
6549 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6550 | ||
b1c3ae8c | 6551 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 6552 | |
d62a17ae | 6553 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6554 | inet_ntoa(ospf->router_id)); | |
6555 | ||
6556 | /* Set database type to show. */ | |
6557 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6558 | type = OSPF_ROUTER_LSA; | |
6559 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6560 | type = OSPF_NETWORK_LSA; | |
6561 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6562 | type = OSPF_AS_NSSA_LSA; | |
6563 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
6564 | type = OSPF_SUMMARY_LSA; | |
6565 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6566 | type = OSPF_ASBR_SUMMARY_LSA; | |
6567 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6568 | type = OSPF_AS_EXTERNAL_LSA; | |
6569 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6570 | type = OSPF_OPAQUE_LINK_LSA; | |
6571 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6572 | type = OSPF_OPAQUE_AREA_LSA; | |
6573 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6574 | type = OSPF_OPAQUE_AS_LSA; | |
6575 | else | |
6576 | return CMD_WARNING; | |
7c8ff89e | 6577 | |
d62a17ae | 6578 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
6579 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
6580 | adv_router = ospf->router_id; | |
6581 | else { | |
6582 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
6583 | if (!ret) | |
6584 | return CMD_WARNING; | |
6585 | } | |
7c8ff89e | 6586 | |
d62a17ae | 6587 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router); |
7c8ff89e | 6588 | |
d62a17ae | 6589 | return CMD_SUCCESS; |
7c8ff89e DS |
6590 | } |
6591 | ||
7c8ff89e DS |
6592 | DEFUN (show_ip_ospf_instance_database_type_adv_router, |
6593 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
43b8d1d8 | 6594 | "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 |
6595 | SHOW_STR |
6596 | IP_STR | |
6597 | "OSPF information\n" | |
6598 | "Instance ID\n" | |
b5a8894d | 6599 | VRF_CMD_HELP_STR |
7c8ff89e DS |
6600 | "Database summary\n" |
6601 | OSPF_LSA_TYPES_DESC | |
6602 | "Advertising Router link states\n" | |
3a2d747c QY |
6603 | "Advertising Router (as an IP address)\n" |
6604 | "Self-originated link states\n") | |
7c8ff89e | 6605 | { |
b5a8894d | 6606 | struct ospf *ospf = NULL; |
d7c0a89a | 6607 | unsigned short instance = 0; |
b5a8894d CS |
6608 | struct listnode *node = NULL; |
6609 | char *vrf_name = NULL; | |
2951a7a4 | 6610 | bool all_vrf = false; |
b5a8894d CS |
6611 | int ret = CMD_SUCCESS; |
6612 | int inst = 0; | |
43b8d1d8 | 6613 | int idx = 0, idx_vrf = 0; |
d7c0a89a | 6614 | uint8_t use_vrf = 0; |
7c8ff89e | 6615 | |
d62a17ae | 6616 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6617 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6618 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6619 | if (ospf == NULL) |
6620 | return CMD_NOT_MY_INSTANCE; | |
9f049418 | 6621 | if (!ospf->oi_running) { |
94d4c685 | 6622 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6623 | return CMD_SUCCESS; |
9f049418 DS |
6624 | } |
6625 | ||
996c9314 LB |
6626 | return (show_ip_ospf_database_type_adv_router_common( |
6627 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf)); | |
b5a8894d | 6628 | } |
43b8d1d8 CS |
6629 | |
6630 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
6631 | ||
b5a8894d | 6632 | if (vrf_name) { |
2951a7a4 | 6633 | bool ospf_output = false; |
874f58d8 | 6634 | |
b1c3ae8c | 6635 | use_vrf = 1; |
94d4c685 | 6636 | |
b5a8894d CS |
6637 | if (all_vrf) { |
6638 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6639 | if (!ospf->oi_running) | |
6640 | continue; | |
2951a7a4 | 6641 | ospf_output = true; |
996c9314 LB |
6642 | ret = show_ip_ospf_database_type_adv_router_common( |
6643 | vty, ospf, idx ? 1 : 0, argc, argv, | |
6644 | use_vrf); | |
b5a8894d | 6645 | } |
9f049418 DS |
6646 | if (!ospf_output) |
6647 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
6648 | } else { |
6649 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6650 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 6651 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6652 | return CMD_SUCCESS; |
9f049418 DS |
6653 | } |
6654 | ||
996c9314 LB |
6655 | ret = show_ip_ospf_database_type_adv_router_common( |
6656 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf); | |
b5a8894d CS |
6657 | } |
6658 | } else { | |
6659 | /* Display default ospf (instance 0) info */ | |
6660 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6661 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6662 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6663 | return CMD_SUCCESS; |
9f049418 DS |
6664 | } |
6665 | ||
996c9314 LB |
6666 | ret = show_ip_ospf_database_type_adv_router_common( |
6667 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf); | |
b5a8894d CS |
6668 | } |
6669 | return ret; | |
6670 | /*return (show_ip_ospf_database_type_adv_router_common( | |
6671 | vty, ospf, idx ? 1 : 0, argc, argv));*/ | |
718e3744 | 6672 | } |
6673 | ||
718e3744 | 6674 | DEFUN (ip_ospf_authentication_args, |
6675 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6676 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 6677 | "IP Information\n" |
6678 | "OSPF interface commands\n" | |
6679 | "Enable authentication on this interface\n" | |
6680 | "Use null authentication\n" | |
6681 | "Use message-digest authentication\n" | |
7a7be519 | 6682 | "Address of interface\n") |
718e3744 | 6683 | { |
d62a17ae | 6684 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6685 | int idx_encryption = 3; | |
6686 | int idx_ipv4 = 4; | |
6687 | struct in_addr addr; | |
6688 | int ret; | |
6689 | struct ospf_if_params *params; | |
6690 | ||
6691 | params = IF_DEF_PARAMS(ifp); | |
6692 | ||
6693 | if (argc == 5) { | |
6694 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6695 | if (!ret) { | |
6696 | vty_out(vty, | |
6697 | "Please specify interface address by A.B.C.D\n"); | |
6698 | return CMD_WARNING_CONFIG_FAILED; | |
6699 | } | |
718e3744 | 6700 | |
d62a17ae | 6701 | params = ospf_get_if_params(ifp, addr); |
6702 | ospf_if_update_params(ifp, addr); | |
6703 | } | |
718e3744 | 6704 | |
d62a17ae | 6705 | /* Handle null authentication */ |
6706 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6707 | SET_IF_PARAM(params, auth_type); | |
6708 | params->auth_type = OSPF_AUTH_NULL; | |
6709 | return CMD_SUCCESS; | |
6710 | } | |
718e3744 | 6711 | |
d62a17ae | 6712 | /* Handle message-digest authentication */ |
6713 | if (argv[idx_encryption]->arg[0] == 'm') { | |
6714 | SET_IF_PARAM(params, auth_type); | |
6715 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6716 | return CMD_SUCCESS; | |
6717 | } | |
718e3744 | 6718 | |
d62a17ae | 6719 | vty_out(vty, "You shouldn't get here!\n"); |
6720 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 6721 | } |
6722 | ||
718e3744 | 6723 | DEFUN (ip_ospf_authentication, |
6724 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6725 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 6726 | "IP Information\n" |
6727 | "OSPF interface commands\n" | |
6728 | "Enable authentication on this interface\n" | |
efd7904e | 6729 | "Address of interface\n") |
718e3744 | 6730 | { |
d62a17ae | 6731 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6732 | int idx_ipv4 = 3; | |
6733 | struct in_addr addr; | |
6734 | int ret; | |
6735 | struct ospf_if_params *params; | |
6736 | ||
6737 | params = IF_DEF_PARAMS(ifp); | |
6738 | ||
6739 | if (argc == 4) { | |
6740 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6741 | if (!ret) { | |
6742 | vty_out(vty, | |
6743 | "Please specify interface address by A.B.C.D\n"); | |
6744 | return CMD_WARNING_CONFIG_FAILED; | |
6745 | } | |
6746 | ||
6747 | params = ospf_get_if_params(ifp, addr); | |
6748 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6749 | } |
6750 | ||
d62a17ae | 6751 | SET_IF_PARAM(params, auth_type); |
6752 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 6753 | |
d62a17ae | 6754 | return CMD_SUCCESS; |
718e3744 | 6755 | } |
6756 | ||
b4a039bf DS |
6757 | DEFUN (no_ip_ospf_authentication_args, |
6758 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6759 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
6760 | NO_STR |
6761 | "IP Information\n" | |
6762 | "OSPF interface commands\n" | |
6763 | "Enable authentication on this interface\n" | |
6764 | "Use null authentication\n" | |
6765 | "Use message-digest authentication\n" | |
efd7904e | 6766 | "Address of interface\n") |
b4a039bf | 6767 | { |
d62a17ae | 6768 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6769 | int idx_encryption = 4; | |
6770 | int idx_ipv4 = 5; | |
6771 | struct in_addr addr; | |
6772 | int ret; | |
6773 | struct ospf_if_params *params; | |
6774 | struct route_node *rn; | |
6775 | int auth_type; | |
6776 | ||
6777 | params = IF_DEF_PARAMS(ifp); | |
6778 | ||
6779 | if (argc == 6) { | |
6780 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6781 | if (!ret) { | |
6782 | vty_out(vty, | |
6783 | "Please specify interface address by A.B.C.D\n"); | |
6784 | return CMD_WARNING_CONFIG_FAILED; | |
6785 | } | |
b4a039bf | 6786 | |
d62a17ae | 6787 | params = ospf_lookup_if_params(ifp, addr); |
6788 | if (params == NULL) { | |
6789 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6790 | return CMD_WARNING_CONFIG_FAILED; | |
6791 | } | |
6792 | params->auth_type = OSPF_AUTH_NOTSET; | |
6793 | UNSET_IF_PARAM(params, auth_type); | |
6794 | if (params != IF_DEF_PARAMS(ifp)) { | |
6795 | ospf_free_if_params(ifp, addr); | |
6796 | ospf_if_update_params(ifp, addr); | |
6797 | } | |
6798 | } else { | |
6799 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6800 | auth_type = OSPF_AUTH_NULL; | |
6801 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
6802 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6803 | } else { | |
6804 | vty_out(vty, "Unexpected input encountered\n"); | |
6805 | return CMD_WARNING_CONFIG_FAILED; | |
6806 | } | |
6807 | /* | |
6808 | * Here we have a case where the user has entered | |
6809 | * 'no ip ospf authentication (null | message_digest )' | |
6810 | * we need to find if we have any ip addresses underneath it | |
6811 | * that | |
6812 | * correspond to the associated type. | |
6813 | */ | |
6814 | if (params->auth_type == auth_type) { | |
6815 | params->auth_type = OSPF_AUTH_NOTSET; | |
6816 | UNSET_IF_PARAM(params, auth_type); | |
6817 | } | |
6818 | ||
6819 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
6820 | rn = route_next(rn)) { | |
6821 | if ((params = rn->info)) { | |
6822 | if (params->auth_type == auth_type) { | |
6823 | params->auth_type = OSPF_AUTH_NOTSET; | |
6824 | UNSET_IF_PARAM(params, auth_type); | |
6825 | if (params != IF_DEF_PARAMS(ifp)) { | |
6826 | ospf_free_if_params( | |
6827 | ifp, rn->p.u.prefix4); | |
6828 | ospf_if_update_params( | |
6829 | ifp, rn->p.u.prefix4); | |
6830 | } | |
6831 | } | |
6832 | } | |
b4a039bf | 6833 | } |
b4a039bf | 6834 | } |
b4a039bf | 6835 | |
d62a17ae | 6836 | return CMD_SUCCESS; |
b4a039bf DS |
6837 | } |
6838 | ||
718e3744 | 6839 | DEFUN (no_ip_ospf_authentication, |
6840 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6841 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 6842 | NO_STR |
6843 | "IP Information\n" | |
6844 | "OSPF interface commands\n" | |
6845 | "Enable authentication on this interface\n" | |
efd7904e | 6846 | "Address of interface\n") |
718e3744 | 6847 | { |
d62a17ae | 6848 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6849 | int idx_ipv4 = 4; | |
6850 | struct in_addr addr; | |
6851 | int ret; | |
6852 | struct ospf_if_params *params; | |
6853 | struct route_node *rn; | |
6854 | ||
6855 | params = IF_DEF_PARAMS(ifp); | |
6856 | ||
6857 | if (argc == 5) { | |
6858 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6859 | if (!ret) { | |
6860 | vty_out(vty, | |
6861 | "Please specify interface address by A.B.C.D\n"); | |
6862 | return CMD_WARNING_CONFIG_FAILED; | |
6863 | } | |
718e3744 | 6864 | |
d62a17ae | 6865 | params = ospf_lookup_if_params(ifp, addr); |
6866 | if (params == NULL) { | |
6867 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6868 | return CMD_WARNING_CONFIG_FAILED; | |
6869 | } | |
718e3744 | 6870 | |
d62a17ae | 6871 | params->auth_type = OSPF_AUTH_NOTSET; |
6872 | UNSET_IF_PARAM(params, auth_type); | |
6873 | if (params != IF_DEF_PARAMS(ifp)) { | |
6874 | ospf_free_if_params(ifp, addr); | |
6875 | ospf_if_update_params(ifp, addr); | |
6876 | } | |
6877 | } else { | |
6878 | /* | |
6879 | * When a user enters 'no ip ospf authentication' | |
6880 | * We should remove all authentication types from | |
6881 | * the interface. | |
6882 | */ | |
6883 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6884 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
6885 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
6886 | params->auth_type = OSPF_AUTH_NOTSET; | |
6887 | UNSET_IF_PARAM(params, auth_type); | |
6888 | } | |
813d4307 | 6889 | |
d62a17ae | 6890 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
6891 | rn = route_next(rn)) { | |
6892 | if ((params = rn->info)) { | |
6893 | ||
6894 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6895 | || (params->auth_type | |
6896 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
6897 | || (params->auth_type | |
6898 | == OSPF_AUTH_SIMPLE)) { | |
6899 | params->auth_type = OSPF_AUTH_NOTSET; | |
6900 | UNSET_IF_PARAM(params, auth_type); | |
6901 | if (params != IF_DEF_PARAMS(ifp)) { | |
6902 | ospf_free_if_params( | |
6903 | ifp, rn->p.u.prefix4); | |
6904 | ospf_if_update_params( | |
6905 | ifp, rn->p.u.prefix4); | |
6906 | } | |
6907 | } | |
6908 | } | |
b4a039bf | 6909 | } |
b4a039bf | 6910 | } |
d62a17ae | 6911 | |
6912 | return CMD_SUCCESS; | |
718e3744 | 6913 | } |
6914 | ||
0d829fa7 | 6915 | |
718e3744 | 6916 | DEFUN (ip_ospf_authentication_key, |
6917 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 6918 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 6919 | "IP Information\n" |
6920 | "OSPF interface commands\n" | |
6921 | "Authentication password (key)\n" | |
6922 | "The OSPF password (key)\n" | |
efd7904e | 6923 | "Address of interface\n") |
718e3744 | 6924 | { |
d62a17ae | 6925 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6926 | int idx = 0; | |
6927 | struct in_addr addr; | |
6928 | struct ospf_if_params *params; | |
718e3744 | 6929 | |
d62a17ae | 6930 | params = IF_DEF_PARAMS(ifp); |
6931 | ||
6932 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6933 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6934 | vty_out(vty, | |
6935 | "Please specify interface address by A.B.C.D\n"); | |
6936 | return CMD_WARNING_CONFIG_FAILED; | |
6937 | } | |
718e3744 | 6938 | |
d62a17ae | 6939 | params = ospf_get_if_params(ifp, addr); |
6940 | ospf_if_update_params(ifp, addr); | |
6941 | } | |
718e3744 | 6942 | |
4d65d927 QY |
6943 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
6944 | sizeof(params->auth_simple)); | |
d62a17ae | 6945 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 6946 | |
d62a17ae | 6947 | return CMD_SUCCESS; |
718e3744 | 6948 | } |
6949 | ||
7a7be519 | 6950 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 6951 | ospf_authentication_key_cmd, |
0d829fa7 | 6952 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 6953 | "OSPF interface commands\n" |
baf9eaad | 6954 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 6955 | "Address of interface\n") |
718e3744 | 6956 | { |
d62a17ae | 6957 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 6958 | } |
6959 | ||
7a7be519 | 6960 | DEFUN (no_ip_ospf_authentication_key, |
6961 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
6962 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6963 | NO_STR | |
6964 | "IP Information\n" | |
6965 | "OSPF interface commands\n" | |
baf9eaad CS |
6966 | VLINK_HELPSTR_AUTH_SIMPLE |
6967 | "Address of interface\n") | |
7a7be519 | 6968 | { |
d62a17ae | 6969 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6970 | int idx = 0; | |
6971 | struct in_addr addr; | |
6972 | struct ospf_if_params *params; | |
6973 | params = IF_DEF_PARAMS(ifp); | |
6974 | ||
6975 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6976 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6977 | vty_out(vty, | |
6978 | "Please specify interface address by A.B.C.D\n"); | |
6979 | return CMD_WARNING_CONFIG_FAILED; | |
6980 | } | |
7a7be519 | 6981 | |
d62a17ae | 6982 | params = ospf_lookup_if_params(ifp, addr); |
6983 | if (params == NULL) | |
6984 | return CMD_SUCCESS; | |
7a7be519 | 6985 | } |
813d4307 | 6986 | |
d62a17ae | 6987 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
6988 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 6989 | |
d62a17ae | 6990 | if (params != IF_DEF_PARAMS(ifp)) { |
6991 | ospf_free_if_params(ifp, addr); | |
6992 | ospf_if_update_params(ifp, addr); | |
6993 | } | |
813d4307 | 6994 | |
d62a17ae | 6995 | return CMD_SUCCESS; |
7a7be519 | 6996 | } |
813d4307 | 6997 | |
0d829fa7 QY |
6998 | DEFUN_HIDDEN (no_ospf_authentication_key, |
6999 | no_ospf_authentication_key_authkey_addr_cmd, | |
7000 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7001 | NO_STR | |
7002 | "OSPF interface commands\n" | |
baf9eaad CS |
7003 | VLINK_HELPSTR_AUTH_SIMPLE |
7004 | "Address of interface\n") | |
0d829fa7 | 7005 | { |
d62a17ae | 7006 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
7007 | } |
7008 | ||
718e3744 | 7009 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 7010 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 7011 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 7012 | "IP Information\n" |
7013 | "OSPF interface commands\n" | |
7014 | "Message digest authentication password (key)\n" | |
7015 | "Key ID\n" | |
7016 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
7017 | "The OSPF password (key)\n" |
7018 | "Address of interface\n") | |
718e3744 | 7019 | { |
d62a17ae | 7020 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7021 | struct crypt_key *ck; | |
d7c0a89a | 7022 | uint8_t key_id; |
d62a17ae | 7023 | struct in_addr addr; |
7024 | struct ospf_if_params *params; | |
7025 | ||
7026 | params = IF_DEF_PARAMS(ifp); | |
7027 | int idx = 0; | |
7028 | ||
7029 | argv_find(argv, argc, "(1-255)", &idx); | |
7030 | char *keyid = argv[idx]->arg; | |
7031 | argv_find(argv, argc, "KEY", &idx); | |
7032 | char *cryptkey = argv[idx]->arg; | |
7033 | ||
7034 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7035 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7036 | vty_out(vty, | |
7037 | "Please specify interface address by A.B.C.D\n"); | |
7038 | return CMD_WARNING_CONFIG_FAILED; | |
7039 | } | |
7040 | ||
7041 | params = ospf_get_if_params(ifp, addr); | |
7042 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7043 | } |
7044 | ||
d62a17ae | 7045 | key_id = strtol(keyid, NULL, 10); |
7046 | if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) { | |
7047 | vty_out(vty, "OSPF: Key %d already exists\n", key_id); | |
851fcbae | 7048 | return CMD_WARNING; |
d62a17ae | 7049 | } |
718e3744 | 7050 | |
d62a17ae | 7051 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7052 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7053 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7054 | |
d62a17ae | 7055 | ospf_crypt_key_add(params->auth_crypt, ck); |
7056 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7057 | |
d62a17ae | 7058 | return CMD_SUCCESS; |
718e3744 | 7059 | } |
7060 | ||
7a7be519 | 7061 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7062 | ospf_message_digest_key_cmd, |
0d829fa7 | 7063 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7064 | "OSPF interface commands\n" |
7065 | "Message digest authentication password (key)\n" | |
7066 | "Key ID\n" | |
7067 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7068 | "The OSPF password (key)\n" |
7069 | "Address of interface\n") | |
7a7be519 | 7070 | { |
d62a17ae | 7071 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7072 | } |
718e3744 | 7073 | |
537eae3f QY |
7074 | DEFUN (no_ip_ospf_message_digest_key, |
7075 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7076 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7077 | NO_STR |
7078 | "IP Information\n" | |
7079 | "OSPF interface commands\n" | |
7080 | "Message digest authentication password (key)\n" | |
7081 | "Key ID\n" | |
7082 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7083 | "The OSPF password (key)\n" |
7084 | "Address of interface\n") | |
813d4307 | 7085 | { |
d62a17ae | 7086 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7087 | int idx = 0; | |
7088 | struct crypt_key *ck; | |
7089 | int key_id; | |
7090 | struct in_addr addr; | |
7091 | struct ospf_if_params *params; | |
7092 | params = IF_DEF_PARAMS(ifp); | |
7093 | ||
7094 | argv_find(argv, argc, "(1-255)", &idx); | |
7095 | char *keyid = argv[idx]->arg; | |
7096 | ||
7097 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7098 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7099 | vty_out(vty, | |
7100 | "Please specify interface address by A.B.C.D\n"); | |
7101 | return CMD_WARNING_CONFIG_FAILED; | |
7102 | } | |
7a7be519 | 7103 | |
d62a17ae | 7104 | params = ospf_lookup_if_params(ifp, addr); |
7105 | if (params == NULL) | |
7106 | return CMD_SUCCESS; | |
7a7be519 | 7107 | } |
7108 | ||
d62a17ae | 7109 | key_id = strtol(keyid, NULL, 10); |
7110 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7111 | if (ck == NULL) { | |
7112 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7113 | return CMD_WARNING_CONFIG_FAILED; | |
7114 | } | |
7a7be519 | 7115 | |
d62a17ae | 7116 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7117 | |
d62a17ae | 7118 | if (params != IF_DEF_PARAMS(ifp)) { |
7119 | ospf_free_if_params(ifp, addr); | |
7120 | ospf_if_update_params(ifp, addr); | |
7121 | } | |
7a7be519 | 7122 | |
d62a17ae | 7123 | return CMD_SUCCESS; |
7a7be519 | 7124 | } |
813d4307 | 7125 | |
0d829fa7 | 7126 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7127 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7128 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7129 | NO_STR | |
7130 | "OSPF interface commands\n" | |
7131 | "Message digest authentication password (key)\n" | |
7132 | "Key ID\n" | |
efd7904e RW |
7133 | "Use MD5 algorithm\n" |
7134 | "The OSPF password (key)\n" | |
7135 | "Address of interface\n") | |
718e3744 | 7136 | { |
d62a17ae | 7137 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7138 | } |
7139 | ||
718e3744 | 7140 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7141 | ip_ospf_cost_cmd, |
7a7be519 | 7142 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7143 | "IP Information\n" |
7144 | "OSPF interface commands\n" | |
7145 | "Interface cost\n" | |
7146 | "Cost\n" | |
5c2fc921 | 7147 | "Address of interface\n") |
718e3744 | 7148 | { |
d62a17ae | 7149 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7150 | int idx = 0; | |
d7c0a89a | 7151 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7152 | struct in_addr addr; |
7153 | struct ospf_if_params *params; | |
7154 | params = IF_DEF_PARAMS(ifp); | |
7155 | ||
7156 | // get arguments | |
7157 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7158 | |
c31a793b VJ |
7159 | argv_find(argv, argc, "(1-65535)", &idx); |
7160 | coststr = argv[idx]->arg; | |
d62a17ae | 7161 | cost = strtol(coststr, NULL, 10); |
7162 | ||
c31a793b | 7163 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7164 | if (ifaddr) { |
7165 | if (!inet_aton(ifaddr, &addr)) { | |
7166 | vty_out(vty, | |
7167 | "Please specify interface address by A.B.C.D\n"); | |
7168 | return CMD_WARNING_CONFIG_FAILED; | |
7169 | } | |
718e3744 | 7170 | |
d62a17ae | 7171 | params = ospf_get_if_params(ifp, addr); |
7172 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7173 | } |
7174 | ||
d62a17ae | 7175 | SET_IF_PARAM(params, output_cost_cmd); |
7176 | params->output_cost_cmd = cost; | |
718e3744 | 7177 | |
d62a17ae | 7178 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 7179 | |
d62a17ae | 7180 | return CMD_SUCCESS; |
718e3744 | 7181 | } |
7182 | ||
7a7be519 | 7183 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
7184 | ospf_cost_cmd, |
7185 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
7186 | "OSPF interface commands\n" |
7187 | "Interface cost\n" | |
7188 | "Cost\n" | |
5c2fc921 | 7189 | "Address of interface\n") |
7a7be519 | 7190 | { |
d62a17ae | 7191 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 7192 | } |
9eff36b3 | 7193 | |
718e3744 | 7194 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
7195 | no_ip_ospf_cost_cmd, |
7196 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 7197 | NO_STR |
efd7904e | 7198 | "IP Information\n" |
718e3744 | 7199 | "OSPF interface commands\n" |
7200 | "Interface cost\n" | |
efd7904e RW |
7201 | "Cost\n" |
7202 | "Address of interface\n") | |
718e3744 | 7203 | { |
d62a17ae | 7204 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7205 | int idx = 0; | |
7206 | struct in_addr addr; | |
7207 | struct ospf_if_params *params; | |
7a7be519 | 7208 | |
d62a17ae | 7209 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7210 | |
d62a17ae | 7211 | // get arguments |
7212 | char *ifaddr = NULL; | |
7213 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 7214 | |
d62a17ae | 7215 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
7216 | * always treated as "no ip ospf cost" regardless of the actual value | |
7217 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 7218 | |
d62a17ae | 7219 | if (ifaddr) { |
7220 | if (!inet_aton(ifaddr, &addr)) { | |
7221 | vty_out(vty, | |
7222 | "Please specify interface address by A.B.C.D\n"); | |
7223 | return CMD_WARNING_CONFIG_FAILED; | |
7224 | } | |
7a7be519 | 7225 | |
d62a17ae | 7226 | params = ospf_lookup_if_params(ifp, addr); |
7227 | if (params == NULL) | |
7228 | return CMD_SUCCESS; | |
7229 | } | |
7a7be519 | 7230 | |
d62a17ae | 7231 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 7232 | |
d62a17ae | 7233 | if (params != IF_DEF_PARAMS(ifp)) { |
7234 | ospf_free_if_params(ifp, addr); | |
7235 | ospf_if_update_params(ifp, addr); | |
7236 | } | |
7a7be519 | 7237 | |
d62a17ae | 7238 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 7239 | |
d62a17ae | 7240 | return CMD_SUCCESS; |
7a7be519 | 7241 | } |
9eff36b3 | 7242 | |
5c2fc921 QY |
7243 | DEFUN_HIDDEN (no_ospf_cost, |
7244 | no_ospf_cost_cmd, | |
7245 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
7246 | NO_STR | |
7247 | "OSPF interface commands\n" | |
7248 | "Interface cost\n" | |
7249 | "Cost\n" | |
7250 | "Address of interface\n") | |
827341b7 | 7251 | { |
d62a17ae | 7252 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
7253 | } |
7254 | ||
d62a17ae | 7255 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 7256 | { |
d62a17ae | 7257 | struct route_node *rn; |
7258 | struct ospf_neighbor *nbr; | |
718e3744 | 7259 | |
d62a17ae | 7260 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
7261 | if ((nbr = rn->info)) { | |
7262 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
7263 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
7264 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
7265 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
7266 | } | |
718e3744 | 7267 | } |
7268 | ||
d62a17ae | 7269 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
7270 | const char *nbr_str, | |
7271 | const char *fast_hello_str) | |
7272 | { | |
7273 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
7274 | uint32_t seconds; |
7275 | uint8_t hellomult; | |
d62a17ae | 7276 | struct in_addr addr; |
7277 | int ret; | |
7278 | struct ospf_if_params *params; | |
7279 | struct ospf_interface *oi; | |
7280 | struct route_node *rn; | |
718e3744 | 7281 | |
d62a17ae | 7282 | params = IF_DEF_PARAMS(ifp); |
7283 | ||
7284 | if (nbr_str) { | |
7285 | ret = inet_aton(nbr_str, &addr); | |
7286 | if (!ret) { | |
7287 | vty_out(vty, | |
7288 | "Please specify interface address by A.B.C.D\n"); | |
7289 | return CMD_WARNING_CONFIG_FAILED; | |
7290 | } | |
7291 | ||
7292 | params = ospf_get_if_params(ifp, addr); | |
7293 | ospf_if_update_params(ifp, addr); | |
7294 | } | |
7295 | ||
7296 | if (interval_str) { | |
7297 | seconds = strtoul(interval_str, NULL, 10); | |
7298 | ||
7299 | /* reset fast_hello too, just to be sure */ | |
7300 | UNSET_IF_PARAM(params, fast_hello); | |
7301 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7302 | } else if (fast_hello_str) { | |
7303 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
7304 | /* 1s dead-interval with sub-second hellos desired */ | |
7305 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
7306 | SET_IF_PARAM(params, fast_hello); | |
7307 | params->fast_hello = hellomult; | |
7308 | } else { | |
7309 | vty_out(vty, | |
7310 | "Please specify dead-interval or hello-multiplier\n"); | |
7311 | return CMD_WARNING_CONFIG_FAILED; | |
7312 | } | |
7313 | ||
7314 | SET_IF_PARAM(params, v_wait); | |
7315 | params->v_wait = seconds; | |
7316 | ||
7317 | /* Update timer values in neighbor structure. */ | |
7318 | if (nbr_str) { | |
b5a8894d CS |
7319 | struct ospf *ospf = NULL; |
7320 | ||
a36898e7 | 7321 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 7322 | if (ospf) { |
d62a17ae | 7323 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7324 | if (oi) | |
7325 | ospf_nbr_timer_update(oi); | |
7326 | } | |
7327 | } else { | |
7328 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7329 | if ((oi = rn->info)) | |
7330 | ospf_nbr_timer_update(oi); | |
7331 | } | |
7332 | ||
7333 | return CMD_SUCCESS; | |
718e3744 | 7334 | } |
7335 | ||
f9ad937f | 7336 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 7337 | ip_ospf_dead_interval_cmd, |
7a7be519 | 7338 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 7339 | "IP Information\n" |
7340 | "OSPF interface commands\n" | |
99a522c7 | 7341 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7342 | "Seconds\n" |
7343 | "Address of interface\n") | |
7344 | { | |
d62a17ae | 7345 | int idx = 0; |
7346 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
7347 | ? argv[idx]->arg | |
7348 | : NULL; | |
7349 | char *ifaddr = | |
7350 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
7351 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 7352 | } |
7353 | ||
718e3744 | 7354 | |
7a7be519 | 7355 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 7356 | ospf_dead_interval_cmd, |
0d829fa7 | 7357 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 7358 | "OSPF interface commands\n" |
99a522c7 | 7359 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
7360 | "Seconds\n" |
7361 | "Address of interface\n") | |
7a7be519 | 7362 | { |
d62a17ae | 7363 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 7364 | } |
718e3744 | 7365 | |
f9ad937f | 7366 | DEFUN (ip_ospf_dead_interval_minimal, |
7367 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 7368 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 7369 | "IP Information\n" |
7370 | "OSPF interface commands\n" | |
99a522c7 | 7371 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7372 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7373 | "Hello multiplier factor\n" | |
7374 | "Number of Hellos to send each second\n" | |
7375 | "Address of interface\n") | |
7376 | { | |
d62a17ae | 7377 | int idx_number = 5; |
7378 | int idx_ipv4 = 6; | |
7379 | if (argc == 7) | |
7380 | return ospf_vty_dead_interval_set( | |
7381 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
7382 | else | |
7383 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
7384 | argv[idx_number]->arg); | |
f9ad937f | 7385 | } |
7386 | ||
718e3744 | 7387 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 7388 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 7389 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 7390 | NO_STR |
7391 | "IP Information\n" | |
7392 | "OSPF interface commands\n" | |
99a522c7 | 7393 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 7394 | "Seconds\n" |
efd7904e RW |
7395 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7396 | "Hello multiplier factor\n" | |
7397 | "Number of Hellos to send each second\n" | |
7398 | "Address of interface\n") | |
718e3744 | 7399 | { |
d62a17ae | 7400 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7401 | int idx_ipv4 = argc - 1; | |
7402 | struct in_addr addr = {.s_addr = 0L}; | |
7403 | int ret; | |
7404 | struct ospf_if_params *params; | |
7405 | struct ospf_interface *oi; | |
7406 | struct route_node *rn; | |
7407 | ||
7408 | params = IF_DEF_PARAMS(ifp); | |
7409 | ||
7410 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
7411 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7412 | if (!ret) { | |
7413 | vty_out(vty, | |
7414 | "Please specify interface address by A.B.C.D\n"); | |
7415 | return CMD_WARNING_CONFIG_FAILED; | |
7416 | } | |
020709f9 | 7417 | |
d62a17ae | 7418 | params = ospf_lookup_if_params(ifp, addr); |
7419 | if (params == NULL) | |
7420 | return CMD_SUCCESS; | |
7421 | } | |
718e3744 | 7422 | |
d62a17ae | 7423 | UNSET_IF_PARAM(params, v_wait); |
7424 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
7425 | ||
7426 | UNSET_IF_PARAM(params, fast_hello); | |
7427 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7428 | ||
7429 | if (params != IF_DEF_PARAMS(ifp)) { | |
7430 | ospf_free_if_params(ifp, addr); | |
7431 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7432 | } |
7433 | ||
d62a17ae | 7434 | /* Update timer values in neighbor structure. */ |
7435 | if (argc == 1) { | |
b5a8894d | 7436 | struct ospf *ospf = NULL; |
718e3744 | 7437 | |
a36898e7 | 7438 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 7439 | if (ospf) { |
d62a17ae | 7440 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7441 | if (oi) | |
7442 | ospf_nbr_timer_update(oi); | |
7443 | } | |
7444 | } else { | |
7445 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7446 | if ((oi = rn->info)) | |
7447 | ospf_nbr_timer_update(oi); | |
7448 | } | |
7449 | ||
7450 | return CMD_SUCCESS; | |
718e3744 | 7451 | } |
7452 | ||
0d829fa7 QY |
7453 | DEFUN_HIDDEN (no_ospf_dead_interval, |
7454 | no_ospf_dead_interval_cmd, | |
7455 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
7456 | NO_STR | |
7457 | "OSPF interface commands\n" | |
99a522c7 | 7458 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 7459 | "Seconds\n" |
efd7904e RW |
7460 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7461 | "Hello multiplier factor\n" | |
7462 | "Number of Hellos to send each second\n" | |
7463 | "Address of interface\n") | |
0d829fa7 | 7464 | { |
d62a17ae | 7465 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
7466 | } |
7467 | ||
718e3744 | 7468 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 7469 | ip_ospf_hello_interval_cmd, |
7a7be519 | 7470 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 7471 | "IP Information\n" |
7472 | "OSPF interface commands\n" | |
7473 | "Time between HELLO packets\n" | |
7474 | "Seconds\n" | |
0d829fa7 | 7475 | "Address of interface\n") |
718e3744 | 7476 | { |
d62a17ae | 7477 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7478 | int idx = 0; | |
7479 | struct in_addr addr; | |
7480 | struct ospf_if_params *params; | |
7481 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 7482 | uint32_t seconds = 0; |
d62a17ae | 7483 | |
7484 | argv_find(argv, argc, "(1-65535)", &idx); | |
7485 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7486 | ||
7487 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7488 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7489 | vty_out(vty, | |
7490 | "Please specify interface address by A.B.C.D\n"); | |
7491 | return CMD_WARNING_CONFIG_FAILED; | |
7492 | } | |
718e3744 | 7493 | |
d62a17ae | 7494 | params = ospf_get_if_params(ifp, addr); |
7495 | ospf_if_update_params(ifp, addr); | |
7496 | } | |
718e3744 | 7497 | |
d62a17ae | 7498 | SET_IF_PARAM(params, v_hello); |
7499 | params->v_hello = seconds; | |
718e3744 | 7500 | |
d62a17ae | 7501 | return CMD_SUCCESS; |
718e3744 | 7502 | } |
7503 | ||
7a7be519 | 7504 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 7505 | ospf_hello_interval_cmd, |
0d829fa7 | 7506 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
7507 | "OSPF interface commands\n" |
7508 | "Time between HELLO packets\n" | |
0d829fa7 QY |
7509 | "Seconds\n" |
7510 | "Address of interface\n") | |
7a7be519 | 7511 | { |
d62a17ae | 7512 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 7513 | } |
718e3744 | 7514 | |
7515 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
7516 | no_ip_ospf_hello_interval_cmd, |
7517 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 7518 | NO_STR |
7519 | "IP Information\n" | |
7520 | "OSPF interface commands\n" | |
0d829fa7 | 7521 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 7522 | "Seconds\n" |
0d829fa7 | 7523 | "Address of interface\n") |
718e3744 | 7524 | { |
d62a17ae | 7525 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7526 | int idx = 0; | |
7527 | struct in_addr addr; | |
7528 | struct ospf_if_params *params; | |
df581cd3 | 7529 | |
d62a17ae | 7530 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7531 | |
d62a17ae | 7532 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7533 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7534 | vty_out(vty, | |
7535 | "Please specify interface address by A.B.C.D\n"); | |
7536 | return CMD_WARNING_CONFIG_FAILED; | |
7537 | } | |
718e3744 | 7538 | |
d62a17ae | 7539 | params = ospf_lookup_if_params(ifp, addr); |
7540 | if (params == NULL) | |
7541 | return CMD_SUCCESS; | |
7542 | } | |
718e3744 | 7543 | |
d62a17ae | 7544 | UNSET_IF_PARAM(params, v_hello); |
7545 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 7546 | |
d62a17ae | 7547 | if (params != IF_DEF_PARAMS(ifp)) { |
7548 | ospf_free_if_params(ifp, addr); | |
7549 | ospf_if_update_params(ifp, addr); | |
7550 | } | |
718e3744 | 7551 | |
d62a17ae | 7552 | return CMD_SUCCESS; |
718e3744 | 7553 | } |
7554 | ||
0d829fa7 QY |
7555 | DEFUN_HIDDEN (no_ospf_hello_interval, |
7556 | no_ospf_hello_interval_cmd, | |
7557 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
7558 | NO_STR | |
7559 | "OSPF interface commands\n" | |
7560 | "Time between HELLO packets\n" // ignored | |
7561 | "Seconds\n" | |
7562 | "Address of interface\n") | |
7563 | { | |
d62a17ae | 7564 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 7565 | } |
718e3744 | 7566 | |
7567 | DEFUN (ip_ospf_network, | |
7568 | ip_ospf_network_cmd, | |
6147e2c6 | 7569 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
718e3744 | 7570 | "IP Information\n" |
7571 | "OSPF interface commands\n" | |
7572 | "Network type\n" | |
7573 | "Specify OSPF broadcast multi-access network\n" | |
7574 | "Specify OSPF NBMA network\n" | |
7575 | "Specify OSPF point-to-multipoint network\n" | |
7576 | "Specify OSPF point-to-point network\n") | |
7577 | { | |
d62a17ae | 7578 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7579 | int idx = 0; | |
7580 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7581 | struct route_node *rn; | |
718e3744 | 7582 | |
d62a17ae | 7583 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
7584 | vty_out(vty, | |
7585 | "This is a loopback interface. Can't set network type.\n"); | |
7586 | return CMD_WARNING_CONFIG_FAILED; | |
7587 | } | |
718e3744 | 7588 | |
d62a17ae | 7589 | if (argv_find(argv, argc, "broadcast", &idx)) |
7590 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
7591 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
7592 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
7593 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
7594 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
7595 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
7596 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
718e3744 | 7597 | |
d62a17ae | 7598 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7599 | return CMD_SUCCESS; | |
7600 | ||
7601 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
7602 | ||
7603 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7604 | struct ospf_interface *oi = rn->info; | |
7605 | ||
7606 | if (!oi) | |
7607 | continue; | |
7608 | ||
7609 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
7610 | ||
7611 | if (oi->state > ISM_Down) { | |
7612 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7613 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7614 | } | |
7a7be519 | 7615 | } |
7a7be519 | 7616 | |
d62a17ae | 7617 | return CMD_SUCCESS; |
7a7be519 | 7618 | } |
7619 | ||
7620 | DEFUN_HIDDEN (ospf_network, | |
7621 | ospf_network_cmd, | |
e83a9414 | 7622 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 7623 | "OSPF interface commands\n" |
7624 | "Network type\n" | |
7625 | "Specify OSPF broadcast multi-access network\n" | |
7626 | "Specify OSPF NBMA network\n" | |
7627 | "Specify OSPF point-to-multipoint network\n" | |
7628 | "Specify OSPF point-to-point network\n") | |
7629 | { | |
d62a17ae | 7630 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 7631 | } |
7632 | ||
7633 | DEFUN (no_ip_ospf_network, | |
7634 | no_ip_ospf_network_cmd, | |
7635 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7636 | NO_STR | |
7637 | "IP Information\n" | |
7638 | "OSPF interface commands\n" | |
7639 | "Network type\n" | |
7640 | "Specify OSPF broadcast multi-access network\n" | |
7641 | "Specify OSPF NBMA network\n" | |
7642 | "Specify OSPF point-to-multipoint network\n" | |
7643 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 7644 | { |
d62a17ae | 7645 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7646 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7647 | struct route_node *rn; | |
7a7be519 | 7648 | |
d62a17ae | 7649 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
7a7be519 | 7650 | |
d62a17ae | 7651 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7652 | return CMD_SUCCESS; | |
7a7be519 | 7653 | |
d62a17ae | 7654 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7655 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7656 | |
d62a17ae | 7657 | if (!oi) |
7658 | continue; | |
7a7be519 | 7659 | |
d62a17ae | 7660 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 7661 | |
d62a17ae | 7662 | if (oi->state > ISM_Down) { |
7663 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7664 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7665 | } | |
7a7be519 | 7666 | } |
7a7be519 | 7667 | |
d62a17ae | 7668 | return CMD_SUCCESS; |
7a7be519 | 7669 | } |
7670 | ||
0d829fa7 QY |
7671 | DEFUN_HIDDEN (no_ospf_network, |
7672 | no_ospf_network_cmd, | |
7673 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7674 | NO_STR | |
7675 | "OSPF interface commands\n" | |
7676 | "Network type\n" | |
7677 | "Specify OSPF broadcast multi-access network\n" | |
7678 | "Specify OSPF NBMA network\n" | |
7679 | "Specify OSPF point-to-multipoint network\n" | |
7680 | "Specify OSPF point-to-point network\n") | |
7681 | { | |
d62a17ae | 7682 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
7683 | } |
7684 | ||
7a7be519 | 7685 | DEFUN (ip_ospf_priority, |
537eae3f | 7686 | ip_ospf_priority_cmd, |
7a7be519 | 7687 | "ip ospf priority (0-255) [A.B.C.D]", |
7688 | "IP Information\n" | |
7689 | "OSPF interface commands\n" | |
7690 | "Router priority\n" | |
7691 | "Priority\n" | |
efd7904e | 7692 | "Address of interface\n") |
7a7be519 | 7693 | { |
d62a17ae | 7694 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7695 | int idx = 0; | |
7696 | long priority; | |
7697 | struct route_node *rn; | |
7698 | struct in_addr addr; | |
7699 | struct ospf_if_params *params; | |
7700 | params = IF_DEF_PARAMS(ifp); | |
7701 | ||
7702 | argv_find(argv, argc, "(0-255)", &idx); | |
7703 | priority = strtol(argv[idx]->arg, NULL, 10); | |
7704 | ||
7705 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7706 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7707 | vty_out(vty, | |
7708 | "Please specify interface address by A.B.C.D\n"); | |
7709 | return CMD_WARNING_CONFIG_FAILED; | |
7710 | } | |
7a7be519 | 7711 | |
d62a17ae | 7712 | params = ospf_get_if_params(ifp, addr); |
7713 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 7714 | } |
7715 | ||
d62a17ae | 7716 | SET_IF_PARAM(params, priority); |
7717 | params->priority = priority; | |
7a7be519 | 7718 | |
d62a17ae | 7719 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7720 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7721 | |
d62a17ae | 7722 | if (!oi) |
7723 | continue; | |
7a7be519 | 7724 | |
d62a17ae | 7725 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
7726 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7727 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7728 | } | |
718e3744 | 7729 | } |
718e3744 | 7730 | |
d62a17ae | 7731 | return CMD_SUCCESS; |
718e3744 | 7732 | } |
7733 | ||
7a7be519 | 7734 | DEFUN_HIDDEN (ospf_priority, |
7735 | ospf_priority_cmd, | |
0d829fa7 | 7736 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 7737 | "OSPF interface commands\n" |
7738 | "Router priority\n" | |
3a2d747c | 7739 | "Priority\n" |
efd7904e | 7740 | "Address of interface\n") |
718e3744 | 7741 | { |
d62a17ae | 7742 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 7743 | } |
7744 | ||
718e3744 | 7745 | DEFUN (no_ip_ospf_priority, |
537eae3f | 7746 | no_ip_ospf_priority_cmd, |
7a7be519 | 7747 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 7748 | NO_STR |
7749 | "IP Information\n" | |
7750 | "OSPF interface commands\n" | |
0d829fa7 | 7751 | "Router priority\n" // ignored |
813d4307 | 7752 | "Priority\n" |
efd7904e | 7753 | "Address of interface\n") |
718e3744 | 7754 | { |
d62a17ae | 7755 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7756 | int idx = 0; | |
7757 | struct route_node *rn; | |
7758 | struct in_addr addr; | |
7759 | struct ospf_if_params *params; | |
7760 | ||
7761 | params = IF_DEF_PARAMS(ifp); | |
7762 | ||
7763 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7764 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7765 | vty_out(vty, | |
7766 | "Please specify interface address by A.B.C.D\n"); | |
7767 | return CMD_WARNING_CONFIG_FAILED; | |
7768 | } | |
7769 | ||
7770 | params = ospf_lookup_if_params(ifp, addr); | |
7771 | if (params == NULL) | |
7772 | return CMD_SUCCESS; | |
718e3744 | 7773 | } |
7774 | ||
d62a17ae | 7775 | UNSET_IF_PARAM(params, priority); |
7776 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
7777 | ||
7778 | if (params != IF_DEF_PARAMS(ifp)) { | |
7779 | ospf_free_if_params(ifp, addr); | |
7780 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7781 | } |
d62a17ae | 7782 | |
7783 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7784 | struct ospf_interface *oi = rn->info; | |
7785 | ||
7786 | if (!oi) | |
7787 | continue; | |
7788 | ||
7789 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7790 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7791 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7792 | } | |
7793 | } | |
7794 | ||
7795 | return CMD_SUCCESS; | |
718e3744 | 7796 | } |
7797 | ||
0d829fa7 | 7798 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 7799 | no_ospf_priority_cmd, |
0d829fa7 QY |
7800 | "no ospf priority [(0-255) [A.B.C.D]]", |
7801 | NO_STR | |
7802 | "OSPF interface commands\n" | |
7803 | "Router priority\n" | |
7804 | "Priority\n" | |
efd7904e | 7805 | "Address of interface\n") |
0d829fa7 | 7806 | { |
d62a17ae | 7807 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 7808 | } |
a1afa410 | 7809 | |
718e3744 | 7810 | DEFUN (ip_ospf_retransmit_interval, |
7811 | ip_ospf_retransmit_interval_addr_cmd, | |
7a7be519 | 7812 | "ip ospf retransmit-interval (3-65535) [A.B.C.D]", |
718e3744 | 7813 | "IP Information\n" |
7814 | "OSPF interface commands\n" | |
7815 | "Time between retransmitting lost link state advertisements\n" | |
7816 | "Seconds\n" | |
efd7904e | 7817 | "Address of interface\n") |
718e3744 | 7818 | { |
d62a17ae | 7819 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7820 | int idx = 0; | |
d7c0a89a | 7821 | uint32_t seconds; |
d62a17ae | 7822 | struct in_addr addr; |
7823 | struct ospf_if_params *params; | |
7824 | params = IF_DEF_PARAMS(ifp); | |
7825 | ||
7826 | argv_find(argv, argc, "(3-65535)", &idx); | |
7827 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7828 | ||
7829 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7830 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7831 | vty_out(vty, | |
7832 | "Please specify interface address by A.B.C.D\n"); | |
7833 | return CMD_WARNING_CONFIG_FAILED; | |
7834 | } | |
718e3744 | 7835 | |
d62a17ae | 7836 | params = ospf_get_if_params(ifp, addr); |
7837 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7838 | } |
7839 | ||
d62a17ae | 7840 | SET_IF_PARAM(params, retransmit_interval); |
7841 | params->retransmit_interval = seconds; | |
718e3744 | 7842 | |
d62a17ae | 7843 | return CMD_SUCCESS; |
718e3744 | 7844 | } |
7845 | ||
7a7be519 | 7846 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 7847 | ospf_retransmit_interval_cmd, |
0d829fa7 | 7848 | "ospf retransmit-interval (3-65535) [A.B.C.D]", |
747e489c DW |
7849 | "OSPF interface commands\n" |
7850 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 7851 | "Seconds\n" |
efd7904e | 7852 | "Address of interface\n") |
7a7be519 | 7853 | { |
d62a17ae | 7854 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 7855 | } |
718e3744 | 7856 | |
7857 | DEFUN (no_ip_ospf_retransmit_interval, | |
7858 | no_ip_ospf_retransmit_interval_addr_cmd, | |
0d829fa7 | 7859 | "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]", |
718e3744 | 7860 | NO_STR |
7861 | "IP Information\n" | |
7862 | "OSPF interface commands\n" | |
3a2d747c QY |
7863 | "Time between retransmitting lost link state advertisements\n" |
7864 | "Seconds\n" | |
0d829fa7 | 7865 | "Address of interface\n") |
718e3744 | 7866 | { |
d62a17ae | 7867 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7868 | int idx = 0; | |
7869 | struct in_addr addr; | |
7870 | struct ospf_if_params *params; | |
47b91972 | 7871 | |
d62a17ae | 7872 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7873 | |
d62a17ae | 7874 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7875 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7876 | vty_out(vty, | |
7877 | "Please specify interface address by A.B.C.D\n"); | |
7878 | return CMD_WARNING_CONFIG_FAILED; | |
7879 | } | |
718e3744 | 7880 | |
d62a17ae | 7881 | params = ospf_lookup_if_params(ifp, addr); |
7882 | if (params == NULL) | |
7883 | return CMD_SUCCESS; | |
7884 | } | |
718e3744 | 7885 | |
d62a17ae | 7886 | UNSET_IF_PARAM(params, retransmit_interval); |
7887 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 7888 | |
d62a17ae | 7889 | if (params != IF_DEF_PARAMS(ifp)) { |
7890 | ospf_free_if_params(ifp, addr); | |
7891 | ospf_if_update_params(ifp, addr); | |
7892 | } | |
718e3744 | 7893 | |
d62a17ae | 7894 | return CMD_SUCCESS; |
718e3744 | 7895 | } |
7896 | ||
0d829fa7 QY |
7897 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
7898 | no_ospf_retransmit_interval_cmd, | |
7899 | "no ospf retransmit-interval [(3-65535)] [A.B.C.D]", | |
7900 | NO_STR | |
7901 | "OSPF interface commands\n" | |
3a2d747c QY |
7902 | "Time between retransmitting lost link state advertisements\n" |
7903 | "Seconds\n" | |
7904 | "Address of interface\n") | |
0d829fa7 | 7905 | { |
d62a17ae | 7906 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 7907 | } |
813d4307 | 7908 | |
718e3744 | 7909 | DEFUN (ip_ospf_transmit_delay, |
7910 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 7911 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 7912 | "IP Information\n" |
7913 | "OSPF interface commands\n" | |
7914 | "Link state transmit delay\n" | |
7915 | "Seconds\n" | |
efd7904e | 7916 | "Address of interface\n") |
718e3744 | 7917 | { |
d62a17ae | 7918 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7919 | int idx = 0; | |
d7c0a89a | 7920 | uint32_t seconds; |
d62a17ae | 7921 | struct in_addr addr; |
7922 | struct ospf_if_params *params; | |
7923 | ||
7924 | params = IF_DEF_PARAMS(ifp); | |
7925 | argv_find(argv, argc, "(1-65535)", &idx); | |
7926 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7927 | ||
7928 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7929 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7930 | vty_out(vty, | |
7931 | "Please specify interface address by A.B.C.D\n"); | |
7932 | return CMD_WARNING_CONFIG_FAILED; | |
7933 | } | |
718e3744 | 7934 | |
d62a17ae | 7935 | params = ospf_get_if_params(ifp, addr); |
7936 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7937 | } |
7938 | ||
d62a17ae | 7939 | SET_IF_PARAM(params, transmit_delay); |
7940 | params->transmit_delay = seconds; | |
718e3744 | 7941 | |
d62a17ae | 7942 | return CMD_SUCCESS; |
718e3744 | 7943 | } |
7944 | ||
7a7be519 | 7945 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 7946 | ospf_transmit_delay_cmd, |
0d829fa7 | 7947 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
7948 | "OSPF interface commands\n" |
7949 | "Link state transmit delay\n" | |
3a2d747c | 7950 | "Seconds\n" |
efd7904e | 7951 | "Address of interface\n") |
7a7be519 | 7952 | { |
d62a17ae | 7953 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 7954 | } |
718e3744 | 7955 | |
7956 | DEFUN (no_ip_ospf_transmit_delay, | |
7957 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 7958 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 7959 | NO_STR |
7960 | "IP Information\n" | |
7961 | "OSPF interface commands\n" | |
7962 | "Link state transmit delay\n" | |
efd7904e RW |
7963 | "Seconds\n" |
7964 | "Address of interface\n") | |
718e3744 | 7965 | { |
d62a17ae | 7966 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7967 | int idx = 0; | |
7968 | struct in_addr addr; | |
7969 | struct ospf_if_params *params; | |
718e3744 | 7970 | |
d62a17ae | 7971 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7972 | |
d62a17ae | 7973 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7974 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7975 | vty_out(vty, | |
7976 | "Please specify interface address by A.B.C.D\n"); | |
7977 | return CMD_WARNING_CONFIG_FAILED; | |
7978 | } | |
718e3744 | 7979 | |
d62a17ae | 7980 | params = ospf_lookup_if_params(ifp, addr); |
7981 | if (params == NULL) | |
7982 | return CMD_SUCCESS; | |
7983 | } | |
718e3744 | 7984 | |
d62a17ae | 7985 | UNSET_IF_PARAM(params, transmit_delay); |
7986 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 7987 | |
d62a17ae | 7988 | if (params != IF_DEF_PARAMS(ifp)) { |
7989 | ospf_free_if_params(ifp, addr); | |
7990 | ospf_if_update_params(ifp, addr); | |
7991 | } | |
7992 | ||
7993 | return CMD_SUCCESS; | |
718e3744 | 7994 | } |
7995 | ||
813d4307 | 7996 | |
0d829fa7 QY |
7997 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
7998 | no_ospf_transmit_delay_cmd, | |
32573073 | 7999 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
8000 | NO_STR |
8001 | "OSPF interface commands\n" | |
32573073 QY |
8002 | "Link state transmit delay\n" |
8003 | "Seconds\n" | |
efd7904e | 8004 | "Address of interface\n") |
813d4307 | 8005 | { |
d62a17ae | 8006 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
8007 | } |
8008 | ||
e723861d DS |
8009 | DEFUN (ip_ospf_area, |
8010 | ip_ospf_area_cmd, | |
52c62ab8 | 8011 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
8012 | "IP Information\n" |
8013 | "OSPF interface commands\n" | |
7a7be519 | 8014 | "Instance ID\n" |
e723861d DS |
8015 | "Enable OSPF on this interface\n" |
8016 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8017 | "OSPF area ID as a decimal value\n" |
8018 | "Address of interface\n") | |
e723861d | 8019 | { |
d62a17ae | 8020 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8021 | int idx = 0; | |
8022 | int format, ret; | |
8023 | struct in_addr area_id; | |
8024 | struct in_addr addr; | |
35955c14 | 8025 | struct ospf_if_params *params = NULL; |
d62a17ae | 8026 | struct route_node *rn; |
b5a8894d | 8027 | struct ospf *ospf = NULL; |
d7c0a89a | 8028 | unsigned short instance = 0; |
d62a17ae | 8029 | char *areaid; |
8030 | ||
8031 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8032 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8033 | ||
8034 | argv_find(argv, argc, "area", &idx); | |
8035 | areaid = argv[idx + 1]->arg; | |
8036 | ||
a36898e7 DS |
8037 | if (ifp->vrf_id && !instance) |
8038 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
8039 | else |
8040 | ospf = ospf_lookup_instance(instance); | |
8041 | ||
aed7cc62 | 8042 | if (instance && ospf == NULL) { |
d62a17ae | 8043 | params = IF_DEF_PARAMS(ifp); |
8044 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8045 | UNSET_IF_PARAM(params, if_area); | |
b5a8894d CS |
8046 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
8047 | ospf_interface_area_unset(ospf, ifp); | |
d62a17ae | 8048 | ospf->if_ospf_cli_count--; |
8049 | } | |
ac28e4ec | 8050 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8051 | } |
e723861d | 8052 | |
d62a17ae | 8053 | ret = str2area_id(areaid, &area_id, &format); |
8054 | if (ret < 0) { | |
8055 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8056 | return CMD_WARNING_CONFIG_FAILED; | |
8057 | } | |
8058 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8059 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8060 | return CMD_WARNING_CONFIG_FAILED; | |
8061 | } | |
8062 | ||
8063 | params = IF_DEF_PARAMS(ifp); | |
8064 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8065 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8066 | vty_out(vty, | |
8067 | "Must remove previous area config before changing ospf area \n"); | |
8068 | return CMD_WARNING_CONFIG_FAILED; | |
8069 | } | |
8070 | ||
8071 | // Check if we have an address arg and proccess it | |
8072 | if (argc == idx + 3) { | |
cc9b06ad | 8073 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8074 | vty_out(vty, |
8075 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8076 | return CMD_WARNING_CONFIG_FAILED; |
8077 | } | |
d62a17ae | 8078 | // update/create address-level params |
8079 | params = ospf_get_if_params((ifp), (addr)); | |
8080 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8081 | vty_out(vty, | |
8082 | "Must remove previous area/address config before changing ospf area"); | |
8083 | return CMD_WARNING_CONFIG_FAILED; | |
8084 | } | |
8085 | ospf_if_update_params((ifp), (addr)); | |
8086 | } | |
8087 | ||
aed7cc62 CS |
8088 | if (ospf) { |
8089 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8090 | if (rn->info != NULL) { | |
8091 | vty_out(vty, | |
8092 | "Please remove all network commands first.\n"); | |
8093 | return CMD_WARNING_CONFIG_FAILED; | |
8094 | } | |
d62a17ae | 8095 | } |
8096 | } | |
8097 | ||
8098 | /* enable ospf on this interface with area_id */ | |
35955c14 CS |
8099 | if (params) { |
8100 | SET_IF_PARAM(params, if_area); | |
8101 | params->if_area = area_id; | |
8102 | params->if_area_id_fmt = format; | |
8103 | } | |
aed7cc62 CS |
8104 | |
8105 | if (ospf) { | |
8106 | ospf_interface_area_set(ospf, ifp); | |
8107 | ospf->if_ospf_cli_count++; | |
8108 | } | |
d62a17ae | 8109 | |
8110 | return CMD_SUCCESS; | |
e723861d DS |
8111 | } |
8112 | ||
8113 | DEFUN (no_ip_ospf_area, | |
8114 | no_ip_ospf_area_cmd, | |
52c62ab8 | 8115 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
8116 | NO_STR |
8117 | "IP Information\n" | |
8118 | "OSPF interface commands\n" | |
3a2d747c | 8119 | "Instance ID\n" |
7a7be519 | 8120 | "Disable OSPF on this interface\n" |
8121 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8122 | "OSPF area ID as a decimal value\n" |
8123 | "Address of interface\n") | |
e723861d | 8124 | { |
d62a17ae | 8125 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8126 | int idx = 0; | |
8127 | struct ospf *ospf; | |
8128 | struct ospf_if_params *params; | |
d7c0a89a | 8129 | unsigned short instance = 0; |
d62a17ae | 8130 | struct in_addr addr; |
8131 | ||
8132 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8133 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8134 | ||
a36898e7 DS |
8135 | if (ifp->vrf_id && !instance) |
8136 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
8137 | else |
8138 | ospf = ospf_lookup_instance(instance); | |
8139 | ||
ac28e4ec CS |
8140 | if (ospf == NULL) |
8141 | return CMD_NOT_MY_INSTANCE; | |
d62a17ae | 8142 | |
8143 | argv_find(argv, argc, "area", &idx); | |
8144 | ||
8145 | // Check if we have an address arg and proccess it | |
8146 | if (argc == idx + 3) { | |
cc9b06ad | 8147 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8148 | vty_out(vty, |
8149 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8150 | return CMD_WARNING_CONFIG_FAILED; |
8151 | } | |
d62a17ae | 8152 | params = ospf_lookup_if_params(ifp, addr); |
8153 | if ((params) == NULL) | |
8154 | return CMD_SUCCESS; | |
8155 | } else | |
8156 | params = IF_DEF_PARAMS(ifp); | |
8157 | ||
8158 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8159 | vty_out(vty, | |
8160 | "Can't find specified interface area configuration.\n"); | |
8161 | return CMD_WARNING_CONFIG_FAILED; | |
8162 | } | |
813d4307 | 8163 | |
d62a17ae | 8164 | UNSET_IF_PARAM(params, if_area); |
8165 | if (params != IF_DEF_PARAMS((ifp))) { | |
8166 | ospf_free_if_params((ifp), (addr)); | |
8167 | ospf_if_update_params((ifp), (addr)); | |
8168 | } | |
8169 | ||
b5a8894d | 8170 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8171 | ospf->if_ospf_cli_count--; |
8172 | return CMD_SUCCESS; | |
813d4307 DW |
8173 | } |
8174 | ||
6f2a6703 CF |
8175 | DEFUN (ospf_redistribute_source, |
8176 | ospf_redistribute_source_cmd, | |
ea38ced1 | 8177 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
d1c65c21 | 8178 | REDIST_STR |
ab0181ee | 8179 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 8180 | "Metric for redistributed routes\n" |
8181 | "OSPF default metric\n" | |
8182 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8183 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8184 | "Route map reference\n" |
8185 | "Pointer to route-map entries\n") | |
8186 | { | |
a3d826f0 | 8187 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8188 | int idx_protocol = 1; |
8189 | int source; | |
8190 | int type = -1; | |
8191 | int metric = -1; | |
8192 | struct ospf_redist *red; | |
8193 | int idx = 0; | |
6f2a6703 | 8194 | |
d62a17ae | 8195 | /* Get distribute source. */ |
8196 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
8197 | if (source < 0) | |
8198 | return CMD_WARNING_CONFIG_FAILED; | |
8199 | ||
8200 | red = ospf_redist_add(ospf, source, 0); | |
8201 | ||
8202 | /* Get metric value. */ | |
8203 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
8204 | if (!str2metric(argv[idx]->arg, &metric)) | |
8205 | return CMD_WARNING_CONFIG_FAILED; | |
8206 | } | |
951da435 | 8207 | idx = 1; |
d62a17ae | 8208 | /* Get metric type. */ |
ea38ced1 | 8209 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 8210 | if (!str2metric_type(argv[idx]->arg, &type)) |
8211 | return CMD_WARNING_CONFIG_FAILED; | |
8212 | } | |
951da435 | 8213 | idx = 1; |
d62a17ae | 8214 | /* Get route-map */ |
ea38ced1 | 8215 | if (argv_find(argv, argc, "WORD", &idx)) { |
d62a17ae | 8216 | ospf_routemap_set(red, argv[idx]->arg); |
8217 | } else | |
8218 | ospf_routemap_unset(red); | |
7c8ff89e | 8219 | |
d62a17ae | 8220 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 8221 | } |
8222 | ||
718e3744 | 8223 | DEFUN (no_ospf_redistribute_source, |
8224 | no_ospf_redistribute_source_cmd, | |
ea38ced1 | 8225 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8226 | NO_STR |
d1c65c21 | 8227 | REDIST_STR |
ab0181ee | 8228 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
8229 | "Metric for redistributed routes\n" |
8230 | "OSPF default metric\n" | |
8231 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8232 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8233 | "Route map reference\n" |
8234 | "Pointer to route-map entries\n") | |
718e3744 | 8235 | { |
a3d826f0 | 8236 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8237 | int idx_protocol = 2; |
8238 | int source; | |
8239 | struct ospf_redist *red; | |
718e3744 | 8240 | |
d62a17ae | 8241 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
8242 | if (source < 0) | |
8243 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8244 | |
d62a17ae | 8245 | red = ospf_redist_lookup(ospf, source, 0); |
8246 | if (!red) | |
8247 | return CMD_SUCCESS; | |
7c8ff89e | 8248 | |
d62a17ae | 8249 | ospf_routemap_unset(red); |
766b826f DA |
8250 | ospf_redist_del(ospf, source, 0); |
8251 | ||
d62a17ae | 8252 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
8253 | } |
8254 | ||
8255 | DEFUN (ospf_redistribute_instance_source, | |
8256 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8257 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8258 | REDIST_STR |
8259 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8260 | "Non-main Kernel Routing Table\n" |
8261 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
8262 | "Metric for redistributed routes\n" |
8263 | "OSPF default metric\n" | |
8264 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8265 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8266 | "Route map reference\n" |
8267 | "Pointer to route-map entries\n") | |
8268 | { | |
a3d826f0 | 8269 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8270 | int idx_ospf_table = 1; |
8271 | int idx_number = 2; | |
8272 | int idx = 3; | |
8273 | int source; | |
8274 | int type = -1; | |
8275 | int metric = -1; | |
d7c0a89a | 8276 | unsigned short instance; |
d62a17ae | 8277 | struct ospf_redist *red; |
7c8ff89e | 8278 | |
d62a17ae | 8279 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 8280 | |
13f0e434 | 8281 | if (source < 0) { |
8282 | vty_out(vty, "Unknown instance redistribution\n"); | |
8283 | return CMD_WARNING_CONFIG_FAILED; | |
8284 | } | |
8285 | ||
d62a17ae | 8286 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 8287 | |
d62a17ae | 8288 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8289 | vty_out(vty, | |
8290 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8291 | return CMD_WARNING_CONFIG_FAILED; | |
8292 | } | |
7c8ff89e | 8293 | |
d62a17ae | 8294 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
8295 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8296 | return CMD_WARNING_CONFIG_FAILED; | |
8297 | } | |
7c8ff89e | 8298 | |
d62a17ae | 8299 | /* Get metric value. */ |
8300 | if (argv_find(argv, argc, "metric", &idx)) | |
8301 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
8302 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 8303 | |
d62a17ae | 8304 | idx = 3; |
8305 | /* Get metric type. */ | |
8306 | if (argv_find(argv, argc, "metric-type", &idx)) | |
8307 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
8308 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 8309 | |
d62a17ae | 8310 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 8311 | |
d62a17ae | 8312 | idx = 3; |
8313 | if (argv_find(argv, argc, "route-map", &idx)) | |
8314 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
8315 | else | |
8316 | ospf_routemap_unset(red); | |
7c8ff89e | 8317 | |
d62a17ae | 8318 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
8319 | } |
8320 | ||
8321 | DEFUN (no_ospf_redistribute_instance_source, | |
8322 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8323 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8324 | NO_STR |
8325 | REDIST_STR | |
8326 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8327 | "Non-main Kernel Routing Table\n" |
8328 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
8329 | "Metric for redistributed routes\n" |
8330 | "OSPF default metric\n" | |
8331 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8332 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8333 | "Route map reference\n" |
8334 | "Pointer to route-map entries\n") | |
8335 | { | |
a3d826f0 | 8336 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8337 | int idx_ospf_table = 2; |
8338 | int idx_number = 3; | |
d7c0a89a | 8339 | unsigned int instance; |
d62a17ae | 8340 | struct ospf_redist *red; |
8341 | int source; | |
8342 | ||
8343 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
8344 | source = ZEBRA_ROUTE_OSPF; | |
8345 | else | |
8346 | source = ZEBRA_ROUTE_TABLE; | |
8347 | ||
8348 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 8349 | |
d62a17ae | 8350 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8351 | vty_out(vty, | |
8352 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8353 | return CMD_WARNING_CONFIG_FAILED; | |
8354 | } | |
8355 | ||
8356 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
8357 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8358 | return CMD_WARNING_CONFIG_FAILED; | |
8359 | } | |
8360 | ||
8361 | red = ospf_redist_lookup(ospf, source, instance); | |
8362 | if (!red) | |
8363 | return CMD_SUCCESS; | |
8364 | ||
8365 | ospf_routemap_unset(red); | |
766b826f DA |
8366 | ospf_redist_del(ospf, source, instance); |
8367 | ||
d62a17ae | 8368 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 8369 | } |
8370 | ||
8371 | DEFUN (ospf_distribute_list_out, | |
8372 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 8373 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 8374 | "Filter networks in routing updates\n" |
6f2a6703 CF |
8375 | "Access-list name\n" |
8376 | OUT_STR | |
ab0181ee | 8377 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 8378 | { |
a3d826f0 | 8379 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8380 | int idx_word = 1; |
8381 | int source; | |
718e3744 | 8382 | |
d62a17ae | 8383 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 8384 | |
d62a17ae | 8385 | /* Get distribute source. */ |
8386 | source = proto_redistnum(AFI_IP, proto); | |
8387 | if (source < 0) | |
8388 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8389 | |
d62a17ae | 8390 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 8391 | } |
8392 | ||
6f2a6703 CF |
8393 | DEFUN (no_ospf_distribute_list_out, |
8394 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 8395 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
8396 | NO_STR |
8397 | "Filter networks in routing updates\n" | |
8398 | "Access-list name\n" | |
8399 | OUT_STR | |
ab0181ee | 8400 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 8401 | { |
a3d826f0 | 8402 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8403 | int idx_word = 2; |
8404 | int source; | |
020709f9 | 8405 | |
d62a17ae | 8406 | char *proto = argv[argc - 1]->text; |
8407 | source = proto_redistnum(AFI_IP, proto); | |
8408 | if (source < 0) | |
8409 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8410 | |
d62a17ae | 8411 | return ospf_distribute_list_out_unset(ospf, source, |
8412 | argv[idx_word]->arg); | |
718e3744 | 8413 | } |
8414 | ||
6f2a6703 CF |
8415 | /* Default information originate. */ |
8416 | DEFUN (ospf_default_information_originate, | |
8417 | ospf_default_information_originate_cmd, | |
ea38ced1 | 8418 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8419 | "Control distribution of default information\n" |
8420 | "Distribute a default route\n" | |
8421 | "Always advertise default route\n" | |
6f2a6703 CF |
8422 | "OSPF default metric\n" |
8423 | "OSPF metric\n" | |
718e3744 | 8424 | "OSPF metric type for default routes\n" |
7111c1a0 | 8425 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8426 | "Route map reference\n" |
8427 | "Pointer to route-map entries\n") | |
8428 | { | |
a3d826f0 | 8429 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8430 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
8431 | int type = -1; | |
8432 | int metric = -1; | |
8433 | struct ospf_redist *red; | |
8434 | int idx = 0; | |
1fb93326 | 8435 | int cur_originate = ospf->default_originate; |
8436 | int sameRtmap = 0; | |
8437 | char *rtmap = NULL; | |
d62a17ae | 8438 | |
8439 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
8440 | ||
8441 | /* Check whether "always" was specified */ | |
8442 | if (argv_find(argv, argc, "always", &idx)) | |
8443 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 8444 | idx = 1; |
d62a17ae | 8445 | /* Get metric value */ |
ea38ced1 | 8446 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 8447 | if (!str2metric(argv[idx]->arg, &metric)) |
8448 | return CMD_WARNING_CONFIG_FAILED; | |
8449 | } | |
951da435 | 8450 | idx = 1; |
d62a17ae | 8451 | /* Get metric type. */ |
ea38ced1 | 8452 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 8453 | if (!str2metric_type(argv[idx]->arg, &type)) |
8454 | return CMD_WARNING_CONFIG_FAILED; | |
8455 | } | |
951da435 | 8456 | idx = 1; |
d62a17ae | 8457 | /* Get route-map */ |
ea38ced1 | 8458 | if (argv_find(argv, argc, "WORD", &idx)) |
1fb93326 | 8459 | rtmap = argv[idx]->arg; |
8460 | ||
8461 | /* To check ,if user is providing same route map */ | |
8462 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
8463 | (rtmap && ROUTEMAP_NAME(red) | |
8464 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
8465 | sameRtmap = 1; | |
8466 | ||
8467 | /* Don't allow if the same lsa is aleardy originated. */ | |
8468 | if ((sameRtmap) | |
8469 | && (red->dmetric.type == type) | |
8470 | && (red->dmetric.value == metric) | |
8471 | && (cur_originate == default_originate)) | |
8472 | return CMD_SUCCESS; | |
8473 | ||
8474 | /* Updating Metric details */ | |
8475 | red->dmetric.type = type; | |
8476 | red->dmetric.value = metric; | |
8477 | ||
8478 | /* updating route map details */ | |
8479 | if (rtmap) | |
8480 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 8481 | else |
8482 | ospf_routemap_unset(red); | |
8483 | ||
8484 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
8485 | metric); | |
718e3744 | 8486 | } |
8487 | ||
8488 | DEFUN (no_ospf_default_information_originate, | |
8489 | no_ospf_default_information_originate_cmd, | |
ea38ced1 | 8490 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8491 | NO_STR |
8492 | "Control distribution of default information\n" | |
813d4307 DW |
8493 | "Distribute a default route\n" |
8494 | "Always advertise default route\n" | |
8495 | "OSPF default metric\n" | |
8496 | "OSPF metric\n" | |
8497 | "OSPF metric type for default routes\n" | |
7111c1a0 | 8498 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8499 | "Route map reference\n" |
8500 | "Pointer to route-map entries\n") | |
718e3744 | 8501 | { |
a3d826f0 | 8502 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8503 | struct ospf_redist *red; |
7c8ff89e | 8504 | |
d62a17ae | 8505 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
8506 | if (!red) | |
8507 | return CMD_SUCCESS; | |
7c8ff89e | 8508 | |
d62a17ae | 8509 | ospf_routemap_unset(red); |
766b826f DA |
8510 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
8511 | ||
d5eac1e0 DL |
8512 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
8513 | 0, 0); | |
718e3744 | 8514 | } |
8515 | ||
8516 | DEFUN (ospf_default_metric, | |
8517 | ospf_default_metric_cmd, | |
6147e2c6 | 8518 | "default-metric (0-16777214)", |
718e3744 | 8519 | "Set metric of redistributed routes\n" |
8520 | "Default metric\n") | |
8521 | { | |
a3d826f0 | 8522 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8523 | int idx_number = 1; |
8524 | int metric = -1; | |
718e3744 | 8525 | |
d62a17ae | 8526 | if (!str2metric(argv[idx_number]->arg, &metric)) |
8527 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8528 | |
d62a17ae | 8529 | ospf->default_metric = metric; |
718e3744 | 8530 | |
d62a17ae | 8531 | return CMD_SUCCESS; |
718e3744 | 8532 | } |
8533 | ||
8534 | DEFUN (no_ospf_default_metric, | |
8535 | no_ospf_default_metric_cmd, | |
7a7be519 | 8536 | "no default-metric [(0-16777214)]", |
718e3744 | 8537 | NO_STR |
7a7be519 | 8538 | "Set metric of redistributed routes\n" |
8539 | "Default metric\n") | |
718e3744 | 8540 | { |
a3d826f0 | 8541 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8542 | |
d62a17ae | 8543 | ospf->default_metric = -1; |
68980084 | 8544 | |
d62a17ae | 8545 | return CMD_SUCCESS; |
718e3744 | 8546 | } |
8547 | ||
718e3744 | 8548 | |
8549 | DEFUN (ospf_distance, | |
8550 | ospf_distance_cmd, | |
6147e2c6 | 8551 | "distance (1-255)", |
eaa1ae0d | 8552 | "Administrative distance\n" |
718e3744 | 8553 | "OSPF Administrative distance\n") |
8554 | { | |
a3d826f0 | 8555 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8556 | int idx_number = 1; |
68980084 | 8557 | |
d62a17ae | 8558 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 8559 | |
d62a17ae | 8560 | return CMD_SUCCESS; |
718e3744 | 8561 | } |
8562 | ||
8563 | DEFUN (no_ospf_distance, | |
8564 | no_ospf_distance_cmd, | |
6147e2c6 | 8565 | "no distance (1-255)", |
718e3744 | 8566 | NO_STR |
eaa1ae0d | 8567 | "Administrative distance\n" |
718e3744 | 8568 | "OSPF Administrative distance\n") |
8569 | { | |
a3d826f0 | 8570 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8571 | |
d62a17ae | 8572 | ospf->distance_all = 0; |
68980084 | 8573 | |
d62a17ae | 8574 | return CMD_SUCCESS; |
718e3744 | 8575 | } |
8576 | ||
8577 | DEFUN (no_ospf_distance_ospf, | |
8578 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 8579 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 8580 | NO_STR |
eaa1ae0d QY |
8581 | "Administrative distance\n" |
8582 | "OSPF administrative distance\n" | |
718e3744 | 8583 | "Intra-area routes\n" |
813d4307 | 8584 | "Distance for intra-area routes\n" |
718e3744 | 8585 | "Inter-area routes\n" |
813d4307 DW |
8586 | "Distance for inter-area routes\n" |
8587 | "External routes\n" | |
8588 | "Distance for external routes\n") | |
718e3744 | 8589 | { |
a3d826f0 | 8590 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8591 | int idx = 0; |
718e3744 | 8592 | |
d62a17ae | 8593 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
8594 | idx = ospf->distance_intra = 0; | |
8595 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
8596 | idx = ospf->distance_inter = 0; | |
8597 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
8598 | ospf->distance_external = 0; | |
718e3744 | 8599 | |
d62a17ae | 8600 | return CMD_SUCCESS; |
718e3744 | 8601 | } |
8602 | ||
6f2a6703 CF |
8603 | DEFUN (ospf_distance_ospf, |
8604 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
8605 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
8606 | "Administrative distance\n" | |
8607 | "OSPF administrative distance\n" | |
718e3744 | 8608 | "Intra-area routes\n" |
8609 | "Distance for intra-area routes\n" | |
718e3744 | 8610 | "Inter-area routes\n" |
8611 | "Distance for inter-area routes\n" | |
8612 | "External routes\n" | |
718e3744 | 8613 | "Distance for external routes\n") |
8614 | { | |
a3d826f0 | 8615 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8616 | int idx = 0; |
68980084 | 8617 | |
926b88f0 CS |
8618 | ospf->distance_intra = 0; |
8619 | ospf->distance_inter = 0; | |
8620 | ospf->distance_external = 0; | |
8621 | ||
d62a17ae | 8622 | if (argv_find(argv, argc, "intra-area", &idx)) |
8623 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
8624 | idx = 0; | |
8625 | if (argv_find(argv, argc, "inter-area", &idx)) | |
8626 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
8627 | idx = 0; | |
8628 | if (argv_find(argv, argc, "external", &idx)) | |
8629 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 8630 | |
d62a17ae | 8631 | return CMD_SUCCESS; |
718e3744 | 8632 | } |
8633 | ||
d7d73ffc | 8634 | #if 0 |
718e3744 | 8635 | DEFUN (ospf_distance_source, |
8636 | ospf_distance_source_cmd, | |
6147e2c6 | 8637 | "distance (1-255) A.B.C.D/M", |
718e3744 | 8638 | "Administrative distance\n" |
8639 | "Distance value\n" | |
8640 | "IP source prefix\n") | |
8641 | { | |
cdc2d765 | 8642 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8643 | int idx_number = 1; |
8644 | int idx_ipv4_prefixlen = 2; | |
020709f9 | 8645 | |
8d769265 | 8646 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
68980084 | 8647 | |
718e3744 | 8648 | return CMD_SUCCESS; |
8649 | } | |
8650 | ||
8651 | DEFUN (no_ospf_distance_source, | |
8652 | no_ospf_distance_source_cmd, | |
6147e2c6 | 8653 | "no distance (1-255) A.B.C.D/M", |
718e3744 | 8654 | NO_STR |
8655 | "Administrative distance\n" | |
8656 | "Distance value\n" | |
8657 | "IP source prefix\n") | |
8658 | { | |
cdc2d765 | 8659 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8660 | int idx_number = 2; |
8661 | int idx_ipv4_prefixlen = 3; | |
020709f9 | 8662 | |
8d769265 | 8663 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
020709f9 | 8664 | |
718e3744 | 8665 | return CMD_SUCCESS; |
8666 | } | |
8667 | ||
8668 | DEFUN (ospf_distance_source_access_list, | |
8669 | ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8670 | "distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8671 | "Administrative distance\n" |
8672 | "Distance value\n" | |
8673 | "IP source prefix\n" | |
8674 | "Access list name\n") | |
8675 | { | |
cdc2d765 | 8676 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8677 | int idx_number = 1; |
8678 | int idx_ipv4_prefixlen = 2; | |
8679 | int idx_word = 3; | |
020709f9 | 8680 | |
8d769265 | 8681 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8682 | |
718e3744 | 8683 | return CMD_SUCCESS; |
8684 | } | |
8685 | ||
8686 | DEFUN (no_ospf_distance_source_access_list, | |
8687 | no_ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8688 | "no distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8689 | NO_STR |
8690 | "Administrative distance\n" | |
8691 | "Distance value\n" | |
8692 | "IP source prefix\n" | |
8693 | "Access list name\n") | |
8694 | { | |
cdc2d765 | 8695 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8696 | int idx_number = 2; |
8697 | int idx_ipv4_prefixlen = 3; | |
8698 | int idx_word = 4; | |
020709f9 | 8699 | |
8d769265 | 8700 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8701 | |
718e3744 | 8702 | return CMD_SUCCESS; |
8703 | } | |
d7d73ffc | 8704 | #endif |
718e3744 | 8705 | |
ba682537 | 8706 | DEFUN (ip_ospf_mtu_ignore, |
8707 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8708 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 8709 | "IP Information\n" |
8710 | "OSPF interface commands\n" | |
99a522c7 | 8711 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8712 | "Address of interface\n") |
ba682537 | 8713 | { |
d62a17ae | 8714 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8715 | int idx_ipv4 = 3; | |
8716 | struct in_addr addr; | |
8717 | int ret; | |
8718 | ||
8719 | struct ospf_if_params *params; | |
8720 | params = IF_DEF_PARAMS(ifp); | |
8721 | ||
8722 | if (argc == 4) { | |
8723 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8724 | if (!ret) { | |
8725 | vty_out(vty, | |
8726 | "Please specify interface address by A.B.C.D\n"); | |
8727 | return CMD_WARNING_CONFIG_FAILED; | |
8728 | } | |
8729 | params = ospf_get_if_params(ifp, addr); | |
8730 | ospf_if_update_params(ifp, addr); | |
8731 | } | |
8732 | params->mtu_ignore = 1; | |
8733 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8734 | SET_IF_PARAM(params, mtu_ignore); | |
8735 | else { | |
8736 | UNSET_IF_PARAM(params, mtu_ignore); | |
8737 | if (params != IF_DEF_PARAMS(ifp)) { | |
8738 | ospf_free_if_params(ifp, addr); | |
8739 | ospf_if_update_params(ifp, addr); | |
8740 | } | |
8741 | } | |
8742 | return CMD_SUCCESS; | |
ba682537 | 8743 | } |
8744 | ||
ba682537 | 8745 | DEFUN (no_ip_ospf_mtu_ignore, |
8746 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8747 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 8748 | NO_STR |
ba682537 | 8749 | "IP Information\n" |
8750 | "OSPF interface commands\n" | |
99a522c7 | 8751 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8752 | "Address of interface\n") |
ba682537 | 8753 | { |
d62a17ae | 8754 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8755 | int idx_ipv4 = 4; | |
8756 | struct in_addr addr; | |
8757 | int ret; | |
8758 | ||
8759 | struct ospf_if_params *params; | |
8760 | params = IF_DEF_PARAMS(ifp); | |
8761 | ||
8762 | if (argc == 5) { | |
8763 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8764 | if (!ret) { | |
8765 | vty_out(vty, | |
8766 | "Please specify interface address by A.B.C.D\n"); | |
8767 | return CMD_WARNING_CONFIG_FAILED; | |
8768 | } | |
8769 | params = ospf_get_if_params(ifp, addr); | |
8770 | ospf_if_update_params(ifp, addr); | |
8771 | } | |
8772 | params->mtu_ignore = 0; | |
8773 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8774 | SET_IF_PARAM(params, mtu_ignore); | |
8775 | else { | |
8776 | UNSET_IF_PARAM(params, mtu_ignore); | |
8777 | if (params != IF_DEF_PARAMS(ifp)) { | |
8778 | ospf_free_if_params(ifp, addr); | |
8779 | ospf_if_update_params(ifp, addr); | |
8780 | } | |
8781 | } | |
8782 | return CMD_SUCCESS; | |
ba682537 | 8783 | } |
8784 | ||
6b0655a2 | 8785 | |
88d6cf37 | 8786 | DEFUN (ospf_max_metric_router_lsa_admin, |
8787 | ospf_max_metric_router_lsa_admin_cmd, | |
8788 | "max-metric router-lsa administrative", | |
8789 | "OSPF maximum / infinite-distance metric\n" | |
8790 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8791 | "Administratively applied, for an indefinite period\n") | |
8792 | { | |
a3d826f0 | 8793 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8794 | struct listnode *ln; |
8795 | struct ospf_area *area; | |
7c8ff89e | 8796 | |
d62a17ae | 8797 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
8798 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 8799 | |
d62a17ae | 8800 | if (!CHECK_FLAG(area->stub_router_state, |
8801 | OSPF_AREA_IS_STUB_ROUTED)) | |
8802 | ospf_router_lsa_update_area(area); | |
8803 | } | |
4ba4fc85 | 8804 | |
d62a17ae | 8805 | /* Allows for areas configured later to get the property */ |
8806 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
8807 | ||
8808 | return CMD_SUCCESS; | |
88d6cf37 | 8809 | } |
8810 | ||
8811 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
8812 | no_ospf_max_metric_router_lsa_admin_cmd, | |
8813 | "no max-metric router-lsa administrative", | |
8814 | NO_STR | |
8815 | "OSPF maximum / infinite-distance metric\n" | |
8816 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8817 | "Administratively applied, for an indefinite period\n") | |
8818 | { | |
a3d826f0 | 8819 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8820 | struct listnode *ln; |
8821 | struct ospf_area *area; | |
8822 | ||
8823 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8824 | UNSET_FLAG(area->stub_router_state, | |
8825 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
8826 | ||
8827 | /* Don't trample on the start-up stub timer */ | |
8828 | if (CHECK_FLAG(area->stub_router_state, | |
8829 | OSPF_AREA_IS_STUB_ROUTED) | |
8830 | && !area->t_stub_router) { | |
8831 | UNSET_FLAG(area->stub_router_state, | |
8832 | OSPF_AREA_IS_STUB_ROUTED); | |
8833 | ospf_router_lsa_update_area(area); | |
8834 | } | |
8835 | } | |
8836 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
8837 | return CMD_SUCCESS; | |
88d6cf37 | 8838 | } |
8839 | ||
8840 | DEFUN (ospf_max_metric_router_lsa_startup, | |
8841 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 8842 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 8843 | "OSPF maximum / infinite-distance metric\n" |
8844 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8845 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8846 | "Time (seconds) to advertise self as stub-router\n") | |
8847 | { | |
a3d826f0 | 8848 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8849 | int idx_number = 3; |
8850 | unsigned int seconds; | |
8851 | ||
b5a8894d | 8852 | if (argc < 4) { |
d62a17ae | 8853 | vty_out(vty, "%% Must supply stub-router period"); |
8854 | return CMD_WARNING_CONFIG_FAILED; | |
8855 | } | |
8856 | ||
8857 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8858 | ||
8859 | ospf->stub_router_startup_time = seconds; | |
8860 | ||
8861 | return CMD_SUCCESS; | |
88d6cf37 | 8862 | } |
8863 | ||
8864 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
8865 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 8866 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 8867 | NO_STR |
8868 | "OSPF maximum / infinite-distance metric\n" | |
8869 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8870 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
8871 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 8872 | { |
a3d826f0 | 8873 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8874 | struct listnode *ln; |
8875 | struct ospf_area *area; | |
8876 | ||
8877 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8878 | ||
8879 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8880 | SET_FLAG(area->stub_router_state, | |
8881 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
8882 | OSPF_TIMER_OFF(area->t_stub_router); | |
8883 | ||
8884 | /* Don't trample on admin stub routed */ | |
8885 | if (!CHECK_FLAG(area->stub_router_state, | |
8886 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8887 | UNSET_FLAG(area->stub_router_state, | |
8888 | OSPF_AREA_IS_STUB_ROUTED); | |
8889 | ospf_router_lsa_update_area(area); | |
8890 | } | |
8891 | } | |
8892 | return CMD_SUCCESS; | |
88d6cf37 | 8893 | } |
8894 | ||
a1afa410 | 8895 | |
88d6cf37 | 8896 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
8897 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 8898 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 8899 | "OSPF maximum / infinite-distance metric\n" |
8900 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8901 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8902 | "Time (seconds) to wait till full shutdown\n") | |
8903 | { | |
a3d826f0 | 8904 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8905 | int idx_number = 3; |
8906 | unsigned int seconds; | |
8907 | ||
b5a8894d | 8908 | if (argc < 4) { |
d62a17ae | 8909 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
8910 | return CMD_WARNING_CONFIG_FAILED; | |
8911 | } | |
8912 | ||
8913 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8914 | ||
8915 | ospf->stub_router_shutdown_time = seconds; | |
8916 | ||
8917 | return CMD_SUCCESS; | |
88d6cf37 | 8918 | } |
8919 | ||
8920 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
8921 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 8922 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 8923 | NO_STR |
8924 | "OSPF maximum / infinite-distance metric\n" | |
8925 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8926 | "Advertise stub-router prior to full shutdown of OSPF\n" |
8927 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 8928 | { |
a3d826f0 | 8929 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 8930 | |
d62a17ae | 8931 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
8932 | ||
8933 | return CMD_SUCCESS; | |
88d6cf37 | 8934 | } |
8935 | ||
d62a17ae | 8936 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
8937 | { | |
8938 | struct listnode *ln; | |
8939 | struct ospf_area *area; | |
8940 | ||
8941 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8942 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
8943 | ospf->stub_router_startup_time); | |
8944 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8945 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
8946 | ospf->stub_router_shutdown_time); | |
8947 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8948 | if (CHECK_FLAG(area->stub_router_state, | |
8949 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8950 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
8951 | break; | |
8952 | } | |
8953 | } | |
8954 | return; | |
8955 | } | |
8956 | ||
b5a8894d | 8957 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
8958 | struct route_table *rt, |
8959 | json_object *json) | |
d62a17ae | 8960 | { |
8961 | struct route_node *rn; | |
8962 | struct ospf_route * or ; | |
8963 | struct listnode *pnode, *pnnode; | |
8964 | struct ospf_path *path; | |
0f478e30 CS |
8965 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
8966 | *json_nexthop = NULL; | |
d62a17ae | 8967 | |
0f478e30 | 8968 | if (!json) |
996c9314 LB |
8969 | vty_out(vty, |
8970 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 8971 | |
0f478e30 CS |
8972 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
8973 | if ((or = rn->info) == NULL) | |
8974 | continue; | |
8975 | char buf1[PREFIX2STR_BUFFER]; | |
8976 | ||
8977 | memset(buf1, 0, sizeof(buf1)); | |
8978 | prefix2str(&rn->p, buf1, sizeof(buf1)); | |
8979 | ||
8980 | json_route = json_object_new_object(); | |
8981 | if (json) { | |
996c9314 LB |
8982 | json_object_object_add(json, buf1, json_route); |
8983 | json_object_to_json_string_ext( | |
8984 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 CS |
8985 | } |
8986 | ||
8987 | switch (or->path_type) { | |
8988 | case OSPF_PATH_INTER_AREA: | |
8989 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
8990 | if (json) { | |
8991 | json_object_string_add(json_route, | |
996c9314 LB |
8992 | "routeType", |
8993 | "N IA"); | |
8994 | json_object_int_add(json_route, "cost", | |
0f478e30 CS |
8995 | or->cost); |
8996 | json_object_string_add( | |
996c9314 LB |
8997 | json_route, "area", |
8998 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 | 8999 | } else { |
d62a17ae | 9000 | vty_out(vty, |
996c9314 | 9001 | "N IA %-18s [%d] area: %s\n", |
d62a17ae | 9002 | buf1, or->cost, |
996c9314 | 9003 | inet_ntoa(or->u.std.area_id)); |
0f478e30 | 9004 | } |
996c9314 | 9005 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
9006 | if (json) { |
9007 | json_object_string_add(json_route, | |
996c9314 LB |
9008 | "routeType", |
9009 | "D IA"); | |
0f478e30 | 9010 | } else { |
d62a17ae | 9011 | vty_out(vty, |
9012 | "D IA %-18s Discard entry\n", | |
9013 | buf1); | |
0f478e30 CS |
9014 | } |
9015 | } | |
9016 | break; | |
9017 | case OSPF_PATH_INTRA_AREA: | |
9018 | if (json) { | |
996c9314 LB |
9019 | json_object_string_add(json_route, "routeType", |
9020 | "N"); | |
0f478e30 | 9021 | json_object_int_add(json_route, "cost", |
996c9314 LB |
9022 | or->cost); |
9023 | json_object_string_add( | |
9024 | json_route, "area", | |
9025 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 | 9026 | } else { |
d62a17ae | 9027 | vty_out(vty, "N %-18s [%d] area: %s\n", |
9028 | buf1, or->cost, | |
9029 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 CS |
9030 | } |
9031 | break; | |
9032 | default: | |
9033 | break; | |
9034 | } | |
9035 | ||
9036 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
9037 | if (json) { | |
9038 | json_nexthop_array = json_object_new_array(); | |
9039 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 9040 | json_nexthop_array); |
d62a17ae | 9041 | } |
9042 | ||
0f478e30 CS |
9043 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
9044 | path)) { | |
9045 | if (json) { | |
996c9314 LB |
9046 | json_nexthop = json_object_new_object(); |
9047 | json_object_array_add( | |
9048 | json_nexthop_array, | |
9049 | json_nexthop); | |
0f478e30 CS |
9050 | } |
9051 | if (if_lookup_by_index(path->ifindex, | |
9052 | ospf->vrf_id)) { | |
9053 | ||
9054 | if (path->nexthop.s_addr == 0) { | |
9055 | if (json) { | |
9056 | json_object_string_add( | |
9057 | json_nexthop, | |
996c9314 | 9058 | "ip", " "); |
0f478e30 CS |
9059 | json_object_string_add( |
9060 | json_nexthop, | |
9061 | "directly attached to", | |
d62a17ae | 9062 | ifindex2ifname( |
996c9314 LB |
9063 | path->ifindex, |
9064 | ospf->vrf_id)); | |
0f478e30 | 9065 | } else { |
d62a17ae | 9066 | vty_out(vty, |
996c9314 LB |
9067 | "%24s directly attached to %s\n", |
9068 | "", | |
9069 | ifindex2ifname( | |
9070 | path->ifindex, | |
9071 | ospf->vrf_id)); | |
0f478e30 CS |
9072 | } |
9073 | } else { | |
9074 | if (json) { | |
9075 | json_object_string_add( | |
9076 | json_nexthop, | |
9077 | "ip", | |
d62a17ae | 9078 | inet_ntoa( |
996c9314 | 9079 | path->nexthop)); |
0f478e30 CS |
9080 | json_object_string_add( |
9081 | json_nexthop, | |
9082 | "via", | |
d62a17ae | 9083 | ifindex2ifname( |
996c9314 LB |
9084 | path->ifindex, |
9085 | ospf->vrf_id)); | |
0f478e30 CS |
9086 | } else { |
9087 | vty_out(vty, | |
996c9314 LB |
9088 | "%24s via %s, %s\n", |
9089 | "", | |
9090 | inet_ntoa( | |
9091 | path->nexthop), | |
9092 | ifindex2ifname( | |
9093 | path->ifindex, | |
9094 | ospf->vrf_id)); | |
0f478e30 | 9095 | } |
d62a17ae | 9096 | } |
9097 | } | |
0f478e30 | 9098 | } |
d62a17ae | 9099 | } |
0f478e30 CS |
9100 | if (!json) |
9101 | json_object_free(json_route); | |
9102 | } | |
9103 | if (!json) | |
9104 | vty_out(vty, "\n"); | |
d62a17ae | 9105 | } |
9106 | ||
b5a8894d | 9107 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
9108 | struct route_table *rtrs, |
9109 | json_object *json) | |
d62a17ae | 9110 | { |
9111 | struct route_node *rn; | |
9112 | struct ospf_route * or ; | |
9113 | struct listnode *pnode; | |
9114 | struct listnode *node; | |
9115 | struct ospf_path *path; | |
0f478e30 CS |
9116 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
9117 | *json_nexthop = NULL; | |
d62a17ae | 9118 | |
0f478e30 | 9119 | if (!json) |
996c9314 LB |
9120 | vty_out(vty, |
9121 | "============ OSPF router routing table =============\n"); | |
d62a17ae | 9122 | |
0f478e30 CS |
9123 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
9124 | if (rn->info == NULL) | |
9125 | continue; | |
9126 | int flag = 0; | |
9127 | ||
9128 | json_route = json_object_new_object(); | |
9129 | if (json) { | |
996c9314 LB |
9130 | json_object_object_add(json, inet_ntoa(rn->p.u.prefix4), |
9131 | json_route); | |
9132 | json_object_string_add(json_route, "routeType", "R "); | |
0f478e30 | 9133 | } else { |
d62a17ae | 9134 | vty_out(vty, "R %-15s ", |
9135 | inet_ntoa(rn->p.u.prefix4)); | |
0f478e30 | 9136 | } |
d62a17ae | 9137 | |
996c9314 | 9138 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
9139 | if (flag++) { |
9140 | if (!json) | |
d62a17ae | 9141 | vty_out(vty, "%24s", ""); |
0f478e30 | 9142 | } |
d62a17ae | 9143 | |
0f478e30 CS |
9144 | /* Show path. */ |
9145 | if (json) { | |
9146 | json_object_int_add(json_route, "cost", | |
9147 | or->cost); | |
996c9314 LB |
9148 | json_object_string_add( |
9149 | json_route, "area", | |
0f478e30 | 9150 | inet_ntoa(or->u.std.area_id)); |
996c9314 LB |
9151 | if (or->path_type == OSPF_PATH_INTER_AREA) |
9152 | json_object_boolean_true_add(json_route, | |
9153 | "IA"); | |
0f478e30 | 9154 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
9155 | json_object_string_add(json_route, |
9156 | "routerType", | |
9157 | "abr"); | |
9158 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
9159 | json_object_string_add(json_route, | |
9160 | "routerType", | |
9161 | "asbr"); | |
0f478e30 | 9162 | } else { |
d62a17ae | 9163 | vty_out(vty, "%s [%d] area: %s", |
996c9314 LB |
9164 | (or->path_type == OSPF_PATH_INTER_AREA |
9165 | ? "IA" | |
9166 | : " "), | |
9167 | or->cost, inet_ntoa(or->u.std.area_id)); | |
d62a17ae | 9168 | /* Show flags. */ |
9169 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
9170 | (or->u.std.flags & ROUTER_LSA_BORDER |
9171 | ? ", ABR" | |
9172 | : ""), | |
9173 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
9174 | ? ", ASBR" | |
9175 | : "")); | |
0f478e30 CS |
9176 | } |
9177 | ||
9178 | if (json) { | |
996c9314 | 9179 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 9180 | json_object_object_add(json_route, "nexthops", |
996c9314 | 9181 | json_nexthop_array); |
0f478e30 CS |
9182 | } |
9183 | ||
996c9314 | 9184 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 9185 | if (json) { |
996c9314 | 9186 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
9187 | json_object_array_add( |
9188 | json_nexthop_array, | |
9189 | json_nexthop); | |
9190 | } | |
9191 | if (if_lookup_by_index(path->ifindex, | |
9192 | ospf->vrf_id)) { | |
9193 | if (path->nexthop.s_addr == 0) { | |
9194 | if (json) { | |
9195 | json_object_string_add( | |
9196 | json_nexthop, | |
996c9314 | 9197 | "ip", " "); |
0f478e30 CS |
9198 | json_object_string_add( |
9199 | json_nexthop, | |
9200 | "directly attached to", | |
d62a17ae | 9201 | ifindex2ifname( |
9202 | path->ifindex, | |
b5a8894d | 9203 | ospf->vrf_id)); |
0f478e30 | 9204 | } else { |
d62a17ae | 9205 | vty_out(vty, |
996c9314 LB |
9206 | "%24s directly attached to %s\n", |
9207 | "", | |
9208 | ifindex2ifname( | |
9209 | path->ifindex, | |
9210 | ospf->vrf_id)); | |
0f478e30 CS |
9211 | } |
9212 | } else { | |
9213 | if (json) { | |
9214 | json_object_string_add( | |
9215 | json_nexthop, | |
9216 | "ip", | |
996c9314 LB |
9217 | inet_ntoa( |
9218 | path->nexthop)); | |
0f478e30 CS |
9219 | json_object_string_add( |
9220 | json_nexthop, | |
9221 | "via", | |
d62a17ae | 9222 | ifindex2ifname( |
9223 | path->ifindex, | |
b5a8894d | 9224 | ospf->vrf_id)); |
0f478e30 CS |
9225 | } else { |
9226 | vty_out(vty, | |
996c9314 LB |
9227 | "%24s via %s, %s\n", |
9228 | "", | |
9229 | inet_ntoa( | |
9230 | path->nexthop), | |
9231 | ifindex2ifname( | |
9232 | path->ifindex, | |
9233 | ospf->vrf_id)); | |
0f478e30 | 9234 | } |
d62a17ae | 9235 | } |
9236 | } | |
9237 | } | |
9238 | } | |
0f478e30 CS |
9239 | if (!json) |
9240 | json_object_free(json_route); | |
9241 | } | |
9242 | if (!json) | |
9243 | vty_out(vty, "\n"); | |
d62a17ae | 9244 | } |
9245 | ||
b5a8894d | 9246 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
9247 | struct route_table *rt, |
9248 | json_object *json) | |
d62a17ae | 9249 | { |
9250 | struct route_node *rn; | |
9251 | struct ospf_route *er; | |
9252 | struct listnode *pnode, *pnnode; | |
9253 | struct ospf_path *path; | |
0f478e30 CS |
9254 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
9255 | *json_nexthop = NULL; | |
d62a17ae | 9256 | |
0f478e30 | 9257 | if (!json) |
996c9314 LB |
9258 | vty_out(vty, |
9259 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
9260 | |
9261 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
9262 | if ((er = rn->info) == NULL) | |
9263 | continue; | |
9264 | ||
9265 | char buf1[19]; | |
9266 | ||
9267 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
9268 | rn->p.prefixlen); | |
9269 | json_route = json_object_new_object(); | |
9270 | if (json) { | |
996c9314 LB |
9271 | json_object_object_add(json, buf1, json_route); |
9272 | json_object_to_json_string_ext( | |
9273 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 | 9274 | } |
d62a17ae | 9275 | |
0f478e30 CS |
9276 | switch (er->path_type) { |
9277 | case OSPF_PATH_TYPE1_EXTERNAL: | |
9278 | if (json) { | |
996c9314 | 9279 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
9280 | "N E1"); |
9281 | json_object_int_add(json_route, "cost", | |
996c9314 | 9282 | er->cost); |
0f478e30 | 9283 | } else { |
d62a17ae | 9284 | vty_out(vty, |
996c9314 LB |
9285 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
9286 | "\n", | |
9287 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
9288 | } |
9289 | break; | |
9290 | case OSPF_PATH_TYPE2_EXTERNAL: | |
9291 | if (json) { | |
996c9314 | 9292 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
9293 | "N E2"); |
9294 | json_object_int_add(json_route, "cost", | |
996c9314 | 9295 | er->cost); |
0f478e30 | 9296 | } else { |
d62a17ae | 9297 | vty_out(vty, |
996c9314 LB |
9298 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
9299 | "\n", | |
9300 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 9301 | er->u.ext.tag); |
d62a17ae | 9302 | } |
0f478e30 CS |
9303 | break; |
9304 | } | |
d62a17ae | 9305 | |
0f478e30 CS |
9306 | if (json) { |
9307 | json_nexthop_array = json_object_new_array(); | |
9308 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 9309 | json_nexthop_array); |
0f478e30 CS |
9310 | } |
9311 | ||
996c9314 | 9312 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
9313 | if (json) { |
9314 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
9315 | json_object_array_add(json_nexthop_array, |
9316 | json_nexthop); | |
0f478e30 CS |
9317 | } |
9318 | ||
996c9314 | 9319 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
0f478e30 CS |
9320 | if (path->nexthop.s_addr == 0) { |
9321 | if (json) { | |
9322 | json_object_string_add( | |
996c9314 LB |
9323 | json_nexthop, "ip", |
9324 | " "); | |
0f478e30 CS |
9325 | json_object_string_add( |
9326 | json_nexthop, | |
9327 | "directly attached to", | |
d62a17ae | 9328 | ifindex2ifname( |
996c9314 LB |
9329 | path->ifindex, |
9330 | ospf->vrf_id)); | |
0f478e30 | 9331 | } else { |
d62a17ae | 9332 | vty_out(vty, |
996c9314 LB |
9333 | "%24s directly attached to %s\n", |
9334 | "", | |
9335 | ifindex2ifname( | |
9336 | path->ifindex, | |
9337 | ospf->vrf_id)); | |
0f478e30 CS |
9338 | } |
9339 | } else { | |
9340 | if (json) { | |
9341 | json_object_string_add( | |
996c9314 | 9342 | json_nexthop, "ip", |
d62a17ae | 9343 | inet_ntoa( |
996c9314 | 9344 | path->nexthop)); |
0f478e30 | 9345 | json_object_string_add( |
996c9314 | 9346 | json_nexthop, "via", |
d62a17ae | 9347 | ifindex2ifname( |
996c9314 LB |
9348 | path->ifindex, |
9349 | ospf->vrf_id)); | |
0f478e30 CS |
9350 | } else { |
9351 | vty_out(vty, | |
996c9314 LB |
9352 | "%24s via %s, %s\n", |
9353 | "", | |
9354 | inet_ntoa( | |
9355 | path->nexthop), | |
9356 | ifindex2ifname( | |
9357 | path->ifindex, | |
9358 | ospf->vrf_id)); | |
0f478e30 | 9359 | } |
d62a17ae | 9360 | } |
54bedb55 | 9361 | } |
d62a17ae | 9362 | } |
0f478e30 CS |
9363 | if (!json) |
9364 | json_object_free(json_route); | |
9365 | } | |
9366 | if (!json) | |
9367 | vty_out(vty, "\n"); | |
718e3744 | 9368 | } |
9369 | ||
d62a17ae | 9370 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
9371 | struct ospf *ospf, |
9372 | uint8_t use_vrf) | |
718e3744 | 9373 | { |
d62a17ae | 9374 | if (ospf->instance) |
9375 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 9376 | |
b1c3ae8c | 9377 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 9378 | |
d62a17ae | 9379 | if (ospf->new_table == NULL) { |
9380 | vty_out(vty, "No OSPF routing information exist\n"); | |
9381 | return CMD_SUCCESS; | |
9382 | } | |
718e3744 | 9383 | |
d62a17ae | 9384 | /* Show Network routes. |
9385 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 9386 | |
d62a17ae | 9387 | /* Show Router routes. */ |
0f478e30 | 9388 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 9389 | |
d62a17ae | 9390 | vty_out(vty, "\n"); |
7c8ff89e | 9391 | |
d62a17ae | 9392 | return CMD_SUCCESS; |
718e3744 | 9393 | } |
718e3744 | 9394 | |
7c8ff89e DS |
9395 | DEFUN (show_ip_ospf_border_routers, |
9396 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 9397 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 9398 | SHOW_STR |
9399 | IP_STR | |
9400 | "OSPF information\n" | |
b5a8894d CS |
9401 | VRF_CMD_HELP_STR |
9402 | "All VRFs\n" | |
7c8ff89e | 9403 | "Show all the ABR's and ASBR's\n") |
718e3744 | 9404 | { |
b5a8894d CS |
9405 | struct ospf *ospf = NULL; |
9406 | struct listnode *node = NULL; | |
9407 | char *vrf_name = NULL; | |
2951a7a4 | 9408 | bool all_vrf = false; |
b5a8894d CS |
9409 | int ret = CMD_SUCCESS; |
9410 | int inst = 0; | |
9411 | int idx_vrf = 0; | |
d7c0a89a | 9412 | uint8_t use_vrf = 0; |
68980084 | 9413 | |
43b8d1d8 | 9414 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 9415 | |
b5a8894d | 9416 | if (vrf_name) { |
2951a7a4 | 9417 | bool ospf_output = false; |
874f58d8 | 9418 | |
b1c3ae8c | 9419 | use_vrf = 1; |
94d4c685 | 9420 | |
b5a8894d CS |
9421 | if (all_vrf) { |
9422 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9423 | if (!ospf->oi_running) | |
9424 | continue; | |
b5a8894d | 9425 | |
2951a7a4 | 9426 | ospf_output = true; |
996c9314 LB |
9427 | ret = show_ip_ospf_border_routers_common( |
9428 | vty, ospf, use_vrf); | |
b5a8894d | 9429 | } |
9f049418 DS |
9430 | |
9431 | if (!ospf_output) | |
94d4c685 | 9432 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d CS |
9433 | } else { |
9434 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 9435 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 9436 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 9437 | return CMD_SUCCESS; |
9f049418 | 9438 | } |
b5a8894d | 9439 | |
b1c3ae8c CS |
9440 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
9441 | use_vrf); | |
b5a8894d CS |
9442 | } |
9443 | } else { | |
9444 | /* Display default ospf (instance 0) info */ | |
9445 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 9446 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 9447 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 9448 | return CMD_SUCCESS; |
9f049418 DS |
9449 | } |
9450 | ||
b1c3ae8c | 9451 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
9452 | } |
9453 | ||
9454 | return ret; | |
7c8ff89e DS |
9455 | } |
9456 | ||
9457 | DEFUN (show_ip_ospf_instance_border_routers, | |
9458 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 9459 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
9460 | SHOW_STR |
9461 | IP_STR | |
9462 | "OSPF information\n" | |
9463 | "Instance ID\n" | |
9464 | "Show all the ABR's and ASBR's\n") | |
9465 | { | |
d62a17ae | 9466 | int idx_number = 3; |
9467 | struct ospf *ospf; | |
d7c0a89a | 9468 | unsigned short instance = 0; |
7c8ff89e | 9469 | |
d62a17ae | 9470 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
9471 | ospf = ospf_lookup_instance(instance); |
9472 | if (ospf == NULL) | |
9473 | return CMD_NOT_MY_INSTANCE; | |
9474 | ||
9475 | if (!ospf->oi_running) | |
d62a17ae | 9476 | return CMD_SUCCESS; |
7c8ff89e | 9477 | |
b1c3ae8c | 9478 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
9479 | } |
9480 | ||
b1c3ae8c | 9481 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 9482 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 9483 | { |
0f478e30 CS |
9484 | json_object *json_vrf = NULL; |
9485 | ||
d62a17ae | 9486 | if (ospf->instance) |
9487 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 9488 | |
0f478e30 CS |
9489 | |
9490 | if (json) { | |
9491 | if (use_vrf) | |
9492 | json_vrf = json_object_new_object(); | |
9493 | else | |
9494 | json_vrf = json; | |
9495 | } | |
9496 | ||
9497 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
87bd50e8 | 9498 | |
d62a17ae | 9499 | if (ospf->new_table == NULL) { |
9500 | vty_out(vty, "No OSPF routing information exist\n"); | |
9501 | return CMD_SUCCESS; | |
9502 | } | |
718e3744 | 9503 | |
d62a17ae | 9504 | /* Show Network routes. */ |
0f478e30 | 9505 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 9506 | |
d62a17ae | 9507 | /* Show Router routes. */ |
0f478e30 | 9508 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 9509 | |
d62a17ae | 9510 | /* Show AS External routes. */ |
0f478e30 CS |
9511 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
9512 | json_vrf); | |
718e3744 | 9513 | |
0f478e30 CS |
9514 | if (json) { |
9515 | if (use_vrf) { | |
996c9314 LB |
9516 | // json_object_object_add(json_vrf, "areas", |
9517 | // json_areas); | |
0f478e30 CS |
9518 | if (ospf->vrf_id == VRF_DEFAULT) |
9519 | json_object_object_add(json, "default", | |
9520 | json_vrf); | |
9521 | else | |
9522 | json_object_object_add(json, ospf->name, | |
9523 | json_vrf); | |
9524 | } | |
9525 | } else { | |
9526 | vty_out(vty, "\n"); | |
9527 | } | |
7c8ff89e | 9528 | |
d62a17ae | 9529 | return CMD_SUCCESS; |
718e3744 | 9530 | } |
9531 | ||
7c8ff89e DS |
9532 | DEFUN (show_ip_ospf_route, |
9533 | show_ip_ospf_route_cmd, | |
0f478e30 | 9534 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
9535 | SHOW_STR |
9536 | IP_STR | |
9537 | "OSPF information\n" | |
9538 | VRF_CMD_HELP_STR | |
9539 | "All VRFs\n" | |
0f478e30 CS |
9540 | "OSPF routing table\n" |
9541 | JSON_STR) | |
b5a8894d CS |
9542 | { |
9543 | struct ospf *ospf = NULL; | |
9544 | struct listnode *node = NULL; | |
9545 | char *vrf_name = NULL; | |
2951a7a4 | 9546 | bool all_vrf = false; |
b5a8894d CS |
9547 | int ret = CMD_SUCCESS; |
9548 | int inst = 0; | |
9549 | int idx_vrf = 0; | |
d7c0a89a | 9550 | uint8_t use_vrf = 0; |
9f049418 | 9551 | bool uj = use_json(argc, argv); |
0f478e30 CS |
9552 | json_object *json = NULL; |
9553 | ||
9554 | if (uj) | |
9555 | json = json_object_new_object(); | |
7c8ff89e | 9556 | |
43b8d1d8 | 9557 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 9558 | |
b5a8894d CS |
9559 | /* vrf input is provided could be all or specific vrf*/ |
9560 | if (vrf_name) { | |
2951a7a4 | 9561 | bool ospf_output = false; |
874f58d8 | 9562 | |
b1c3ae8c | 9563 | use_vrf = 1; |
94d4c685 | 9564 | |
b5a8894d CS |
9565 | if (all_vrf) { |
9566 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9567 | if (!ospf->oi_running) | |
9568 | continue; | |
2951a7a4 | 9569 | ospf_output = true; |
0f478e30 | 9570 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 9571 | use_vrf); |
b5a8894d | 9572 | } |
0f478e30 CS |
9573 | |
9574 | if (uj) { | |
1406159f | 9575 | /* Keep Non-pretty format */ |
0f478e30 | 9576 | vty_out(vty, "%s\n", |
1406159f | 9577 | json_object_to_json_string(json)); |
0f478e30 | 9578 | json_object_free(json); |
9f049418 DS |
9579 | } else if (!ospf_output) |
9580 | vty_out(vty, "%% OSPF instance not found\n"); | |
0f478e30 | 9581 | |
b5a8894d CS |
9582 | return ret; |
9583 | } | |
9584 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 9585 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
9586 | if (uj) { |
9587 | vty_out(vty, "%s\n", | |
9588 | json_object_to_json_string_ext( | |
9589 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 9590 | json_object_free(json); |
9f049418 | 9591 | } else |
94d4c685 | 9592 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 9593 | |
b5a8894d | 9594 | return CMD_SUCCESS; |
0f478e30 | 9595 | } |
b5a8894d CS |
9596 | } else { |
9597 | /* Display default ospf (instance 0) info */ | |
9598 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 9599 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
9600 | if (uj) { |
9601 | vty_out(vty, "%s\n", | |
9602 | json_object_to_json_string_ext( | |
9603 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 9604 | json_object_free(json); |
9f049418 | 9605 | } else |
94d4c685 | 9606 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 9607 | |
b5a8894d | 9608 | return CMD_SUCCESS; |
0f478e30 CS |
9609 | } |
9610 | } | |
9611 | ||
9612 | if (ospf) { | |
9613 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 9614 | /* Keep Non-pretty format */ |
0f478e30 | 9615 | if (uj) |
1406159f | 9616 | vty_out(vty, "%s\n", json_object_to_json_string(json)); |
b5a8894d CS |
9617 | } |
9618 | ||
0f478e30 CS |
9619 | if (uj) |
9620 | json_object_free(json); | |
b5a8894d CS |
9621 | |
9622 | return ret; | |
7c8ff89e DS |
9623 | } |
9624 | ||
9625 | DEFUN (show_ip_ospf_instance_route, | |
9626 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 9627 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
9628 | SHOW_STR |
9629 | IP_STR | |
9630 | "OSPF information\n" | |
9631 | "Instance ID\n" | |
9632 | "OSPF routing table\n") | |
9633 | { | |
d62a17ae | 9634 | int idx_number = 3; |
9635 | struct ospf *ospf; | |
d7c0a89a | 9636 | unsigned short instance = 0; |
7c8ff89e | 9637 | |
d62a17ae | 9638 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
9639 | ospf = ospf_lookup_instance(instance); |
9640 | if (ospf == NULL) | |
9641 | return CMD_NOT_MY_INSTANCE; | |
9642 | ||
9643 | if (!ospf->oi_running) | |
d62a17ae | 9644 | return CMD_SUCCESS; |
7c8ff89e | 9645 | |
0f478e30 | 9646 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 9647 | } |
6b0655a2 | 9648 | |
b5a8894d CS |
9649 | |
9650 | DEFUN (show_ip_ospf_vrfs, | |
9651 | show_ip_ospf_vrfs_cmd, | |
9652 | "show ip ospf vrfs [json]", | |
9653 | SHOW_STR | |
9654 | IP_STR | |
9655 | "OSPF information\n" | |
9656 | "Show OSPF VRFs \n" | |
9657 | JSON_STR) | |
9658 | { | |
9f049418 | 9659 | bool uj = use_json(argc, argv); |
b5a8894d CS |
9660 | json_object *json = NULL; |
9661 | json_object *json_vrfs = NULL; | |
9662 | struct ospf *ospf = NULL; | |
9663 | struct listnode *node = NULL; | |
9664 | int count = 0; | |
2b64873d | 9665 | static const char header[] = "Name Id RouterId "; |
b5a8894d CS |
9666 | |
9667 | if (uj) { | |
9668 | json = json_object_new_object(); | |
9669 | json_vrfs = json_object_new_object(); | |
9670 | } | |
9671 | ||
9672 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9673 | json_object *json_vrf = NULL; | |
9674 | const char *name = NULL; | |
fe3da9e7 | 9675 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
9676 | |
9677 | count++; | |
9678 | ||
9679 | if (!uj && count == 1) | |
9680 | vty_out(vty, "%s\n", header); | |
9681 | if (uj) | |
9682 | json_vrf = json_object_new_object(); | |
9683 | ||
946de1b9 | 9684 | if (ospf->vrf_id == VRF_DEFAULT) |
b5a8894d CS |
9685 | name = VRF_DEFAULT_NAME; |
9686 | else | |
9687 | name = ospf->name; | |
9688 | ||
996c9314 LB |
9689 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
9690 | ? -1 | |
9691 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
9692 | |
9693 | if (uj) { | |
9694 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
9695 | json_object_string_add(json_vrf, "routerId", | |
9696 | inet_ntoa(ospf->router_id)); | |
9697 | ||
9698 | json_object_object_add(json_vrfs, name, json_vrf); | |
9699 | ||
9700 | } else { | |
996c9314 LB |
9701 | vty_out(vty, "%-25s %-5d %-16s \n", name, |
9702 | ospf->vrf_id, inet_ntoa(ospf->router_id)); | |
b5a8894d CS |
9703 | } |
9704 | } | |
9705 | ||
9706 | if (uj) { | |
9707 | json_object_object_add(json, "vrfs", json_vrfs); | |
9708 | json_object_int_add(json, "totalVrfs", count); | |
9709 | ||
996c9314 LB |
9710 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
9711 | json, JSON_C_TO_STRING_PRETTY)); | |
b5a8894d CS |
9712 | json_object_free(json); |
9713 | } else { | |
9714 | if (count) | |
34d6798f | 9715 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
9716 | count); |
9717 | } | |
9718 | ||
9719 | return CMD_SUCCESS; | |
9720 | } | |
9721 | ||
2b64873d DL |
9722 | static const char *const ospf_abr_type_str[] = { |
9723 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
9724 | }; | |
718e3744 | 9725 | |
2b64873d DL |
9726 | static const char *const ospf_shortcut_mode_str[] = { |
9727 | "default", "enable", "disable" | |
9728 | }; | |
718e3744 | 9729 | |
2b64873d DL |
9730 | static const char *const ospf_int_type_str[] = { |
9731 | "unknown", /* should never be used. */ | |
9732 | "point-to-point", | |
9733 | "broadcast", | |
9734 | "non-broadcast", | |
9735 | "point-to-multipoint", | |
9736 | "virtual-link", /* should never be used. */ | |
9737 | "loopback" | |
9738 | }; | |
718e3744 | 9739 | |
545f0503 | 9740 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 9741 | { |
f4e14fdb | 9742 | struct listnode *node; |
d62a17ae | 9743 | struct interface *ifp; |
9744 | struct crypt_key *ck; | |
d62a17ae | 9745 | struct route_node *rn = NULL; |
9746 | struct ospf_if_params *params; | |
43b8d1d8 | 9747 | int write = 0; |
545f0503 | 9748 | struct ospf *ospf = vrf->info; |
d62a17ae | 9749 | |
545f0503 | 9750 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 9751 | |
545f0503 CS |
9752 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
9753 | continue; | |
35955c14 | 9754 | |
545f0503 | 9755 | vty_frame(vty, "!\n"); |
a36898e7 | 9756 | if (ifp->vrf_id == VRF_DEFAULT) |
545f0503 CS |
9757 | vty_frame(vty, "interface %s\n", ifp->name); |
9758 | else | |
996c9314 LB |
9759 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, |
9760 | vrf->name); | |
545f0503 CS |
9761 | if (ifp->desc) |
9762 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 9763 | |
545f0503 | 9764 | write++; |
43b8d1d8 | 9765 | |
545f0503 | 9766 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 9767 | |
545f0503 CS |
9768 | do { |
9769 | /* Interface Network print. */ | |
9770 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
9771 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 9772 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
9773 | vty_out(vty, " ip ospf network %s", |
9774 | ospf_int_type_str | |
996c9314 | 9775 | [params->type]); |
e425c019 | 9776 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
9777 | vty_out(vty, " %s", |
9778 | inet_ntoa( | |
996c9314 | 9779 | rn->p.u.prefix4)); |
545f0503 | 9780 | vty_out(vty, "\n"); |
d62a17ae | 9781 | } |
545f0503 | 9782 | } |
d62a17ae | 9783 | |
545f0503 CS |
9784 | /* OSPF interface authentication print */ |
9785 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
996c9314 | 9786 | && params->auth_type != OSPF_AUTH_NOTSET) { |
545f0503 | 9787 | const char *auth_str; |
d62a17ae | 9788 | |
545f0503 CS |
9789 | /* Translation tables are not that much help |
9790 | * here due to syntax | |
9791 | * of the simple option */ | |
9792 | switch (params->auth_type) { | |
d62a17ae | 9793 | |
545f0503 CS |
9794 | case OSPF_AUTH_NULL: |
9795 | auth_str = " null"; | |
9796 | break; | |
d62a17ae | 9797 | |
545f0503 CS |
9798 | case OSPF_AUTH_SIMPLE: |
9799 | auth_str = ""; | |
9800 | break; | |
b5a8894d | 9801 | |
545f0503 CS |
9802 | case OSPF_AUTH_CRYPTOGRAPHIC: |
9803 | auth_str = " message-digest"; | |
9804 | break; | |
d62a17ae | 9805 | |
545f0503 CS |
9806 | default: |
9807 | auth_str = ""; | |
9808 | break; | |
c7fd72d2 | 9809 | } |
d62a17ae | 9810 | |
545f0503 CS |
9811 | vty_out(vty, " ip ospf authentication%s", |
9812 | auth_str); | |
e425c019 | 9813 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9814 | vty_out(vty, " %s", |
c7fd72d2 | 9815 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9816 | vty_out(vty, "\n"); |
9817 | } | |
d62a17ae | 9818 | |
545f0503 CS |
9819 | /* Simple Authentication Password print. */ |
9820 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 9821 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
9822 | vty_out(vty, " ip ospf authentication-key %s", |
9823 | params->auth_simple); | |
e425c019 | 9824 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
9825 | vty_out(vty, " %s", |
9826 | inet_ntoa(rn->p.u.prefix4)); | |
9827 | vty_out(vty, "\n"); | |
9828 | } | |
c7fd72d2 | 9829 | |
545f0503 CS |
9830 | /* Cryptographic Authentication Key print. */ |
9831 | if (params && params->auth_crypt) { | |
996c9314 LB |
9832 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
9833 | node, ck)) { | |
545f0503 CS |
9834 | vty_out(vty, |
9835 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 9836 | ck->key_id, ck->auth_key); |
e425c019 | 9837 | if (params != IF_DEF_PARAMS(ifp) && rn) |
c7fd72d2 | 9838 | vty_out(vty, " %s", |
996c9314 LB |
9839 | inet_ntoa( |
9840 | rn->p.u.prefix4)); | |
c7fd72d2 CS |
9841 | vty_out(vty, "\n"); |
9842 | } | |
545f0503 | 9843 | } |
d62a17ae | 9844 | |
545f0503 | 9845 | /* Interface Output Cost print. */ |
996c9314 | 9846 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
9847 | vty_out(vty, " ip ospf cost %u", |
9848 | params->output_cost_cmd); | |
e425c019 | 9849 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9850 | vty_out(vty, " %s", |
43b8d1d8 | 9851 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9852 | vty_out(vty, "\n"); |
9853 | } | |
d62a17ae | 9854 | |
545f0503 CS |
9855 | /* Hello Interval print. */ |
9856 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 9857 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
9858 | vty_out(vty, " ip ospf hello-interval %u", |
9859 | params->v_hello); | |
e425c019 | 9860 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
9861 | vty_out(vty, " %s", |
9862 | inet_ntoa(rn->p.u.prefix4)); | |
9863 | vty_out(vty, "\n"); | |
9864 | } | |
d62a17ae | 9865 | |
d62a17ae | 9866 | |
545f0503 CS |
9867 | /* Router Dead Interval print. */ |
9868 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
996c9314 LB |
9869 | && params->v_wait |
9870 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
545f0503 | 9871 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 9872 | |
545f0503 CS |
9873 | /* fast hello ? */ |
9874 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 9875 | fast_hello)) |
545f0503 CS |
9876 | vty_out(vty, |
9877 | "minimal hello-multiplier %d", | |
9878 | params->fast_hello); | |
9879 | else | |
996c9314 | 9880 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 9881 | |
e425c019 | 9882 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9883 | vty_out(vty, " %s", |
43b8d1d8 | 9884 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9885 | vty_out(vty, "\n"); |
9886 | } | |
d62a17ae | 9887 | |
545f0503 CS |
9888 | /* Router Priority print. */ |
9889 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
9890 | && params->priority |
9891 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
9892 | vty_out(vty, " ip ospf priority %u", |
9893 | params->priority); | |
e425c019 | 9894 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9895 | vty_out(vty, " %s", |
43b8d1d8 | 9896 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9897 | vty_out(vty, "\n"); |
9898 | } | |
d62a17ae | 9899 | |
545f0503 CS |
9900 | /* Retransmit Interval print. */ |
9901 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
9902 | retransmit_interval) |
9903 | && params->retransmit_interval | |
9904 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
9905 | vty_out(vty, " ip ospf retransmit-interval %u", |
9906 | params->retransmit_interval); | |
e425c019 | 9907 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9908 | vty_out(vty, " %s", |
43b8d1d8 | 9909 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9910 | vty_out(vty, "\n"); |
9911 | } | |
d62a17ae | 9912 | |
545f0503 | 9913 | /* Transmit Delay print. */ |
996c9314 LB |
9914 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
9915 | && params->transmit_delay | |
9916 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
9917 | vty_out(vty, " ip ospf transmit-delay %u", |
9918 | params->transmit_delay); | |
e425c019 | 9919 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9920 | vty_out(vty, " %s", |
996c9314 | 9921 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9922 | vty_out(vty, "\n"); |
9923 | } | |
d62a17ae | 9924 | |
545f0503 CS |
9925 | /* Area print. */ |
9926 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
9927 | if (ospf && ospf->instance) | |
9928 | vty_out(vty, " ip ospf %d", | |
9929 | ospf->instance); | |
9930 | else | |
9931 | vty_out(vty, " ip ospf"); | |
d62a17ae | 9932 | |
1f9d4e3d | 9933 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 9934 | |
996c9314 LB |
9935 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
9936 | params->if_area_id_fmt); | |
545f0503 | 9937 | vty_out(vty, " area %s", buf); |
e425c019 | 9938 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9939 | vty_out(vty, " %s", |
996c9314 | 9940 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9941 | vty_out(vty, "\n"); |
9942 | } | |
d62a17ae | 9943 | |
545f0503 | 9944 | /* bfd print. */ |
e89ffeee | 9945 | if (params && params->bfd_info) |
545f0503 | 9946 | ospf_bfd_write_config(vty, params); |
d62a17ae | 9947 | |
545f0503 CS |
9948 | /* MTU ignore print. */ |
9949 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 9950 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
9951 | if (params->mtu_ignore == 0) |
9952 | vty_out(vty, " no ip ospf mtu-ignore"); | |
9953 | else | |
9954 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 9955 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9956 | vty_out(vty, " %s", |
996c9314 | 9957 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9958 | vty_out(vty, "\n"); |
9959 | } | |
a8b828f3 | 9960 | |
d62a17ae | 9961 | |
545f0503 CS |
9962 | while (1) { |
9963 | if (rn == NULL) | |
996c9314 | 9964 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
9965 | else |
9966 | rn = route_next(rn); | |
43b8d1d8 | 9967 | |
545f0503 CS |
9968 | if (rn == NULL) |
9969 | break; | |
9970 | params = rn->info; | |
9971 | if (params != NULL) | |
9972 | break; | |
9973 | } | |
9974 | } while (rn); | |
43b8d1d8 | 9975 | |
545f0503 CS |
9976 | ospf_opaque_config_write_if(vty, ifp); |
9977 | ||
9978 | vty_endframe(vty, NULL); | |
b5a8894d | 9979 | } |
545f0503 | 9980 | |
d62a17ae | 9981 | return write; |
718e3744 | 9982 | } |
9983 | ||
43b8d1d8 CS |
9984 | /* Configuration write function for ospfd. */ |
9985 | static int config_write_interface(struct vty *vty) | |
9986 | { | |
9987 | int write = 0; | |
545f0503 | 9988 | struct vrf *vrf = NULL; |
43b8d1d8 | 9989 | |
545f0503 CS |
9990 | /* Display all VRF aware OSPF interface configuration */ |
9991 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
9992 | write += config_write_interface_one(vty, vrf); | |
9993 | } | |
43b8d1d8 CS |
9994 | |
9995 | return write; | |
9996 | } | |
9997 | ||
d62a17ae | 9998 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 9999 | { |
d62a17ae | 10000 | struct route_node *rn; |
d7c0a89a | 10001 | uint8_t buf[INET_ADDRSTRLEN]; |
718e3744 | 10002 | |
d62a17ae | 10003 | /* `network area' print. */ |
10004 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
10005 | if (rn->info) { | |
10006 | struct ospf_network *n = rn->info; | |
718e3744 | 10007 | |
d62a17ae | 10008 | /* Create Area ID string by specified Area ID format. */ |
10009 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
1f9d4e3d | 10010 | inet_ntop(AF_INET, &n->area_id, (char *)buf, |
10011 | sizeof(buf)); | |
d62a17ae | 10012 | else |
10013 | sprintf((char *)buf, "%lu", | |
10014 | (unsigned long int)ntohl( | |
10015 | n->area_id.s_addr)); | |
718e3744 | 10016 | |
d62a17ae | 10017 | /* Network print. */ |
10018 | vty_out(vty, " network %s/%d area %s\n", | |
10019 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen, | |
10020 | buf); | |
10021 | } | |
718e3744 | 10022 | |
d62a17ae | 10023 | return 0; |
718e3744 | 10024 | } |
10025 | ||
d62a17ae | 10026 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 10027 | { |
d62a17ae | 10028 | struct listnode *node; |
10029 | struct ospf_area *area; | |
d7c0a89a | 10030 | uint8_t buf[INET_ADDRSTRLEN]; |
718e3744 | 10031 | |
d62a17ae | 10032 | /* Area configuration print. */ |
10033 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
10034 | struct route_node *rn1; | |
718e3744 | 10035 | |
1f9d4e3d | 10036 | area_id2str((char *)buf, sizeof(buf), &area->area_id, |
d62a17ae | 10037 | area->area_id_fmt); |
718e3744 | 10038 | |
d62a17ae | 10039 | if (area->auth_type != OSPF_AUTH_NULL) { |
10040 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
10041 | vty_out(vty, " area %s authentication\n", buf); | |
10042 | else | |
10043 | vty_out(vty, | |
10044 | " area %s authentication message-digest\n", | |
10045 | buf); | |
10046 | } | |
718e3744 | 10047 | |
d62a17ae | 10048 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
10049 | vty_out(vty, " area %s shortcut %s\n", buf, | |
10050 | ospf_shortcut_mode_str | |
10051 | [area->shortcut_configured]); | |
10052 | ||
10053 | if ((area->external_routing == OSPF_AREA_STUB) | |
10054 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 10055 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 10056 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
10057 | if (area->no_summary) |
10058 | vty_out(vty, " no-summary\n"); | |
10059 | vty_out(vty, "\n"); | |
10060 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 10061 | switch (area->NSSATranslatorRole) { |
10062 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
10063 | vty_out(vty, |
10064 | " area %s nssa translate-never\n", | |
10065 | buf); | |
d62a17ae | 10066 | break; |
10067 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
10068 | vty_out(vty, |
10069 | " area %s nssa translate-always\n", | |
10070 | buf); | |
d62a17ae | 10071 | break; |
2643b2bc CS |
10072 | case OSPF_NSSA_ROLE_CANDIDATE: |
10073 | vty_out(vty, " area %s nssa \n", buf); | |
10074 | break; | |
d62a17ae | 10075 | } |
7ef56a73 CS |
10076 | if (area->no_summary) |
10077 | vty_out(vty, | |
10078 | " area %s nssa no-summary\n", | |
10079 | buf); | |
d62a17ae | 10080 | } |
718e3744 | 10081 | |
d62a17ae | 10082 | if (area->default_cost != 1) |
10083 | vty_out(vty, " area %s default-cost %d\n", buf, | |
10084 | area->default_cost); | |
10085 | } | |
718e3744 | 10086 | |
d62a17ae | 10087 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
10088 | if (rn1->info) { | |
10089 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 10090 | |
d62a17ae | 10091 | vty_out(vty, " area %s range %s/%d", buf, |
10092 | inet_ntoa(rn1->p.u.prefix4), | |
10093 | rn1->p.prefixlen); | |
718e3744 | 10094 | |
d62a17ae | 10095 | if (range->cost_config |
10096 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
10097 | vty_out(vty, " cost %d", | |
10098 | range->cost_config); | |
718e3744 | 10099 | |
d62a17ae | 10100 | if (!CHECK_FLAG(range->flags, |
10101 | OSPF_AREA_RANGE_ADVERTISE)) | |
10102 | vty_out(vty, " not-advertise"); | |
718e3744 | 10103 | |
d62a17ae | 10104 | if (CHECK_FLAG(range->flags, |
10105 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
10106 | vty_out(vty, " substitute %s/%d", | |
10107 | inet_ntoa(range->subst_addr), | |
10108 | range->subst_masklen); | |
10109 | ||
10110 | vty_out(vty, "\n"); | |
10111 | } | |
10112 | ||
10113 | if (EXPORT_NAME(area)) | |
10114 | vty_out(vty, " area %s export-list %s\n", buf, | |
10115 | EXPORT_NAME(area)); | |
10116 | ||
10117 | if (IMPORT_NAME(area)) | |
10118 | vty_out(vty, " area %s import-list %s\n", buf, | |
10119 | IMPORT_NAME(area)); | |
10120 | ||
10121 | if (PREFIX_NAME_IN(area)) | |
10122 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
10123 | PREFIX_NAME_IN(area)); | |
10124 | ||
10125 | if (PREFIX_NAME_OUT(area)) | |
10126 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
10127 | buf, PREFIX_NAME_OUT(area)); | |
10128 | } | |
10129 | ||
10130 | return 0; | |
718e3744 | 10131 | } |
10132 | ||
d62a17ae | 10133 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 10134 | { |
d62a17ae | 10135 | struct ospf_nbr_nbma *nbr_nbma; |
10136 | struct route_node *rn; | |
718e3744 | 10137 | |
d62a17ae | 10138 | /* Static Neighbor configuration print. */ |
10139 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
10140 | if ((nbr_nbma = rn->info)) { | |
10141 | vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr)); | |
718e3744 | 10142 | |
d62a17ae | 10143 | if (nbr_nbma->priority |
10144 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
10145 | vty_out(vty, " priority %d", | |
10146 | nbr_nbma->priority); | |
718e3744 | 10147 | |
d62a17ae | 10148 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
10149 | vty_out(vty, " poll-interval %d", | |
10150 | nbr_nbma->v_poll); | |
10151 | ||
10152 | vty_out(vty, "\n"); | |
10153 | } | |
10154 | ||
10155 | return 0; | |
10156 | } | |
10157 | ||
10158 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
10159 | { | |
10160 | struct listnode *node; | |
10161 | struct ospf_vl_data *vl_data; | |
10162 | char buf[INET_ADDRSTRLEN]; | |
10163 | ||
10164 | /* Virtual-Link print */ | |
10165 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
10166 | struct listnode *n2; | |
10167 | struct crypt_key *ck; | |
10168 | struct ospf_interface *oi; | |
10169 | ||
10170 | if (vl_data != NULL) { | |
d62a17ae | 10171 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
10172 | vl_data->vl_area_id_fmt); | |
10173 | oi = vl_data->vl_oi; | |
10174 | ||
10175 | /* timers */ | |
10176 | if (OSPF_IF_PARAM(oi, v_hello) | |
10177 | != OSPF_HELLO_INTERVAL_DEFAULT | |
10178 | || OSPF_IF_PARAM(oi, v_wait) | |
10179 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
10180 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
10181 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
10182 | || OSPF_IF_PARAM(oi, transmit_delay) | |
10183 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
10184 | vty_out(vty, | |
10185 | " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", | |
10186 | buf, inet_ntoa(vl_data->vl_peer), | |
10187 | OSPF_IF_PARAM(oi, v_hello), | |
10188 | OSPF_IF_PARAM(oi, retransmit_interval), | |
10189 | OSPF_IF_PARAM(oi, transmit_delay), | |
10190 | OSPF_IF_PARAM(oi, v_wait)); | |
10191 | else | |
10192 | vty_out(vty, " area %s virtual-link %s\n", buf, | |
10193 | inet_ntoa(vl_data->vl_peer)); | |
10194 | /* Auth key */ | |
10195 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
10196 | != '\0') | |
10197 | vty_out(vty, | |
10198 | " area %s virtual-link %s authentication-key %s\n", | |
10199 | buf, inet_ntoa(vl_data->vl_peer), | |
10200 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
10201 | ->auth_simple); | |
10202 | /* md5 keys */ | |
10203 | for (ALL_LIST_ELEMENTS_RO( | |
10204 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
10205 | ->auth_crypt, | |
10206 | n2, ck)) | |
10207 | vty_out(vty, | |
10208 | " area %s virtual-link %s" | |
10209 | " message-digest-key %d md5 %s\n", | |
10210 | buf, inet_ntoa(vl_data->vl_peer), | |
10211 | ck->key_id, ck->auth_key); | |
10212 | } | |
10213 | } | |
10214 | ||
10215 | return 0; | |
718e3744 | 10216 | } |
10217 | ||
6b0655a2 | 10218 | |
d62a17ae | 10219 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 10220 | { |
d62a17ae | 10221 | int type; |
718e3744 | 10222 | |
d62a17ae | 10223 | /* redistribute print. */ |
10224 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
10225 | struct list *red_list; | |
10226 | struct listnode *node; | |
10227 | struct ospf_redist *red; | |
718e3744 | 10228 | |
d62a17ae | 10229 | red_list = ospf->redist[type]; |
10230 | if (!red_list) | |
10231 | continue; | |
7c8ff89e | 10232 | |
d62a17ae | 10233 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
10234 | vty_out(vty, " redistribute %s", | |
10235 | zebra_route_string(type)); | |
10236 | if (red->instance) | |
10237 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 10238 | |
d62a17ae | 10239 | if (red->dmetric.value >= 0) |
10240 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 10241 | |
d62a17ae | 10242 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
10243 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 10244 | |
d62a17ae | 10245 | if (ROUTEMAP_NAME(red)) |
10246 | vty_out(vty, " route-map %s", | |
10247 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 10248 | |
d62a17ae | 10249 | vty_out(vty, "\n"); |
10250 | } | |
10251 | } | |
718e3744 | 10252 | |
d62a17ae | 10253 | return 0; |
718e3744 | 10254 | } |
10255 | ||
d62a17ae | 10256 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 10257 | { |
d62a17ae | 10258 | if (ospf->default_metric != -1) |
10259 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
10260 | return 0; | |
718e3744 | 10261 | } |
10262 | ||
d62a17ae | 10263 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
10264 | { | |
10265 | int type; | |
10266 | struct ospf_redist *red; | |
718e3744 | 10267 | |
d62a17ae | 10268 | if (ospf) { |
10269 | /* distribute-list print. */ | |
10270 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
10271 | if (DISTRIBUTE_NAME(ospf, type)) | |
10272 | vty_out(vty, " distribute-list %s out %s\n", | |
10273 | DISTRIBUTE_NAME(ospf, type), | |
10274 | zebra_route_string(type)); | |
7c8ff89e | 10275 | |
d62a17ae | 10276 | /* default-information print. */ |
10277 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
10278 | vty_out(vty, " default-information originate"); | |
10279 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
10280 | vty_out(vty, " always"); | |
718e3744 | 10281 | |
d62a17ae | 10282 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
10283 | if (red) { | |
10284 | if (red->dmetric.value >= 0) | |
10285 | vty_out(vty, " metric %d", | |
10286 | red->dmetric.value); | |
951da435 | 10287 | |
d62a17ae | 10288 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
10289 | vty_out(vty, " metric-type 1"); | |
718e3744 | 10290 | |
d62a17ae | 10291 | if (ROUTEMAP_NAME(red)) |
10292 | vty_out(vty, " route-map %s", | |
10293 | ROUTEMAP_NAME(red)); | |
10294 | } | |
10295 | ||
10296 | vty_out(vty, "\n"); | |
10297 | } | |
10298 | } | |
10299 | ||
10300 | return 0; | |
718e3744 | 10301 | } |
10302 | ||
d62a17ae | 10303 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
10304 | { | |
10305 | struct route_node *rn; | |
10306 | struct ospf_distance *odistance; | |
10307 | ||
10308 | if (ospf->distance_all) | |
10309 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
10310 | ||
10311 | if (ospf->distance_intra || ospf->distance_inter | |
10312 | || ospf->distance_external) { | |
10313 | vty_out(vty, " distance ospf"); | |
10314 | ||
10315 | if (ospf->distance_intra) | |
10316 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
10317 | if (ospf->distance_inter) | |
10318 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
10319 | if (ospf->distance_external) | |
10320 | vty_out(vty, " external %d", ospf->distance_external); | |
10321 | ||
10322 | vty_out(vty, "\n"); | |
10323 | } | |
10324 | ||
10325 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
10326 | if ((odistance = rn->info) != NULL) { | |
10327 | vty_out(vty, " distance %d %s/%d %s\n", | |
10328 | odistance->distance, inet_ntoa(rn->p.u.prefix4), | |
10329 | rn->p.prefixlen, | |
10330 | odistance->access_list ? odistance->access_list | |
10331 | : ""); | |
10332 | } | |
10333 | return 0; | |
718e3744 | 10334 | } |
10335 | ||
43b8d1d8 | 10336 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 10337 | { |
f4e14fdb | 10338 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 10339 | struct interface *ifp; |
10340 | struct ospf_interface *oi; | |
43b8d1d8 | 10341 | struct listnode *node = NULL; |
d62a17ae | 10342 | int write = 0; |
10343 | ||
43b8d1d8 CS |
10344 | /* `router ospf' print. */ |
10345 | if (ospf->instance && ospf->name) { | |
996c9314 LB |
10346 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
10347 | ospf->name); | |
43b8d1d8 | 10348 | } else if (ospf->instance) { |
996c9314 | 10349 | vty_out(vty, "router ospf %d\n", ospf->instance); |
43b8d1d8 | 10350 | } else if (ospf->name) { |
996c9314 | 10351 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
10352 | } else |
10353 | vty_out(vty, "router ospf\n"); | |
10354 | ||
10355 | if (!ospf->networks) { | |
10356 | write++; | |
b5a8894d | 10357 | return write; |
43b8d1d8 | 10358 | } |
d62a17ae | 10359 | |
43b8d1d8 CS |
10360 | /* Router ID print. */ |
10361 | if (ospf->router_id_static.s_addr != 0) | |
10362 | vty_out(vty, " ospf router-id %s\n", | |
10363 | inet_ntoa(ospf->router_id_static)); | |
d62a17ae | 10364 | |
43b8d1d8 CS |
10365 | /* ABR type print. */ |
10366 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
10367 | vty_out(vty, " ospf abr-type %s\n", | |
10368 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 10369 | |
43b8d1d8 CS |
10370 | /* log-adjacency-changes flag print. */ |
10371 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
10372 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
10373 | vty_out(vty, " log-adjacency-changes detail\n"); | |
c572fbfe | 10374 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
43b8d1d8 | 10375 | vty_out(vty, " log-adjacency-changes\n"); |
c572fbfe | 10376 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
43b8d1d8 CS |
10377 | vty_out(vty, " no log-adjacency-changes\n"); |
10378 | } | |
b5a8894d | 10379 | |
43b8d1d8 CS |
10380 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
10381 | * 12.1. */ | |
10382 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
10383 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 10384 | |
43b8d1d8 CS |
10385 | /* auto-cost reference-bandwidth configuration. */ |
10386 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
10387 | vty_out(vty, | |
10388 | "! Important: ensure reference bandwidth " | |
10389 | "is consistent across all routers\n"); | |
10390 | vty_out(vty, " auto-cost reference-bandwidth %d\n", | |
10391 | ospf->ref_bandwidth); | |
10392 | } | |
d62a17ae | 10393 | |
43b8d1d8 CS |
10394 | /* SPF timers print. */ |
10395 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
10396 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
10397 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
10398 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
10399 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
10400 | |
10401 | /* LSA timers print. */ | |
10402 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
10403 | vty_out(vty, " timers throttle lsa all %d\n", | |
10404 | ospf->min_ls_interval); | |
10405 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
10406 | vty_out(vty, " timers lsa min-arrival %d\n", | |
10407 | ospf->min_ls_arrival); | |
10408 | ||
10409 | /* Write multiplier print. */ | |
10410 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
10411 | vty_out(vty, " ospf write-multiplier %d\n", | |
10412 | ospf->write_oi_count); | |
d62a17ae | 10413 | |
43b8d1d8 CS |
10414 | /* Max-metric router-lsa print */ |
10415 | config_write_stub_router(vty, ospf); | |
d62a17ae | 10416 | |
43b8d1d8 | 10417 | /* SPF refresh parameters print. */ |
996c9314 LB |
10418 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
10419 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 10420 | |
43b8d1d8 CS |
10421 | /* Redistribute information print. */ |
10422 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 10423 | |
43b8d1d8 CS |
10424 | /* passive-interface print. */ |
10425 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
10426 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 10427 | |
451fda4f | 10428 | FOR_ALL_INTERFACES (vrf, ifp) |
43b8d1d8 CS |
10429 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
10430 | passive_interface) | |
10431 | && IF_DEF_PARAMS(ifp)->passive_interface | |
996c9314 | 10432 | != ospf->passive_interface_default) { |
43b8d1d8 | 10433 | vty_out(vty, " %spassive-interface %s\n", |
996c9314 LB |
10434 | IF_DEF_PARAMS(ifp)->passive_interface ? "" |
10435 | : "no ", | |
43b8d1d8 CS |
10436 | ifp->name); |
10437 | } | |
10438 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
996c9314 | 10439 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) |
43b8d1d8 CS |
10440 | continue; |
10441 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
10442 | passive_interface)) { | |
10443 | if (oi->params->passive_interface | |
996c9314 | 10444 | == IF_DEF_PARAMS(oi->ifp)->passive_interface) |
43b8d1d8 CS |
10445 | continue; |
10446 | } else if (oi->params->passive_interface | |
10447 | == ospf->passive_interface_default) | |
10448 | continue; | |
d62a17ae | 10449 | |
43b8d1d8 CS |
10450 | vty_out(vty, " %spassive-interface %s %s\n", |
10451 | oi->params->passive_interface ? "" : "no ", | |
996c9314 | 10452 | oi->ifp->name, inet_ntoa(oi->address->u.prefix4)); |
43b8d1d8 | 10453 | } |
d62a17ae | 10454 | |
43b8d1d8 CS |
10455 | /* Network area print. */ |
10456 | config_write_network_area(vty, ospf); | |
d62a17ae | 10457 | |
43b8d1d8 CS |
10458 | /* Area config print. */ |
10459 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 10460 | |
43b8d1d8 CS |
10461 | /* static neighbor print. */ |
10462 | config_write_ospf_nbr_nbma(vty, ospf); | |
10463 | ||
10464 | /* Virtual-Link print. */ | |
10465 | config_write_virtual_link(vty, ospf); | |
10466 | ||
10467 | /* Default metric configuration. */ | |
10468 | config_write_ospf_default_metric(vty, ospf); | |
10469 | ||
10470 | /* Distribute-list and default-information print. */ | |
10471 | config_write_ospf_distribute(vty, ospf); | |
10472 | ||
10473 | /* Distance configuration. */ | |
10474 | config_write_ospf_distance(vty, ospf); | |
10475 | ||
10476 | ospf_opaque_config_write_router(vty, ospf); | |
10477 | ||
10478 | write++; | |
10479 | return write; | |
10480 | } | |
10481 | ||
10482 | /* OSPF configuration write function. */ | |
10483 | static int ospf_config_write(struct vty *vty) | |
10484 | { | |
10485 | struct ospf *ospf; | |
10486 | struct listnode *ospf_node = NULL; | |
10487 | int write = 0; | |
10488 | ||
10489 | if (listcount(om->ospf) == 0) | |
10490 | return write; | |
10491 | ||
10492 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
10493 | /* VRF Default check if it is running. |
10494 | * Upon daemon start, there could be default instance | |
10495 | * in absence of 'router ospf'/oi_running is disabled. */ | |
10496 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
10497 | write += ospf_config_write_one(vty, ospf); | |
10498 | /* For Non-Default VRF simply display the configuration, | |
10499 | * even if it is not oi_running. */ | |
10500 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 10501 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 10502 | } |
d62a17ae | 10503 | return write; |
10504 | } | |
10505 | ||
10506 | void ospf_vty_show_init(void) | |
10507 | { | |
10508 | /* "show ip ospf" commands. */ | |
10509 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
10510 | ||
10511 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
10512 | ||
10513 | /* "show ip ospf database" commands. */ | |
10514 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
10515 | ||
10516 | install_element(VIEW_NODE, | |
10517 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
10518 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
10519 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
10520 | ||
10521 | /* "show ip ospf interface" commands. */ | |
10522 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
10523 | ||
10524 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
10525 | /* "show ip ospf interface traffic */ |
10526 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 10527 | |
10528 | /* "show ip ospf neighbor" commands. */ | |
10529 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
10530 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
10531 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
10532 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
10533 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
10534 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
10535 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
10536 | ||
10537 | install_element(VIEW_NODE, | |
10538 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
10539 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
10540 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
10541 | install_element(VIEW_NODE, | |
10542 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
10543 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
10544 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
10545 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
10546 | ||
10547 | /* "show ip ospf route" commands. */ | |
10548 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
10549 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
10550 | ||
10551 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
10552 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
10553 | |
10554 | /* "show ip ospf vrfs" commands. */ | |
10555 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
718e3744 | 10556 | } |
10557 | ||
6b0655a2 | 10558 | |
718e3744 | 10559 | /* ospfd's interface node. */ |
d62a17ae | 10560 | static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1}; |
718e3744 | 10561 | |
10562 | /* Initialization of OSPF interface. */ | |
d62a17ae | 10563 | static void ospf_vty_if_init(void) |
10564 | { | |
10565 | /* Install interface node. */ | |
10566 | install_node(&interface_node, config_write_interface); | |
10567 | if_cmd_init(); | |
10568 | ||
10569 | /* "ip ospf authentication" commands. */ | |
10570 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
10571 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
10572 | install_element(INTERFACE_NODE, | |
10573 | &no_ip_ospf_authentication_args_addr_cmd); | |
10574 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
10575 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
10576 | install_element(INTERFACE_NODE, | |
10577 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
10578 | install_element(INTERFACE_NODE, | |
10579 | &no_ospf_authentication_key_authkey_addr_cmd); | |
10580 | ||
10581 | /* "ip ospf message-digest-key" commands. */ | |
10582 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
10583 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
10584 | ||
10585 | /* "ip ospf cost" commands. */ | |
10586 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
10587 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
10588 | ||
10589 | /* "ip ospf mtu-ignore" commands. */ | |
10590 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
10591 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
10592 | ||
10593 | /* "ip ospf dead-interval" commands. */ | |
10594 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
10595 | install_element(INTERFACE_NODE, | |
10596 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
10597 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
10598 | ||
10599 | /* "ip ospf hello-interval" commands. */ | |
10600 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
10601 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
10602 | ||
10603 | /* "ip ospf network" commands. */ | |
10604 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
10605 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
10606 | ||
10607 | /* "ip ospf priority" commands. */ | |
10608 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
10609 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
10610 | ||
10611 | /* "ip ospf retransmit-interval" commands. */ | |
10612 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
10613 | install_element(INTERFACE_NODE, | |
10614 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
10615 | ||
10616 | /* "ip ospf transmit-delay" commands. */ | |
10617 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
10618 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
10619 | ||
10620 | /* "ip ospf area" commands. */ | |
10621 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
10622 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
10623 | ||
10624 | /* These commands are compatibitliy for previous version. */ | |
10625 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
10626 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
10627 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
10628 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
10629 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
10630 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
10631 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
10632 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
10633 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
10634 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
10635 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
10636 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
10637 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
10638 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
10639 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
10640 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
10641 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
10642 | } | |
10643 | ||
10644 | static void ospf_vty_zebra_init(void) | |
10645 | { | |
10646 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
10647 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
10648 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
10649 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
10650 | ||
10651 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
10652 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
10653 | ||
10654 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
10655 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
10656 | ||
10657 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
10658 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
10659 | ||
10660 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
10661 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
10662 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
10663 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
718e3744 | 10664 | #if 0 |
10665 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
10666 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
10667 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
10668 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
10669 | #endif /* 0 */ | |
10670 | } | |
10671 | ||
d62a17ae | 10672 | static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1}; |
718e3744 | 10673 | |
d62a17ae | 10674 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 10675 | { |
d62a17ae | 10676 | if (!if_is_operative(ifp)) |
10677 | return; | |
09f35f8c | 10678 | |
d62a17ae | 10679 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
10680 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 10681 | |
d62a17ae | 10682 | ospf_if_reset(ifp); |
09f35f8c DS |
10683 | } |
10684 | ||
10685 | DEFUN (clear_ip_ospf_interface, | |
10686 | clear_ip_ospf_interface_cmd, | |
1e81afc3 | 10687 | "clear ip ospf [vrf NAME] interface [IFNAME]", |
09f35f8c DS |
10688 | CLEAR_STR |
10689 | IP_STR | |
10690 | "OSPF information\n" | |
03ed9f02 | 10691 | VRF_CMD_HELP_STR |
09f35f8c DS |
10692 | "Interface information\n" |
10693 | "Interface name\n") | |
10694 | { | |
03ed9f02 PG |
10695 | int idx_ifname = 0; |
10696 | int idx_vrf = 0; | |
d62a17ae | 10697 | struct interface *ifp; |
f4e14fdb | 10698 | struct listnode *node; |
b5a8894d | 10699 | struct ospf *ospf = NULL; |
03ed9f02 PG |
10700 | char *vrf_name = NULL; |
10701 | vrf_id_t vrf_id = VRF_DEFAULT; | |
10702 | struct vrf *vrf = NULL; | |
09f35f8c | 10703 | |
03ed9f02 PG |
10704 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
10705 | vrf_name = argv[idx_vrf + 1]->arg; | |
10706 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
10707 | vrf_name = NULL; | |
10708 | if (vrf_name) { | |
10709 | vrf = vrf_lookup_by_name(vrf_name); | |
10710 | if (vrf) | |
10711 | vrf_id = vrf->vrf_id; | |
10712 | } | |
10713 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
10714 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 10715 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
10716 | if (vrf_id != ospf->vrf_id) |
10717 | continue; | |
10718 | if (!vrf) | |
10719 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 10720 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
10721 | ospf_interface_clear(ifp); |
10722 | } | |
10723 | } else { | |
10724 | /* Interface name is specified. */ | |
a36898e7 | 10725 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 10726 | if (ifp == NULL) |
d62a17ae | 10727 | vty_out(vty, "No such interface name\n"); |
10728 | else | |
10729 | ospf_interface_clear(ifp); | |
10730 | } | |
10731 | ||
10732 | return CMD_SUCCESS; | |
09f35f8c DS |
10733 | } |
10734 | ||
d62a17ae | 10735 | void ospf_vty_clear_init(void) |
09f35f8c | 10736 | { |
d62a17ae | 10737 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
09f35f8c DS |
10738 | } |
10739 | ||
6b0655a2 | 10740 | |
718e3744 | 10741 | /* Install OSPF related vty commands. */ |
d62a17ae | 10742 | void ospf_vty_init(void) |
10743 | { | |
10744 | /* Install ospf top node. */ | |
10745 | install_node(&ospf_node, ospf_config_write); | |
10746 | ||
10747 | /* "router ospf" commands. */ | |
10748 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
10749 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
10750 | ||
10751 | ||
10752 | install_default(OSPF_NODE); | |
10753 | ||
10754 | /* "ospf router-id" commands. */ | |
10755 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
10756 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
10757 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
10758 | ||
10759 | /* "passive-interface" commands. */ | |
10760 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
10761 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
10762 | ||
10763 | /* "ospf abr-type" commands. */ | |
10764 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
10765 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
10766 | ||
10767 | /* "ospf log-adjacency-changes" commands. */ | |
10768 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
10769 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
10770 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
10771 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
10772 | ||
10773 | /* "ospf rfc1583-compatible" commands. */ | |
10774 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
10775 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
10776 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
10777 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
10778 | ||
10779 | /* "network area" commands. */ | |
10780 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
10781 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
10782 | ||
10783 | /* "area authentication" commands. */ | |
10784 | install_element(OSPF_NODE, | |
10785 | &ospf_area_authentication_message_digest_cmd); | |
10786 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
10787 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
10788 | ||
10789 | /* "area range" commands. */ | |
10790 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
10791 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
10792 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
10793 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
10794 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
10795 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
10796 | ||
10797 | /* "area virtual-link" commands. */ | |
10798 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
10799 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
10800 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
10801 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
10802 | ||
10803 | ||
10804 | /* "area stub" commands. */ | |
10805 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
10806 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
10807 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
10808 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
10809 | ||
10810 | /* "area nssa" commands. */ | |
10811 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 10812 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
10813 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 10814 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
d62a17ae | 10815 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
10816 | ||
10817 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
10818 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
10819 | ||
10820 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
10821 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
10822 | ||
10823 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
10824 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
10825 | ||
10826 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
10827 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
10828 | ||
10829 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
10830 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
10831 | ||
10832 | /* SPF timer commands */ | |
10833 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
10834 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
10835 | ||
10836 | /* LSA timers commands */ | |
10837 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
10838 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
10839 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
10840 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 10841 | |
10842 | /* refresh timer commands */ | |
10843 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
10844 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
10845 | ||
10846 | /* max-metric commands */ | |
10847 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
10848 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
10849 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
10850 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
10851 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
10852 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
10853 | ||
10854 | /* reference bandwidth commands */ | |
10855 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
10856 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
10857 | ||
10858 | /* "neighbor" commands. */ | |
10859 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
10860 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
10861 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
10862 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
10863 | ||
10864 | /* write multiplier commands */ | |
10865 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
10866 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
10867 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
10868 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
10869 | ||
10870 | /* Init interface related vty commands. */ | |
10871 | ospf_vty_if_init(); | |
10872 | ||
10873 | /* Init zebra related vty commands. */ | |
10874 | ospf_vty_zebra_init(); | |
718e3744 | 10875 | } |