]>
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" |
132a782e | 55 | #include "ospfd/ospf_ldp_sync.h" |
718e3744 | 56 | |
c572fbfe | 57 | FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES, |
4c1458b5 DL |
58 | { .val_bool = true, .match_profile = "datacenter", }, |
59 | { .val_bool = false }, | |
c572fbfe DL |
60 | ) |
61 | ||
2b64873d | 62 | static const char *const ospf_network_type_str[] = { |
d62a17ae | 63 | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", |
64 | "VIRTUALLINK", "LOOPBACK"}; | |
718e3744 | 65 | |
718e3744 | 66 | /* Utility functions. */ |
d62a17ae | 67 | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) |
718e3744 | 68 | { |
d62a17ae | 69 | char *ep; |
718e3744 | 70 | |
d62a17ae | 71 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); |
72 | if (*ep && !inet_aton(str, area_id)) | |
73 | return -1; | |
718e3744 | 74 | |
d62a17ae | 75 | *area_id_fmt = |
76 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; | |
718e3744 | 77 | |
d62a17ae | 78 | return 0; |
718e3744 | 79 | } |
80 | ||
1f9d4e3d | 81 | static void area_id2str(char *buf, int length, struct in_addr *area_id, |
82 | int area_id_fmt) | |
86573dcb | 83 | { |
d62a17ae | 84 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
1f9d4e3d | 85 | inet_ntop(AF_INET, area_id, buf, length); |
d62a17ae | 86 | else |
fc746f1c QY |
87 | snprintf(buf, length, "%lu", |
88 | (unsigned long)ntohl(area_id->s_addr)); | |
86573dcb | 89 | } |
6b0655a2 | 90 | |
d62a17ae | 91 | static int str2metric(const char *str, int *metric) |
718e3744 | 92 | { |
d62a17ae | 93 | /* Sanity check. */ |
94 | if (str == NULL) | |
95 | return 0; | |
718e3744 | 96 | |
d62a17ae | 97 | *metric = strtol(str, NULL, 10); |
1fdc969f | 98 | if (*metric < 0 || *metric > 16777214) { |
d62a17ae | 99 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ |
100 | return 0; | |
101 | } | |
718e3744 | 102 | |
d62a17ae | 103 | return 1; |
718e3744 | 104 | } |
105 | ||
d62a17ae | 106 | static int str2metric_type(const char *str, int *metric_type) |
718e3744 | 107 | { |
d62a17ae | 108 | /* Sanity check. */ |
109 | if (str == NULL) | |
110 | return 0; | |
718e3744 | 111 | |
d62a17ae | 112 | if (strncmp(str, "1", 1) == 0) |
113 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
114 | else if (strncmp(str, "2", 1) == 0) | |
115 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
116 | else | |
117 | return 0; | |
718e3744 | 118 | |
d62a17ae | 119 | return 1; |
718e3744 | 120 | } |
121 | ||
d62a17ae | 122 | int ospf_oi_count(struct interface *ifp) |
718e3744 | 123 | { |
d62a17ae | 124 | struct route_node *rn; |
125 | int i = 0; | |
718e3744 | 126 | |
d62a17ae | 127 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
128 | if (rn->info) | |
129 | i++; | |
718e3744 | 130 | |
d62a17ae | 131 | return i; |
718e3744 | 132 | } |
133 | ||
996c9314 LB |
134 | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ |
135 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ | |
136 | vrf_name = argv[idx_vrf + 1]->arg; \ | |
137 | all_vrf = strmatch(vrf_name, "all"); \ | |
43b8d1d8 CS |
138 | } |
139 | ||
140 | static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, | |
141 | struct cmd_token *argv[], | |
996c9314 | 142 | const int argc, uint32_t enable, |
d7c0a89a | 143 | unsigned short *instance) |
718e3744 | 144 | { |
b5a8894d | 145 | struct ospf *ospf = NULL; |
34d6798f | 146 | int idx_vrf = 0, idx_inst = 0; |
b5a8894d | 147 | const char *vrf_name = NULL; |
c572fbfe | 148 | bool created = false; |
b5a8894d | 149 | |
34d6798f CS |
150 | *instance = 0; |
151 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) | |
152 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); | |
153 | ||
b5a8894d | 154 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
b5a8894d | 155 | vrf_name = argv[idx_vrf + 1]->arg; |
6895b354 PG |
156 | if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME)) |
157 | vrf_name = NULL; | |
43b8d1d8 | 158 | if (enable) { |
43b8d1d8 | 159 | /* Allocate VRF aware instance */ |
c572fbfe | 160 | ospf = ospf_get(*instance, vrf_name, &created); |
43b8d1d8 | 161 | } else { |
43b8d1d8 CS |
162 | ospf = ospf_lookup_by_inst_name(*instance, vrf_name); |
163 | } | |
b5a8894d | 164 | } else { |
43b8d1d8 | 165 | if (enable) { |
c572fbfe | 166 | ospf = ospf_get(*instance, NULL, &created); |
43b8d1d8 | 167 | } else { |
43b8d1d8 | 168 | ospf = ospf_lookup_instance(*instance); |
b5a8894d | 169 | } |
d62a17ae | 170 | } |
34d6798f | 171 | |
c572fbfe DL |
172 | if (created) { |
173 | if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
174 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
175 | } | |
176 | ||
43b8d1d8 CS |
177 | return ospf; |
178 | } | |
179 | ||
52d0c099 | 180 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
d7c0a89a | 181 | json_object *json, uint8_t use_vrf) |
52d0c099 | 182 | { |
b1c3ae8c CS |
183 | if (use_vrf) { |
184 | if (json) { | |
185 | if (ospf->vrf_id == VRF_DEFAULT) | |
186 | json_object_string_add(json, "vrfName", | |
187 | "default"); | |
188 | else | |
189 | json_object_string_add(json, "vrfName", | |
190 | ospf->name); | |
191 | json_object_int_add(json, "vrfId", ospf->vrf_id); | |
192 | } else { | |
193 | if (ospf->vrf_id == VRF_DEFAULT) | |
194 | vty_out(vty, "VRF Name: %s\n", "default"); | |
195 | else if (ospf->name) | |
196 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
197 | } | |
52d0c099 | 198 | } |
52d0c099 CS |
199 | } |
200 | ||
43b8d1d8 | 201 | #ifndef VTYSH_EXTRACT_PL |
2e4c2296 | 202 | #include "ospfd/ospf_vty_clippy.c" |
43b8d1d8 CS |
203 | #endif |
204 | ||
205 | DEFUN_NOSH (router_ospf, | |
206 | router_ospf_cmd, | |
207 | "router ospf [{(1-65535)|vrf NAME}]", | |
208 | "Enable a routing process\n" | |
209 | "Start OSPF configuration\n" | |
210 | "Instance ID\n" | |
211 | VRF_CMD_HELP_STR) | |
212 | { | |
213 | struct ospf *ospf = NULL; | |
214 | int ret = CMD_SUCCESS; | |
d7c0a89a | 215 | unsigned short instance = 0; |
aed7cc62 CS |
216 | struct vrf *vrf = NULL; |
217 | struct route_node *rn; | |
218 | struct interface *ifp; | |
43b8d1d8 CS |
219 | |
220 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance); | |
221 | if (!ospf) | |
222 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 223 | |
d62a17ae | 224 | /* The following logic to set the vty qobj index is in place to be able |
225 | to ignore the commands which dont belong to this instance. */ | |
64ac44f6 | 226 | if (ospf->instance != instance) { |
d62a17ae | 227 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
64ac44f6 CS |
228 | ret = CMD_NOT_MY_INSTANCE; |
229 | } else { | |
b5a8894d CS |
230 | if (ospf->vrf_id != VRF_UNKNOWN) |
231 | ospf->oi_running = 1; | |
d62a17ae | 232 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 LB |
233 | zlog_debug( |
234 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
235 | instance, ospf->name ? ospf->name : "NIL", | |
236 | ospf->vrf_id, ospf->oi_running); | |
d62a17ae | 237 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); |
aed7cc62 CS |
238 | |
239 | /* Activate 'ip ospf area x' configured interfaces for given | |
240 | * vrf. Activate area on vrf x aware interfaces. | |
241 | * vrf_enable callback calls router_id_update which | |
242 | * internally will call ospf_if_update to trigger | |
243 | * network_run_state | |
244 | */ | |
245 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
246 | ||
247 | FOR_ALL_INTERFACES (vrf, ifp) { | |
248 | struct ospf_if_params *params; | |
249 | ||
250 | params = IF_DEF_PARAMS(ifp); | |
251 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
252 | for (rn = route_top(ospf->networks); rn; | |
253 | rn = route_next(rn)) { | |
254 | if (rn->info != NULL) { | |
255 | vty_out(vty, | |
996c9314 LB |
256 | "Interface %s has area config but please remove all network commands first.\n", |
257 | ifp->name); | |
aed7cc62 CS |
258 | return ret; |
259 | } | |
260 | } | |
e9f07a30 PG |
261 | if (!ospf_interface_area_is_already_set(ospf, |
262 | ifp)) { | |
263 | ospf_interface_area_set(ospf, ifp); | |
264 | ospf->if_ospf_cli_count++; | |
265 | } | |
aed7cc62 CS |
266 | } |
267 | } | |
268 | ||
d62a17ae | 269 | ospf_router_id_update(ospf); |
270 | } | |
271 | ||
64ac44f6 | 272 | return ret; |
718e3744 | 273 | } |
274 | ||
275 | DEFUN (no_router_ospf, | |
276 | no_router_ospf_cmd, | |
43b8d1d8 | 277 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 278 | NO_STR |
279 | "Enable a routing process\n" | |
7a7be519 | 280 | "Start OSPF configuration\n" |
b5a8894d CS |
281 | "Instance ID\n" |
282 | VRF_CMD_HELP_STR) | |
718e3744 | 283 | { |
d62a17ae | 284 | struct ospf *ospf; |
d7c0a89a | 285 | unsigned short instance = 0; |
b5a8894d | 286 | |
43b8d1d8 CS |
287 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); |
288 | if (ospf == NULL) { | |
289 | if (instance) | |
b5a8894d | 290 | return CMD_NOT_MY_INSTANCE; |
43b8d1d8 CS |
291 | else |
292 | return CMD_WARNING; | |
b5a8894d | 293 | } |
d62a17ae | 294 | ospf_finish(ospf); |
718e3744 | 295 | |
d62a17ae | 296 | return CMD_SUCCESS; |
718e3744 | 297 | } |
298 | ||
7c8ff89e | 299 | |
43b8d1d8 | 300 | DEFPY (ospf_router_id, |
718e3744 | 301 | ospf_router_id_cmd, |
302 | "ospf router-id A.B.C.D", | |
303 | "OSPF specific commands\n" | |
304 | "router-id for the OSPF process\n" | |
305 | "OSPF router-id in IP address format\n") | |
306 | { | |
a3d826f0 | 307 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 308 | |
d62a17ae | 309 | struct listnode *node; |
310 | struct ospf_area *area; | |
d62a17ae | 311 | |
312 | ospf->router_id_static = router_id; | |
313 | ||
314 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
315 | if (area->full_nbrs) { | |
316 | vty_out(vty, | |
3efd0893 | 317 | "For this router-id change to take effect, save config and restart ospfd\n"); |
d62a17ae | 318 | return CMD_SUCCESS; |
319 | } | |
320 | ||
321 | ospf_router_id_update(ospf); | |
322 | ||
323 | return CMD_SUCCESS; | |
718e3744 | 324 | } |
325 | ||
7a7be519 | 326 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
327 | ospf_router_id_old_cmd, |
328 | "router-id A.B.C.D", | |
329 | "router-id for the OSPF process\n" | |
330 | "OSPF router-id in IP address format\n") | |
7a7be519 | 331 | { |
a3d826f0 | 332 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 333 | int idx_ipv4 = 1; |
334 | struct listnode *node; | |
335 | struct ospf_area *area; | |
336 | struct in_addr router_id; | |
337 | int ret; | |
338 | ||
339 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
340 | if (!ret) { | |
341 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
342 | return CMD_WARNING_CONFIG_FAILED; | |
343 | } | |
7a7be519 | 344 | |
d62a17ae | 345 | ospf->router_id_static = router_id; |
346 | ||
347 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
348 | if (area->full_nbrs) { | |
349 | vty_out(vty, | |
3efd0893 | 350 | "For this router-id change to take effect, save config and restart ospfd\n"); |
d62a17ae | 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, | |
3efd0893 | 383 | "For this router-id change to take effect, save config and restart ospfd\n"); |
d62a17ae | 384 | return CMD_SUCCESS; |
385 | } | |
2c19a6ec | 386 | |
d62a17ae | 387 | ospf_router_id_update(ospf); |
718e3744 | 388 | |
d62a17ae | 389 | return CMD_SUCCESS; |
718e3744 | 390 | } |
391 | ||
718e3744 | 392 | |
d7c0a89a | 393 | static void ospf_passive_interface_default(struct ospf *ospf, uint8_t newval) |
d62a17ae | 394 | { |
f4e14fdb | 395 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 396 | struct listnode *ln; |
397 | struct interface *ifp; | |
398 | struct ospf_interface *oi; | |
399 | ||
400 | ospf->passive_interface_default = newval; | |
401 | ||
451fda4f | 402 | FOR_ALL_INTERFACES (vrf, ifp) { |
9d303b37 DL |
403 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
404 | passive_interface)) | |
d62a17ae | 405 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); |
406 | } | |
407 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
408 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
409 | UNSET_IF_PARAM(oi->params, passive_interface); | |
410 | /* update multicast memberships */ | |
411 | ospf_if_set_multicast(oi); | |
412 | } | |
413 | } | |
414 | ||
415 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
416 | struct interface *ifp, | |
417 | struct ospf_if_params *params, | |
d7c0a89a | 418 | uint8_t value, |
d62a17ae | 419 | struct in_addr addr) |
420 | { | |
d7c0a89a | 421 | uint8_t dflt; |
d62a17ae | 422 | |
423 | params->passive_interface = value; | |
424 | if (params != IF_DEF_PARAMS(ifp)) { | |
425 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
426 | passive_interface)) | |
427 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
428 | else | |
429 | dflt = ospf->passive_interface_default; | |
430 | ||
431 | if (value != dflt) | |
432 | SET_IF_PARAM(params, passive_interface); | |
433 | else | |
434 | UNSET_IF_PARAM(params, passive_interface); | |
435 | ||
436 | ospf_free_if_params(ifp, addr); | |
437 | ospf_if_update_params(ifp, addr); | |
438 | } | |
439 | } | |
440 | ||
441 | static void ospf_passive_interface_update(struct ospf *ospf, | |
442 | struct interface *ifp, | |
443 | struct ospf_if_params *params, | |
d7c0a89a | 444 | uint8_t value) |
d62a17ae | 445 | { |
446 | params->passive_interface = value; | |
447 | if (params == IF_DEF_PARAMS(ifp)) { | |
448 | if (value != ospf->passive_interface_default) | |
449 | SET_IF_PARAM(params, passive_interface); | |
450 | else | |
451 | UNSET_IF_PARAM(params, passive_interface); | |
452 | } | |
7ffa8fa2 PJ |
453 | } |
454 | ||
a2c62831 | 455 | DEFUN (ospf_passive_interface, |
456 | ospf_passive_interface_addr_cmd, | |
7a7be519 | 457 | "passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 458 | "Suppress routing updates on an interface\n" |
7a7be519 | 459 | "Interface's name\n" |
3a2d747c | 460 | "IPv4 address\n" |
7a7be519 | 461 | "Suppress routing updates on interfaces by default\n") |
718e3744 | 462 | { |
a3d826f0 | 463 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 464 | int idx_ipv4 = 2; |
e99734f1 | 465 | struct interface *ifp = NULL; |
d62a17ae | 466 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
467 | int ret; | |
468 | struct ospf_if_params *params; | |
469 | struct route_node *rn; | |
470 | ||
471 | if (strmatch(argv[1]->text, "default")) { | |
472 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
473 | return CMD_SUCCESS; | |
474 | } | |
e99734f1 | 475 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 476 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
d62a17ae | 477 | |
b5a8894d | 478 | if (ifp == NULL) { |
996c9314 | 479 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 480 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 481 | } |
d62a17ae | 482 | |
483 | params = IF_DEF_PARAMS(ifp); | |
484 | ||
485 | if (argc == 3) { | |
486 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
487 | if (!ret) { | |
488 | vty_out(vty, | |
489 | "Please specify interface address by A.B.C.D\n"); | |
490 | return CMD_WARNING_CONFIG_FAILED; | |
491 | } | |
492 | ||
493 | params = ospf_get_if_params(ifp, addr); | |
494 | ospf_if_update_params(ifp, addr); | |
495 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
496 | OSPF_IF_PASSIVE, addr); | |
497 | } | |
498 | ||
499 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
500 | ||
501 | /* XXX We should call ospf_if_set_multicast on exactly those | |
502 | * interfaces for which the passive property changed. It is too much | |
503 | * work to determine this set, so we do this for every interface. | |
504 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
505 | * record of joined groups to avoid systems calls if the desired | |
506 | * memberships match the current memership. | |
507 | */ | |
508 | ||
509 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
510 | struct ospf_interface *oi = rn->info; | |
511 | ||
9d303b37 DL |
512 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) |
513 | == OSPF_IF_PASSIVE)) | |
d62a17ae | 514 | ospf_if_set_multicast(oi); |
515 | } | |
516 | /* | |
517 | * XXX It is not clear what state transitions the interface needs to | |
518 | * undergo when going from active to passive. Fixing this will | |
519 | * require precise identification of interfaces having such a | |
520 | * transition. | |
521 | */ | |
522 | ||
523 | return CMD_SUCCESS; | |
718e3744 | 524 | } |
525 | ||
a2c62831 | 526 | DEFUN (no_ospf_passive_interface, |
527 | no_ospf_passive_interface_addr_cmd, | |
7a7be519 | 528 | "no passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 529 | NO_STR |
530 | "Allow routing updates on an interface\n" | |
7a7be519 | 531 | "Interface's name\n" |
3a2d747c | 532 | "IPv4 address\n" |
7a7be519 | 533 | "Allow routing updates on interfaces by default\n") |
718e3744 | 534 | { |
a3d826f0 | 535 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 536 | int idx_ipv4 = 3; |
e99734f1 | 537 | struct interface *ifp = NULL; |
d62a17ae | 538 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
539 | struct ospf_if_params *params; | |
540 | int ret; | |
541 | struct route_node *rn; | |
542 | ||
543 | if (strmatch(argv[2]->text, "default")) { | |
544 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
545 | return CMD_SUCCESS; | |
43540886 AS |
546 | } |
547 | ||
e99734f1 | 548 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 549 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
e99734f1 | 550 | |
b5a8894d | 551 | if (ifp == NULL) { |
996c9314 | 552 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 553 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 554 | } |
ba6454ec | 555 | |
d62a17ae | 556 | params = IF_DEF_PARAMS(ifp); |
557 | ||
558 | if (argc == 4) { | |
559 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
560 | if (!ret) { | |
561 | vty_out(vty, | |
562 | "Please specify interface address by A.B.C.D\n"); | |
563 | return CMD_WARNING_CONFIG_FAILED; | |
564 | } | |
565 | ||
566 | params = ospf_lookup_if_params(ifp, addr); | |
567 | if (params == NULL) | |
568 | return CMD_SUCCESS; | |
569 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
570 | OSPF_IF_ACTIVE, addr); | |
571 | } | |
572 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
573 | ||
574 | /* XXX We should call ospf_if_set_multicast on exactly those | |
575 | * interfaces for which the passive property changed. It is too much | |
576 | * work to determine this set, so we do this for every interface. | |
577 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
578 | * record of joined groups to avoid systems calls if the desired | |
579 | * memberships match the current memership. | |
580 | */ | |
581 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
582 | struct ospf_interface *oi = rn->info; | |
583 | ||
584 | if (oi | |
585 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
586 | ospf_if_set_multicast(oi); | |
587 | } | |
588 | ||
589 | return CMD_SUCCESS; | |
718e3744 | 590 | } |
591 | ||
718e3744 | 592 | |
a2c62831 | 593 | DEFUN (ospf_network_area, |
594 | ospf_network_area_cmd, | |
6147e2c6 | 595 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 596 | "Enable routing on an IP network\n" |
597 | "OSPF network prefix\n" | |
598 | "Set the OSPF area ID\n" | |
599 | "OSPF area ID in IP address format\n" | |
600 | "OSPF area ID as a decimal value\n") | |
601 | { | |
a3d826f0 | 602 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 603 | int idx_ipv4_prefixlen = 1; |
604 | int idx_ipv4_number = 3; | |
605 | struct prefix_ipv4 p; | |
606 | struct in_addr area_id; | |
607 | int ret, format; | |
608 | ||
609 | if (ospf->instance) { | |
610 | vty_out(vty, | |
611 | "The network command is not supported in multi-instance ospf\n"); | |
612 | return CMD_WARNING_CONFIG_FAILED; | |
613 | } | |
718e3744 | 614 | |
d62a17ae | 615 | if (ospf->if_ospf_cli_count > 0) { |
616 | vty_out(vty, | |
617 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 618 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 LB |
619 | zlog_debug( |
620 | "%s ospf vrf %s num of %u ip osp area x config", | |
5e81f5dd | 621 | __func__, ospf->name ? ospf->name : "NIL", |
996c9314 | 622 | ospf->if_ospf_cli_count); |
d62a17ae | 623 | return CMD_WARNING_CONFIG_FAILED; |
624 | } | |
625 | ||
626 | /* Get network prefix and Area ID. */ | |
627 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
628 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
629 | ||
630 | ret = ospf_network_set(ospf, &p, area_id, format); | |
631 | if (ret == 0) { | |
632 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 633 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 634 | } |
635 | ||
636 | return CMD_SUCCESS; | |
718e3744 | 637 | } |
638 | ||
a2c62831 | 639 | DEFUN (no_ospf_network_area, |
640 | no_ospf_network_area_cmd, | |
6147e2c6 | 641 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 642 | NO_STR |
643 | "Enable routing on an IP network\n" | |
644 | "OSPF network prefix\n" | |
645 | "Set the OSPF area ID\n" | |
646 | "OSPF area ID in IP address format\n" | |
647 | "OSPF area ID as a decimal value\n") | |
648 | { | |
a3d826f0 | 649 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 650 | int idx_ipv4_prefixlen = 2; |
651 | int idx_ipv4_number = 4; | |
652 | struct prefix_ipv4 p; | |
653 | struct in_addr area_id; | |
654 | int ret, format; | |
655 | ||
656 | if (ospf->instance) { | |
657 | vty_out(vty, | |
658 | "The network command is not supported in multi-instance ospf\n"); | |
659 | return CMD_WARNING_CONFIG_FAILED; | |
660 | } | |
718e3744 | 661 | |
d62a17ae | 662 | /* Get network prefix and Area ID. */ |
663 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
664 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
665 | ||
666 | ret = ospf_network_unset(ospf, &p, area_id); | |
667 | if (ret == 0) { | |
668 | vty_out(vty, | |
669 | "Can't find specified network area configuration.\n"); | |
670 | return CMD_WARNING_CONFIG_FAILED; | |
671 | } | |
672 | ||
673 | return CMD_SUCCESS; | |
718e3744 | 674 | } |
675 | ||
a2c62831 | 676 | DEFUN (ospf_area_range, |
677 | ospf_area_range_cmd, | |
7a7be519 | 678 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 679 | "OSPF area parameters\n" |
680 | "OSPF area ID in IP address format\n" | |
681 | "OSPF area ID as a decimal value\n" | |
682 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 683 | "Area range prefix\n" |
684 | "Advertise this range (default)\n" | |
685 | "User specified metric for this range\n" | |
686 | "Advertised metric for this range\n") | |
718e3744 | 687 | { |
a3d826f0 | 688 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 689 | int idx_ipv4_number = 1; |
690 | int idx_ipv4_prefixlen = 3; | |
691 | int idx_cost = 6; | |
692 | struct prefix_ipv4 p; | |
693 | struct in_addr area_id; | |
694 | int format; | |
d7c0a89a | 695 | uint32_t cost; |
d62a17ae | 696 | |
697 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
698 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
699 | ||
700 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
ed709ed1 GW |
701 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
702 | format); | |
d62a17ae | 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 |
7e5ee522 IR |
1181 | "Enable authentication on this virtual link\n" |
1182 | "Use message-digest authentication\n" | |
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, | |
3efd0893 | 1388 | "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n"); |
718e3744 | 1389 | |
d62a17ae | 1390 | return CMD_SUCCESS; |
718e3744 | 1391 | } |
1392 | ||
a2c62831 | 1393 | DEFUN (no_ospf_area_shortcut, |
1394 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1395 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1396 | NO_STR |
1397 | "OSPF area parameters\n" | |
1398 | "OSPF area ID in IP address format\n" | |
1399 | "OSPF area ID as a decimal value\n" | |
1400 | "Deconfigure the area's shortcutting mode\n" | |
1401 | "Deconfigure enabled shortcutting through the area\n" | |
1402 | "Deconfigure disabled shortcutting through the area\n") | |
1403 | { | |
a3d826f0 | 1404 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1405 | int idx_ipv4_number = 2; |
1406 | struct ospf_area *area; | |
1407 | struct in_addr area_id; | |
1408 | int format; | |
718e3744 | 1409 | |
d62a17ae | 1410 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1411 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1412 | |
d62a17ae | 1413 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1414 | if (!area) | |
1415 | return CMD_SUCCESS; | |
718e3744 | 1416 | |
d62a17ae | 1417 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1418 | |
d62a17ae | 1419 | return CMD_SUCCESS; |
718e3744 | 1420 | } |
1421 | ||
6b0655a2 | 1422 | |
a2c62831 | 1423 | DEFUN (ospf_area_stub, |
1424 | ospf_area_stub_cmd, | |
6147e2c6 | 1425 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1426 | "OSPF area parameters\n" |
1427 | "OSPF area ID in IP address format\n" | |
1428 | "OSPF area ID as a decimal value\n" | |
1429 | "Configure OSPF area as stub\n") | |
1430 | { | |
a3d826f0 | 1431 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1432 | int idx_ipv4_number = 1; |
1433 | struct in_addr area_id; | |
1434 | int ret, format; | |
1435 | ||
1436 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1437 | argv[idx_ipv4_number]->arg); | |
1438 | ||
1439 | ret = ospf_area_stub_set(ospf, area_id); | |
1440 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1441 | format); | |
1442 | if (ret == 0) { | |
1443 | vty_out(vty, | |
1444 | "First deconfigure all virtual link through this area\n"); | |
1445 | return CMD_WARNING_CONFIG_FAILED; | |
1446 | } | |
718e3744 | 1447 | |
d62a17ae | 1448 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1449 | |
d62a17ae | 1450 | return CMD_SUCCESS; |
718e3744 | 1451 | } |
1452 | ||
a2c62831 | 1453 | DEFUN (ospf_area_stub_no_summary, |
1454 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1455 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1456 | "OSPF stub parameters\n" |
1457 | "OSPF area ID in IP address format\n" | |
1458 | "OSPF area ID as a decimal value\n" | |
1459 | "Configure OSPF area as stub\n" | |
1460 | "Do not inject inter-area routes into stub\n") | |
1461 | { | |
a3d826f0 | 1462 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1463 | int idx_ipv4_number = 1; |
1464 | struct in_addr area_id; | |
1465 | int ret, format; | |
1466 | ||
1467 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1468 | argv[idx_ipv4_number]->arg); | |
1469 | ||
1470 | ret = ospf_area_stub_set(ospf, area_id); | |
1471 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1472 | format); | |
1473 | if (ret == 0) { | |
1474 | vty_out(vty, | |
1475 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1476 | return CMD_WARNING_CONFIG_FAILED; | |
1477 | } | |
718e3744 | 1478 | |
d62a17ae | 1479 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1480 | |
d62a17ae | 1481 | return CMD_SUCCESS; |
718e3744 | 1482 | } |
1483 | ||
a2c62831 | 1484 | DEFUN (no_ospf_area_stub, |
1485 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1486 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1487 | NO_STR |
1488 | "OSPF area parameters\n" | |
1489 | "OSPF area ID in IP address format\n" | |
1490 | "OSPF area ID as a decimal value\n" | |
1491 | "Configure OSPF area as stub\n") | |
1492 | { | |
a3d826f0 | 1493 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1494 | int idx_ipv4_number = 2; |
1495 | struct in_addr area_id; | |
1496 | int format; | |
718e3744 | 1497 | |
d62a17ae | 1498 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1499 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1500 | |
d62a17ae | 1501 | ospf_area_stub_unset(ospf, area_id); |
1502 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1503 | |
d62a17ae | 1504 | return CMD_SUCCESS; |
718e3744 | 1505 | } |
1506 | ||
a2c62831 | 1507 | DEFUN (no_ospf_area_stub_no_summary, |
1508 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1509 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1510 | NO_STR |
1511 | "OSPF area parameters\n" | |
1512 | "OSPF area ID in IP address format\n" | |
1513 | "OSPF area ID as a decimal value\n" | |
1514 | "Configure OSPF area as stub\n" | |
1515 | "Do not inject inter-area routes into area\n") | |
1516 | { | |
a3d826f0 | 1517 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1518 | int idx_ipv4_number = 2; |
1519 | struct in_addr area_id; | |
1520 | int format; | |
718e3744 | 1521 | |
d62a17ae | 1522 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1523 | argv[idx_ipv4_number]->arg); | |
1524 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1525 | |
d62a17ae | 1526 | return CMD_SUCCESS; |
718e3744 | 1527 | } |
1528 | ||
d62a17ae | 1529 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1530 | struct cmd_token **argv, int cfg_nosum, |
1531 | int nosum) | |
718e3744 | 1532 | { |
a3d826f0 | 1533 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1534 | struct in_addr area_id; |
1535 | int ret, format; | |
1536 | ||
1537 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1538 | ||
1539 | ret = ospf_area_nssa_set(ospf, area_id); | |
1540 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1541 | format); | |
1542 | if (ret == 0) { | |
1543 | vty_out(vty, | |
1544 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1545 | return CMD_WARNING_CONFIG_FAILED; | |
1546 | } | |
1547 | ||
1548 | if (argc > 3) { | |
1549 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1550 | ospf_area_nssa_translator_role_set( | |
1551 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1552 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1553 | ospf_area_nssa_translator_role_set( | |
1554 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1555 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1556 | ospf_area_nssa_translator_role_set( | |
1557 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1558 | } else { | |
1559 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1560 | OSPF_NSSA_ROLE_CANDIDATE); | |
1561 | } | |
1562 | ||
7ef56a73 CS |
1563 | if (cfg_nosum) { |
1564 | if (nosum) | |
1565 | ospf_area_no_summary_set(ospf, area_id); | |
1566 | else | |
1567 | ospf_area_no_summary_unset(ospf, area_id); | |
1568 | } | |
d62a17ae | 1569 | |
1570 | ospf_schedule_abr_task(ospf); | |
1571 | ||
1572 | return CMD_SUCCESS; | |
718e3744 | 1573 | } |
1574 | ||
718e3744 | 1575 | |
b0a053be | 1576 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1577 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1578 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1579 | "OSPF area parameters\n" |
1580 | "OSPF area ID in IP address format\n" | |
1581 | "OSPF area ID as a decimal value\n" | |
1582 | "Configure OSPF area as nssa\n" | |
1583 | "Configure NSSA-ABR for translate election (default)\n" | |
1584 | "Configure NSSA-ABR to never translate\n" | |
1585 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1586 | { |
7ef56a73 | 1587 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1588 | } |
1589 | ||
1590 | DEFUN (ospf_area_nssa, | |
1591 | ospf_area_nssa_cmd, | |
6147e2c6 | 1592 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1593 | "OSPF area parameters\n" |
1594 | "OSPF area ID in IP address format\n" | |
1595 | "OSPF area ID as a decimal value\n" | |
1596 | "Configure OSPF area as nssa\n") | |
1597 | { | |
2643b2bc | 1598 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1599 | } |
718e3744 | 1600 | |
a2c62831 | 1601 | DEFUN (ospf_area_nssa_no_summary, |
1602 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1603 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1604 | "OSPF area parameters\n" |
1605 | "OSPF area ID in IP address format\n" | |
1606 | "OSPF area ID as a decimal value\n" | |
1607 | "Configure OSPF area as nssa\n" | |
1608 | "Do not inject inter-area routes into nssa\n") | |
1609 | { | |
7ef56a73 CS |
1610 | int idx_ipv4_number = 1; |
1611 | struct in_addr area_id; | |
1612 | int format; | |
1613 | ||
1614 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1615 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1616 | argv[idx_ipv4_number]->arg); | |
1617 | ||
1618 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1619 | format); | |
1620 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1621 | ||
1622 | ospf_schedule_abr_task(ospf); | |
1623 | ||
1624 | return CMD_SUCCESS; | |
1625 | } | |
1626 | ||
1627 | DEFUN (no_ospf_area_nssa_no_summary, | |
1628 | no_ospf_area_nssa_no_summary_cmd, | |
1629 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1630 | NO_STR | |
1631 | "OSPF area parameters\n" | |
1632 | "OSPF area ID in IP address format\n" | |
1633 | "OSPF area ID as a decimal value\n" | |
1634 | "Configure OSPF area as nssa\n" | |
1635 | "Do not inject inter-area routes into nssa\n") | |
1636 | { | |
1637 | int idx_ipv4_number = 2; | |
1638 | struct in_addr area_id; | |
1639 | int format; | |
1640 | ||
1641 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1642 | ||
1643 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1644 | argv[idx_ipv4_number]->arg); | |
1645 | ||
1646 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1647 | format); | |
1648 | ospf_area_no_summary_unset(ospf, area_id); | |
1649 | ||
1650 | ospf_schedule_abr_task(ospf); | |
1651 | ||
1652 | return CMD_SUCCESS; | |
718e3744 | 1653 | } |
1654 | ||
a2c62831 | 1655 | DEFUN (no_ospf_area_nssa, |
1656 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1657 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1658 | NO_STR |
1659 | "OSPF area parameters\n" | |
1660 | "OSPF area ID in IP address format\n" | |
1661 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1662 | "Configure OSPF area as nssa\n" |
1663 | "Configure NSSA-ABR for translate election (default)\n" | |
1664 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1665 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1666 | { |
a3d826f0 | 1667 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1668 | int idx_ipv4_number = 2; |
1669 | struct in_addr area_id; | |
1670 | int format; | |
718e3744 | 1671 | |
d62a17ae | 1672 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1673 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1674 | |
7ef56a73 | 1675 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1676 | |
d62a17ae | 1677 | ospf_schedule_abr_task(ospf); |
b0a053be | 1678 | |
d62a17ae | 1679 | return CMD_SUCCESS; |
718e3744 | 1680 | } |
1681 | ||
718e3744 | 1682 | |
a2c62831 | 1683 | DEFUN (ospf_area_default_cost, |
1684 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1685 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1686 | "OSPF area parameters\n" |
1687 | "OSPF area ID in IP address format\n" | |
1688 | "OSPF area ID as a decimal value\n" | |
1689 | "Set the summary-default cost of a NSSA or stub area\n" | |
1690 | "Stub's advertised default summary cost\n") | |
1691 | { | |
a3d826f0 | 1692 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1693 | int idx_ipv4_number = 1; |
1694 | int idx_number = 3; | |
1695 | struct ospf_area *area; | |
1696 | struct in_addr area_id; | |
d7c0a89a | 1697 | uint32_t cost; |
d62a17ae | 1698 | int format; |
1699 | struct prefix_ipv4 p; | |
1700 | ||
1701 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1702 | argv[idx_ipv4_number]->arg); | |
1703 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1704 | ||
1705 | area = ospf_area_get(ospf, area_id); | |
1706 | ospf_area_display_format_set(ospf, area, format); | |
1707 | ||
1708 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1709 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1710 | return CMD_WARNING_CONFIG_FAILED; | |
1711 | } | |
ba682537 | 1712 | |
d62a17ae | 1713 | area->default_cost = cost; |
1714 | ||
1715 | p.family = AF_INET; | |
1716 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1717 | p.prefixlen = 0; | |
1718 | if (IS_DEBUG_OSPF_EVENT) | |
1719 | zlog_debug( | |
3efd0893 | 1720 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %s", |
d62a17ae | 1721 | inet_ntoa(area->area_id)); |
1722 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
1723 | ||
1724 | return CMD_SUCCESS; | |
718e3744 | 1725 | } |
1726 | ||
a2c62831 | 1727 | DEFUN (no_ospf_area_default_cost, |
1728 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1729 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1730 | NO_STR |
1731 | "OSPF area parameters\n" | |
1732 | "OSPF area ID in IP address format\n" | |
1733 | "OSPF area ID as a decimal value\n" | |
1734 | "Set the summary-default cost of a NSSA or stub area\n" | |
1735 | "Stub's advertised default summary cost\n") | |
1736 | { | |
a3d826f0 | 1737 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1738 | int idx_ipv4_number = 2; |
1739 | struct ospf_area *area; | |
1740 | struct in_addr area_id; | |
1741 | int format; | |
1742 | struct prefix_ipv4 p; | |
718e3744 | 1743 | |
d62a17ae | 1744 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1745 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1746 | |
d62a17ae | 1747 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1748 | if (area == NULL) | |
1749 | return CMD_SUCCESS; | |
718e3744 | 1750 | |
d62a17ae | 1751 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1752 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1753 | return CMD_WARNING_CONFIG_FAILED; | |
1754 | } | |
718e3744 | 1755 | |
d62a17ae | 1756 | area->default_cost = 1; |
718e3744 | 1757 | |
d62a17ae | 1758 | p.family = AF_INET; |
1759 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1760 | p.prefixlen = 0; | |
1761 | if (IS_DEBUG_OSPF_EVENT) | |
1762 | zlog_debug( | |
3efd0893 | 1763 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %s", |
d62a17ae | 1764 | inet_ntoa(area->area_id)); |
1765 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
ba682537 | 1766 | |
1767 | ||
d62a17ae | 1768 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1769 | |
d62a17ae | 1770 | return CMD_SUCCESS; |
718e3744 | 1771 | } |
1772 | ||
a2c62831 | 1773 | DEFUN (ospf_area_export_list, |
1774 | ospf_area_export_list_cmd, | |
6147e2c6 | 1775 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1776 | "OSPF area parameters\n" |
1777 | "OSPF area ID in IP address format\n" | |
1778 | "OSPF area ID as a decimal value\n" | |
1779 | "Set the filter for networks announced to other areas\n" | |
1780 | "Name of the access-list\n") | |
1781 | { | |
a3d826f0 | 1782 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1783 | int idx_ipv4_number = 1; |
1784 | struct ospf_area *area; | |
1785 | struct in_addr area_id; | |
1786 | int format; | |
718e3744 | 1787 | |
d62a17ae | 1788 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1789 | |
d62a17ae | 1790 | area = ospf_area_get(ospf, area_id); |
1791 | ospf_area_display_format_set(ospf, area, format); | |
1792 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1793 | |
d62a17ae | 1794 | return CMD_SUCCESS; |
718e3744 | 1795 | } |
1796 | ||
a2c62831 | 1797 | DEFUN (no_ospf_area_export_list, |
1798 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1799 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1800 | NO_STR |
1801 | "OSPF area parameters\n" | |
1802 | "OSPF area ID in IP address format\n" | |
1803 | "OSPF area ID as a decimal value\n" | |
1804 | "Unset the filter for networks announced to other areas\n" | |
1805 | "Name of the access-list\n") | |
1806 | { | |
a3d826f0 | 1807 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1808 | int idx_ipv4_number = 2; |
1809 | struct ospf_area *area; | |
1810 | struct in_addr area_id; | |
1811 | int format; | |
718e3744 | 1812 | |
d62a17ae | 1813 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1814 | |
d62a17ae | 1815 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1816 | if (area == NULL) | |
1817 | return CMD_SUCCESS; | |
718e3744 | 1818 | |
d62a17ae | 1819 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1820 | |
d62a17ae | 1821 | return CMD_SUCCESS; |
718e3744 | 1822 | } |
1823 | ||
1824 | ||
a2c62831 | 1825 | DEFUN (ospf_area_import_list, |
1826 | ospf_area_import_list_cmd, | |
6147e2c6 | 1827 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1828 | "OSPF area parameters\n" |
1829 | "OSPF area ID in IP address format\n" | |
1830 | "OSPF area ID as a decimal value\n" | |
1831 | "Set the filter for networks from other areas announced to the specified one\n" | |
1832 | "Name of the access-list\n") | |
1833 | { | |
a3d826f0 | 1834 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1835 | int idx_ipv4_number = 1; |
1836 | struct ospf_area *area; | |
1837 | struct in_addr area_id; | |
1838 | int format; | |
718e3744 | 1839 | |
d62a17ae | 1840 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1841 | |
d62a17ae | 1842 | area = ospf_area_get(ospf, area_id); |
1843 | ospf_area_display_format_set(ospf, area, format); | |
1844 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1845 | |
d62a17ae | 1846 | return CMD_SUCCESS; |
718e3744 | 1847 | } |
1848 | ||
a2c62831 | 1849 | DEFUN (no_ospf_area_import_list, |
1850 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1851 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1852 | NO_STR |
1853 | "OSPF area parameters\n" | |
1854 | "OSPF area ID in IP address format\n" | |
1855 | "OSPF area ID as a decimal value\n" | |
1856 | "Unset the filter for networks announced to other areas\n" | |
1857 | "Name of the access-list\n") | |
1858 | { | |
a3d826f0 | 1859 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1860 | int idx_ipv4_number = 2; |
1861 | struct ospf_area *area; | |
1862 | struct in_addr area_id; | |
1863 | int format; | |
718e3744 | 1864 | |
d62a17ae | 1865 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1866 | |
d62a17ae | 1867 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1868 | if (area == NULL) | |
1869 | return CMD_SUCCESS; | |
718e3744 | 1870 | |
d62a17ae | 1871 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1872 | |
d62a17ae | 1873 | return CMD_SUCCESS; |
718e3744 | 1874 | } |
1875 | ||
a2c62831 | 1876 | DEFUN (ospf_area_filter_list, |
1877 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1878 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1879 | "OSPF area parameters\n" |
1880 | "OSPF area ID in IP address format\n" | |
1881 | "OSPF area ID as a decimal value\n" | |
1882 | "Filter networks between OSPF areas\n" | |
1883 | "Filter prefixes between OSPF areas\n" | |
1884 | "Name of an IP prefix-list\n" | |
1885 | "Filter networks sent to this area\n" | |
1886 | "Filter networks sent from this area\n") | |
1887 | { | |
a3d826f0 | 1888 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1889 | int idx_ipv4_number = 1; |
1890 | int idx_word = 4; | |
1891 | int idx_in_out = 5; | |
1892 | struct ospf_area *area; | |
1893 | struct in_addr area_id; | |
1894 | struct prefix_list *plist; | |
1895 | int format; | |
1896 | ||
1897 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1898 | ||
1899 | area = ospf_area_get(ospf, area_id); | |
1900 | ospf_area_display_format_set(ospf, area, format); | |
1901 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1902 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1903 | PREFIX_LIST_IN(area) = plist; | |
1904 | if (PREFIX_NAME_IN(area)) | |
1905 | free(PREFIX_NAME_IN(area)); | |
1906 | ||
1907 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1908 | ospf_schedule_abr_task(ospf); | |
1909 | } else { | |
1910 | PREFIX_LIST_OUT(area) = plist; | |
1911 | if (PREFIX_NAME_OUT(area)) | |
1912 | free(PREFIX_NAME_OUT(area)); | |
1913 | ||
1914 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1915 | ospf_schedule_abr_task(ospf); | |
1916 | } | |
718e3744 | 1917 | |
d62a17ae | 1918 | return CMD_SUCCESS; |
718e3744 | 1919 | } |
1920 | ||
a2c62831 | 1921 | DEFUN (no_ospf_area_filter_list, |
1922 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1923 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1924 | NO_STR |
1925 | "OSPF area parameters\n" | |
1926 | "OSPF area ID in IP address format\n" | |
1927 | "OSPF area ID as a decimal value\n" | |
1928 | "Filter networks between OSPF areas\n" | |
1929 | "Filter prefixes between OSPF areas\n" | |
1930 | "Name of an IP prefix-list\n" | |
1931 | "Filter networks sent to this area\n" | |
1932 | "Filter networks sent from this area\n") | |
1933 | { | |
a3d826f0 | 1934 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1935 | int idx_ipv4_number = 2; |
1936 | int idx_word = 5; | |
1937 | int idx_in_out = 6; | |
1938 | struct ospf_area *area; | |
1939 | struct in_addr area_id; | |
1940 | int format; | |
718e3744 | 1941 | |
d62a17ae | 1942 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1943 | |
d62a17ae | 1944 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1945 | return CMD_SUCCESS; | |
718e3744 | 1946 | |
d62a17ae | 1947 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1948 | if (PREFIX_NAME_IN(area)) | |
1949 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1950 | != 0) | |
1951 | return CMD_SUCCESS; | |
718e3744 | 1952 | |
d62a17ae | 1953 | PREFIX_LIST_IN(area) = NULL; |
1954 | if (PREFIX_NAME_IN(area)) | |
1955 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1956 | |
d62a17ae | 1957 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1958 | |
d62a17ae | 1959 | ospf_schedule_abr_task(ospf); |
1960 | } else { | |
1961 | if (PREFIX_NAME_OUT(area)) | |
1962 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1963 | != 0) | |
1964 | return CMD_SUCCESS; | |
718e3744 | 1965 | |
d62a17ae | 1966 | PREFIX_LIST_OUT(area) = NULL; |
1967 | if (PREFIX_NAME_OUT(area)) | |
1968 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1969 | |
d62a17ae | 1970 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1971 | |
d62a17ae | 1972 | ospf_schedule_abr_task(ospf); |
1973 | } | |
1974 | ||
1975 | return CMD_SUCCESS; | |
718e3744 | 1976 | } |
1977 | ||
6b0655a2 | 1978 | |
a2c62831 | 1979 | DEFUN (ospf_area_authentication_message_digest, |
1980 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1981 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1982 | NO_STR | |
718e3744 | 1983 | "OSPF area parameters\n" |
2b00515a CF |
1984 | "OSPF area ID in IP address format\n" |
1985 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1986 | "Enable authentication\n" |
1987 | "Use message-digest authentication\n") | |
1988 | { | |
a3d826f0 | 1989 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 1990 | int idx = 0; |
d62a17ae | 1991 | struct ospf_area *area; |
1992 | struct in_addr area_id; | |
1993 | int format; | |
718e3744 | 1994 | |
ca19319b | 1995 | argv_find(argv, argc, "area", &idx); |
1996 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 1997 | |
d62a17ae | 1998 | area = ospf_area_get(ospf, area_id); |
1999 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
2000 | area->auth_type = strmatch(argv[0]->text, "no") |
2001 | ? OSPF_AUTH_NULL | |
2002 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 2003 | |
d62a17ae | 2004 | return CMD_SUCCESS; |
718e3744 | 2005 | } |
2006 | ||
a2c62831 | 2007 | DEFUN (ospf_area_authentication, |
2008 | ospf_area_authentication_cmd, | |
6147e2c6 | 2009 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2010 | "OSPF area parameters\n" |
2011 | "OSPF area ID in IP address format\n" | |
2012 | "OSPF area ID as a decimal value\n" | |
2013 | "Enable authentication\n") | |
2014 | { | |
a3d826f0 | 2015 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2016 | int idx_ipv4_number = 1; |
2017 | struct ospf_area *area; | |
2018 | struct in_addr area_id; | |
2019 | int format; | |
718e3744 | 2020 | |
d62a17ae | 2021 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2022 | |
d62a17ae | 2023 | area = ospf_area_get(ospf, area_id); |
2024 | ospf_area_display_format_set(ospf, area, format); | |
2025 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 2026 | |
d62a17ae | 2027 | return CMD_SUCCESS; |
718e3744 | 2028 | } |
2029 | ||
a2c62831 | 2030 | DEFUN (no_ospf_area_authentication, |
2031 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2032 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2033 | NO_STR |
2034 | "OSPF area parameters\n" | |
2035 | "OSPF area ID in IP address format\n" | |
2036 | "OSPF area ID as a decimal value\n" | |
2037 | "Enable authentication\n") | |
2038 | { | |
a3d826f0 | 2039 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2040 | int idx_ipv4_number = 2; |
2041 | struct ospf_area *area; | |
2042 | struct in_addr area_id; | |
2043 | int format; | |
718e3744 | 2044 | |
d62a17ae | 2045 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2046 | |
d62a17ae | 2047 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2048 | if (area == NULL) | |
2049 | return CMD_SUCCESS; | |
718e3744 | 2050 | |
d62a17ae | 2051 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2052 | |
d62a17ae | 2053 | ospf_area_check_free(ospf, area_id); |
2054 | ||
2055 | return CMD_SUCCESS; | |
718e3744 | 2056 | } |
2057 | ||
6b0655a2 | 2058 | |
718e3744 | 2059 | DEFUN (ospf_abr_type, |
2060 | ospf_abr_type_cmd, | |
6147e2c6 | 2061 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2062 | "OSPF specific commands\n" |
2063 | "Set OSPF ABR type\n" | |
2064 | "Alternative ABR, cisco implementation\n" | |
2065 | "Alternative ABR, IBM implementation\n" | |
2066 | "Shortcut ABR\n" | |
2067 | "Standard behavior (RFC2328)\n") | |
2068 | { | |
a3d826f0 | 2069 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2070 | int idx_vendor = 2; |
d7c0a89a | 2071 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2072 | |
2073 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2074 | abr_type = OSPF_ABR_CISCO; | |
2075 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2076 | abr_type = OSPF_ABR_IBM; | |
2077 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2078 | abr_type = OSPF_ABR_SHORTCUT; | |
2079 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2080 | abr_type = OSPF_ABR_STAND; | |
2081 | else | |
2082 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2083 | |
d62a17ae | 2084 | /* If ABR type value is changed, schedule ABR task. */ |
2085 | if (ospf->abr_type != abr_type) { | |
2086 | ospf->abr_type = abr_type; | |
2087 | ospf_schedule_abr_task(ospf); | |
2088 | } | |
2089 | ||
2090 | return CMD_SUCCESS; | |
718e3744 | 2091 | } |
2092 | ||
2093 | DEFUN (no_ospf_abr_type, | |
2094 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2095 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2096 | NO_STR |
2097 | "OSPF specific commands\n" | |
2098 | "Set OSPF ABR type\n" | |
2099 | "Alternative ABR, cisco implementation\n" | |
2100 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2101 | "Shortcut ABR\n" |
2102 | "Standard ABR\n") | |
718e3744 | 2103 | { |
a3d826f0 | 2104 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2105 | int idx_vendor = 3; |
d7c0a89a | 2106 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2107 | |
2108 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2109 | abr_type = OSPF_ABR_CISCO; | |
2110 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2111 | abr_type = OSPF_ABR_IBM; | |
2112 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2113 | abr_type = OSPF_ABR_SHORTCUT; | |
2114 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2115 | abr_type = OSPF_ABR_STAND; | |
2116 | else | |
2117 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2118 | |
d62a17ae | 2119 | /* If ABR type value is changed, schedule ABR task. */ |
2120 | if (ospf->abr_type == abr_type) { | |
2121 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2122 | ospf_schedule_abr_task(ospf); | |
2123 | } | |
2124 | ||
2125 | return CMD_SUCCESS; | |
718e3744 | 2126 | } |
2127 | ||
d7e60dd7 AS |
2128 | DEFUN (ospf_log_adjacency_changes, |
2129 | ospf_log_adjacency_changes_cmd, | |
2130 | "log-adjacency-changes", | |
2131 | "Log changes in adjacency state\n") | |
2132 | { | |
a3d826f0 | 2133 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2134 | |
d62a17ae | 2135 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2136 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2137 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2138 | } |
2139 | ||
2140 | DEFUN (ospf_log_adjacency_changes_detail, | |
2141 | ospf_log_adjacency_changes_detail_cmd, | |
2142 | "log-adjacency-changes detail", | |
2143 | "Log changes in adjacency state\n" | |
2144 | "Log all state changes\n") | |
2145 | { | |
a3d826f0 | 2146 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2147 | |
d62a17ae | 2148 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2149 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2150 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2151 | } |
2152 | ||
2153 | DEFUN (no_ospf_log_adjacency_changes, | |
2154 | no_ospf_log_adjacency_changes_cmd, | |
2155 | "no log-adjacency-changes", | |
2156 | NO_STR | |
2157 | "Log changes in adjacency state\n") | |
2158 | { | |
a3d826f0 | 2159 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2160 | |
d62a17ae | 2161 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2162 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2163 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2164 | } |
2165 | ||
2166 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2167 | no_ospf_log_adjacency_changes_detail_cmd, | |
2168 | "no log-adjacency-changes detail", | |
2169 | NO_STR | |
2170 | "Log changes in adjacency state\n" | |
2171 | "Log all state changes\n") | |
2172 | { | |
a3d826f0 | 2173 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2174 | |
d62a17ae | 2175 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2176 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2177 | } |
2178 | ||
718e3744 | 2179 | DEFUN (ospf_compatible_rfc1583, |
2180 | ospf_compatible_rfc1583_cmd, | |
2181 | "compatible rfc1583", | |
2182 | "OSPF compatibility list\n" | |
2183 | "compatible with RFC 1583\n") | |
2184 | { | |
a3d826f0 | 2185 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2186 | |
d62a17ae | 2187 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2188 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2189 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2190 | } | |
2191 | return CMD_SUCCESS; | |
718e3744 | 2192 | } |
2193 | ||
2194 | DEFUN (no_ospf_compatible_rfc1583, | |
2195 | no_ospf_compatible_rfc1583_cmd, | |
2196 | "no compatible rfc1583", | |
2197 | NO_STR | |
2198 | "OSPF compatibility list\n" | |
2199 | "compatible with RFC 1583\n") | |
2200 | { | |
a3d826f0 | 2201 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2202 | |
d62a17ae | 2203 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2204 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2205 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2206 | } | |
2207 | return CMD_SUCCESS; | |
718e3744 | 2208 | } |
2209 | ||
d62a17ae | 2210 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2211 | "ospf rfc1583compatibility", | |
2212 | "OSPF specific commands\n" | |
2213 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2214 | |
d62a17ae | 2215 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2216 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2217 | "OSPF specific commands\n" |
2218 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2219 | |
d62a17ae | 2220 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2221 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2222 | { |
a3d826f0 | 2223 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2224 | |
d62a17ae | 2225 | ospf->spf_delay = delay; |
2226 | ospf->spf_holdtime = hold; | |
2227 | ospf->spf_max_holdtime = max; | |
2228 | ||
2229 | return CMD_SUCCESS; | |
d24f6e2a | 2230 | } |
718e3744 | 2231 | |
ac7424f9 MR |
2232 | DEFUN (ospf_timers_min_ls_interval, |
2233 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2234 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2235 | "Adjust routing timers\n" |
2236 | "Throttling adaptive timer\n" | |
2237 | "LSA delay between transmissions\n" | |
813d4307 | 2238 | "All LSA types\n" |
ac7424f9 MR |
2239 | "Delay (msec) between sending LSAs\n") |
2240 | { | |
a3d826f0 | 2241 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2242 | int idx_number = 4; |
2243 | unsigned int interval; | |
ac7424f9 | 2244 | |
d62a17ae | 2245 | if (argc < 5) { |
2246 | vty_out(vty, "Insufficient arguments\n"); | |
2247 | return CMD_WARNING_CONFIG_FAILED; | |
2248 | } | |
ac7424f9 | 2249 | |
d62a17ae | 2250 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2251 | |
d62a17ae | 2252 | ospf->min_ls_interval = interval; |
ac7424f9 | 2253 | |
d62a17ae | 2254 | return CMD_SUCCESS; |
ac7424f9 MR |
2255 | } |
2256 | ||
2257 | DEFUN (no_ospf_timers_min_ls_interval, | |
2258 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2259 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2260 | NO_STR |
2261 | "Adjust routing timers\n" | |
2262 | "Throttling adaptive timer\n" | |
813d4307 | 2263 | "LSA delay between transmissions\n" |
7a7be519 | 2264 | "All LSA types\n" |
2265 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2266 | { |
a3d826f0 | 2267 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2268 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2269 | |
d62a17ae | 2270 | return CMD_SUCCESS; |
ac7424f9 MR |
2271 | } |
2272 | ||
d24f6e2a | 2273 | DEFUN (ospf_timers_throttle_spf, |
2274 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2275 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2276 | "Adjust routing timers\n" |
2277 | "Throttling adaptive timer\n" | |
2278 | "OSPF SPF timers\n" | |
2279 | "Delay (msec) from first change received till SPF calculation\n" | |
2280 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2281 | "Maximum hold time (msec)\n") | |
2282 | { | |
d62a17ae | 2283 | int idx_number = 3; |
2284 | int idx_number_2 = 4; | |
2285 | int idx_number_3 = 5; | |
2286 | unsigned int delay, hold, max; | |
2287 | ||
2288 | if (argc < 6) { | |
2289 | vty_out(vty, "Insufficient arguments\n"); | |
2290 | return CMD_WARNING_CONFIG_FAILED; | |
2291 | } | |
2292 | ||
2293 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2294 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2295 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2296 | ||
2297 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2298 | } |
2299 | ||
d24f6e2a | 2300 | DEFUN (no_ospf_timers_throttle_spf, |
2301 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2302 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2303 | NO_STR |
2304 | "Adjust routing timers\n" | |
d24f6e2a | 2305 | "Throttling adaptive timer\n" |
7a7be519 | 2306 | "OSPF SPF timers\n" |
2307 | "Delay (msec) from first change received till SPF calculation\n" | |
2308 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2309 | "Maximum hold time (msec)\n") | |
22b27e95 | 2310 | { |
d62a17ae | 2311 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2312 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2313 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2314 | } |
2315 | ||
b4a039bf | 2316 | |
0e88de35 QY |
2317 | DEFUN (ospf_timers_lsa_min_arrival, |
2318 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2319 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2320 | "Adjust routing timers\n" |
2321 | "OSPF LSA timers\n" | |
2322 | "Minimum delay in receiving new version of a LSA\n" | |
2323 | "Delay in milliseconds\n") | |
2324 | { | |
a3d826f0 | 2325 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2326 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2327 | return CMD_SUCCESS; |
b6927875 DS |
2328 | } |
2329 | ||
0e88de35 QY |
2330 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2331 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2332 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2333 | NO_STR |
2334 | "Adjust routing timers\n" | |
2335 | "OSPF LSA timers\n" | |
7a7be519 | 2336 | "Minimum delay in receiving new version of a LSA\n" |
2337 | "Delay in milliseconds\n") | |
b6927875 | 2338 | { |
a3d826f0 | 2339 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2340 | unsigned int minarrival; |
b6927875 | 2341 | |
d62a17ae | 2342 | if (argc > 4) { |
0e88de35 | 2343 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2344 | |
d62a17ae | 2345 | if (ospf->min_ls_arrival != minarrival |
2346 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2347 | return CMD_SUCCESS; | |
2348 | } | |
b6927875 | 2349 | |
d62a17ae | 2350 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2351 | |
d62a17ae | 2352 | return CMD_SUCCESS; |
b6927875 DS |
2353 | } |
2354 | ||
a2c62831 | 2355 | DEFUN (ospf_neighbor, |
2356 | ospf_neighbor_cmd, | |
7a7be519 | 2357 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2358 | NEIGHBOR_STR |
7a7be519 | 2359 | "Neighbor IP address\n" |
2360 | "Neighbor Priority\n" | |
2361 | "Priority\n" | |
2362 | "Dead Neighbor Polling interval\n" | |
2363 | "Seconds\n") | |
718e3744 | 2364 | { |
a3d826f0 | 2365 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2366 | int idx_ipv4 = 1; |
2367 | int idx_pri = 3; | |
2368 | int idx_poll = 5; | |
2369 | struct in_addr nbr_addr; | |
2370 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2371 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2372 | |
cc9b06ad DS |
2373 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2374 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2375 | return CMD_WARNING_CONFIG_FAILED; | |
2376 | } | |
718e3744 | 2377 | |
d62a17ae | 2378 | if (argc > 2) |
2379 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2380 | |
d62a17ae | 2381 | if (argc > 4) |
2382 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2383 | |
d62a17ae | 2384 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2385 | |
d62a17ae | 2386 | if (argc > 2) |
2387 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2388 | |
d62a17ae | 2389 | if (argc > 4) |
2390 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2391 | |
d62a17ae | 2392 | return CMD_SUCCESS; |
718e3744 | 2393 | } |
2394 | ||
a2c62831 | 2395 | DEFUN (ospf_neighbor_poll_interval, |
2396 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2397 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2398 | NEIGHBOR_STR |
2399 | "Neighbor IP address\n" | |
2400 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2401 | "Seconds\n" |
2402 | "OSPF priority of non-broadcast neighbor\n" | |
2403 | "Priority\n") | |
22b27e95 | 2404 | { |
a3d826f0 | 2405 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2406 | int idx_ipv4 = 1; |
2407 | int idx_poll = 3; | |
2408 | int idx_pri = 5; | |
2409 | struct in_addr nbr_addr; | |
a2b6e694 | 2410 | unsigned int priority; |
2411 | unsigned int interval; | |
718e3744 | 2412 | |
cc9b06ad DS |
2413 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2414 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2415 | return CMD_WARNING_CONFIG_FAILED; | |
2416 | } | |
718e3744 | 2417 | |
d62a17ae | 2418 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2419 | |
a2b6e694 | 2420 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2421 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2422 | |
d62a17ae | 2423 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2424 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2425 | |
d62a17ae | 2426 | if (argc > 4) |
2427 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2428 | |
d62a17ae | 2429 | return CMD_SUCCESS; |
718e3744 | 2430 | } |
2431 | ||
a2c62831 | 2432 | DEFUN (no_ospf_neighbor, |
2433 | no_ospf_neighbor_cmd, | |
7a7be519 | 2434 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2435 | NO_STR |
2436 | NEIGHBOR_STR | |
7a7be519 | 2437 | "Neighbor IP address\n" |
2438 | "Neighbor Priority\n" | |
2439 | "Priority\n" | |
2440 | "Dead Neighbor Polling interval\n" | |
2441 | "Seconds\n") | |
718e3744 | 2442 | { |
a3d826f0 | 2443 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2444 | int idx_ipv4 = 2; |
2445 | struct in_addr nbr_addr; | |
718e3744 | 2446 | |
cc9b06ad DS |
2447 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2448 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2449 | return CMD_WARNING_CONFIG_FAILED; | |
2450 | } | |
718e3744 | 2451 | |
d62a17ae | 2452 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2453 | |
d62a17ae | 2454 | return CMD_SUCCESS; |
718e3744 | 2455 | } |
2456 | ||
7a7be519 | 2457 | DEFUN (no_ospf_neighbor_poll, |
2458 | no_ospf_neighbor_poll_cmd, | |
2459 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2460 | NO_STR | |
2461 | NEIGHBOR_STR | |
2462 | "Neighbor IP address\n" | |
2463 | "Dead Neighbor Polling interval\n" | |
2464 | "Seconds\n" | |
2465 | "Neighbor Priority\n" | |
2466 | "Priority\n") | |
2467 | { | |
a3d826f0 | 2468 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2469 | int idx_ipv4 = 2; |
2470 | struct in_addr nbr_addr; | |
7a7be519 | 2471 | |
cc9b06ad DS |
2472 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2473 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2474 | return CMD_WARNING_CONFIG_FAILED; | |
2475 | } | |
718e3744 | 2476 | |
d62a17ae | 2477 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2478 | |
d62a17ae | 2479 | return CMD_SUCCESS; |
7a7be519 | 2480 | } |
718e3744 | 2481 | |
bf2bfafd DW |
2482 | DEFUN (ospf_refresh_timer, |
2483 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2484 | "refresh timer (10-1800)", |
718e3744 | 2485 | "Adjust refresh parameters\n" |
2486 | "Set refresh timer\n" | |
2487 | "Timer value in seconds\n") | |
2488 | { | |
a3d826f0 | 2489 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2490 | int idx_number = 2; |
2491 | unsigned int interval; | |
7c8ff89e | 2492 | |
d62a17ae | 2493 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2494 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2495 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2496 | |
d62a17ae | 2497 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2498 | |
d62a17ae | 2499 | return CMD_SUCCESS; |
718e3744 | 2500 | } |
2501 | ||
bf2bfafd DW |
2502 | DEFUN (no_ospf_refresh_timer, |
2503 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2504 | "no refresh timer [(10-1800)]", |
3a2d747c | 2505 | NO_STR |
718e3744 | 2506 | "Adjust refresh parameters\n" |
2507 | "Unset refresh timer\n" | |
2508 | "Timer value in seconds\n") | |
2509 | { | |
a3d826f0 | 2510 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2511 | int idx_number = 3; |
2512 | unsigned int interval; | |
718e3744 | 2513 | |
d62a17ae | 2514 | if (argc == 1) { |
2515 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2516 | |
d62a17ae | 2517 | if (ospf->lsa_refresh_interval != interval |
2518 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2519 | return CMD_SUCCESS; | |
2520 | } | |
2521 | ||
2522 | ospf_timers_refresh_unset(ospf); | |
2523 | ||
2524 | return CMD_SUCCESS; | |
718e3744 | 2525 | } |
2526 | ||
718e3744 | 2527 | |
a2c62831 | 2528 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2529 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2530 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2531 | "Calculate OSPF interface cost according to bandwidth\n" |
2532 | "Use reference bandwidth method to assign OSPF cost\n" | |
2533 | "The reference bandwidth in terms of Mbits per second\n") | |
2534 | { | |
a3d826f0 | 2535 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2536 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2537 | int idx_number = 2; |
d7c0a89a | 2538 | uint32_t refbw; |
d62a17ae | 2539 | struct interface *ifp; |
2540 | ||
2541 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2542 | if (refbw < 1 || refbw > 4294967) { | |
2543 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2544 | return CMD_WARNING_CONFIG_FAILED; | |
2545 | } | |
2546 | ||
2547 | /* If reference bandwidth is changed. */ | |
2548 | if ((refbw) == ospf->ref_bandwidth) | |
2549 | return CMD_SUCCESS; | |
2550 | ||
2551 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2552 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2553 | ospf_if_recalculate_output_cost(ifp); |
2554 | ||
2555 | return CMD_SUCCESS; | |
718e3744 | 2556 | } |
2557 | ||
a2c62831 | 2558 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2559 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2560 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2561 | NO_STR |
2562 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2563 | "Use reference bandwidth method to assign OSPF cost\n" |
2564 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2565 | { |
a3d826f0 | 2566 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2567 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2568 | struct interface *ifp; |
718e3744 | 2569 | |
d62a17ae | 2570 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2571 | return CMD_SUCCESS; | |
2572 | ||
2573 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2574 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2575 | vty_out(vty, | |
2576 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2577 | ||
451fda4f | 2578 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2579 | ospf_if_recalculate_output_cost(ifp); |
2580 | ||
2581 | return CMD_SUCCESS; | |
718e3744 | 2582 | } |
2583 | ||
2f8f370e DS |
2584 | DEFUN (ospf_write_multiplier, |
2585 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2586 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2587 | "OSPF specific commands\n" |
2588 | "Write multiplier\n" | |
2589 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2590 | { |
a3d826f0 | 2591 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2592 | int idx_number; |
d7c0a89a | 2593 | uint32_t write_oi_count; |
d62a17ae | 2594 | |
2595 | if (argc == 3) | |
2596 | idx_number = 2; | |
2597 | else | |
2598 | idx_number = 1; | |
2599 | ||
2600 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2601 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2602 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2603 | return CMD_WARNING_CONFIG_FAILED; | |
2604 | } | |
2605 | ||
2606 | ospf->write_oi_count = write_oi_count; | |
2607 | return CMD_SUCCESS; | |
2f8f370e DS |
2608 | } |
2609 | ||
d62a17ae | 2610 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2611 | "Write multiplier\n" | |
2612 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2613 | |
2f8f370e DS |
2614 | DEFUN (no_ospf_write_multiplier, |
2615 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2616 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2617 | NO_STR |
e8f45e82 | 2618 | "OSPF specific commands\n" |
813d4307 DW |
2619 | "Write multiplier\n" |
2620 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2621 | { |
a3d826f0 | 2622 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2623 | |
d62a17ae | 2624 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2625 | return CMD_SUCCESS; | |
2f8f370e DS |
2626 | } |
2627 | ||
d62a17ae | 2628 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2629 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2630 | "Write multiplier\n" |
2631 | "Maximum number of interface serviced per write\n") | |
2632 | ||
2b64873d DL |
2633 | static const char *const ospf_abr_type_descr_str[] = { |
2634 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2635 | "Alternative Cisco", "Alternative Shortcut" | |
2636 | }; | |
d62a17ae | 2637 | |
2b64873d DL |
2638 | static const char *const ospf_shortcut_mode_descr_str[] = { |
2639 | "Default", "Enabled", "Disabled" | |
2640 | }; | |
d62a17ae | 2641 | |
2642 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2643 | json_object *json_areas, bool use_json) |
d62a17ae | 2644 | { |
2645 | json_object *json_area = NULL; | |
2646 | ||
2647 | if (use_json) | |
2648 | json_area = json_object_new_object(); | |
2649 | ||
2650 | /* Show Area ID. */ | |
2651 | if (!use_json) | |
2652 | vty_out(vty, " Area ID: %s", inet_ntoa(area->area_id)); | |
2653 | ||
2654 | /* Show Area type/mode. */ | |
2655 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2656 | if (use_json) | |
2657 | json_object_boolean_true_add(json_area, "backbone"); | |
2658 | else | |
2659 | vty_out(vty, " (Backbone)\n"); | |
2660 | } else { | |
2661 | if (use_json) { | |
2662 | if (area->external_routing == OSPF_AREA_STUB) { | |
2663 | if (area->no_summary) | |
2664 | json_object_boolean_true_add( | |
2665 | json_area, "stubNoSummary"); | |
2666 | if (area->shortcut_configured) | |
2667 | json_object_boolean_true_add( | |
2668 | json_area, "stubShortcut"); | |
2669 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2670 | if (area->no_summary) | |
2671 | json_object_boolean_true_add( | |
2672 | json_area, "nssaNoSummary"); | |
2673 | if (area->shortcut_configured) | |
2674 | json_object_boolean_true_add( | |
2675 | json_area, "nssaShortcut"); | |
2676 | } | |
813d4307 | 2677 | |
d62a17ae | 2678 | json_object_string_add( |
2679 | json_area, "shortcuttingMode", | |
2680 | ospf_shortcut_mode_descr_str | |
2681 | [area->shortcut_configured]); | |
2682 | if (area->shortcut_capability) | |
2683 | json_object_boolean_true_add(json_area, | |
2684 | "sBitConcensus"); | |
2685 | } else { | |
2686 | if (area->external_routing == OSPF_AREA_STUB) | |
2687 | vty_out(vty, " (Stub%s%s)", | |
2688 | area->no_summary ? ", no summary" : "", | |
2689 | area->shortcut_configured ? "; " : ""); | |
2690 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2691 | vty_out(vty, " (NSSA%s%s)", | |
2692 | area->no_summary ? ", no summary" : "", | |
2693 | area->shortcut_configured ? "; " : ""); | |
2694 | ||
2695 | vty_out(vty, "\n"); | |
2696 | vty_out(vty, " Shortcutting mode: %s", | |
2697 | ospf_shortcut_mode_descr_str | |
2698 | [area->shortcut_configured]); | |
2699 | vty_out(vty, ", S-bit consensus: %s\n", | |
2700 | area->shortcut_capability ? "ok" : "no"); | |
2701 | } | |
2702 | } | |
718e3744 | 2703 | |
d62a17ae | 2704 | /* Show number of interfaces */ |
2705 | if (use_json) { | |
2706 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2707 | listcount(area->oiflist)); | |
2708 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2709 | area->act_ints); | |
2710 | } else | |
2711 | vty_out(vty, | |
3efd0893 | 2712 | " Number of interfaces in this area: Total: %d, Active: %d\n", |
d62a17ae | 2713 | listcount(area->oiflist), area->act_ints); |
2714 | ||
2715 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2716 | if (use_json) { | |
2717 | json_object_boolean_true_add(json_area, "nssa"); | |
2718 | if (!IS_OSPF_ABR(area->ospf)) | |
2719 | json_object_boolean_false_add(json_area, "abr"); | |
2720 | else if (area->NSSATranslatorState) { | |
2721 | json_object_boolean_true_add(json_area, "abr"); | |
2722 | if (area->NSSATranslatorRole | |
2723 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2724 | json_object_boolean_true_add( | |
2725 | json_area, | |
2726 | "nssaTranslatorElected"); | |
2727 | else if (area->NSSATranslatorRole | |
2728 | == OSPF_NSSA_ROLE_ALWAYS) | |
2729 | json_object_boolean_true_add( | |
2730 | json_area, | |
2731 | "nssaTranslatorAlways"); | |
2732 | } else { | |
2733 | json_object_boolean_true_add(json_area, "abr"); | |
2734 | if (area->NSSATranslatorRole | |
2735 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2736 | json_object_boolean_false_add( | |
2737 | json_area, | |
2738 | "nssaTranslatorElected"); | |
2739 | else | |
2740 | json_object_boolean_true_add( | |
2741 | json_area, | |
2742 | "nssaTranslatorNever"); | |
2743 | } | |
2744 | } else { | |
2745 | vty_out(vty, | |
2746 | " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n"); | |
2747 | if (!IS_OSPF_ABR(area->ospf)) | |
2748 | vty_out(vty, | |
2749 | " It is not ABR, therefore not Translator. \n"); | |
2750 | else if (area->NSSATranslatorState) { | |
2751 | vty_out(vty, " We are an ABR and "); | |
2752 | if (area->NSSATranslatorRole | |
2753 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2754 | vty_out(vty, | |
2755 | "the NSSA Elected Translator. \n"); | |
2756 | else if (area->NSSATranslatorRole | |
2757 | == OSPF_NSSA_ROLE_ALWAYS) | |
2758 | vty_out(vty, | |
2759 | "always an NSSA Translator. \n"); | |
2760 | } else { | |
2761 | vty_out(vty, " We are an ABR, but "); | |
2762 | if (area->NSSATranslatorRole | |
2763 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2764 | vty_out(vty, | |
2765 | "not the NSSA Elected Translator. \n"); | |
2766 | else | |
2767 | vty_out(vty, | |
2768 | "never an NSSA Translator. \n"); | |
2769 | } | |
2770 | } | |
2771 | } | |
2772 | ||
2773 | /* Stub-router state for this area */ | |
2774 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2775 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2776 | ||
2777 | if (use_json) { | |
2778 | json_object_boolean_true_add( | |
2779 | json_area, "originStubMaxDistRouterLsa"); | |
2780 | if (CHECK_FLAG(area->stub_router_state, | |
2781 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2782 | json_object_boolean_true_add( | |
2783 | json_area, "indefiniteActiveAdmin"); | |
2784 | if (area->t_stub_router) { | |
2785 | long time_store; | |
2786 | time_store = | |
2787 | monotime_until( | |
2788 | &area->t_stub_router->u.sands, | |
2789 | NULL) | |
2790 | / 1000LL; | |
2791 | json_object_int_add( | |
2792 | json_area, | |
2793 | "activeStartupRemainderMsecs", | |
2794 | time_store); | |
2795 | } | |
2796 | } else { | |
2797 | vty_out(vty, | |
2798 | " Originating stub / maximum-distance Router-LSA\n"); | |
2799 | if (CHECK_FLAG(area->stub_router_state, | |
2800 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2801 | vty_out(vty, | |
2802 | " Administratively activated (indefinitely)\n"); | |
2803 | if (area->t_stub_router) | |
2804 | vty_out(vty, | |
2805 | " Active from startup, %s remaining\n", | |
2806 | ospf_timer_dump(area->t_stub_router, | |
2807 | timebuf, | |
2808 | sizeof(timebuf))); | |
2809 | } | |
2810 | } | |
2811 | ||
2812 | if (use_json) { | |
2813 | /* Show number of fully adjacent neighbors. */ | |
2814 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2815 | area->full_nbrs); | |
2816 | ||
2817 | /* Show authentication type. */ | |
2818 | if (area->auth_type == OSPF_AUTH_NULL) | |
2819 | json_object_string_add(json_area, "authentication", | |
2820 | "authenticationNone"); | |
2821 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2822 | json_object_string_add(json_area, "authentication", | |
2823 | "authenticationSimplePassword"); | |
2824 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2825 | json_object_string_add(json_area, "authentication", | |
2826 | "authenticationMessageDigest"); | |
2827 | ||
2828 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2829 | json_object_int_add(json_area, | |
2830 | "virtualAdjacenciesPassingCounter", | |
2831 | area->full_vls); | |
2832 | ||
2833 | /* Show SPF calculation times. */ | |
2834 | json_object_int_add(json_area, "spfExecutedCounter", | |
2835 | area->spf_calculation); | |
2836 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2837 | json_object_int_add( | |
2838 | json_area, "lsaRouterNumber", | |
2839 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2840 | json_object_int_add( | |
2841 | json_area, "lsaRouterChecksum", | |
2842 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2843 | json_object_int_add( | |
2844 | json_area, "lsaNetworkNumber", | |
2845 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2846 | json_object_int_add( | |
2847 | json_area, "lsaNetworkChecksum", | |
2848 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2849 | json_object_int_add( | |
2850 | json_area, "lsaSummaryNumber", | |
2851 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2852 | json_object_int_add( | |
2853 | json_area, "lsaSummaryChecksum", | |
2854 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2855 | json_object_int_add( | |
2856 | json_area, "lsaAsbrNumber", | |
2857 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2858 | json_object_int_add( | |
2859 | json_area, "lsaAsbrChecksum", | |
2860 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2861 | json_object_int_add( | |
2862 | json_area, "lsaNssaNumber", | |
2863 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2864 | json_object_int_add( | |
2865 | json_area, "lsaNssaChecksum", | |
2866 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2867 | } else { | |
2868 | /* Show number of fully adjacent neighbors. */ | |
2869 | vty_out(vty, | |
3efd0893 | 2870 | " Number of fully adjacent neighbors in this area: %d\n", |
d62a17ae | 2871 | area->full_nbrs); |
2872 | ||
2873 | /* Show authentication type. */ | |
2874 | vty_out(vty, " Area has "); | |
2875 | if (area->auth_type == OSPF_AUTH_NULL) | |
2876 | vty_out(vty, "no authentication\n"); | |
2877 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2878 | vty_out(vty, "simple password authentication\n"); | |
2879 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2880 | vty_out(vty, "message digest authentication\n"); | |
2881 | ||
2882 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2883 | vty_out(vty, | |
3efd0893 | 2884 | " Number of full virtual adjacencies going through this area: %d\n", |
d62a17ae | 2885 | area->full_vls); |
2886 | ||
2887 | /* Show SPF calculation times. */ | |
2888 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2889 | area->spf_calculation); | |
2890 | ||
2891 | /* Show number of LSA. */ | |
2892 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2893 | vty_out(vty, | |
2894 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2895 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2896 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2897 | vty_out(vty, | |
2898 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2899 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2900 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2901 | vty_out(vty, | |
2902 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2903 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2904 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2905 | vty_out(vty, | |
2906 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2907 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
2908 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2909 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
2910 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
2911 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2912 | } | |
2913 | ||
2914 | if (use_json) { | |
2915 | json_object_int_add( | |
2916 | json_area, "lsaOpaqueLinkNumber", | |
2917 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2918 | json_object_int_add( | |
2919 | json_area, "lsaOpaqueLinkChecksum", | |
2920 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2921 | json_object_int_add( | |
2922 | json_area, "lsaOpaqueAreaNumber", | |
2923 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2924 | json_object_int_add( | |
2925 | json_area, "lsaOpaqueAreaChecksum", | |
2926 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2927 | } else { | |
2928 | vty_out(vty, | |
2929 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
2930 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
2931 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2932 | vty_out(vty, | |
2933 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
2934 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
2935 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2936 | } | |
718e3744 | 2937 | |
d62a17ae | 2938 | if (use_json) |
2939 | json_object_object_add(json_areas, inet_ntoa(area->area_id), | |
2940 | json_area); | |
2941 | else | |
2942 | vty_out(vty, "\n"); | |
718e3744 | 2943 | } |
2944 | ||
d62a17ae | 2945 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 2946 | json_object *json, uint8_t use_vrf) |
d62a17ae | 2947 | { |
2948 | struct listnode *node, *nnode; | |
2949 | struct ospf_area *area; | |
2950 | struct timeval result; | |
2951 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
b1c3ae8c | 2952 | json_object *json_vrf = NULL; |
d62a17ae | 2953 | json_object *json_areas = NULL; |
718e3744 | 2954 | |
b1c3ae8c CS |
2955 | if (json) { |
2956 | if (use_vrf) | |
2957 | json_vrf = json_object_new_object(); | |
2958 | else | |
2959 | json_vrf = json; | |
d62a17ae | 2960 | json_areas = json_object_new_object(); |
2961 | } | |
2962 | ||
2963 | if (ospf->instance) { | |
b1c3ae8c | 2964 | if (json) { |
d62a17ae | 2965 | json_object_int_add(json, "ospfInstance", |
2966 | ospf->instance); | |
2967 | } else { | |
2968 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
2969 | } | |
2970 | } | |
2971 | ||
b1c3ae8c | 2972 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 2973 | |
d62a17ae | 2974 | /* Show Router ID. */ |
b1c3ae8c CS |
2975 | if (json) { |
2976 | json_object_string_add(json_vrf, "routerId", | |
d62a17ae | 2977 | inet_ntoa(ospf->router_id)); |
2978 | } else { | |
2979 | vty_out(vty, " OSPF Routing Process, Router ID: %s\n", | |
2980 | inet_ntoa(ospf->router_id)); | |
2981 | } | |
2982 | ||
2983 | /* Graceful shutdown */ | |
2984 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 2985 | if (json) { |
d62a17ae | 2986 | long time_store; |
2987 | time_store = | |
2988 | monotime_until( | |
2989 | &ospf->t_deferred_shutdown->u.sands, | |
2990 | NULL) | |
2991 | / 1000LL; | |
b1c3ae8c | 2992 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 2993 | time_store); |
2994 | } else { | |
2995 | vty_out(vty, | |
2996 | " Deferred shutdown in progress, %s remaining\n", | |
2997 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
2998 | timebuf, sizeof(timebuf))); | |
2999 | } | |
3000 | } | |
3001 | ||
3002 | /* Show capability. */ | |
b1c3ae8c CS |
3003 | if (json) { |
3004 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
3005 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 3006 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 3007 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3008 | "rfc1583Compatibility"); |
3009 | } | |
3010 | } else { | |
3011 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3012 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3013 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3014 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3015 | ? "enabled" | |
3016 | : "disabled"); | |
3017 | } | |
3018 | ||
b1c3ae8c | 3019 | if (json) { |
d62a17ae | 3020 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3021 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3022 | } |
3023 | } else { | |
3024 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3025 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3026 | ? "enabled" | |
3027 | : "disabled"); | |
3028 | } | |
3029 | ||
3030 | /* Show stub-router configuration */ | |
3031 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3032 | || ospf->stub_router_shutdown_time | |
3033 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3034 | if (json) { |
3035 | json_object_boolean_true_add(json_vrf, | |
3036 | "stubAdvertisement"); | |
d62a17ae | 3037 | if (ospf->stub_router_startup_time |
3038 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3039 | json_object_int_add( | |
50ad4b42 MS |
3040 | json_vrf, "postStartEnabledSecs", |
3041 | ospf->stub_router_startup_time); | |
d62a17ae | 3042 | if (ospf->stub_router_shutdown_time |
3043 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3044 | json_object_int_add( | |
50ad4b42 MS |
3045 | json_vrf, "preShutdownEnabledSecs", |
3046 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3047 | } else { |
3048 | vty_out(vty, | |
3049 | " Stub router advertisement is configured\n"); | |
3050 | if (ospf->stub_router_startup_time | |
3051 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3052 | vty_out(vty, | |
3053 | " Enabled for %us after start-up\n", | |
3054 | ospf->stub_router_startup_time); | |
3055 | if (ospf->stub_router_shutdown_time | |
3056 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3057 | vty_out(vty, | |
3058 | " Enabled for %us prior to full shutdown\n", | |
3059 | ospf->stub_router_shutdown_time); | |
3060 | } | |
3061 | } | |
3062 | ||
3063 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3064 | if (json) { |
3065 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3066 | ospf->spf_delay); |
b1c3ae8c | 3067 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3068 | ospf->spf_holdtime); |
b1c3ae8c | 3069 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3070 | ospf->spf_max_holdtime); |
b1c3ae8c | 3071 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3072 | ospf->spf_hold_multiplier); |
3073 | } else { | |
3074 | vty_out(vty, | |
3075 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3076 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3077 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3078 | " Hold time multiplier is currently %d\n", | |
3079 | ospf->spf_delay, ospf->spf_holdtime, | |
3080 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3081 | } | |
3082 | ||
b1c3ae8c | 3083 | if (json) { |
d62a17ae | 3084 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3085 | long time_store = 0; | |
3086 | ||
3087 | time_store = | |
3088 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3089 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3090 | time_store); |
3091 | ||
3092 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3093 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3094 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3095 | time_store); |
3096 | } else | |
b1c3ae8c | 3097 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3098 | } else { |
3099 | vty_out(vty, " SPF algorithm "); | |
3100 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3101 | monotime_since(&ospf->ts_spf, &result); | |
3102 | vty_out(vty, "last executed %s ago\n", | |
3103 | ospf_timeval_dump(&result, timebuf, | |
3104 | sizeof(timebuf))); | |
3105 | vty_out(vty, " Last SPF duration %s\n", | |
3106 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3107 | timebuf, sizeof(timebuf))); | |
3108 | } else | |
3109 | vty_out(vty, "has not been run\n"); | |
3110 | } | |
3111 | ||
b1c3ae8c | 3112 | if (json) { |
d62a17ae | 3113 | if (ospf->t_spf_calc) { |
3114 | long time_store; | |
3115 | time_store = | |
3116 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3117 | / 1000LL; | |
b1c3ae8c | 3118 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3119 | time_store); |
3120 | } | |
3121 | ||
b1c3ae8c | 3122 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3123 | ospf->min_ls_interval); |
b1c3ae8c | 3124 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3125 | ospf->min_ls_arrival); |
3126 | /* Show write multiplier values */ | |
b1c3ae8c | 3127 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3128 | ospf->write_oi_count); |
3129 | /* Show refresh parameters. */ | |
b1c3ae8c | 3130 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3131 | ospf->lsa_refresh_interval * 1000); |
3132 | } else { | |
3133 | vty_out(vty, " SPF timer %s%s\n", | |
3134 | (ospf->t_spf_calc ? "due in " : "is "), | |
3135 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3136 | sizeof(timebuf))); | |
3137 | ||
3138 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3139 | ospf->min_ls_interval); | |
3140 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3141 | ospf->min_ls_arrival); | |
3142 | ||
3143 | /* Show write multiplier values */ | |
3144 | vty_out(vty, " Write Multiplier set to %d \n", | |
3145 | ospf->write_oi_count); | |
3146 | ||
3147 | /* Show refresh parameters. */ | |
3148 | vty_out(vty, " Refresh timer %d secs\n", | |
3149 | ospf->lsa_refresh_interval); | |
3150 | } | |
3151 | ||
3152 | /* Show ABR/ASBR flags. */ | |
3153 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3154 | if (json) |
d62a17ae | 3155 | json_object_string_add( |
b1c3ae8c | 3156 | json_vrf, "abrType", |
d62a17ae | 3157 | ospf_abr_type_descr_str[ospf->abr_type]); |
3158 | else | |
3159 | vty_out(vty, | |
3160 | " This router is an ABR, ABR type is: %s\n", | |
3161 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3162 | } | |
3163 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3164 | if (json) |
d62a17ae | 3165 | json_object_string_add( |
b1c3ae8c | 3166 | json_vrf, "asbrRouter", |
d62a17ae | 3167 | "injectingExternalRoutingInformation"); |
3168 | else | |
3169 | vty_out(vty, | |
3efd0893 | 3170 | " This router is an ASBR (injecting external routing information)\n"); |
d62a17ae | 3171 | } |
3172 | ||
3173 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3174 | if (json) { |
d62a17ae | 3175 | json_object_int_add( |
b1c3ae8c | 3176 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3177 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3178 | json_object_int_add( | |
b1c3ae8c | 3179 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3180 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3181 | } else { | |
3182 | vty_out(vty, | |
3183 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3184 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3185 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3186 | } | |
3187 | ||
b1c3ae8c | 3188 | if (json) { |
d62a17ae | 3189 | json_object_int_add( |
b1c3ae8c | 3190 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3191 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3192 | json_object_int_add( | |
b1c3ae8c | 3193 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3194 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3195 | } else { | |
3196 | vty_out(vty, | |
3197 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3198 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3199 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3200 | } | |
3201 | ||
3202 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3203 | if (json) |
3204 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3205 | listcount(ospf->areas)); |
3206 | else | |
3207 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3208 | listcount(ospf->areas)); | |
3209 | ||
3210 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3211 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3212 | if (json) |
d62a17ae | 3213 | json_object_boolean_true_add( |
b1c3ae8c | 3214 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3215 | else |
3216 | vty_out(vty, | |
3217 | " All adjacency changes are logged\n"); | |
3218 | } else { | |
b1c3ae8c | 3219 | if (json) |
d62a17ae | 3220 | json_object_boolean_true_add( |
b1c3ae8c | 3221 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3222 | else |
3223 | vty_out(vty, " Adjacency changes are logged\n"); | |
3224 | } | |
3225 | } | |
132a782e | 3226 | |
3227 | /* show LDP-Sync status */ | |
3228 | ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0); | |
3229 | ||
d62a17ae | 3230 | /* Show each area status. */ |
3231 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3232 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3233 | ||
3234 | if (json) { | |
3235 | if (use_vrf) { | |
3236 | json_object_object_add(json_vrf, "areas", json_areas); | |
3237 | if (ospf->vrf_id == VRF_DEFAULT) | |
3238 | json_object_object_add(json, "default", | |
3239 | json_vrf); | |
3240 | else | |
3241 | json_object_object_add(json, ospf->name, | |
3242 | json_vrf); | |
3243 | } else { | |
3244 | json_object_object_add(json, "areas", json_areas); | |
3245 | } | |
d62a17ae | 3246 | } else |
3247 | vty_out(vty, "\n"); | |
3248 | ||
3249 | return CMD_SUCCESS; | |
718e3744 | 3250 | } |
3251 | ||
7c8ff89e DS |
3252 | DEFUN (show_ip_ospf, |
3253 | show_ip_ospf_cmd, | |
b5a8894d | 3254 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3255 | SHOW_STR |
3256 | IP_STR | |
ca08c43d | 3257 | "OSPF information\n" |
b5a8894d CS |
3258 | VRF_CMD_HELP_STR |
3259 | "All VRFs\n" | |
9973d184 | 3260 | JSON_STR) |
7c8ff89e | 3261 | { |
d62a17ae | 3262 | struct ospf *ospf; |
9f049418 | 3263 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3264 | struct listnode *node = NULL; |
3265 | char *vrf_name = NULL; | |
2951a7a4 | 3266 | bool all_vrf = false; |
b5a8894d CS |
3267 | int ret = CMD_SUCCESS; |
3268 | int inst = 0; | |
3269 | int idx_vrf = 0; | |
b1c3ae8c | 3270 | json_object *json = NULL; |
d7c0a89a | 3271 | uint8_t use_vrf = 0; |
7c8ff89e | 3272 | |
b5a8894d | 3273 | if (listcount(om->ospf) == 0) |
d62a17ae | 3274 | return CMD_SUCCESS; |
7c8ff89e | 3275 | |
43b8d1d8 | 3276 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3277 | |
b1c3ae8c CS |
3278 | if (uj) |
3279 | json = json_object_new_object(); | |
3280 | ||
996c9314 | 3281 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3282 | if (vrf_name) { |
2951a7a4 | 3283 | bool ospf_output = false; |
874f58d8 | 3284 | |
b1c3ae8c | 3285 | use_vrf = 1; |
94d4c685 | 3286 | |
b5a8894d CS |
3287 | if (all_vrf) { |
3288 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3289 | if (!ospf->oi_running) | |
3290 | continue; | |
2951a7a4 | 3291 | ospf_output = true; |
b1c3ae8c CS |
3292 | ret = show_ip_ospf_common(vty, ospf, json, |
3293 | use_vrf); | |
3294 | } | |
3295 | if (uj) { | |
3296 | vty_out(vty, "%s\n", | |
996c9314 LB |
3297 | json_object_to_json_string_ext( |
3298 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3299 | json_object_free(json); |
9f049418 DS |
3300 | } else if (!ospf_output) |
3301 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
3302 | return ret; |
3303 | } | |
3304 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3305 | if ((ospf == NULL) || !ospf->oi_running) { |
9f049418 DS |
3306 | if (uj) { |
3307 | vty_out(vty, "%s\n", | |
3308 | json_object_to_json_string_ext( | |
3309 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3310 | json_object_free(json); |
9f049418 | 3311 | } else |
94d4c685 | 3312 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3313 | |
b5a8894d | 3314 | return CMD_SUCCESS; |
b1c3ae8c | 3315 | } |
b5a8894d CS |
3316 | } else { |
3317 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3318 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3319 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3320 | if (uj) { |
3321 | vty_out(vty, "%s\n", | |
3322 | json_object_to_json_string_ext( | |
3323 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3324 | json_object_free(json); |
9f049418 | 3325 | } else |
94d4c685 | 3326 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3327 | |
b5a8894d | 3328 | return CMD_SUCCESS; |
b1c3ae8c | 3329 | } |
b5a8894d CS |
3330 | } |
3331 | ||
996c9314 | 3332 | if (ospf) { |
b1c3ae8c CS |
3333 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3334 | if (uj) | |
996c9314 LB |
3335 | vty_out(vty, "%s\n", |
3336 | json_object_to_json_string_ext( | |
3337 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3338 | } |
3339 | ||
3340 | if (uj) | |
3341 | json_object_free(json); | |
b5a8894d CS |
3342 | |
3343 | return ret; | |
7c8ff89e DS |
3344 | } |
3345 | ||
3346 | DEFUN (show_ip_ospf_instance, | |
3347 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3348 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3349 | SHOW_STR |
3350 | IP_STR | |
3351 | "OSPF information\n" | |
ca08c43d | 3352 | "Instance ID\n" |
9973d184 | 3353 | JSON_STR) |
7c8ff89e | 3354 | { |
d62a17ae | 3355 | int idx_number = 3; |
3356 | struct ospf *ospf; | |
d7c0a89a | 3357 | unsigned short instance = 0; |
9f049418 | 3358 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3359 | int ret = CMD_SUCCESS; |
3360 | json_object *json = NULL; | |
d62a17ae | 3361 | |
3362 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3363 | ospf = ospf_lookup_instance(instance); |
3364 | if (ospf == NULL) | |
3365 | return CMD_NOT_MY_INSTANCE; | |
3366 | ||
3367 | if (!ospf->oi_running) | |
d62a17ae | 3368 | return CMD_SUCCESS; |
3369 | ||
b1c3ae8c CS |
3370 | if (uj) |
3371 | json = json_object_new_object(); | |
3372 | ||
3373 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3374 | ||
3375 | if (uj) { | |
996c9314 LB |
3376 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3377 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3378 | json_object_free(json); |
3379 | } | |
3380 | ||
3381 | return ret; | |
d62a17ae | 3382 | } |
3383 | ||
3384 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, | |
3385 | struct interface *ifp, | |
3386 | json_object *json_interface_sub, | |
9f049418 | 3387 | bool use_json) |
d62a17ae | 3388 | { |
3389 | int is_up; | |
3390 | struct ospf_neighbor *nbr; | |
3391 | struct route_node *rn; | |
3392 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; | |
3393 | ||
3394 | /* Is interface up? */ | |
3395 | if (use_json) { | |
3396 | is_up = if_is_operative(ifp); | |
3397 | if (is_up) | |
3398 | json_object_boolean_true_add(json_interface_sub, | |
3399 | "ifUp"); | |
3400 | else | |
3401 | json_object_boolean_false_add(json_interface_sub, | |
3402 | "ifDown"); | |
3403 | ||
3404 | json_object_int_add(json_interface_sub, "ifIndex", | |
3405 | ifp->ifindex); | |
3406 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3407 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3408 | bandwidth); | |
3409 | json_object_string_add(json_interface_sub, "ifFlags", | |
3410 | if_flag_dump(ifp->flags)); | |
3411 | } else { | |
3412 | vty_out(vty, "%s is %s\n", ifp->name, | |
3413 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3414 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3415 | ifp->ifindex, ifp->mtu, bandwidth, | |
3416 | if_flag_dump(ifp->flags)); | |
3417 | } | |
7c8ff89e | 3418 | |
d62a17ae | 3419 | /* Is interface OSPF enabled? */ |
3420 | if (use_json) { | |
3421 | if (ospf_oi_count(ifp) == 0) { | |
3422 | json_object_boolean_false_add(json_interface_sub, | |
3423 | "ospfEnabled"); | |
3424 | return; | |
3425 | } else if (!is_up) { | |
3426 | json_object_boolean_false_add(json_interface_sub, | |
3427 | "ospfRunning"); | |
3428 | return; | |
3429 | } else | |
3430 | json_object_boolean_true_add(json_interface_sub, | |
3431 | "ospfEnabled"); | |
3432 | } else { | |
3433 | if (ospf_oi_count(ifp) == 0) { | |
3434 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3435 | return; | |
3436 | } else if (!is_up) { | |
3437 | vty_out(vty, | |
3438 | " OSPF is enabled, but not running on this interface\n"); | |
3439 | return; | |
3440 | } | |
3441 | } | |
3442 | ||
3443 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3444 | struct ospf_interface *oi = rn->info; | |
3445 | ||
3446 | if (oi == NULL) | |
3447 | continue; | |
3448 | ||
3449 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3450 | if (use_json) | |
3451 | json_object_boolean_true_add(json_interface_sub, | |
3452 | "ifUnnumbered"); | |
3453 | else | |
3454 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3455 | } else { | |
0f3af738 JW |
3456 | struct in_addr dest; |
3457 | const char *dstr; | |
3458 | ||
d62a17ae | 3459 | /* Show OSPF interface information. */ |
3460 | if (use_json) { | |
3461 | json_object_string_add( | |
3462 | json_interface_sub, "ipAddress", | |
3463 | inet_ntoa(oi->address->u.prefix4)); | |
3464 | json_object_int_add(json_interface_sub, | |
3465 | "ipAddressPrefixlen", | |
3466 | oi->address->prefixlen); | |
3467 | } else | |
3468 | vty_out(vty, " Internet Address %s/%d,", | |
3469 | inet_ntoa(oi->address->u.prefix4), | |
3470 | oi->address->prefixlen); | |
3471 | ||
0f3af738 JW |
3472 | /* For Vlinks, showing the peer address is |
3473 | * probably more informative than the local | |
3474 | * interface that is being used */ | |
3475 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3476 | dstr = "Peer"; | |
3477 | dest = oi->vl_data->peer_addr; | |
3478 | } else if (CONNECTED_PEER(oi->connected) | |
3479 | && oi->connected->destination) { | |
3480 | dstr = "Peer"; | |
3481 | dest = oi->connected->destination->u.prefix4; | |
3482 | } else { | |
3483 | dstr = "Broadcast"; | |
3484 | dest.s_addr = ipv4_broadcast_addr( | |
3485 | oi->connected->address->u.prefix4.s_addr, | |
3486 | oi->connected->address->prefixlen); | |
3487 | } | |
d62a17ae | 3488 | |
0f3af738 JW |
3489 | if (use_json) { |
3490 | json_object_string_add( | |
3491 | json_interface_sub, | |
3492 | "ospfIfType", dstr); | |
d62a17ae | 3493 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
0f3af738 JW |
3494 | json_object_string_add( |
3495 | json_interface_sub, | |
3496 | "vlinkPeer", | |
3497 | inet_ntoa(dest)); | |
d62a17ae | 3498 | else |
d62a17ae | 3499 | json_object_string_add( |
3500 | json_interface_sub, | |
0f3af738 JW |
3501 | "localIfUsed", |
3502 | inet_ntoa(dest)); | |
3503 | } else | |
3504 | vty_out(vty, " %s %s,", dstr, | |
3505 | inet_ntoa(dest)); | |
d62a17ae | 3506 | } |
3507 | if (use_json) { | |
3508 | json_object_string_add(json_interface_sub, "area", | |
3509 | ospf_area_desc_string(oi->area)); | |
3510 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3511 | json_object_boolean_true_add( | |
3512 | json_interface_sub, | |
3513 | "mtuMismatchDetect"); | |
3514 | json_object_string_add(json_interface_sub, "routerId", | |
3515 | inet_ntoa(ospf->router_id)); | |
3516 | json_object_string_add(json_interface_sub, | |
3517 | "networkType", | |
3518 | ospf_network_type_str[oi->type]); | |
3519 | json_object_int_add(json_interface_sub, "cost", | |
3520 | oi->output_cost); | |
3521 | json_object_int_add( | |
50ad4b42 MS |
3522 | json_interface_sub, "transmitDelaySecs", |
3523 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3524 | json_object_string_add(json_interface_sub, "state", |
3525 | lookup_msg(ospf_ism_state_msg, | |
3526 | oi->state, NULL)); | |
3527 | json_object_int_add(json_interface_sub, "priority", | |
3528 | PRIORITY(oi)); | |
3529 | } else { | |
3530 | vty_out(vty, " Area %s\n", | |
3531 | ospf_area_desc_string(oi->area)); | |
3532 | ||
3533 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3534 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3535 | : "enabled"); | |
3536 | ||
3537 | vty_out(vty, | |
3538 | " Router ID %s, Network Type %s, Cost: %d\n", | |
3539 | inet_ntoa(ospf->router_id), | |
3540 | ospf_network_type_str[oi->type], | |
3541 | oi->output_cost); | |
3542 | ||
3543 | vty_out(vty, | |
3544 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3545 | OSPF_IF_PARAM(oi, transmit_delay), | |
3546 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3547 | PRIORITY(oi)); | |
3548 | } | |
3549 | ||
3550 | /* Show DR information. */ | |
975a328e | 3551 | if (DR(oi).s_addr == INADDR_ANY) { |
d62a17ae | 3552 | if (!use_json) |
3553 | vty_out(vty, | |
3554 | " No backup designated router on this network\n"); | |
3555 | } else { | |
3556 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3557 | if (nbr == NULL) { | |
3558 | if (!use_json) | |
3559 | vty_out(vty, | |
3560 | " No backup designated router on this network\n"); | |
3561 | } else { | |
3562 | if (use_json) { | |
3563 | json_object_string_add( | |
3564 | json_interface_sub, "bdrId", | |
3565 | inet_ntoa(nbr->router_id)); | |
3566 | json_object_string_add( | |
3567 | json_interface_sub, | |
3568 | "bdrAddress", | |
3569 | inet_ntoa(nbr->address.u | |
3570 | .prefix4)); | |
3571 | } else { | |
3572 | vty_out(vty, | |
3573 | " Backup Designated Router (ID) %s,", | |
3574 | inet_ntoa(nbr->router_id)); | |
3575 | vty_out(vty, " Interface Address %s\n", | |
3576 | inet_ntoa(nbr->address.u | |
3577 | .prefix4)); | |
3578 | } | |
3579 | } | |
3580 | } | |
3581 | ||
3582 | /* Next network-LSA sequence number we'll use, if we're elected | |
3583 | * DR */ | |
3584 | if (oi->params | |
3585 | && ntohl(oi->params->network_lsa_seqnum) | |
3586 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3587 | if (use_json) | |
3588 | json_object_int_add( | |
3589 | json_interface_sub, | |
3590 | "networkLsaSequence", | |
3591 | ntohl(oi->params->network_lsa_seqnum)); | |
3592 | else | |
3593 | vty_out(vty, | |
3594 | " Saved Network-LSA sequence number 0x%x\n", | |
3595 | ntohl(oi->params->network_lsa_seqnum)); | |
3596 | } | |
3597 | ||
3598 | if (use_json) { | |
3599 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3600 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3601 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3602 | json_object_boolean_true_add( | |
3603 | json_interface_sub, | |
3604 | "mcastMemberOspfAllRouters"); | |
3605 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3606 | json_object_boolean_true_add( | |
3607 | json_interface_sub, | |
3608 | "mcastMemberOspfDesignatedRouters"); | |
3609 | } | |
3610 | } else { | |
3611 | vty_out(vty, " Multicast group memberships:"); | |
3612 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3613 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3614 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3615 | vty_out(vty, " OSPFAllRouters"); | |
3616 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3617 | vty_out(vty, " OSPFDesignatedRouters"); | |
3618 | } else | |
3619 | vty_out(vty, " <None>"); | |
3620 | vty_out(vty, "\n"); | |
3621 | } | |
3622 | ||
3623 | if (use_json) { | |
3624 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3625 | json_object_int_add( | |
3626 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3627 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3628 | else |
3629 | json_object_int_add( | |
3630 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3631 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3632 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3633 | "timerDeadSecs", |
3634 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3635 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3636 | "timerWaitSecs", |
3637 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3638 | json_object_int_add( |
50ad4b42 MS |
3639 | json_interface_sub, "timerRetransmitSecs", |
3640 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3641 | } else { |
3642 | vty_out(vty, " Timer intervals configured,"); | |
3643 | vty_out(vty, " Hello "); | |
3644 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3645 | vty_out(vty, "%ds,", | |
3646 | OSPF_IF_PARAM(oi, v_hello)); | |
3647 | else | |
3648 | vty_out(vty, "%dms,", | |
3649 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3650 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3651 | OSPF_IF_PARAM(oi, v_wait), | |
3652 | OSPF_IF_PARAM(oi, v_wait), | |
3653 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3654 | } | |
3655 | ||
3656 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3657 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3658 | if (use_json) { | |
3659 | long time_store = 0; | |
3660 | if (oi->t_hello) | |
3661 | time_store = | |
3662 | monotime_until( | |
3663 | &oi->t_hello->u.sands, | |
3664 | NULL) | |
3665 | / 1000LL; | |
3666 | json_object_int_add(json_interface_sub, | |
3667 | "timerHelloInMsecs", | |
3668 | time_store); | |
3669 | } else | |
3670 | vty_out(vty, " Hello due in %s\n", | |
3671 | ospf_timer_dump(oi->t_hello, timebuf, | |
3672 | sizeof(timebuf))); | |
3673 | } else /* passive-interface is set */ | |
3674 | { | |
3675 | if (use_json) | |
3676 | json_object_boolean_true_add( | |
3677 | json_interface_sub, | |
3678 | "timerPassiveIface"); | |
3679 | else | |
3680 | vty_out(vty, | |
3681 | " No Hellos (Passive interface)\n"); | |
3682 | } | |
7c8ff89e | 3683 | |
d62a17ae | 3684 | if (use_json) { |
3685 | json_object_int_add(json_interface_sub, "nbrCount", | |
3686 | ospf_nbr_count(oi, 0)); | |
3687 | json_object_int_add(json_interface_sub, | |
3688 | "nbrAdjacentCount", | |
3689 | ospf_nbr_count(oi, NSM_Full)); | |
3690 | } else | |
3691 | vty_out(vty, | |
3692 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3693 | ospf_nbr_count(oi, 0), | |
3694 | ospf_nbr_count(oi, NSM_Full)); | |
3695 | ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json); | |
3696 | } | |
718e3744 | 3697 | } |
3698 | ||
d62a17ae | 3699 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3700 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3701 | json_object *json, bool use_json) |
d62a17ae | 3702 | { |
3703 | struct interface *ifp; | |
f4e14fdb | 3704 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3705 | json_object *json_vrf = NULL; |
7dab10ce | 3706 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3707 | |
d62a17ae | 3708 | if (use_json) { |
b1c3ae8c CS |
3709 | if (use_vrf) |
3710 | json_vrf = json_object_new_object(); | |
3711 | else | |
3712 | json_vrf = json; | |
6282e124 | 3713 | json_interface = json_object_new_object(); |
d62a17ae | 3714 | } |
3715 | ||
3716 | if (ospf->instance) { | |
3717 | if (use_json) | |
3718 | json_object_int_add(json, "ospfInstance", | |
3719 | ospf->instance); | |
3720 | else | |
3721 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3722 | } | |
3723 | ||
b1c3ae8c CS |
3724 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3725 | ||
3726 | if (intf_name == NULL) { | |
d62a17ae | 3727 | /* Show All Interfaces.*/ |
451fda4f | 3728 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3729 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3730 | if (use_json) { |
d62a17ae | 3731 | json_interface_sub = |
3732 | json_object_new_object(); | |
7dab10ce | 3733 | } |
d62a17ae | 3734 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3735 | json_interface_sub, | |
3736 | use_json); | |
3737 | ||
7dab10ce | 3738 | if (use_json) { |
d62a17ae | 3739 | json_object_object_add( |
7dab10ce | 3740 | json_interface, ifp->name, |
d62a17ae | 3741 | json_interface_sub); |
7dab10ce | 3742 | } |
d62a17ae | 3743 | } |
3744 | } | |
6282e124 CS |
3745 | if (use_json) |
3746 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3747 | json_interface); |
d62a17ae | 3748 | } else { |
3749 | /* Interface name is specified. */ | |
a36898e7 | 3750 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3751 | if (ifp == NULL) { |
d62a17ae | 3752 | if (use_json) |
b1c3ae8c | 3753 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3754 | "noSuchIface"); |
3755 | else | |
3756 | vty_out(vty, "No such interface name\n"); | |
3757 | } else { | |
7dab10ce | 3758 | if (use_json) { |
d62a17ae | 3759 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3760 | json_interface = json_object_new_object(); |
7dab10ce | 3761 | } |
d62a17ae | 3762 | |
3763 | show_ip_ospf_interface_sub( | |
3764 | vty, ospf, ifp, json_interface_sub, use_json); | |
3765 | ||
7dab10ce | 3766 | if (use_json) { |
7dab10ce CS |
3767 | json_object_object_add(json_interface, |
3768 | ifp->name, | |
d62a17ae | 3769 | json_interface_sub); |
6282e124 CS |
3770 | json_object_object_add(json_vrf, "interfaces", |
3771 | json_interface); | |
7dab10ce | 3772 | } |
d62a17ae | 3773 | } |
3774 | } | |
3775 | ||
3776 | if (use_json) { | |
b1c3ae8c CS |
3777 | if (use_vrf) { |
3778 | if (ospf->vrf_id == VRF_DEFAULT) | |
3779 | json_object_object_add(json, "default", | |
3780 | json_vrf); | |
3781 | else | |
3782 | json_object_object_add(json, ospf->name, | |
3783 | json_vrf); | |
3784 | } | |
d62a17ae | 3785 | } else |
3786 | vty_out(vty, "\n"); | |
3787 | ||
3788 | return CMD_SUCCESS; | |
718e3744 | 3789 | } |
3790 | ||
c9339663 CS |
3791 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3792 | struct ospf_interface *oi, | |
3793 | json_object *json_interface_sub, | |
9f049418 | 3794 | bool use_json) |
c9339663 CS |
3795 | { |
3796 | if (use_json) { | |
996c9314 LB |
3797 | json_object_int_add(json_interface_sub, "ifIndex", |
3798 | oi->ifp->ifindex); | |
3799 | json_object_int_add(json_interface_sub, "helloIn", | |
3800 | oi->hello_in); | |
3801 | json_object_int_add(json_interface_sub, "helloOut", | |
3802 | oi->hello_out); | |
3803 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3804 | oi->db_desc_in); | |
3805 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3806 | oi->db_desc_out); | |
3807 | json_object_int_add(json_interface_sub, "lsReqIn", | |
3808 | oi->ls_req_in); | |
3809 | json_object_int_add(json_interface_sub, "lsReqOut", | |
3810 | oi->ls_req_out); | |
3811 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
3812 | oi->ls_upd_in); | |
3813 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
3814 | oi->ls_upd_out); | |
3815 | json_object_int_add(json_interface_sub, "lsAckIn", | |
3816 | oi->ls_ack_in); | |
3817 | json_object_int_add(json_interface_sub, "lsAckOut", | |
3818 | oi->ls_ack_out); | |
c9339663 CS |
3819 | } else { |
3820 | vty_out(vty, | |
3821 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
3822 | oi->ifp->name, oi->hello_in, oi->hello_out, |
3823 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
3824 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
3825 | oi->ls_ack_in, oi->ls_ack_out); |
3826 | } | |
3827 | } | |
3828 | ||
3829 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
3830 | static int show_ip_ospf_interface_traffic_common( |
3831 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 3832 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
3833 | { |
3834 | struct vrf *vrf = NULL; | |
3835 | struct interface *ifp = NULL; | |
b1c3ae8c | 3836 | json_object *json_vrf = NULL; |
c9339663 CS |
3837 | json_object *json_interface_sub = NULL; |
3838 | ||
3839 | if (!use_json && !display_once) { | |
3840 | vty_out(vty, "\n"); | |
996c9314 LB |
3841 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
3842 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
3843 | " LS-Ack"); | |
c9339663 | 3844 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
3845 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
3846 | " Rx/Tx"); | |
c9339663 | 3847 | vty_out(vty, |
996c9314 | 3848 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 3849 | } else if (use_json) { |
b1c3ae8c CS |
3850 | if (use_vrf) |
3851 | json_vrf = json_object_new_object(); | |
3852 | else | |
3853 | json_vrf = json; | |
c9339663 CS |
3854 | } |
3855 | ||
b1c3ae8c CS |
3856 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3857 | ||
c9339663 CS |
3858 | if (intf_name == NULL) { |
3859 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
3860 | FOR_ALL_INTERFACES (vrf, ifp) { | |
3861 | struct route_node *rn; | |
3862 | struct ospf_interface *oi; | |
3863 | ||
3864 | if (ospf_oi_count(ifp) == 0) | |
3865 | continue; | |
3866 | ||
3867 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 3868 | rn = route_next(rn)) { |
c9339663 CS |
3869 | oi = rn->info; |
3870 | ||
3871 | if (oi == NULL) | |
3872 | continue; | |
3873 | ||
3874 | if (use_json) { | |
3875 | json_interface_sub = | |
3876 | json_object_new_object(); | |
3877 | } | |
3878 | ||
996c9314 LB |
3879 | show_ip_ospf_interface_traffic_sub( |
3880 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 3881 | if (use_json) { |
996c9314 LB |
3882 | json_object_object_add( |
3883 | json_vrf, ifp->name, | |
3884 | json_interface_sub); | |
c9339663 CS |
3885 | } |
3886 | } | |
3887 | } | |
3888 | } else { | |
3889 | /* Interface name is specified. */ | |
a36898e7 | 3890 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
3891 | if (ifp != NULL) { |
3892 | struct route_node *rn; | |
3893 | struct ospf_interface *oi; | |
3894 | ||
3895 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
3896 | vty_out(vty, |
3897 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
3898 | ifp->name); |
3899 | return CMD_SUCCESS; | |
3900 | } | |
3901 | ||
3902 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3903 | rn = route_next(rn)) { | |
3904 | oi = rn->info; | |
3905 | ||
3906 | if (use_json) { | |
3907 | json_interface_sub = | |
3908 | json_object_new_object(); | |
3909 | } | |
3910 | ||
996c9314 LB |
3911 | show_ip_ospf_interface_traffic_sub( |
3912 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 3913 | if (use_json) { |
996c9314 LB |
3914 | json_object_object_add( |
3915 | json_vrf, ifp->name, | |
3916 | json_interface_sub); | |
c9339663 CS |
3917 | } |
3918 | } | |
3919 | } | |
3920 | } | |
3921 | ||
3922 | if (use_json) { | |
b1c3ae8c CS |
3923 | if (use_vrf) { |
3924 | if (ospf->vrf_id == VRF_DEFAULT) | |
3925 | json_object_object_add(json, "default", | |
3926 | json_vrf); | |
3927 | else | |
3928 | json_object_object_add(json, ospf->name, | |
3929 | json_vrf); | |
3930 | } | |
3931 | } else | |
3932 | vty_out(vty, "\n"); | |
c9339663 CS |
3933 | |
3934 | return CMD_SUCCESS; | |
3935 | } | |
3936 | ||
7c8ff89e DS |
3937 | DEFUN (show_ip_ospf_interface, |
3938 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 3939 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
3940 | SHOW_STR |
3941 | IP_STR | |
3942 | "OSPF information\n" | |
b5a8894d | 3943 | VRF_CMD_HELP_STR |
43b8d1d8 | 3944 | "All VRFs\n" |
7c8ff89e | 3945 | "Interface information\n" |
7ec4159b | 3946 | "Interface name\n" |
9973d184 | 3947 | JSON_STR) |
7c8ff89e | 3948 | { |
d62a17ae | 3949 | struct ospf *ospf; |
9f049418 | 3950 | bool uj = use_json(argc, argv); |
b5a8894d | 3951 | struct listnode *node = NULL; |
b1c3ae8c | 3952 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 3953 | bool all_vrf = false; |
b5a8894d CS |
3954 | int ret = CMD_SUCCESS; |
3955 | int inst = 0; | |
b1c3ae8c | 3956 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 3957 | uint8_t use_vrf = 0; |
b1c3ae8c | 3958 | json_object *json = NULL; |
7c8ff89e | 3959 | |
43b8d1d8 CS |
3960 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
3961 | ||
b1c3ae8c CS |
3962 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
3963 | intf_name = argv[idx_intf]->arg; | |
3964 | ||
d62a17ae | 3965 | if (uj) |
b1c3ae8c | 3966 | json = json_object_new_object(); |
6be4da3d | 3967 | |
b5a8894d CS |
3968 | /* vrf input is provided could be all or specific vrf*/ |
3969 | if (vrf_name) { | |
b1c3ae8c | 3970 | use_vrf = 1; |
b5a8894d CS |
3971 | if (all_vrf) { |
3972 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3973 | if (!ospf->oi_running) | |
3974 | continue; | |
996c9314 LB |
3975 | ret = show_ip_ospf_interface_common( |
3976 | vty, ospf, intf_name, use_vrf, json, | |
3977 | uj); | |
b5a8894d | 3978 | } |
b1c3ae8c CS |
3979 | |
3980 | if (uj) { | |
3981 | vty_out(vty, "%s\n", | |
996c9314 LB |
3982 | json_object_to_json_string_ext( |
3983 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3984 | json_object_free(json); |
9f049418 | 3985 | } else if (!ospf) |
94d4c685 | 3986 | vty_out(vty, "%% OSPF instance not found\n"); |
b1c3ae8c | 3987 | |
b5a8894d CS |
3988 | return ret; |
3989 | } | |
3990 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3991 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3992 | if (uj) { |
3993 | vty_out(vty, "%s\n", | |
3994 | json_object_to_json_string_ext( | |
3995 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3996 | json_object_free(json); |
9f049418 | 3997 | } else |
94d4c685 | 3998 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3999 | |
b5a8894d | 4000 | return CMD_SUCCESS; |
b1c3ae8c CS |
4001 | } |
4002 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4003 | use_vrf, json, uj); | |
b5a8894d CS |
4004 | |
4005 | } else { | |
4006 | /* Display default ospf (instance 0) info */ | |
4007 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4008 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4009 | if (uj) { |
4010 | vty_out(vty, "%s\n", | |
4011 | json_object_to_json_string_ext( | |
4012 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4013 | json_object_free(json); |
9f049418 | 4014 | } else |
94d4c685 | 4015 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4016 | |
b5a8894d | 4017 | return CMD_SUCCESS; |
b1c3ae8c CS |
4018 | } |
4019 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4020 | use_vrf, json, uj); | |
4021 | } | |
4022 | ||
4023 | if (uj) { | |
996c9314 LB |
4024 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4025 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4026 | json_object_free(json); |
b5a8894d CS |
4027 | } |
4028 | ||
4029 | return ret; | |
7c8ff89e DS |
4030 | } |
4031 | ||
4032 | DEFUN (show_ip_ospf_instance_interface, | |
4033 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4034 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4035 | SHOW_STR |
4036 | IP_STR | |
4037 | "OSPF information\n" | |
4038 | "Instance ID\n" | |
4039 | "Interface information\n" | |
7ec4159b | 4040 | "Interface name\n" |
9973d184 | 4041 | JSON_STR) |
7c8ff89e | 4042 | { |
d62a17ae | 4043 | int idx_number = 3; |
b1c3ae8c | 4044 | int idx_intf = 0; |
d62a17ae | 4045 | struct ospf *ospf; |
d7c0a89a | 4046 | unsigned short instance = 0; |
9f049418 | 4047 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4048 | char *intf_name = NULL; |
4049 | int ret = CMD_SUCCESS; | |
4050 | json_object *json = NULL; | |
d62a17ae | 4051 | |
4052 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
4053 | ospf = ospf_lookup_instance(instance); |
4054 | if (ospf == NULL) | |
4055 | return CMD_NOT_MY_INSTANCE; | |
4056 | ||
4057 | if (!ospf->oi_running) | |
d62a17ae | 4058 | return CMD_SUCCESS; |
4059 | ||
4060 | if (uj) | |
b1c3ae8c CS |
4061 | json = json_object_new_object(); |
4062 | ||
4063 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4064 | intf_name = argv[idx_intf]->arg; | |
4065 | ||
4066 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4067 | ||
4068 | if (uj) { | |
996c9314 LB |
4069 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4070 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4071 | json_object_free(json); |
4072 | } | |
d62a17ae | 4073 | |
b1c3ae8c | 4074 | return ret; |
d62a17ae | 4075 | } |
4076 | ||
c9339663 CS |
4077 | DEFUN (show_ip_ospf_interface_traffic, |
4078 | show_ip_ospf_interface_traffic_cmd, | |
4079 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4080 | SHOW_STR | |
4081 | IP_STR | |
4082 | "OSPF information\n" | |
4083 | VRF_CMD_HELP_STR | |
4084 | "All VRFs\n" | |
4085 | "Interface information\n" | |
4086 | "Protocol Packet counters\n" | |
4087 | "Interface name\n" | |
4088 | JSON_STR) | |
4089 | { | |
4090 | struct ospf *ospf = NULL; | |
4091 | struct listnode *node = NULL; | |
4092 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4093 | bool all_vrf = false; |
c9339663 CS |
4094 | int inst = 0; |
4095 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4096 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4097 | json_object *json = NULL; |
c9339663 CS |
4098 | int ret = CMD_SUCCESS; |
4099 | int display_once = 0; | |
d7c0a89a | 4100 | uint8_t use_vrf = 0; |
c9339663 CS |
4101 | |
4102 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4103 | ||
4104 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4105 | intf_name = argv[idx_intf]->arg; | |
4106 | ||
b1c3ae8c CS |
4107 | if (uj) |
4108 | json = json_object_new_object(); | |
4109 | ||
c9339663 | 4110 | if (vrf_name) { |
b1c3ae8c | 4111 | use_vrf = 1; |
c9339663 CS |
4112 | if (all_vrf) { |
4113 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4114 | if (!ospf->oi_running) | |
4115 | continue; | |
4116 | ||
996c9314 LB |
4117 | ret = show_ip_ospf_interface_traffic_common( |
4118 | vty, ospf, intf_name, json, | |
4119 | display_once, use_vrf, uj); | |
c9339663 CS |
4120 | display_once = 1; |
4121 | } | |
b1c3ae8c CS |
4122 | |
4123 | if (uj) { | |
4124 | vty_out(vty, "%s\n", | |
996c9314 LB |
4125 | json_object_to_json_string_ext( |
4126 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4127 | json_object_free(json); |
4128 | } | |
4129 | ||
c9339663 CS |
4130 | return ret; |
4131 | } | |
4132 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4133 | if (ospf == NULL || !ospf->oi_running) { |
4134 | if (uj) | |
4135 | json_object_free(json); | |
c9339663 | 4136 | return CMD_SUCCESS; |
b1c3ae8c CS |
4137 | } |
4138 | ||
996c9314 LB |
4139 | ret = show_ip_ospf_interface_traffic_common( |
4140 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4141 | } else { |
4142 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4143 | if (ospf == NULL || !ospf->oi_running) { |
4144 | if (uj) | |
4145 | json_object_free(json); | |
c9339663 | 4146 | return CMD_SUCCESS; |
b1c3ae8c CS |
4147 | } |
4148 | ||
996c9314 LB |
4149 | ret = show_ip_ospf_interface_traffic_common( |
4150 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4151 | } |
4152 | ||
4153 | if (uj) { | |
996c9314 LB |
4154 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4155 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4156 | json_object_free(json); |
c9339663 CS |
4157 | } |
4158 | ||
4159 | return ret; | |
4160 | } | |
4161 | ||
4162 | ||
d62a17ae | 4163 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4164 | { | |
c84355a9 | 4165 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n", |
d62a17ae | 4166 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", |
4167 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4168 | } | |
4169 | ||
4170 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4171 | struct ospf_interface *oi, | |
9f049418 | 4172 | json_object *json, bool use_json) |
d62a17ae | 4173 | { |
4174 | struct route_node *rn; | |
cef262c3 | 4175 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4176 | char msgbuf[16]; |
4177 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cef262c3 | 4178 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4179 | |
4180 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4181 | if ((nbr = rn->info)) { | |
4182 | /* Do not show myself. */ | |
cef262c3 CS |
4183 | if (nbr == oi->nbr_self) |
4184 | continue; | |
4185 | /* Down state is not shown. */ | |
4186 | if (nbr->state == NSM_Down) | |
4187 | continue; | |
4188 | if (use_json) { | |
4189 | char neigh_str[INET_ADDRSTRLEN]; | |
4190 | ||
996c9314 LB |
4191 | if (prev_nbr |
4192 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4193 | &nbr->src)) { | |
cef262c3 CS |
4194 | /* Start new neigh list */ |
4195 | json_neigh_array = NULL; | |
4196 | } | |
4197 | ||
996c9314 | 4198 | if (nbr->state == NSM_Attempt |
975a328e | 4199 | && nbr->router_id.s_addr == INADDR_ANY) |
6021c6c0 CS |
4200 | strlcpy(neigh_str, "neighbor", |
4201 | sizeof(neigh_str)); | |
cef262c3 | 4202 | else |
6021c6c0 | 4203 | strlcpy(neigh_str, |
cef262c3 | 4204 | inet_ntoa(nbr->router_id), |
6021c6c0 | 4205 | sizeof(neigh_str)); |
cef262c3 CS |
4206 | |
4207 | json_object_object_get_ex(json, neigh_str, | |
4208 | &json_neigh_array); | |
4209 | ||
4210 | if (!json_neigh_array) { | |
996c9314 LB |
4211 | json_neigh_array = |
4212 | json_object_new_array(); | |
4213 | json_object_object_add( | |
4214 | json, neigh_str, | |
4215 | json_neigh_array); | |
d62a17ae | 4216 | } |
cef262c3 | 4217 | |
996c9314 | 4218 | json_neighbor = json_object_new_object(); |
cef262c3 CS |
4219 | |
4220 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4221 | ||
4222 | long time_store; | |
4223 | ||
996c9314 LB |
4224 | time_store = |
4225 | monotime_until( | |
cef262c3 | 4226 | &nbr->t_inactivity->u.sands, |
996c9314 LB |
4227 | NULL) |
4228 | / 1000LL; | |
cef262c3 | 4229 | |
996c9314 | 4230 | json_object_int_add(json_neighbor, "priority", |
cef262c3 CS |
4231 | nbr->priority); |
4232 | json_object_string_add(json_neighbor, "state", | |
4233 | msgbuf); | |
4234 | json_object_int_add(json_neighbor, | |
4235 | "deadTimeMsecs", | |
4236 | time_store); | |
996c9314 | 4237 | json_object_string_add(json_neighbor, "address", |
cef262c3 CS |
4238 | inet_ntoa(nbr->src)); |
4239 | json_object_string_add(json_neighbor, | |
4240 | "ifaceName", | |
4241 | IF_NAME(oi)); | |
996c9314 LB |
4242 | json_object_int_add( |
4243 | json_neighbor, "retransmitCounter", | |
4244 | ospf_ls_retransmit_count(nbr)); | |
cef262c3 | 4245 | json_object_int_add(json_neighbor, |
996c9314 LB |
4246 | "requestCounter", |
4247 | ospf_ls_request_count(nbr)); | |
cef262c3 | 4248 | json_object_int_add(json_neighbor, |
996c9314 LB |
4249 | "dbSummaryCounter", |
4250 | ospf_db_summary_count(nbr)); | |
cef262c3 CS |
4251 | |
4252 | json_object_array_add(json_neigh_array, | |
4253 | json_neighbor); | |
4254 | } else { | |
4255 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4256 | ||
996c9314 | 4257 | if (nbr->state == NSM_Attempt |
975a328e | 4258 | && nbr->router_id.s_addr == INADDR_ANY) |
996c9314 LB |
4259 | vty_out(vty, "%-15s %3d %-15s ", "-", |
4260 | nbr->priority, msgbuf); | |
cef262c3 | 4261 | else |
996c9314 | 4262 | vty_out(vty, "%-15s %3d %-15s ", |
cef262c3 | 4263 | inet_ntoa(nbr->router_id), |
996c9314 | 4264 | nbr->priority, msgbuf); |
cef262c3 CS |
4265 | |
4266 | vty_out(vty, "%9s ", | |
4267 | ospf_timer_dump(nbr->t_inactivity, | |
4268 | timebuf, | |
4269 | sizeof(timebuf))); | |
4270 | vty_out(vty, "%-15s ", inet_ntoa(nbr->src)); | |
c84355a9 | 4271 | vty_out(vty, "%-32s %5ld %5ld %5d\n", |
cef262c3 CS |
4272 | IF_NAME(oi), |
4273 | ospf_ls_retransmit_count(nbr), | |
4274 | ospf_ls_request_count(nbr), | |
4275 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4276 | } |
cef262c3 | 4277 | prev_nbr = nbr; |
d62a17ae | 4278 | } |
4279 | } | |
4280 | } | |
4281 | ||
4282 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4283 | json_object *json, bool use_json, |
d7c0a89a | 4284 | uint8_t use_vrf) |
d62a17ae | 4285 | { |
4286 | struct ospf_interface *oi; | |
4287 | struct listnode *node; | |
6282e124 | 4288 | json_object *json_vrf = NULL; |
2bc7673f | 4289 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4290 | |
b1c3ae8c CS |
4291 | if (use_json) { |
4292 | if (use_vrf) | |
4293 | json_vrf = json_object_new_object(); | |
4294 | else | |
4295 | json_vrf = json; | |
6282e124 | 4296 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4297 | } |
d62a17ae | 4298 | |
4299 | if (ospf->instance) { | |
4300 | if (use_json) | |
4301 | json_object_int_add(json, "ospfInstance", | |
4302 | ospf->instance); | |
4303 | else | |
4304 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4305 | } | |
7c8ff89e | 4306 | |
b1c3ae8c CS |
4307 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4308 | if (!use_json) | |
4309 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4310 | |
2bc7673f CS |
4311 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4312 | if (ospf_interface_neighbor_count(oi) == 0) | |
4313 | continue; | |
2bc7673f CS |
4314 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4315 | } | |
718e3744 | 4316 | |
d62a17ae | 4317 | if (use_json) { |
996c9314 | 4318 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
b1c3ae8c CS |
4319 | if (use_vrf) { |
4320 | if (ospf->vrf_id == VRF_DEFAULT) | |
4321 | json_object_object_add(json, "default", | |
4322 | json_vrf); | |
4323 | else | |
4324 | json_object_object_add(json, ospf->name, | |
4325 | json_vrf); | |
4326 | } | |
d62a17ae | 4327 | } else |
4328 | vty_out(vty, "\n"); | |
7c8ff89e | 4329 | |
d62a17ae | 4330 | return CMD_SUCCESS; |
718e3744 | 4331 | } |
4332 | ||
7c8ff89e DS |
4333 | DEFUN (show_ip_ospf_neighbor, |
4334 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4335 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4336 | SHOW_STR |
4337 | IP_STR | |
4338 | "OSPF information\n" | |
b5a8894d CS |
4339 | VRF_CMD_HELP_STR |
4340 | "All VRFs\n" | |
91756b38 | 4341 | "Neighbor list\n" |
9973d184 | 4342 | JSON_STR) |
718e3744 | 4343 | { |
d62a17ae | 4344 | struct ospf *ospf; |
9f049418 | 4345 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4346 | struct listnode *node = NULL; |
4347 | char *vrf_name = NULL; | |
2951a7a4 | 4348 | bool all_vrf = false; |
b5a8894d CS |
4349 | int ret = CMD_SUCCESS; |
4350 | int inst = 0; | |
4351 | int idx_vrf = 0; | |
d7c0a89a | 4352 | uint8_t use_vrf = 0; |
b1c3ae8c | 4353 | json_object *json = NULL; |
718e3744 | 4354 | |
43b8d1d8 | 4355 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4356 | |
b1c3ae8c CS |
4357 | if (uj) |
4358 | json = json_object_new_object(); | |
b5a8894d CS |
4359 | |
4360 | /* vrf input is provided could be all or specific vrf*/ | |
4361 | if (vrf_name) { | |
b1c3ae8c | 4362 | use_vrf = 1; |
b5a8894d CS |
4363 | if (all_vrf) { |
4364 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4365 | if (!ospf->oi_running) | |
4366 | continue; | |
996c9314 LB |
4367 | ret = show_ip_ospf_neighbor_common( |
4368 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4369 | } |
4370 | ||
4371 | if (uj) { | |
4372 | vty_out(vty, "%s\n", | |
996c9314 LB |
4373 | json_object_to_json_string_ext( |
4374 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4375 | json_object_free(json); |
9f049418 DS |
4376 | } else if (!ospf) |
4377 | vty_out(vty, "OSPF instance not found\n"); | |
b1c3ae8c | 4378 | |
b5a8894d CS |
4379 | return ret; |
4380 | } | |
b1c3ae8c | 4381 | |
b5a8894d | 4382 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4383 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4384 | if (uj) { |
4385 | vty_out(vty, "%s\n", | |
4386 | json_object_to_json_string_ext( | |
4387 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4388 | json_object_free(json); |
9f049418 DS |
4389 | } else |
4390 | vty_out(vty, "%% OSPF instance not found\n"); | |
4391 | ||
b5a8894d | 4392 | return CMD_SUCCESS; |
b1c3ae8c | 4393 | } |
b5a8894d CS |
4394 | } else { |
4395 | /* Display default ospf (instance 0) info */ | |
4396 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4397 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4398 | if (uj) { |
4399 | vty_out(vty, "%s\n", | |
4400 | json_object_to_json_string_ext( | |
4401 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4402 | json_object_free(json); |
9f049418 DS |
4403 | } else |
4404 | vty_out(vty, "%% OSPF instance not found\n"); | |
4405 | ||
b5a8894d | 4406 | return CMD_SUCCESS; |
b1c3ae8c | 4407 | } |
b5a8894d CS |
4408 | } |
4409 | ||
b1c3ae8c CS |
4410 | if (ospf) { |
4411 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4412 | use_vrf); | |
4413 | ||
4414 | if (uj) { | |
4415 | vty_out(vty, "%s\n", | |
996c9314 LB |
4416 | json_object_to_json_string_ext( |
4417 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4418 | } |
4419 | } | |
4420 | ||
4421 | if (uj) | |
4422 | json_object_free(json); | |
b5a8894d CS |
4423 | |
4424 | return ret; | |
7c8ff89e DS |
4425 | } |
4426 | ||
4427 | ||
4428 | DEFUN (show_ip_ospf_instance_neighbor, | |
4429 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4430 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4431 | SHOW_STR |
4432 | IP_STR | |
4433 | "OSPF information\n" | |
4434 | "Instance ID\n" | |
91756b38 | 4435 | "Neighbor list\n" |
9973d184 | 4436 | JSON_STR) |
7c8ff89e | 4437 | { |
d62a17ae | 4438 | int idx_number = 3; |
4439 | struct ospf *ospf; | |
d7c0a89a | 4440 | unsigned short instance = 0; |
9f049418 | 4441 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4442 | json_object *json = NULL; |
4443 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4444 | |
d62a17ae | 4445 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4446 | ospf = ospf_lookup_instance(instance); |
4447 | if (ospf == NULL) | |
4448 | return CMD_NOT_MY_INSTANCE; | |
4449 | ||
4450 | if (!ospf->oi_running) | |
d62a17ae | 4451 | return CMD_SUCCESS; |
7c8ff89e | 4452 | |
b1c3ae8c CS |
4453 | if (uj) |
4454 | json = json_object_new_object(); | |
b5a8894d | 4455 | |
b1c3ae8c CS |
4456 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4457 | ||
4458 | if (uj) { | |
996c9314 LB |
4459 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4460 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4461 | json_object_free(json); |
4462 | } | |
4463 | ||
4464 | return ret; | |
7c8ff89e DS |
4465 | } |
4466 | ||
d62a17ae | 4467 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4468 | json_object *json, bool use_json, |
d7c0a89a | 4469 | uint8_t use_vrf) |
d62a17ae | 4470 | { |
4471 | struct listnode *node; | |
4472 | struct ospf_interface *oi; | |
b1c3ae8c | 4473 | json_object *json_vrf = NULL; |
d62a17ae | 4474 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4475 | |
d62a17ae | 4476 | if (use_json) { |
b1c3ae8c CS |
4477 | if (use_vrf) |
4478 | json_vrf = json_object_new_object(); | |
4479 | else | |
4480 | json_vrf = json; | |
d62a17ae | 4481 | json_neighbor_sub = json_object_new_object(); |
b5a8894d | 4482 | } |
d62a17ae | 4483 | |
b1c3ae8c CS |
4484 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4485 | if (!use_json) | |
4486 | show_ip_ospf_neighbour_header(vty); | |
4487 | ||
d62a17ae | 4488 | if (ospf->instance) { |
4489 | if (use_json) | |
b1c3ae8c | 4490 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4491 | ospf->instance); |
4492 | else | |
4493 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4494 | } | |
4495 | ||
4496 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4497 | struct listnode *nbr_node; | |
4498 | struct ospf_nbr_nbma *nbr_nbma; | |
4499 | ||
b1c3ae8c | 4500 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4501 | |
4502 | /* print Down neighbor status */ | |
4503 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4504 | if (nbr_nbma->nbr == NULL | |
4505 | || nbr_nbma->nbr->state == NSM_Down) { | |
4506 | if (use_json) { | |
4507 | json_object_int_add(json_neighbor_sub, | |
4508 | "nbrNbmaPriority", | |
4509 | nbr_nbma->priority); | |
4510 | json_object_boolean_true_add( | |
4511 | json_neighbor_sub, | |
4512 | "nbrNbmaDown"); | |
4513 | json_object_string_add( | |
4514 | json_neighbor_sub, | |
4515 | "nbrNbmaIfaceName", | |
4516 | IF_NAME(oi)); | |
4517 | json_object_int_add( | |
4518 | json_neighbor_sub, | |
4519 | "nbrNbmaRetransmitCounter", 0); | |
4520 | json_object_int_add( | |
4521 | json_neighbor_sub, | |
4522 | "nbrNbmaRequestCounter", 0); | |
4523 | json_object_int_add( | |
4524 | json_neighbor_sub, | |
4525 | "nbrNbmaDbSummaryCounter", 0); | |
4526 | json_object_object_add( | |
b1c3ae8c CS |
4527 | json_vrf, |
4528 | inet_ntoa(nbr_nbma->addr), | |
d62a17ae | 4529 | json_neighbor_sub); |
4530 | } else { | |
4531 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4532 | "-", nbr_nbma->priority, "Down", | |
4533 | "-"); | |
4534 | vty_out(vty, | |
c84355a9 | 4535 | "%-32s %-20s %5d %5d %5d\n", |
d62a17ae | 4536 | inet_ntoa(nbr_nbma->addr), |
4537 | IF_NAME(oi), 0, 0, 0); | |
4538 | } | |
4539 | } | |
4540 | } | |
4541 | } | |
4542 | ||
4543 | if (use_json) { | |
b1c3ae8c CS |
4544 | if (use_vrf) { |
4545 | if (ospf->vrf_id == VRF_DEFAULT) | |
4546 | json_object_object_add(json, "default", | |
4547 | json_vrf); | |
4548 | else | |
4549 | json_object_object_add(json, ospf->name, | |
4550 | json_vrf); | |
4551 | } | |
d62a17ae | 4552 | } else |
4553 | vty_out(vty, "\n"); | |
4554 | ||
4555 | return CMD_SUCCESS; | |
718e3744 | 4556 | } |
4557 | ||
7c8ff89e DS |
4558 | DEFUN (show_ip_ospf_neighbor_all, |
4559 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4560 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4561 | SHOW_STR |
4562 | IP_STR | |
4563 | "OSPF information\n" | |
b5a8894d CS |
4564 | VRF_CMD_HELP_STR |
4565 | "All VRFs\n" | |
718e3744 | 4566 | "Neighbor list\n" |
91756b38 | 4567 | "include down status neighbor\n" |
9973d184 | 4568 | JSON_STR) |
7c8ff89e | 4569 | { |
d62a17ae | 4570 | struct ospf *ospf; |
9f049418 | 4571 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4572 | struct listnode *node = NULL; |
4573 | char *vrf_name = NULL; | |
2951a7a4 | 4574 | bool all_vrf = false; |
b5a8894d CS |
4575 | int ret = CMD_SUCCESS; |
4576 | int inst = 0; | |
4577 | int idx_vrf = 0; | |
d7c0a89a | 4578 | uint8_t use_vrf = 0; |
b1c3ae8c | 4579 | json_object *json = NULL; |
7c8ff89e | 4580 | |
43b8d1d8 | 4581 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4582 | |
b1c3ae8c CS |
4583 | if (uj) |
4584 | json = json_object_new_object(); | |
b5a8894d CS |
4585 | |
4586 | /* vrf input is provided could be all or specific vrf*/ | |
4587 | if (vrf_name) { | |
b1c3ae8c | 4588 | use_vrf = 1; |
b5a8894d CS |
4589 | if (all_vrf) { |
4590 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4591 | if (!ospf->oi_running) | |
4592 | continue; | |
996c9314 LB |
4593 | ret = show_ip_ospf_neighbor_all_common( |
4594 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4595 | } |
4596 | ||
4597 | if (uj) { | |
4598 | vty_out(vty, "%s\n", | |
996c9314 LB |
4599 | json_object_to_json_string_ext( |
4600 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4601 | json_object_free(json); |
b5a8894d | 4602 | } |
b1c3ae8c | 4603 | |
b5a8894d CS |
4604 | return ret; |
4605 | } | |
b1c3ae8c | 4606 | |
b5a8894d | 4607 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4608 | if (ospf == NULL || !ospf->oi_running) { |
4609 | if (uj) | |
4610 | json_object_free(json); | |
b5a8894d | 4611 | return CMD_SUCCESS; |
b1c3ae8c | 4612 | } |
b5a8894d CS |
4613 | } else { |
4614 | /* Display default ospf (instance 0) info */ | |
4615 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4616 | if (ospf == NULL || !ospf->oi_running) { |
4617 | if (uj) | |
4618 | json_object_free(json); | |
b5a8894d | 4619 | return CMD_SUCCESS; |
b1c3ae8c | 4620 | } |
b5a8894d CS |
4621 | } |
4622 | ||
b1c3ae8c CS |
4623 | if (ospf) { |
4624 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4625 | use_vrf); | |
4626 | if (uj) { | |
4627 | vty_out(vty, "%s\n", | |
996c9314 LB |
4628 | json_object_to_json_string_ext( |
4629 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4630 | } |
4631 | } | |
4632 | ||
4633 | if (uj) | |
4634 | json_object_free(json); | |
b5a8894d CS |
4635 | |
4636 | return ret; | |
7c8ff89e DS |
4637 | } |
4638 | ||
4639 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4640 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4641 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4642 | SHOW_STR |
4643 | IP_STR | |
4644 | "OSPF information\n" | |
4645 | "Instance ID\n" | |
4646 | "Neighbor list\n" | |
91756b38 | 4647 | "include down status neighbor\n" |
9973d184 | 4648 | JSON_STR) |
718e3744 | 4649 | { |
d62a17ae | 4650 | int idx_number = 3; |
4651 | struct ospf *ospf; | |
d7c0a89a | 4652 | unsigned short instance = 0; |
9f049418 | 4653 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4654 | json_object *json = NULL; |
4655 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4656 | |
d62a17ae | 4657 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4658 | ospf = ospf_lookup_instance(instance); |
4659 | if (ospf == NULL) | |
4660 | return CMD_NOT_MY_INSTANCE; | |
4661 | ||
4662 | if (!ospf->oi_running) | |
d62a17ae | 4663 | return CMD_SUCCESS; |
b1c3ae8c CS |
4664 | if (uj) |
4665 | json = json_object_new_object(); | |
4666 | ||
4667 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4668 | ||
4669 | if (uj) { | |
4670 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4671 | json, JSON_C_TO_STRING_PRETTY)); | |
4672 | json_object_free(json); | |
4673 | } | |
7c8ff89e | 4674 | |
b1c3ae8c | 4675 | return ret; |
7c8ff89e DS |
4676 | } |
4677 | ||
d62a17ae | 4678 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4679 | int arg_base, | |
4680 | struct cmd_token **argv, | |
9f049418 | 4681 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4682 | { |
4683 | struct interface *ifp; | |
4684 | struct route_node *rn; | |
4685 | json_object *json = NULL; | |
91756b38 | 4686 | |
d62a17ae | 4687 | if (use_json) |
4688 | json = json_object_new_object(); | |
d62a17ae | 4689 | |
4690 | if (ospf->instance) { | |
4691 | if (use_json) | |
4692 | json_object_int_add(json, "ospfInstance", | |
4693 | ospf->instance); | |
4694 | else | |
4695 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4696 | } | |
4697 | ||
b1c3ae8c | 4698 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4699 | |
a36898e7 | 4700 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4701 | if (!ifp) { |
4702 | if (use_json) | |
4703 | json_object_boolean_true_add(json, "noSuchIface"); | |
4704 | else | |
4705 | vty_out(vty, "No such interface.\n"); | |
4706 | return CMD_WARNING; | |
4707 | } | |
4708 | ||
4709 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4710 | struct ospf_interface *oi = rn->info; | |
4711 | ||
4712 | if (oi == NULL) | |
4713 | continue; | |
4714 | ||
4715 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4716 | } | |
4717 | ||
4718 | if (use_json) { | |
9d303b37 DL |
4719 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4720 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4721 | json_object_free(json); |
4722 | } else | |
4723 | vty_out(vty, "\n"); | |
4724 | ||
4725 | return CMD_SUCCESS; | |
718e3744 | 4726 | } |
4727 | ||
7c8ff89e DS |
4728 | DEFUN (show_ip_ospf_neighbor_int, |
4729 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4730 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4731 | SHOW_STR |
4732 | IP_STR | |
4733 | "OSPF information\n" | |
03ed9f02 | 4734 | VRF_CMD_HELP_STR |
7c8ff89e | 4735 | "Neighbor list\n" |
91756b38 | 4736 | "Interface name\n" |
9973d184 | 4737 | JSON_STR) |
7c8ff89e | 4738 | { |
d62a17ae | 4739 | struct ospf *ospf; |
03ed9f02 PG |
4740 | int idx_ifname = 0; |
4741 | int idx_vrf = 0; | |
9f049418 | 4742 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4743 | int ret = CMD_SUCCESS; |
4744 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4745 | char *vrf_name = NULL; |
4746 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4747 | struct vrf *vrf = NULL; | |
4748 | ||
4749 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4750 | vrf_name = argv[idx_vrf + 1]->arg; | |
4751 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4752 | vrf_name = NULL; | |
4753 | if (vrf_name) { | |
4754 | vrf = vrf_lookup_by_name(vrf_name); | |
4755 | if (vrf) | |
4756 | vrf_id = vrf->vrf_id; | |
4757 | } | |
4758 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4759 | ||
4760 | if (!ospf || !ospf->oi_running) | |
4761 | return ret; | |
7c8ff89e | 4762 | |
b5a8894d CS |
4763 | if (!uj) |
4764 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4765 | |
03ed9f02 | 4766 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4767 | |
a36898e7 | 4768 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4769 | if (!ifp) |
4770 | return ret; | |
4771 | ||
4772 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4773 | argv, uj, 0); | |
b5a8894d | 4774 | return ret; |
7c8ff89e DS |
4775 | } |
4776 | ||
4777 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4778 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4779 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4780 | SHOW_STR |
4781 | IP_STR | |
4782 | "OSPF information\n" | |
4783 | "Instance ID\n" | |
4784 | "Neighbor list\n" | |
91756b38 | 4785 | "Interface name\n" |
9973d184 | 4786 | JSON_STR) |
7c8ff89e | 4787 | { |
d62a17ae | 4788 | int idx_number = 3; |
b4e84315 | 4789 | int idx_ifname = 5; |
d62a17ae | 4790 | struct ospf *ospf; |
d7c0a89a | 4791 | unsigned short instance = 0; |
9f049418 | 4792 | bool uj = use_json(argc, argv); |
7c8ff89e | 4793 | |
b5a8894d CS |
4794 | if (!uj) |
4795 | show_ip_ospf_neighbour_header(vty); | |
4796 | ||
d62a17ae | 4797 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4798 | ospf = ospf_lookup_instance(instance); |
4799 | if (ospf == NULL) | |
4800 | return CMD_NOT_MY_INSTANCE; | |
4801 | ||
4802 | if (!ospf->oi_running) | |
d62a17ae | 4803 | return CMD_SUCCESS; |
7c8ff89e | 4804 | |
b5a8894d CS |
4805 | if (!uj) |
4806 | show_ip_ospf_neighbour_header(vty); | |
4807 | ||
996c9314 LB |
4808 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
4809 | 0); | |
718e3744 | 4810 | } |
4811 | ||
d62a17ae | 4812 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
4813 | struct ospf_interface *oi, | |
4814 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 4815 | bool use_json, json_object *json) |
d62a17ae | 4816 | { |
4817 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4818 | json_object *json_sub = NULL; | |
718e3744 | 4819 | |
d62a17ae | 4820 | if (use_json) |
4821 | json_sub = json_object_new_object(); | |
4822 | else /* Show neighbor ID. */ | |
4823 | vty_out(vty, " Neighbor %s,", "-"); | |
4824 | ||
4825 | /* Show interface address. */ | |
4826 | if (use_json) | |
4827 | json_object_string_add(json_sub, "ifaceAddress", | |
4828 | inet_ntoa(nbr_nbma->addr)); | |
4829 | else | |
4830 | vty_out(vty, " interface address %s\n", | |
4831 | inet_ntoa(nbr_nbma->addr)); | |
4832 | ||
4833 | /* Show Area ID. */ | |
4834 | if (use_json) { | |
4835 | json_object_string_add(json_sub, "areaId", | |
4836 | ospf_area_desc_string(oi->area)); | |
4837 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
4838 | } else | |
4839 | vty_out(vty, " In the area %s via interface %s\n", | |
4840 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
4841 | ||
4842 | /* Show neighbor priority and state. */ | |
4843 | if (use_json) { | |
4844 | json_object_int_add(json_sub, "nbrPriority", | |
4845 | nbr_nbma->priority); | |
4846 | json_object_string_add(json_sub, "nbrState", "down"); | |
4847 | } else | |
4848 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4849 | nbr_nbma->priority, "Down"); | |
4850 | ||
4851 | /* Show state changes. */ | |
4852 | if (use_json) | |
4853 | json_object_int_add(json_sub, "stateChangeCounter", | |
4854 | nbr_nbma->state_change); | |
4855 | else | |
4856 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
4857 | ||
4858 | /* Show PollInterval */ | |
4859 | if (use_json) | |
4860 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
4861 | else | |
4862 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
4863 | ||
4864 | /* Show poll-interval timer. */ | |
b575a12c A |
4865 | if (nbr_nbma->t_poll) { |
4866 | if (use_json) { | |
4867 | long time_store; | |
4868 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
4869 | NULL) / 1000LL; | |
4870 | json_object_int_add(json_sub, | |
4871 | "pollIntervalTimerDueMsec", | |
4872 | time_store); | |
4873 | } else | |
4874 | vty_out(vty, " Poll timer due in %s\n", | |
4875 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
4876 | sizeof(timebuf))); | |
4877 | } | |
d62a17ae | 4878 | |
4879 | /* Show poll-interval timer thread. */ | |
4880 | if (use_json) { | |
4881 | if (nbr_nbma->t_poll != NULL) | |
4882 | json_object_string_add(json_sub, | |
4883 | "pollIntervalTimerThread", "on"); | |
4884 | } else | |
4885 | vty_out(vty, " Thread Poll Timer %s\n", | |
4886 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
4887 | ||
4888 | if (use_json) | |
4889 | json_object_object_add(json, "noNbrId", json_sub); | |
4890 | } | |
4891 | ||
4892 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
4893 | struct ospf_interface *oi, | |
4894 | struct ospf_neighbor *nbr, | |
cb0b2ac6 | 4895 | struct ospf_neighbor *prev_nbr, |
9f049418 | 4896 | json_object *json, bool use_json) |
d62a17ae | 4897 | { |
4898 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cb0b2ac6 CS |
4899 | json_object *json_neigh = NULL, *json_neigh_array = NULL; |
4900 | char neigh_str[INET_ADDRSTRLEN] = {0}; | |
d62a17ae | 4901 | |
cb0b2ac6 CS |
4902 | if (use_json) { |
4903 | if (prev_nbr && | |
4904 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
4905 | json_neigh_array = NULL; | |
4906 | } | |
4907 | ||
975a328e DA |
4908 | if (nbr->state == NSM_Attempt |
4909 | && nbr->router_id.s_addr == INADDR_ANY) | |
cb0b2ac6 CS |
4910 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
4911 | else | |
4912 | strlcpy(neigh_str, inet_ntoa(nbr->router_id), | |
4913 | sizeof(neigh_str)); | |
4914 | ||
4915 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
4916 | ||
4917 | if (!json_neigh_array) { | |
4918 | json_neigh_array = json_object_new_array(); | |
4919 | json_object_object_add(json, neigh_str, | |
4920 | json_neigh_array); | |
4921 | } | |
4922 | ||
4923 | json_neigh = json_object_new_object(); | |
4924 | ||
4925 | } else { | |
d62a17ae | 4926 | /* Show neighbor ID. */ |
975a328e DA |
4927 | if (nbr->state == NSM_Attempt |
4928 | && nbr->router_id.s_addr == INADDR_ANY) | |
d62a17ae | 4929 | vty_out(vty, " Neighbor %s,", "-"); |
4930 | else | |
4931 | vty_out(vty, " Neighbor %s,", | |
4932 | inet_ntoa(nbr->router_id)); | |
4933 | } | |
4934 | ||
4935 | /* Show interface address. */ | |
4936 | if (use_json) | |
cb0b2ac6 | 4937 | json_object_string_add(json_neigh, "ifaceAddress", |
d62a17ae | 4938 | inet_ntoa(nbr->address.u.prefix4)); |
4939 | else | |
4940 | vty_out(vty, " interface address %s\n", | |
4941 | inet_ntoa(nbr->address.u.prefix4)); | |
4942 | ||
4943 | /* Show Area ID. */ | |
4944 | if (use_json) { | |
cb0b2ac6 | 4945 | json_object_string_add(json_neigh, "areaId", |
d62a17ae | 4946 | ospf_area_desc_string(oi->area)); |
cb0b2ac6 | 4947 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
d62a17ae | 4948 | } else |
4949 | vty_out(vty, " In the area %s via interface %s\n", | |
4950 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
4951 | ||
4952 | /* Show neighbor priority and state. */ | |
4953 | if (use_json) { | |
cb0b2ac6 | 4954 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
d62a17ae | 4955 | json_object_string_add( |
cb0b2ac6 | 4956 | json_neigh, "nbrState", |
d62a17ae | 4957 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); |
4958 | } else | |
4959 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4960 | nbr->priority, | |
4961 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4962 | ||
4963 | /* Show state changes. */ | |
4964 | if (use_json) | |
cb0b2ac6 | 4965 | json_object_int_add(json_neigh, "stateChangeCounter", |
d62a17ae | 4966 | nbr->state_change); |
4967 | else | |
4968 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
4969 | ||
4970 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
4971 | struct timeval res; | |
4972 | long time_store; | |
4973 | ||
4974 | time_store = | |
4975 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
4976 | if (use_json) { | |
cb0b2ac6 | 4977 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
d62a17ae | 4978 | time_store); |
4979 | } else { | |
4980 | vty_out(vty, | |
4981 | " Most recent state change statistics:\n"); | |
4982 | vty_out(vty, " Progressive change %s ago\n", | |
4983 | ospf_timeval_dump(&res, timebuf, | |
4984 | sizeof(timebuf))); | |
4985 | } | |
4986 | } | |
4987 | ||
4988 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
4989 | struct timeval res; | |
4990 | long time_store; | |
4991 | ||
4992 | time_store = | |
4993 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
4994 | if (use_json) { | |
cb0b2ac6 | 4995 | json_object_int_add(json_neigh, |
d62a17ae | 4996 | "lastRegressiveChangeMsec", |
4997 | time_store); | |
4998 | if (nbr->last_regress_str) | |
4999 | json_object_string_add( | |
cb0b2ac6 CS |
5000 | json_neigh, |
5001 | "lastRegressiveChangeReason", | |
d62a17ae | 5002 | nbr->last_regress_str); |
5003 | } else { | |
5004 | vty_out(vty, | |
5005 | " Regressive change %s ago, due to %s\n", | |
5006 | ospf_timeval_dump(&res, timebuf, | |
5007 | sizeof(timebuf)), | |
5008 | (nbr->last_regress_str ? nbr->last_regress_str | |
5009 | : "??")); | |
5010 | } | |
5011 | } | |
5012 | ||
5013 | /* Show Designated Rotuer ID. */ | |
5014 | if (use_json) | |
cb0b2ac6 | 5015 | json_object_string_add(json_neigh, "routerDesignatedId", |
d62a17ae | 5016 | inet_ntoa(nbr->d_router)); |
5017 | else | |
5018 | vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router)); | |
5019 | ||
5020 | /* Show Backup Designated Rotuer ID. */ | |
5021 | if (use_json) | |
cb0b2ac6 | 5022 | json_object_string_add(json_neigh, "routerDesignatedBackupId", |
d62a17ae | 5023 | inet_ntoa(nbr->bd_router)); |
5024 | else | |
5025 | vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router)); | |
5026 | ||
5027 | /* Show options. */ | |
5028 | if (use_json) { | |
cb0b2ac6 CS |
5029 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5030 | json_object_string_add(json_neigh, "optionsList", | |
d62a17ae | 5031 | ospf_options_dump(nbr->options)); |
5032 | } else | |
5033 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5034 | ospf_options_dump(nbr->options)); | |
5035 | ||
5036 | /* Show Router Dead interval timer. */ | |
5037 | if (use_json) { | |
5038 | if (nbr->t_inactivity) { | |
5039 | long time_store; | |
5040 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5041 | NULL) | |
5042 | / 1000LL; | |
cb0b2ac6 | 5043 | json_object_int_add(json_neigh, |
d62a17ae | 5044 | "routerDeadIntervalTimerDueMsec", |
5045 | time_store); | |
5046 | } else | |
5047 | json_object_int_add( | |
cb0b2ac6 CS |
5048 | json_neigh, |
5049 | "routerDeadIntervalTimerDueMsec", -1); | |
d62a17ae | 5050 | } else |
5051 | vty_out(vty, " Dead timer due in %s\n", | |
5052 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5053 | sizeof(timebuf))); | |
5054 | ||
5055 | /* Show Database Summary list. */ | |
5056 | if (use_json) | |
cb0b2ac6 | 5057 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
d62a17ae | 5058 | ospf_db_summary_count(nbr)); |
5059 | else | |
5060 | vty_out(vty, " Database Summary List %d\n", | |
5061 | ospf_db_summary_count(nbr)); | |
5062 | ||
5063 | /* Show Link State Request list. */ | |
5064 | if (use_json) | |
cb0b2ac6 | 5065 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
d62a17ae | 5066 | ospf_ls_request_count(nbr)); |
5067 | else | |
5068 | vty_out(vty, " Link State Request List %ld\n", | |
5069 | ospf_ls_request_count(nbr)); | |
5070 | ||
5071 | /* Show Link State Retransmission list. */ | |
5072 | if (use_json) | |
cb0b2ac6 | 5073 | json_object_int_add(json_neigh, |
d62a17ae | 5074 | "linkStateRetransmissionListCounter", |
5075 | ospf_ls_retransmit_count(nbr)); | |
5076 | else | |
5077 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5078 | ospf_ls_retransmit_count(nbr)); | |
5079 | ||
5080 | /* Show inactivity timer thread. */ | |
5081 | if (use_json) { | |
5082 | if (nbr->t_inactivity != NULL) | |
cb0b2ac6 | 5083 | json_object_string_add(json_neigh, |
d62a17ae | 5084 | "threadInactivityTimer", "on"); |
5085 | } else | |
5086 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5087 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5088 | ||
5089 | /* Show Database Description retransmission thread. */ | |
5090 | if (use_json) { | |
5091 | if (nbr->t_db_desc != NULL) | |
5092 | json_object_string_add( | |
cb0b2ac6 | 5093 | json_neigh, |
d62a17ae | 5094 | "threadDatabaseDescriptionRetransmission", |
5095 | "on"); | |
5096 | } else | |
5097 | vty_out(vty, | |
5098 | " Thread Database Description Retransmision %s\n", | |
5099 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5100 | ||
5101 | /* Show Link State Request Retransmission thread. */ | |
5102 | if (use_json) { | |
5103 | if (nbr->t_ls_req != NULL) | |
5104 | json_object_string_add( | |
cb0b2ac6 | 5105 | json_neigh, |
d62a17ae | 5106 | "threadLinkStateRequestRetransmission", "on"); |
5107 | } else | |
5108 | vty_out(vty, | |
5109 | " Thread Link State Request Retransmission %s\n", | |
5110 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5111 | ||
5112 | /* Show Link State Update Retransmission thread. */ | |
5113 | if (use_json) { | |
5114 | if (nbr->t_ls_upd != NULL) | |
5115 | json_object_string_add( | |
cb0b2ac6 CS |
5116 | json_neigh, |
5117 | "threadLinkStateUpdateRetransmission", | |
d62a17ae | 5118 | "on"); |
5119 | } else | |
5120 | vty_out(vty, | |
5121 | " Thread Link State Update Retransmission %s\n\n", | |
5122 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5123 | ||
cb0b2ac6 CS |
5124 | ospf_bfd_show_info(vty, nbr->bfd_info, json_neigh, use_json, 0); |
5125 | ||
5126 | if (use_json) | |
5127 | json_object_array_add(json_neigh_array, json_neigh); | |
d62a17ae | 5128 | |
d62a17ae | 5129 | } |
5130 | ||
5131 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5132 | struct in_addr *router_id, |
9f049418 | 5133 | bool use_json, uint8_t use_vrf) |
d62a17ae | 5134 | { |
5135 | struct listnode *node; | |
5136 | struct ospf_neighbor *nbr; | |
5137 | struct ospf_interface *oi; | |
d62a17ae | 5138 | json_object *json = NULL; |
5139 | ||
5140 | if (use_json) | |
5141 | json = json_object_new_object(); | |
5142 | ||
5143 | if (ospf->instance) { | |
5144 | if (use_json) | |
5145 | json_object_int_add(json, "ospfInstance", | |
5146 | ospf->instance); | |
5147 | else | |
5148 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5149 | } | |
5150 | ||
b1c3ae8c | 5151 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5152 | |
d62a17ae | 5153 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5154 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
cb0b2ac6 CS |
5155 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5156 | json, use_json); | |
d62a17ae | 5157 | } |
5158 | } | |
5159 | ||
5160 | if (use_json) { | |
9d303b37 DL |
5161 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5162 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5163 | json_object_free(json); |
5164 | } else | |
5165 | vty_out(vty, "\n"); | |
5166 | ||
5167 | return CMD_SUCCESS; | |
718e3744 | 5168 | } |
5169 | ||
986b87cb | 5170 | DEFPY (show_ip_ospf_neighbor_id, |
7c8ff89e | 5171 | show_ip_ospf_neighbor_id_cmd, |
986b87cb | 5172 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", |
718e3744 | 5173 | SHOW_STR |
5174 | IP_STR | |
5175 | "OSPF information\n" | |
5176 | "Neighbor list\n" | |
3ac237f8 | 5177 | "Neighbor ID\n" |
9973d184 | 5178 | JSON_STR) |
718e3744 | 5179 | { |
d62a17ae | 5180 | struct ospf *ospf; |
986b87cb | 5181 | struct listnode *node; |
b5a8894d | 5182 | int ret = CMD_SUCCESS; |
7c8ff89e | 5183 | |
b5a8894d CS |
5184 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5185 | if (!ospf->oi_running) | |
5186 | continue; | |
986b87cb RW |
5187 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
5188 | !!json, 0); | |
b5a8894d | 5189 | } |
7c8ff89e | 5190 | |
b5a8894d | 5191 | return ret; |
7c8ff89e DS |
5192 | } |
5193 | ||
986b87cb | 5194 | DEFPY (show_ip_ospf_instance_neighbor_id, |
7c8ff89e | 5195 | show_ip_ospf_instance_neighbor_id_cmd, |
986b87cb | 5196 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", |
7c8ff89e DS |
5197 | SHOW_STR |
5198 | IP_STR | |
5199 | "OSPF information\n" | |
5200 | "Instance ID\n" | |
5201 | "Neighbor list\n" | |
3ac237f8 | 5202 | "Neighbor ID\n" |
9973d184 | 5203 | JSON_STR) |
7c8ff89e | 5204 | { |
d62a17ae | 5205 | struct ospf *ospf; |
7c8ff89e | 5206 | |
ac28e4ec CS |
5207 | ospf = ospf_lookup_instance(instance); |
5208 | if (ospf == NULL) | |
5209 | return CMD_NOT_MY_INSTANCE; | |
5210 | ||
5211 | if (!ospf->oi_running) | |
d62a17ae | 5212 | return CMD_SUCCESS; |
7c8ff89e | 5213 | |
986b87cb RW |
5214 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, |
5215 | 0); | |
7c8ff89e DS |
5216 | } |
5217 | ||
d62a17ae | 5218 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5219 | struct ospf *ospf, | |
9f049418 | 5220 | json_object *json, bool use_json, |
d7c0a89a | 5221 | uint8_t use_vrf) |
d62a17ae | 5222 | { |
5223 | struct ospf_interface *oi; | |
5224 | struct listnode *node; | |
b1c3ae8c | 5225 | json_object *json_vrf = NULL; |
cb0b2ac6 | 5226 | json_object *json_nbr_sub = NULL; |
d62a17ae | 5227 | |
b1c3ae8c CS |
5228 | if (use_json) { |
5229 | if (use_vrf) | |
5230 | json_vrf = json_object_new_object(); | |
5231 | else | |
5232 | json_vrf = json; | |
cb0b2ac6 CS |
5233 | |
5234 | json_nbr_sub = json_object_new_object(); | |
b1c3ae8c | 5235 | } |
cb0b2ac6 | 5236 | |
d62a17ae | 5237 | if (ospf->instance) { |
5238 | if (use_json) | |
cb0b2ac6 | 5239 | json_object_int_add(json, "ospfInstance", |
d62a17ae | 5240 | ospf->instance); |
5241 | else | |
5242 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5243 | } | |
5244 | ||
b1c3ae8c | 5245 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5246 | |
d62a17ae | 5247 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5248 | struct route_node *rn; | |
cb0b2ac6 | 5249 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5250 | |
5251 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5252 | if ((nbr = rn->info)) { | |
5253 | if (nbr != oi->nbr_self) { | |
5254 | if (nbr->state != NSM_Down) { | |
5255 | show_ip_ospf_neighbor_detail_sub( | |
cb0b2ac6 CS |
5256 | vty, oi, nbr, prev_nbr, |
5257 | json_nbr_sub, use_json); | |
d62a17ae | 5258 | } |
5259 | } | |
cb0b2ac6 | 5260 | prev_nbr = nbr; |
d62a17ae | 5261 | } |
5262 | } | |
5263 | } | |
5264 | ||
5265 | if (use_json) { | |
cb0b2ac6 CS |
5266 | json_object_object_add(json_vrf, "neighbors", |
5267 | json_nbr_sub); | |
b1c3ae8c CS |
5268 | if (use_vrf) { |
5269 | if (ospf->vrf_id == VRF_DEFAULT) | |
5270 | json_object_object_add(json, "default", | |
5271 | json_vrf); | |
5272 | else | |
5273 | json_object_object_add(json, ospf->name, | |
5274 | json_vrf); | |
5275 | } | |
d62a17ae | 5276 | } else |
5277 | vty_out(vty, "\n"); | |
5278 | ||
5279 | return CMD_SUCCESS; | |
718e3744 | 5280 | } |
5281 | ||
7c8ff89e DS |
5282 | DEFUN (show_ip_ospf_neighbor_detail, |
5283 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5284 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5285 | SHOW_STR |
5286 | IP_STR | |
5287 | "OSPF information\n" | |
b5a8894d CS |
5288 | VRF_CMD_HELP_STR |
5289 | "All VRFs\n" | |
718e3744 | 5290 | "Neighbor list\n" |
3ac237f8 | 5291 | "detail of all neighbors\n" |
9973d184 | 5292 | JSON_STR) |
718e3744 | 5293 | { |
d62a17ae | 5294 | struct ospf *ospf; |
9f049418 | 5295 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5296 | struct listnode *node = NULL; |
5297 | char *vrf_name = NULL; | |
2951a7a4 | 5298 | bool all_vrf = false; |
b5a8894d CS |
5299 | int ret = CMD_SUCCESS; |
5300 | int inst = 0; | |
5301 | int idx_vrf = 0; | |
d7c0a89a | 5302 | uint8_t use_vrf = 0; |
b1c3ae8c | 5303 | json_object *json = NULL; |
7c8ff89e | 5304 | |
43b8d1d8 | 5305 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5306 | |
b1c3ae8c CS |
5307 | if (uj) |
5308 | json = json_object_new_object(); | |
5309 | ||
b5a8894d CS |
5310 | /* vrf input is provided could be all or specific vrf*/ |
5311 | if (vrf_name) { | |
b1c3ae8c | 5312 | use_vrf = 1; |
b5a8894d CS |
5313 | if (all_vrf) { |
5314 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5315 | if (!ospf->oi_running) | |
5316 | continue; | |
996c9314 LB |
5317 | ret = show_ip_ospf_neighbor_detail_common( |
5318 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
5319 | } |
5320 | if (uj) { | |
5321 | vty_out(vty, "%s\n", | |
996c9314 LB |
5322 | json_object_to_json_string_ext( |
5323 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 5324 | json_object_free(json); |
b5a8894d | 5325 | } |
b1c3ae8c | 5326 | |
b5a8894d CS |
5327 | return ret; |
5328 | } | |
5329 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5330 | if (ospf == NULL || !ospf->oi_running) { |
5331 | if (uj) | |
5332 | json_object_free(json); | |
b5a8894d | 5333 | return CMD_SUCCESS; |
b1c3ae8c | 5334 | } |
b5a8894d CS |
5335 | } else { |
5336 | /* Display default ospf (instance 0) info */ | |
5337 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5338 | if (ospf == NULL || !ospf->oi_running) { |
5339 | if (uj) | |
5340 | json_object_free(json); | |
b5a8894d | 5341 | return CMD_SUCCESS; |
b1c3ae8c | 5342 | } |
b5a8894d CS |
5343 | } |
5344 | ||
b1c3ae8c CS |
5345 | if (ospf) { |
5346 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5347 | use_vrf); | |
5348 | if (uj) { | |
5349 | vty_out(vty, "%s\n", | |
996c9314 LB |
5350 | json_object_to_json_string_ext( |
5351 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5352 | } |
5353 | } | |
5354 | ||
5355 | if (uj) | |
5356 | json_object_free(json); | |
b5a8894d CS |
5357 | |
5358 | return ret; | |
7c8ff89e DS |
5359 | } |
5360 | ||
5361 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5362 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5363 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5364 | SHOW_STR |
5365 | IP_STR | |
5366 | "OSPF information\n" | |
5367 | "Instance ID\n" | |
5368 | "Neighbor list\n" | |
3ac237f8 | 5369 | "detail of all neighbors\n" |
9973d184 | 5370 | JSON_STR) |
7c8ff89e | 5371 | { |
d62a17ae | 5372 | int idx_number = 3; |
5373 | struct ospf *ospf; | |
d7c0a89a | 5374 | unsigned short instance = 0; |
9f049418 | 5375 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5376 | json_object *json = NULL; |
5377 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5378 | |
d62a17ae | 5379 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5380 | ospf = ospf_lookup_instance(instance); |
5381 | if (ospf == NULL) | |
5382 | return CMD_NOT_MY_INSTANCE; | |
5383 | ||
5384 | if (!ospf->oi_running) | |
d62a17ae | 5385 | return CMD_SUCCESS; |
7c8ff89e | 5386 | |
b1c3ae8c CS |
5387 | if (uj) |
5388 | json = json_object_new_object(); | |
5389 | ||
5390 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5391 | ||
5392 | if (uj) { | |
5393 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5394 | json, JSON_C_TO_STRING_PRETTY)); | |
5395 | json_object_free(json); | |
5396 | } | |
5397 | ||
5398 | return ret; | |
7c8ff89e DS |
5399 | } |
5400 | ||
d62a17ae | 5401 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5402 | struct ospf *ospf, | |
b1c3ae8c | 5403 | json_object *json, |
9f049418 | 5404 | bool use_json, |
d7c0a89a | 5405 | uint8_t use_vrf) |
d62a17ae | 5406 | { |
5407 | struct listnode *node; | |
5408 | struct ospf_interface *oi; | |
b1c3ae8c | 5409 | json_object *json_vrf = NULL; |
718e3744 | 5410 | |
b1c3ae8c CS |
5411 | if (use_json) { |
5412 | if (use_vrf) | |
5413 | json_vrf = json_object_new_object(); | |
5414 | else | |
5415 | json_vrf = json; | |
5416 | } | |
d62a17ae | 5417 | |
5418 | if (ospf->instance) { | |
5419 | if (use_json) | |
5420 | json_object_int_add(json, "ospfInstance", | |
5421 | ospf->instance); | |
5422 | else | |
5423 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5424 | } | |
5425 | ||
b1c3ae8c | 5426 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5427 | |
d62a17ae | 5428 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5429 | struct route_node *rn; | |
cb0b2ac6 | 5430 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5431 | struct ospf_nbr_nbma *nbr_nbma; |
5432 | ||
cb0b2ac6 CS |
5433 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5434 | if ((nbr = rn->info)) { | |
d62a17ae | 5435 | if (nbr != oi->nbr_self) |
5436 | if (nbr->state != NSM_Down) | |
5437 | show_ip_ospf_neighbor_detail_sub( | |
5438 | vty, oi, rn->info, | |
cb0b2ac6 | 5439 | prev_nbr, |
b1c3ae8c | 5440 | json_vrf, use_json); |
cb0b2ac6 CS |
5441 | prev_nbr = nbr; |
5442 | } | |
5443 | } | |
d62a17ae | 5444 | |
5445 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5446 | struct listnode *nd; | |
5447 | ||
5448 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5449 | if (nbr_nbma->nbr == NULL | |
5450 | || nbr_nbma->nbr->state == NSM_Down) | |
5451 | show_ip_ospf_nbr_nbma_detail_sub( | |
5452 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5453 | json_vrf); |
d62a17ae | 5454 | } |
5455 | } | |
5456 | } | |
5457 | ||
5458 | if (use_json) { | |
b1c3ae8c CS |
5459 | if (use_vrf) { |
5460 | if (ospf->vrf_id == VRF_DEFAULT) | |
5461 | json_object_object_add(json, "default", | |
5462 | json_vrf); | |
5463 | else | |
5464 | json_object_object_add(json, ospf->name, | |
5465 | json_vrf); | |
5466 | } | |
d62a17ae | 5467 | } else { |
5468 | vty_out(vty, "\n"); | |
5469 | } | |
5470 | ||
5471 | return CMD_SUCCESS; | |
718e3744 | 5472 | } |
5473 | ||
7c8ff89e DS |
5474 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5475 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5476 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5477 | SHOW_STR |
5478 | IP_STR | |
5479 | "OSPF information\n" | |
b5a8894d CS |
5480 | VRF_CMD_HELP_STR |
5481 | "All VRFs\n" | |
718e3744 | 5482 | "Neighbor list\n" |
7c8ff89e | 5483 | "detail of all neighbors\n" |
3ac237f8 | 5484 | "include down status neighbor\n" |
9973d184 | 5485 | JSON_STR) |
718e3744 | 5486 | { |
d62a17ae | 5487 | struct ospf *ospf; |
9f049418 | 5488 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5489 | struct listnode *node = NULL; |
5490 | char *vrf_name = NULL; | |
2951a7a4 | 5491 | bool all_vrf = false; |
b5a8894d CS |
5492 | int ret = CMD_SUCCESS; |
5493 | int inst = 0; | |
5494 | int idx_vrf = 0; | |
d7c0a89a | 5495 | uint8_t use_vrf = 0; |
b1c3ae8c | 5496 | json_object *json = NULL; |
7c8ff89e | 5497 | |
43b8d1d8 | 5498 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5499 | |
b1c3ae8c CS |
5500 | if (uj) |
5501 | json = json_object_new_object(); | |
5502 | ||
b5a8894d CS |
5503 | /* vrf input is provided could be all or specific vrf*/ |
5504 | if (vrf_name) { | |
b1c3ae8c | 5505 | use_vrf = 1; |
b5a8894d CS |
5506 | if (all_vrf) { |
5507 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5508 | if (!ospf->oi_running) | |
5509 | continue; | |
996c9314 LB |
5510 | ret = show_ip_ospf_neighbor_detail_all_common( |
5511 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5512 | } |
b1c3ae8c CS |
5513 | |
5514 | if (uj) { | |
5515 | vty_out(vty, "%s\n", | |
996c9314 LB |
5516 | json_object_to_json_string_ext( |
5517 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5518 | json_object_free(json); |
5519 | } | |
5520 | ||
b5a8894d CS |
5521 | return ret; |
5522 | } | |
5523 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5524 | if (ospf == NULL || !ospf->oi_running) { |
5525 | if (uj) | |
5526 | json_object_free(json); | |
b5a8894d | 5527 | return CMD_SUCCESS; |
b1c3ae8c | 5528 | } |
b5a8894d CS |
5529 | } else { |
5530 | /* Display default ospf (instance 0) info */ | |
5531 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5532 | if (ospf == NULL || !ospf->oi_running) { |
5533 | if (uj) | |
5534 | json_object_free(json); | |
b5a8894d | 5535 | return CMD_SUCCESS; |
b1c3ae8c | 5536 | } |
b5a8894d CS |
5537 | } |
5538 | ||
b1c3ae8c CS |
5539 | if (ospf) { |
5540 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5541 | uj, use_vrf); | |
5542 | if (uj) { | |
5543 | vty_out(vty, "%s\n", | |
996c9314 LB |
5544 | json_object_to_json_string_ext( |
5545 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5546 | } |
5547 | } | |
5548 | ||
5549 | if (uj) | |
5550 | json_object_free(json); | |
b5a8894d CS |
5551 | |
5552 | return ret; | |
7c8ff89e DS |
5553 | } |
5554 | ||
5555 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5556 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5557 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5558 | SHOW_STR |
5559 | IP_STR | |
5560 | "OSPF information\n" | |
5561 | "Instance ID\n" | |
5562 | "Neighbor list\n" | |
5563 | "detail of all neighbors\n" | |
3ac237f8 | 5564 | "include down status neighbor\n" |
9973d184 | 5565 | JSON_STR) |
7c8ff89e | 5566 | { |
d62a17ae | 5567 | int idx_number = 3; |
5568 | struct ospf *ospf; | |
d7c0a89a | 5569 | unsigned short instance = 0; |
9f049418 | 5570 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5571 | json_object *json = NULL; |
5572 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5573 | |
d62a17ae | 5574 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5575 | ospf = ospf_lookup_instance(instance); |
5576 | if (ospf == NULL) | |
5577 | return CMD_NOT_MY_INSTANCE; | |
5578 | ||
5579 | if (!ospf->oi_running) | |
d62a17ae | 5580 | return CMD_SUCCESS; |
7c8ff89e | 5581 | |
b1c3ae8c CS |
5582 | if (uj) |
5583 | json = json_object_new_object(); | |
5584 | ||
5585 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5586 | ||
5587 | if (uj) { | |
996c9314 LB |
5588 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5589 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5590 | json_object_free(json); |
5591 | } | |
5592 | ||
5593 | return ret; | |
7c8ff89e DS |
5594 | } |
5595 | ||
d62a17ae | 5596 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5597 | struct ospf *ospf, | |
5598 | int arg_base, | |
5599 | struct cmd_token **argv, | |
9f049418 | 5600 | bool use_json) |
d62a17ae | 5601 | { |
5602 | struct ospf_interface *oi; | |
5603 | struct interface *ifp; | |
5604 | struct route_node *rn, *nrn; | |
5605 | struct ospf_neighbor *nbr; | |
5606 | json_object *json = NULL; | |
718e3744 | 5607 | |
d62a17ae | 5608 | if (use_json) |
5609 | json = json_object_new_object(); | |
5610 | ||
5611 | if (ospf->instance) { | |
5612 | if (use_json) | |
5613 | json_object_int_add(json, "ospfInstance", | |
5614 | ospf->instance); | |
5615 | else | |
5616 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5617 | } | |
5618 | ||
a36898e7 | 5619 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5620 | if (!ifp) { |
5621 | if (!use_json) | |
5622 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5623 | else { |
5624 | vty_out(vty, "{}\n"); | |
5625 | json_object_free(json); | |
5626 | } | |
d62a17ae | 5627 | return CMD_WARNING; |
5628 | } | |
5629 | ||
5630 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5631 | if ((oi = rn->info)) { | |
5632 | for (nrn = route_top(oi->nbrs); nrn; | |
5633 | nrn = route_next(nrn)) { | |
5634 | if ((nbr = nrn->info)) { | |
5635 | if (nbr != oi->nbr_self) { | |
5636 | if (nbr->state != NSM_Down) | |
5637 | show_ip_ospf_neighbor_detail_sub( | |
5638 | vty, oi, nbr, | |
cb0b2ac6 | 5639 | NULL, |
b1c3ae8c | 5640 | json, use_json); |
d62a17ae | 5641 | } |
5642 | } | |
5643 | } | |
5644 | } | |
5645 | } | |
5646 | ||
5647 | if (use_json) { | |
9d303b37 DL |
5648 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5649 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5650 | json_object_free(json); |
5651 | } else | |
5652 | vty_out(vty, "\n"); | |
5653 | ||
5654 | return CMD_SUCCESS; | |
718e3744 | 5655 | } |
5656 | ||
7c8ff89e DS |
5657 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5658 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5659 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5660 | SHOW_STR |
5661 | IP_STR | |
5662 | "OSPF information\n" | |
5663 | "Neighbor list\n" | |
5664 | "Interface name\n" | |
3ac237f8 | 5665 | "detail of all neighbors\n" |
9973d184 | 5666 | JSON_STR) |
7c8ff89e | 5667 | { |
d62a17ae | 5668 | struct ospf *ospf; |
9f049418 | 5669 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5670 | struct listnode *node = NULL; |
5671 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5672 | bool ospf_output = false; |
7c8ff89e | 5673 | |
b5a8894d CS |
5674 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5675 | if (!ospf->oi_running) | |
5676 | continue; | |
2951a7a4 | 5677 | ospf_output = true; |
cb0b2ac6 | 5678 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, |
b5a8894d CS |
5679 | argv, uj); |
5680 | } | |
7c8ff89e | 5681 | |
9f049418 DS |
5682 | if (!ospf_output) |
5683 | vty_out(vty, "%% OSPF instance not found\n"); | |
5684 | ||
b5a8894d | 5685 | return ret; |
7c8ff89e DS |
5686 | } |
5687 | ||
5688 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5689 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5690 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5691 | SHOW_STR |
5692 | IP_STR | |
5693 | "OSPF information\n" | |
5694 | "Instance ID\n" | |
5695 | "Neighbor list\n" | |
5696 | "Interface name\n" | |
3ac237f8 | 5697 | "detail of all neighbors\n" |
9973d184 | 5698 | JSON_STR) |
7c8ff89e | 5699 | { |
d62a17ae | 5700 | int idx_number = 3; |
b4e84315 | 5701 | int idx_ifname = 5; |
d62a17ae | 5702 | struct ospf *ospf; |
d7c0a89a | 5703 | unsigned short instance = 0; |
9f049418 | 5704 | bool uj = use_json(argc, argv); |
7c8ff89e | 5705 | |
d62a17ae | 5706 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5707 | ospf = ospf_lookup_instance(instance); |
5708 | if (ospf == NULL) | |
5709 | return CMD_NOT_MY_INSTANCE; | |
5710 | ||
5711 | if (!ospf->oi_running) | |
d62a17ae | 5712 | return CMD_SUCCESS; |
7c8ff89e | 5713 | |
996c9314 LB |
5714 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5715 | argv, uj); | |
7c8ff89e | 5716 | } |
6b0655a2 | 5717 | |
718e3744 | 5718 | /* Show functions */ |
d62a17ae | 5719 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) |
5720 | { | |
5721 | struct router_lsa *rl; | |
5722 | struct summary_lsa *sl; | |
5723 | struct as_external_lsa *asel; | |
5724 | struct prefix_ipv4 p; | |
5725 | ||
5726 | if (lsa != NULL) | |
5727 | /* If self option is set, check LSA self flag. */ | |
5728 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
5729 | /* LSA common part show. */ | |
5730 | vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id)); | |
5731 | vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", | |
5732 | inet_ntoa(lsa->data->adv_router), LS_AGE(lsa), | |
d7c0a89a | 5733 | (unsigned long)ntohl(lsa->data->ls_seqnum), |
d62a17ae | 5734 | ntohs(lsa->data->checksum)); |
5735 | /* LSA specific part show. */ | |
5736 | switch (lsa->data->type) { | |
5737 | case OSPF_ROUTER_LSA: | |
5738 | rl = (struct router_lsa *)lsa->data; | |
5739 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5740 | break; | |
5741 | case OSPF_SUMMARY_LSA: | |
5742 | sl = (struct summary_lsa *)lsa->data; | |
5743 | ||
5744 | p.family = AF_INET; | |
5745 | p.prefix = sl->header.id; | |
5746 | p.prefixlen = ip_masklen(sl->mask); | |
5747 | apply_mask_ipv4(&p); | |
5748 | ||
5749 | vty_out(vty, " %s/%d", inet_ntoa(p.prefix), | |
5750 | p.prefixlen); | |
5751 | break; | |
5752 | case OSPF_AS_EXTERNAL_LSA: | |
5753 | case OSPF_AS_NSSA_LSA: | |
5754 | asel = (struct as_external_lsa *)lsa->data; | |
5755 | ||
5756 | p.family = AF_INET; | |
5757 | p.prefix = asel->header.id; | |
5758 | p.prefixlen = ip_masklen(asel->mask); | |
5759 | apply_mask_ipv4(&p); | |
5760 | ||
5761 | vty_out(vty, " %s %s/%d [0x%lx]", | |
5762 | IS_EXTERNAL_METRIC(asel->e[0].tos) | |
5763 | ? "E2" | |
5764 | : "E1", | |
5765 | inet_ntoa(p.prefix), p.prefixlen, | |
d7c0a89a QY |
5766 | (unsigned long)ntohl( |
5767 | asel->e[0].route_tag)); | |
d62a17ae | 5768 | break; |
5769 | case OSPF_NETWORK_LSA: | |
5770 | case OSPF_ASBR_SUMMARY_LSA: | |
5771 | case OSPF_OPAQUE_LINK_LSA: | |
5772 | case OSPF_OPAQUE_AREA_LSA: | |
5773 | case OSPF_OPAQUE_AS_LSA: | |
5774 | default: | |
5775 | break; | |
5776 | } | |
5777 | vty_out(vty, "\n"); | |
5778 | } | |
718e3744 | 5779 | |
d62a17ae | 5780 | return 0; |
5781 | } | |
5782 | ||
2b64873d | 5783 | static const char *const show_database_desc[] = { |
d62a17ae | 5784 | "unknown", |
5785 | "Router Link States", | |
5786 | "Net Link States", | |
5787 | "Summary Link States", | |
5788 | "ASBR-Summary Link States", | |
5789 | "AS External Link States", | |
5790 | "Group Membership LSA", | |
5791 | "NSSA-external Link States", | |
5792 | "Type-8 LSA", | |
5793 | "Link-Local Opaque-LSA", | |
5794 | "Area-Local Opaque-LSA", | |
5795 | "AS-external Opaque-LSA", | |
718e3744 | 5796 | }; |
5797 | ||
2b64873d | 5798 | static const char *const show_database_header[] = { |
d62a17ae | 5799 | "", |
5800 | "Link ID ADV Router Age Seq# CkSum Link count", | |
5801 | "Link ID ADV Router Age Seq# CkSum", | |
5802 | "Link ID ADV Router Age Seq# CkSum Route", | |
5803 | "Link ID ADV Router Age Seq# CkSum", | |
5804 | "Link ID ADV Router Age Seq# CkSum Route", | |
5805 | " --- header for Group Member ----", | |
5806 | "Link ID ADV Router Age Seq# CkSum Route", | |
5807 | " --- type-8 ---", | |
5808 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5809 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5810 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 5811 | }; |
5812 | ||
d62a17ae | 5813 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa) |
5814 | { | |
5815 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
5816 | ||
5817 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
5818 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
5819 | ospf_options_dump(lsa->data->options)); | |
5820 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
5821 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" | |
5822 | : "")); | |
5823 | ||
5824 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
5825 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
5826 | ||
5827 | if (rlsa->flags) | |
5828 | vty_out(vty, " :%s%s%s%s", | |
5829 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "", | |
5830 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "", | |
5831 | IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint" | |
5832 | : "", | |
5833 | IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut" | |
5834 | : ""); | |
5835 | ||
5836 | vty_out(vty, "\n"); | |
5837 | } | |
5838 | vty_out(vty, " LS Type: %s\n", | |
5839 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
5840 | vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id), | |
5841 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL)); | |
5842 | vty_out(vty, " Advertising Router: %s\n", | |
5843 | inet_ntoa(lsa->data->adv_router)); | |
5844 | vty_out(vty, " LS Seq Number: %08lx\n", | |
d7c0a89a | 5845 | (unsigned long)ntohl(lsa->data->ls_seqnum)); |
d62a17ae | 5846 | vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum)); |
5847 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
5848 | } | |
5849 | ||
2b64873d | 5850 | static const char *const link_type_desc[] = { |
d62a17ae | 5851 | "(null)", |
5852 | "another Router (point-to-point)", | |
5853 | "a Transit Network", | |
5854 | "Stub Network", | |
5855 | "a Virtual Link", | |
718e3744 | 5856 | }; |
5857 | ||
2b64873d | 5858 | static const char *const link_id_desc[] = { |
d62a17ae | 5859 | "(null)", "Neighboring Router ID", "Designated Router address", |
5860 | "Net", "Neighboring Router ID", | |
718e3744 | 5861 | }; |
5862 | ||
2b64873d | 5863 | static const char *const link_data_desc[] = { |
d62a17ae | 5864 | "(null)", "Router Interface address", "Router Interface address", |
5865 | "Network Mask", "Router Interface address", | |
718e3744 | 5866 | }; |
5867 | ||
5868 | /* Show router-LSA each Link information. */ | |
d62a17ae | 5869 | static void show_ip_ospf_database_router_links(struct vty *vty, |
5870 | struct router_lsa *rl) | |
5871 | { | |
5872 | int len, type; | |
5873 | unsigned int i; | |
5874 | ||
5875 | len = ntohs(rl->header.length) - 4; | |
5876 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
5877 | type = rl->link[i].type; | |
5878 | ||
5879 | vty_out(vty, " Link connected to: %s\n", | |
5880 | link_type_desc[type]); | |
5881 | vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type], | |
5882 | inet_ntoa(rl->link[i].link_id)); | |
5883 | vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type], | |
5884 | inet_ntoa(rl->link[i].link_data)); | |
5885 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
5886 | vty_out(vty, " TOS 0 Metric: %d\n", | |
5887 | ntohs(rl->link[i].metric)); | |
5888 | vty_out(vty, "\n"); | |
5889 | } | |
718e3744 | 5890 | } |
5891 | ||
5892 | /* Show router-LSA detail information. */ | |
d62a17ae | 5893 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5894 | { |
d62a17ae | 5895 | if (lsa != NULL) { |
5896 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 5897 | |
d62a17ae | 5898 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5899 | |
d62a17ae | 5900 | vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links)); |
718e3744 | 5901 | |
d62a17ae | 5902 | show_ip_ospf_database_router_links(vty, rl); |
5903 | vty_out(vty, "\n"); | |
5904 | } | |
5905 | ||
5906 | return 0; | |
718e3744 | 5907 | } |
5908 | ||
5909 | /* Show network-LSA detail information. */ | |
d62a17ae | 5910 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5911 | { |
d62a17ae | 5912 | int length, i; |
718e3744 | 5913 | |
d62a17ae | 5914 | if (lsa != NULL) { |
5915 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
718e3744 | 5916 | |
d62a17ae | 5917 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5918 | |
d62a17ae | 5919 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask)); |
718e3744 | 5920 | |
d62a17ae | 5921 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; |
718e3744 | 5922 | |
d62a17ae | 5923 | for (i = 0; length > 0; i++, length -= 4) |
5924 | vty_out(vty, " Attached Router: %s\n", | |
5925 | inet_ntoa(nl->routers[i])); | |
718e3744 | 5926 | |
d62a17ae | 5927 | vty_out(vty, "\n"); |
5928 | } | |
718e3744 | 5929 | |
d62a17ae | 5930 | return 0; |
718e3744 | 5931 | } |
5932 | ||
5933 | /* Show summary-LSA detail information. */ | |
d62a17ae | 5934 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5935 | { |
d62a17ae | 5936 | if (lsa != NULL) { |
5937 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5938 | |
d62a17ae | 5939 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5940 | |
d62a17ae | 5941 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5942 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5943 | GET_METRIC(sl->metric)); | |
5944 | vty_out(vty, "\n"); | |
5945 | } | |
718e3744 | 5946 | |
d62a17ae | 5947 | return 0; |
718e3744 | 5948 | } |
5949 | ||
5950 | /* Show summary-ASBR-LSA detail information. */ | |
d62a17ae | 5951 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5952 | { |
d62a17ae | 5953 | if (lsa != NULL) { |
5954 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5955 | |
d62a17ae | 5956 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5957 | |
d62a17ae | 5958 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5959 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5960 | GET_METRIC(sl->metric)); | |
5961 | vty_out(vty, "\n"); | |
5962 | } | |
718e3744 | 5963 | |
d62a17ae | 5964 | return 0; |
718e3744 | 5965 | } |
5966 | ||
5967 | /* Show AS-external-LSA detail information. */ | |
d62a17ae | 5968 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5969 | { | |
5970 | if (lsa != NULL) { | |
5971 | struct as_external_lsa *al = | |
5972 | (struct as_external_lsa *)lsa->data; | |
5973 | ||
5974 | show_ip_ospf_database_header(vty, lsa); | |
5975 | ||
5976 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5977 | vty_out(vty, " Metric Type: %s\n", | |
5978 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5979 | ? "2 (Larger than any link state path)" | |
5980 | : "1"); | |
5981 | vty_out(vty, " TOS: 0\n"); | |
5982 | vty_out(vty, " Metric: %d\n", | |
5983 | GET_METRIC(al->e[0].metric)); | |
5984 | vty_out(vty, " Forward Address: %s\n", | |
5985 | inet_ntoa(al->e[0].fwd_addr)); | |
5986 | ||
5987 | vty_out(vty, | |
5988 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5989 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5990 | } | |
718e3744 | 5991 | |
d62a17ae | 5992 | return 0; |
718e3744 | 5993 | } |
075e12f5 | 5994 | #if 0 |
4dadc291 | 5995 | static int |
718e3744 | 5996 | show_as_external_lsa_stdvty (struct ospf_lsa *lsa) |
5997 | { | |
5998 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; | |
5999 | ||
6000 | /* show_ip_ospf_database_header (vty, lsa); */ | |
6001 | ||
2a42e285 | 6002 | zlog_debug( " Network Mask: /%d%s", |
718e3744 | 6003 | ip_masklen (al->mask), "\n"); |
2a42e285 | 6004 | zlog_debug( " Metric Type: %s%s", |
718e3744 | 6005 | IS_EXTERNAL_METRIC (al->e[0].tos) ? |
6006 | "2 (Larger than any link state path)" : "1", "\n"); | |
2a42e285 | 6007 | zlog_debug( " TOS: 0%s", "\n"); |
6008 | zlog_debug( " Metric: %d%s", | |
718e3744 | 6009 | GET_METRIC (al->e[0].metric), "\n"); |
2a42e285 | 6010 | zlog_debug( " Forward Address: %s%s", |
718e3744 | 6011 | inet_ntoa (al->e[0].fwd_addr), "\n"); |
6012 | ||
dc9ffce8 CF |
6013 | zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s", |
6014 | (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n"); | |
718e3744 | 6015 | |
6016 | return 0; | |
6017 | } | |
075e12f5 | 6018 | #endif |
718e3744 | 6019 | /* Show AS-NSSA-LSA detail information. */ |
d62a17ae | 6020 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
6021 | { | |
6022 | if (lsa != NULL) { | |
6023 | struct as_external_lsa *al = | |
6024 | (struct as_external_lsa *)lsa->data; | |
6025 | ||
6026 | show_ip_ospf_database_header(vty, lsa); | |
6027 | ||
6028 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
6029 | vty_out(vty, " Metric Type: %s\n", | |
6030 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6031 | ? "2 (Larger than any link state path)" | |
6032 | : "1"); | |
6033 | vty_out(vty, " TOS: 0\n"); | |
6034 | vty_out(vty, " Metric: %d\n", | |
6035 | GET_METRIC(al->e[0].metric)); | |
6036 | vty_out(vty, " NSSA: Forward Address: %s\n", | |
6037 | inet_ntoa(al->e[0].fwd_addr)); | |
6038 | ||
6039 | vty_out(vty, | |
6040 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6041 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6042 | } | |
718e3744 | 6043 | |
d62a17ae | 6044 | return 0; |
718e3744 | 6045 | } |
6046 | ||
d62a17ae | 6047 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 6048 | { |
d62a17ae | 6049 | return 0; |
718e3744 | 6050 | } |
6051 | ||
d62a17ae | 6052 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 6053 | { |
d62a17ae | 6054 | if (lsa != NULL) { |
6055 | show_ip_ospf_database_header(vty, lsa); | |
6056 | show_opaque_info_detail(vty, lsa); | |
718e3744 | 6057 | |
d62a17ae | 6058 | vty_out(vty, "\n"); |
6059 | } | |
6060 | return 0; | |
6061 | } | |
6062 | ||
2b64873d | 6063 | int (*const show_function[])(struct vty *, struct ospf_lsa *) = { |
d62a17ae | 6064 | NULL, |
6065 | show_router_lsa_detail, | |
6066 | show_network_lsa_detail, | |
6067 | show_summary_lsa_detail, | |
6068 | show_summary_asbr_lsa_detail, | |
6069 | show_as_external_lsa_detail, | |
6070 | show_func_dummy, | |
6071 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6072 | NULL, /* type-8 */ | |
6073 | show_opaque_lsa_detail, | |
6074 | show_opaque_lsa_detail, | |
6075 | show_opaque_lsa_detail, | |
6076 | }; | |
6077 | ||
6078 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6079 | struct in_addr *id, struct in_addr *adv_router) | |
6080 | { | |
6081 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6082 | lp->family = 0; | |
6083 | if (id == NULL) | |
6084 | lp->prefixlen = 0; | |
6085 | else if (adv_router == NULL) { | |
6086 | lp->prefixlen = 32; | |
6087 | lp->id = *id; | |
6088 | } else { | |
6089 | lp->prefixlen = 64; | |
6090 | lp->id = *id; | |
6091 | lp->adv_router = *adv_router; | |
6092 | } | |
718e3744 | 6093 | } |
718e3744 | 6094 | |
d62a17ae | 6095 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
6096 | struct in_addr *id, struct in_addr *adv_router) | |
6097 | { | |
6098 | struct prefix_ls lp; | |
6099 | struct route_node *rn, *start; | |
6100 | struct ospf_lsa *lsa; | |
718e3744 | 6101 | |
d62a17ae | 6102 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6103 | start = route_node_get(rt, (struct prefix *)&lp); | |
6104 | if (start) { | |
6105 | route_lock_node(start); | |
6106 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6107 | if ((lsa = rn->info)) { | |
6108 | if (show_function[lsa->data->type] != NULL) | |
6109 | show_function[lsa->data->type](vty, | |
6110 | lsa); | |
6111 | } | |
6112 | route_unlock_node(start); | |
6113 | } | |
718e3744 | 6114 | } |
6115 | ||
6116 | /* Show detail LSA information | |
6117 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6118 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
6119 | struct in_addr *id, struct in_addr *adv_router) | |
6120 | { | |
6121 | struct listnode *node; | |
6122 | struct ospf_area *area; | |
6123 | ||
6124 | switch (type) { | |
6125 | case OSPF_AS_EXTERNAL_LSA: | |
6126 | case OSPF_OPAQUE_AS_LSA: | |
6127 | vty_out(vty, " %s \n\n", | |
6128 | show_database_desc[type]); | |
6129 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router); | |
6130 | break; | |
6131 | default: | |
6132 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6133 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6134 | show_database_desc[type], | |
6135 | ospf_area_desc_string(area)); | |
6136 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, | |
6137 | adv_router); | |
6138 | } | |
6139 | break; | |
718e3744 | 6140 | } |
6141 | } | |
6142 | ||
d62a17ae | 6143 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6144 | struct route_table *rt, | |
6145 | struct in_addr *adv_router) | |
6146 | { | |
6147 | struct route_node *rn; | |
6148 | struct ospf_lsa *lsa; | |
6149 | ||
6150 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
6151 | if ((lsa = rn->info)) | |
6152 | if (IPV4_ADDR_SAME(adv_router, | |
6153 | &lsa->data->adv_router)) { | |
6154 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6155 | continue; | |
6156 | if (show_function[lsa->data->type] != NULL) | |
6157 | show_function[lsa->data->type](vty, | |
6158 | lsa); | |
6159 | } | |
6160 | } | |
6161 | ||
718e3744 | 6162 | /* Show detail LSA information. */ |
d62a17ae | 6163 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
6164 | int type, struct in_addr *adv_router) | |
6165 | { | |
6166 | struct listnode *node; | |
6167 | struct ospf_area *area; | |
6168 | ||
6169 | switch (type) { | |
6170 | case OSPF_AS_EXTERNAL_LSA: | |
6171 | case OSPF_OPAQUE_AS_LSA: | |
6172 | vty_out(vty, " %s \n\n", | |
6173 | show_database_desc[type]); | |
6174 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), | |
6175 | adv_router); | |
6176 | break; | |
6177 | default: | |
6178 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6179 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6180 | show_database_desc[type], | |
6181 | ospf_area_desc_string(area)); | |
6182 | show_lsa_detail_adv_router_proc( | |
6183 | vty, AREA_LSDB(area, type), adv_router); | |
6184 | } | |
6185 | break; | |
6186 | } | |
6187 | } | |
6188 | ||
6189 | static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, | |
6190 | int self) | |
6191 | { | |
6192 | struct ospf_lsa *lsa; | |
6193 | struct route_node *rn; | |
6194 | struct ospf_area *area; | |
6195 | struct listnode *node; | |
6196 | int type; | |
6197 | ||
6198 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6199 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6200 | switch (type) { | |
6201 | case OSPF_AS_EXTERNAL_LSA: | |
6202 | case OSPF_OPAQUE_AS_LSA: | |
6203 | continue; | |
6204 | default: | |
6205 | break; | |
6206 | } | |
6207 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6208 | || (!self | |
6209 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
6210 | vty_out(vty, " %s (Area %s)\n\n", | |
6211 | show_database_desc[type], | |
6212 | ospf_area_desc_string(area)); | |
6213 | vty_out(vty, "%s\n", | |
6214 | show_database_header[type]); | |
6215 | ||
996c9314 | 6216 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) |
044506e7 | 6217 | show_lsa_summary(vty, lsa, self); |
d62a17ae | 6218 | |
6219 | vty_out(vty, "\n"); | |
6220 | } | |
6221 | } | |
6222 | } | |
6223 | ||
6224 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6225 | switch (type) { | |
6226 | case OSPF_AS_EXTERNAL_LSA: | |
6227 | case OSPF_OPAQUE_AS_LSA: | |
6228 | break; | |
6229 | default: | |
6230 | continue; | |
6231 | } | |
6232 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6233 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
6234 | vty_out(vty, " %s\n\n", | |
6235 | show_database_desc[type]); | |
6236 | vty_out(vty, "%s\n", show_database_header[type]); | |
6237 | ||
996c9314 | 6238 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) |
044506e7 | 6239 | show_lsa_summary(vty, lsa, self); |
d62a17ae | 6240 | |
6241 | vty_out(vty, "\n"); | |
6242 | } | |
6243 | } | |
6244 | ||
6245 | vty_out(vty, "\n"); | |
6246 | } | |
6247 | ||
6248 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) | |
6249 | { | |
6250 | struct route_node *rn; | |
6251 | ||
6252 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6253 | ||
6254 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6255 | struct ospf_lsa *lsa; | |
6256 | ||
6257 | if ((lsa = rn->info) != NULL) { | |
6258 | vty_out(vty, "Link type: %d\n", lsa->data->type); | |
6259 | vty_out(vty, "Link State ID: %s\n", | |
6260 | inet_ntoa(lsa->data->id)); | |
6261 | vty_out(vty, "Advertising Router: %s\n", | |
6262 | inet_ntoa(lsa->data->adv_router)); | |
6263 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6264 | vty_out(vty, "\n"); | |
6265 | } | |
91e6a0e5 | 6266 | } |
718e3744 | 6267 | } |
6268 | ||
718e3744 | 6269 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6270 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6271 | |
718e3744 | 6272 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6273 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6274 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6275 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6276 | |
d62a17ae | 6277 | #define OSPF_LSA_TYPES_DESC \ |
6278 | "ASBR summary link states\n" \ | |
6279 | "External link states\n" \ | |
6280 | "Network link states\n" \ | |
6281 | "Router link states\n" \ | |
6282 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6283 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6284 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6285 | ||
6286 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6287 | int arg_base, int argc, | |
d7c0a89a QY |
6288 | struct cmd_token **argv, |
6289 | uint8_t use_vrf) | |
d62a17ae | 6290 | { |
6291 | int idx_type = 4; | |
6292 | int type, ret; | |
6293 | struct in_addr id, adv_router; | |
6294 | ||
6295 | if (ospf->instance) | |
6296 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6297 | ||
b1c3ae8c | 6298 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 6299 | |
d62a17ae | 6300 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6301 | inet_ntoa(ospf->router_id)); | |
6302 | ||
6303 | /* Show all LSA. */ | |
6304 | if (argc == arg_base + 4) { | |
6305 | show_ip_ospf_database_summary(vty, ospf, 0); | |
6306 | return CMD_SUCCESS; | |
6307 | } | |
718e3744 | 6308 | |
d62a17ae | 6309 | /* Set database type to show. */ |
6310 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6311 | type = OSPF_ROUTER_LSA; | |
6312 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6313 | type = OSPF_NETWORK_LSA; | |
6314 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6315 | type = OSPF_AS_NSSA_LSA; | |
6316 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
6317 | type = OSPF_SUMMARY_LSA; | |
6318 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6319 | type = OSPF_ASBR_SUMMARY_LSA; | |
6320 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6321 | type = OSPF_AS_EXTERNAL_LSA; | |
6322 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
6323 | show_ip_ospf_database_summary(vty, ospf, 1); | |
6324 | return CMD_SUCCESS; | |
6325 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
6326 | show_ip_ospf_database_maxage(vty, ospf); | |
6327 | return CMD_SUCCESS; | |
6328 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6329 | type = OSPF_OPAQUE_LINK_LSA; | |
6330 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6331 | type = OSPF_OPAQUE_AREA_LSA; | |
6332 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6333 | type = OSPF_OPAQUE_AS_LSA; | |
6334 | else | |
718e3744 | 6335 | return CMD_WARNING; |
d62a17ae | 6336 | |
6337 | /* `show ip ospf database LSA'. */ | |
6338 | if (argc == arg_base + 5) | |
6339 | show_lsa_detail(vty, ospf, type, NULL, NULL); | |
6340 | else if (argc >= arg_base + 6) { | |
6341 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
6342 | if (!ret) | |
6343 | return CMD_WARNING; | |
6344 | ||
6345 | /* `show ip ospf database LSA ID'. */ | |
6346 | if (argc == arg_base + 6) | |
6347 | show_lsa_detail(vty, ospf, type, &id, NULL); | |
6348 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ | |
6349 | else if (argc == arg_base + 7) { | |
6350 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) | |
6351 | adv_router = ospf->router_id; | |
6352 | else { | |
6353 | ret = inet_aton(argv[arg_base + 7]->arg, | |
6354 | &adv_router); | |
6355 | if (!ret) | |
6356 | return CMD_WARNING; | |
6357 | } | |
6358 | show_lsa_detail(vty, ospf, type, &id, &adv_router); | |
6359 | } | |
718e3744 | 6360 | } |
718e3744 | 6361 | |
d62a17ae | 6362 | return CMD_SUCCESS; |
718e3744 | 6363 | } |
6364 | ||
7a7be519 | 6365 | DEFUN (show_ip_ospf_database_max, |
6366 | show_ip_ospf_database_max_cmd, | |
b5a8894d | 6367 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>", |
7a7be519 | 6368 | SHOW_STR |
6369 | IP_STR | |
6370 | "OSPF information\n" | |
b5a8894d CS |
6371 | VRF_CMD_HELP_STR |
6372 | "All VRFs\n" | |
7a7be519 | 6373 | "Database summary\n" |
6374 | "LSAs in MaxAge list\n" | |
6375 | "Self-originated link states\n") | |
6376 | { | |
b5a8894d CS |
6377 | struct ospf *ospf = NULL; |
6378 | struct listnode *node = NULL; | |
6379 | char *vrf_name = NULL; | |
2951a7a4 | 6380 | bool all_vrf = false; |
b5a8894d CS |
6381 | int ret = CMD_SUCCESS; |
6382 | int inst = 0; | |
6383 | int idx_vrf = 0; | |
d7c0a89a | 6384 | uint8_t use_vrf = 0; |
f412b39a | 6385 | |
43b8d1d8 | 6386 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 6387 | |
b5a8894d | 6388 | if (vrf_name) { |
2951a7a4 | 6389 | bool ospf_output = false; |
874f58d8 | 6390 | |
b1c3ae8c | 6391 | use_vrf = 1; |
94d4c685 | 6392 | |
b5a8894d CS |
6393 | if (all_vrf) { |
6394 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6395 | if (!ospf->oi_running) | |
6396 | continue; | |
2951a7a4 | 6397 | ospf_output = true; |
996c9314 LB |
6398 | ret = show_ip_ospf_database_common( |
6399 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
6400 | use_vrf); | |
b5a8894d | 6401 | } |
9f049418 DS |
6402 | |
6403 | if (!ospf_output) | |
6404 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
6405 | } else { |
6406 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6407 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6408 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6409 | return CMD_SUCCESS; |
9f049418 | 6410 | } |
996c9314 LB |
6411 | ret = (show_ip_ospf_database_common( |
6412 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
6413 | use_vrf)); | |
b5a8894d CS |
6414 | } |
6415 | } else { | |
6416 | /* Display default ospf (instance 0) info */ | |
6417 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6418 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6419 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6420 | return CMD_SUCCESS; |
9f049418 DS |
6421 | } |
6422 | ||
b1c3ae8c CS |
6423 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
6424 | use_vrf); | |
b5a8894d CS |
6425 | } |
6426 | ||
6427 | return ret; | |
7a7be519 | 6428 | } |
f412b39a | 6429 | |
f412b39a DW |
6430 | DEFUN (show_ip_ospf_instance_database, |
6431 | show_ip_ospf_instance_database_cmd, | |
43b8d1d8 | 6432 | "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 | 6433 | SHOW_STR |
6434 | IP_STR | |
6435 | "OSPF information\n" | |
7c8ff89e | 6436 | "Instance ID\n" |
b5a8894d | 6437 | VRF_CMD_HELP_STR |
7a7be519 | 6438 | "Database summary\n" |
6439 | OSPF_LSA_TYPES_DESC | |
6440 | "Link State ID (as an IP address)\n" | |
6441 | "Self-originated link states\n" | |
6442 | "Advertising Router link states\n" | |
6443 | "Advertising Router (as an IP address)\n") | |
7c8ff89e | 6444 | { |
d62a17ae | 6445 | struct ospf *ospf; |
d7c0a89a | 6446 | unsigned short instance = 0; |
b5a8894d CS |
6447 | struct listnode *node = NULL; |
6448 | char *vrf_name = NULL; | |
2951a7a4 | 6449 | bool all_vrf = false; |
b5a8894d CS |
6450 | int ret = CMD_SUCCESS; |
6451 | int inst = 0; | |
d62a17ae | 6452 | int idx = 0; |
d7c0a89a | 6453 | uint8_t use_vrf = 0; |
b5a8894d | 6454 | |
d62a17ae | 6455 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6456 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6457 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6458 | if (ospf == NULL) |
6459 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
6460 | if (!ospf->oi_running) |
6461 | return CMD_SUCCESS; | |
6462 | ||
6463 | return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, | |
b1c3ae8c | 6464 | argc, argv, use_vrf)); |
b5a8894d CS |
6465 | } else if (argv_find(argv, argc, "vrf", &idx)) { |
6466 | vrf_name = argv[++idx]->arg; | |
6467 | all_vrf = strmatch(vrf_name, "all"); | |
d62a17ae | 6468 | } |
7c8ff89e | 6469 | |
b5a8894d | 6470 | if (vrf_name) { |
b1c3ae8c | 6471 | use_vrf = 1; |
b5a8894d CS |
6472 | if (all_vrf) { |
6473 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6474 | if (!ospf->oi_running) | |
6475 | continue; | |
996c9314 LB |
6476 | ret = (show_ip_ospf_database_common( |
6477 | vty, ospf, idx ? 2 : 0, argc, argv, | |
6478 | use_vrf)); | |
b5a8894d CS |
6479 | } |
6480 | } else { | |
6481 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6482 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 6483 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6484 | return CMD_SUCCESS; |
9f049418 DS |
6485 | } |
6486 | ||
996c9314 LB |
6487 | ret = (show_ip_ospf_database_common( |
6488 | vty, ospf, idx ? 2 : 0, argc, argv, use_vrf)); | |
b5a8894d CS |
6489 | } |
6490 | } else { | |
6491 | /* Display default ospf (instance 0) info */ | |
6492 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6493 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6494 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6495 | return CMD_SUCCESS; |
9f049418 DS |
6496 | } |
6497 | ||
b1c3ae8c CS |
6498 | ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
6499 | use_vrf)); | |
b5a8894d | 6500 | } |
7c8ff89e | 6501 | |
b5a8894d | 6502 | return ret; |
7c8ff89e DS |
6503 | } |
6504 | ||
7a7be519 | 6505 | DEFUN (show_ip_ospf_instance_database_max, |
6506 | show_ip_ospf_instance_database_max_cmd, | |
6507 | "show ip ospf (1-65535) database <max-age|self-originate>", | |
6508 | SHOW_STR | |
6509 | IP_STR | |
6510 | "OSPF information\n" | |
6511 | "Instance ID\n" | |
6512 | "Database summary\n" | |
6513 | "LSAs in MaxAge list\n" | |
6514 | "Self-originated link states\n") | |
6515 | { | |
d62a17ae | 6516 | int idx_number = 3; |
6517 | struct ospf *ospf; | |
d7c0a89a | 6518 | unsigned short instance = 0; |
d62a17ae | 6519 | |
6520 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
6521 | ||
ac28e4ec CS |
6522 | ospf = ospf_lookup_instance(instance); |
6523 | if (ospf == NULL) | |
6524 | return CMD_NOT_MY_INSTANCE; | |
6525 | ||
9f049418 | 6526 | if (!ospf->oi_running) { |
94d4c685 | 6527 | vty_out(vty, "%% OSPF instance not found\n"); |
d62a17ae | 6528 | return CMD_SUCCESS; |
9f049418 | 6529 | } |
d62a17ae | 6530 | |
b1c3ae8c | 6531 | return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0); |
d62a17ae | 6532 | } |
6533 | ||
6534 | ||
6535 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
6536 | struct ospf *ospf, | |
6537 | int arg_base, int argc, | |
b1c3ae8c | 6538 | struct cmd_token **argv, |
d7c0a89a | 6539 | uint8_t use_vrf) |
d62a17ae | 6540 | { |
6541 | int idx_type = 4; | |
6542 | int type, ret; | |
6543 | struct in_addr adv_router; | |
6544 | ||
6545 | if (ospf->instance) | |
6546 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6547 | ||
b1c3ae8c | 6548 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 6549 | |
d62a17ae | 6550 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6551 | inet_ntoa(ospf->router_id)); | |
6552 | ||
6553 | /* Set database type to show. */ | |
6554 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6555 | type = OSPF_ROUTER_LSA; | |
6556 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6557 | type = OSPF_NETWORK_LSA; | |
6558 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6559 | type = OSPF_AS_NSSA_LSA; | |
6560 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
6561 | type = OSPF_SUMMARY_LSA; | |
6562 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6563 | type = OSPF_ASBR_SUMMARY_LSA; | |
6564 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6565 | type = OSPF_AS_EXTERNAL_LSA; | |
6566 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6567 | type = OSPF_OPAQUE_LINK_LSA; | |
6568 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6569 | type = OSPF_OPAQUE_AREA_LSA; | |
6570 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6571 | type = OSPF_OPAQUE_AS_LSA; | |
6572 | else | |
6573 | return CMD_WARNING; | |
7c8ff89e | 6574 | |
d62a17ae | 6575 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
6576 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
6577 | adv_router = ospf->router_id; | |
6578 | else { | |
6579 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
6580 | if (!ret) | |
6581 | return CMD_WARNING; | |
6582 | } | |
7c8ff89e | 6583 | |
d62a17ae | 6584 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router); |
7c8ff89e | 6585 | |
d62a17ae | 6586 | return CMD_SUCCESS; |
7c8ff89e DS |
6587 | } |
6588 | ||
7c8ff89e DS |
6589 | DEFUN (show_ip_ospf_instance_database_type_adv_router, |
6590 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
43b8d1d8 | 6591 | "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 |
6592 | SHOW_STR |
6593 | IP_STR | |
6594 | "OSPF information\n" | |
6595 | "Instance ID\n" | |
b5a8894d | 6596 | VRF_CMD_HELP_STR |
7c8ff89e DS |
6597 | "Database summary\n" |
6598 | OSPF_LSA_TYPES_DESC | |
6599 | "Advertising Router link states\n" | |
3a2d747c QY |
6600 | "Advertising Router (as an IP address)\n" |
6601 | "Self-originated link states\n") | |
7c8ff89e | 6602 | { |
b5a8894d | 6603 | struct ospf *ospf = NULL; |
d7c0a89a | 6604 | unsigned short instance = 0; |
b5a8894d CS |
6605 | struct listnode *node = NULL; |
6606 | char *vrf_name = NULL; | |
2951a7a4 | 6607 | bool all_vrf = false; |
b5a8894d CS |
6608 | int ret = CMD_SUCCESS; |
6609 | int inst = 0; | |
43b8d1d8 | 6610 | int idx = 0, idx_vrf = 0; |
d7c0a89a | 6611 | uint8_t use_vrf = 0; |
7c8ff89e | 6612 | |
d62a17ae | 6613 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6614 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6615 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6616 | if (ospf == NULL) |
6617 | return CMD_NOT_MY_INSTANCE; | |
9f049418 | 6618 | if (!ospf->oi_running) { |
94d4c685 | 6619 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6620 | return CMD_SUCCESS; |
9f049418 DS |
6621 | } |
6622 | ||
996c9314 LB |
6623 | return (show_ip_ospf_database_type_adv_router_common( |
6624 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf)); | |
b5a8894d | 6625 | } |
43b8d1d8 CS |
6626 | |
6627 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
6628 | ||
b5a8894d | 6629 | if (vrf_name) { |
2951a7a4 | 6630 | bool ospf_output = false; |
874f58d8 | 6631 | |
b1c3ae8c | 6632 | use_vrf = 1; |
94d4c685 | 6633 | |
b5a8894d CS |
6634 | if (all_vrf) { |
6635 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6636 | if (!ospf->oi_running) | |
6637 | continue; | |
2951a7a4 | 6638 | ospf_output = true; |
996c9314 LB |
6639 | ret = show_ip_ospf_database_type_adv_router_common( |
6640 | vty, ospf, idx ? 1 : 0, argc, argv, | |
6641 | use_vrf); | |
b5a8894d | 6642 | } |
9f049418 DS |
6643 | if (!ospf_output) |
6644 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
6645 | } else { |
6646 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6647 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 6648 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6649 | return CMD_SUCCESS; |
9f049418 DS |
6650 | } |
6651 | ||
996c9314 LB |
6652 | ret = show_ip_ospf_database_type_adv_router_common( |
6653 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf); | |
b5a8894d CS |
6654 | } |
6655 | } else { | |
6656 | /* Display default ospf (instance 0) info */ | |
6657 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6658 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6659 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6660 | return CMD_SUCCESS; |
9f049418 DS |
6661 | } |
6662 | ||
996c9314 LB |
6663 | ret = show_ip_ospf_database_type_adv_router_common( |
6664 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf); | |
b5a8894d CS |
6665 | } |
6666 | return ret; | |
6667 | /*return (show_ip_ospf_database_type_adv_router_common( | |
6668 | vty, ospf, idx ? 1 : 0, argc, argv));*/ | |
718e3744 | 6669 | } |
6670 | ||
718e3744 | 6671 | DEFUN (ip_ospf_authentication_args, |
6672 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6673 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 6674 | "IP Information\n" |
6675 | "OSPF interface commands\n" | |
6676 | "Enable authentication on this interface\n" | |
6677 | "Use null authentication\n" | |
6678 | "Use message-digest authentication\n" | |
7a7be519 | 6679 | "Address of interface\n") |
718e3744 | 6680 | { |
d62a17ae | 6681 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6682 | int idx_encryption = 3; | |
6683 | int idx_ipv4 = 4; | |
6684 | struct in_addr addr; | |
6685 | int ret; | |
6686 | struct ospf_if_params *params; | |
6687 | ||
6688 | params = IF_DEF_PARAMS(ifp); | |
6689 | ||
6690 | if (argc == 5) { | |
6691 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6692 | if (!ret) { | |
6693 | vty_out(vty, | |
6694 | "Please specify interface address by A.B.C.D\n"); | |
6695 | return CMD_WARNING_CONFIG_FAILED; | |
6696 | } | |
718e3744 | 6697 | |
d62a17ae | 6698 | params = ospf_get_if_params(ifp, addr); |
6699 | ospf_if_update_params(ifp, addr); | |
6700 | } | |
718e3744 | 6701 | |
d62a17ae | 6702 | /* Handle null authentication */ |
6703 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6704 | SET_IF_PARAM(params, auth_type); | |
6705 | params->auth_type = OSPF_AUTH_NULL; | |
6706 | return CMD_SUCCESS; | |
6707 | } | |
718e3744 | 6708 | |
d62a17ae | 6709 | /* Handle message-digest authentication */ |
6710 | if (argv[idx_encryption]->arg[0] == 'm') { | |
6711 | SET_IF_PARAM(params, auth_type); | |
6712 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6713 | return CMD_SUCCESS; | |
6714 | } | |
718e3744 | 6715 | |
d62a17ae | 6716 | vty_out(vty, "You shouldn't get here!\n"); |
6717 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 6718 | } |
6719 | ||
718e3744 | 6720 | DEFUN (ip_ospf_authentication, |
6721 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6722 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 6723 | "IP Information\n" |
6724 | "OSPF interface commands\n" | |
6725 | "Enable authentication on this interface\n" | |
efd7904e | 6726 | "Address of interface\n") |
718e3744 | 6727 | { |
d62a17ae | 6728 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6729 | int idx_ipv4 = 3; | |
6730 | struct in_addr addr; | |
6731 | int ret; | |
6732 | struct ospf_if_params *params; | |
6733 | ||
6734 | params = IF_DEF_PARAMS(ifp); | |
6735 | ||
6736 | if (argc == 4) { | |
6737 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6738 | if (!ret) { | |
6739 | vty_out(vty, | |
6740 | "Please specify interface address by A.B.C.D\n"); | |
6741 | return CMD_WARNING_CONFIG_FAILED; | |
6742 | } | |
6743 | ||
6744 | params = ospf_get_if_params(ifp, addr); | |
6745 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6746 | } |
6747 | ||
d62a17ae | 6748 | SET_IF_PARAM(params, auth_type); |
6749 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 6750 | |
d62a17ae | 6751 | return CMD_SUCCESS; |
718e3744 | 6752 | } |
6753 | ||
b4a039bf DS |
6754 | DEFUN (no_ip_ospf_authentication_args, |
6755 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6756 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
6757 | NO_STR |
6758 | "IP Information\n" | |
6759 | "OSPF interface commands\n" | |
6760 | "Enable authentication on this interface\n" | |
6761 | "Use null authentication\n" | |
6762 | "Use message-digest authentication\n" | |
efd7904e | 6763 | "Address of interface\n") |
b4a039bf | 6764 | { |
d62a17ae | 6765 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6766 | int idx_encryption = 4; | |
6767 | int idx_ipv4 = 5; | |
6768 | struct in_addr addr; | |
6769 | int ret; | |
6770 | struct ospf_if_params *params; | |
6771 | struct route_node *rn; | |
6772 | int auth_type; | |
6773 | ||
6774 | params = IF_DEF_PARAMS(ifp); | |
6775 | ||
6776 | if (argc == 6) { | |
6777 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6778 | if (!ret) { | |
6779 | vty_out(vty, | |
6780 | "Please specify interface address by A.B.C.D\n"); | |
6781 | return CMD_WARNING_CONFIG_FAILED; | |
6782 | } | |
b4a039bf | 6783 | |
d62a17ae | 6784 | params = ospf_lookup_if_params(ifp, addr); |
6785 | if (params == NULL) { | |
6786 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6787 | return CMD_WARNING_CONFIG_FAILED; | |
6788 | } | |
6789 | params->auth_type = OSPF_AUTH_NOTSET; | |
6790 | UNSET_IF_PARAM(params, auth_type); | |
6791 | if (params != IF_DEF_PARAMS(ifp)) { | |
6792 | ospf_free_if_params(ifp, addr); | |
6793 | ospf_if_update_params(ifp, addr); | |
6794 | } | |
6795 | } else { | |
6796 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6797 | auth_type = OSPF_AUTH_NULL; | |
6798 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
6799 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6800 | } else { | |
6801 | vty_out(vty, "Unexpected input encountered\n"); | |
6802 | return CMD_WARNING_CONFIG_FAILED; | |
6803 | } | |
6804 | /* | |
6805 | * Here we have a case where the user has entered | |
6806 | * 'no ip ospf authentication (null | message_digest )' | |
6807 | * we need to find if we have any ip addresses underneath it | |
6808 | * that | |
6809 | * correspond to the associated type. | |
6810 | */ | |
6811 | if (params->auth_type == auth_type) { | |
6812 | params->auth_type = OSPF_AUTH_NOTSET; | |
6813 | UNSET_IF_PARAM(params, auth_type); | |
6814 | } | |
6815 | ||
6816 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
6817 | rn = route_next(rn)) { | |
6818 | if ((params = rn->info)) { | |
6819 | if (params->auth_type == auth_type) { | |
6820 | params->auth_type = OSPF_AUTH_NOTSET; | |
6821 | UNSET_IF_PARAM(params, auth_type); | |
6822 | if (params != IF_DEF_PARAMS(ifp)) { | |
6823 | ospf_free_if_params( | |
6824 | ifp, rn->p.u.prefix4); | |
6825 | ospf_if_update_params( | |
6826 | ifp, rn->p.u.prefix4); | |
6827 | } | |
6828 | } | |
6829 | } | |
b4a039bf | 6830 | } |
b4a039bf | 6831 | } |
b4a039bf | 6832 | |
d62a17ae | 6833 | return CMD_SUCCESS; |
b4a039bf DS |
6834 | } |
6835 | ||
718e3744 | 6836 | DEFUN (no_ip_ospf_authentication, |
6837 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6838 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 6839 | NO_STR |
6840 | "IP Information\n" | |
6841 | "OSPF interface commands\n" | |
6842 | "Enable authentication on this interface\n" | |
efd7904e | 6843 | "Address of interface\n") |
718e3744 | 6844 | { |
d62a17ae | 6845 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6846 | int idx_ipv4 = 4; | |
6847 | struct in_addr addr; | |
6848 | int ret; | |
6849 | struct ospf_if_params *params; | |
6850 | struct route_node *rn; | |
6851 | ||
6852 | params = IF_DEF_PARAMS(ifp); | |
6853 | ||
6854 | if (argc == 5) { | |
6855 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6856 | if (!ret) { | |
6857 | vty_out(vty, | |
6858 | "Please specify interface address by A.B.C.D\n"); | |
6859 | return CMD_WARNING_CONFIG_FAILED; | |
6860 | } | |
718e3744 | 6861 | |
d62a17ae | 6862 | params = ospf_lookup_if_params(ifp, addr); |
6863 | if (params == NULL) { | |
6864 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6865 | return CMD_WARNING_CONFIG_FAILED; | |
6866 | } | |
718e3744 | 6867 | |
d62a17ae | 6868 | params->auth_type = OSPF_AUTH_NOTSET; |
6869 | UNSET_IF_PARAM(params, auth_type); | |
6870 | if (params != IF_DEF_PARAMS(ifp)) { | |
6871 | ospf_free_if_params(ifp, addr); | |
6872 | ospf_if_update_params(ifp, addr); | |
6873 | } | |
6874 | } else { | |
6875 | /* | |
6876 | * When a user enters 'no ip ospf authentication' | |
6877 | * We should remove all authentication types from | |
6878 | * the interface. | |
6879 | */ | |
6880 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6881 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
6882 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
6883 | params->auth_type = OSPF_AUTH_NOTSET; | |
6884 | UNSET_IF_PARAM(params, auth_type); | |
6885 | } | |
813d4307 | 6886 | |
d62a17ae | 6887 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
6888 | rn = route_next(rn)) { | |
6889 | if ((params = rn->info)) { | |
6890 | ||
6891 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6892 | || (params->auth_type | |
6893 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
6894 | || (params->auth_type | |
6895 | == OSPF_AUTH_SIMPLE)) { | |
6896 | params->auth_type = OSPF_AUTH_NOTSET; | |
6897 | UNSET_IF_PARAM(params, auth_type); | |
6898 | if (params != IF_DEF_PARAMS(ifp)) { | |
6899 | ospf_free_if_params( | |
6900 | ifp, rn->p.u.prefix4); | |
6901 | ospf_if_update_params( | |
6902 | ifp, rn->p.u.prefix4); | |
6903 | } | |
6904 | } | |
6905 | } | |
b4a039bf | 6906 | } |
b4a039bf | 6907 | } |
d62a17ae | 6908 | |
6909 | return CMD_SUCCESS; | |
718e3744 | 6910 | } |
6911 | ||
0d829fa7 | 6912 | |
718e3744 | 6913 | DEFUN (ip_ospf_authentication_key, |
6914 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 6915 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 6916 | "IP Information\n" |
6917 | "OSPF interface commands\n" | |
6918 | "Authentication password (key)\n" | |
6919 | "The OSPF password (key)\n" | |
efd7904e | 6920 | "Address of interface\n") |
718e3744 | 6921 | { |
d62a17ae | 6922 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6923 | int idx = 0; | |
6924 | struct in_addr addr; | |
6925 | struct ospf_if_params *params; | |
718e3744 | 6926 | |
d62a17ae | 6927 | params = IF_DEF_PARAMS(ifp); |
6928 | ||
6929 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6930 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6931 | vty_out(vty, | |
6932 | "Please specify interface address by A.B.C.D\n"); | |
6933 | return CMD_WARNING_CONFIG_FAILED; | |
6934 | } | |
718e3744 | 6935 | |
d62a17ae | 6936 | params = ospf_get_if_params(ifp, addr); |
6937 | ospf_if_update_params(ifp, addr); | |
6938 | } | |
718e3744 | 6939 | |
4d65d927 QY |
6940 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
6941 | sizeof(params->auth_simple)); | |
d62a17ae | 6942 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 6943 | |
d62a17ae | 6944 | return CMD_SUCCESS; |
718e3744 | 6945 | } |
6946 | ||
7a7be519 | 6947 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 6948 | ospf_authentication_key_cmd, |
0d829fa7 | 6949 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 6950 | "OSPF interface commands\n" |
baf9eaad | 6951 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 6952 | "Address of interface\n") |
718e3744 | 6953 | { |
d62a17ae | 6954 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 6955 | } |
6956 | ||
7a7be519 | 6957 | DEFUN (no_ip_ospf_authentication_key, |
6958 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
6959 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6960 | NO_STR | |
6961 | "IP Information\n" | |
6962 | "OSPF interface commands\n" | |
baf9eaad CS |
6963 | VLINK_HELPSTR_AUTH_SIMPLE |
6964 | "Address of interface\n") | |
7a7be519 | 6965 | { |
d62a17ae | 6966 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6967 | int idx = 0; | |
6968 | struct in_addr addr; | |
6969 | struct ospf_if_params *params; | |
6970 | params = IF_DEF_PARAMS(ifp); | |
6971 | ||
6972 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6973 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6974 | vty_out(vty, | |
6975 | "Please specify interface address by A.B.C.D\n"); | |
6976 | return CMD_WARNING_CONFIG_FAILED; | |
6977 | } | |
7a7be519 | 6978 | |
d62a17ae | 6979 | params = ospf_lookup_if_params(ifp, addr); |
6980 | if (params == NULL) | |
6981 | return CMD_SUCCESS; | |
7a7be519 | 6982 | } |
813d4307 | 6983 | |
d62a17ae | 6984 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
6985 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 6986 | |
d62a17ae | 6987 | if (params != IF_DEF_PARAMS(ifp)) { |
6988 | ospf_free_if_params(ifp, addr); | |
6989 | ospf_if_update_params(ifp, addr); | |
6990 | } | |
813d4307 | 6991 | |
d62a17ae | 6992 | return CMD_SUCCESS; |
7a7be519 | 6993 | } |
813d4307 | 6994 | |
0d829fa7 QY |
6995 | DEFUN_HIDDEN (no_ospf_authentication_key, |
6996 | no_ospf_authentication_key_authkey_addr_cmd, | |
6997 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6998 | NO_STR | |
6999 | "OSPF interface commands\n" | |
baf9eaad CS |
7000 | VLINK_HELPSTR_AUTH_SIMPLE |
7001 | "Address of interface\n") | |
0d829fa7 | 7002 | { |
d62a17ae | 7003 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
7004 | } |
7005 | ||
718e3744 | 7006 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 7007 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 7008 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 7009 | "IP Information\n" |
7010 | "OSPF interface commands\n" | |
7011 | "Message digest authentication password (key)\n" | |
7012 | "Key ID\n" | |
7013 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
7014 | "The OSPF password (key)\n" |
7015 | "Address of interface\n") | |
718e3744 | 7016 | { |
d62a17ae | 7017 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7018 | struct crypt_key *ck; | |
d7c0a89a | 7019 | uint8_t key_id; |
d62a17ae | 7020 | struct in_addr addr; |
7021 | struct ospf_if_params *params; | |
7022 | ||
7023 | params = IF_DEF_PARAMS(ifp); | |
7024 | int idx = 0; | |
7025 | ||
7026 | argv_find(argv, argc, "(1-255)", &idx); | |
7027 | char *keyid = argv[idx]->arg; | |
7028 | argv_find(argv, argc, "KEY", &idx); | |
7029 | char *cryptkey = argv[idx]->arg; | |
7030 | ||
7031 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7032 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7033 | vty_out(vty, | |
7034 | "Please specify interface address by A.B.C.D\n"); | |
7035 | return CMD_WARNING_CONFIG_FAILED; | |
7036 | } | |
7037 | ||
7038 | params = ospf_get_if_params(ifp, addr); | |
7039 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7040 | } |
7041 | ||
d62a17ae | 7042 | key_id = strtol(keyid, NULL, 10); |
7043 | if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) { | |
7044 | vty_out(vty, "OSPF: Key %d already exists\n", key_id); | |
851fcbae | 7045 | return CMD_WARNING; |
d62a17ae | 7046 | } |
718e3744 | 7047 | |
d62a17ae | 7048 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7049 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7050 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7051 | |
d62a17ae | 7052 | ospf_crypt_key_add(params->auth_crypt, ck); |
7053 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7054 | |
d62a17ae | 7055 | return CMD_SUCCESS; |
718e3744 | 7056 | } |
7057 | ||
7a7be519 | 7058 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7059 | ospf_message_digest_key_cmd, |
0d829fa7 | 7060 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7061 | "OSPF interface commands\n" |
7062 | "Message digest authentication password (key)\n" | |
7063 | "Key ID\n" | |
7064 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7065 | "The OSPF password (key)\n" |
7066 | "Address of interface\n") | |
7a7be519 | 7067 | { |
d62a17ae | 7068 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7069 | } |
718e3744 | 7070 | |
537eae3f QY |
7071 | DEFUN (no_ip_ospf_message_digest_key, |
7072 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7073 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7074 | NO_STR |
7075 | "IP Information\n" | |
7076 | "OSPF interface commands\n" | |
7077 | "Message digest authentication password (key)\n" | |
7078 | "Key ID\n" | |
7079 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7080 | "The OSPF password (key)\n" |
7081 | "Address of interface\n") | |
813d4307 | 7082 | { |
d62a17ae | 7083 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7084 | int idx = 0; | |
7085 | struct crypt_key *ck; | |
7086 | int key_id; | |
7087 | struct in_addr addr; | |
7088 | struct ospf_if_params *params; | |
7089 | params = IF_DEF_PARAMS(ifp); | |
7090 | ||
7091 | argv_find(argv, argc, "(1-255)", &idx); | |
7092 | char *keyid = argv[idx]->arg; | |
7093 | ||
7094 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7095 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7096 | vty_out(vty, | |
7097 | "Please specify interface address by A.B.C.D\n"); | |
7098 | return CMD_WARNING_CONFIG_FAILED; | |
7099 | } | |
7a7be519 | 7100 | |
d62a17ae | 7101 | params = ospf_lookup_if_params(ifp, addr); |
7102 | if (params == NULL) | |
7103 | return CMD_SUCCESS; | |
7a7be519 | 7104 | } |
7105 | ||
d62a17ae | 7106 | key_id = strtol(keyid, NULL, 10); |
7107 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7108 | if (ck == NULL) { | |
7109 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7110 | return CMD_WARNING_CONFIG_FAILED; | |
7111 | } | |
7a7be519 | 7112 | |
d62a17ae | 7113 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7114 | |
d62a17ae | 7115 | if (params != IF_DEF_PARAMS(ifp)) { |
7116 | ospf_free_if_params(ifp, addr); | |
7117 | ospf_if_update_params(ifp, addr); | |
7118 | } | |
7a7be519 | 7119 | |
d62a17ae | 7120 | return CMD_SUCCESS; |
7a7be519 | 7121 | } |
813d4307 | 7122 | |
0d829fa7 | 7123 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7124 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7125 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7126 | NO_STR | |
7127 | "OSPF interface commands\n" | |
7128 | "Message digest authentication password (key)\n" | |
7129 | "Key ID\n" | |
efd7904e RW |
7130 | "Use MD5 algorithm\n" |
7131 | "The OSPF password (key)\n" | |
7132 | "Address of interface\n") | |
718e3744 | 7133 | { |
d62a17ae | 7134 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7135 | } |
7136 | ||
718e3744 | 7137 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7138 | ip_ospf_cost_cmd, |
7a7be519 | 7139 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7140 | "IP Information\n" |
7141 | "OSPF interface commands\n" | |
7142 | "Interface cost\n" | |
7143 | "Cost\n" | |
5c2fc921 | 7144 | "Address of interface\n") |
718e3744 | 7145 | { |
d62a17ae | 7146 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7147 | int idx = 0; | |
d7c0a89a | 7148 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7149 | struct in_addr addr; |
7150 | struct ospf_if_params *params; | |
7151 | params = IF_DEF_PARAMS(ifp); | |
7152 | ||
7153 | // get arguments | |
7154 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7155 | |
c31a793b VJ |
7156 | argv_find(argv, argc, "(1-65535)", &idx); |
7157 | coststr = argv[idx]->arg; | |
d62a17ae | 7158 | cost = strtol(coststr, NULL, 10); |
7159 | ||
c31a793b | 7160 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7161 | if (ifaddr) { |
7162 | if (!inet_aton(ifaddr, &addr)) { | |
7163 | vty_out(vty, | |
7164 | "Please specify interface address by A.B.C.D\n"); | |
7165 | return CMD_WARNING_CONFIG_FAILED; | |
7166 | } | |
718e3744 | 7167 | |
d62a17ae | 7168 | params = ospf_get_if_params(ifp, addr); |
7169 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7170 | } |
7171 | ||
d62a17ae | 7172 | SET_IF_PARAM(params, output_cost_cmd); |
7173 | params->output_cost_cmd = cost; | |
718e3744 | 7174 | |
d62a17ae | 7175 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 7176 | |
d62a17ae | 7177 | return CMD_SUCCESS; |
718e3744 | 7178 | } |
7179 | ||
7a7be519 | 7180 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
7181 | ospf_cost_cmd, |
7182 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
7183 | "OSPF interface commands\n" |
7184 | "Interface cost\n" | |
7185 | "Cost\n" | |
5c2fc921 | 7186 | "Address of interface\n") |
7a7be519 | 7187 | { |
d62a17ae | 7188 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 7189 | } |
9eff36b3 | 7190 | |
718e3744 | 7191 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
7192 | no_ip_ospf_cost_cmd, |
7193 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 7194 | NO_STR |
efd7904e | 7195 | "IP Information\n" |
718e3744 | 7196 | "OSPF interface commands\n" |
7197 | "Interface cost\n" | |
efd7904e RW |
7198 | "Cost\n" |
7199 | "Address of interface\n") | |
718e3744 | 7200 | { |
d62a17ae | 7201 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7202 | int idx = 0; | |
7203 | struct in_addr addr; | |
7204 | struct ospf_if_params *params; | |
7a7be519 | 7205 | |
d62a17ae | 7206 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7207 | |
d62a17ae | 7208 | // get arguments |
7209 | char *ifaddr = NULL; | |
7210 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 7211 | |
d62a17ae | 7212 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
7213 | * always treated as "no ip ospf cost" regardless of the actual value | |
7214 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 7215 | |
d62a17ae | 7216 | if (ifaddr) { |
7217 | if (!inet_aton(ifaddr, &addr)) { | |
7218 | vty_out(vty, | |
7219 | "Please specify interface address by A.B.C.D\n"); | |
7220 | return CMD_WARNING_CONFIG_FAILED; | |
7221 | } | |
7a7be519 | 7222 | |
d62a17ae | 7223 | params = ospf_lookup_if_params(ifp, addr); |
7224 | if (params == NULL) | |
7225 | return CMD_SUCCESS; | |
7226 | } | |
7a7be519 | 7227 | |
d62a17ae | 7228 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 7229 | |
d62a17ae | 7230 | if (params != IF_DEF_PARAMS(ifp)) { |
7231 | ospf_free_if_params(ifp, addr); | |
7232 | ospf_if_update_params(ifp, addr); | |
7233 | } | |
7a7be519 | 7234 | |
d62a17ae | 7235 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 7236 | |
d62a17ae | 7237 | return CMD_SUCCESS; |
7a7be519 | 7238 | } |
9eff36b3 | 7239 | |
5c2fc921 QY |
7240 | DEFUN_HIDDEN (no_ospf_cost, |
7241 | no_ospf_cost_cmd, | |
7242 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
7243 | NO_STR | |
7244 | "OSPF interface commands\n" | |
7245 | "Interface cost\n" | |
7246 | "Cost\n" | |
7247 | "Address of interface\n") | |
827341b7 | 7248 | { |
d62a17ae | 7249 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
7250 | } |
7251 | ||
d62a17ae | 7252 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 7253 | { |
d62a17ae | 7254 | struct route_node *rn; |
7255 | struct ospf_neighbor *nbr; | |
718e3744 | 7256 | |
d62a17ae | 7257 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
7258 | if ((nbr = rn->info)) { | |
7259 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
7260 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
7261 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
7262 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
7263 | } | |
718e3744 | 7264 | } |
7265 | ||
d62a17ae | 7266 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
7267 | const char *nbr_str, | |
7268 | const char *fast_hello_str) | |
7269 | { | |
7270 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
7271 | uint32_t seconds; |
7272 | uint8_t hellomult; | |
d62a17ae | 7273 | struct in_addr addr; |
7274 | int ret; | |
7275 | struct ospf_if_params *params; | |
7276 | struct ospf_interface *oi; | |
7277 | struct route_node *rn; | |
718e3744 | 7278 | |
d62a17ae | 7279 | params = IF_DEF_PARAMS(ifp); |
7280 | ||
7281 | if (nbr_str) { | |
7282 | ret = inet_aton(nbr_str, &addr); | |
7283 | if (!ret) { | |
7284 | vty_out(vty, | |
7285 | "Please specify interface address by A.B.C.D\n"); | |
7286 | return CMD_WARNING_CONFIG_FAILED; | |
7287 | } | |
7288 | ||
7289 | params = ospf_get_if_params(ifp, addr); | |
7290 | ospf_if_update_params(ifp, addr); | |
7291 | } | |
7292 | ||
7293 | if (interval_str) { | |
7294 | seconds = strtoul(interval_str, NULL, 10); | |
7295 | ||
7296 | /* reset fast_hello too, just to be sure */ | |
7297 | UNSET_IF_PARAM(params, fast_hello); | |
7298 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7299 | } else if (fast_hello_str) { | |
7300 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
7301 | /* 1s dead-interval with sub-second hellos desired */ | |
7302 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
7303 | SET_IF_PARAM(params, fast_hello); | |
7304 | params->fast_hello = hellomult; | |
7305 | } else { | |
7306 | vty_out(vty, | |
7307 | "Please specify dead-interval or hello-multiplier\n"); | |
7308 | return CMD_WARNING_CONFIG_FAILED; | |
7309 | } | |
7310 | ||
7311 | SET_IF_PARAM(params, v_wait); | |
7312 | params->v_wait = seconds; | |
182d6bdc | 7313 | params->is_v_wait_set = true; |
d62a17ae | 7314 | |
7315 | /* Update timer values in neighbor structure. */ | |
7316 | if (nbr_str) { | |
b5a8894d CS |
7317 | struct ospf *ospf = NULL; |
7318 | ||
a36898e7 | 7319 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 7320 | if (ospf) { |
d62a17ae | 7321 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7322 | if (oi) | |
7323 | ospf_nbr_timer_update(oi); | |
7324 | } | |
7325 | } else { | |
7326 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7327 | if ((oi = rn->info)) | |
7328 | ospf_nbr_timer_update(oi); | |
7329 | } | |
7330 | ||
7331 | return CMD_SUCCESS; | |
718e3744 | 7332 | } |
7333 | ||
f9ad937f | 7334 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 7335 | ip_ospf_dead_interval_cmd, |
7a7be519 | 7336 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 7337 | "IP Information\n" |
7338 | "OSPF interface commands\n" | |
99a522c7 | 7339 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7340 | "Seconds\n" |
7341 | "Address of interface\n") | |
7342 | { | |
d62a17ae | 7343 | int idx = 0; |
7344 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
7345 | ? argv[idx]->arg | |
7346 | : NULL; | |
7347 | char *ifaddr = | |
7348 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
7349 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 7350 | } |
7351 | ||
718e3744 | 7352 | |
7a7be519 | 7353 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 7354 | ospf_dead_interval_cmd, |
0d829fa7 | 7355 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 7356 | "OSPF interface commands\n" |
99a522c7 | 7357 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
7358 | "Seconds\n" |
7359 | "Address of interface\n") | |
7a7be519 | 7360 | { |
d62a17ae | 7361 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 7362 | } |
718e3744 | 7363 | |
f9ad937f | 7364 | DEFUN (ip_ospf_dead_interval_minimal, |
7365 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 7366 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 7367 | "IP Information\n" |
7368 | "OSPF interface commands\n" | |
99a522c7 | 7369 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7370 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7371 | "Hello multiplier factor\n" | |
7372 | "Number of Hellos to send each second\n" | |
7373 | "Address of interface\n") | |
7374 | { | |
d62a17ae | 7375 | int idx_number = 5; |
7376 | int idx_ipv4 = 6; | |
7377 | if (argc == 7) | |
7378 | return ospf_vty_dead_interval_set( | |
7379 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
7380 | else | |
7381 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
7382 | argv[idx_number]->arg); | |
f9ad937f | 7383 | } |
7384 | ||
718e3744 | 7385 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 7386 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 7387 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 7388 | NO_STR |
7389 | "IP Information\n" | |
7390 | "OSPF interface commands\n" | |
99a522c7 | 7391 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 7392 | "Seconds\n" |
efd7904e RW |
7393 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7394 | "Hello multiplier factor\n" | |
7395 | "Number of Hellos to send each second\n" | |
7396 | "Address of interface\n") | |
718e3744 | 7397 | { |
d62a17ae | 7398 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7399 | int idx_ipv4 = argc - 1; | |
7400 | struct in_addr addr = {.s_addr = 0L}; | |
7401 | int ret; | |
7402 | struct ospf_if_params *params; | |
7403 | struct ospf_interface *oi; | |
7404 | struct route_node *rn; | |
7405 | ||
7406 | params = IF_DEF_PARAMS(ifp); | |
7407 | ||
7408 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
7409 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7410 | if (!ret) { | |
7411 | vty_out(vty, | |
7412 | "Please specify interface address by A.B.C.D\n"); | |
7413 | return CMD_WARNING_CONFIG_FAILED; | |
7414 | } | |
020709f9 | 7415 | |
d62a17ae | 7416 | params = ospf_lookup_if_params(ifp, addr); |
7417 | if (params == NULL) | |
7418 | return CMD_SUCCESS; | |
7419 | } | |
718e3744 | 7420 | |
d62a17ae | 7421 | UNSET_IF_PARAM(params, v_wait); |
7422 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
182d6bdc | 7423 | params->is_v_wait_set = false; |
d62a17ae | 7424 | |
7425 | UNSET_IF_PARAM(params, fast_hello); | |
7426 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7427 | ||
7428 | if (params != IF_DEF_PARAMS(ifp)) { | |
7429 | ospf_free_if_params(ifp, addr); | |
7430 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7431 | } |
7432 | ||
d62a17ae | 7433 | /* Update timer values in neighbor structure. */ |
7434 | if (argc == 1) { | |
b5a8894d | 7435 | struct ospf *ospf = NULL; |
718e3744 | 7436 | |
a36898e7 | 7437 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 7438 | if (ospf) { |
d62a17ae | 7439 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7440 | if (oi) | |
7441 | ospf_nbr_timer_update(oi); | |
7442 | } | |
7443 | } else { | |
7444 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7445 | if ((oi = rn->info)) | |
7446 | ospf_nbr_timer_update(oi); | |
7447 | } | |
7448 | ||
7449 | return CMD_SUCCESS; | |
718e3744 | 7450 | } |
7451 | ||
0d829fa7 QY |
7452 | DEFUN_HIDDEN (no_ospf_dead_interval, |
7453 | no_ospf_dead_interval_cmd, | |
7454 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
7455 | NO_STR | |
7456 | "OSPF interface commands\n" | |
99a522c7 | 7457 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 7458 | "Seconds\n" |
efd7904e RW |
7459 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7460 | "Hello multiplier factor\n" | |
7461 | "Number of Hellos to send each second\n" | |
7462 | "Address of interface\n") | |
0d829fa7 | 7463 | { |
d62a17ae | 7464 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
7465 | } |
7466 | ||
718e3744 | 7467 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 7468 | ip_ospf_hello_interval_cmd, |
7a7be519 | 7469 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 7470 | "IP Information\n" |
7471 | "OSPF interface commands\n" | |
7472 | "Time between HELLO packets\n" | |
7473 | "Seconds\n" | |
0d829fa7 | 7474 | "Address of interface\n") |
718e3744 | 7475 | { |
d62a17ae | 7476 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7477 | int idx = 0; | |
7478 | struct in_addr addr; | |
7479 | struct ospf_if_params *params; | |
7480 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 7481 | uint32_t seconds = 0; |
d62a17ae | 7482 | |
7483 | argv_find(argv, argc, "(1-65535)", &idx); | |
7484 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7485 | ||
7486 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7487 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7488 | vty_out(vty, | |
7489 | "Please specify interface address by A.B.C.D\n"); | |
7490 | return CMD_WARNING_CONFIG_FAILED; | |
7491 | } | |
718e3744 | 7492 | |
d62a17ae | 7493 | params = ospf_get_if_params(ifp, addr); |
7494 | ospf_if_update_params(ifp, addr); | |
7495 | } | |
718e3744 | 7496 | |
d62a17ae | 7497 | SET_IF_PARAM(params, v_hello); |
7498 | params->v_hello = seconds; | |
718e3744 | 7499 | |
182d6bdc K |
7500 | if (!params->is_v_wait_set) { |
7501 | SET_IF_PARAM(params, v_wait); | |
7502 | /* As per RFC 4062 | |
7503 | * The router dead interval should | |
7504 | * be some multiple of the HelloInterval (perhaps 4 times the | |
7505 | * hello interval) and must be the same for all routers | |
7506 | * attached to a common network. | |
7507 | */ | |
7508 | params->v_wait = 4 * seconds; | |
7509 | } | |
7510 | ||
d62a17ae | 7511 | return CMD_SUCCESS; |
718e3744 | 7512 | } |
7513 | ||
7a7be519 | 7514 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 7515 | ospf_hello_interval_cmd, |
0d829fa7 | 7516 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
7517 | "OSPF interface commands\n" |
7518 | "Time between HELLO packets\n" | |
0d829fa7 QY |
7519 | "Seconds\n" |
7520 | "Address of interface\n") | |
7a7be519 | 7521 | { |
d62a17ae | 7522 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 7523 | } |
718e3744 | 7524 | |
7525 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
7526 | no_ip_ospf_hello_interval_cmd, |
7527 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 7528 | NO_STR |
7529 | "IP Information\n" | |
7530 | "OSPF interface commands\n" | |
0d829fa7 | 7531 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 7532 | "Seconds\n" |
0d829fa7 | 7533 | "Address of interface\n") |
718e3744 | 7534 | { |
d62a17ae | 7535 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7536 | int idx = 0; | |
7537 | struct in_addr addr; | |
7538 | struct ospf_if_params *params; | |
182d6bdc | 7539 | struct route_node *rn; |
df581cd3 | 7540 | |
d62a17ae | 7541 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7542 | |
d62a17ae | 7543 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7544 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7545 | vty_out(vty, | |
7546 | "Please specify interface address by A.B.C.D\n"); | |
7547 | return CMD_WARNING_CONFIG_FAILED; | |
7548 | } | |
718e3744 | 7549 | |
d62a17ae | 7550 | params = ospf_lookup_if_params(ifp, addr); |
7551 | if (params == NULL) | |
7552 | return CMD_SUCCESS; | |
7553 | } | |
718e3744 | 7554 | |
d62a17ae | 7555 | UNSET_IF_PARAM(params, v_hello); |
7556 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 7557 | |
182d6bdc K |
7558 | if (!params->is_v_wait_set) { |
7559 | UNSET_IF_PARAM(params, v_wait); | |
7560 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
7561 | } | |
7562 | ||
7563 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7564 | struct ospf_interface *oi = rn->info; | |
7565 | ||
7566 | if (!oi) | |
7567 | continue; | |
7568 | ||
7569 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
7570 | ||
7571 | if (oi->state > ISM_Down) { | |
7572 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7573 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7574 | } | |
7575 | } | |
7576 | ||
d62a17ae | 7577 | if (params != IF_DEF_PARAMS(ifp)) { |
7578 | ospf_free_if_params(ifp, addr); | |
7579 | ospf_if_update_params(ifp, addr); | |
7580 | } | |
718e3744 | 7581 | |
d62a17ae | 7582 | return CMD_SUCCESS; |
718e3744 | 7583 | } |
7584 | ||
0d829fa7 QY |
7585 | DEFUN_HIDDEN (no_ospf_hello_interval, |
7586 | no_ospf_hello_interval_cmd, | |
7587 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
7588 | NO_STR | |
7589 | "OSPF interface commands\n" | |
7590 | "Time between HELLO packets\n" // ignored | |
7591 | "Seconds\n" | |
7592 | "Address of interface\n") | |
7593 | { | |
d62a17ae | 7594 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 7595 | } |
718e3744 | 7596 | |
7597 | DEFUN (ip_ospf_network, | |
7598 | ip_ospf_network_cmd, | |
6147e2c6 | 7599 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
718e3744 | 7600 | "IP Information\n" |
7601 | "OSPF interface commands\n" | |
7602 | "Network type\n" | |
7603 | "Specify OSPF broadcast multi-access network\n" | |
7604 | "Specify OSPF NBMA network\n" | |
7605 | "Specify OSPF point-to-multipoint network\n" | |
7606 | "Specify OSPF point-to-point network\n") | |
7607 | { | |
d62a17ae | 7608 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7609 | int idx = 0; | |
7610 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7611 | struct route_node *rn; | |
718e3744 | 7612 | |
d62a17ae | 7613 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
7614 | vty_out(vty, | |
7615 | "This is a loopback interface. Can't set network type.\n"); | |
7616 | return CMD_WARNING_CONFIG_FAILED; | |
7617 | } | |
718e3744 | 7618 | |
d62a17ae | 7619 | if (argv_find(argv, argc, "broadcast", &idx)) |
7620 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
7621 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
7622 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
7623 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
7624 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
7625 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
7626 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
718e3744 | 7627 | |
d62a17ae | 7628 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7629 | return CMD_SUCCESS; | |
7630 | ||
7631 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
7632 | ||
7633 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7634 | struct ospf_interface *oi = rn->info; | |
7635 | ||
7636 | if (!oi) | |
7637 | continue; | |
7638 | ||
7639 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
7640 | ||
7641 | if (oi->state > ISM_Down) { | |
7642 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7643 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7644 | } | |
7a7be519 | 7645 | } |
7a7be519 | 7646 | |
d62a17ae | 7647 | return CMD_SUCCESS; |
7a7be519 | 7648 | } |
7649 | ||
7650 | DEFUN_HIDDEN (ospf_network, | |
7651 | ospf_network_cmd, | |
e83a9414 | 7652 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 7653 | "OSPF interface commands\n" |
7654 | "Network type\n" | |
7655 | "Specify OSPF broadcast multi-access network\n" | |
7656 | "Specify OSPF NBMA network\n" | |
7657 | "Specify OSPF point-to-multipoint network\n" | |
7658 | "Specify OSPF point-to-point network\n") | |
7659 | { | |
d62a17ae | 7660 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 7661 | } |
7662 | ||
7663 | DEFUN (no_ip_ospf_network, | |
7664 | no_ip_ospf_network_cmd, | |
7665 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7666 | NO_STR | |
7667 | "IP Information\n" | |
7668 | "OSPF interface commands\n" | |
7669 | "Network type\n" | |
7670 | "Specify OSPF broadcast multi-access network\n" | |
7671 | "Specify OSPF NBMA network\n" | |
7672 | "Specify OSPF point-to-multipoint network\n" | |
7673 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 7674 | { |
d62a17ae | 7675 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7676 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7677 | struct route_node *rn; | |
7a7be519 | 7678 | |
d62a17ae | 7679 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
7a7be519 | 7680 | |
d62a17ae | 7681 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7682 | return CMD_SUCCESS; | |
7a7be519 | 7683 | |
d62a17ae | 7684 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7685 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7686 | |
d62a17ae | 7687 | if (!oi) |
7688 | continue; | |
7a7be519 | 7689 | |
d62a17ae | 7690 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 7691 | |
d62a17ae | 7692 | if (oi->state > ISM_Down) { |
7693 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7694 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7695 | } | |
7a7be519 | 7696 | } |
7a7be519 | 7697 | |
d62a17ae | 7698 | return CMD_SUCCESS; |
7a7be519 | 7699 | } |
7700 | ||
0d829fa7 QY |
7701 | DEFUN_HIDDEN (no_ospf_network, |
7702 | no_ospf_network_cmd, | |
7703 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7704 | NO_STR | |
7705 | "OSPF interface commands\n" | |
7706 | "Network type\n" | |
7707 | "Specify OSPF broadcast multi-access network\n" | |
7708 | "Specify OSPF NBMA network\n" | |
7709 | "Specify OSPF point-to-multipoint network\n" | |
7710 | "Specify OSPF point-to-point network\n") | |
7711 | { | |
d62a17ae | 7712 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
7713 | } |
7714 | ||
7a7be519 | 7715 | DEFUN (ip_ospf_priority, |
537eae3f | 7716 | ip_ospf_priority_cmd, |
7a7be519 | 7717 | "ip ospf priority (0-255) [A.B.C.D]", |
7718 | "IP Information\n" | |
7719 | "OSPF interface commands\n" | |
7720 | "Router priority\n" | |
7721 | "Priority\n" | |
efd7904e | 7722 | "Address of interface\n") |
7a7be519 | 7723 | { |
d62a17ae | 7724 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7725 | int idx = 0; | |
7726 | long priority; | |
7727 | struct route_node *rn; | |
7728 | struct in_addr addr; | |
7729 | struct ospf_if_params *params; | |
7730 | params = IF_DEF_PARAMS(ifp); | |
7731 | ||
7732 | argv_find(argv, argc, "(0-255)", &idx); | |
7733 | priority = strtol(argv[idx]->arg, NULL, 10); | |
7734 | ||
7735 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7736 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7737 | vty_out(vty, | |
7738 | "Please specify interface address by A.B.C.D\n"); | |
7739 | return CMD_WARNING_CONFIG_FAILED; | |
7740 | } | |
7a7be519 | 7741 | |
d62a17ae | 7742 | params = ospf_get_if_params(ifp, addr); |
7743 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 7744 | } |
7745 | ||
d62a17ae | 7746 | SET_IF_PARAM(params, priority); |
7747 | params->priority = priority; | |
7a7be519 | 7748 | |
d62a17ae | 7749 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7750 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7751 | |
d62a17ae | 7752 | if (!oi) |
7753 | continue; | |
7a7be519 | 7754 | |
d62a17ae | 7755 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
7756 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7757 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7758 | } | |
718e3744 | 7759 | } |
718e3744 | 7760 | |
d62a17ae | 7761 | return CMD_SUCCESS; |
718e3744 | 7762 | } |
7763 | ||
7a7be519 | 7764 | DEFUN_HIDDEN (ospf_priority, |
7765 | ospf_priority_cmd, | |
0d829fa7 | 7766 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 7767 | "OSPF interface commands\n" |
7768 | "Router priority\n" | |
3a2d747c | 7769 | "Priority\n" |
efd7904e | 7770 | "Address of interface\n") |
718e3744 | 7771 | { |
d62a17ae | 7772 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 7773 | } |
7774 | ||
718e3744 | 7775 | DEFUN (no_ip_ospf_priority, |
537eae3f | 7776 | no_ip_ospf_priority_cmd, |
7a7be519 | 7777 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 7778 | NO_STR |
7779 | "IP Information\n" | |
7780 | "OSPF interface commands\n" | |
0d829fa7 | 7781 | "Router priority\n" // ignored |
813d4307 | 7782 | "Priority\n" |
efd7904e | 7783 | "Address of interface\n") |
718e3744 | 7784 | { |
d62a17ae | 7785 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7786 | int idx = 0; | |
7787 | struct route_node *rn; | |
7788 | struct in_addr addr; | |
7789 | struct ospf_if_params *params; | |
7790 | ||
7791 | params = IF_DEF_PARAMS(ifp); | |
7792 | ||
7793 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7794 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7795 | vty_out(vty, | |
7796 | "Please specify interface address by A.B.C.D\n"); | |
7797 | return CMD_WARNING_CONFIG_FAILED; | |
7798 | } | |
7799 | ||
7800 | params = ospf_lookup_if_params(ifp, addr); | |
7801 | if (params == NULL) | |
7802 | return CMD_SUCCESS; | |
718e3744 | 7803 | } |
7804 | ||
d62a17ae | 7805 | UNSET_IF_PARAM(params, priority); |
7806 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
7807 | ||
7808 | if (params != IF_DEF_PARAMS(ifp)) { | |
7809 | ospf_free_if_params(ifp, addr); | |
7810 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7811 | } |
d62a17ae | 7812 | |
7813 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7814 | struct ospf_interface *oi = rn->info; | |
7815 | ||
7816 | if (!oi) | |
7817 | continue; | |
7818 | ||
7819 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7820 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7821 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7822 | } | |
7823 | } | |
7824 | ||
7825 | return CMD_SUCCESS; | |
718e3744 | 7826 | } |
7827 | ||
0d829fa7 | 7828 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 7829 | no_ospf_priority_cmd, |
0d829fa7 QY |
7830 | "no ospf priority [(0-255) [A.B.C.D]]", |
7831 | NO_STR | |
7832 | "OSPF interface commands\n" | |
7833 | "Router priority\n" | |
7834 | "Priority\n" | |
efd7904e | 7835 | "Address of interface\n") |
0d829fa7 | 7836 | { |
d62a17ae | 7837 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 7838 | } |
a1afa410 | 7839 | |
718e3744 | 7840 | DEFUN (ip_ospf_retransmit_interval, |
7841 | ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 7842 | "ip ospf retransmit-interval (1-65535) [A.B.C.D]", |
718e3744 | 7843 | "IP Information\n" |
7844 | "OSPF interface commands\n" | |
7845 | "Time between retransmitting lost link state advertisements\n" | |
7846 | "Seconds\n" | |
efd7904e | 7847 | "Address of interface\n") |
718e3744 | 7848 | { |
d62a17ae | 7849 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7850 | int idx = 0; | |
d7c0a89a | 7851 | uint32_t seconds; |
d62a17ae | 7852 | struct in_addr addr; |
7853 | struct ospf_if_params *params; | |
7854 | params = IF_DEF_PARAMS(ifp); | |
7855 | ||
d4badaf6 | 7856 | argv_find(argv, argc, "(1-65535)", &idx); |
d62a17ae | 7857 | seconds = strtol(argv[idx]->arg, NULL, 10); |
7858 | ||
7859 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7860 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7861 | vty_out(vty, | |
7862 | "Please specify interface address by A.B.C.D\n"); | |
7863 | return CMD_WARNING_CONFIG_FAILED; | |
7864 | } | |
718e3744 | 7865 | |
d62a17ae | 7866 | params = ospf_get_if_params(ifp, addr); |
7867 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7868 | } |
7869 | ||
d62a17ae | 7870 | SET_IF_PARAM(params, retransmit_interval); |
7871 | params->retransmit_interval = seconds; | |
718e3744 | 7872 | |
d62a17ae | 7873 | return CMD_SUCCESS; |
718e3744 | 7874 | } |
7875 | ||
7a7be519 | 7876 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 7877 | ospf_retransmit_interval_cmd, |
d4badaf6 | 7878 | "ospf retransmit-interval (1-65535) [A.B.C.D]", |
747e489c DW |
7879 | "OSPF interface commands\n" |
7880 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 7881 | "Seconds\n" |
efd7904e | 7882 | "Address of interface\n") |
7a7be519 | 7883 | { |
d62a17ae | 7884 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 7885 | } |
718e3744 | 7886 | |
7887 | DEFUN (no_ip_ospf_retransmit_interval, | |
7888 | no_ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 7889 | "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
718e3744 | 7890 | NO_STR |
7891 | "IP Information\n" | |
7892 | "OSPF interface commands\n" | |
3a2d747c QY |
7893 | "Time between retransmitting lost link state advertisements\n" |
7894 | "Seconds\n" | |
0d829fa7 | 7895 | "Address of interface\n") |
718e3744 | 7896 | { |
d62a17ae | 7897 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7898 | int idx = 0; | |
7899 | struct in_addr addr; | |
7900 | struct ospf_if_params *params; | |
47b91972 | 7901 | |
d62a17ae | 7902 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7903 | |
d62a17ae | 7904 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7905 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7906 | vty_out(vty, | |
7907 | "Please specify interface address by A.B.C.D\n"); | |
7908 | return CMD_WARNING_CONFIG_FAILED; | |
7909 | } | |
718e3744 | 7910 | |
d62a17ae | 7911 | params = ospf_lookup_if_params(ifp, addr); |
7912 | if (params == NULL) | |
7913 | return CMD_SUCCESS; | |
7914 | } | |
718e3744 | 7915 | |
d62a17ae | 7916 | UNSET_IF_PARAM(params, retransmit_interval); |
7917 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 7918 | |
d62a17ae | 7919 | if (params != IF_DEF_PARAMS(ifp)) { |
7920 | ospf_free_if_params(ifp, addr); | |
7921 | ospf_if_update_params(ifp, addr); | |
7922 | } | |
718e3744 | 7923 | |
d62a17ae | 7924 | return CMD_SUCCESS; |
718e3744 | 7925 | } |
7926 | ||
0d829fa7 QY |
7927 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
7928 | no_ospf_retransmit_interval_cmd, | |
d4badaf6 | 7929 | "no ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
0d829fa7 QY |
7930 | NO_STR |
7931 | "OSPF interface commands\n" | |
3a2d747c QY |
7932 | "Time between retransmitting lost link state advertisements\n" |
7933 | "Seconds\n" | |
7934 | "Address of interface\n") | |
0d829fa7 | 7935 | { |
d62a17ae | 7936 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 7937 | } |
813d4307 | 7938 | |
718e3744 | 7939 | DEFUN (ip_ospf_transmit_delay, |
7940 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 7941 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 7942 | "IP Information\n" |
7943 | "OSPF interface commands\n" | |
7944 | "Link state transmit delay\n" | |
7945 | "Seconds\n" | |
efd7904e | 7946 | "Address of interface\n") |
718e3744 | 7947 | { |
d62a17ae | 7948 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7949 | int idx = 0; | |
d7c0a89a | 7950 | uint32_t seconds; |
d62a17ae | 7951 | struct in_addr addr; |
7952 | struct ospf_if_params *params; | |
7953 | ||
7954 | params = IF_DEF_PARAMS(ifp); | |
7955 | argv_find(argv, argc, "(1-65535)", &idx); | |
7956 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7957 | ||
7958 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7959 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7960 | vty_out(vty, | |
7961 | "Please specify interface address by A.B.C.D\n"); | |
7962 | return CMD_WARNING_CONFIG_FAILED; | |
7963 | } | |
718e3744 | 7964 | |
d62a17ae | 7965 | params = ospf_get_if_params(ifp, addr); |
7966 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7967 | } |
7968 | ||
d62a17ae | 7969 | SET_IF_PARAM(params, transmit_delay); |
7970 | params->transmit_delay = seconds; | |
718e3744 | 7971 | |
d62a17ae | 7972 | return CMD_SUCCESS; |
718e3744 | 7973 | } |
7974 | ||
7a7be519 | 7975 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 7976 | ospf_transmit_delay_cmd, |
0d829fa7 | 7977 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
7978 | "OSPF interface commands\n" |
7979 | "Link state transmit delay\n" | |
3a2d747c | 7980 | "Seconds\n" |
efd7904e | 7981 | "Address of interface\n") |
7a7be519 | 7982 | { |
d62a17ae | 7983 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 7984 | } |
718e3744 | 7985 | |
7986 | DEFUN (no_ip_ospf_transmit_delay, | |
7987 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 7988 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 7989 | NO_STR |
7990 | "IP Information\n" | |
7991 | "OSPF interface commands\n" | |
7992 | "Link state transmit delay\n" | |
efd7904e RW |
7993 | "Seconds\n" |
7994 | "Address of interface\n") | |
718e3744 | 7995 | { |
d62a17ae | 7996 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7997 | int idx = 0; | |
7998 | struct in_addr addr; | |
7999 | struct ospf_if_params *params; | |
718e3744 | 8000 | |
d62a17ae | 8001 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8002 | |
d62a17ae | 8003 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8004 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8005 | vty_out(vty, | |
8006 | "Please specify interface address by A.B.C.D\n"); | |
8007 | return CMD_WARNING_CONFIG_FAILED; | |
8008 | } | |
718e3744 | 8009 | |
d62a17ae | 8010 | params = ospf_lookup_if_params(ifp, addr); |
8011 | if (params == NULL) | |
8012 | return CMD_SUCCESS; | |
8013 | } | |
718e3744 | 8014 | |
d62a17ae | 8015 | UNSET_IF_PARAM(params, transmit_delay); |
8016 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 8017 | |
d62a17ae | 8018 | if (params != IF_DEF_PARAMS(ifp)) { |
8019 | ospf_free_if_params(ifp, addr); | |
8020 | ospf_if_update_params(ifp, addr); | |
8021 | } | |
8022 | ||
8023 | return CMD_SUCCESS; | |
718e3744 | 8024 | } |
8025 | ||
813d4307 | 8026 | |
0d829fa7 QY |
8027 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
8028 | no_ospf_transmit_delay_cmd, | |
32573073 | 8029 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
8030 | NO_STR |
8031 | "OSPF interface commands\n" | |
32573073 QY |
8032 | "Link state transmit delay\n" |
8033 | "Seconds\n" | |
efd7904e | 8034 | "Address of interface\n") |
813d4307 | 8035 | { |
d62a17ae | 8036 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
8037 | } |
8038 | ||
e723861d DS |
8039 | DEFUN (ip_ospf_area, |
8040 | ip_ospf_area_cmd, | |
52c62ab8 | 8041 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
8042 | "IP Information\n" |
8043 | "OSPF interface commands\n" | |
7a7be519 | 8044 | "Instance ID\n" |
e723861d DS |
8045 | "Enable OSPF on this interface\n" |
8046 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8047 | "OSPF area ID as a decimal value\n" |
8048 | "Address of interface\n") | |
e723861d | 8049 | { |
d62a17ae | 8050 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8051 | int idx = 0; | |
8052 | int format, ret; | |
8053 | struct in_addr area_id; | |
8054 | struct in_addr addr; | |
35955c14 | 8055 | struct ospf_if_params *params = NULL; |
d62a17ae | 8056 | struct route_node *rn; |
b5a8894d | 8057 | struct ospf *ospf = NULL; |
d7c0a89a | 8058 | unsigned short instance = 0; |
d62a17ae | 8059 | char *areaid; |
8060 | ||
8061 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8062 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8063 | ||
8064 | argv_find(argv, argc, "area", &idx); | |
8065 | areaid = argv[idx + 1]->arg; | |
8066 | ||
a36898e7 DS |
8067 | if (ifp->vrf_id && !instance) |
8068 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
8069 | else |
8070 | ospf = ospf_lookup_instance(instance); | |
8071 | ||
aed7cc62 | 8072 | if (instance && ospf == NULL) { |
d62a17ae | 8073 | params = IF_DEF_PARAMS(ifp); |
8074 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8075 | UNSET_IF_PARAM(params, if_area); | |
b5a8894d CS |
8076 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
8077 | ospf_interface_area_unset(ospf, ifp); | |
d62a17ae | 8078 | ospf->if_ospf_cli_count--; |
8079 | } | |
ac28e4ec | 8080 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8081 | } |
e723861d | 8082 | |
d62a17ae | 8083 | ret = str2area_id(areaid, &area_id, &format); |
8084 | if (ret < 0) { | |
8085 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8086 | return CMD_WARNING_CONFIG_FAILED; | |
8087 | } | |
8088 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8089 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8090 | return CMD_WARNING_CONFIG_FAILED; | |
8091 | } | |
8092 | ||
8093 | params = IF_DEF_PARAMS(ifp); | |
8094 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8095 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8096 | vty_out(vty, | |
8097 | "Must remove previous area config before changing ospf area \n"); | |
8098 | return CMD_WARNING_CONFIG_FAILED; | |
8099 | } | |
8100 | ||
8101 | // Check if we have an address arg and proccess it | |
8102 | if (argc == idx + 3) { | |
cc9b06ad | 8103 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8104 | vty_out(vty, |
8105 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8106 | return CMD_WARNING_CONFIG_FAILED; |
8107 | } | |
d62a17ae | 8108 | // update/create address-level params |
8109 | params = ospf_get_if_params((ifp), (addr)); | |
8110 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8111 | vty_out(vty, | |
8112 | "Must remove previous area/address config before changing ospf area"); | |
8113 | return CMD_WARNING_CONFIG_FAILED; | |
8114 | } | |
8115 | ospf_if_update_params((ifp), (addr)); | |
8116 | } | |
8117 | ||
aed7cc62 CS |
8118 | if (ospf) { |
8119 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8120 | if (rn->info != NULL) { | |
8121 | vty_out(vty, | |
8122 | "Please remove all network commands first.\n"); | |
8123 | return CMD_WARNING_CONFIG_FAILED; | |
8124 | } | |
d62a17ae | 8125 | } |
8126 | } | |
8127 | ||
8128 | /* enable ospf on this interface with area_id */ | |
35955c14 CS |
8129 | if (params) { |
8130 | SET_IF_PARAM(params, if_area); | |
8131 | params->if_area = area_id; | |
8132 | params->if_area_id_fmt = format; | |
8133 | } | |
aed7cc62 CS |
8134 | |
8135 | if (ospf) { | |
8136 | ospf_interface_area_set(ospf, ifp); | |
8137 | ospf->if_ospf_cli_count++; | |
8138 | } | |
d62a17ae | 8139 | |
8140 | return CMD_SUCCESS; | |
e723861d DS |
8141 | } |
8142 | ||
8143 | DEFUN (no_ip_ospf_area, | |
8144 | no_ip_ospf_area_cmd, | |
52c62ab8 | 8145 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
8146 | NO_STR |
8147 | "IP Information\n" | |
8148 | "OSPF interface commands\n" | |
3a2d747c | 8149 | "Instance ID\n" |
7a7be519 | 8150 | "Disable OSPF on this interface\n" |
8151 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8152 | "OSPF area ID as a decimal value\n" |
8153 | "Address of interface\n") | |
e723861d | 8154 | { |
d62a17ae | 8155 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8156 | int idx = 0; | |
8157 | struct ospf *ospf; | |
8158 | struct ospf_if_params *params; | |
d7c0a89a | 8159 | unsigned short instance = 0; |
d62a17ae | 8160 | struct in_addr addr; |
8161 | ||
8162 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8163 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8164 | ||
a36898e7 DS |
8165 | if (ifp->vrf_id && !instance) |
8166 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
8167 | else |
8168 | ospf = ospf_lookup_instance(instance); | |
8169 | ||
ac28e4ec CS |
8170 | if (ospf == NULL) |
8171 | return CMD_NOT_MY_INSTANCE; | |
d62a17ae | 8172 | |
8173 | argv_find(argv, argc, "area", &idx); | |
8174 | ||
8175 | // Check if we have an address arg and proccess it | |
8176 | if (argc == idx + 3) { | |
cc9b06ad | 8177 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8178 | vty_out(vty, |
8179 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8180 | return CMD_WARNING_CONFIG_FAILED; |
8181 | } | |
d62a17ae | 8182 | params = ospf_lookup_if_params(ifp, addr); |
8183 | if ((params) == NULL) | |
8184 | return CMD_SUCCESS; | |
8185 | } else | |
8186 | params = IF_DEF_PARAMS(ifp); | |
8187 | ||
8188 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8189 | vty_out(vty, | |
8190 | "Can't find specified interface area configuration.\n"); | |
8191 | return CMD_WARNING_CONFIG_FAILED; | |
8192 | } | |
813d4307 | 8193 | |
d62a17ae | 8194 | UNSET_IF_PARAM(params, if_area); |
8195 | if (params != IF_DEF_PARAMS((ifp))) { | |
8196 | ospf_free_if_params((ifp), (addr)); | |
8197 | ospf_if_update_params((ifp), (addr)); | |
8198 | } | |
8199 | ||
b5a8894d | 8200 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8201 | ospf->if_ospf_cli_count--; |
8202 | return CMD_SUCCESS; | |
813d4307 DW |
8203 | } |
8204 | ||
6f2a6703 CF |
8205 | DEFUN (ospf_redistribute_source, |
8206 | ospf_redistribute_source_cmd, | |
ea38ced1 | 8207 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
d1c65c21 | 8208 | REDIST_STR |
ab0181ee | 8209 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 8210 | "Metric for redistributed routes\n" |
8211 | "OSPF default metric\n" | |
8212 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8213 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8214 | "Route map reference\n" |
8215 | "Pointer to route-map entries\n") | |
8216 | { | |
a3d826f0 | 8217 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8218 | int idx_protocol = 1; |
8219 | int source; | |
8220 | int type = -1; | |
8221 | int metric = -1; | |
8222 | struct ospf_redist *red; | |
8223 | int idx = 0; | |
6f2a6703 | 8224 | |
d62a17ae | 8225 | /* Get distribute source. */ |
8226 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
8227 | if (source < 0) | |
8228 | return CMD_WARNING_CONFIG_FAILED; | |
8229 | ||
8230 | red = ospf_redist_add(ospf, source, 0); | |
8231 | ||
8232 | /* Get metric value. */ | |
8233 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
8234 | if (!str2metric(argv[idx]->arg, &metric)) | |
8235 | return CMD_WARNING_CONFIG_FAILED; | |
8236 | } | |
951da435 | 8237 | idx = 1; |
d62a17ae | 8238 | /* Get metric type. */ |
ea38ced1 | 8239 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 8240 | if (!str2metric_type(argv[idx]->arg, &type)) |
8241 | return CMD_WARNING_CONFIG_FAILED; | |
8242 | } | |
951da435 | 8243 | idx = 1; |
d62a17ae | 8244 | /* Get route-map */ |
ea38ced1 | 8245 | if (argv_find(argv, argc, "WORD", &idx)) { |
d62a17ae | 8246 | ospf_routemap_set(red, argv[idx]->arg); |
8247 | } else | |
8248 | ospf_routemap_unset(red); | |
7c8ff89e | 8249 | |
d62a17ae | 8250 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 8251 | } |
8252 | ||
718e3744 | 8253 | DEFUN (no_ospf_redistribute_source, |
8254 | no_ospf_redistribute_source_cmd, | |
ea38ced1 | 8255 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8256 | NO_STR |
d1c65c21 | 8257 | REDIST_STR |
ab0181ee | 8258 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
8259 | "Metric for redistributed routes\n" |
8260 | "OSPF default metric\n" | |
8261 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8262 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8263 | "Route map reference\n" |
8264 | "Pointer to route-map entries\n") | |
718e3744 | 8265 | { |
a3d826f0 | 8266 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8267 | int idx_protocol = 2; |
8268 | int source; | |
8269 | struct ospf_redist *red; | |
718e3744 | 8270 | |
d62a17ae | 8271 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
8272 | if (source < 0) | |
8273 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8274 | |
d62a17ae | 8275 | red = ospf_redist_lookup(ospf, source, 0); |
8276 | if (!red) | |
8277 | return CMD_SUCCESS; | |
7c8ff89e | 8278 | |
d62a17ae | 8279 | ospf_routemap_unset(red); |
766b826f DA |
8280 | ospf_redist_del(ospf, source, 0); |
8281 | ||
d62a17ae | 8282 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
8283 | } |
8284 | ||
8285 | DEFUN (ospf_redistribute_instance_source, | |
8286 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8287 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8288 | REDIST_STR |
8289 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8290 | "Non-main Kernel Routing Table\n" |
8291 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
8292 | "Metric for redistributed routes\n" |
8293 | "OSPF default metric\n" | |
8294 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8295 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8296 | "Route map reference\n" |
8297 | "Pointer to route-map entries\n") | |
8298 | { | |
a3d826f0 | 8299 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8300 | int idx_ospf_table = 1; |
8301 | int idx_number = 2; | |
8302 | int idx = 3; | |
8303 | int source; | |
8304 | int type = -1; | |
8305 | int metric = -1; | |
d7c0a89a | 8306 | unsigned short instance; |
d62a17ae | 8307 | struct ospf_redist *red; |
7c8ff89e | 8308 | |
d62a17ae | 8309 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 8310 | |
13f0e434 | 8311 | if (source < 0) { |
8312 | vty_out(vty, "Unknown instance redistribution\n"); | |
8313 | return CMD_WARNING_CONFIG_FAILED; | |
8314 | } | |
8315 | ||
d62a17ae | 8316 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 8317 | |
d62a17ae | 8318 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8319 | vty_out(vty, | |
8320 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8321 | return CMD_WARNING_CONFIG_FAILED; | |
8322 | } | |
7c8ff89e | 8323 | |
d62a17ae | 8324 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
8325 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8326 | return CMD_WARNING_CONFIG_FAILED; | |
8327 | } | |
7c8ff89e | 8328 | |
d62a17ae | 8329 | /* Get metric value. */ |
8330 | if (argv_find(argv, argc, "metric", &idx)) | |
8331 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
8332 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 8333 | |
d62a17ae | 8334 | idx = 3; |
8335 | /* Get metric type. */ | |
8336 | if (argv_find(argv, argc, "metric-type", &idx)) | |
8337 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
8338 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 8339 | |
d62a17ae | 8340 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 8341 | |
d62a17ae | 8342 | idx = 3; |
8343 | if (argv_find(argv, argc, "route-map", &idx)) | |
8344 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
8345 | else | |
8346 | ospf_routemap_unset(red); | |
7c8ff89e | 8347 | |
d62a17ae | 8348 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
8349 | } |
8350 | ||
8351 | DEFUN (no_ospf_redistribute_instance_source, | |
8352 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8353 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8354 | NO_STR |
8355 | REDIST_STR | |
8356 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8357 | "Non-main Kernel Routing Table\n" |
8358 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
8359 | "Metric for redistributed routes\n" |
8360 | "OSPF default metric\n" | |
8361 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8362 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8363 | "Route map reference\n" |
8364 | "Pointer to route-map entries\n") | |
8365 | { | |
a3d826f0 | 8366 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8367 | int idx_ospf_table = 2; |
8368 | int idx_number = 3; | |
d7c0a89a | 8369 | unsigned int instance; |
d62a17ae | 8370 | struct ospf_redist *red; |
8371 | int source; | |
8372 | ||
8373 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
8374 | source = ZEBRA_ROUTE_OSPF; | |
8375 | else | |
8376 | source = ZEBRA_ROUTE_TABLE; | |
8377 | ||
8378 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 8379 | |
d62a17ae | 8380 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8381 | vty_out(vty, | |
8382 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8383 | return CMD_WARNING_CONFIG_FAILED; | |
8384 | } | |
8385 | ||
8386 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
8387 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8388 | return CMD_WARNING_CONFIG_FAILED; | |
8389 | } | |
8390 | ||
8391 | red = ospf_redist_lookup(ospf, source, instance); | |
8392 | if (!red) | |
8393 | return CMD_SUCCESS; | |
8394 | ||
8395 | ospf_routemap_unset(red); | |
766b826f DA |
8396 | ospf_redist_del(ospf, source, instance); |
8397 | ||
d62a17ae | 8398 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 8399 | } |
8400 | ||
8401 | DEFUN (ospf_distribute_list_out, | |
8402 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 8403 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 8404 | "Filter networks in routing updates\n" |
6f2a6703 CF |
8405 | "Access-list name\n" |
8406 | OUT_STR | |
ab0181ee | 8407 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 8408 | { |
a3d826f0 | 8409 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8410 | int idx_word = 1; |
8411 | int source; | |
718e3744 | 8412 | |
d62a17ae | 8413 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 8414 | |
d62a17ae | 8415 | /* Get distribute source. */ |
8416 | source = proto_redistnum(AFI_IP, proto); | |
8417 | if (source < 0) | |
8418 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8419 | |
d62a17ae | 8420 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 8421 | } |
8422 | ||
6f2a6703 CF |
8423 | DEFUN (no_ospf_distribute_list_out, |
8424 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 8425 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
8426 | NO_STR |
8427 | "Filter networks in routing updates\n" | |
8428 | "Access-list name\n" | |
8429 | OUT_STR | |
ab0181ee | 8430 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 8431 | { |
a3d826f0 | 8432 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8433 | int idx_word = 2; |
8434 | int source; | |
020709f9 | 8435 | |
d62a17ae | 8436 | char *proto = argv[argc - 1]->text; |
8437 | source = proto_redistnum(AFI_IP, proto); | |
8438 | if (source < 0) | |
8439 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8440 | |
d62a17ae | 8441 | return ospf_distribute_list_out_unset(ospf, source, |
8442 | argv[idx_word]->arg); | |
718e3744 | 8443 | } |
8444 | ||
6f2a6703 CF |
8445 | /* Default information originate. */ |
8446 | DEFUN (ospf_default_information_originate, | |
8447 | ospf_default_information_originate_cmd, | |
ea38ced1 | 8448 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8449 | "Control distribution of default information\n" |
8450 | "Distribute a default route\n" | |
8451 | "Always advertise default route\n" | |
6f2a6703 CF |
8452 | "OSPF default metric\n" |
8453 | "OSPF metric\n" | |
718e3744 | 8454 | "OSPF metric type for default routes\n" |
7111c1a0 | 8455 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8456 | "Route map reference\n" |
8457 | "Pointer to route-map entries\n") | |
8458 | { | |
a3d826f0 | 8459 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8460 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
8461 | int type = -1; | |
8462 | int metric = -1; | |
8463 | struct ospf_redist *red; | |
8464 | int idx = 0; | |
1fb93326 | 8465 | int cur_originate = ospf->default_originate; |
8466 | int sameRtmap = 0; | |
8467 | char *rtmap = NULL; | |
d62a17ae | 8468 | |
8469 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
8470 | ||
8471 | /* Check whether "always" was specified */ | |
8472 | if (argv_find(argv, argc, "always", &idx)) | |
8473 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 8474 | idx = 1; |
d62a17ae | 8475 | /* Get metric value */ |
ea38ced1 | 8476 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 8477 | if (!str2metric(argv[idx]->arg, &metric)) |
8478 | return CMD_WARNING_CONFIG_FAILED; | |
8479 | } | |
951da435 | 8480 | idx = 1; |
d62a17ae | 8481 | /* Get metric type. */ |
ea38ced1 | 8482 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 8483 | if (!str2metric_type(argv[idx]->arg, &type)) |
8484 | return CMD_WARNING_CONFIG_FAILED; | |
8485 | } | |
951da435 | 8486 | idx = 1; |
d62a17ae | 8487 | /* Get route-map */ |
ea38ced1 | 8488 | if (argv_find(argv, argc, "WORD", &idx)) |
1fb93326 | 8489 | rtmap = argv[idx]->arg; |
8490 | ||
8491 | /* To check ,if user is providing same route map */ | |
8492 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
8493 | (rtmap && ROUTEMAP_NAME(red) | |
8494 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
8495 | sameRtmap = 1; | |
8496 | ||
8497 | /* Don't allow if the same lsa is aleardy originated. */ | |
8498 | if ((sameRtmap) | |
8499 | && (red->dmetric.type == type) | |
8500 | && (red->dmetric.value == metric) | |
8501 | && (cur_originate == default_originate)) | |
8502 | return CMD_SUCCESS; | |
8503 | ||
8504 | /* Updating Metric details */ | |
8505 | red->dmetric.type = type; | |
8506 | red->dmetric.value = metric; | |
8507 | ||
8508 | /* updating route map details */ | |
8509 | if (rtmap) | |
8510 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 8511 | else |
8512 | ospf_routemap_unset(red); | |
8513 | ||
8514 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
8515 | metric); | |
718e3744 | 8516 | } |
8517 | ||
8518 | DEFUN (no_ospf_default_information_originate, | |
8519 | no_ospf_default_information_originate_cmd, | |
ea38ced1 | 8520 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8521 | NO_STR |
8522 | "Control distribution of default information\n" | |
813d4307 DW |
8523 | "Distribute a default route\n" |
8524 | "Always advertise default route\n" | |
8525 | "OSPF default metric\n" | |
8526 | "OSPF metric\n" | |
8527 | "OSPF metric type for default routes\n" | |
7111c1a0 | 8528 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8529 | "Route map reference\n" |
8530 | "Pointer to route-map entries\n") | |
718e3744 | 8531 | { |
a3d826f0 | 8532 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8533 | struct ospf_redist *red; |
7c8ff89e | 8534 | |
d62a17ae | 8535 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
8536 | if (!red) | |
8537 | return CMD_SUCCESS; | |
7c8ff89e | 8538 | |
d62a17ae | 8539 | ospf_routemap_unset(red); |
766b826f DA |
8540 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
8541 | ||
d5eac1e0 DL |
8542 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
8543 | 0, 0); | |
718e3744 | 8544 | } |
8545 | ||
8546 | DEFUN (ospf_default_metric, | |
8547 | ospf_default_metric_cmd, | |
6147e2c6 | 8548 | "default-metric (0-16777214)", |
718e3744 | 8549 | "Set metric of redistributed routes\n" |
8550 | "Default metric\n") | |
8551 | { | |
a3d826f0 | 8552 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8553 | int idx_number = 1; |
8554 | int metric = -1; | |
718e3744 | 8555 | |
d62a17ae | 8556 | if (!str2metric(argv[idx_number]->arg, &metric)) |
8557 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8558 | |
d62a17ae | 8559 | ospf->default_metric = metric; |
718e3744 | 8560 | |
d62a17ae | 8561 | return CMD_SUCCESS; |
718e3744 | 8562 | } |
8563 | ||
8564 | DEFUN (no_ospf_default_metric, | |
8565 | no_ospf_default_metric_cmd, | |
7a7be519 | 8566 | "no default-metric [(0-16777214)]", |
718e3744 | 8567 | NO_STR |
7a7be519 | 8568 | "Set metric of redistributed routes\n" |
8569 | "Default metric\n") | |
718e3744 | 8570 | { |
a3d826f0 | 8571 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8572 | |
d62a17ae | 8573 | ospf->default_metric = -1; |
68980084 | 8574 | |
d62a17ae | 8575 | return CMD_SUCCESS; |
718e3744 | 8576 | } |
8577 | ||
718e3744 | 8578 | |
8579 | DEFUN (ospf_distance, | |
8580 | ospf_distance_cmd, | |
6147e2c6 | 8581 | "distance (1-255)", |
eaa1ae0d | 8582 | "Administrative distance\n" |
718e3744 | 8583 | "OSPF Administrative distance\n") |
8584 | { | |
a3d826f0 | 8585 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8586 | int idx_number = 1; |
68980084 | 8587 | |
d62a17ae | 8588 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 8589 | |
d62a17ae | 8590 | return CMD_SUCCESS; |
718e3744 | 8591 | } |
8592 | ||
8593 | DEFUN (no_ospf_distance, | |
8594 | no_ospf_distance_cmd, | |
6147e2c6 | 8595 | "no distance (1-255)", |
718e3744 | 8596 | NO_STR |
eaa1ae0d | 8597 | "Administrative distance\n" |
718e3744 | 8598 | "OSPF Administrative distance\n") |
8599 | { | |
a3d826f0 | 8600 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8601 | |
d62a17ae | 8602 | ospf->distance_all = 0; |
68980084 | 8603 | |
d62a17ae | 8604 | return CMD_SUCCESS; |
718e3744 | 8605 | } |
8606 | ||
8607 | DEFUN (no_ospf_distance_ospf, | |
8608 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 8609 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 8610 | NO_STR |
eaa1ae0d QY |
8611 | "Administrative distance\n" |
8612 | "OSPF administrative distance\n" | |
718e3744 | 8613 | "Intra-area routes\n" |
813d4307 | 8614 | "Distance for intra-area routes\n" |
718e3744 | 8615 | "Inter-area routes\n" |
813d4307 DW |
8616 | "Distance for inter-area routes\n" |
8617 | "External routes\n" | |
8618 | "Distance for external routes\n") | |
718e3744 | 8619 | { |
a3d826f0 | 8620 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8621 | int idx = 0; |
718e3744 | 8622 | |
d62a17ae | 8623 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
8624 | idx = ospf->distance_intra = 0; | |
8625 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
8626 | idx = ospf->distance_inter = 0; | |
8627 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
8628 | ospf->distance_external = 0; | |
718e3744 | 8629 | |
d62a17ae | 8630 | return CMD_SUCCESS; |
718e3744 | 8631 | } |
8632 | ||
6f2a6703 CF |
8633 | DEFUN (ospf_distance_ospf, |
8634 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
8635 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
8636 | "Administrative distance\n" | |
8637 | "OSPF administrative distance\n" | |
718e3744 | 8638 | "Intra-area routes\n" |
8639 | "Distance for intra-area routes\n" | |
718e3744 | 8640 | "Inter-area routes\n" |
8641 | "Distance for inter-area routes\n" | |
8642 | "External routes\n" | |
718e3744 | 8643 | "Distance for external routes\n") |
8644 | { | |
a3d826f0 | 8645 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8646 | int idx = 0; |
68980084 | 8647 | |
926b88f0 CS |
8648 | ospf->distance_intra = 0; |
8649 | ospf->distance_inter = 0; | |
8650 | ospf->distance_external = 0; | |
8651 | ||
d62a17ae | 8652 | if (argv_find(argv, argc, "intra-area", &idx)) |
8653 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
8654 | idx = 0; | |
8655 | if (argv_find(argv, argc, "inter-area", &idx)) | |
8656 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
8657 | idx = 0; | |
8658 | if (argv_find(argv, argc, "external", &idx)) | |
8659 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 8660 | |
d62a17ae | 8661 | return CMD_SUCCESS; |
718e3744 | 8662 | } |
8663 | ||
d7d73ffc | 8664 | #if 0 |
718e3744 | 8665 | DEFUN (ospf_distance_source, |
8666 | ospf_distance_source_cmd, | |
6147e2c6 | 8667 | "distance (1-255) A.B.C.D/M", |
718e3744 | 8668 | "Administrative distance\n" |
8669 | "Distance value\n" | |
8670 | "IP source prefix\n") | |
8671 | { | |
cdc2d765 | 8672 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8673 | int idx_number = 1; |
8674 | int idx_ipv4_prefixlen = 2; | |
020709f9 | 8675 | |
8d769265 | 8676 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
68980084 | 8677 | |
718e3744 | 8678 | return CMD_SUCCESS; |
8679 | } | |
8680 | ||
8681 | DEFUN (no_ospf_distance_source, | |
8682 | no_ospf_distance_source_cmd, | |
6147e2c6 | 8683 | "no distance (1-255) A.B.C.D/M", |
718e3744 | 8684 | NO_STR |
8685 | "Administrative distance\n" | |
8686 | "Distance value\n" | |
8687 | "IP source prefix\n") | |
8688 | { | |
cdc2d765 | 8689 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8690 | int idx_number = 2; |
8691 | int idx_ipv4_prefixlen = 3; | |
020709f9 | 8692 | |
8d769265 | 8693 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
020709f9 | 8694 | |
718e3744 | 8695 | return CMD_SUCCESS; |
8696 | } | |
8697 | ||
8698 | DEFUN (ospf_distance_source_access_list, | |
8699 | ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8700 | "distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8701 | "Administrative distance\n" |
8702 | "Distance value\n" | |
8703 | "IP source prefix\n" | |
8704 | "Access list name\n") | |
8705 | { | |
cdc2d765 | 8706 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8707 | int idx_number = 1; |
8708 | int idx_ipv4_prefixlen = 2; | |
8709 | int idx_word = 3; | |
020709f9 | 8710 | |
8d769265 | 8711 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8712 | |
718e3744 | 8713 | return CMD_SUCCESS; |
8714 | } | |
8715 | ||
8716 | DEFUN (no_ospf_distance_source_access_list, | |
8717 | no_ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8718 | "no distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8719 | NO_STR |
8720 | "Administrative distance\n" | |
8721 | "Distance value\n" | |
8722 | "IP source prefix\n" | |
8723 | "Access list name\n") | |
8724 | { | |
cdc2d765 | 8725 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8726 | int idx_number = 2; |
8727 | int idx_ipv4_prefixlen = 3; | |
8728 | int idx_word = 4; | |
020709f9 | 8729 | |
8d769265 | 8730 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8731 | |
718e3744 | 8732 | return CMD_SUCCESS; |
8733 | } | |
d7d73ffc | 8734 | #endif |
718e3744 | 8735 | |
ba682537 | 8736 | DEFUN (ip_ospf_mtu_ignore, |
8737 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8738 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 8739 | "IP Information\n" |
8740 | "OSPF interface commands\n" | |
99a522c7 | 8741 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8742 | "Address of interface\n") |
ba682537 | 8743 | { |
d62a17ae | 8744 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8745 | int idx_ipv4 = 3; | |
8746 | struct in_addr addr; | |
8747 | int ret; | |
8748 | ||
8749 | struct ospf_if_params *params; | |
8750 | params = IF_DEF_PARAMS(ifp); | |
8751 | ||
8752 | if (argc == 4) { | |
8753 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8754 | if (!ret) { | |
8755 | vty_out(vty, | |
8756 | "Please specify interface address by A.B.C.D\n"); | |
8757 | return CMD_WARNING_CONFIG_FAILED; | |
8758 | } | |
8759 | params = ospf_get_if_params(ifp, addr); | |
8760 | ospf_if_update_params(ifp, addr); | |
8761 | } | |
8762 | params->mtu_ignore = 1; | |
8763 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8764 | SET_IF_PARAM(params, mtu_ignore); | |
8765 | else { | |
8766 | UNSET_IF_PARAM(params, mtu_ignore); | |
8767 | if (params != IF_DEF_PARAMS(ifp)) { | |
8768 | ospf_free_if_params(ifp, addr); | |
8769 | ospf_if_update_params(ifp, addr); | |
8770 | } | |
8771 | } | |
8772 | return CMD_SUCCESS; | |
ba682537 | 8773 | } |
8774 | ||
ba682537 | 8775 | DEFUN (no_ip_ospf_mtu_ignore, |
8776 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8777 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 8778 | NO_STR |
ba682537 | 8779 | "IP Information\n" |
8780 | "OSPF interface commands\n" | |
99a522c7 | 8781 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8782 | "Address of interface\n") |
ba682537 | 8783 | { |
d62a17ae | 8784 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8785 | int idx_ipv4 = 4; | |
8786 | struct in_addr addr; | |
8787 | int ret; | |
8788 | ||
8789 | struct ospf_if_params *params; | |
8790 | params = IF_DEF_PARAMS(ifp); | |
8791 | ||
8792 | if (argc == 5) { | |
8793 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8794 | if (!ret) { | |
8795 | vty_out(vty, | |
8796 | "Please specify interface address by A.B.C.D\n"); | |
8797 | return CMD_WARNING_CONFIG_FAILED; | |
8798 | } | |
8799 | params = ospf_get_if_params(ifp, addr); | |
8800 | ospf_if_update_params(ifp, addr); | |
8801 | } | |
8802 | params->mtu_ignore = 0; | |
8803 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8804 | SET_IF_PARAM(params, mtu_ignore); | |
8805 | else { | |
8806 | UNSET_IF_PARAM(params, mtu_ignore); | |
8807 | if (params != IF_DEF_PARAMS(ifp)) { | |
8808 | ospf_free_if_params(ifp, addr); | |
8809 | ospf_if_update_params(ifp, addr); | |
8810 | } | |
8811 | } | |
8812 | return CMD_SUCCESS; | |
ba682537 | 8813 | } |
8814 | ||
6b0655a2 | 8815 | |
88d6cf37 | 8816 | DEFUN (ospf_max_metric_router_lsa_admin, |
8817 | ospf_max_metric_router_lsa_admin_cmd, | |
8818 | "max-metric router-lsa administrative", | |
8819 | "OSPF maximum / infinite-distance metric\n" | |
8820 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8821 | "Administratively applied, for an indefinite period\n") | |
8822 | { | |
a3d826f0 | 8823 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8824 | struct listnode *ln; |
8825 | struct ospf_area *area; | |
7c8ff89e | 8826 | |
d62a17ae | 8827 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
8828 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 8829 | |
d62a17ae | 8830 | if (!CHECK_FLAG(area->stub_router_state, |
8831 | OSPF_AREA_IS_STUB_ROUTED)) | |
8832 | ospf_router_lsa_update_area(area); | |
8833 | } | |
4ba4fc85 | 8834 | |
d62a17ae | 8835 | /* Allows for areas configured later to get the property */ |
8836 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
8837 | ||
8838 | return CMD_SUCCESS; | |
88d6cf37 | 8839 | } |
8840 | ||
8841 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
8842 | no_ospf_max_metric_router_lsa_admin_cmd, | |
8843 | "no max-metric router-lsa administrative", | |
8844 | NO_STR | |
8845 | "OSPF maximum / infinite-distance metric\n" | |
8846 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8847 | "Administratively applied, for an indefinite period\n") | |
8848 | { | |
a3d826f0 | 8849 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8850 | struct listnode *ln; |
8851 | struct ospf_area *area; | |
8852 | ||
8853 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8854 | UNSET_FLAG(area->stub_router_state, | |
8855 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
8856 | ||
8857 | /* Don't trample on the start-up stub timer */ | |
8858 | if (CHECK_FLAG(area->stub_router_state, | |
8859 | OSPF_AREA_IS_STUB_ROUTED) | |
8860 | && !area->t_stub_router) { | |
8861 | UNSET_FLAG(area->stub_router_state, | |
8862 | OSPF_AREA_IS_STUB_ROUTED); | |
8863 | ospf_router_lsa_update_area(area); | |
8864 | } | |
8865 | } | |
8866 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
8867 | return CMD_SUCCESS; | |
88d6cf37 | 8868 | } |
8869 | ||
8870 | DEFUN (ospf_max_metric_router_lsa_startup, | |
8871 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 8872 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 8873 | "OSPF maximum / infinite-distance metric\n" |
8874 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8875 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8876 | "Time (seconds) to advertise self as stub-router\n") | |
8877 | { | |
a3d826f0 | 8878 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8879 | int idx_number = 3; |
8880 | unsigned int seconds; | |
8881 | ||
b5a8894d | 8882 | if (argc < 4) { |
d62a17ae | 8883 | vty_out(vty, "%% Must supply stub-router period"); |
8884 | return CMD_WARNING_CONFIG_FAILED; | |
8885 | } | |
8886 | ||
8887 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8888 | ||
8889 | ospf->stub_router_startup_time = seconds; | |
8890 | ||
8891 | return CMD_SUCCESS; | |
88d6cf37 | 8892 | } |
8893 | ||
8894 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
8895 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 8896 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 8897 | NO_STR |
8898 | "OSPF maximum / infinite-distance metric\n" | |
8899 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8900 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
8901 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 8902 | { |
a3d826f0 | 8903 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8904 | struct listnode *ln; |
8905 | struct ospf_area *area; | |
8906 | ||
8907 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8908 | ||
8909 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8910 | SET_FLAG(area->stub_router_state, | |
8911 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
8912 | OSPF_TIMER_OFF(area->t_stub_router); | |
8913 | ||
8914 | /* Don't trample on admin stub routed */ | |
8915 | if (!CHECK_FLAG(area->stub_router_state, | |
8916 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8917 | UNSET_FLAG(area->stub_router_state, | |
8918 | OSPF_AREA_IS_STUB_ROUTED); | |
8919 | ospf_router_lsa_update_area(area); | |
8920 | } | |
8921 | } | |
8922 | return CMD_SUCCESS; | |
88d6cf37 | 8923 | } |
8924 | ||
a1afa410 | 8925 | |
88d6cf37 | 8926 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
8927 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 8928 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 8929 | "OSPF maximum / infinite-distance metric\n" |
8930 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8931 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8932 | "Time (seconds) to wait till full shutdown\n") | |
8933 | { | |
a3d826f0 | 8934 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8935 | int idx_number = 3; |
8936 | unsigned int seconds; | |
8937 | ||
b5a8894d | 8938 | if (argc < 4) { |
d62a17ae | 8939 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
8940 | return CMD_WARNING_CONFIG_FAILED; | |
8941 | } | |
8942 | ||
8943 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8944 | ||
8945 | ospf->stub_router_shutdown_time = seconds; | |
8946 | ||
8947 | return CMD_SUCCESS; | |
88d6cf37 | 8948 | } |
8949 | ||
8950 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
8951 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 8952 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 8953 | NO_STR |
8954 | "OSPF maximum / infinite-distance metric\n" | |
8955 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8956 | "Advertise stub-router prior to full shutdown of OSPF\n" |
8957 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 8958 | { |
a3d826f0 | 8959 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 8960 | |
d62a17ae | 8961 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
8962 | ||
8963 | return CMD_SUCCESS; | |
88d6cf37 | 8964 | } |
8965 | ||
a92706bb JU |
8966 | DEFUN (ospf_proactive_arp, |
8967 | ospf_proactive_arp_cmd, | |
8968 | "proactive-arp", | |
8969 | "Allow sending ARP requests proactively\n") | |
8970 | { | |
8971 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8972 | ||
8973 | ospf->proactive_arp = true; | |
8974 | ||
8975 | return CMD_SUCCESS; | |
8976 | } | |
8977 | ||
8978 | DEFUN (no_ospf_proactive_arp, | |
8979 | no_ospf_proactive_arp_cmd, | |
8980 | "no proactive-arp", | |
8981 | NO_STR | |
8982 | "Disallow sending ARP requests proactively\n") | |
8983 | { | |
8984 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8985 | ||
8986 | ospf->proactive_arp = false; | |
8987 | ||
8988 | return CMD_SUCCESS; | |
8989 | } | |
8990 | ||
07b33add | 8991 | /* Graceful Restart HELPER Commands */ |
8992 | DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd, | |
8993 | "graceful-restart helper-only [A.B.C.D]", | |
8994 | "OSPF Graceful Restart\n" | |
8995 | "Enable Helper support\n" | |
8996 | "Advertising router id\n") | |
8997 | { | |
8998 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8999 | struct in_addr addr; | |
9000 | int ret; | |
9001 | ||
9002 | if (argc == 3) { | |
9003 | ret = inet_aton(argv[2]->arg, &addr); | |
9004 | if (!ret) { | |
9005 | vty_out(vty, | |
9006 | "Please specify the valid routerid address.\n"); | |
9007 | return CMD_WARNING_CONFIG_FAILED; | |
9008 | } | |
9009 | ||
9010 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE); | |
9011 | return CMD_SUCCESS; | |
9012 | } | |
9013 | ||
9014 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); | |
9015 | ||
9016 | return CMD_SUCCESS; | |
9017 | } | |
9018 | ||
9019 | DEFPY(no_ospf_gr_helper_enable, | |
9020 | no_ospf_gr_helper_enable_cmd, | |
9021 | "no graceful-restart helper-only [A.B.C.D]", | |
9022 | NO_STR | |
9023 | "OSPF Graceful Restart\n" | |
9024 | "Disable Helper support\n" | |
9025 | "Advertising router id\n") | |
9026 | { | |
9027 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9028 | struct in_addr addr; | |
9029 | int ret; | |
9030 | ||
9031 | if (argc == 4) { | |
9032 | ret = inet_aton(argv[3]->arg, &addr); | |
9033 | if (!ret) { | |
9034 | vty_out(vty, | |
9035 | "Please specify the valid routerid address.\n"); | |
9036 | return CMD_WARNING_CONFIG_FAILED; | |
9037 | } | |
9038 | ||
9039 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, | |
9040 | OSPF_GR_FALSE); | |
9041 | return CMD_SUCCESS; | |
9042 | } | |
9043 | ||
9044 | ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE); | |
9045 | return CMD_SUCCESS; | |
9046 | } | |
9047 | ||
9048 | DEFPY(ospf_gr_helper_enable_lsacheck, | |
9049 | ospf_gr_helper_enable_lsacheck_cmd, | |
9050 | "graceful-restart helper strict-lsa-checking", | |
9051 | "OSPF Graceful Restart\n" | |
9052 | "OSPF GR Helper\n" | |
9053 | "Enable strict LSA check\n") | |
9054 | { | |
9055 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9056 | ||
9057 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE); | |
9058 | return CMD_SUCCESS; | |
9059 | } | |
9060 | ||
9061 | DEFPY(no_ospf_gr_helper_enable_lsacheck, | |
9062 | no_ospf_gr_helper_enable_lsacheck_cmd, | |
9063 | "no graceful-restart helper strict-lsa-checking", | |
9064 | NO_STR | |
9065 | "OSPF Graceful Restart\n" | |
9066 | "OSPF GR Helper\n" | |
9067 | "Disable strict LSA check\n") | |
9068 | { | |
9069 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9070 | ||
9071 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE); | |
9072 | return CMD_SUCCESS; | |
9073 | } | |
9074 | ||
9075 | DEFPY(ospf_gr_helper_supported_grace_time, | |
9076 | ospf_gr_helper_supported_grace_time_cmd, | |
9077 | "graceful-restart helper supported-grace-time (10-1800)$interval", | |
9078 | "OSPF Graceful Restart\n" | |
9079 | "OSPF GR Helper\n" | |
9080 | "Supported grace timer\n" | |
9081 | "Grace interval(in seconds)\n") | |
9082 | { | |
9083 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9084 | ||
9085 | ospf_gr_helper_supported_gracetime_set(ospf, interval); | |
9086 | return CMD_SUCCESS; | |
9087 | } | |
9088 | ||
9089 | DEFPY(no_ospf_gr_helper_supported_grace_time, | |
9090 | no_ospf_gr_helper_supported_grace_time_cmd, | |
9091 | "no graceful-restart helper supported-grace-time (10-1800)$interval", | |
9092 | NO_STR | |
9093 | "OSPF Graceful Restart\n" | |
9094 | "OSPF GR Helper\n" | |
9095 | "Supported grace timer\n" | |
9096 | "Grace interval(in seconds)\n") | |
9097 | { | |
9098 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9099 | ||
9100 | ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL); | |
9101 | return CMD_SUCCESS; | |
9102 | } | |
9103 | ||
9104 | DEFPY(ospf_gr_helper_planned_only, | |
9105 | ospf_gr_helper_planned_only_cmd, | |
9106 | "graceful-restart helper planned-only", | |
9107 | "OSPF Graceful Restart\n" | |
9108 | "OSPF GR Helper\n" | |
9109 | "Supported only planned restart\n") | |
9110 | { | |
9111 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9112 | ||
9113 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE); | |
9114 | ||
9115 | return CMD_SUCCESS; | |
9116 | } | |
9117 | ||
9118 | DEFPY(no_ospf_gr_helper_planned_only, | |
9119 | no_ospf_gr_helper_planned_only_cmd, | |
9120 | "no graceful-restart helper planned-only", | |
9121 | NO_STR | |
9122 | "OSPF Graceful Restart\n" | |
9123 | "OSPF GR Helper\n" | |
9124 | "Supported only for planned restart\n") | |
9125 | { | |
9126 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9127 | ||
9128 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE); | |
9129 | ||
9130 | return CMD_SUCCESS; | |
9131 | } | |
9132 | /* Graceful Restart HELPER commands end */ | |
9133 | ||
d62a17ae | 9134 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
9135 | { | |
9136 | struct listnode *ln; | |
9137 | struct ospf_area *area; | |
9138 | ||
9139 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
9140 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
9141 | ospf->stub_router_startup_time); | |
9142 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
9143 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
9144 | ospf->stub_router_shutdown_time); | |
9145 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9146 | if (CHECK_FLAG(area->stub_router_state, | |
9147 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
9148 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
9149 | break; | |
9150 | } | |
9151 | } | |
9152 | return; | |
9153 | } | |
9154 | ||
b5a8894d | 9155 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
9156 | struct route_table *rt, |
9157 | json_object *json) | |
d62a17ae | 9158 | { |
9159 | struct route_node *rn; | |
9160 | struct ospf_route * or ; | |
9161 | struct listnode *pnode, *pnnode; | |
9162 | struct ospf_path *path; | |
0f478e30 CS |
9163 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
9164 | *json_nexthop = NULL; | |
d62a17ae | 9165 | |
0f478e30 | 9166 | if (!json) |
996c9314 LB |
9167 | vty_out(vty, |
9168 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 9169 | |
0f478e30 CS |
9170 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
9171 | if ((or = rn->info) == NULL) | |
9172 | continue; | |
9173 | char buf1[PREFIX2STR_BUFFER]; | |
9174 | ||
9175 | memset(buf1, 0, sizeof(buf1)); | |
9176 | prefix2str(&rn->p, buf1, sizeof(buf1)); | |
9177 | ||
9178 | json_route = json_object_new_object(); | |
9179 | if (json) { | |
996c9314 LB |
9180 | json_object_object_add(json, buf1, json_route); |
9181 | json_object_to_json_string_ext( | |
9182 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 CS |
9183 | } |
9184 | ||
9185 | switch (or->path_type) { | |
9186 | case OSPF_PATH_INTER_AREA: | |
9187 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
9188 | if (json) { | |
9189 | json_object_string_add(json_route, | |
996c9314 LB |
9190 | "routeType", |
9191 | "N IA"); | |
9192 | json_object_int_add(json_route, "cost", | |
0f478e30 CS |
9193 | or->cost); |
9194 | json_object_string_add( | |
996c9314 LB |
9195 | json_route, "area", |
9196 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 | 9197 | } else { |
d62a17ae | 9198 | vty_out(vty, |
996c9314 | 9199 | "N IA %-18s [%d] area: %s\n", |
d62a17ae | 9200 | buf1, or->cost, |
996c9314 | 9201 | inet_ntoa(or->u.std.area_id)); |
0f478e30 | 9202 | } |
996c9314 | 9203 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
9204 | if (json) { |
9205 | json_object_string_add(json_route, | |
996c9314 LB |
9206 | "routeType", |
9207 | "D IA"); | |
0f478e30 | 9208 | } else { |
d62a17ae | 9209 | vty_out(vty, |
9210 | "D IA %-18s Discard entry\n", | |
9211 | buf1); | |
0f478e30 CS |
9212 | } |
9213 | } | |
9214 | break; | |
9215 | case OSPF_PATH_INTRA_AREA: | |
9216 | if (json) { | |
996c9314 LB |
9217 | json_object_string_add(json_route, "routeType", |
9218 | "N"); | |
0f478e30 | 9219 | json_object_int_add(json_route, "cost", |
996c9314 LB |
9220 | or->cost); |
9221 | json_object_string_add( | |
9222 | json_route, "area", | |
9223 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 | 9224 | } else { |
d62a17ae | 9225 | vty_out(vty, "N %-18s [%d] area: %s\n", |
9226 | buf1, or->cost, | |
9227 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 CS |
9228 | } |
9229 | break; | |
9230 | default: | |
9231 | break; | |
9232 | } | |
9233 | ||
9234 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
9235 | if (json) { | |
9236 | json_nexthop_array = json_object_new_array(); | |
9237 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 9238 | json_nexthop_array); |
d62a17ae | 9239 | } |
9240 | ||
0f478e30 CS |
9241 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
9242 | path)) { | |
9243 | if (json) { | |
996c9314 LB |
9244 | json_nexthop = json_object_new_object(); |
9245 | json_object_array_add( | |
9246 | json_nexthop_array, | |
9247 | json_nexthop); | |
0f478e30 CS |
9248 | } |
9249 | if (if_lookup_by_index(path->ifindex, | |
9250 | ospf->vrf_id)) { | |
9251 | ||
9252 | if (path->nexthop.s_addr == 0) { | |
9253 | if (json) { | |
9254 | json_object_string_add( | |
9255 | json_nexthop, | |
996c9314 | 9256 | "ip", " "); |
0f478e30 CS |
9257 | json_object_string_add( |
9258 | json_nexthop, | |
9259 | "directly attached to", | |
d62a17ae | 9260 | ifindex2ifname( |
996c9314 LB |
9261 | path->ifindex, |
9262 | ospf->vrf_id)); | |
0f478e30 | 9263 | } else { |
d62a17ae | 9264 | vty_out(vty, |
996c9314 LB |
9265 | "%24s directly attached to %s\n", |
9266 | "", | |
9267 | ifindex2ifname( | |
9268 | path->ifindex, | |
9269 | ospf->vrf_id)); | |
0f478e30 CS |
9270 | } |
9271 | } else { | |
9272 | if (json) { | |
9273 | json_object_string_add( | |
9274 | json_nexthop, | |
9275 | "ip", | |
d62a17ae | 9276 | inet_ntoa( |
996c9314 | 9277 | path->nexthop)); |
0f478e30 CS |
9278 | json_object_string_add( |
9279 | json_nexthop, | |
9280 | "via", | |
d62a17ae | 9281 | ifindex2ifname( |
996c9314 LB |
9282 | path->ifindex, |
9283 | ospf->vrf_id)); | |
0f478e30 CS |
9284 | } else { |
9285 | vty_out(vty, | |
996c9314 LB |
9286 | "%24s via %s, %s\n", |
9287 | "", | |
9288 | inet_ntoa( | |
9289 | path->nexthop), | |
9290 | ifindex2ifname( | |
9291 | path->ifindex, | |
9292 | ospf->vrf_id)); | |
0f478e30 | 9293 | } |
d62a17ae | 9294 | } |
9295 | } | |
0f478e30 | 9296 | } |
d62a17ae | 9297 | } |
0f478e30 CS |
9298 | if (!json) |
9299 | json_object_free(json_route); | |
9300 | } | |
9301 | if (!json) | |
9302 | vty_out(vty, "\n"); | |
d62a17ae | 9303 | } |
9304 | ||
b5a8894d | 9305 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
9306 | struct route_table *rtrs, |
9307 | json_object *json) | |
d62a17ae | 9308 | { |
9309 | struct route_node *rn; | |
9310 | struct ospf_route * or ; | |
9311 | struct listnode *pnode; | |
9312 | struct listnode *node; | |
9313 | struct ospf_path *path; | |
0f478e30 CS |
9314 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
9315 | *json_nexthop = NULL; | |
d62a17ae | 9316 | |
0f478e30 | 9317 | if (!json) |
996c9314 LB |
9318 | vty_out(vty, |
9319 | "============ OSPF router routing table =============\n"); | |
d62a17ae | 9320 | |
0f478e30 CS |
9321 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
9322 | if (rn->info == NULL) | |
9323 | continue; | |
9324 | int flag = 0; | |
9325 | ||
9326 | json_route = json_object_new_object(); | |
9327 | if (json) { | |
996c9314 LB |
9328 | json_object_object_add(json, inet_ntoa(rn->p.u.prefix4), |
9329 | json_route); | |
9330 | json_object_string_add(json_route, "routeType", "R "); | |
0f478e30 | 9331 | } else { |
d62a17ae | 9332 | vty_out(vty, "R %-15s ", |
9333 | inet_ntoa(rn->p.u.prefix4)); | |
0f478e30 | 9334 | } |
d62a17ae | 9335 | |
996c9314 | 9336 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
9337 | if (flag++) { |
9338 | if (!json) | |
d62a17ae | 9339 | vty_out(vty, "%24s", ""); |
0f478e30 | 9340 | } |
d62a17ae | 9341 | |
0f478e30 CS |
9342 | /* Show path. */ |
9343 | if (json) { | |
9344 | json_object_int_add(json_route, "cost", | |
9345 | or->cost); | |
996c9314 LB |
9346 | json_object_string_add( |
9347 | json_route, "area", | |
0f478e30 | 9348 | inet_ntoa(or->u.std.area_id)); |
996c9314 LB |
9349 | if (or->path_type == OSPF_PATH_INTER_AREA) |
9350 | json_object_boolean_true_add(json_route, | |
9351 | "IA"); | |
0f478e30 | 9352 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
9353 | json_object_string_add(json_route, |
9354 | "routerType", | |
9355 | "abr"); | |
9356 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
9357 | json_object_string_add(json_route, | |
9358 | "routerType", | |
9359 | "asbr"); | |
0f478e30 | 9360 | } else { |
d62a17ae | 9361 | vty_out(vty, "%s [%d] area: %s", |
996c9314 LB |
9362 | (or->path_type == OSPF_PATH_INTER_AREA |
9363 | ? "IA" | |
9364 | : " "), | |
9365 | or->cost, inet_ntoa(or->u.std.area_id)); | |
d62a17ae | 9366 | /* Show flags. */ |
9367 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
9368 | (or->u.std.flags & ROUTER_LSA_BORDER |
9369 | ? ", ABR" | |
9370 | : ""), | |
9371 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
9372 | ? ", ASBR" | |
9373 | : "")); | |
0f478e30 CS |
9374 | } |
9375 | ||
9376 | if (json) { | |
996c9314 | 9377 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 9378 | json_object_object_add(json_route, "nexthops", |
996c9314 | 9379 | json_nexthop_array); |
0f478e30 CS |
9380 | } |
9381 | ||
996c9314 | 9382 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 9383 | if (json) { |
996c9314 | 9384 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
9385 | json_object_array_add( |
9386 | json_nexthop_array, | |
9387 | json_nexthop); | |
9388 | } | |
9389 | if (if_lookup_by_index(path->ifindex, | |
9390 | ospf->vrf_id)) { | |
9391 | if (path->nexthop.s_addr == 0) { | |
9392 | if (json) { | |
9393 | json_object_string_add( | |
9394 | json_nexthop, | |
996c9314 | 9395 | "ip", " "); |
0f478e30 CS |
9396 | json_object_string_add( |
9397 | json_nexthop, | |
9398 | "directly attached to", | |
d62a17ae | 9399 | ifindex2ifname( |
9400 | path->ifindex, | |
b5a8894d | 9401 | ospf->vrf_id)); |
0f478e30 | 9402 | } else { |
d62a17ae | 9403 | vty_out(vty, |
996c9314 LB |
9404 | "%24s directly attached to %s\n", |
9405 | "", | |
9406 | ifindex2ifname( | |
9407 | path->ifindex, | |
9408 | ospf->vrf_id)); | |
0f478e30 CS |
9409 | } |
9410 | } else { | |
9411 | if (json) { | |
9412 | json_object_string_add( | |
9413 | json_nexthop, | |
9414 | "ip", | |
996c9314 LB |
9415 | inet_ntoa( |
9416 | path->nexthop)); | |
0f478e30 CS |
9417 | json_object_string_add( |
9418 | json_nexthop, | |
9419 | "via", | |
d62a17ae | 9420 | ifindex2ifname( |
9421 | path->ifindex, | |
b5a8894d | 9422 | ospf->vrf_id)); |
0f478e30 CS |
9423 | } else { |
9424 | vty_out(vty, | |
996c9314 LB |
9425 | "%24s via %s, %s\n", |
9426 | "", | |
9427 | inet_ntoa( | |
9428 | path->nexthop), | |
9429 | ifindex2ifname( | |
9430 | path->ifindex, | |
9431 | ospf->vrf_id)); | |
0f478e30 | 9432 | } |
d62a17ae | 9433 | } |
9434 | } | |
9435 | } | |
9436 | } | |
0f478e30 CS |
9437 | if (!json) |
9438 | json_object_free(json_route); | |
9439 | } | |
9440 | if (!json) | |
9441 | vty_out(vty, "\n"); | |
d62a17ae | 9442 | } |
9443 | ||
b5a8894d | 9444 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
9445 | struct route_table *rt, |
9446 | json_object *json) | |
d62a17ae | 9447 | { |
9448 | struct route_node *rn; | |
9449 | struct ospf_route *er; | |
9450 | struct listnode *pnode, *pnnode; | |
9451 | struct ospf_path *path; | |
0f478e30 CS |
9452 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
9453 | *json_nexthop = NULL; | |
d62a17ae | 9454 | |
0f478e30 | 9455 | if (!json) |
996c9314 LB |
9456 | vty_out(vty, |
9457 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
9458 | |
9459 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
9460 | if ((er = rn->info) == NULL) | |
9461 | continue; | |
9462 | ||
9463 | char buf1[19]; | |
9464 | ||
772270f3 QY |
9465 | snprintf(buf1, sizeof(buf1), "%s/%d", |
9466 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen); | |
0f478e30 CS |
9467 | json_route = json_object_new_object(); |
9468 | if (json) { | |
996c9314 LB |
9469 | json_object_object_add(json, buf1, json_route); |
9470 | json_object_to_json_string_ext( | |
9471 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 | 9472 | } |
d62a17ae | 9473 | |
0f478e30 CS |
9474 | switch (er->path_type) { |
9475 | case OSPF_PATH_TYPE1_EXTERNAL: | |
9476 | if (json) { | |
996c9314 | 9477 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
9478 | "N E1"); |
9479 | json_object_int_add(json_route, "cost", | |
996c9314 | 9480 | er->cost); |
0f478e30 | 9481 | } else { |
d62a17ae | 9482 | vty_out(vty, |
996c9314 LB |
9483 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
9484 | "\n", | |
9485 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
9486 | } |
9487 | break; | |
9488 | case OSPF_PATH_TYPE2_EXTERNAL: | |
9489 | if (json) { | |
996c9314 | 9490 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
9491 | "N E2"); |
9492 | json_object_int_add(json_route, "cost", | |
996c9314 | 9493 | er->cost); |
0f478e30 | 9494 | } else { |
d62a17ae | 9495 | vty_out(vty, |
996c9314 LB |
9496 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
9497 | "\n", | |
9498 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 9499 | er->u.ext.tag); |
d62a17ae | 9500 | } |
0f478e30 CS |
9501 | break; |
9502 | } | |
d62a17ae | 9503 | |
0f478e30 CS |
9504 | if (json) { |
9505 | json_nexthop_array = json_object_new_array(); | |
9506 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 9507 | json_nexthop_array); |
0f478e30 CS |
9508 | } |
9509 | ||
996c9314 | 9510 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
9511 | if (json) { |
9512 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
9513 | json_object_array_add(json_nexthop_array, |
9514 | json_nexthop); | |
0f478e30 CS |
9515 | } |
9516 | ||
996c9314 | 9517 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
0f478e30 CS |
9518 | if (path->nexthop.s_addr == 0) { |
9519 | if (json) { | |
9520 | json_object_string_add( | |
996c9314 LB |
9521 | json_nexthop, "ip", |
9522 | " "); | |
0f478e30 CS |
9523 | json_object_string_add( |
9524 | json_nexthop, | |
9525 | "directly attached to", | |
d62a17ae | 9526 | ifindex2ifname( |
996c9314 LB |
9527 | path->ifindex, |
9528 | ospf->vrf_id)); | |
0f478e30 | 9529 | } else { |
d62a17ae | 9530 | vty_out(vty, |
996c9314 LB |
9531 | "%24s directly attached to %s\n", |
9532 | "", | |
9533 | ifindex2ifname( | |
9534 | path->ifindex, | |
9535 | ospf->vrf_id)); | |
0f478e30 CS |
9536 | } |
9537 | } else { | |
9538 | if (json) { | |
9539 | json_object_string_add( | |
996c9314 | 9540 | json_nexthop, "ip", |
d62a17ae | 9541 | inet_ntoa( |
996c9314 | 9542 | path->nexthop)); |
0f478e30 | 9543 | json_object_string_add( |
996c9314 | 9544 | json_nexthop, "via", |
d62a17ae | 9545 | ifindex2ifname( |
996c9314 LB |
9546 | path->ifindex, |
9547 | ospf->vrf_id)); | |
0f478e30 CS |
9548 | } else { |
9549 | vty_out(vty, | |
996c9314 LB |
9550 | "%24s via %s, %s\n", |
9551 | "", | |
9552 | inet_ntoa( | |
9553 | path->nexthop), | |
9554 | ifindex2ifname( | |
9555 | path->ifindex, | |
9556 | ospf->vrf_id)); | |
0f478e30 | 9557 | } |
d62a17ae | 9558 | } |
54bedb55 | 9559 | } |
d62a17ae | 9560 | } |
0f478e30 CS |
9561 | if (!json) |
9562 | json_object_free(json_route); | |
9563 | } | |
9564 | if (!json) | |
9565 | vty_out(vty, "\n"); | |
718e3744 | 9566 | } |
9567 | ||
d62a17ae | 9568 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
9569 | struct ospf *ospf, |
9570 | uint8_t use_vrf) | |
718e3744 | 9571 | { |
d62a17ae | 9572 | if (ospf->instance) |
9573 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 9574 | |
b1c3ae8c | 9575 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 9576 | |
d62a17ae | 9577 | if (ospf->new_table == NULL) { |
9578 | vty_out(vty, "No OSPF routing information exist\n"); | |
9579 | return CMD_SUCCESS; | |
9580 | } | |
718e3744 | 9581 | |
d62a17ae | 9582 | /* Show Network routes. |
9583 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 9584 | |
d62a17ae | 9585 | /* Show Router routes. */ |
0f478e30 | 9586 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 9587 | |
d62a17ae | 9588 | vty_out(vty, "\n"); |
7c8ff89e | 9589 | |
d62a17ae | 9590 | return CMD_SUCCESS; |
718e3744 | 9591 | } |
718e3744 | 9592 | |
7c8ff89e DS |
9593 | DEFUN (show_ip_ospf_border_routers, |
9594 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 9595 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 9596 | SHOW_STR |
9597 | IP_STR | |
9598 | "OSPF information\n" | |
b5a8894d CS |
9599 | VRF_CMD_HELP_STR |
9600 | "All VRFs\n" | |
7c8ff89e | 9601 | "Show all the ABR's and ASBR's\n") |
718e3744 | 9602 | { |
b5a8894d CS |
9603 | struct ospf *ospf = NULL; |
9604 | struct listnode *node = NULL; | |
9605 | char *vrf_name = NULL; | |
2951a7a4 | 9606 | bool all_vrf = false; |
b5a8894d CS |
9607 | int ret = CMD_SUCCESS; |
9608 | int inst = 0; | |
9609 | int idx_vrf = 0; | |
d7c0a89a | 9610 | uint8_t use_vrf = 0; |
68980084 | 9611 | |
43b8d1d8 | 9612 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 9613 | |
b5a8894d | 9614 | if (vrf_name) { |
2951a7a4 | 9615 | bool ospf_output = false; |
874f58d8 | 9616 | |
b1c3ae8c | 9617 | use_vrf = 1; |
94d4c685 | 9618 | |
b5a8894d CS |
9619 | if (all_vrf) { |
9620 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9621 | if (!ospf->oi_running) | |
9622 | continue; | |
b5a8894d | 9623 | |
2951a7a4 | 9624 | ospf_output = true; |
996c9314 LB |
9625 | ret = show_ip_ospf_border_routers_common( |
9626 | vty, ospf, use_vrf); | |
b5a8894d | 9627 | } |
9f049418 DS |
9628 | |
9629 | if (!ospf_output) | |
94d4c685 | 9630 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d CS |
9631 | } else { |
9632 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 9633 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 9634 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 9635 | return CMD_SUCCESS; |
9f049418 | 9636 | } |
b5a8894d | 9637 | |
b1c3ae8c CS |
9638 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
9639 | use_vrf); | |
b5a8894d CS |
9640 | } |
9641 | } else { | |
9642 | /* Display default ospf (instance 0) info */ | |
9643 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 9644 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 9645 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 9646 | return CMD_SUCCESS; |
9f049418 DS |
9647 | } |
9648 | ||
b1c3ae8c | 9649 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
9650 | } |
9651 | ||
9652 | return ret; | |
7c8ff89e DS |
9653 | } |
9654 | ||
9655 | DEFUN (show_ip_ospf_instance_border_routers, | |
9656 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 9657 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
9658 | SHOW_STR |
9659 | IP_STR | |
9660 | "OSPF information\n" | |
9661 | "Instance ID\n" | |
9662 | "Show all the ABR's and ASBR's\n") | |
9663 | { | |
d62a17ae | 9664 | int idx_number = 3; |
9665 | struct ospf *ospf; | |
d7c0a89a | 9666 | unsigned short instance = 0; |
7c8ff89e | 9667 | |
d62a17ae | 9668 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
9669 | ospf = ospf_lookup_instance(instance); |
9670 | if (ospf == NULL) | |
9671 | return CMD_NOT_MY_INSTANCE; | |
9672 | ||
9673 | if (!ospf->oi_running) | |
d62a17ae | 9674 | return CMD_SUCCESS; |
7c8ff89e | 9675 | |
b1c3ae8c | 9676 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
9677 | } |
9678 | ||
b1c3ae8c | 9679 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 9680 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 9681 | { |
0f478e30 CS |
9682 | json_object *json_vrf = NULL; |
9683 | ||
d62a17ae | 9684 | if (ospf->instance) |
9685 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 9686 | |
0f478e30 CS |
9687 | |
9688 | if (json) { | |
9689 | if (use_vrf) | |
9690 | json_vrf = json_object_new_object(); | |
9691 | else | |
9692 | json_vrf = json; | |
9693 | } | |
9694 | ||
9695 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
87bd50e8 | 9696 | |
d62a17ae | 9697 | if (ospf->new_table == NULL) { |
9698 | vty_out(vty, "No OSPF routing information exist\n"); | |
9699 | return CMD_SUCCESS; | |
9700 | } | |
718e3744 | 9701 | |
d62a17ae | 9702 | /* Show Network routes. */ |
0f478e30 | 9703 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 9704 | |
d62a17ae | 9705 | /* Show Router routes. */ |
0f478e30 | 9706 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 9707 | |
d62a17ae | 9708 | /* Show AS External routes. */ |
0f478e30 CS |
9709 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
9710 | json_vrf); | |
718e3744 | 9711 | |
0f478e30 CS |
9712 | if (json) { |
9713 | if (use_vrf) { | |
996c9314 LB |
9714 | // json_object_object_add(json_vrf, "areas", |
9715 | // json_areas); | |
0f478e30 CS |
9716 | if (ospf->vrf_id == VRF_DEFAULT) |
9717 | json_object_object_add(json, "default", | |
9718 | json_vrf); | |
9719 | else | |
9720 | json_object_object_add(json, ospf->name, | |
9721 | json_vrf); | |
9722 | } | |
9723 | } else { | |
9724 | vty_out(vty, "\n"); | |
9725 | } | |
7c8ff89e | 9726 | |
d62a17ae | 9727 | return CMD_SUCCESS; |
718e3744 | 9728 | } |
9729 | ||
7c8ff89e DS |
9730 | DEFUN (show_ip_ospf_route, |
9731 | show_ip_ospf_route_cmd, | |
0f478e30 | 9732 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
9733 | SHOW_STR |
9734 | IP_STR | |
9735 | "OSPF information\n" | |
9736 | VRF_CMD_HELP_STR | |
9737 | "All VRFs\n" | |
0f478e30 CS |
9738 | "OSPF routing table\n" |
9739 | JSON_STR) | |
b5a8894d CS |
9740 | { |
9741 | struct ospf *ospf = NULL; | |
9742 | struct listnode *node = NULL; | |
9743 | char *vrf_name = NULL; | |
2951a7a4 | 9744 | bool all_vrf = false; |
b5a8894d CS |
9745 | int ret = CMD_SUCCESS; |
9746 | int inst = 0; | |
9747 | int idx_vrf = 0; | |
d7c0a89a | 9748 | uint8_t use_vrf = 0; |
9f049418 | 9749 | bool uj = use_json(argc, argv); |
0f478e30 CS |
9750 | json_object *json = NULL; |
9751 | ||
9752 | if (uj) | |
9753 | json = json_object_new_object(); | |
7c8ff89e | 9754 | |
43b8d1d8 | 9755 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 9756 | |
b5a8894d CS |
9757 | /* vrf input is provided could be all or specific vrf*/ |
9758 | if (vrf_name) { | |
2951a7a4 | 9759 | bool ospf_output = false; |
874f58d8 | 9760 | |
b1c3ae8c | 9761 | use_vrf = 1; |
94d4c685 | 9762 | |
b5a8894d CS |
9763 | if (all_vrf) { |
9764 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9765 | if (!ospf->oi_running) | |
9766 | continue; | |
2951a7a4 | 9767 | ospf_output = true; |
0f478e30 | 9768 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 9769 | use_vrf); |
b5a8894d | 9770 | } |
0f478e30 CS |
9771 | |
9772 | if (uj) { | |
1406159f | 9773 | /* Keep Non-pretty format */ |
0f478e30 | 9774 | vty_out(vty, "%s\n", |
1406159f | 9775 | json_object_to_json_string(json)); |
0f478e30 | 9776 | json_object_free(json); |
9f049418 DS |
9777 | } else if (!ospf_output) |
9778 | vty_out(vty, "%% OSPF instance not found\n"); | |
0f478e30 | 9779 | |
b5a8894d CS |
9780 | return ret; |
9781 | } | |
9782 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 9783 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
9784 | if (uj) { |
9785 | vty_out(vty, "%s\n", | |
9786 | json_object_to_json_string_ext( | |
9787 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 9788 | json_object_free(json); |
9f049418 | 9789 | } else |
94d4c685 | 9790 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 9791 | |
b5a8894d | 9792 | return CMD_SUCCESS; |
0f478e30 | 9793 | } |
b5a8894d CS |
9794 | } else { |
9795 | /* Display default ospf (instance 0) info */ | |
9796 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 9797 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
9798 | if (uj) { |
9799 | vty_out(vty, "%s\n", | |
9800 | json_object_to_json_string_ext( | |
9801 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 9802 | json_object_free(json); |
9f049418 | 9803 | } else |
94d4c685 | 9804 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 9805 | |
b5a8894d | 9806 | return CMD_SUCCESS; |
0f478e30 CS |
9807 | } |
9808 | } | |
9809 | ||
9810 | if (ospf) { | |
9811 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 9812 | /* Keep Non-pretty format */ |
0f478e30 | 9813 | if (uj) |
1406159f | 9814 | vty_out(vty, "%s\n", json_object_to_json_string(json)); |
b5a8894d CS |
9815 | } |
9816 | ||
0f478e30 CS |
9817 | if (uj) |
9818 | json_object_free(json); | |
b5a8894d CS |
9819 | |
9820 | return ret; | |
7c8ff89e DS |
9821 | } |
9822 | ||
9823 | DEFUN (show_ip_ospf_instance_route, | |
9824 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 9825 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
9826 | SHOW_STR |
9827 | IP_STR | |
9828 | "OSPF information\n" | |
9829 | "Instance ID\n" | |
9830 | "OSPF routing table\n") | |
9831 | { | |
d62a17ae | 9832 | int idx_number = 3; |
9833 | struct ospf *ospf; | |
d7c0a89a | 9834 | unsigned short instance = 0; |
7c8ff89e | 9835 | |
d62a17ae | 9836 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
9837 | ospf = ospf_lookup_instance(instance); |
9838 | if (ospf == NULL) | |
9839 | return CMD_NOT_MY_INSTANCE; | |
9840 | ||
9841 | if (!ospf->oi_running) | |
d62a17ae | 9842 | return CMD_SUCCESS; |
7c8ff89e | 9843 | |
0f478e30 | 9844 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 9845 | } |
6b0655a2 | 9846 | |
b5a8894d CS |
9847 | |
9848 | DEFUN (show_ip_ospf_vrfs, | |
9849 | show_ip_ospf_vrfs_cmd, | |
9850 | "show ip ospf vrfs [json]", | |
9851 | SHOW_STR | |
9852 | IP_STR | |
9853 | "OSPF information\n" | |
9854 | "Show OSPF VRFs \n" | |
9855 | JSON_STR) | |
9856 | { | |
9f049418 | 9857 | bool uj = use_json(argc, argv); |
b5a8894d CS |
9858 | json_object *json = NULL; |
9859 | json_object *json_vrfs = NULL; | |
9860 | struct ospf *ospf = NULL; | |
9861 | struct listnode *node = NULL; | |
9862 | int count = 0; | |
2b64873d | 9863 | static const char header[] = "Name Id RouterId "; |
b5a8894d CS |
9864 | |
9865 | if (uj) { | |
9866 | json = json_object_new_object(); | |
9867 | json_vrfs = json_object_new_object(); | |
9868 | } | |
9869 | ||
9870 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9871 | json_object *json_vrf = NULL; | |
9872 | const char *name = NULL; | |
fe3da9e7 | 9873 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
9874 | |
9875 | count++; | |
9876 | ||
9877 | if (!uj && count == 1) | |
9878 | vty_out(vty, "%s\n", header); | |
9879 | if (uj) | |
9880 | json_vrf = json_object_new_object(); | |
9881 | ||
946de1b9 | 9882 | if (ospf->vrf_id == VRF_DEFAULT) |
b5a8894d CS |
9883 | name = VRF_DEFAULT_NAME; |
9884 | else | |
9885 | name = ospf->name; | |
9886 | ||
996c9314 LB |
9887 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
9888 | ? -1 | |
9889 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
9890 | |
9891 | if (uj) { | |
9892 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
9893 | json_object_string_add(json_vrf, "routerId", | |
9894 | inet_ntoa(ospf->router_id)); | |
9895 | ||
9896 | json_object_object_add(json_vrfs, name, json_vrf); | |
9897 | ||
9898 | } else { | |
996c9314 LB |
9899 | vty_out(vty, "%-25s %-5d %-16s \n", name, |
9900 | ospf->vrf_id, inet_ntoa(ospf->router_id)); | |
b5a8894d CS |
9901 | } |
9902 | } | |
9903 | ||
9904 | if (uj) { | |
9905 | json_object_object_add(json, "vrfs", json_vrfs); | |
9906 | json_object_int_add(json, "totalVrfs", count); | |
9907 | ||
996c9314 LB |
9908 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
9909 | json, JSON_C_TO_STRING_PRETTY)); | |
b5a8894d CS |
9910 | json_object_free(json); |
9911 | } else { | |
9912 | if (count) | |
34d6798f | 9913 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
9914 | count); |
9915 | } | |
9916 | ||
9917 | return CMD_SUCCESS; | |
9918 | } | |
9919 | ||
2b64873d DL |
9920 | static const char *const ospf_abr_type_str[] = { |
9921 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
9922 | }; | |
718e3744 | 9923 | |
2b64873d DL |
9924 | static const char *const ospf_shortcut_mode_str[] = { |
9925 | "default", "enable", "disable" | |
9926 | }; | |
718e3744 | 9927 | |
2b64873d DL |
9928 | static const char *const ospf_int_type_str[] = { |
9929 | "unknown", /* should never be used. */ | |
9930 | "point-to-point", | |
9931 | "broadcast", | |
9932 | "non-broadcast", | |
9933 | "point-to-multipoint", | |
9934 | "virtual-link", /* should never be used. */ | |
9935 | "loopback" | |
9936 | }; | |
718e3744 | 9937 | |
545f0503 | 9938 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 9939 | { |
f4e14fdb | 9940 | struct listnode *node; |
d62a17ae | 9941 | struct interface *ifp; |
9942 | struct crypt_key *ck; | |
d62a17ae | 9943 | struct route_node *rn = NULL; |
9944 | struct ospf_if_params *params; | |
43b8d1d8 | 9945 | int write = 0; |
545f0503 | 9946 | struct ospf *ospf = vrf->info; |
d62a17ae | 9947 | |
545f0503 | 9948 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 9949 | |
545f0503 CS |
9950 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
9951 | continue; | |
35955c14 | 9952 | |
545f0503 | 9953 | vty_frame(vty, "!\n"); |
a36898e7 | 9954 | if (ifp->vrf_id == VRF_DEFAULT) |
545f0503 CS |
9955 | vty_frame(vty, "interface %s\n", ifp->name); |
9956 | else | |
996c9314 LB |
9957 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, |
9958 | vrf->name); | |
545f0503 CS |
9959 | if (ifp->desc) |
9960 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 9961 | |
545f0503 | 9962 | write++; |
43b8d1d8 | 9963 | |
545f0503 | 9964 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 9965 | |
545f0503 CS |
9966 | do { |
9967 | /* Interface Network print. */ | |
9968 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
9969 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 9970 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
9971 | vty_out(vty, " ip ospf network %s", |
9972 | ospf_int_type_str | |
996c9314 | 9973 | [params->type]); |
e425c019 | 9974 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
9975 | vty_out(vty, " %s", |
9976 | inet_ntoa( | |
996c9314 | 9977 | rn->p.u.prefix4)); |
545f0503 | 9978 | vty_out(vty, "\n"); |
d62a17ae | 9979 | } |
545f0503 | 9980 | } |
d62a17ae | 9981 | |
545f0503 CS |
9982 | /* OSPF interface authentication print */ |
9983 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
996c9314 | 9984 | && params->auth_type != OSPF_AUTH_NOTSET) { |
545f0503 | 9985 | const char *auth_str; |
d62a17ae | 9986 | |
545f0503 CS |
9987 | /* Translation tables are not that much help |
9988 | * here due to syntax | |
9989 | * of the simple option */ | |
9990 | switch (params->auth_type) { | |
d62a17ae | 9991 | |
545f0503 CS |
9992 | case OSPF_AUTH_NULL: |
9993 | auth_str = " null"; | |
9994 | break; | |
d62a17ae | 9995 | |
545f0503 CS |
9996 | case OSPF_AUTH_SIMPLE: |
9997 | auth_str = ""; | |
9998 | break; | |
b5a8894d | 9999 | |
545f0503 CS |
10000 | case OSPF_AUTH_CRYPTOGRAPHIC: |
10001 | auth_str = " message-digest"; | |
10002 | break; | |
d62a17ae | 10003 | |
545f0503 CS |
10004 | default: |
10005 | auth_str = ""; | |
10006 | break; | |
c7fd72d2 | 10007 | } |
d62a17ae | 10008 | |
545f0503 CS |
10009 | vty_out(vty, " ip ospf authentication%s", |
10010 | auth_str); | |
e425c019 | 10011 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 10012 | vty_out(vty, " %s", |
c7fd72d2 | 10013 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
10014 | vty_out(vty, "\n"); |
10015 | } | |
d62a17ae | 10016 | |
545f0503 CS |
10017 | /* Simple Authentication Password print. */ |
10018 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 10019 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
10020 | vty_out(vty, " ip ospf authentication-key %s", |
10021 | params->auth_simple); | |
e425c019 | 10022 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
10023 | vty_out(vty, " %s", |
10024 | inet_ntoa(rn->p.u.prefix4)); | |
10025 | vty_out(vty, "\n"); | |
10026 | } | |
c7fd72d2 | 10027 | |
545f0503 CS |
10028 | /* Cryptographic Authentication Key print. */ |
10029 | if (params && params->auth_crypt) { | |
996c9314 LB |
10030 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
10031 | node, ck)) { | |
545f0503 CS |
10032 | vty_out(vty, |
10033 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 10034 | ck->key_id, ck->auth_key); |
e425c019 | 10035 | if (params != IF_DEF_PARAMS(ifp) && rn) |
c7fd72d2 | 10036 | vty_out(vty, " %s", |
996c9314 LB |
10037 | inet_ntoa( |
10038 | rn->p.u.prefix4)); | |
c7fd72d2 CS |
10039 | vty_out(vty, "\n"); |
10040 | } | |
545f0503 | 10041 | } |
d62a17ae | 10042 | |
545f0503 | 10043 | /* Interface Output Cost print. */ |
996c9314 | 10044 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
10045 | vty_out(vty, " ip ospf cost %u", |
10046 | params->output_cost_cmd); | |
e425c019 | 10047 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 10048 | vty_out(vty, " %s", |
43b8d1d8 | 10049 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
10050 | vty_out(vty, "\n"); |
10051 | } | |
d62a17ae | 10052 | |
545f0503 CS |
10053 | /* Hello Interval print. */ |
10054 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 10055 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
10056 | vty_out(vty, " ip ospf hello-interval %u", |
10057 | params->v_hello); | |
e425c019 | 10058 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
10059 | vty_out(vty, " %s", |
10060 | inet_ntoa(rn->p.u.prefix4)); | |
10061 | vty_out(vty, "\n"); | |
10062 | } | |
d62a17ae | 10063 | |
d62a17ae | 10064 | |
545f0503 CS |
10065 | /* Router Dead Interval print. */ |
10066 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
996c9314 LB |
10067 | && params->v_wait |
10068 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
545f0503 | 10069 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 10070 | |
545f0503 CS |
10071 | /* fast hello ? */ |
10072 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 10073 | fast_hello)) |
545f0503 CS |
10074 | vty_out(vty, |
10075 | "minimal hello-multiplier %d", | |
10076 | params->fast_hello); | |
10077 | else | |
996c9314 | 10078 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 10079 | |
e425c019 | 10080 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 10081 | vty_out(vty, " %s", |
43b8d1d8 | 10082 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
10083 | vty_out(vty, "\n"); |
10084 | } | |
d62a17ae | 10085 | |
545f0503 CS |
10086 | /* Router Priority print. */ |
10087 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
10088 | && params->priority |
10089 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
10090 | vty_out(vty, " ip ospf priority %u", |
10091 | params->priority); | |
e425c019 | 10092 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 10093 | vty_out(vty, " %s", |
43b8d1d8 | 10094 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
10095 | vty_out(vty, "\n"); |
10096 | } | |
d62a17ae | 10097 | |
545f0503 CS |
10098 | /* Retransmit Interval print. */ |
10099 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
10100 | retransmit_interval) |
10101 | && params->retransmit_interval | |
10102 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
10103 | vty_out(vty, " ip ospf retransmit-interval %u", |
10104 | params->retransmit_interval); | |
e425c019 | 10105 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 10106 | vty_out(vty, " %s", |
43b8d1d8 | 10107 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
10108 | vty_out(vty, "\n"); |
10109 | } | |
d62a17ae | 10110 | |
545f0503 | 10111 | /* Transmit Delay print. */ |
996c9314 LB |
10112 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
10113 | && params->transmit_delay | |
10114 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
10115 | vty_out(vty, " ip ospf transmit-delay %u", |
10116 | params->transmit_delay); | |
e425c019 | 10117 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 10118 | vty_out(vty, " %s", |
996c9314 | 10119 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
10120 | vty_out(vty, "\n"); |
10121 | } | |
d62a17ae | 10122 | |
545f0503 CS |
10123 | /* Area print. */ |
10124 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
10125 | if (ospf && ospf->instance) | |
10126 | vty_out(vty, " ip ospf %d", | |
10127 | ospf->instance); | |
10128 | else | |
10129 | vty_out(vty, " ip ospf"); | |
d62a17ae | 10130 | |
1f9d4e3d | 10131 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 10132 | |
996c9314 LB |
10133 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
10134 | params->if_area_id_fmt); | |
545f0503 | 10135 | vty_out(vty, " area %s", buf); |
e425c019 | 10136 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 10137 | vty_out(vty, " %s", |
996c9314 | 10138 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
10139 | vty_out(vty, "\n"); |
10140 | } | |
d62a17ae | 10141 | |
545f0503 | 10142 | /* bfd print. */ |
e89ffeee | 10143 | if (params && params->bfd_info) |
545f0503 | 10144 | ospf_bfd_write_config(vty, params); |
d62a17ae | 10145 | |
545f0503 CS |
10146 | /* MTU ignore print. */ |
10147 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 10148 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
10149 | if (params->mtu_ignore == 0) |
10150 | vty_out(vty, " no ip ospf mtu-ignore"); | |
10151 | else | |
10152 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 10153 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 10154 | vty_out(vty, " %s", |
996c9314 | 10155 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
10156 | vty_out(vty, "\n"); |
10157 | } | |
a8b828f3 | 10158 | |
132a782e | 10159 | /* LDP-Sync print */ |
10160 | if (params && params->ldp_sync_info) | |
10161 | ospf_ldp_sync_if_write_config(vty, params); | |
d62a17ae | 10162 | |
545f0503 CS |
10163 | while (1) { |
10164 | if (rn == NULL) | |
996c9314 | 10165 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
10166 | else |
10167 | rn = route_next(rn); | |
43b8d1d8 | 10168 | |
545f0503 CS |
10169 | if (rn == NULL) |
10170 | break; | |
10171 | params = rn->info; | |
10172 | if (params != NULL) | |
10173 | break; | |
10174 | } | |
10175 | } while (rn); | |
43b8d1d8 | 10176 | |
545f0503 CS |
10177 | ospf_opaque_config_write_if(vty, ifp); |
10178 | ||
10179 | vty_endframe(vty, NULL); | |
b5a8894d | 10180 | } |
545f0503 | 10181 | |
d62a17ae | 10182 | return write; |
718e3744 | 10183 | } |
10184 | ||
43b8d1d8 CS |
10185 | /* Configuration write function for ospfd. */ |
10186 | static int config_write_interface(struct vty *vty) | |
10187 | { | |
10188 | int write = 0; | |
545f0503 | 10189 | struct vrf *vrf = NULL; |
43b8d1d8 | 10190 | |
545f0503 CS |
10191 | /* Display all VRF aware OSPF interface configuration */ |
10192 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
10193 | write += config_write_interface_one(vty, vrf); | |
10194 | } | |
43b8d1d8 CS |
10195 | |
10196 | return write; | |
10197 | } | |
10198 | ||
d62a17ae | 10199 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 10200 | { |
d62a17ae | 10201 | struct route_node *rn; |
fc746f1c | 10202 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 10203 | |
d62a17ae | 10204 | /* `network area' print. */ |
10205 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
10206 | if (rn->info) { | |
10207 | struct ospf_network *n = rn->info; | |
718e3744 | 10208 | |
d62a17ae | 10209 | /* Create Area ID string by specified Area ID format. */ |
10210 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
fc746f1c | 10211 | inet_ntop(AF_INET, &n->area_id, buf, |
1f9d4e3d | 10212 | sizeof(buf)); |
d62a17ae | 10213 | else |
fc746f1c QY |
10214 | snprintf(buf, sizeof(buf), "%lu", |
10215 | (unsigned long int)ntohl( | |
10216 | n->area_id.s_addr)); | |
718e3744 | 10217 | |
d62a17ae | 10218 | /* Network print. */ |
10219 | vty_out(vty, " network %s/%d area %s\n", | |
10220 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen, | |
10221 | buf); | |
10222 | } | |
718e3744 | 10223 | |
d62a17ae | 10224 | return 0; |
718e3744 | 10225 | } |
10226 | ||
d62a17ae | 10227 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 10228 | { |
d62a17ae | 10229 | struct listnode *node; |
10230 | struct ospf_area *area; | |
fc746f1c | 10231 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 10232 | |
d62a17ae | 10233 | /* Area configuration print. */ |
10234 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
10235 | struct route_node *rn1; | |
718e3744 | 10236 | |
fc746f1c | 10237 | area_id2str(buf, sizeof(buf), &area->area_id, |
d62a17ae | 10238 | area->area_id_fmt); |
718e3744 | 10239 | |
d62a17ae | 10240 | if (area->auth_type != OSPF_AUTH_NULL) { |
10241 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
10242 | vty_out(vty, " area %s authentication\n", buf); | |
10243 | else | |
10244 | vty_out(vty, | |
10245 | " area %s authentication message-digest\n", | |
10246 | buf); | |
10247 | } | |
718e3744 | 10248 | |
d62a17ae | 10249 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
10250 | vty_out(vty, " area %s shortcut %s\n", buf, | |
10251 | ospf_shortcut_mode_str | |
10252 | [area->shortcut_configured]); | |
10253 | ||
10254 | if ((area->external_routing == OSPF_AREA_STUB) | |
10255 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 10256 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 10257 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
10258 | if (area->no_summary) |
10259 | vty_out(vty, " no-summary\n"); | |
10260 | vty_out(vty, "\n"); | |
10261 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 10262 | switch (area->NSSATranslatorRole) { |
10263 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
10264 | vty_out(vty, |
10265 | " area %s nssa translate-never\n", | |
10266 | buf); | |
d62a17ae | 10267 | break; |
10268 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
10269 | vty_out(vty, |
10270 | " area %s nssa translate-always\n", | |
10271 | buf); | |
d62a17ae | 10272 | break; |
2643b2bc CS |
10273 | case OSPF_NSSA_ROLE_CANDIDATE: |
10274 | vty_out(vty, " area %s nssa \n", buf); | |
10275 | break; | |
d62a17ae | 10276 | } |
7ef56a73 CS |
10277 | if (area->no_summary) |
10278 | vty_out(vty, | |
10279 | " area %s nssa no-summary\n", | |
10280 | buf); | |
d62a17ae | 10281 | } |
718e3744 | 10282 | |
d62a17ae | 10283 | if (area->default_cost != 1) |
10284 | vty_out(vty, " area %s default-cost %d\n", buf, | |
10285 | area->default_cost); | |
10286 | } | |
718e3744 | 10287 | |
d62a17ae | 10288 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
10289 | if (rn1->info) { | |
10290 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 10291 | |
d62a17ae | 10292 | vty_out(vty, " area %s range %s/%d", buf, |
10293 | inet_ntoa(rn1->p.u.prefix4), | |
10294 | rn1->p.prefixlen); | |
718e3744 | 10295 | |
d62a17ae | 10296 | if (range->cost_config |
10297 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
10298 | vty_out(vty, " cost %d", | |
10299 | range->cost_config); | |
718e3744 | 10300 | |
d62a17ae | 10301 | if (!CHECK_FLAG(range->flags, |
10302 | OSPF_AREA_RANGE_ADVERTISE)) | |
10303 | vty_out(vty, " not-advertise"); | |
718e3744 | 10304 | |
d62a17ae | 10305 | if (CHECK_FLAG(range->flags, |
10306 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
10307 | vty_out(vty, " substitute %s/%d", | |
10308 | inet_ntoa(range->subst_addr), | |
10309 | range->subst_masklen); | |
10310 | ||
10311 | vty_out(vty, "\n"); | |
10312 | } | |
10313 | ||
10314 | if (EXPORT_NAME(area)) | |
10315 | vty_out(vty, " area %s export-list %s\n", buf, | |
10316 | EXPORT_NAME(area)); | |
10317 | ||
10318 | if (IMPORT_NAME(area)) | |
10319 | vty_out(vty, " area %s import-list %s\n", buf, | |
10320 | IMPORT_NAME(area)); | |
10321 | ||
10322 | if (PREFIX_NAME_IN(area)) | |
10323 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
10324 | PREFIX_NAME_IN(area)); | |
10325 | ||
10326 | if (PREFIX_NAME_OUT(area)) | |
10327 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
10328 | buf, PREFIX_NAME_OUT(area)); | |
10329 | } | |
10330 | ||
10331 | return 0; | |
718e3744 | 10332 | } |
10333 | ||
d62a17ae | 10334 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 10335 | { |
d62a17ae | 10336 | struct ospf_nbr_nbma *nbr_nbma; |
10337 | struct route_node *rn; | |
718e3744 | 10338 | |
d62a17ae | 10339 | /* Static Neighbor configuration print. */ |
10340 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
10341 | if ((nbr_nbma = rn->info)) { | |
10342 | vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr)); | |
718e3744 | 10343 | |
d62a17ae | 10344 | if (nbr_nbma->priority |
10345 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
10346 | vty_out(vty, " priority %d", | |
10347 | nbr_nbma->priority); | |
718e3744 | 10348 | |
d62a17ae | 10349 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
10350 | vty_out(vty, " poll-interval %d", | |
10351 | nbr_nbma->v_poll); | |
10352 | ||
10353 | vty_out(vty, "\n"); | |
10354 | } | |
10355 | ||
10356 | return 0; | |
10357 | } | |
10358 | ||
10359 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
10360 | { | |
10361 | struct listnode *node; | |
10362 | struct ospf_vl_data *vl_data; | |
10363 | char buf[INET_ADDRSTRLEN]; | |
10364 | ||
10365 | /* Virtual-Link print */ | |
10366 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
10367 | struct listnode *n2; | |
10368 | struct crypt_key *ck; | |
10369 | struct ospf_interface *oi; | |
10370 | ||
10371 | if (vl_data != NULL) { | |
d62a17ae | 10372 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
10373 | vl_data->vl_area_id_fmt); | |
10374 | oi = vl_data->vl_oi; | |
10375 | ||
10376 | /* timers */ | |
10377 | if (OSPF_IF_PARAM(oi, v_hello) | |
10378 | != OSPF_HELLO_INTERVAL_DEFAULT | |
10379 | || OSPF_IF_PARAM(oi, v_wait) | |
10380 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
10381 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
10382 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
10383 | || OSPF_IF_PARAM(oi, transmit_delay) | |
10384 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
10385 | vty_out(vty, | |
10386 | " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", | |
10387 | buf, inet_ntoa(vl_data->vl_peer), | |
10388 | OSPF_IF_PARAM(oi, v_hello), | |
10389 | OSPF_IF_PARAM(oi, retransmit_interval), | |
10390 | OSPF_IF_PARAM(oi, transmit_delay), | |
10391 | OSPF_IF_PARAM(oi, v_wait)); | |
10392 | else | |
10393 | vty_out(vty, " area %s virtual-link %s\n", buf, | |
10394 | inet_ntoa(vl_data->vl_peer)); | |
10395 | /* Auth key */ | |
10396 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
10397 | != '\0') | |
10398 | vty_out(vty, | |
10399 | " area %s virtual-link %s authentication-key %s\n", | |
10400 | buf, inet_ntoa(vl_data->vl_peer), | |
10401 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
10402 | ->auth_simple); | |
10403 | /* md5 keys */ | |
10404 | for (ALL_LIST_ELEMENTS_RO( | |
10405 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
10406 | ->auth_crypt, | |
10407 | n2, ck)) | |
10408 | vty_out(vty, | |
3efd0893 | 10409 | " area %s virtual-link %s message-digest-key %d md5 %s\n", |
d62a17ae | 10410 | buf, inet_ntoa(vl_data->vl_peer), |
10411 | ck->key_id, ck->auth_key); | |
10412 | } | |
10413 | } | |
10414 | ||
10415 | return 0; | |
718e3744 | 10416 | } |
10417 | ||
6b0655a2 | 10418 | |
d62a17ae | 10419 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 10420 | { |
d62a17ae | 10421 | int type; |
718e3744 | 10422 | |
d62a17ae | 10423 | /* redistribute print. */ |
10424 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
10425 | struct list *red_list; | |
10426 | struct listnode *node; | |
10427 | struct ospf_redist *red; | |
718e3744 | 10428 | |
d62a17ae | 10429 | red_list = ospf->redist[type]; |
10430 | if (!red_list) | |
10431 | continue; | |
7c8ff89e | 10432 | |
d62a17ae | 10433 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
10434 | vty_out(vty, " redistribute %s", | |
10435 | zebra_route_string(type)); | |
10436 | if (red->instance) | |
10437 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 10438 | |
d62a17ae | 10439 | if (red->dmetric.value >= 0) |
10440 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 10441 | |
d62a17ae | 10442 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
10443 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 10444 | |
d62a17ae | 10445 | if (ROUTEMAP_NAME(red)) |
10446 | vty_out(vty, " route-map %s", | |
10447 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 10448 | |
d62a17ae | 10449 | vty_out(vty, "\n"); |
10450 | } | |
10451 | } | |
718e3744 | 10452 | |
d62a17ae | 10453 | return 0; |
718e3744 | 10454 | } |
10455 | ||
07b33add | 10456 | static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *backet, |
10457 | void *arg) | |
10458 | { | |
10459 | struct advRtr *rtr = backet->data; | |
10460 | struct vty *vty = (struct vty *)arg; | |
10461 | ||
10462 | vty_out(vty, " graceful-restart helper-only %s\n", | |
10463 | inet_ntoa(rtr->advRtrAddr)); | |
10464 | return HASHWALK_CONTINUE; | |
10465 | } | |
10466 | ||
10467 | static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf) | |
10468 | { | |
10469 | if (ospf->is_helper_supported) | |
10470 | vty_out(vty, " graceful-restart helper-only\n"); | |
10471 | ||
10472 | if (!ospf->strict_lsa_check) | |
10473 | vty_out(vty, " no graceful-restart helper strict-lsa-checking\n"); | |
10474 | ||
10475 | if (ospf->only_planned_restart) | |
10476 | vty_out(vty, " graceful-restart helper planned-only\n"); | |
10477 | ||
10478 | if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL) | |
10479 | vty_out(vty, | |
10480 | " graceful-restart helper supported-grace-time %d\n", | |
10481 | ospf->supported_grace_time); | |
10482 | ||
10483 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
10484 | hash_walk(ospf->enable_rtr_list, | |
10485 | ospf_cfg_write_helper_dis_rtr_walkcb, vty); | |
10486 | } | |
10487 | ||
10488 | return 0; | |
10489 | } | |
10490 | ||
d62a17ae | 10491 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 10492 | { |
d62a17ae | 10493 | if (ospf->default_metric != -1) |
10494 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
10495 | return 0; | |
718e3744 | 10496 | } |
10497 | ||
d62a17ae | 10498 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
10499 | { | |
10500 | int type; | |
10501 | struct ospf_redist *red; | |
718e3744 | 10502 | |
d62a17ae | 10503 | if (ospf) { |
10504 | /* distribute-list print. */ | |
10505 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
10506 | if (DISTRIBUTE_NAME(ospf, type)) | |
10507 | vty_out(vty, " distribute-list %s out %s\n", | |
10508 | DISTRIBUTE_NAME(ospf, type), | |
10509 | zebra_route_string(type)); | |
7c8ff89e | 10510 | |
d62a17ae | 10511 | /* default-information print. */ |
10512 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
10513 | vty_out(vty, " default-information originate"); | |
10514 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
10515 | vty_out(vty, " always"); | |
718e3744 | 10516 | |
d62a17ae | 10517 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
10518 | if (red) { | |
10519 | if (red->dmetric.value >= 0) | |
10520 | vty_out(vty, " metric %d", | |
10521 | red->dmetric.value); | |
951da435 | 10522 | |
d62a17ae | 10523 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
10524 | vty_out(vty, " metric-type 1"); | |
718e3744 | 10525 | |
d62a17ae | 10526 | if (ROUTEMAP_NAME(red)) |
10527 | vty_out(vty, " route-map %s", | |
10528 | ROUTEMAP_NAME(red)); | |
10529 | } | |
10530 | ||
10531 | vty_out(vty, "\n"); | |
10532 | } | |
10533 | } | |
10534 | ||
10535 | return 0; | |
718e3744 | 10536 | } |
10537 | ||
d62a17ae | 10538 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
10539 | { | |
10540 | struct route_node *rn; | |
10541 | struct ospf_distance *odistance; | |
10542 | ||
10543 | if (ospf->distance_all) | |
10544 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
10545 | ||
10546 | if (ospf->distance_intra || ospf->distance_inter | |
10547 | || ospf->distance_external) { | |
10548 | vty_out(vty, " distance ospf"); | |
10549 | ||
10550 | if (ospf->distance_intra) | |
10551 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
10552 | if (ospf->distance_inter) | |
10553 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
10554 | if (ospf->distance_external) | |
10555 | vty_out(vty, " external %d", ospf->distance_external); | |
10556 | ||
10557 | vty_out(vty, "\n"); | |
10558 | } | |
10559 | ||
10560 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
10561 | if ((odistance = rn->info) != NULL) { | |
10562 | vty_out(vty, " distance %d %s/%d %s\n", | |
10563 | odistance->distance, inet_ntoa(rn->p.u.prefix4), | |
10564 | rn->p.prefixlen, | |
10565 | odistance->access_list ? odistance->access_list | |
10566 | : ""); | |
10567 | } | |
10568 | return 0; | |
718e3744 | 10569 | } |
10570 | ||
43b8d1d8 | 10571 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 10572 | { |
f4e14fdb | 10573 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 10574 | struct interface *ifp; |
10575 | struct ospf_interface *oi; | |
43b8d1d8 | 10576 | struct listnode *node = NULL; |
d62a17ae | 10577 | int write = 0; |
10578 | ||
43b8d1d8 CS |
10579 | /* `router ospf' print. */ |
10580 | if (ospf->instance && ospf->name) { | |
996c9314 LB |
10581 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
10582 | ospf->name); | |
43b8d1d8 | 10583 | } else if (ospf->instance) { |
996c9314 | 10584 | vty_out(vty, "router ospf %d\n", ospf->instance); |
43b8d1d8 | 10585 | } else if (ospf->name) { |
996c9314 | 10586 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
10587 | } else |
10588 | vty_out(vty, "router ospf\n"); | |
10589 | ||
10590 | if (!ospf->networks) { | |
10591 | write++; | |
b5a8894d | 10592 | return write; |
43b8d1d8 | 10593 | } |
d62a17ae | 10594 | |
43b8d1d8 CS |
10595 | /* Router ID print. */ |
10596 | if (ospf->router_id_static.s_addr != 0) | |
10597 | vty_out(vty, " ospf router-id %s\n", | |
10598 | inet_ntoa(ospf->router_id_static)); | |
d62a17ae | 10599 | |
43b8d1d8 CS |
10600 | /* ABR type print. */ |
10601 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
10602 | vty_out(vty, " ospf abr-type %s\n", | |
10603 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 10604 | |
43b8d1d8 CS |
10605 | /* log-adjacency-changes flag print. */ |
10606 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
10607 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
10608 | vty_out(vty, " log-adjacency-changes detail\n"); | |
c572fbfe | 10609 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
43b8d1d8 | 10610 | vty_out(vty, " log-adjacency-changes\n"); |
c572fbfe | 10611 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
43b8d1d8 CS |
10612 | vty_out(vty, " no log-adjacency-changes\n"); |
10613 | } | |
b5a8894d | 10614 | |
43b8d1d8 CS |
10615 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
10616 | * 12.1. */ | |
10617 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
10618 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 10619 | |
43b8d1d8 CS |
10620 | /* auto-cost reference-bandwidth configuration. */ |
10621 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
10622 | vty_out(vty, | |
3efd0893 | 10623 | "! Important: ensure reference bandwidth is consistent across all routers\n"); |
43b8d1d8 CS |
10624 | vty_out(vty, " auto-cost reference-bandwidth %d\n", |
10625 | ospf->ref_bandwidth); | |
10626 | } | |
d62a17ae | 10627 | |
43b8d1d8 CS |
10628 | /* SPF timers print. */ |
10629 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
10630 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
10631 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
10632 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
10633 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
10634 | |
10635 | /* LSA timers print. */ | |
10636 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
10637 | vty_out(vty, " timers throttle lsa all %d\n", | |
10638 | ospf->min_ls_interval); | |
10639 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
10640 | vty_out(vty, " timers lsa min-arrival %d\n", | |
10641 | ospf->min_ls_arrival); | |
10642 | ||
10643 | /* Write multiplier print. */ | |
10644 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
10645 | vty_out(vty, " ospf write-multiplier %d\n", | |
10646 | ospf->write_oi_count); | |
d62a17ae | 10647 | |
43b8d1d8 CS |
10648 | /* Max-metric router-lsa print */ |
10649 | config_write_stub_router(vty, ospf); | |
d62a17ae | 10650 | |
43b8d1d8 | 10651 | /* SPF refresh parameters print. */ |
996c9314 LB |
10652 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
10653 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 10654 | |
43b8d1d8 CS |
10655 | /* Redistribute information print. */ |
10656 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 10657 | |
07b33add | 10658 | /* Print gr helper configs */ |
10659 | config_write_ospf_gr_helper(vty, ospf); | |
10660 | ||
43b8d1d8 CS |
10661 | /* passive-interface print. */ |
10662 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
10663 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 10664 | |
a92706bb JU |
10665 | /* proactive-arp print. */ |
10666 | if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) { | |
10667 | if (ospf->proactive_arp) | |
10668 | vty_out(vty, " proactive-arp\n"); | |
10669 | else | |
10670 | vty_out(vty, " no proactive-arp\n"); | |
10671 | } | |
10672 | ||
451fda4f | 10673 | FOR_ALL_INTERFACES (vrf, ifp) |
43b8d1d8 CS |
10674 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
10675 | passive_interface) | |
10676 | && IF_DEF_PARAMS(ifp)->passive_interface | |
996c9314 | 10677 | != ospf->passive_interface_default) { |
43b8d1d8 | 10678 | vty_out(vty, " %spassive-interface %s\n", |
996c9314 LB |
10679 | IF_DEF_PARAMS(ifp)->passive_interface ? "" |
10680 | : "no ", | |
43b8d1d8 CS |
10681 | ifp->name); |
10682 | } | |
10683 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
996c9314 | 10684 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) |
43b8d1d8 CS |
10685 | continue; |
10686 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
10687 | passive_interface)) { | |
10688 | if (oi->params->passive_interface | |
996c9314 | 10689 | == IF_DEF_PARAMS(oi->ifp)->passive_interface) |
43b8d1d8 CS |
10690 | continue; |
10691 | } else if (oi->params->passive_interface | |
10692 | == ospf->passive_interface_default) | |
10693 | continue; | |
d62a17ae | 10694 | |
43b8d1d8 CS |
10695 | vty_out(vty, " %spassive-interface %s %s\n", |
10696 | oi->params->passive_interface ? "" : "no ", | |
996c9314 | 10697 | oi->ifp->name, inet_ntoa(oi->address->u.prefix4)); |
43b8d1d8 | 10698 | } |
d62a17ae | 10699 | |
43b8d1d8 CS |
10700 | /* Network area print. */ |
10701 | config_write_network_area(vty, ospf); | |
d62a17ae | 10702 | |
43b8d1d8 CS |
10703 | /* Area config print. */ |
10704 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 10705 | |
43b8d1d8 CS |
10706 | /* static neighbor print. */ |
10707 | config_write_ospf_nbr_nbma(vty, ospf); | |
10708 | ||
10709 | /* Virtual-Link print. */ | |
10710 | config_write_virtual_link(vty, ospf); | |
10711 | ||
10712 | /* Default metric configuration. */ | |
10713 | config_write_ospf_default_metric(vty, ospf); | |
10714 | ||
10715 | /* Distribute-list and default-information print. */ | |
10716 | config_write_ospf_distribute(vty, ospf); | |
10717 | ||
10718 | /* Distance configuration. */ | |
10719 | config_write_ospf_distance(vty, ospf); | |
10720 | ||
10721 | ospf_opaque_config_write_router(vty, ospf); | |
10722 | ||
132a782e | 10723 | /* LDP-Sync print */ |
10724 | ospf_ldp_sync_write_config(vty, ospf); | |
10725 | ||
43b8d1d8 CS |
10726 | write++; |
10727 | return write; | |
10728 | } | |
10729 | ||
10730 | /* OSPF configuration write function. */ | |
10731 | static int ospf_config_write(struct vty *vty) | |
10732 | { | |
10733 | struct ospf *ospf; | |
10734 | struct listnode *ospf_node = NULL; | |
10735 | int write = 0; | |
10736 | ||
10737 | if (listcount(om->ospf) == 0) | |
10738 | return write; | |
10739 | ||
10740 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
10741 | /* VRF Default check if it is running. |
10742 | * Upon daemon start, there could be default instance | |
10743 | * in absence of 'router ospf'/oi_running is disabled. */ | |
10744 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
10745 | write += ospf_config_write_one(vty, ospf); | |
10746 | /* For Non-Default VRF simply display the configuration, | |
10747 | * even if it is not oi_running. */ | |
10748 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 10749 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 10750 | } |
d62a17ae | 10751 | return write; |
10752 | } | |
10753 | ||
10754 | void ospf_vty_show_init(void) | |
10755 | { | |
10756 | /* "show ip ospf" commands. */ | |
10757 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
10758 | ||
10759 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
10760 | ||
10761 | /* "show ip ospf database" commands. */ | |
10762 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
10763 | ||
10764 | install_element(VIEW_NODE, | |
10765 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
10766 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
10767 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
10768 | ||
10769 | /* "show ip ospf interface" commands. */ | |
10770 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
10771 | ||
10772 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
10773 | /* "show ip ospf interface traffic */ |
10774 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 10775 | |
10776 | /* "show ip ospf neighbor" commands. */ | |
10777 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
10778 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
10779 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
10780 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
10781 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
10782 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
10783 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
10784 | ||
10785 | install_element(VIEW_NODE, | |
10786 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
10787 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
10788 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
10789 | install_element(VIEW_NODE, | |
10790 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
10791 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
10792 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
10793 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
10794 | ||
10795 | /* "show ip ospf route" commands. */ | |
10796 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
10797 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
10798 | ||
10799 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
10800 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
10801 | |
10802 | /* "show ip ospf vrfs" commands. */ | |
10803 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
718e3744 | 10804 | } |
10805 | ||
6b0655a2 | 10806 | |
612c2c15 | 10807 | static int config_write_interface(struct vty *vty); |
718e3744 | 10808 | /* ospfd's interface node. */ |
62b346ee | 10809 | static struct cmd_node interface_node = { |
f4b8291f | 10810 | .name = "interface", |
62b346ee | 10811 | .node = INTERFACE_NODE, |
24389580 | 10812 | .parent_node = CONFIG_NODE, |
62b346ee | 10813 | .prompt = "%s(config-if)# ", |
612c2c15 | 10814 | .config_write = config_write_interface, |
62b346ee | 10815 | }; |
718e3744 | 10816 | |
10817 | /* Initialization of OSPF interface. */ | |
d62a17ae | 10818 | static void ospf_vty_if_init(void) |
10819 | { | |
10820 | /* Install interface node. */ | |
612c2c15 | 10821 | install_node(&interface_node); |
d62a17ae | 10822 | if_cmd_init(); |
10823 | ||
10824 | /* "ip ospf authentication" commands. */ | |
10825 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
10826 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
10827 | install_element(INTERFACE_NODE, | |
10828 | &no_ip_ospf_authentication_args_addr_cmd); | |
10829 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
10830 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
10831 | install_element(INTERFACE_NODE, | |
10832 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
10833 | install_element(INTERFACE_NODE, | |
10834 | &no_ospf_authentication_key_authkey_addr_cmd); | |
10835 | ||
10836 | /* "ip ospf message-digest-key" commands. */ | |
10837 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
10838 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
10839 | ||
10840 | /* "ip ospf cost" commands. */ | |
10841 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
10842 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
10843 | ||
10844 | /* "ip ospf mtu-ignore" commands. */ | |
10845 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
10846 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
10847 | ||
10848 | /* "ip ospf dead-interval" commands. */ | |
10849 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
10850 | install_element(INTERFACE_NODE, | |
10851 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
10852 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
10853 | ||
10854 | /* "ip ospf hello-interval" commands. */ | |
10855 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
10856 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
10857 | ||
10858 | /* "ip ospf network" commands. */ | |
10859 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
10860 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
10861 | ||
10862 | /* "ip ospf priority" commands. */ | |
10863 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
10864 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
10865 | ||
10866 | /* "ip ospf retransmit-interval" commands. */ | |
10867 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
10868 | install_element(INTERFACE_NODE, | |
10869 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
10870 | ||
10871 | /* "ip ospf transmit-delay" commands. */ | |
10872 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
10873 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
10874 | ||
10875 | /* "ip ospf area" commands. */ | |
10876 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
10877 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
10878 | ||
10879 | /* These commands are compatibitliy for previous version. */ | |
10880 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
10881 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
10882 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
10883 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
10884 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
10885 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
10886 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
10887 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
10888 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
10889 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
10890 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
10891 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
10892 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
10893 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
10894 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
10895 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
10896 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
10897 | } | |
10898 | ||
10899 | static void ospf_vty_zebra_init(void) | |
10900 | { | |
10901 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
10902 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
10903 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
10904 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
10905 | ||
10906 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
10907 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
10908 | ||
10909 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
10910 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
10911 | ||
10912 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
10913 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
10914 | ||
10915 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
10916 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
10917 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
10918 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
07b33add | 10919 | |
10920 | /*Ospf garcefull restart helper configurations */ | |
10921 | install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd); | |
10922 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd); | |
10923 | install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd); | |
10924 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd); | |
10925 | install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd); | |
10926 | install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd); | |
10927 | install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd); | |
10928 | install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd); | |
718e3744 | 10929 | #if 0 |
10930 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
10931 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
10932 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
10933 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
10934 | #endif /* 0 */ | |
10935 | } | |
10936 | ||
612c2c15 | 10937 | static int ospf_config_write(struct vty *vty); |
62b346ee | 10938 | static struct cmd_node ospf_node = { |
f4b8291f | 10939 | .name = "ospf", |
62b346ee | 10940 | .node = OSPF_NODE, |
24389580 | 10941 | .parent_node = CONFIG_NODE, |
62b346ee | 10942 | .prompt = "%s(config-router)# ", |
612c2c15 | 10943 | .config_write = ospf_config_write, |
62b346ee | 10944 | }; |
718e3744 | 10945 | |
d62a17ae | 10946 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 10947 | { |
d62a17ae | 10948 | if (!if_is_operative(ifp)) |
10949 | return; | |
09f35f8c | 10950 | |
d62a17ae | 10951 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
10952 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 10953 | |
d62a17ae | 10954 | ospf_if_reset(ifp); |
09f35f8c DS |
10955 | } |
10956 | ||
10957 | DEFUN (clear_ip_ospf_interface, | |
10958 | clear_ip_ospf_interface_cmd, | |
1e81afc3 | 10959 | "clear ip ospf [vrf NAME] interface [IFNAME]", |
09f35f8c DS |
10960 | CLEAR_STR |
10961 | IP_STR | |
10962 | "OSPF information\n" | |
03ed9f02 | 10963 | VRF_CMD_HELP_STR |
09f35f8c DS |
10964 | "Interface information\n" |
10965 | "Interface name\n") | |
10966 | { | |
03ed9f02 PG |
10967 | int idx_ifname = 0; |
10968 | int idx_vrf = 0; | |
d62a17ae | 10969 | struct interface *ifp; |
f4e14fdb | 10970 | struct listnode *node; |
b5a8894d | 10971 | struct ospf *ospf = NULL; |
03ed9f02 PG |
10972 | char *vrf_name = NULL; |
10973 | vrf_id_t vrf_id = VRF_DEFAULT; | |
10974 | struct vrf *vrf = NULL; | |
09f35f8c | 10975 | |
03ed9f02 PG |
10976 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
10977 | vrf_name = argv[idx_vrf + 1]->arg; | |
10978 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
10979 | vrf_name = NULL; | |
10980 | if (vrf_name) { | |
10981 | vrf = vrf_lookup_by_name(vrf_name); | |
10982 | if (vrf) | |
10983 | vrf_id = vrf->vrf_id; | |
10984 | } | |
10985 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
10986 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 10987 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
10988 | if (vrf_id != ospf->vrf_id) |
10989 | continue; | |
10990 | if (!vrf) | |
10991 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 10992 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
10993 | ospf_interface_clear(ifp); |
10994 | } | |
10995 | } else { | |
10996 | /* Interface name is specified. */ | |
a36898e7 | 10997 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 10998 | if (ifp == NULL) |
d62a17ae | 10999 | vty_out(vty, "No such interface name\n"); |
11000 | else | |
11001 | ospf_interface_clear(ifp); | |
11002 | } | |
11003 | ||
11004 | return CMD_SUCCESS; | |
09f35f8c DS |
11005 | } |
11006 | ||
d62a17ae | 11007 | void ospf_vty_clear_init(void) |
09f35f8c | 11008 | { |
d62a17ae | 11009 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
09f35f8c DS |
11010 | } |
11011 | ||
6b0655a2 | 11012 | |
718e3744 | 11013 | /* Install OSPF related vty commands. */ |
d62a17ae | 11014 | void ospf_vty_init(void) |
11015 | { | |
11016 | /* Install ospf top node. */ | |
612c2c15 | 11017 | install_node(&ospf_node); |
d62a17ae | 11018 | |
11019 | /* "router ospf" commands. */ | |
11020 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
11021 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
11022 | ||
11023 | ||
11024 | install_default(OSPF_NODE); | |
11025 | ||
11026 | /* "ospf router-id" commands. */ | |
11027 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
11028 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
11029 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
11030 | ||
11031 | /* "passive-interface" commands. */ | |
11032 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
11033 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
11034 | ||
11035 | /* "ospf abr-type" commands. */ | |
11036 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
11037 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
11038 | ||
11039 | /* "ospf log-adjacency-changes" commands. */ | |
11040 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
11041 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
11042 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
11043 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
11044 | ||
11045 | /* "ospf rfc1583-compatible" commands. */ | |
11046 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
11047 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
11048 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
11049 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
11050 | ||
11051 | /* "network area" commands. */ | |
11052 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
11053 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
11054 | ||
11055 | /* "area authentication" commands. */ | |
11056 | install_element(OSPF_NODE, | |
11057 | &ospf_area_authentication_message_digest_cmd); | |
11058 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
11059 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
11060 | ||
11061 | /* "area range" commands. */ | |
11062 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
11063 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
11064 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
11065 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
11066 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
11067 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
11068 | ||
11069 | /* "area virtual-link" commands. */ | |
11070 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
11071 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
11072 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
11073 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
11074 | ||
11075 | ||
11076 | /* "area stub" commands. */ | |
11077 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
11078 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
11079 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
11080 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
11081 | ||
11082 | /* "area nssa" commands. */ | |
11083 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 11084 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
11085 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 11086 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
d62a17ae | 11087 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
11088 | ||
11089 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
11090 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
11091 | ||
11092 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
11093 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
11094 | ||
11095 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
11096 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
11097 | ||
11098 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
11099 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
11100 | ||
11101 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
11102 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
11103 | ||
11104 | /* SPF timer commands */ | |
11105 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
11106 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
11107 | ||
11108 | /* LSA timers commands */ | |
11109 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
11110 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
11111 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
11112 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 11113 | |
11114 | /* refresh timer commands */ | |
11115 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
11116 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
11117 | ||
11118 | /* max-metric commands */ | |
11119 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
11120 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
11121 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
11122 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
11123 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
11124 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
11125 | ||
11126 | /* reference bandwidth commands */ | |
11127 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
11128 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
11129 | ||
11130 | /* "neighbor" commands. */ | |
11131 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
11132 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
11133 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
11134 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
11135 | ||
11136 | /* write multiplier commands */ | |
11137 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
11138 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
11139 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
11140 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
11141 | ||
a92706bb JU |
11142 | /* "proactive-arp" commands. */ |
11143 | install_element(OSPF_NODE, &ospf_proactive_arp_cmd); | |
11144 | install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd); | |
11145 | ||
d62a17ae | 11146 | /* Init interface related vty commands. */ |
11147 | ospf_vty_if_init(); | |
11148 | ||
11149 | /* Init zebra related vty commands. */ | |
11150 | ospf_vty_zebra_init(); | |
718e3744 | 11151 | } |