]>
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 | |
f328dc60 | 25 | #include "printfrr.h" |
cbf3e3eb | 26 | #include "monotime.h" |
718e3744 | 27 | #include "memory.h" |
28 | #include "thread.h" | |
29 | #include "prefix.h" | |
30 | #include "table.h" | |
31 | #include "vty.h" | |
32 | #include "command.h" | |
33 | #include "plist.h" | |
34 | #include "log.h" | |
35 | #include "zclient.h" | |
bf2bfafd | 36 | #include <lib/json.h> |
8efe88ea | 37 | #include "defaults.h" |
96b663a3 | 38 | #include "lib/printfrr.h" |
718e3744 | 39 | |
40 | #include "ospfd/ospfd.h" | |
41 | #include "ospfd/ospf_asbr.h" | |
42 | #include "ospfd/ospf_lsa.h" | |
43 | #include "ospfd/ospf_lsdb.h" | |
44 | #include "ospfd/ospf_ism.h" | |
45 | #include "ospfd/ospf_interface.h" | |
46 | #include "ospfd/ospf_nsm.h" | |
47 | #include "ospfd/ospf_neighbor.h" | |
48 | #include "ospfd/ospf_flood.h" | |
49 | #include "ospfd/ospf_abr.h" | |
50 | #include "ospfd/ospf_spf.h" | |
51 | #include "ospfd/ospf_route.h" | |
52 | #include "ospfd/ospf_zebra.h" | |
53 | /*#include "ospfd/ospf_routemap.h" */ | |
54 | #include "ospfd/ospf_vty.h" | |
55 | #include "ospfd/ospf_dump.h" | |
7f342629 | 56 | #include "ospfd/ospf_bfd.h" |
132a782e | 57 | #include "ospfd/ospf_ldp_sync.h" |
718e3744 | 58 | |
f328dc60 | 59 | |
c572fbfe | 60 | FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES, |
4c1458b5 DL |
61 | { .val_bool = true, .match_profile = "datacenter", }, |
62 | { .val_bool = false }, | |
c572fbfe DL |
63 | ) |
64 | ||
2b64873d | 65 | static const char *const ospf_network_type_str[] = { |
d62a17ae | 66 | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", |
67 | "VIRTUALLINK", "LOOPBACK"}; | |
718e3744 | 68 | |
718e3744 | 69 | /* Utility functions. */ |
d62a17ae | 70 | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) |
718e3744 | 71 | { |
d62a17ae | 72 | char *ep; |
718e3744 | 73 | |
d62a17ae | 74 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); |
75 | if (*ep && !inet_aton(str, area_id)) | |
76 | return -1; | |
718e3744 | 77 | |
d62a17ae | 78 | *area_id_fmt = |
79 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; | |
718e3744 | 80 | |
d62a17ae | 81 | return 0; |
718e3744 | 82 | } |
83 | ||
1f9d4e3d | 84 | static void area_id2str(char *buf, int length, struct in_addr *area_id, |
85 | int area_id_fmt) | |
86573dcb | 86 | { |
d62a17ae | 87 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
1f9d4e3d | 88 | inet_ntop(AF_INET, area_id, buf, length); |
d62a17ae | 89 | else |
fc746f1c QY |
90 | snprintf(buf, length, "%lu", |
91 | (unsigned long)ntohl(area_id->s_addr)); | |
86573dcb | 92 | } |
6b0655a2 | 93 | |
d62a17ae | 94 | static int str2metric(const char *str, int *metric) |
718e3744 | 95 | { |
d62a17ae | 96 | /* Sanity check. */ |
97 | if (str == NULL) | |
98 | return 0; | |
718e3744 | 99 | |
d62a17ae | 100 | *metric = strtol(str, NULL, 10); |
1fdc969f | 101 | if (*metric < 0 || *metric > 16777214) { |
d62a17ae | 102 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ |
103 | return 0; | |
104 | } | |
718e3744 | 105 | |
d62a17ae | 106 | return 1; |
718e3744 | 107 | } |
108 | ||
d62a17ae | 109 | static int str2metric_type(const char *str, int *metric_type) |
718e3744 | 110 | { |
d62a17ae | 111 | /* Sanity check. */ |
112 | if (str == NULL) | |
113 | return 0; | |
718e3744 | 114 | |
d62a17ae | 115 | if (strncmp(str, "1", 1) == 0) |
116 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
117 | else if (strncmp(str, "2", 1) == 0) | |
118 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
119 | else | |
120 | return 0; | |
718e3744 | 121 | |
d62a17ae | 122 | return 1; |
718e3744 | 123 | } |
124 | ||
d62a17ae | 125 | int ospf_oi_count(struct interface *ifp) |
718e3744 | 126 | { |
d62a17ae | 127 | struct route_node *rn; |
128 | int i = 0; | |
718e3744 | 129 | |
d62a17ae | 130 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
131 | if (rn->info) | |
132 | i++; | |
718e3744 | 133 | |
d62a17ae | 134 | return i; |
718e3744 | 135 | } |
136 | ||
996c9314 LB |
137 | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ |
138 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ | |
139 | vrf_name = argv[idx_vrf + 1]->arg; \ | |
140 | all_vrf = strmatch(vrf_name, "all"); \ | |
43b8d1d8 CS |
141 | } |
142 | ||
143 | static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, | |
144 | struct cmd_token *argv[], | |
996c9314 | 145 | const int argc, uint32_t enable, |
d7c0a89a | 146 | unsigned short *instance) |
718e3744 | 147 | { |
b5a8894d | 148 | struct ospf *ospf = NULL; |
34d6798f | 149 | int idx_vrf = 0, idx_inst = 0; |
b5a8894d | 150 | const char *vrf_name = NULL; |
c572fbfe | 151 | bool created = false; |
b5a8894d | 152 | |
34d6798f CS |
153 | *instance = 0; |
154 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) | |
155 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); | |
156 | ||
b5a8894d | 157 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
b5a8894d | 158 | vrf_name = argv[idx_vrf + 1]->arg; |
6895b354 PG |
159 | if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME)) |
160 | vrf_name = NULL; | |
43b8d1d8 | 161 | if (enable) { |
43b8d1d8 | 162 | /* Allocate VRF aware instance */ |
c572fbfe | 163 | ospf = ospf_get(*instance, vrf_name, &created); |
43b8d1d8 | 164 | } else { |
43b8d1d8 CS |
165 | ospf = ospf_lookup_by_inst_name(*instance, vrf_name); |
166 | } | |
b5a8894d | 167 | } else { |
43b8d1d8 | 168 | if (enable) { |
c572fbfe | 169 | ospf = ospf_get(*instance, NULL, &created); |
43b8d1d8 | 170 | } else { |
43b8d1d8 | 171 | ospf = ospf_lookup_instance(*instance); |
b5a8894d | 172 | } |
d62a17ae | 173 | } |
34d6798f | 174 | |
c572fbfe DL |
175 | if (created) { |
176 | if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
177 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
178 | } | |
179 | ||
43b8d1d8 CS |
180 | return ospf; |
181 | } | |
182 | ||
52d0c099 | 183 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
d7c0a89a | 184 | json_object *json, uint8_t use_vrf) |
52d0c099 | 185 | { |
b1c3ae8c CS |
186 | if (use_vrf) { |
187 | if (json) { | |
188 | if (ospf->vrf_id == VRF_DEFAULT) | |
189 | json_object_string_add(json, "vrfName", | |
190 | "default"); | |
191 | else | |
192 | json_object_string_add(json, "vrfName", | |
193 | ospf->name); | |
194 | json_object_int_add(json, "vrfId", ospf->vrf_id); | |
195 | } else { | |
196 | if (ospf->vrf_id == VRF_DEFAULT) | |
197 | vty_out(vty, "VRF Name: %s\n", "default"); | |
198 | else if (ospf->name) | |
199 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
200 | } | |
52d0c099 | 201 | } |
52d0c099 CS |
202 | } |
203 | ||
43b8d1d8 | 204 | #ifndef VTYSH_EXTRACT_PL |
2e4c2296 | 205 | #include "ospfd/ospf_vty_clippy.c" |
43b8d1d8 CS |
206 | #endif |
207 | ||
208 | DEFUN_NOSH (router_ospf, | |
209 | router_ospf_cmd, | |
210 | "router ospf [{(1-65535)|vrf NAME}]", | |
211 | "Enable a routing process\n" | |
212 | "Start OSPF configuration\n" | |
213 | "Instance ID\n" | |
214 | VRF_CMD_HELP_STR) | |
215 | { | |
216 | struct ospf *ospf = NULL; | |
217 | int ret = CMD_SUCCESS; | |
d7c0a89a | 218 | unsigned short instance = 0; |
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 { | |
d62a17ae | 230 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 LB |
231 | zlog_debug( |
232 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
233 | instance, ospf->name ? ospf->name : "NIL", | |
234 | ospf->vrf_id, ospf->oi_running); | |
d62a17ae | 235 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); |
d62a17ae | 236 | } |
237 | ||
64ac44f6 | 238 | return ret; |
718e3744 | 239 | } |
240 | ||
241 | DEFUN (no_router_ospf, | |
242 | no_router_ospf_cmd, | |
43b8d1d8 | 243 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 244 | NO_STR |
245 | "Enable a routing process\n" | |
7a7be519 | 246 | "Start OSPF configuration\n" |
b5a8894d CS |
247 | "Instance ID\n" |
248 | VRF_CMD_HELP_STR) | |
718e3744 | 249 | { |
d62a17ae | 250 | struct ospf *ospf; |
d7c0a89a | 251 | unsigned short instance = 0; |
b5a8894d | 252 | |
43b8d1d8 CS |
253 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); |
254 | if (ospf == NULL) { | |
255 | if (instance) | |
b5a8894d | 256 | return CMD_NOT_MY_INSTANCE; |
43b8d1d8 CS |
257 | else |
258 | return CMD_WARNING; | |
b5a8894d | 259 | } |
d62a17ae | 260 | ospf_finish(ospf); |
718e3744 | 261 | |
d62a17ae | 262 | return CMD_SUCCESS; |
718e3744 | 263 | } |
264 | ||
7c8ff89e | 265 | |
43b8d1d8 | 266 | DEFPY (ospf_router_id, |
718e3744 | 267 | ospf_router_id_cmd, |
268 | "ospf router-id A.B.C.D", | |
269 | "OSPF specific commands\n" | |
270 | "router-id for the OSPF process\n" | |
271 | "OSPF router-id in IP address format\n") | |
272 | { | |
a3d826f0 | 273 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 274 | |
d62a17ae | 275 | struct listnode *node; |
276 | struct ospf_area *area; | |
d62a17ae | 277 | |
278 | ospf->router_id_static = router_id; | |
279 | ||
280 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
281 | if (area->full_nbrs) { | |
282 | vty_out(vty, | |
3efd0893 | 283 | "For this router-id change to take effect, save config and restart ospfd\n"); |
d62a17ae | 284 | return CMD_SUCCESS; |
285 | } | |
286 | ||
287 | ospf_router_id_update(ospf); | |
288 | ||
289 | return CMD_SUCCESS; | |
718e3744 | 290 | } |
291 | ||
7a7be519 | 292 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
293 | ospf_router_id_old_cmd, |
294 | "router-id A.B.C.D", | |
295 | "router-id for the OSPF process\n" | |
296 | "OSPF router-id in IP address format\n") | |
7a7be519 | 297 | { |
a3d826f0 | 298 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 299 | int idx_ipv4 = 1; |
300 | struct listnode *node; | |
301 | struct ospf_area *area; | |
302 | struct in_addr router_id; | |
303 | int ret; | |
304 | ||
305 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
306 | if (!ret) { | |
307 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
308 | return CMD_WARNING_CONFIG_FAILED; | |
309 | } | |
7a7be519 | 310 | |
d62a17ae | 311 | ospf->router_id_static = router_id; |
312 | ||
313 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
314 | if (area->full_nbrs) { | |
315 | vty_out(vty, | |
3efd0893 | 316 | "For this router-id change to take effect, save config and restart ospfd\n"); |
d62a17ae | 317 | return CMD_SUCCESS; |
318 | } | |
319 | ||
320 | ospf_router_id_update(ospf); | |
321 | ||
322 | return CMD_SUCCESS; | |
7a7be519 | 323 | } |
747e489c | 324 | |
43b8d1d8 | 325 | DEFPY (no_ospf_router_id, |
718e3744 | 326 | no_ospf_router_id_cmd, |
7a7be519 | 327 | "no ospf router-id [A.B.C.D]", |
718e3744 | 328 | NO_STR |
329 | "OSPF specific commands\n" | |
7a7be519 | 330 | "router-id for the OSPF process\n" |
331 | "OSPF router-id in IP address format\n") | |
718e3744 | 332 | { |
a3d826f0 | 333 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 334 | struct listnode *node; |
335 | struct ospf_area *area; | |
68980084 | 336 | |
43b8d1d8 CS |
337 | if (router_id_str) { |
338 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
339 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
340 | return CMD_WARNING_CONFIG_FAILED; | |
341 | } | |
342 | } | |
343 | ||
d62a17ae | 344 | ospf->router_id_static.s_addr = 0; |
718e3744 | 345 | |
d62a17ae | 346 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
347 | if (area->full_nbrs) { | |
348 | vty_out(vty, | |
3efd0893 | 349 | "For this router-id change to take effect, save config and restart ospfd\n"); |
d62a17ae | 350 | return CMD_SUCCESS; |
351 | } | |
2c19a6ec | 352 | |
d62a17ae | 353 | ospf_router_id_update(ospf); |
718e3744 | 354 | |
d62a17ae | 355 | return CMD_SUCCESS; |
718e3744 | 356 | } |
357 | ||
718e3744 | 358 | |
d7c0a89a | 359 | static void ospf_passive_interface_default(struct ospf *ospf, uint8_t newval) |
d62a17ae | 360 | { |
f4e14fdb | 361 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 362 | struct listnode *ln; |
363 | struct interface *ifp; | |
364 | struct ospf_interface *oi; | |
365 | ||
366 | ospf->passive_interface_default = newval; | |
367 | ||
451fda4f | 368 | FOR_ALL_INTERFACES (vrf, ifp) { |
9d303b37 DL |
369 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
370 | passive_interface)) | |
d62a17ae | 371 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); |
372 | } | |
373 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
374 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
375 | UNSET_IF_PARAM(oi->params, passive_interface); | |
376 | /* update multicast memberships */ | |
377 | ospf_if_set_multicast(oi); | |
378 | } | |
379 | } | |
380 | ||
381 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
382 | struct interface *ifp, | |
383 | struct ospf_if_params *params, | |
d7c0a89a | 384 | uint8_t value, |
d62a17ae | 385 | struct in_addr addr) |
386 | { | |
d7c0a89a | 387 | uint8_t dflt; |
d62a17ae | 388 | |
389 | params->passive_interface = value; | |
390 | if (params != IF_DEF_PARAMS(ifp)) { | |
391 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
392 | passive_interface)) | |
393 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
394 | else | |
395 | dflt = ospf->passive_interface_default; | |
396 | ||
397 | if (value != dflt) | |
398 | SET_IF_PARAM(params, passive_interface); | |
399 | else | |
400 | UNSET_IF_PARAM(params, passive_interface); | |
401 | ||
402 | ospf_free_if_params(ifp, addr); | |
403 | ospf_if_update_params(ifp, addr); | |
404 | } | |
405 | } | |
406 | ||
407 | static void ospf_passive_interface_update(struct ospf *ospf, | |
408 | struct interface *ifp, | |
409 | struct ospf_if_params *params, | |
d7c0a89a | 410 | uint8_t value) |
d62a17ae | 411 | { |
412 | params->passive_interface = value; | |
413 | if (params == IF_DEF_PARAMS(ifp)) { | |
414 | if (value != ospf->passive_interface_default) | |
415 | SET_IF_PARAM(params, passive_interface); | |
416 | else | |
417 | UNSET_IF_PARAM(params, passive_interface); | |
418 | } | |
7ffa8fa2 PJ |
419 | } |
420 | ||
a2c62831 | 421 | DEFUN (ospf_passive_interface, |
422 | ospf_passive_interface_addr_cmd, | |
7a7be519 | 423 | "passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 424 | "Suppress routing updates on an interface\n" |
7a7be519 | 425 | "Interface's name\n" |
3a2d747c | 426 | "IPv4 address\n" |
7a7be519 | 427 | "Suppress routing updates on interfaces by default\n") |
718e3744 | 428 | { |
a3d826f0 | 429 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 430 | int idx_ipv4 = 2; |
e99734f1 | 431 | struct interface *ifp = NULL; |
d62a17ae | 432 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
433 | int ret; | |
434 | struct ospf_if_params *params; | |
435 | struct route_node *rn; | |
436 | ||
437 | if (strmatch(argv[1]->text, "default")) { | |
438 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
439 | return CMD_SUCCESS; | |
440 | } | |
e99734f1 | 441 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 442 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
d62a17ae | 443 | |
b5a8894d | 444 | if (ifp == NULL) { |
996c9314 | 445 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 446 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 447 | } |
d62a17ae | 448 | |
449 | params = IF_DEF_PARAMS(ifp); | |
450 | ||
451 | if (argc == 3) { | |
452 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
453 | if (!ret) { | |
454 | vty_out(vty, | |
455 | "Please specify interface address by A.B.C.D\n"); | |
456 | return CMD_WARNING_CONFIG_FAILED; | |
457 | } | |
458 | ||
459 | params = ospf_get_if_params(ifp, addr); | |
460 | ospf_if_update_params(ifp, addr); | |
461 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
462 | OSPF_IF_PASSIVE, addr); | |
463 | } | |
464 | ||
465 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
466 | ||
467 | /* XXX We should call ospf_if_set_multicast on exactly those | |
468 | * interfaces for which the passive property changed. It is too much | |
469 | * work to determine this set, so we do this for every interface. | |
470 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
471 | * record of joined groups to avoid systems calls if the desired | |
472 | * memberships match the current memership. | |
473 | */ | |
474 | ||
475 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
476 | struct ospf_interface *oi = rn->info; | |
477 | ||
9d303b37 DL |
478 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) |
479 | == OSPF_IF_PASSIVE)) | |
d62a17ae | 480 | ospf_if_set_multicast(oi); |
481 | } | |
482 | /* | |
483 | * XXX It is not clear what state transitions the interface needs to | |
484 | * undergo when going from active to passive. Fixing this will | |
485 | * require precise identification of interfaces having such a | |
486 | * transition. | |
487 | */ | |
488 | ||
489 | return CMD_SUCCESS; | |
718e3744 | 490 | } |
491 | ||
a2c62831 | 492 | DEFUN (no_ospf_passive_interface, |
493 | no_ospf_passive_interface_addr_cmd, | |
7a7be519 | 494 | "no passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 495 | NO_STR |
496 | "Allow routing updates on an interface\n" | |
7a7be519 | 497 | "Interface's name\n" |
3a2d747c | 498 | "IPv4 address\n" |
7a7be519 | 499 | "Allow routing updates on interfaces by default\n") |
718e3744 | 500 | { |
a3d826f0 | 501 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 502 | int idx_ipv4 = 3; |
e99734f1 | 503 | struct interface *ifp = NULL; |
d62a17ae | 504 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
505 | struct ospf_if_params *params; | |
506 | int ret; | |
507 | struct route_node *rn; | |
508 | ||
509 | if (strmatch(argv[2]->text, "default")) { | |
510 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
511 | return CMD_SUCCESS; | |
43540886 AS |
512 | } |
513 | ||
e99734f1 | 514 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 515 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
e99734f1 | 516 | |
b5a8894d | 517 | if (ifp == NULL) { |
996c9314 | 518 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 519 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 520 | } |
ba6454ec | 521 | |
d62a17ae | 522 | params = IF_DEF_PARAMS(ifp); |
523 | ||
524 | if (argc == 4) { | |
525 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
526 | if (!ret) { | |
527 | vty_out(vty, | |
528 | "Please specify interface address by A.B.C.D\n"); | |
529 | return CMD_WARNING_CONFIG_FAILED; | |
530 | } | |
531 | ||
532 | params = ospf_lookup_if_params(ifp, addr); | |
533 | if (params == NULL) | |
534 | return CMD_SUCCESS; | |
535 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
536 | OSPF_IF_ACTIVE, addr); | |
537 | } | |
538 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
539 | ||
540 | /* XXX We should call ospf_if_set_multicast on exactly those | |
541 | * interfaces for which the passive property changed. It is too much | |
542 | * work to determine this set, so we do this for every interface. | |
543 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
544 | * record of joined groups to avoid systems calls if the desired | |
545 | * memberships match the current memership. | |
546 | */ | |
547 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
548 | struct ospf_interface *oi = rn->info; | |
549 | ||
550 | if (oi | |
551 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
552 | ospf_if_set_multicast(oi); | |
553 | } | |
554 | ||
555 | return CMD_SUCCESS; | |
718e3744 | 556 | } |
557 | ||
718e3744 | 558 | |
a2c62831 | 559 | DEFUN (ospf_network_area, |
560 | ospf_network_area_cmd, | |
6147e2c6 | 561 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 562 | "Enable routing on an IP network\n" |
563 | "OSPF network prefix\n" | |
564 | "Set the OSPF area ID\n" | |
565 | "OSPF area ID in IP address format\n" | |
566 | "OSPF area ID as a decimal value\n") | |
567 | { | |
a3d826f0 | 568 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 569 | int idx_ipv4_prefixlen = 1; |
570 | int idx_ipv4_number = 3; | |
571 | struct prefix_ipv4 p; | |
572 | struct in_addr area_id; | |
573 | int ret, format; | |
574 | ||
575 | if (ospf->instance) { | |
576 | vty_out(vty, | |
577 | "The network command is not supported in multi-instance ospf\n"); | |
578 | return CMD_WARNING_CONFIG_FAILED; | |
579 | } | |
718e3744 | 580 | |
d62a17ae | 581 | if (ospf->if_ospf_cli_count > 0) { |
582 | vty_out(vty, | |
583 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 584 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 | 585 | zlog_debug( |
d12566a1 | 586 | "%s ospf vrf %s num of %u ip ospf area x config", |
5e81f5dd | 587 | __func__, ospf->name ? ospf->name : "NIL", |
996c9314 | 588 | ospf->if_ospf_cli_count); |
d62a17ae | 589 | return CMD_WARNING_CONFIG_FAILED; |
590 | } | |
591 | ||
592 | /* Get network prefix and Area ID. */ | |
593 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
594 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
595 | ||
596 | ret = ospf_network_set(ospf, &p, area_id, format); | |
597 | if (ret == 0) { | |
598 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 599 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 600 | } |
601 | ||
602 | return CMD_SUCCESS; | |
718e3744 | 603 | } |
604 | ||
a2c62831 | 605 | DEFUN (no_ospf_network_area, |
606 | no_ospf_network_area_cmd, | |
6147e2c6 | 607 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 608 | NO_STR |
609 | "Enable routing on an IP network\n" | |
610 | "OSPF network prefix\n" | |
611 | "Set the OSPF area ID\n" | |
612 | "OSPF area ID in IP address format\n" | |
613 | "OSPF area ID as a decimal value\n") | |
614 | { | |
a3d826f0 | 615 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 616 | int idx_ipv4_prefixlen = 2; |
617 | int idx_ipv4_number = 4; | |
618 | struct prefix_ipv4 p; | |
619 | struct in_addr area_id; | |
620 | int ret, format; | |
621 | ||
622 | if (ospf->instance) { | |
623 | vty_out(vty, | |
624 | "The network command is not supported in multi-instance ospf\n"); | |
625 | return CMD_WARNING_CONFIG_FAILED; | |
626 | } | |
718e3744 | 627 | |
d62a17ae | 628 | /* Get network prefix and Area ID. */ |
629 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
630 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
631 | ||
632 | ret = ospf_network_unset(ospf, &p, area_id); | |
633 | if (ret == 0) { | |
634 | vty_out(vty, | |
635 | "Can't find specified network area configuration.\n"); | |
636 | return CMD_WARNING_CONFIG_FAILED; | |
637 | } | |
638 | ||
639 | return CMD_SUCCESS; | |
718e3744 | 640 | } |
641 | ||
a2c62831 | 642 | DEFUN (ospf_area_range, |
643 | ospf_area_range_cmd, | |
7a7be519 | 644 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 645 | "OSPF area parameters\n" |
646 | "OSPF area ID in IP address format\n" | |
647 | "OSPF area ID as a decimal value\n" | |
648 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 649 | "Area range prefix\n" |
650 | "Advertise this range (default)\n" | |
651 | "User specified metric for this range\n" | |
652 | "Advertised metric for this range\n") | |
718e3744 | 653 | { |
a3d826f0 | 654 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 655 | int idx_ipv4_number = 1; |
656 | int idx_ipv4_prefixlen = 3; | |
657 | int idx_cost = 6; | |
658 | struct prefix_ipv4 p; | |
659 | struct in_addr area_id; | |
660 | int format; | |
d7c0a89a | 661 | uint32_t cost; |
d62a17ae | 662 | |
663 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
664 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
665 | ||
666 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
ed709ed1 GW |
667 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
668 | format); | |
d62a17ae | 669 | if (argc > 5) { |
670 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
671 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
672 | } | |
718e3744 | 673 | |
d62a17ae | 674 | return CMD_SUCCESS; |
718e3744 | 675 | } |
676 | ||
7a7be519 | 677 | DEFUN (ospf_area_range_cost, |
678 | ospf_area_range_cost_cmd, | |
679 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
680 | "OSPF area parameters\n" | |
681 | "OSPF area ID in IP address format\n" | |
682 | "OSPF area ID as a decimal value\n" | |
683 | "Summarize routes matching address/mask (border routers only)\n" | |
684 | "Area range prefix\n" | |
685 | "User specified metric for this range\n" | |
686 | "Advertised metric for this range\n") | |
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 = 5; | |
692 | struct prefix_ipv4 p; | |
693 | struct in_addr area_id; | |
694 | int format; | |
d7c0a89a | 695 | uint32_t cost; |
7a7be519 | 696 | |
d62a17ae | 697 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
698 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 699 | |
d62a17ae | 700 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
701 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
702 | format); | |
718e3744 | 703 | |
d62a17ae | 704 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
705 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 706 | |
d62a17ae | 707 | return CMD_SUCCESS; |
7a7be519 | 708 | } |
718e3744 | 709 | |
a2c62831 | 710 | DEFUN (ospf_area_range_not_advertise, |
711 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 712 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 713 | "OSPF area parameters\n" |
714 | "OSPF area ID in IP address format\n" | |
715 | "OSPF area ID as a decimal value\n" | |
716 | "Summarize routes matching address/mask (border routers only)\n" | |
717 | "Area range prefix\n" | |
718 | "DoNotAdvertise this range\n") | |
719 | { | |
a3d826f0 | 720 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 721 | int idx_ipv4_number = 1; |
722 | int idx_ipv4_prefixlen = 3; | |
723 | struct prefix_ipv4 p; | |
724 | struct in_addr area_id; | |
725 | int format; | |
718e3744 | 726 | |
d62a17ae | 727 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
728 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 729 | |
d62a17ae | 730 | ospf_area_range_set(ospf, area_id, &p, 0); |
731 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
732 | format); | |
990baca0 | 733 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 734 | |
d62a17ae | 735 | return CMD_SUCCESS; |
718e3744 | 736 | } |
737 | ||
a2c62831 | 738 | DEFUN (no_ospf_area_range, |
739 | no_ospf_area_range_cmd, | |
3a2d747c | 740 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 741 | NO_STR |
742 | "OSPF area parameters\n" | |
743 | "OSPF area ID in IP address format\n" | |
744 | "OSPF area ID as a decimal value\n" | |
745 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 746 | "Area range prefix\n" |
3a2d747c QY |
747 | "User specified metric for this range\n" |
748 | "Advertised metric for this range\n" | |
7a7be519 | 749 | "Advertise this range (default)\n" |
3a2d747c QY |
750 | "User specified metric for this range\n" |
751 | "Advertised metric for this range\n" | |
7a7be519 | 752 | "DoNotAdvertise this range\n") |
718e3744 | 753 | { |
a3d826f0 | 754 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 755 | int idx_ipv4_number = 2; |
756 | int idx_ipv4_prefixlen = 4; | |
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_unset(ospf, area_id, &p); |
718e3744 | 765 | |
d62a17ae | 766 | return CMD_SUCCESS; |
718e3744 | 767 | } |
768 | ||
a2c62831 | 769 | DEFUN (ospf_area_range_substitute, |
770 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 771 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 772 | "OSPF area parameters\n" |
773 | "OSPF area ID in IP address format\n" | |
774 | "OSPF area ID as a decimal value\n" | |
775 | "Summarize routes matching address/mask (border routers only)\n" | |
776 | "Area range prefix\n" | |
777 | "Announce area range as another prefix\n" | |
778 | "Network prefix to be announced instead of range\n") | |
779 | { | |
a3d826f0 | 780 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 781 | int idx_ipv4_number = 1; |
782 | int idx_ipv4_prefixlen = 3; | |
783 | int idx_ipv4_prefixlen_2 = 5; | |
784 | struct prefix_ipv4 p, s; | |
785 | struct in_addr area_id; | |
786 | int format; | |
718e3744 | 787 | |
d62a17ae | 788 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
789 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
790 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 791 | |
d62a17ae | 792 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
793 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
794 | format); | |
718e3744 | 795 | |
d62a17ae | 796 | return CMD_SUCCESS; |
718e3744 | 797 | } |
798 | ||
a2c62831 | 799 | DEFUN (no_ospf_area_range_substitute, |
800 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 801 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 802 | NO_STR |
803 | "OSPF area parameters\n" | |
804 | "OSPF area ID in IP address format\n" | |
805 | "OSPF area ID as a decimal value\n" | |
806 | "Summarize routes matching address/mask (border routers only)\n" | |
807 | "Area range prefix\n" | |
808 | "Announce area range as another prefix\n" | |
809 | "Network prefix to be announced instead of range\n") | |
810 | { | |
a3d826f0 | 811 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 812 | int idx_ipv4_number = 2; |
813 | int idx_ipv4_prefixlen = 4; | |
814 | int idx_ipv4_prefixlen_2 = 6; | |
815 | struct prefix_ipv4 p, s; | |
816 | struct in_addr area_id; | |
817 | int format; | |
718e3744 | 818 | |
d62a17ae | 819 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
820 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
821 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 822 | |
d62a17ae | 823 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 824 | |
d62a17ae | 825 | return CMD_SUCCESS; |
718e3744 | 826 | } |
827 | ||
6b0655a2 | 828 | |
718e3744 | 829 | /* Command Handler Logic in VLink stuff is delicate!! |
830 | ||
831 | ALTER AT YOUR OWN RISK!!!! | |
832 | ||
833 | Various dummy values are used to represent 'NoChange' state for | |
834 | VLink configuration NOT being changed by a VLink command, and | |
835 | special syntax is used within the command strings so that the | |
836 | typed in command verbs can be seen in the configuration command | |
837 | bacckend handler. This is to drastically reduce the verbeage | |
838 | required to coe up with a reasonably compatible Cisco VLink command | |
839 | ||
d62a17ae | 840 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 841 | Wed, 21 Feb 2001 15:13:52 +1300 |
842 | */ | |
843 | ||
d62a17ae | 844 | /* Configuration data for virtual links |
845 | */ | |
718e3744 | 846 | struct ospf_vl_config_data { |
d62a17ae | 847 | struct vty *vty; /* vty stuff */ |
848 | struct in_addr area_id; /* area ID from command line */ | |
849 | int area_id_fmt; /* command line area ID format */ | |
850 | struct in_addr vl_peer; /* command line vl_peer */ | |
851 | int auth_type; /* Authehntication type, if given */ | |
852 | char *auth_key; /* simple password if present */ | |
853 | int crypto_key_id; /* Cryptographic key ID */ | |
854 | char *md5_key; /* MD5 authentication key */ | |
855 | int hello_interval; /* Obvious what these are... */ | |
856 | int retransmit_interval; | |
857 | int transmit_delay; | |
858 | int dead_interval; | |
718e3744 | 859 | }; |
860 | ||
d62a17ae | 861 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
862 | struct vty *vty) | |
718e3744 | 863 | { |
d62a17ae | 864 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
865 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
866 | vl_config->vty = vty; | |
718e3744 | 867 | } |
868 | ||
4dadc291 | 869 | static struct ospf_vl_data * |
d62a17ae | 870 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
871 | { | |
872 | struct ospf_area *area; | |
873 | struct ospf_vl_data *vl_data; | |
874 | struct vty *vty; | |
875 | struct in_addr area_id; | |
876 | ||
877 | vty = vl_config->vty; | |
878 | area_id = vl_config->area_id; | |
879 | ||
880 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
881 | vty_out(vty, | |
882 | "Configuring VLs over the backbone is not allowed\n"); | |
883 | return NULL; | |
884 | } | |
885 | area = ospf_area_get(ospf, area_id); | |
886 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
887 | ||
888 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
889 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
96b663a3 | 890 | vty_out(vty, "Area %pI4 is %s\n", &area_id, |
d62a17ae | 891 | area->external_routing == OSPF_AREA_NSSA |
892 | ? "nssa" | |
893 | : "stub"); | |
894 | else | |
895 | vty_out(vty, "Area %ld is %s\n", | |
d7c0a89a | 896 | (unsigned long)ntohl(area_id.s_addr), |
d62a17ae | 897 | area->external_routing == OSPF_AREA_NSSA |
898 | ? "nssa" | |
899 | : "stub"); | |
900 | return NULL; | |
901 | } | |
902 | ||
903 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
904 | == NULL) { | |
905 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
906 | if (vl_data->vl_oi == NULL) { | |
907 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
908 | ospf_vl_add(ospf, vl_data); | |
909 | ospf_spf_calculate_schedule(ospf, | |
910 | SPF_FLAG_CONFIG_CHANGE); | |
911 | } | |
718e3744 | 912 | } |
d62a17ae | 913 | return vl_data; |
718e3744 | 914 | } |
915 | ||
916 | ||
d62a17ae | 917 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
918 | struct ospf_vl_config_data *vl_config) | |
919 | { | |
920 | struct crypt_key *ck; | |
921 | struct vty *vty; | |
922 | struct interface *ifp = vl_data->vl_oi->ifp; | |
923 | ||
924 | vty = vl_config->vty; | |
925 | ||
926 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
927 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
928 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 929 | } |
718e3744 | 930 | |
d62a17ae | 931 | if (vl_config->auth_key) { |
932 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
933 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
4d65d927 QY |
934 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
935 | vl_config->auth_key, | |
936 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
d62a17ae | 937 | } else if (vl_config->md5_key) { |
938 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
939 | vl_config->crypto_key_id) | |
940 | != NULL) { | |
941 | vty_out(vty, "OSPF: Key %d already exists\n", | |
942 | vl_config->crypto_key_id); | |
851fcbae | 943 | return CMD_WARNING; |
d62a17ae | 944 | } |
945 | ck = ospf_crypt_key_new(); | |
946 | ck->key_id = vl_config->crypto_key_id; | |
947 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
4d65d927 QY |
948 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
949 | sizeof(ck->auth_key)); | |
d62a17ae | 950 | |
951 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
952 | } else if (vl_config->crypto_key_id != 0) { | |
953 | /* Delete a key */ | |
954 | ||
955 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
956 | vl_config->crypto_key_id) | |
957 | == NULL) { | |
958 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
959 | vl_config->crypto_key_id); | |
960 | return CMD_WARNING_CONFIG_FAILED; | |
961 | } | |
962 | ||
963 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
964 | vl_config->crypto_key_id); | |
965 | } | |
966 | ||
967 | return CMD_SUCCESS; | |
718e3744 | 968 | } |
969 | ||
d62a17ae | 970 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
971 | struct ospf_vl_config_data *vl_config) | |
972 | { | |
973 | struct interface *ifp = vl_data->vl_oi->ifp; | |
974 | /* Virtual Link data initialised to defaults, so only set | |
975 | if a value given */ | |
976 | if (vl_config->hello_interval) { | |
977 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
978 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
979 | } | |
980 | ||
981 | if (vl_config->dead_interval) { | |
982 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
983 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
984 | } | |
985 | ||
986 | if (vl_config->retransmit_interval) { | |
987 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
988 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
989 | vl_config->retransmit_interval; | |
990 | } | |
991 | ||
992 | if (vl_config->transmit_delay) { | |
993 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
994 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
995 | } | |
996 | ||
997 | return CMD_SUCCESS; | |
718e3744 | 998 | } |
999 | ||
1000 | ||
718e3744 | 1001 | /* The business end of all of the above */ |
d62a17ae | 1002 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
1003 | { | |
1004 | struct ospf_vl_data *vl_data; | |
1005 | int ret; | |
718e3744 | 1006 | |
d62a17ae | 1007 | vl_data = ospf_find_vl_data(ospf, vl_config); |
1008 | if (!vl_data) | |
1009 | return CMD_WARNING_CONFIG_FAILED; | |
1010 | ||
1011 | /* Process this one first as it can have a fatal result, which can | |
1012 | only logically occur if the virtual link exists already | |
1013 | Thus a command error does not result in a change to the | |
1014 | running configuration such as unexpectedly altered timer | |
1015 | values etc.*/ | |
1016 | ret = ospf_vl_set_security(vl_data, vl_config); | |
1017 | if (ret != CMD_SUCCESS) | |
1018 | return ret; | |
1019 | ||
1020 | /* Set any time based parameters, these area already range checked */ | |
1021 | ||
1022 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1023 | if (ret != CMD_SUCCESS) | |
1024 | return ret; | |
718e3744 | 1025 | |
d62a17ae | 1026 | return CMD_SUCCESS; |
718e3744 | 1027 | } |
1028 | ||
1029 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1030 | */ | |
d62a17ae | 1031 | #define VLINK_HELPSTR_IPADDR \ |
1032 | "OSPF area parameters\n" \ | |
1033 | "OSPF area ID in IP address format\n" \ | |
1034 | "OSPF area ID as a decimal value\n" \ | |
1035 | "Configure a virtual link\n" \ | |
1036 | "Router ID of the remote ABR\n" | |
1037 | ||
1038 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1039 | "Enable authentication on this virtual link\n" \ | |
1040 | "dummy string \n" | |
1041 | ||
1042 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1043 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1044 | "Use null authentication\n" \ | |
1045 | "Use message-digest authentication\n" | |
1046 | ||
1047 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1048 | "Time between HELLO packets\n" \ | |
1049 | "Seconds\n" \ | |
1050 | "Time between retransmitting lost link state advertisements\n" \ | |
1051 | "Seconds\n" \ | |
1052 | "Link state transmit delay\n" \ | |
1053 | "Seconds\n" \ | |
1054 | "Interval time after which a neighbor is declared down\n" \ | |
1055 | "Seconds\n" | |
1056 | ||
1057 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1058 | "Authentication password (key)\n" \ | |
baf9eaad | 1059 | "The OSPF password (key)\n" |
d62a17ae | 1060 | |
1061 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1062 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1063 | "Key ID\n" \ |
1064 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1065 | "The OSPF password (key)\n" |
718e3744 | 1066 | |
a2c62831 | 1067 | DEFUN (ospf_area_vlink, |
1068 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1069 | "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 | 1070 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1071 | "Enable authentication on this virtual link\n" |
7a7be519 | 1072 | "Use message-digest authentication\n" |
3d1c6dc2 | 1073 | "Use null authentication\n" |
baf9eaad CS |
1074 | VLINK_HELPSTR_AUTH_MD5 |
1075 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1076 | { |
a3d826f0 | 1077 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1078 | int idx_ipv4_number = 1; |
1079 | int idx_ipv4 = 3; | |
1080 | struct ospf_vl_config_data vl_config; | |
1081 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1082 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1083 | int ret; |
55d1da24 | 1084 | int idx = 0; |
d62a17ae | 1085 | |
1086 | ospf_vl_config_data_init(&vl_config, vty); | |
1087 | ||
1088 | /* Read off first 2 parameters and check them */ | |
1089 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1090 | &vl_config.area_id_fmt); | |
1091 | if (ret < 0) { | |
1092 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1093 | return CMD_WARNING_CONFIG_FAILED; | |
1094 | } | |
718e3744 | 1095 | |
d62a17ae | 1096 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1097 | if (!ret) { | |
1098 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1099 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1100 | } |
7a7be519 | 1101 | |
d62a17ae | 1102 | if (argc <= 4) { |
1103 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1104 | |
d62a17ae | 1105 | return ospf_vl_set(ospf, &vl_config); |
1106 | } | |
1107 | ||
3d1c6dc2 CS |
1108 | if (argv_find(argv, argc, "authentication", &idx)) { |
1109 | /* authentication - this option can only occur | |
1110 | at start of command line */ | |
1111 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1112 | } | |
1113 | ||
3d1c6dc2 | 1114 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1115 | /* authentication message-digest */ |
3d1c6dc2 CS |
1116 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1117 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1118 | /* "authentication null" */ | |
1119 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1120 | } |
7a7be519 | 1121 | |
3d1c6dc2 | 1122 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1123 | vl_config.md5_key = NULL; |
cbb9b53d | 1124 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1125 | if (vl_config.crypto_key_id < 0) |
1126 | return CMD_WARNING_CONFIG_FAILED; | |
1127 | ||
4d65d927 | 1128 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
3d1c6dc2 CS |
1129 | vl_config.md5_key = md5_key; |
1130 | } | |
1131 | ||
3d1c6dc2 | 1132 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
4d65d927 | 1133 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
3d1c6dc2 CS |
1134 | vl_config.auth_key = auth_key; |
1135 | } | |
7a7be519 | 1136 | |
d62a17ae | 1137 | /* Action configuration */ |
1138 | ||
1139 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1140 | } |
1141 | ||
a2c62831 | 1142 | DEFUN (no_ospf_area_vlink, |
1143 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1144 | "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 | 1145 | NO_STR |
7a7be519 | 1146 | VLINK_HELPSTR_IPADDR |
7e5ee522 IR |
1147 | "Enable authentication on this virtual link\n" |
1148 | "Use message-digest authentication\n" | |
1149 | "Use null authentication\n" | |
baf9eaad CS |
1150 | VLINK_HELPSTR_AUTH_MD5 |
1151 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1152 | { |
a3d826f0 | 1153 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1154 | int idx_ipv4_number = 2; |
1155 | int idx_ipv4 = 4; | |
1156 | struct ospf_area *area; | |
1157 | struct ospf_vl_config_data vl_config; | |
1158 | struct ospf_vl_data *vl_data = NULL; | |
1159 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1160 | int idx = 0; |
d62a17ae | 1161 | int ret, format; |
1162 | ||
1163 | ospf_vl_config_data_init(&vl_config, vty); | |
1164 | ||
1165 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1166 | &format); | |
1167 | if (ret < 0) { | |
1168 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1169 | return CMD_WARNING_CONFIG_FAILED; | |
1170 | } | |
1171 | ||
1172 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1173 | if (!area) { | |
1174 | vty_out(vty, "Area does not exist\n"); | |
1175 | return CMD_WARNING_CONFIG_FAILED; | |
1176 | } | |
1177 | ||
1178 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1179 | if (!ret) { | |
1180 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1181 | return CMD_WARNING_CONFIG_FAILED; | |
1182 | } | |
718e3744 | 1183 | |
188823b0 EDP |
1184 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1185 | if (!vl_data) { | |
1186 | vty_out(vty, "Virtual link does not exist\n"); | |
1187 | return CMD_WARNING_CONFIG_FAILED; | |
1188 | } | |
1189 | ||
d62a17ae | 1190 | if (argc <= 5) { |
1191 | /* Basic VLink no command */ | |
1192 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
188823b0 | 1193 | ospf_vl_delete(ospf, vl_data); |
d62a17ae | 1194 | ospf_area_check_free(ospf, vl_config.area_id); |
d62a17ae | 1195 | return CMD_SUCCESS; |
1196 | } | |
1197 | ||
1198 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1199 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1200 | |
1201 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1202 | /* authentication - this option can only occur | |
1203 | at start of command line */ | |
1204 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1205 | } | |
1206 | ||
3d1c6dc2 | 1207 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1208 | vl_config.md5_key = NULL; |
cbb9b53d | 1209 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1210 | if (vl_config.crypto_key_id < 0) |
1211 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1212 | } |
1213 | ||
3d1c6dc2 | 1214 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1215 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1216 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1217 | vl_config.auth_key = auth_key; | |
1218 | } | |
d62a17ae | 1219 | |
1220 | /* Action configuration */ | |
1221 | ||
1222 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1223 | } |
1224 | ||
b1c02cec QY |
1225 | DEFUN (ospf_area_vlink_intervals, |
1226 | ospf_area_vlink_intervals_cmd, | |
1227 | "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)}", | |
1228 | VLINK_HELPSTR_IPADDR | |
1229 | VLINK_HELPSTR_TIME_PARAM) | |
1230 | { | |
a3d826f0 | 1231 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1232 | struct ospf_vl_config_data vl_config; |
1233 | int ret = 0; | |
1234 | ||
1235 | ospf_vl_config_data_init(&vl_config, vty); | |
1236 | ||
1237 | char *area_id = argv[1]->arg; | |
1238 | char *router_id = argv[3]->arg; | |
1239 | ||
1240 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1241 | if (ret < 0) { | |
1242 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1243 | return CMD_WARNING_CONFIG_FAILED; | |
1244 | } | |
1245 | ||
1246 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1247 | if (!ret) { | |
1248 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1249 | return CMD_WARNING_CONFIG_FAILED; | |
1250 | } | |
1251 | ||
1252 | for (int idx = 4; idx < argc; idx++) { | |
1253 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1254 | vl_config.hello_interval = | |
1255 | strtol(argv[++idx]->arg, NULL, 10); | |
1256 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1257 | vl_config.retransmit_interval = | |
1258 | strtol(argv[++idx]->arg, NULL, 10); | |
1259 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1260 | vl_config.transmit_delay = | |
1261 | strtol(argv[++idx]->arg, NULL, 10); | |
1262 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1263 | vl_config.dead_interval = | |
1264 | strtol(argv[++idx]->arg, NULL, 10); | |
1265 | } | |
1266 | ||
1267 | /* Action configuration */ | |
1268 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1269 | } |
1270 | ||
7a7be519 | 1271 | DEFUN (no_ospf_area_vlink_intervals, |
1272 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1273 | "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 | 1274 | NO_STR |
7a7be519 | 1275 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1276 | VLINK_HELPSTR_TIME_PARAM) |
1277 | { | |
a3d826f0 | 1278 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1279 | struct ospf_vl_config_data vl_config; |
1280 | int ret = 0; | |
1281 | ||
1282 | ospf_vl_config_data_init(&vl_config, vty); | |
1283 | ||
1284 | char *area_id = argv[2]->arg; | |
1285 | char *router_id = argv[4]->arg; | |
1286 | ||
1287 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1288 | if (ret < 0) { | |
1289 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1290 | return CMD_WARNING_CONFIG_FAILED; | |
1291 | } | |
1292 | ||
1293 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1294 | if (!ret) { | |
1295 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1296 | return CMD_WARNING_CONFIG_FAILED; | |
1297 | } | |
1298 | ||
1299 | for (int idx = 5; idx < argc; idx++) { | |
1300 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1301 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1302 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1303 | vl_config.retransmit_interval = | |
1304 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1305 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1306 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1307 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1308 | vl_config.dead_interval = | |
1309 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1310 | } | |
1311 | ||
1312 | /* Action configuration */ | |
1313 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1314 | } |
1315 | ||
a2c62831 | 1316 | DEFUN (ospf_area_shortcut, |
1317 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1318 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1319 | "OSPF area parameters\n" |
1320 | "OSPF area ID in IP address format\n" | |
1321 | "OSPF area ID as a decimal value\n" | |
1322 | "Configure the area's shortcutting mode\n" | |
1323 | "Set default shortcutting behavior\n" | |
1324 | "Enable shortcutting through the area\n" | |
1325 | "Disable shortcutting through the area\n") | |
1326 | { | |
a3d826f0 | 1327 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1328 | int idx_ipv4_number = 1; |
1329 | int idx_enable_disable = 3; | |
1330 | struct ospf_area *area; | |
1331 | struct in_addr area_id; | |
1332 | int mode; | |
1333 | int format; | |
1334 | ||
1335 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1336 | argv[idx_ipv4_number]->arg); | |
1337 | ||
1338 | area = ospf_area_get(ospf, area_id); | |
1339 | ospf_area_display_format_set(ospf, area, format); | |
1340 | ||
1341 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1342 | mode = OSPF_SHORTCUT_DEFAULT; | |
1343 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1344 | mode = OSPF_SHORTCUT_DISABLE; | |
1345 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1346 | mode = OSPF_SHORTCUT_ENABLE; | |
1347 | else | |
1348 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1349 | |
d62a17ae | 1350 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1351 | |
d62a17ae | 1352 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1353 | vty_out(vty, | |
3efd0893 | 1354 | "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n"); |
718e3744 | 1355 | |
d62a17ae | 1356 | return CMD_SUCCESS; |
718e3744 | 1357 | } |
1358 | ||
a2c62831 | 1359 | DEFUN (no_ospf_area_shortcut, |
1360 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1361 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1362 | NO_STR |
1363 | "OSPF area parameters\n" | |
1364 | "OSPF area ID in IP address format\n" | |
1365 | "OSPF area ID as a decimal value\n" | |
1366 | "Deconfigure the area's shortcutting mode\n" | |
1367 | "Deconfigure enabled shortcutting through the area\n" | |
1368 | "Deconfigure disabled shortcutting through the area\n") | |
1369 | { | |
a3d826f0 | 1370 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1371 | int idx_ipv4_number = 2; |
1372 | struct ospf_area *area; | |
1373 | struct in_addr area_id; | |
1374 | int format; | |
718e3744 | 1375 | |
d62a17ae | 1376 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1377 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1378 | |
d62a17ae | 1379 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1380 | if (!area) | |
1381 | return CMD_SUCCESS; | |
718e3744 | 1382 | |
d62a17ae | 1383 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1384 | |
d62a17ae | 1385 | return CMD_SUCCESS; |
718e3744 | 1386 | } |
1387 | ||
6b0655a2 | 1388 | |
a2c62831 | 1389 | DEFUN (ospf_area_stub, |
1390 | ospf_area_stub_cmd, | |
6147e2c6 | 1391 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1392 | "OSPF area parameters\n" |
1393 | "OSPF area ID in IP address format\n" | |
1394 | "OSPF area ID as a decimal value\n" | |
1395 | "Configure OSPF area as stub\n") | |
1396 | { | |
a3d826f0 | 1397 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1398 | int idx_ipv4_number = 1; |
1399 | struct in_addr area_id; | |
1400 | int ret, format; | |
1401 | ||
1402 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1403 | argv[idx_ipv4_number]->arg); | |
1404 | ||
1405 | ret = ospf_area_stub_set(ospf, area_id); | |
1406 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1407 | format); | |
1408 | if (ret == 0) { | |
1409 | vty_out(vty, | |
1410 | "First deconfigure all virtual link through this area\n"); | |
1411 | return CMD_WARNING_CONFIG_FAILED; | |
1412 | } | |
718e3744 | 1413 | |
44445dee S |
1414 | /* Flush the external LSAs from the specified area */ |
1415 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1416 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1417 | |
d62a17ae | 1418 | return CMD_SUCCESS; |
718e3744 | 1419 | } |
1420 | ||
a2c62831 | 1421 | DEFUN (ospf_area_stub_no_summary, |
1422 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1423 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1424 | "OSPF stub parameters\n" |
1425 | "OSPF area ID in IP address format\n" | |
1426 | "OSPF area ID as a decimal value\n" | |
1427 | "Configure OSPF area as stub\n" | |
1428 | "Do not inject inter-area routes into stub\n") | |
1429 | { | |
a3d826f0 | 1430 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1431 | int idx_ipv4_number = 1; |
1432 | struct in_addr area_id; | |
1433 | int ret, format; | |
1434 | ||
1435 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1436 | argv[idx_ipv4_number]->arg); | |
1437 | ||
1438 | ret = ospf_area_stub_set(ospf, area_id); | |
1439 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1440 | format); | |
1441 | if (ret == 0) { | |
1442 | vty_out(vty, | |
1443 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1444 | return CMD_WARNING_CONFIG_FAILED; | |
1445 | } | |
718e3744 | 1446 | |
d62a17ae | 1447 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1448 | |
d62a17ae | 1449 | return CMD_SUCCESS; |
718e3744 | 1450 | } |
1451 | ||
a2c62831 | 1452 | DEFUN (no_ospf_area_stub, |
1453 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1454 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1455 | NO_STR |
1456 | "OSPF area 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 | { | |
a3d826f0 | 1461 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1462 | int idx_ipv4_number = 2; |
1463 | struct in_addr area_id; | |
1464 | int format; | |
718e3744 | 1465 | |
d62a17ae | 1466 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1467 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1468 | |
d62a17ae | 1469 | ospf_area_stub_unset(ospf, area_id); |
1470 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1471 | |
d62a17ae | 1472 | return CMD_SUCCESS; |
718e3744 | 1473 | } |
1474 | ||
a2c62831 | 1475 | DEFUN (no_ospf_area_stub_no_summary, |
1476 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1477 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1478 | NO_STR |
1479 | "OSPF area parameters\n" | |
1480 | "OSPF area ID in IP address format\n" | |
1481 | "OSPF area ID as a decimal value\n" | |
1482 | "Configure OSPF area as stub\n" | |
1483 | "Do not inject inter-area routes into area\n") | |
1484 | { | |
a3d826f0 | 1485 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1486 | int idx_ipv4_number = 2; |
1487 | struct in_addr area_id; | |
1488 | int format; | |
718e3744 | 1489 | |
d62a17ae | 1490 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1491 | argv[idx_ipv4_number]->arg); | |
1492 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1493 | |
d62a17ae | 1494 | return CMD_SUCCESS; |
718e3744 | 1495 | } |
1496 | ||
d62a17ae | 1497 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1498 | struct cmd_token **argv, int cfg_nosum, |
1499 | int nosum) | |
718e3744 | 1500 | { |
a3d826f0 | 1501 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1502 | struct in_addr area_id; |
1503 | int ret, format; | |
1504 | ||
1505 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1506 | ||
1507 | ret = ospf_area_nssa_set(ospf, area_id); | |
1508 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1509 | format); | |
1510 | if (ret == 0) { | |
1511 | vty_out(vty, | |
1512 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1513 | return CMD_WARNING_CONFIG_FAILED; | |
1514 | } | |
1515 | ||
1516 | if (argc > 3) { | |
1517 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1518 | ospf_area_nssa_translator_role_set( | |
1519 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1520 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1521 | ospf_area_nssa_translator_role_set( | |
1522 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1523 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1524 | ospf_area_nssa_translator_role_set( | |
1525 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1526 | } else { | |
1527 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1528 | OSPF_NSSA_ROLE_CANDIDATE); | |
1529 | } | |
1530 | ||
7ef56a73 CS |
1531 | if (cfg_nosum) { |
1532 | if (nosum) | |
1533 | ospf_area_no_summary_set(ospf, area_id); | |
1534 | else | |
1535 | ospf_area_no_summary_unset(ospf, area_id); | |
1536 | } | |
d62a17ae | 1537 | |
44445dee S |
1538 | /* Flush the external LSA for the specified area */ |
1539 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1540 | ospf_schedule_abr_task(ospf); |
1541 | ||
1542 | return CMD_SUCCESS; | |
718e3744 | 1543 | } |
1544 | ||
718e3744 | 1545 | |
b0a053be | 1546 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1547 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1548 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1549 | "OSPF area parameters\n" |
1550 | "OSPF area ID in IP address format\n" | |
1551 | "OSPF area ID as a decimal value\n" | |
1552 | "Configure OSPF area as nssa\n" | |
1553 | "Configure NSSA-ABR for translate election (default)\n" | |
1554 | "Configure NSSA-ABR to never translate\n" | |
1555 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1556 | { |
7ef56a73 | 1557 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1558 | } |
1559 | ||
1560 | DEFUN (ospf_area_nssa, | |
1561 | ospf_area_nssa_cmd, | |
6147e2c6 | 1562 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1563 | "OSPF area parameters\n" |
1564 | "OSPF area ID in IP address format\n" | |
1565 | "OSPF area ID as a decimal value\n" | |
1566 | "Configure OSPF area as nssa\n") | |
1567 | { | |
2643b2bc | 1568 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1569 | } |
718e3744 | 1570 | |
a2c62831 | 1571 | DEFUN (ospf_area_nssa_no_summary, |
1572 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1573 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1574 | "OSPF area parameters\n" |
1575 | "OSPF area ID in IP address format\n" | |
1576 | "OSPF area ID as a decimal value\n" | |
1577 | "Configure OSPF area as nssa\n" | |
1578 | "Do not inject inter-area routes into nssa\n") | |
1579 | { | |
7ef56a73 CS |
1580 | int idx_ipv4_number = 1; |
1581 | struct in_addr area_id; | |
1582 | int format; | |
1583 | ||
1584 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1585 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1586 | argv[idx_ipv4_number]->arg); | |
1587 | ||
1588 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1589 | format); | |
1590 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1591 | ||
1592 | ospf_schedule_abr_task(ospf); | |
1593 | ||
1594 | return CMD_SUCCESS; | |
1595 | } | |
1596 | ||
1597 | DEFUN (no_ospf_area_nssa_no_summary, | |
1598 | no_ospf_area_nssa_no_summary_cmd, | |
1599 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1600 | NO_STR | |
1601 | "OSPF area parameters\n" | |
1602 | "OSPF area ID in IP address format\n" | |
1603 | "OSPF area ID as a decimal value\n" | |
1604 | "Configure OSPF area as nssa\n" | |
1605 | "Do not inject inter-area routes into nssa\n") | |
1606 | { | |
1607 | int idx_ipv4_number = 2; | |
1608 | struct in_addr area_id; | |
1609 | int format; | |
1610 | ||
1611 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1612 | ||
1613 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1614 | argv[idx_ipv4_number]->arg); | |
1615 | ||
1616 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1617 | format); | |
1618 | ospf_area_no_summary_unset(ospf, area_id); | |
1619 | ||
1620 | ospf_schedule_abr_task(ospf); | |
1621 | ||
1622 | return CMD_SUCCESS; | |
718e3744 | 1623 | } |
1624 | ||
a2c62831 | 1625 | DEFUN (no_ospf_area_nssa, |
1626 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1627 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1628 | NO_STR |
1629 | "OSPF area parameters\n" | |
1630 | "OSPF area ID in IP address format\n" | |
1631 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1632 | "Configure OSPF area as nssa\n" |
1633 | "Configure NSSA-ABR for translate election (default)\n" | |
1634 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1635 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1636 | { |
a3d826f0 | 1637 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1638 | int idx_ipv4_number = 2; |
1639 | struct in_addr area_id; | |
1640 | int format; | |
718e3744 | 1641 | |
d62a17ae | 1642 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1643 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1644 | |
44445dee S |
1645 | /* Flush the NSSA LSA for the specified area */ |
1646 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA); | |
7ef56a73 | 1647 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1648 | |
d62a17ae | 1649 | ospf_schedule_abr_task(ospf); |
b0a053be | 1650 | |
d62a17ae | 1651 | return CMD_SUCCESS; |
718e3744 | 1652 | } |
1653 | ||
718e3744 | 1654 | |
a2c62831 | 1655 | DEFUN (ospf_area_default_cost, |
1656 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1657 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1658 | "OSPF area parameters\n" |
1659 | "OSPF area ID in IP address format\n" | |
1660 | "OSPF area ID as a decimal value\n" | |
1661 | "Set the summary-default cost of a NSSA or stub area\n" | |
1662 | "Stub's advertised default summary cost\n") | |
1663 | { | |
a3d826f0 | 1664 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1665 | int idx_ipv4_number = 1; |
1666 | int idx_number = 3; | |
1667 | struct ospf_area *area; | |
1668 | struct in_addr area_id; | |
d7c0a89a | 1669 | uint32_t cost; |
d62a17ae | 1670 | int format; |
1671 | struct prefix_ipv4 p; | |
1672 | ||
1673 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1674 | argv[idx_ipv4_number]->arg); | |
1675 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1676 | ||
1677 | area = ospf_area_get(ospf, area_id); | |
1678 | ospf_area_display_format_set(ospf, area, format); | |
1679 | ||
1680 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1681 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1682 | return CMD_WARNING_CONFIG_FAILED; | |
1683 | } | |
ba682537 | 1684 | |
d62a17ae | 1685 | area->default_cost = cost; |
1686 | ||
1687 | p.family = AF_INET; | |
1688 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1689 | p.prefixlen = 0; | |
1690 | if (IS_DEBUG_OSPF_EVENT) | |
1691 | zlog_debug( | |
96b663a3 MS |
1692 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1693 | &area->area_id); | |
d62a17ae | 1694 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
1695 | ||
1696 | return CMD_SUCCESS; | |
718e3744 | 1697 | } |
1698 | ||
a2c62831 | 1699 | DEFUN (no_ospf_area_default_cost, |
1700 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1701 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1702 | NO_STR |
1703 | "OSPF area parameters\n" | |
1704 | "OSPF area ID in IP address format\n" | |
1705 | "OSPF area ID as a decimal value\n" | |
1706 | "Set the summary-default cost of a NSSA or stub area\n" | |
1707 | "Stub's advertised default summary cost\n") | |
1708 | { | |
a3d826f0 | 1709 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1710 | int idx_ipv4_number = 2; |
1711 | struct ospf_area *area; | |
1712 | struct in_addr area_id; | |
1713 | int format; | |
1714 | struct prefix_ipv4 p; | |
718e3744 | 1715 | |
d62a17ae | 1716 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1717 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1718 | |
d62a17ae | 1719 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1720 | if (area == NULL) | |
1721 | return CMD_SUCCESS; | |
718e3744 | 1722 | |
d62a17ae | 1723 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1724 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1725 | return CMD_WARNING_CONFIG_FAILED; | |
1726 | } | |
718e3744 | 1727 | |
d62a17ae | 1728 | area->default_cost = 1; |
718e3744 | 1729 | |
d62a17ae | 1730 | p.family = AF_INET; |
1731 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1732 | p.prefixlen = 0; | |
1733 | if (IS_DEBUG_OSPF_EVENT) | |
1734 | zlog_debug( | |
96b663a3 MS |
1735 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1736 | &area->area_id); | |
d62a17ae | 1737 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
ba682537 | 1738 | |
1739 | ||
d62a17ae | 1740 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1741 | |
d62a17ae | 1742 | return CMD_SUCCESS; |
718e3744 | 1743 | } |
1744 | ||
a2c62831 | 1745 | DEFUN (ospf_area_export_list, |
1746 | ospf_area_export_list_cmd, | |
6147e2c6 | 1747 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1748 | "OSPF area parameters\n" |
1749 | "OSPF area ID in IP address format\n" | |
1750 | "OSPF area ID as a decimal value\n" | |
1751 | "Set the filter for networks announced to other areas\n" | |
1752 | "Name of the access-list\n") | |
1753 | { | |
a3d826f0 | 1754 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1755 | int idx_ipv4_number = 1; |
1756 | struct ospf_area *area; | |
1757 | struct in_addr area_id; | |
1758 | int format; | |
718e3744 | 1759 | |
d62a17ae | 1760 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1761 | |
d62a17ae | 1762 | area = ospf_area_get(ospf, area_id); |
1763 | ospf_area_display_format_set(ospf, area, format); | |
1764 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1765 | |
d62a17ae | 1766 | return CMD_SUCCESS; |
718e3744 | 1767 | } |
1768 | ||
a2c62831 | 1769 | DEFUN (no_ospf_area_export_list, |
1770 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1771 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1772 | NO_STR |
1773 | "OSPF area parameters\n" | |
1774 | "OSPF area ID in IP address format\n" | |
1775 | "OSPF area ID as a decimal value\n" | |
1776 | "Unset the filter for networks announced to other areas\n" | |
1777 | "Name of the access-list\n") | |
1778 | { | |
a3d826f0 | 1779 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1780 | int idx_ipv4_number = 2; |
1781 | struct ospf_area *area; | |
1782 | struct in_addr area_id; | |
1783 | int format; | |
718e3744 | 1784 | |
d62a17ae | 1785 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1786 | |
d62a17ae | 1787 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1788 | if (area == NULL) | |
1789 | return CMD_SUCCESS; | |
718e3744 | 1790 | |
d62a17ae | 1791 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1792 | |
d62a17ae | 1793 | return CMD_SUCCESS; |
718e3744 | 1794 | } |
1795 | ||
1796 | ||
a2c62831 | 1797 | DEFUN (ospf_area_import_list, |
1798 | ospf_area_import_list_cmd, | |
6147e2c6 | 1799 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1800 | "OSPF area parameters\n" |
1801 | "OSPF area ID in IP address format\n" | |
1802 | "OSPF area ID as a decimal value\n" | |
1803 | "Set the filter for networks from other areas announced to the specified one\n" | |
1804 | "Name of the access-list\n") | |
1805 | { | |
a3d826f0 | 1806 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1807 | int idx_ipv4_number = 1; |
1808 | struct ospf_area *area; | |
1809 | struct in_addr area_id; | |
1810 | int format; | |
718e3744 | 1811 | |
d62a17ae | 1812 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1813 | |
d62a17ae | 1814 | area = ospf_area_get(ospf, area_id); |
1815 | ospf_area_display_format_set(ospf, area, format); | |
1816 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1817 | |
d62a17ae | 1818 | return CMD_SUCCESS; |
718e3744 | 1819 | } |
1820 | ||
a2c62831 | 1821 | DEFUN (no_ospf_area_import_list, |
1822 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1823 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1824 | NO_STR |
1825 | "OSPF area parameters\n" | |
1826 | "OSPF area ID in IP address format\n" | |
1827 | "OSPF area ID as a decimal value\n" | |
1828 | "Unset the filter for networks announced to other areas\n" | |
1829 | "Name of the access-list\n") | |
1830 | { | |
a3d826f0 | 1831 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1832 | int idx_ipv4_number = 2; |
1833 | struct ospf_area *area; | |
1834 | struct in_addr area_id; | |
1835 | int format; | |
718e3744 | 1836 | |
d62a17ae | 1837 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1838 | |
d62a17ae | 1839 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1840 | if (area == NULL) | |
1841 | return CMD_SUCCESS; | |
718e3744 | 1842 | |
d62a17ae | 1843 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1844 | |
d62a17ae | 1845 | return CMD_SUCCESS; |
718e3744 | 1846 | } |
1847 | ||
a2c62831 | 1848 | DEFUN (ospf_area_filter_list, |
1849 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1850 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1851 | "OSPF area parameters\n" |
1852 | "OSPF area ID in IP address format\n" | |
1853 | "OSPF area ID as a decimal value\n" | |
1854 | "Filter networks between OSPF areas\n" | |
1855 | "Filter prefixes between OSPF areas\n" | |
1856 | "Name of an IP prefix-list\n" | |
1857 | "Filter networks sent to this area\n" | |
1858 | "Filter networks sent from this area\n") | |
1859 | { | |
a3d826f0 | 1860 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1861 | int idx_ipv4_number = 1; |
1862 | int idx_word = 4; | |
1863 | int idx_in_out = 5; | |
1864 | struct ospf_area *area; | |
1865 | struct in_addr area_id; | |
1866 | struct prefix_list *plist; | |
1867 | int format; | |
1868 | ||
1869 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1870 | ||
1871 | area = ospf_area_get(ospf, area_id); | |
1872 | ospf_area_display_format_set(ospf, area, format); | |
1873 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1874 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1875 | PREFIX_LIST_IN(area) = plist; | |
1876 | if (PREFIX_NAME_IN(area)) | |
1877 | free(PREFIX_NAME_IN(area)); | |
1878 | ||
1879 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1880 | ospf_schedule_abr_task(ospf); | |
1881 | } else { | |
1882 | PREFIX_LIST_OUT(area) = plist; | |
1883 | if (PREFIX_NAME_OUT(area)) | |
1884 | free(PREFIX_NAME_OUT(area)); | |
1885 | ||
1886 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1887 | ospf_schedule_abr_task(ospf); | |
1888 | } | |
718e3744 | 1889 | |
d62a17ae | 1890 | return CMD_SUCCESS; |
718e3744 | 1891 | } |
1892 | ||
a2c62831 | 1893 | DEFUN (no_ospf_area_filter_list, |
1894 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1895 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1896 | NO_STR |
1897 | "OSPF area parameters\n" | |
1898 | "OSPF area ID in IP address format\n" | |
1899 | "OSPF area ID as a decimal value\n" | |
1900 | "Filter networks between OSPF areas\n" | |
1901 | "Filter prefixes between OSPF areas\n" | |
1902 | "Name of an IP prefix-list\n" | |
1903 | "Filter networks sent to this area\n" | |
1904 | "Filter networks sent from this area\n") | |
1905 | { | |
a3d826f0 | 1906 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1907 | int idx_ipv4_number = 2; |
1908 | int idx_word = 5; | |
1909 | int idx_in_out = 6; | |
1910 | struct ospf_area *area; | |
1911 | struct in_addr area_id; | |
1912 | int format; | |
718e3744 | 1913 | |
d62a17ae | 1914 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1915 | |
d62a17ae | 1916 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1917 | return CMD_SUCCESS; | |
718e3744 | 1918 | |
d62a17ae | 1919 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1920 | if (PREFIX_NAME_IN(area)) | |
1921 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1922 | != 0) | |
1923 | return CMD_SUCCESS; | |
718e3744 | 1924 | |
d62a17ae | 1925 | PREFIX_LIST_IN(area) = NULL; |
1926 | if (PREFIX_NAME_IN(area)) | |
1927 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1928 | |
d62a17ae | 1929 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1930 | |
d62a17ae | 1931 | ospf_schedule_abr_task(ospf); |
1932 | } else { | |
1933 | if (PREFIX_NAME_OUT(area)) | |
1934 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1935 | != 0) | |
1936 | return CMD_SUCCESS; | |
718e3744 | 1937 | |
d62a17ae | 1938 | PREFIX_LIST_OUT(area) = NULL; |
1939 | if (PREFIX_NAME_OUT(area)) | |
1940 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1941 | |
d62a17ae | 1942 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1943 | |
d62a17ae | 1944 | ospf_schedule_abr_task(ospf); |
1945 | } | |
1946 | ||
1947 | return CMD_SUCCESS; | |
718e3744 | 1948 | } |
1949 | ||
6b0655a2 | 1950 | |
a2c62831 | 1951 | DEFUN (ospf_area_authentication_message_digest, |
1952 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1953 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1954 | NO_STR | |
718e3744 | 1955 | "OSPF area parameters\n" |
2b00515a CF |
1956 | "OSPF area ID in IP address format\n" |
1957 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1958 | "Enable authentication\n" |
1959 | "Use message-digest authentication\n") | |
1960 | { | |
a3d826f0 | 1961 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 1962 | int idx = 0; |
d62a17ae | 1963 | struct ospf_area *area; |
1964 | struct in_addr area_id; | |
1965 | int format; | |
718e3744 | 1966 | |
ca19319b | 1967 | argv_find(argv, argc, "area", &idx); |
1968 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 1969 | |
d62a17ae | 1970 | area = ospf_area_get(ospf, area_id); |
1971 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
1972 | area->auth_type = strmatch(argv[0]->text, "no") |
1973 | ? OSPF_AUTH_NULL | |
1974 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 1975 | |
d62a17ae | 1976 | return CMD_SUCCESS; |
718e3744 | 1977 | } |
1978 | ||
a2c62831 | 1979 | DEFUN (ospf_area_authentication, |
1980 | ospf_area_authentication_cmd, | |
6147e2c6 | 1981 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 1982 | "OSPF area parameters\n" |
1983 | "OSPF area ID in IP address format\n" | |
1984 | "OSPF area ID as a decimal value\n" | |
1985 | "Enable authentication\n") | |
1986 | { | |
a3d826f0 | 1987 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1988 | int idx_ipv4_number = 1; |
1989 | struct ospf_area *area; | |
1990 | struct in_addr area_id; | |
1991 | int format; | |
718e3744 | 1992 | |
d62a17ae | 1993 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1994 | |
d62a17ae | 1995 | area = ospf_area_get(ospf, area_id); |
1996 | ospf_area_display_format_set(ospf, area, format); | |
1997 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 1998 | |
d62a17ae | 1999 | return CMD_SUCCESS; |
718e3744 | 2000 | } |
2001 | ||
a2c62831 | 2002 | DEFUN (no_ospf_area_authentication, |
2003 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2004 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2005 | NO_STR |
2006 | "OSPF area parameters\n" | |
2007 | "OSPF area ID in IP address format\n" | |
2008 | "OSPF area ID as a decimal value\n" | |
2009 | "Enable authentication\n") | |
2010 | { | |
a3d826f0 | 2011 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2012 | int idx_ipv4_number = 2; |
2013 | struct ospf_area *area; | |
2014 | struct in_addr area_id; | |
2015 | int format; | |
718e3744 | 2016 | |
d62a17ae | 2017 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2018 | |
d62a17ae | 2019 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2020 | if (area == NULL) | |
2021 | return CMD_SUCCESS; | |
718e3744 | 2022 | |
d62a17ae | 2023 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2024 | |
d62a17ae | 2025 | ospf_area_check_free(ospf, area_id); |
2026 | ||
2027 | return CMD_SUCCESS; | |
718e3744 | 2028 | } |
2029 | ||
6b0655a2 | 2030 | |
718e3744 | 2031 | DEFUN (ospf_abr_type, |
2032 | ospf_abr_type_cmd, | |
6147e2c6 | 2033 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2034 | "OSPF specific commands\n" |
2035 | "Set OSPF ABR type\n" | |
2036 | "Alternative ABR, cisco implementation\n" | |
2037 | "Alternative ABR, IBM implementation\n" | |
2038 | "Shortcut ABR\n" | |
2039 | "Standard behavior (RFC2328)\n") | |
2040 | { | |
a3d826f0 | 2041 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2042 | int idx_vendor = 2; |
d7c0a89a | 2043 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2044 | |
2045 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2046 | abr_type = OSPF_ABR_CISCO; | |
2047 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2048 | abr_type = OSPF_ABR_IBM; | |
2049 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2050 | abr_type = OSPF_ABR_SHORTCUT; | |
2051 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2052 | abr_type = OSPF_ABR_STAND; | |
2053 | else | |
2054 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2055 | |
d62a17ae | 2056 | /* If ABR type value is changed, schedule ABR task. */ |
2057 | if (ospf->abr_type != abr_type) { | |
2058 | ospf->abr_type = abr_type; | |
2059 | ospf_schedule_abr_task(ospf); | |
2060 | } | |
2061 | ||
2062 | return CMD_SUCCESS; | |
718e3744 | 2063 | } |
2064 | ||
2065 | DEFUN (no_ospf_abr_type, | |
2066 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2067 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2068 | NO_STR |
2069 | "OSPF specific commands\n" | |
2070 | "Set OSPF ABR type\n" | |
2071 | "Alternative ABR, cisco implementation\n" | |
2072 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2073 | "Shortcut ABR\n" |
2074 | "Standard ABR\n") | |
718e3744 | 2075 | { |
a3d826f0 | 2076 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2077 | int idx_vendor = 3; |
d7c0a89a | 2078 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2079 | |
2080 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2081 | abr_type = OSPF_ABR_CISCO; | |
2082 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2083 | abr_type = OSPF_ABR_IBM; | |
2084 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2085 | abr_type = OSPF_ABR_SHORTCUT; | |
2086 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2087 | abr_type = OSPF_ABR_STAND; | |
2088 | else | |
2089 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2090 | |
d62a17ae | 2091 | /* If ABR type value is changed, schedule ABR task. */ |
2092 | if (ospf->abr_type == abr_type) { | |
2093 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2094 | ospf_schedule_abr_task(ospf); | |
2095 | } | |
2096 | ||
2097 | return CMD_SUCCESS; | |
718e3744 | 2098 | } |
2099 | ||
d7e60dd7 AS |
2100 | DEFUN (ospf_log_adjacency_changes, |
2101 | ospf_log_adjacency_changes_cmd, | |
2102 | "log-adjacency-changes", | |
2103 | "Log changes in adjacency state\n") | |
2104 | { | |
a3d826f0 | 2105 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2106 | |
d62a17ae | 2107 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2108 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2109 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2110 | } |
2111 | ||
2112 | DEFUN (ospf_log_adjacency_changes_detail, | |
2113 | ospf_log_adjacency_changes_detail_cmd, | |
2114 | "log-adjacency-changes detail", | |
2115 | "Log changes in adjacency state\n" | |
2116 | "Log all state changes\n") | |
2117 | { | |
a3d826f0 | 2118 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2119 | |
d62a17ae | 2120 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2121 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2122 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2123 | } |
2124 | ||
2125 | DEFUN (no_ospf_log_adjacency_changes, | |
2126 | no_ospf_log_adjacency_changes_cmd, | |
2127 | "no log-adjacency-changes", | |
2128 | NO_STR | |
2129 | "Log changes in adjacency state\n") | |
2130 | { | |
a3d826f0 | 2131 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2132 | |
d62a17ae | 2133 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2134 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2135 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2136 | } |
2137 | ||
2138 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2139 | no_ospf_log_adjacency_changes_detail_cmd, | |
2140 | "no log-adjacency-changes detail", | |
2141 | NO_STR | |
2142 | "Log changes in adjacency state\n" | |
2143 | "Log all state changes\n") | |
2144 | { | |
a3d826f0 | 2145 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2146 | |
d62a17ae | 2147 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2148 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2149 | } |
2150 | ||
718e3744 | 2151 | DEFUN (ospf_compatible_rfc1583, |
2152 | ospf_compatible_rfc1583_cmd, | |
2153 | "compatible rfc1583", | |
2154 | "OSPF compatibility list\n" | |
2155 | "compatible with RFC 1583\n") | |
2156 | { | |
a3d826f0 | 2157 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2158 | |
d62a17ae | 2159 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2160 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2161 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2162 | } | |
2163 | return CMD_SUCCESS; | |
718e3744 | 2164 | } |
2165 | ||
2166 | DEFUN (no_ospf_compatible_rfc1583, | |
2167 | no_ospf_compatible_rfc1583_cmd, | |
2168 | "no compatible rfc1583", | |
2169 | NO_STR | |
2170 | "OSPF compatibility list\n" | |
2171 | "compatible with RFC 1583\n") | |
2172 | { | |
a3d826f0 | 2173 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2174 | |
d62a17ae | 2175 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2176 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2177 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2178 | } | |
2179 | return CMD_SUCCESS; | |
718e3744 | 2180 | } |
2181 | ||
d62a17ae | 2182 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2183 | "ospf rfc1583compatibility", | |
2184 | "OSPF specific commands\n" | |
2185 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2186 | |
d62a17ae | 2187 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2188 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2189 | "OSPF specific commands\n" |
2190 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2191 | |
d62a17ae | 2192 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2193 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2194 | { |
a3d826f0 | 2195 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2196 | |
d62a17ae | 2197 | ospf->spf_delay = delay; |
2198 | ospf->spf_holdtime = hold; | |
2199 | ospf->spf_max_holdtime = max; | |
2200 | ||
2201 | return CMD_SUCCESS; | |
d24f6e2a | 2202 | } |
718e3744 | 2203 | |
ac7424f9 MR |
2204 | DEFUN (ospf_timers_min_ls_interval, |
2205 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2206 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2207 | "Adjust routing timers\n" |
2208 | "Throttling adaptive timer\n" | |
2209 | "LSA delay between transmissions\n" | |
813d4307 | 2210 | "All LSA types\n" |
ac7424f9 MR |
2211 | "Delay (msec) between sending LSAs\n") |
2212 | { | |
a3d826f0 | 2213 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2214 | int idx_number = 4; |
2215 | unsigned int interval; | |
ac7424f9 | 2216 | |
d62a17ae | 2217 | if (argc < 5) { |
2218 | vty_out(vty, "Insufficient arguments\n"); | |
2219 | return CMD_WARNING_CONFIG_FAILED; | |
2220 | } | |
ac7424f9 | 2221 | |
d62a17ae | 2222 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2223 | |
d62a17ae | 2224 | ospf->min_ls_interval = interval; |
ac7424f9 | 2225 | |
d62a17ae | 2226 | return CMD_SUCCESS; |
ac7424f9 MR |
2227 | } |
2228 | ||
2229 | DEFUN (no_ospf_timers_min_ls_interval, | |
2230 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2231 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2232 | NO_STR |
2233 | "Adjust routing timers\n" | |
2234 | "Throttling adaptive timer\n" | |
813d4307 | 2235 | "LSA delay between transmissions\n" |
7a7be519 | 2236 | "All LSA types\n" |
2237 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2238 | { |
a3d826f0 | 2239 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2240 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2241 | |
d62a17ae | 2242 | return CMD_SUCCESS; |
ac7424f9 MR |
2243 | } |
2244 | ||
d24f6e2a | 2245 | DEFUN (ospf_timers_throttle_spf, |
2246 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2247 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2248 | "Adjust routing timers\n" |
2249 | "Throttling adaptive timer\n" | |
2250 | "OSPF SPF timers\n" | |
2251 | "Delay (msec) from first change received till SPF calculation\n" | |
2252 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2253 | "Maximum hold time (msec)\n") | |
2254 | { | |
d62a17ae | 2255 | int idx_number = 3; |
2256 | int idx_number_2 = 4; | |
2257 | int idx_number_3 = 5; | |
2258 | unsigned int delay, hold, max; | |
2259 | ||
2260 | if (argc < 6) { | |
2261 | vty_out(vty, "Insufficient arguments\n"); | |
2262 | return CMD_WARNING_CONFIG_FAILED; | |
2263 | } | |
2264 | ||
2265 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2266 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2267 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2268 | ||
2269 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2270 | } |
2271 | ||
d24f6e2a | 2272 | DEFUN (no_ospf_timers_throttle_spf, |
2273 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2274 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2275 | NO_STR |
2276 | "Adjust routing timers\n" | |
d24f6e2a | 2277 | "Throttling adaptive timer\n" |
7a7be519 | 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") | |
22b27e95 | 2282 | { |
d62a17ae | 2283 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2284 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2285 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2286 | } |
2287 | ||
b4a039bf | 2288 | |
0e88de35 QY |
2289 | DEFUN (ospf_timers_lsa_min_arrival, |
2290 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2291 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2292 | "Adjust routing timers\n" |
2293 | "OSPF LSA timers\n" | |
2294 | "Minimum delay in receiving new version of a LSA\n" | |
2295 | "Delay in milliseconds\n") | |
2296 | { | |
a3d826f0 | 2297 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2298 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2299 | return CMD_SUCCESS; |
b6927875 DS |
2300 | } |
2301 | ||
0e88de35 QY |
2302 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2303 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2304 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2305 | NO_STR |
2306 | "Adjust routing timers\n" | |
2307 | "OSPF LSA timers\n" | |
7a7be519 | 2308 | "Minimum delay in receiving new version of a LSA\n" |
2309 | "Delay in milliseconds\n") | |
b6927875 | 2310 | { |
a3d826f0 | 2311 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2312 | unsigned int minarrival; |
b6927875 | 2313 | |
d62a17ae | 2314 | if (argc > 4) { |
0e88de35 | 2315 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2316 | |
d62a17ae | 2317 | if (ospf->min_ls_arrival != minarrival |
2318 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2319 | return CMD_SUCCESS; | |
2320 | } | |
b6927875 | 2321 | |
d62a17ae | 2322 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2323 | |
d62a17ae | 2324 | return CMD_SUCCESS; |
b6927875 DS |
2325 | } |
2326 | ||
a2c62831 | 2327 | DEFUN (ospf_neighbor, |
2328 | ospf_neighbor_cmd, | |
7a7be519 | 2329 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2330 | NEIGHBOR_STR |
7a7be519 | 2331 | "Neighbor IP address\n" |
2332 | "Neighbor Priority\n" | |
2333 | "Priority\n" | |
2334 | "Dead Neighbor Polling interval\n" | |
2335 | "Seconds\n") | |
718e3744 | 2336 | { |
a3d826f0 | 2337 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2338 | int idx_ipv4 = 1; |
2339 | int idx_pri = 3; | |
2340 | int idx_poll = 5; | |
2341 | struct in_addr nbr_addr; | |
2342 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2343 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2344 | |
cc9b06ad DS |
2345 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2346 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2347 | return CMD_WARNING_CONFIG_FAILED; | |
2348 | } | |
718e3744 | 2349 | |
d62a17ae | 2350 | if (argc > 2) |
2351 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2352 | |
d62a17ae | 2353 | if (argc > 4) |
2354 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2355 | |
d62a17ae | 2356 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2357 | |
d62a17ae | 2358 | if (argc > 2) |
2359 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2360 | |
d62a17ae | 2361 | if (argc > 4) |
2362 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2363 | |
d62a17ae | 2364 | return CMD_SUCCESS; |
718e3744 | 2365 | } |
2366 | ||
a2c62831 | 2367 | DEFUN (ospf_neighbor_poll_interval, |
2368 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2369 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2370 | NEIGHBOR_STR |
2371 | "Neighbor IP address\n" | |
2372 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2373 | "Seconds\n" |
2374 | "OSPF priority of non-broadcast neighbor\n" | |
2375 | "Priority\n") | |
22b27e95 | 2376 | { |
a3d826f0 | 2377 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2378 | int idx_ipv4 = 1; |
2379 | int idx_poll = 3; | |
2380 | int idx_pri = 5; | |
2381 | struct in_addr nbr_addr; | |
a2b6e694 | 2382 | unsigned int priority; |
2383 | unsigned int interval; | |
718e3744 | 2384 | |
cc9b06ad DS |
2385 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2386 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2387 | return CMD_WARNING_CONFIG_FAILED; | |
2388 | } | |
718e3744 | 2389 | |
d62a17ae | 2390 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2391 | |
a2b6e694 | 2392 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2393 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2394 | |
d62a17ae | 2395 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2396 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2397 | |
d62a17ae | 2398 | if (argc > 4) |
2399 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2400 | |
d62a17ae | 2401 | return CMD_SUCCESS; |
718e3744 | 2402 | } |
2403 | ||
a2c62831 | 2404 | DEFUN (no_ospf_neighbor, |
2405 | no_ospf_neighbor_cmd, | |
7a7be519 | 2406 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2407 | NO_STR |
2408 | NEIGHBOR_STR | |
7a7be519 | 2409 | "Neighbor IP address\n" |
2410 | "Neighbor Priority\n" | |
2411 | "Priority\n" | |
2412 | "Dead Neighbor Polling interval\n" | |
2413 | "Seconds\n") | |
718e3744 | 2414 | { |
a3d826f0 | 2415 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2416 | int idx_ipv4 = 2; |
2417 | struct in_addr nbr_addr; | |
718e3744 | 2418 | |
cc9b06ad DS |
2419 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2420 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2421 | return CMD_WARNING_CONFIG_FAILED; | |
2422 | } | |
718e3744 | 2423 | |
d62a17ae | 2424 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2425 | |
d62a17ae | 2426 | return CMD_SUCCESS; |
718e3744 | 2427 | } |
2428 | ||
7a7be519 | 2429 | DEFUN (no_ospf_neighbor_poll, |
2430 | no_ospf_neighbor_poll_cmd, | |
2431 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2432 | NO_STR | |
2433 | NEIGHBOR_STR | |
2434 | "Neighbor IP address\n" | |
2435 | "Dead Neighbor Polling interval\n" | |
2436 | "Seconds\n" | |
2437 | "Neighbor Priority\n" | |
2438 | "Priority\n") | |
2439 | { | |
a3d826f0 | 2440 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2441 | int idx_ipv4 = 2; |
2442 | struct in_addr nbr_addr; | |
7a7be519 | 2443 | |
cc9b06ad DS |
2444 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2445 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2446 | return CMD_WARNING_CONFIG_FAILED; | |
2447 | } | |
718e3744 | 2448 | |
d62a17ae | 2449 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2450 | |
d62a17ae | 2451 | return CMD_SUCCESS; |
7a7be519 | 2452 | } |
718e3744 | 2453 | |
bf2bfafd DW |
2454 | DEFUN (ospf_refresh_timer, |
2455 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2456 | "refresh timer (10-1800)", |
718e3744 | 2457 | "Adjust refresh parameters\n" |
2458 | "Set refresh timer\n" | |
2459 | "Timer value in seconds\n") | |
2460 | { | |
a3d826f0 | 2461 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2462 | int idx_number = 2; |
2463 | unsigned int interval; | |
7c8ff89e | 2464 | |
d62a17ae | 2465 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2466 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2467 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2468 | |
d62a17ae | 2469 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2470 | |
d62a17ae | 2471 | return CMD_SUCCESS; |
718e3744 | 2472 | } |
2473 | ||
bf2bfafd DW |
2474 | DEFUN (no_ospf_refresh_timer, |
2475 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2476 | "no refresh timer [(10-1800)]", |
3a2d747c | 2477 | NO_STR |
718e3744 | 2478 | "Adjust refresh parameters\n" |
2479 | "Unset refresh timer\n" | |
2480 | "Timer value in seconds\n") | |
2481 | { | |
a3d826f0 | 2482 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2483 | int idx_number = 3; |
2484 | unsigned int interval; | |
718e3744 | 2485 | |
d62a17ae | 2486 | if (argc == 1) { |
2487 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2488 | |
d62a17ae | 2489 | if (ospf->lsa_refresh_interval != interval |
2490 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2491 | return CMD_SUCCESS; | |
2492 | } | |
2493 | ||
2494 | ospf_timers_refresh_unset(ospf); | |
2495 | ||
2496 | return CMD_SUCCESS; | |
718e3744 | 2497 | } |
2498 | ||
718e3744 | 2499 | |
a2c62831 | 2500 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2501 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2502 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2503 | "Calculate OSPF interface cost according to bandwidth\n" |
2504 | "Use reference bandwidth method to assign OSPF cost\n" | |
2505 | "The reference bandwidth in terms of Mbits per second\n") | |
2506 | { | |
a3d826f0 | 2507 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2508 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2509 | int idx_number = 2; |
d7c0a89a | 2510 | uint32_t refbw; |
d62a17ae | 2511 | struct interface *ifp; |
2512 | ||
2513 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2514 | if (refbw < 1 || refbw > 4294967) { | |
2515 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2516 | return CMD_WARNING_CONFIG_FAILED; | |
2517 | } | |
2518 | ||
2519 | /* If reference bandwidth is changed. */ | |
2520 | if ((refbw) == ospf->ref_bandwidth) | |
2521 | return CMD_SUCCESS; | |
2522 | ||
2523 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2524 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2525 | ospf_if_recalculate_output_cost(ifp); |
2526 | ||
2527 | return CMD_SUCCESS; | |
718e3744 | 2528 | } |
2529 | ||
a2c62831 | 2530 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2531 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2532 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2533 | NO_STR |
2534 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2535 | "Use reference bandwidth method to assign OSPF cost\n" |
2536 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2537 | { |
a3d826f0 | 2538 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2539 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2540 | struct interface *ifp; |
718e3744 | 2541 | |
d62a17ae | 2542 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2543 | return CMD_SUCCESS; | |
2544 | ||
2545 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2546 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2547 | vty_out(vty, | |
2548 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2549 | ||
451fda4f | 2550 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2551 | ospf_if_recalculate_output_cost(ifp); |
2552 | ||
2553 | return CMD_SUCCESS; | |
718e3744 | 2554 | } |
2555 | ||
2f8f370e DS |
2556 | DEFUN (ospf_write_multiplier, |
2557 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2558 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2559 | "OSPF specific commands\n" |
2560 | "Write multiplier\n" | |
2561 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2562 | { |
a3d826f0 | 2563 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2564 | int idx_number; |
d7c0a89a | 2565 | uint32_t write_oi_count; |
d62a17ae | 2566 | |
2567 | if (argc == 3) | |
2568 | idx_number = 2; | |
2569 | else | |
2570 | idx_number = 1; | |
2571 | ||
2572 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2573 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2574 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2575 | return CMD_WARNING_CONFIG_FAILED; | |
2576 | } | |
2577 | ||
2578 | ospf->write_oi_count = write_oi_count; | |
2579 | return CMD_SUCCESS; | |
2f8f370e DS |
2580 | } |
2581 | ||
d62a17ae | 2582 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2583 | "Write multiplier\n" | |
2584 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2585 | |
2f8f370e DS |
2586 | DEFUN (no_ospf_write_multiplier, |
2587 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2588 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2589 | NO_STR |
e8f45e82 | 2590 | "OSPF specific commands\n" |
813d4307 DW |
2591 | "Write multiplier\n" |
2592 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2593 | { |
a3d826f0 | 2594 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2595 | |
d62a17ae | 2596 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2597 | return CMD_SUCCESS; | |
2f8f370e DS |
2598 | } |
2599 | ||
d62a17ae | 2600 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2601 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2602 | "Write multiplier\n" |
2603 | "Maximum number of interface serviced per write\n") | |
2604 | ||
2b64873d DL |
2605 | static const char *const ospf_abr_type_descr_str[] = { |
2606 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2607 | "Alternative Cisco", "Alternative Shortcut" | |
2608 | }; | |
d62a17ae | 2609 | |
2b64873d DL |
2610 | static const char *const ospf_shortcut_mode_descr_str[] = { |
2611 | "Default", "Enabled", "Disabled" | |
2612 | }; | |
d62a17ae | 2613 | |
2614 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2615 | json_object *json_areas, bool use_json) |
d62a17ae | 2616 | { |
2617 | json_object *json_area = NULL; | |
96b663a3 | 2618 | char buf[PREFIX_STRLEN]; |
d62a17ae | 2619 | |
2620 | if (use_json) | |
2621 | json_area = json_object_new_object(); | |
2622 | ||
2623 | /* Show Area ID. */ | |
2624 | if (!use_json) | |
96b663a3 | 2625 | vty_out(vty, " Area ID: %pI4", &area->area_id); |
d62a17ae | 2626 | |
2627 | /* Show Area type/mode. */ | |
2628 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2629 | if (use_json) | |
2630 | json_object_boolean_true_add(json_area, "backbone"); | |
2631 | else | |
2632 | vty_out(vty, " (Backbone)\n"); | |
2633 | } else { | |
2634 | if (use_json) { | |
2635 | if (area->external_routing == OSPF_AREA_STUB) { | |
2636 | if (area->no_summary) | |
2637 | json_object_boolean_true_add( | |
2638 | json_area, "stubNoSummary"); | |
2639 | if (area->shortcut_configured) | |
2640 | json_object_boolean_true_add( | |
2641 | json_area, "stubShortcut"); | |
2642 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2643 | if (area->no_summary) | |
2644 | json_object_boolean_true_add( | |
2645 | json_area, "nssaNoSummary"); | |
2646 | if (area->shortcut_configured) | |
2647 | json_object_boolean_true_add( | |
2648 | json_area, "nssaShortcut"); | |
2649 | } | |
813d4307 | 2650 | |
d62a17ae | 2651 | json_object_string_add( |
2652 | json_area, "shortcuttingMode", | |
2653 | ospf_shortcut_mode_descr_str | |
2654 | [area->shortcut_configured]); | |
2655 | if (area->shortcut_capability) | |
2656 | json_object_boolean_true_add(json_area, | |
2657 | "sBitConcensus"); | |
2658 | } else { | |
2659 | if (area->external_routing == OSPF_AREA_STUB) | |
2660 | vty_out(vty, " (Stub%s%s)", | |
2661 | area->no_summary ? ", no summary" : "", | |
2662 | area->shortcut_configured ? "; " : ""); | |
2663 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2664 | vty_out(vty, " (NSSA%s%s)", | |
2665 | area->no_summary ? ", no summary" : "", | |
2666 | area->shortcut_configured ? "; " : ""); | |
2667 | ||
2668 | vty_out(vty, "\n"); | |
2669 | vty_out(vty, " Shortcutting mode: %s", | |
2670 | ospf_shortcut_mode_descr_str | |
2671 | [area->shortcut_configured]); | |
2672 | vty_out(vty, ", S-bit consensus: %s\n", | |
2673 | area->shortcut_capability ? "ok" : "no"); | |
2674 | } | |
2675 | } | |
718e3744 | 2676 | |
d62a17ae | 2677 | /* Show number of interfaces */ |
2678 | if (use_json) { | |
2679 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2680 | listcount(area->oiflist)); | |
2681 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2682 | area->act_ints); | |
2683 | } else | |
2684 | vty_out(vty, | |
3efd0893 | 2685 | " Number of interfaces in this area: Total: %d, Active: %d\n", |
d62a17ae | 2686 | listcount(area->oiflist), area->act_ints); |
2687 | ||
2688 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2689 | if (use_json) { | |
2690 | json_object_boolean_true_add(json_area, "nssa"); | |
2691 | if (!IS_OSPF_ABR(area->ospf)) | |
2692 | json_object_boolean_false_add(json_area, "abr"); | |
2693 | else if (area->NSSATranslatorState) { | |
2694 | json_object_boolean_true_add(json_area, "abr"); | |
2695 | if (area->NSSATranslatorRole | |
2696 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2697 | json_object_boolean_true_add( | |
2698 | json_area, | |
2699 | "nssaTranslatorElected"); | |
2700 | else if (area->NSSATranslatorRole | |
2701 | == OSPF_NSSA_ROLE_ALWAYS) | |
2702 | json_object_boolean_true_add( | |
2703 | json_area, | |
2704 | "nssaTranslatorAlways"); | |
b79c3070 | 2705 | else |
2706 | json_object_boolean_true_add( | |
2707 | json_area, | |
2708 | "nssaTranslatorNever"); | |
d62a17ae | 2709 | } else { |
2710 | json_object_boolean_true_add(json_area, "abr"); | |
2711 | if (area->NSSATranslatorRole | |
2712 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2713 | json_object_boolean_false_add( | |
2714 | json_area, | |
2715 | "nssaTranslatorElected"); | |
2716 | else | |
2717 | json_object_boolean_true_add( | |
2718 | json_area, | |
2719 | "nssaTranslatorNever"); | |
2720 | } | |
2721 | } else { | |
2722 | vty_out(vty, | |
b79c3070 | 2723 | " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n"); |
d62a17ae | 2724 | if (!IS_OSPF_ABR(area->ospf)) |
2725 | vty_out(vty, | |
b79c3070 | 2726 | " It is not ABR, therefore not Translator.\n"); |
d62a17ae | 2727 | else if (area->NSSATranslatorState) { |
2728 | vty_out(vty, " We are an ABR and "); | |
2729 | if (area->NSSATranslatorRole | |
2730 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2731 | vty_out(vty, | |
b79c3070 | 2732 | "the NSSA Elected Translator.\n"); |
d62a17ae | 2733 | else if (area->NSSATranslatorRole |
2734 | == OSPF_NSSA_ROLE_ALWAYS) | |
2735 | vty_out(vty, | |
b79c3070 | 2736 | "always an NSSA Translator.\n"); |
2737 | else | |
2738 | vty_out(vty, | |
2739 | "never an NSSA Translator.\n"); | |
d62a17ae | 2740 | } else { |
2741 | vty_out(vty, " We are an ABR, but "); | |
2742 | if (area->NSSATranslatorRole | |
2743 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2744 | vty_out(vty, | |
b79c3070 | 2745 | "not the NSSA Elected Translator.\n"); |
d62a17ae | 2746 | else |
2747 | vty_out(vty, | |
b79c3070 | 2748 | "never an NSSA Translator.\n"); |
d62a17ae | 2749 | } |
2750 | } | |
2751 | } | |
2752 | ||
2753 | /* Stub-router state for this area */ | |
2754 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2755 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2756 | ||
2757 | if (use_json) { | |
2758 | json_object_boolean_true_add( | |
2759 | json_area, "originStubMaxDistRouterLsa"); | |
2760 | if (CHECK_FLAG(area->stub_router_state, | |
2761 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2762 | json_object_boolean_true_add( | |
2763 | json_area, "indefiniteActiveAdmin"); | |
2764 | if (area->t_stub_router) { | |
2765 | long time_store; | |
2766 | time_store = | |
2767 | monotime_until( | |
2768 | &area->t_stub_router->u.sands, | |
2769 | NULL) | |
2770 | / 1000LL; | |
2771 | json_object_int_add( | |
2772 | json_area, | |
2773 | "activeStartupRemainderMsecs", | |
2774 | time_store); | |
2775 | } | |
2776 | } else { | |
2777 | vty_out(vty, | |
2778 | " Originating stub / maximum-distance Router-LSA\n"); | |
2779 | if (CHECK_FLAG(area->stub_router_state, | |
2780 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2781 | vty_out(vty, | |
2782 | " Administratively activated (indefinitely)\n"); | |
2783 | if (area->t_stub_router) | |
2784 | vty_out(vty, | |
2785 | " Active from startup, %s remaining\n", | |
2786 | ospf_timer_dump(area->t_stub_router, | |
2787 | timebuf, | |
2788 | sizeof(timebuf))); | |
2789 | } | |
2790 | } | |
2791 | ||
2792 | if (use_json) { | |
2793 | /* Show number of fully adjacent neighbors. */ | |
2794 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2795 | area->full_nbrs); | |
2796 | ||
2797 | /* Show authentication type. */ | |
2798 | if (area->auth_type == OSPF_AUTH_NULL) | |
2799 | json_object_string_add(json_area, "authentication", | |
2800 | "authenticationNone"); | |
2801 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2802 | json_object_string_add(json_area, "authentication", | |
2803 | "authenticationSimplePassword"); | |
2804 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2805 | json_object_string_add(json_area, "authentication", | |
2806 | "authenticationMessageDigest"); | |
2807 | ||
2808 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2809 | json_object_int_add(json_area, | |
2810 | "virtualAdjacenciesPassingCounter", | |
2811 | area->full_vls); | |
2812 | ||
2813 | /* Show SPF calculation times. */ | |
2814 | json_object_int_add(json_area, "spfExecutedCounter", | |
2815 | area->spf_calculation); | |
2816 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2817 | json_object_int_add( | |
2818 | json_area, "lsaRouterNumber", | |
2819 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2820 | json_object_int_add( | |
2821 | json_area, "lsaRouterChecksum", | |
2822 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2823 | json_object_int_add( | |
2824 | json_area, "lsaNetworkNumber", | |
2825 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2826 | json_object_int_add( | |
2827 | json_area, "lsaNetworkChecksum", | |
2828 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2829 | json_object_int_add( | |
2830 | json_area, "lsaSummaryNumber", | |
2831 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2832 | json_object_int_add( | |
2833 | json_area, "lsaSummaryChecksum", | |
2834 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2835 | json_object_int_add( | |
2836 | json_area, "lsaAsbrNumber", | |
2837 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2838 | json_object_int_add( | |
2839 | json_area, "lsaAsbrChecksum", | |
2840 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2841 | json_object_int_add( | |
2842 | json_area, "lsaNssaNumber", | |
2843 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2844 | json_object_int_add( | |
2845 | json_area, "lsaNssaChecksum", | |
2846 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2847 | } else { | |
2848 | /* Show number of fully adjacent neighbors. */ | |
2849 | vty_out(vty, | |
3efd0893 | 2850 | " Number of fully adjacent neighbors in this area: %d\n", |
d62a17ae | 2851 | area->full_nbrs); |
2852 | ||
2853 | /* Show authentication type. */ | |
2854 | vty_out(vty, " Area has "); | |
2855 | if (area->auth_type == OSPF_AUTH_NULL) | |
2856 | vty_out(vty, "no authentication\n"); | |
2857 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2858 | vty_out(vty, "simple password authentication\n"); | |
2859 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2860 | vty_out(vty, "message digest authentication\n"); | |
2861 | ||
2862 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2863 | vty_out(vty, | |
3efd0893 | 2864 | " Number of full virtual adjacencies going through this area: %d\n", |
d62a17ae | 2865 | area->full_vls); |
2866 | ||
2867 | /* Show SPF calculation times. */ | |
2868 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2869 | area->spf_calculation); | |
2870 | ||
2871 | /* Show number of LSA. */ | |
2872 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2873 | vty_out(vty, | |
2874 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2875 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2876 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2877 | vty_out(vty, | |
2878 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2879 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2880 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2881 | vty_out(vty, | |
2882 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2883 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2884 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2885 | vty_out(vty, | |
2886 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2887 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
2888 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2889 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
2890 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
2891 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2892 | } | |
2893 | ||
2894 | if (use_json) { | |
2895 | json_object_int_add( | |
2896 | json_area, "lsaOpaqueLinkNumber", | |
2897 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2898 | json_object_int_add( | |
2899 | json_area, "lsaOpaqueLinkChecksum", | |
2900 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2901 | json_object_int_add( | |
2902 | json_area, "lsaOpaqueAreaNumber", | |
2903 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2904 | json_object_int_add( | |
2905 | json_area, "lsaOpaqueAreaChecksum", | |
2906 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2907 | } else { | |
2908 | vty_out(vty, | |
2909 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
2910 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
2911 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2912 | vty_out(vty, | |
2913 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
2914 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
2915 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2916 | } | |
718e3744 | 2917 | |
d62a17ae | 2918 | if (use_json) |
96b663a3 MS |
2919 | json_object_object_add(json_areas, |
2920 | inet_ntop(AF_INET, &area->area_id, | |
2921 | buf, sizeof(buf)), | |
d62a17ae | 2922 | json_area); |
2923 | else | |
2924 | vty_out(vty, "\n"); | |
718e3744 | 2925 | } |
2926 | ||
d62a17ae | 2927 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 2928 | json_object *json, uint8_t use_vrf) |
d62a17ae | 2929 | { |
2930 | struct listnode *node, *nnode; | |
2931 | struct ospf_area *area; | |
2932 | struct timeval result; | |
2933 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 2934 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 2935 | json_object *json_vrf = NULL; |
d62a17ae | 2936 | json_object *json_areas = NULL; |
718e3744 | 2937 | |
b1c3ae8c CS |
2938 | if (json) { |
2939 | if (use_vrf) | |
2940 | json_vrf = json_object_new_object(); | |
2941 | else | |
2942 | json_vrf = json; | |
d62a17ae | 2943 | json_areas = json_object_new_object(); |
2944 | } | |
2945 | ||
2946 | if (ospf->instance) { | |
b1c3ae8c | 2947 | if (json) { |
d62a17ae | 2948 | json_object_int_add(json, "ospfInstance", |
2949 | ospf->instance); | |
2950 | } else { | |
2951 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
2952 | } | |
2953 | } | |
2954 | ||
b1c3ae8c | 2955 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 2956 | |
d62a17ae | 2957 | /* Show Router ID. */ |
b1c3ae8c CS |
2958 | if (json) { |
2959 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
2960 | inet_ntop(AF_INET, &ospf->router_id, |
2961 | buf, sizeof(buf))); | |
d62a17ae | 2962 | } else { |
96b663a3 MS |
2963 | vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n", |
2964 | &ospf->router_id); | |
d62a17ae | 2965 | } |
2966 | ||
2967 | /* Graceful shutdown */ | |
2968 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 2969 | if (json) { |
d62a17ae | 2970 | long time_store; |
2971 | time_store = | |
2972 | monotime_until( | |
2973 | &ospf->t_deferred_shutdown->u.sands, | |
2974 | NULL) | |
2975 | / 1000LL; | |
b1c3ae8c | 2976 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 2977 | time_store); |
2978 | } else { | |
2979 | vty_out(vty, | |
2980 | " Deferred shutdown in progress, %s remaining\n", | |
2981 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
2982 | timebuf, sizeof(timebuf))); | |
2983 | } | |
2984 | } | |
2985 | ||
2986 | /* Show capability. */ | |
b1c3ae8c CS |
2987 | if (json) { |
2988 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
2989 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 2990 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 2991 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 2992 | "rfc1583Compatibility"); |
2993 | } | |
2994 | } else { | |
2995 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
2996 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
2997 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
2998 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
2999 | ? "enabled" | |
3000 | : "disabled"); | |
3001 | } | |
3002 | ||
b1c3ae8c | 3003 | if (json) { |
d62a17ae | 3004 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3005 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3006 | } |
3007 | } else { | |
3008 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3009 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3010 | ? "enabled" | |
3011 | : "disabled"); | |
3012 | } | |
3013 | ||
3014 | /* Show stub-router configuration */ | |
3015 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3016 | || ospf->stub_router_shutdown_time | |
3017 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3018 | if (json) { |
3019 | json_object_boolean_true_add(json_vrf, | |
3020 | "stubAdvertisement"); | |
d62a17ae | 3021 | if (ospf->stub_router_startup_time |
3022 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3023 | json_object_int_add( | |
50ad4b42 MS |
3024 | json_vrf, "postStartEnabledSecs", |
3025 | ospf->stub_router_startup_time); | |
d62a17ae | 3026 | if (ospf->stub_router_shutdown_time |
3027 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3028 | json_object_int_add( | |
50ad4b42 MS |
3029 | json_vrf, "preShutdownEnabledSecs", |
3030 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3031 | } else { |
3032 | vty_out(vty, | |
3033 | " Stub router advertisement is configured\n"); | |
3034 | if (ospf->stub_router_startup_time | |
3035 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3036 | vty_out(vty, | |
3037 | " Enabled for %us after start-up\n", | |
3038 | ospf->stub_router_startup_time); | |
3039 | if (ospf->stub_router_shutdown_time | |
3040 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3041 | vty_out(vty, | |
3042 | " Enabled for %us prior to full shutdown\n", | |
3043 | ospf->stub_router_shutdown_time); | |
3044 | } | |
3045 | } | |
3046 | ||
3047 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3048 | if (json) { |
3049 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3050 | ospf->spf_delay); |
b1c3ae8c | 3051 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3052 | ospf->spf_holdtime); |
b1c3ae8c | 3053 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3054 | ospf->spf_max_holdtime); |
b1c3ae8c | 3055 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3056 | ospf->spf_hold_multiplier); |
3057 | } else { | |
3058 | vty_out(vty, | |
3059 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3060 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3061 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3062 | " Hold time multiplier is currently %d\n", | |
3063 | ospf->spf_delay, ospf->spf_holdtime, | |
3064 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3065 | } | |
3066 | ||
b1c3ae8c | 3067 | if (json) { |
d62a17ae | 3068 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3069 | long time_store = 0; | |
3070 | ||
3071 | time_store = | |
3072 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3073 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3074 | time_store); |
3075 | ||
3076 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3077 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3078 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3079 | time_store); |
3080 | } else | |
b1c3ae8c | 3081 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3082 | } else { |
3083 | vty_out(vty, " SPF algorithm "); | |
3084 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3085 | monotime_since(&ospf->ts_spf, &result); | |
3086 | vty_out(vty, "last executed %s ago\n", | |
3087 | ospf_timeval_dump(&result, timebuf, | |
3088 | sizeof(timebuf))); | |
3089 | vty_out(vty, " Last SPF duration %s\n", | |
3090 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3091 | timebuf, sizeof(timebuf))); | |
3092 | } else | |
3093 | vty_out(vty, "has not been run\n"); | |
3094 | } | |
3095 | ||
b1c3ae8c | 3096 | if (json) { |
d62a17ae | 3097 | if (ospf->t_spf_calc) { |
3098 | long time_store; | |
3099 | time_store = | |
3100 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3101 | / 1000LL; | |
b1c3ae8c | 3102 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3103 | time_store); |
3104 | } | |
3105 | ||
b1c3ae8c | 3106 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3107 | ospf->min_ls_interval); |
b1c3ae8c | 3108 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3109 | ospf->min_ls_arrival); |
3110 | /* Show write multiplier values */ | |
b1c3ae8c | 3111 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3112 | ospf->write_oi_count); |
3113 | /* Show refresh parameters. */ | |
b1c3ae8c | 3114 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3115 | ospf->lsa_refresh_interval * 1000); |
3116 | } else { | |
3117 | vty_out(vty, " SPF timer %s%s\n", | |
3118 | (ospf->t_spf_calc ? "due in " : "is "), | |
3119 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3120 | sizeof(timebuf))); | |
3121 | ||
3122 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3123 | ospf->min_ls_interval); | |
3124 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3125 | ospf->min_ls_arrival); | |
3126 | ||
3127 | /* Show write multiplier values */ | |
3128 | vty_out(vty, " Write Multiplier set to %d \n", | |
3129 | ospf->write_oi_count); | |
3130 | ||
3131 | /* Show refresh parameters. */ | |
3132 | vty_out(vty, " Refresh timer %d secs\n", | |
3133 | ospf->lsa_refresh_interval); | |
3134 | } | |
3135 | ||
3136 | /* Show ABR/ASBR flags. */ | |
3137 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3138 | if (json) |
d62a17ae | 3139 | json_object_string_add( |
b1c3ae8c | 3140 | json_vrf, "abrType", |
d62a17ae | 3141 | ospf_abr_type_descr_str[ospf->abr_type]); |
3142 | else | |
3143 | vty_out(vty, | |
3144 | " This router is an ABR, ABR type is: %s\n", | |
3145 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3146 | } | |
3147 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3148 | if (json) |
d62a17ae | 3149 | json_object_string_add( |
b1c3ae8c | 3150 | json_vrf, "asbrRouter", |
d62a17ae | 3151 | "injectingExternalRoutingInformation"); |
3152 | else | |
3153 | vty_out(vty, | |
3efd0893 | 3154 | " This router is an ASBR (injecting external routing information)\n"); |
d62a17ae | 3155 | } |
3156 | ||
3157 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3158 | if (json) { |
d62a17ae | 3159 | json_object_int_add( |
b1c3ae8c | 3160 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3161 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3162 | json_object_int_add( | |
b1c3ae8c | 3163 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3164 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3165 | } else { | |
3166 | vty_out(vty, | |
3167 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3168 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3169 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3170 | } | |
3171 | ||
b1c3ae8c | 3172 | if (json) { |
d62a17ae | 3173 | json_object_int_add( |
b1c3ae8c | 3174 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3175 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3176 | json_object_int_add( | |
b1c3ae8c | 3177 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3178 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3179 | } else { | |
3180 | vty_out(vty, | |
3181 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3182 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3183 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3184 | } | |
3185 | ||
3186 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3187 | if (json) |
3188 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3189 | listcount(ospf->areas)); |
3190 | else | |
3191 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3192 | listcount(ospf->areas)); | |
3193 | ||
3194 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3195 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3196 | if (json) |
d62a17ae | 3197 | json_object_boolean_true_add( |
b1c3ae8c | 3198 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3199 | else |
3200 | vty_out(vty, | |
3201 | " All adjacency changes are logged\n"); | |
3202 | } else { | |
b1c3ae8c | 3203 | if (json) |
d62a17ae | 3204 | json_object_boolean_true_add( |
b1c3ae8c | 3205 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3206 | else |
3207 | vty_out(vty, " Adjacency changes are logged\n"); | |
3208 | } | |
3209 | } | |
132a782e | 3210 | |
3211 | /* show LDP-Sync status */ | |
3212 | ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0); | |
3213 | ||
d62a17ae | 3214 | /* Show each area status. */ |
3215 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3216 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3217 | ||
3218 | if (json) { | |
3219 | if (use_vrf) { | |
3220 | json_object_object_add(json_vrf, "areas", json_areas); | |
3221 | if (ospf->vrf_id == VRF_DEFAULT) | |
3222 | json_object_object_add(json, "default", | |
3223 | json_vrf); | |
3224 | else | |
3225 | json_object_object_add(json, ospf->name, | |
3226 | json_vrf); | |
3227 | } else { | |
3228 | json_object_object_add(json, "areas", json_areas); | |
3229 | } | |
d62a17ae | 3230 | } else |
3231 | vty_out(vty, "\n"); | |
3232 | ||
3233 | return CMD_SUCCESS; | |
718e3744 | 3234 | } |
3235 | ||
7c8ff89e DS |
3236 | DEFUN (show_ip_ospf, |
3237 | show_ip_ospf_cmd, | |
b5a8894d | 3238 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3239 | SHOW_STR |
3240 | IP_STR | |
ca08c43d | 3241 | "OSPF information\n" |
b5a8894d CS |
3242 | VRF_CMD_HELP_STR |
3243 | "All VRFs\n" | |
9973d184 | 3244 | JSON_STR) |
7c8ff89e | 3245 | { |
d62a17ae | 3246 | struct ospf *ospf; |
9f049418 | 3247 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3248 | struct listnode *node = NULL; |
3249 | char *vrf_name = NULL; | |
2951a7a4 | 3250 | bool all_vrf = false; |
b5a8894d CS |
3251 | int ret = CMD_SUCCESS; |
3252 | int inst = 0; | |
3253 | int idx_vrf = 0; | |
b1c3ae8c | 3254 | json_object *json = NULL; |
d7c0a89a | 3255 | uint8_t use_vrf = 0; |
7c8ff89e | 3256 | |
b5a8894d | 3257 | if (listcount(om->ospf) == 0) |
d62a17ae | 3258 | return CMD_SUCCESS; |
7c8ff89e | 3259 | |
43b8d1d8 | 3260 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3261 | |
b1c3ae8c CS |
3262 | if (uj) |
3263 | json = json_object_new_object(); | |
3264 | ||
996c9314 | 3265 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3266 | if (vrf_name) { |
2951a7a4 | 3267 | bool ospf_output = false; |
874f58d8 | 3268 | |
b1c3ae8c | 3269 | use_vrf = 1; |
94d4c685 | 3270 | |
b5a8894d CS |
3271 | if (all_vrf) { |
3272 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3273 | if (!ospf->oi_running) | |
3274 | continue; | |
2951a7a4 | 3275 | ospf_output = true; |
b1c3ae8c CS |
3276 | ret = show_ip_ospf_common(vty, ospf, json, |
3277 | use_vrf); | |
3278 | } | |
3279 | if (uj) { | |
3280 | vty_out(vty, "%s\n", | |
996c9314 LB |
3281 | json_object_to_json_string_ext( |
3282 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3283 | json_object_free(json); |
9f049418 DS |
3284 | } else if (!ospf_output) |
3285 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
3286 | return ret; |
3287 | } | |
3288 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3289 | if ((ospf == NULL) || !ospf->oi_running) { |
9f049418 DS |
3290 | if (uj) { |
3291 | vty_out(vty, "%s\n", | |
3292 | json_object_to_json_string_ext( | |
3293 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3294 | json_object_free(json); |
9f049418 | 3295 | } else |
94d4c685 | 3296 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3297 | |
b5a8894d | 3298 | return CMD_SUCCESS; |
b1c3ae8c | 3299 | } |
b5a8894d CS |
3300 | } else { |
3301 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3302 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3303 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3304 | if (uj) { |
3305 | vty_out(vty, "%s\n", | |
3306 | json_object_to_json_string_ext( | |
3307 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3308 | json_object_free(json); |
9f049418 | 3309 | } else |
94d4c685 | 3310 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3311 | |
b5a8894d | 3312 | return CMD_SUCCESS; |
b1c3ae8c | 3313 | } |
b5a8894d CS |
3314 | } |
3315 | ||
996c9314 | 3316 | if (ospf) { |
b1c3ae8c CS |
3317 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3318 | if (uj) | |
996c9314 LB |
3319 | vty_out(vty, "%s\n", |
3320 | json_object_to_json_string_ext( | |
3321 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3322 | } |
3323 | ||
3324 | if (uj) | |
3325 | json_object_free(json); | |
b5a8894d CS |
3326 | |
3327 | return ret; | |
7c8ff89e DS |
3328 | } |
3329 | ||
3330 | DEFUN (show_ip_ospf_instance, | |
3331 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3332 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3333 | SHOW_STR |
3334 | IP_STR | |
3335 | "OSPF information\n" | |
ca08c43d | 3336 | "Instance ID\n" |
9973d184 | 3337 | JSON_STR) |
7c8ff89e | 3338 | { |
d62a17ae | 3339 | int idx_number = 3; |
3340 | struct ospf *ospf; | |
d7c0a89a | 3341 | unsigned short instance = 0; |
9f049418 | 3342 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3343 | int ret = CMD_SUCCESS; |
3344 | json_object *json = NULL; | |
d62a17ae | 3345 | |
3346 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3347 | ospf = ospf_lookup_instance(instance); |
3348 | if (ospf == NULL) | |
3349 | return CMD_NOT_MY_INSTANCE; | |
3350 | ||
3351 | if (!ospf->oi_running) | |
d62a17ae | 3352 | return CMD_SUCCESS; |
3353 | ||
b1c3ae8c CS |
3354 | if (uj) |
3355 | json = json_object_new_object(); | |
3356 | ||
3357 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3358 | ||
3359 | if (uj) { | |
996c9314 LB |
3360 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3361 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3362 | json_object_free(json); |
3363 | } | |
3364 | ||
3365 | return ret; | |
d62a17ae | 3366 | } |
3367 | ||
3368 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, | |
3369 | struct interface *ifp, | |
3370 | json_object *json_interface_sub, | |
9f049418 | 3371 | bool use_json) |
d62a17ae | 3372 | { |
3373 | int is_up; | |
3374 | struct ospf_neighbor *nbr; | |
3375 | struct route_node *rn; | |
96b663a3 | 3376 | char buf[PREFIX_STRLEN]; |
d62a17ae | 3377 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; |
3378 | ||
3379 | /* Is interface up? */ | |
3380 | if (use_json) { | |
3381 | is_up = if_is_operative(ifp); | |
3382 | if (is_up) | |
3383 | json_object_boolean_true_add(json_interface_sub, | |
3384 | "ifUp"); | |
3385 | else | |
3386 | json_object_boolean_false_add(json_interface_sub, | |
3387 | "ifDown"); | |
3388 | ||
3389 | json_object_int_add(json_interface_sub, "ifIndex", | |
3390 | ifp->ifindex); | |
3391 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3392 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3393 | bandwidth); | |
3394 | json_object_string_add(json_interface_sub, "ifFlags", | |
3395 | if_flag_dump(ifp->flags)); | |
3396 | } else { | |
3397 | vty_out(vty, "%s is %s\n", ifp->name, | |
3398 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3399 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3400 | ifp->ifindex, ifp->mtu, bandwidth, | |
3401 | if_flag_dump(ifp->flags)); | |
3402 | } | |
7c8ff89e | 3403 | |
d62a17ae | 3404 | /* Is interface OSPF enabled? */ |
3405 | if (use_json) { | |
3406 | if (ospf_oi_count(ifp) == 0) { | |
3407 | json_object_boolean_false_add(json_interface_sub, | |
3408 | "ospfEnabled"); | |
3409 | return; | |
3410 | } else if (!is_up) { | |
3411 | json_object_boolean_false_add(json_interface_sub, | |
3412 | "ospfRunning"); | |
3413 | return; | |
3414 | } else | |
3415 | json_object_boolean_true_add(json_interface_sub, | |
3416 | "ospfEnabled"); | |
3417 | } else { | |
3418 | if (ospf_oi_count(ifp) == 0) { | |
3419 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3420 | return; | |
3421 | } else if (!is_up) { | |
3422 | vty_out(vty, | |
3423 | " OSPF is enabled, but not running on this interface\n"); | |
3424 | return; | |
3425 | } | |
3426 | } | |
3427 | ||
3428 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3429 | struct ospf_interface *oi = rn->info; | |
3430 | ||
3431 | if (oi == NULL) | |
3432 | continue; | |
3433 | ||
3434 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3435 | if (use_json) | |
3436 | json_object_boolean_true_add(json_interface_sub, | |
3437 | "ifUnnumbered"); | |
3438 | else | |
3439 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3440 | } else { | |
0f3af738 JW |
3441 | struct in_addr dest; |
3442 | const char *dstr; | |
3443 | ||
d62a17ae | 3444 | /* Show OSPF interface information. */ |
3445 | if (use_json) { | |
3446 | json_object_string_add( | |
3447 | json_interface_sub, "ipAddress", | |
96b663a3 MS |
3448 | inet_ntop(AF_INET, |
3449 | &oi->address->u.prefix4, | |
3450 | buf, sizeof(buf))); | |
d62a17ae | 3451 | json_object_int_add(json_interface_sub, |
3452 | "ipAddressPrefixlen", | |
3453 | oi->address->prefixlen); | |
3454 | } else | |
ae32e1c2 DS |
3455 | vty_out(vty, " Internet Address %pFX,", |
3456 | oi->address); | |
d62a17ae | 3457 | |
0f3af738 JW |
3458 | /* For Vlinks, showing the peer address is |
3459 | * probably more informative than the local | |
3460 | * interface that is being used */ | |
3461 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3462 | dstr = "Peer"; | |
3463 | dest = oi->vl_data->peer_addr; | |
3464 | } else if (CONNECTED_PEER(oi->connected) | |
3465 | && oi->connected->destination) { | |
3466 | dstr = "Peer"; | |
3467 | dest = oi->connected->destination->u.prefix4; | |
3468 | } else { | |
3469 | dstr = "Broadcast"; | |
3470 | dest.s_addr = ipv4_broadcast_addr( | |
3471 | oi->connected->address->u.prefix4.s_addr, | |
3472 | oi->connected->address->prefixlen); | |
3473 | } | |
d62a17ae | 3474 | |
0f3af738 JW |
3475 | if (use_json) { |
3476 | json_object_string_add( | |
3477 | json_interface_sub, | |
3478 | "ospfIfType", dstr); | |
d62a17ae | 3479 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
0f3af738 JW |
3480 | json_object_string_add( |
3481 | json_interface_sub, | |
3482 | "vlinkPeer", | |
96b663a3 MS |
3483 | inet_ntop(AF_INET, &dest, |
3484 | buf, sizeof(buf))); | |
d62a17ae | 3485 | else |
d62a17ae | 3486 | json_object_string_add( |
3487 | json_interface_sub, | |
0f3af738 | 3488 | "localIfUsed", |
96b663a3 MS |
3489 | inet_ntop(AF_INET, &dest, |
3490 | buf, sizeof(buf))); | |
0f3af738 | 3491 | } else |
96b663a3 MS |
3492 | vty_out(vty, " %s %pI4,", dstr, |
3493 | &dest); | |
d62a17ae | 3494 | } |
3495 | if (use_json) { | |
3496 | json_object_string_add(json_interface_sub, "area", | |
3497 | ospf_area_desc_string(oi->area)); | |
3498 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3499 | json_object_boolean_true_add( | |
3500 | json_interface_sub, | |
3501 | "mtuMismatchDetect"); | |
96b663a3 MS |
3502 | json_object_string_add( |
3503 | json_interface_sub, "routerId", | |
3504 | inet_ntop(AF_INET, &ospf->router_id, | |
3505 | buf, sizeof(buf))); | |
d62a17ae | 3506 | json_object_string_add(json_interface_sub, |
3507 | "networkType", | |
3508 | ospf_network_type_str[oi->type]); | |
3509 | json_object_int_add(json_interface_sub, "cost", | |
3510 | oi->output_cost); | |
3511 | json_object_int_add( | |
50ad4b42 MS |
3512 | json_interface_sub, "transmitDelaySecs", |
3513 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3514 | json_object_string_add(json_interface_sub, "state", |
3515 | lookup_msg(ospf_ism_state_msg, | |
3516 | oi->state, NULL)); | |
3517 | json_object_int_add(json_interface_sub, "priority", | |
3518 | PRIORITY(oi)); | |
3519 | } else { | |
3520 | vty_out(vty, " Area %s\n", | |
3521 | ospf_area_desc_string(oi->area)); | |
3522 | ||
3523 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3524 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3525 | : "enabled"); | |
3526 | ||
3527 | vty_out(vty, | |
96b663a3 MS |
3528 | " Router ID %pI4, Network Type %s, Cost: %d\n", |
3529 | &ospf->router_id, | |
d62a17ae | 3530 | ospf_network_type_str[oi->type], |
3531 | oi->output_cost); | |
3532 | ||
3533 | vty_out(vty, | |
3534 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3535 | OSPF_IF_PARAM(oi, transmit_delay), | |
3536 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3537 | PRIORITY(oi)); | |
3538 | } | |
3539 | ||
3540 | /* Show DR information. */ | |
975a328e | 3541 | if (DR(oi).s_addr == INADDR_ANY) { |
d62a17ae | 3542 | if (!use_json) |
3543 | vty_out(vty, | |
3544 | " No backup designated router on this network\n"); | |
3545 | } else { | |
3546 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3547 | if (nbr == NULL) { | |
3548 | if (!use_json) | |
3549 | vty_out(vty, | |
3550 | " No backup designated router on this network\n"); | |
3551 | } else { | |
3552 | if (use_json) { | |
3553 | json_object_string_add( | |
3554 | json_interface_sub, "bdrId", | |
96b663a3 MS |
3555 | inet_ntop(AF_INET, |
3556 | &nbr->router_id, | |
3557 | buf, sizeof(buf))); | |
d62a17ae | 3558 | json_object_string_add( |
3559 | json_interface_sub, | |
3560 | "bdrAddress", | |
96b663a3 MS |
3561 | inet_ntop(AF_INET, |
3562 | &nbr->address.u | |
3563 | .prefix4, | |
3564 | buf, sizeof(buf))); | |
d62a17ae | 3565 | } else { |
3566 | vty_out(vty, | |
96b663a3 MS |
3567 | " Backup Designated Router (ID) %pI4,", |
3568 | &nbr->router_id); | |
3569 | vty_out(vty, " Interface Address %pI4\n", | |
3570 | &nbr->address.u.prefix4); | |
d62a17ae | 3571 | } |
3572 | } | |
3573 | } | |
3574 | ||
3575 | /* Next network-LSA sequence number we'll use, if we're elected | |
3576 | * DR */ | |
3577 | if (oi->params | |
3578 | && ntohl(oi->params->network_lsa_seqnum) | |
3579 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3580 | if (use_json) | |
3581 | json_object_int_add( | |
3582 | json_interface_sub, | |
3583 | "networkLsaSequence", | |
3584 | ntohl(oi->params->network_lsa_seqnum)); | |
3585 | else | |
3586 | vty_out(vty, | |
3587 | " Saved Network-LSA sequence number 0x%x\n", | |
3588 | ntohl(oi->params->network_lsa_seqnum)); | |
3589 | } | |
3590 | ||
3591 | if (use_json) { | |
3592 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3593 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3594 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3595 | json_object_boolean_true_add( | |
3596 | json_interface_sub, | |
3597 | "mcastMemberOspfAllRouters"); | |
3598 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3599 | json_object_boolean_true_add( | |
3600 | json_interface_sub, | |
3601 | "mcastMemberOspfDesignatedRouters"); | |
3602 | } | |
3603 | } else { | |
3604 | vty_out(vty, " Multicast group memberships:"); | |
3605 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3606 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3607 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3608 | vty_out(vty, " OSPFAllRouters"); | |
3609 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3610 | vty_out(vty, " OSPFDesignatedRouters"); | |
3611 | } else | |
3612 | vty_out(vty, " <None>"); | |
3613 | vty_out(vty, "\n"); | |
3614 | } | |
3615 | ||
3616 | if (use_json) { | |
3617 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3618 | json_object_int_add( | |
3619 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3620 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3621 | else |
3622 | json_object_int_add( | |
3623 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3624 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3625 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3626 | "timerDeadSecs", |
3627 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3628 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3629 | "timerWaitSecs", |
3630 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3631 | json_object_int_add( |
50ad4b42 MS |
3632 | json_interface_sub, "timerRetransmitSecs", |
3633 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3634 | } else { |
3635 | vty_out(vty, " Timer intervals configured,"); | |
3636 | vty_out(vty, " Hello "); | |
3637 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3638 | vty_out(vty, "%ds,", | |
3639 | OSPF_IF_PARAM(oi, v_hello)); | |
3640 | else | |
3641 | vty_out(vty, "%dms,", | |
3642 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3643 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3644 | OSPF_IF_PARAM(oi, v_wait), | |
3645 | OSPF_IF_PARAM(oi, v_wait), | |
3646 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3647 | } | |
3648 | ||
3649 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3650 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3651 | if (use_json) { | |
3652 | long time_store = 0; | |
3653 | if (oi->t_hello) | |
3654 | time_store = | |
3655 | monotime_until( | |
3656 | &oi->t_hello->u.sands, | |
3657 | NULL) | |
3658 | / 1000LL; | |
3659 | json_object_int_add(json_interface_sub, | |
3660 | "timerHelloInMsecs", | |
3661 | time_store); | |
3662 | } else | |
3663 | vty_out(vty, " Hello due in %s\n", | |
3664 | ospf_timer_dump(oi->t_hello, timebuf, | |
3665 | sizeof(timebuf))); | |
3666 | } else /* passive-interface is set */ | |
3667 | { | |
3668 | if (use_json) | |
3669 | json_object_boolean_true_add( | |
3670 | json_interface_sub, | |
3671 | "timerPassiveIface"); | |
3672 | else | |
3673 | vty_out(vty, | |
3674 | " No Hellos (Passive interface)\n"); | |
3675 | } | |
7c8ff89e | 3676 | |
d62a17ae | 3677 | if (use_json) { |
3678 | json_object_int_add(json_interface_sub, "nbrCount", | |
3679 | ospf_nbr_count(oi, 0)); | |
3680 | json_object_int_add(json_interface_sub, | |
3681 | "nbrAdjacentCount", | |
3682 | ospf_nbr_count(oi, NSM_Full)); | |
3683 | } else | |
3684 | vty_out(vty, | |
3685 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3686 | ospf_nbr_count(oi, 0), | |
3687 | ospf_nbr_count(oi, NSM_Full)); | |
3688 | ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json); | |
3689 | } | |
718e3744 | 3690 | } |
3691 | ||
d62a17ae | 3692 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3693 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3694 | json_object *json, bool use_json) |
d62a17ae | 3695 | { |
3696 | struct interface *ifp; | |
f4e14fdb | 3697 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3698 | json_object *json_vrf = NULL; |
7dab10ce | 3699 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3700 | |
d62a17ae | 3701 | if (use_json) { |
b1c3ae8c CS |
3702 | if (use_vrf) |
3703 | json_vrf = json_object_new_object(); | |
3704 | else | |
3705 | json_vrf = json; | |
6282e124 | 3706 | json_interface = json_object_new_object(); |
d62a17ae | 3707 | } |
3708 | ||
3709 | if (ospf->instance) { | |
3710 | if (use_json) | |
3711 | json_object_int_add(json, "ospfInstance", | |
3712 | ospf->instance); | |
3713 | else | |
3714 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3715 | } | |
3716 | ||
b1c3ae8c CS |
3717 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3718 | ||
3719 | if (intf_name == NULL) { | |
d62a17ae | 3720 | /* Show All Interfaces.*/ |
451fda4f | 3721 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3722 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3723 | if (use_json) { |
d62a17ae | 3724 | json_interface_sub = |
3725 | json_object_new_object(); | |
7dab10ce | 3726 | } |
d62a17ae | 3727 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3728 | json_interface_sub, | |
3729 | use_json); | |
3730 | ||
7dab10ce | 3731 | if (use_json) { |
d62a17ae | 3732 | json_object_object_add( |
7dab10ce | 3733 | json_interface, ifp->name, |
d62a17ae | 3734 | json_interface_sub); |
7dab10ce | 3735 | } |
d62a17ae | 3736 | } |
3737 | } | |
6282e124 CS |
3738 | if (use_json) |
3739 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3740 | json_interface); |
d62a17ae | 3741 | } else { |
3742 | /* Interface name is specified. */ | |
a36898e7 | 3743 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3744 | if (ifp == NULL) { |
d62a17ae | 3745 | if (use_json) |
b1c3ae8c | 3746 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3747 | "noSuchIface"); |
3748 | else | |
3749 | vty_out(vty, "No such interface name\n"); | |
3750 | } else { | |
7dab10ce | 3751 | if (use_json) { |
d62a17ae | 3752 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3753 | json_interface = json_object_new_object(); |
7dab10ce | 3754 | } |
d62a17ae | 3755 | |
3756 | show_ip_ospf_interface_sub( | |
3757 | vty, ospf, ifp, json_interface_sub, use_json); | |
3758 | ||
7dab10ce | 3759 | if (use_json) { |
7dab10ce CS |
3760 | json_object_object_add(json_interface, |
3761 | ifp->name, | |
d62a17ae | 3762 | json_interface_sub); |
6282e124 CS |
3763 | json_object_object_add(json_vrf, "interfaces", |
3764 | json_interface); | |
7dab10ce | 3765 | } |
d62a17ae | 3766 | } |
3767 | } | |
3768 | ||
3769 | if (use_json) { | |
b1c3ae8c CS |
3770 | if (use_vrf) { |
3771 | if (ospf->vrf_id == VRF_DEFAULT) | |
3772 | json_object_object_add(json, "default", | |
3773 | json_vrf); | |
3774 | else | |
3775 | json_object_object_add(json, ospf->name, | |
3776 | json_vrf); | |
3777 | } | |
d62a17ae | 3778 | } else |
3779 | vty_out(vty, "\n"); | |
3780 | ||
3781 | return CMD_SUCCESS; | |
718e3744 | 3782 | } |
3783 | ||
c9339663 CS |
3784 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3785 | struct ospf_interface *oi, | |
3786 | json_object *json_interface_sub, | |
9f049418 | 3787 | bool use_json) |
c9339663 CS |
3788 | { |
3789 | if (use_json) { | |
996c9314 LB |
3790 | json_object_int_add(json_interface_sub, "ifIndex", |
3791 | oi->ifp->ifindex); | |
3792 | json_object_int_add(json_interface_sub, "helloIn", | |
3793 | oi->hello_in); | |
3794 | json_object_int_add(json_interface_sub, "helloOut", | |
3795 | oi->hello_out); | |
3796 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3797 | oi->db_desc_in); | |
3798 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3799 | oi->db_desc_out); | |
3800 | json_object_int_add(json_interface_sub, "lsReqIn", | |
3801 | oi->ls_req_in); | |
3802 | json_object_int_add(json_interface_sub, "lsReqOut", | |
3803 | oi->ls_req_out); | |
3804 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
3805 | oi->ls_upd_in); | |
3806 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
3807 | oi->ls_upd_out); | |
3808 | json_object_int_add(json_interface_sub, "lsAckIn", | |
3809 | oi->ls_ack_in); | |
3810 | json_object_int_add(json_interface_sub, "lsAckOut", | |
3811 | oi->ls_ack_out); | |
c9339663 CS |
3812 | } else { |
3813 | vty_out(vty, | |
3814 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
3815 | oi->ifp->name, oi->hello_in, oi->hello_out, |
3816 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
3817 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
3818 | oi->ls_ack_in, oi->ls_ack_out); |
3819 | } | |
3820 | } | |
3821 | ||
3822 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
3823 | static int show_ip_ospf_interface_traffic_common( |
3824 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 3825 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
3826 | { |
3827 | struct vrf *vrf = NULL; | |
3828 | struct interface *ifp = NULL; | |
b1c3ae8c | 3829 | json_object *json_vrf = NULL; |
c9339663 CS |
3830 | json_object *json_interface_sub = NULL; |
3831 | ||
3832 | if (!use_json && !display_once) { | |
3833 | vty_out(vty, "\n"); | |
996c9314 LB |
3834 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
3835 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
3836 | " LS-Ack"); | |
c9339663 | 3837 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
3838 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
3839 | " Rx/Tx"); | |
c9339663 | 3840 | vty_out(vty, |
996c9314 | 3841 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 3842 | } else if (use_json) { |
b1c3ae8c CS |
3843 | if (use_vrf) |
3844 | json_vrf = json_object_new_object(); | |
3845 | else | |
3846 | json_vrf = json; | |
c9339663 CS |
3847 | } |
3848 | ||
b1c3ae8c CS |
3849 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3850 | ||
c9339663 CS |
3851 | if (intf_name == NULL) { |
3852 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
3853 | FOR_ALL_INTERFACES (vrf, ifp) { | |
3854 | struct route_node *rn; | |
3855 | struct ospf_interface *oi; | |
3856 | ||
3857 | if (ospf_oi_count(ifp) == 0) | |
3858 | continue; | |
3859 | ||
3860 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 3861 | rn = route_next(rn)) { |
c9339663 CS |
3862 | oi = rn->info; |
3863 | ||
3864 | if (oi == NULL) | |
3865 | continue; | |
3866 | ||
3867 | if (use_json) { | |
3868 | json_interface_sub = | |
3869 | json_object_new_object(); | |
3870 | } | |
3871 | ||
996c9314 LB |
3872 | show_ip_ospf_interface_traffic_sub( |
3873 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 3874 | if (use_json) { |
996c9314 LB |
3875 | json_object_object_add( |
3876 | json_vrf, ifp->name, | |
3877 | json_interface_sub); | |
c9339663 CS |
3878 | } |
3879 | } | |
3880 | } | |
3881 | } else { | |
3882 | /* Interface name is specified. */ | |
a36898e7 | 3883 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
3884 | if (ifp != NULL) { |
3885 | struct route_node *rn; | |
3886 | struct ospf_interface *oi; | |
3887 | ||
3888 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
3889 | vty_out(vty, |
3890 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
3891 | ifp->name); |
3892 | return CMD_SUCCESS; | |
3893 | } | |
3894 | ||
3895 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3896 | rn = route_next(rn)) { | |
3897 | oi = rn->info; | |
3898 | ||
3899 | if (use_json) { | |
3900 | json_interface_sub = | |
3901 | json_object_new_object(); | |
3902 | } | |
3903 | ||
996c9314 LB |
3904 | show_ip_ospf_interface_traffic_sub( |
3905 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 3906 | if (use_json) { |
996c9314 LB |
3907 | json_object_object_add( |
3908 | json_vrf, ifp->name, | |
3909 | json_interface_sub); | |
c9339663 CS |
3910 | } |
3911 | } | |
3912 | } | |
3913 | } | |
3914 | ||
3915 | if (use_json) { | |
b1c3ae8c CS |
3916 | if (use_vrf) { |
3917 | if (ospf->vrf_id == VRF_DEFAULT) | |
3918 | json_object_object_add(json, "default", | |
3919 | json_vrf); | |
3920 | else | |
3921 | json_object_object_add(json, ospf->name, | |
3922 | json_vrf); | |
3923 | } | |
3924 | } else | |
3925 | vty_out(vty, "\n"); | |
c9339663 CS |
3926 | |
3927 | return CMD_SUCCESS; | |
3928 | } | |
3929 | ||
7c8ff89e DS |
3930 | DEFUN (show_ip_ospf_interface, |
3931 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 3932 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
3933 | SHOW_STR |
3934 | IP_STR | |
3935 | "OSPF information\n" | |
b5a8894d | 3936 | VRF_CMD_HELP_STR |
43b8d1d8 | 3937 | "All VRFs\n" |
7c8ff89e | 3938 | "Interface information\n" |
7ec4159b | 3939 | "Interface name\n" |
9973d184 | 3940 | JSON_STR) |
7c8ff89e | 3941 | { |
d62a17ae | 3942 | struct ospf *ospf; |
9f049418 | 3943 | bool uj = use_json(argc, argv); |
b5a8894d | 3944 | struct listnode *node = NULL; |
b1c3ae8c | 3945 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 3946 | bool all_vrf = false; |
b5a8894d CS |
3947 | int ret = CMD_SUCCESS; |
3948 | int inst = 0; | |
b1c3ae8c | 3949 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 3950 | uint8_t use_vrf = 0; |
b1c3ae8c | 3951 | json_object *json = NULL; |
7c8ff89e | 3952 | |
43b8d1d8 CS |
3953 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
3954 | ||
b1c3ae8c CS |
3955 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
3956 | intf_name = argv[idx_intf]->arg; | |
3957 | ||
d62a17ae | 3958 | if (uj) |
b1c3ae8c | 3959 | json = json_object_new_object(); |
6be4da3d | 3960 | |
b5a8894d CS |
3961 | /* vrf input is provided could be all or specific vrf*/ |
3962 | if (vrf_name) { | |
b1c3ae8c | 3963 | use_vrf = 1; |
b5a8894d CS |
3964 | if (all_vrf) { |
3965 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3966 | if (!ospf->oi_running) | |
3967 | continue; | |
996c9314 LB |
3968 | ret = show_ip_ospf_interface_common( |
3969 | vty, ospf, intf_name, use_vrf, json, | |
3970 | uj); | |
b5a8894d | 3971 | } |
b1c3ae8c CS |
3972 | |
3973 | if (uj) { | |
3974 | vty_out(vty, "%s\n", | |
996c9314 LB |
3975 | json_object_to_json_string_ext( |
3976 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3977 | json_object_free(json); |
9f049418 | 3978 | } else if (!ospf) |
94d4c685 | 3979 | vty_out(vty, "%% OSPF instance not found\n"); |
b1c3ae8c | 3980 | |
b5a8894d CS |
3981 | return ret; |
3982 | } | |
3983 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3984 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3985 | if (uj) { |
3986 | vty_out(vty, "%s\n", | |
3987 | json_object_to_json_string_ext( | |
3988 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3989 | json_object_free(json); |
9f049418 | 3990 | } else |
94d4c685 | 3991 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3992 | |
b5a8894d | 3993 | return CMD_SUCCESS; |
b1c3ae8c CS |
3994 | } |
3995 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
3996 | use_vrf, json, uj); | |
b5a8894d CS |
3997 | |
3998 | } else { | |
3999 | /* Display default ospf (instance 0) info */ | |
4000 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4001 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4002 | if (uj) { |
4003 | vty_out(vty, "%s\n", | |
4004 | json_object_to_json_string_ext( | |
4005 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4006 | json_object_free(json); |
9f049418 | 4007 | } else |
94d4c685 | 4008 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4009 | |
b5a8894d | 4010 | return CMD_SUCCESS; |
b1c3ae8c CS |
4011 | } |
4012 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4013 | use_vrf, json, uj); | |
4014 | } | |
4015 | ||
4016 | if (uj) { | |
996c9314 LB |
4017 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4018 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4019 | json_object_free(json); |
b5a8894d CS |
4020 | } |
4021 | ||
4022 | return ret; | |
7c8ff89e DS |
4023 | } |
4024 | ||
4025 | DEFUN (show_ip_ospf_instance_interface, | |
4026 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4027 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4028 | SHOW_STR |
4029 | IP_STR | |
4030 | "OSPF information\n" | |
4031 | "Instance ID\n" | |
4032 | "Interface information\n" | |
7ec4159b | 4033 | "Interface name\n" |
9973d184 | 4034 | JSON_STR) |
7c8ff89e | 4035 | { |
d62a17ae | 4036 | int idx_number = 3; |
b1c3ae8c | 4037 | int idx_intf = 0; |
d62a17ae | 4038 | struct ospf *ospf; |
d7c0a89a | 4039 | unsigned short instance = 0; |
9f049418 | 4040 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4041 | char *intf_name = NULL; |
4042 | int ret = CMD_SUCCESS; | |
4043 | json_object *json = NULL; | |
d62a17ae | 4044 | |
4045 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
4046 | ospf = ospf_lookup_instance(instance); |
4047 | if (ospf == NULL) | |
4048 | return CMD_NOT_MY_INSTANCE; | |
4049 | ||
4050 | if (!ospf->oi_running) | |
d62a17ae | 4051 | return CMD_SUCCESS; |
4052 | ||
4053 | if (uj) | |
b1c3ae8c CS |
4054 | json = json_object_new_object(); |
4055 | ||
4056 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4057 | intf_name = argv[idx_intf]->arg; | |
4058 | ||
4059 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4060 | ||
4061 | if (uj) { | |
996c9314 LB |
4062 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4063 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4064 | json_object_free(json); |
4065 | } | |
d62a17ae | 4066 | |
b1c3ae8c | 4067 | return ret; |
d62a17ae | 4068 | } |
4069 | ||
c9339663 CS |
4070 | DEFUN (show_ip_ospf_interface_traffic, |
4071 | show_ip_ospf_interface_traffic_cmd, | |
4072 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4073 | SHOW_STR | |
4074 | IP_STR | |
4075 | "OSPF information\n" | |
4076 | VRF_CMD_HELP_STR | |
4077 | "All VRFs\n" | |
4078 | "Interface information\n" | |
4079 | "Protocol Packet counters\n" | |
4080 | "Interface name\n" | |
4081 | JSON_STR) | |
4082 | { | |
4083 | struct ospf *ospf = NULL; | |
4084 | struct listnode *node = NULL; | |
4085 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4086 | bool all_vrf = false; |
c9339663 CS |
4087 | int inst = 0; |
4088 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4089 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4090 | json_object *json = NULL; |
c9339663 CS |
4091 | int ret = CMD_SUCCESS; |
4092 | int display_once = 0; | |
d7c0a89a | 4093 | uint8_t use_vrf = 0; |
c9339663 CS |
4094 | |
4095 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4096 | ||
4097 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4098 | intf_name = argv[idx_intf]->arg; | |
4099 | ||
b1c3ae8c CS |
4100 | if (uj) |
4101 | json = json_object_new_object(); | |
4102 | ||
c9339663 | 4103 | if (vrf_name) { |
b1c3ae8c | 4104 | use_vrf = 1; |
c9339663 CS |
4105 | if (all_vrf) { |
4106 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4107 | if (!ospf->oi_running) | |
4108 | continue; | |
4109 | ||
996c9314 LB |
4110 | ret = show_ip_ospf_interface_traffic_common( |
4111 | vty, ospf, intf_name, json, | |
4112 | display_once, use_vrf, uj); | |
c9339663 CS |
4113 | display_once = 1; |
4114 | } | |
b1c3ae8c CS |
4115 | |
4116 | if (uj) { | |
4117 | vty_out(vty, "%s\n", | |
996c9314 LB |
4118 | json_object_to_json_string_ext( |
4119 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4120 | json_object_free(json); |
4121 | } | |
4122 | ||
c9339663 CS |
4123 | return ret; |
4124 | } | |
4125 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4126 | if (ospf == NULL || !ospf->oi_running) { |
4127 | if (uj) | |
4128 | json_object_free(json); | |
c9339663 | 4129 | return CMD_SUCCESS; |
b1c3ae8c CS |
4130 | } |
4131 | ||
996c9314 LB |
4132 | ret = show_ip_ospf_interface_traffic_common( |
4133 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4134 | } else { |
4135 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4136 | if (ospf == NULL || !ospf->oi_running) { |
4137 | if (uj) | |
4138 | json_object_free(json); | |
c9339663 | 4139 | return CMD_SUCCESS; |
b1c3ae8c CS |
4140 | } |
4141 | ||
996c9314 LB |
4142 | ret = show_ip_ospf_interface_traffic_common( |
4143 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4144 | } |
4145 | ||
4146 | if (uj) { | |
996c9314 LB |
4147 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4148 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4149 | json_object_free(json); |
c9339663 CS |
4150 | } |
4151 | ||
4152 | return ret; | |
4153 | } | |
4154 | ||
4155 | ||
d62a17ae | 4156 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4157 | { | |
c84355a9 | 4158 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n", |
d62a17ae | 4159 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", |
4160 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4161 | } | |
4162 | ||
4163 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4164 | struct ospf_interface *oi, | |
9f049418 | 4165 | json_object *json, bool use_json) |
d62a17ae | 4166 | { |
4167 | struct route_node *rn; | |
cef262c3 | 4168 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4169 | char msgbuf[16]; |
96b663a3 | 4170 | char buf[PREFIX_STRLEN]; |
d62a17ae | 4171 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
cef262c3 | 4172 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4173 | |
4174 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4175 | if ((nbr = rn->info)) { | |
4176 | /* Do not show myself. */ | |
cef262c3 CS |
4177 | if (nbr == oi->nbr_self) |
4178 | continue; | |
4179 | /* Down state is not shown. */ | |
4180 | if (nbr->state == NSM_Down) | |
4181 | continue; | |
4182 | if (use_json) { | |
4183 | char neigh_str[INET_ADDRSTRLEN]; | |
4184 | ||
996c9314 LB |
4185 | if (prev_nbr |
4186 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4187 | &nbr->src)) { | |
cef262c3 CS |
4188 | /* Start new neigh list */ |
4189 | json_neigh_array = NULL; | |
4190 | } | |
4191 | ||
996c9314 | 4192 | if (nbr->state == NSM_Attempt |
975a328e | 4193 | && nbr->router_id.s_addr == INADDR_ANY) |
6021c6c0 CS |
4194 | strlcpy(neigh_str, "neighbor", |
4195 | sizeof(neigh_str)); | |
cef262c3 | 4196 | else |
96b663a3 MS |
4197 | inet_ntop(AF_INET, &nbr->router_id, |
4198 | neigh_str, sizeof(neigh_str)); | |
cef262c3 CS |
4199 | |
4200 | json_object_object_get_ex(json, neigh_str, | |
4201 | &json_neigh_array); | |
4202 | ||
4203 | if (!json_neigh_array) { | |
996c9314 LB |
4204 | json_neigh_array = |
4205 | json_object_new_array(); | |
4206 | json_object_object_add( | |
4207 | json, neigh_str, | |
4208 | json_neigh_array); | |
d62a17ae | 4209 | } |
cef262c3 | 4210 | |
996c9314 | 4211 | json_neighbor = json_object_new_object(); |
cef262c3 CS |
4212 | |
4213 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4214 | ||
4215 | long time_store; | |
4216 | ||
996c9314 LB |
4217 | time_store = |
4218 | monotime_until( | |
cef262c3 | 4219 | &nbr->t_inactivity->u.sands, |
996c9314 LB |
4220 | NULL) |
4221 | / 1000LL; | |
cef262c3 | 4222 | |
996c9314 | 4223 | json_object_int_add(json_neighbor, "priority", |
cef262c3 CS |
4224 | nbr->priority); |
4225 | json_object_string_add(json_neighbor, "state", | |
4226 | msgbuf); | |
4227 | json_object_int_add(json_neighbor, | |
4228 | "deadTimeMsecs", | |
4229 | time_store); | |
96b663a3 MS |
4230 | json_object_string_add( |
4231 | json_neighbor, "address", | |
4232 | inet_ntop(AF_INET, &nbr->src, | |
4233 | buf, sizeof(buf))); | |
cef262c3 CS |
4234 | json_object_string_add(json_neighbor, |
4235 | "ifaceName", | |
4236 | IF_NAME(oi)); | |
996c9314 LB |
4237 | json_object_int_add( |
4238 | json_neighbor, "retransmitCounter", | |
4239 | ospf_ls_retransmit_count(nbr)); | |
cef262c3 | 4240 | json_object_int_add(json_neighbor, |
996c9314 LB |
4241 | "requestCounter", |
4242 | ospf_ls_request_count(nbr)); | |
cef262c3 | 4243 | json_object_int_add(json_neighbor, |
996c9314 LB |
4244 | "dbSummaryCounter", |
4245 | ospf_db_summary_count(nbr)); | |
cef262c3 CS |
4246 | |
4247 | json_object_array_add(json_neigh_array, | |
4248 | json_neighbor); | |
4249 | } else { | |
4250 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4251 | ||
996c9314 | 4252 | if (nbr->state == NSM_Attempt |
975a328e | 4253 | && nbr->router_id.s_addr == INADDR_ANY) |
996c9314 LB |
4254 | vty_out(vty, "%-15s %3d %-15s ", "-", |
4255 | nbr->priority, msgbuf); | |
cef262c3 | 4256 | else |
96b663a3 MS |
4257 | vty_out(vty, "%-15pI4 %3d %-15s ", |
4258 | &nbr->router_id, | |
996c9314 | 4259 | nbr->priority, msgbuf); |
cef262c3 CS |
4260 | |
4261 | vty_out(vty, "%9s ", | |
4262 | ospf_timer_dump(nbr->t_inactivity, | |
4263 | timebuf, | |
4264 | sizeof(timebuf))); | |
96b663a3 | 4265 | vty_out(vty, "%-15pI4 ", &nbr->src); |
c84355a9 | 4266 | vty_out(vty, "%-32s %5ld %5ld %5d\n", |
cef262c3 CS |
4267 | IF_NAME(oi), |
4268 | ospf_ls_retransmit_count(nbr), | |
4269 | ospf_ls_request_count(nbr), | |
4270 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4271 | } |
cef262c3 | 4272 | prev_nbr = nbr; |
d62a17ae | 4273 | } |
4274 | } | |
4275 | } | |
4276 | ||
4277 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4278 | json_object *json, bool use_json, |
d7c0a89a | 4279 | uint8_t use_vrf) |
d62a17ae | 4280 | { |
4281 | struct ospf_interface *oi; | |
4282 | struct listnode *node; | |
6282e124 | 4283 | json_object *json_vrf = NULL; |
2bc7673f | 4284 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4285 | |
b1c3ae8c CS |
4286 | if (use_json) { |
4287 | if (use_vrf) | |
4288 | json_vrf = json_object_new_object(); | |
4289 | else | |
4290 | json_vrf = json; | |
6282e124 | 4291 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4292 | } |
d62a17ae | 4293 | |
4294 | if (ospf->instance) { | |
4295 | if (use_json) | |
4296 | json_object_int_add(json, "ospfInstance", | |
4297 | ospf->instance); | |
4298 | else | |
4299 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4300 | } | |
7c8ff89e | 4301 | |
b1c3ae8c CS |
4302 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4303 | if (!use_json) | |
4304 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4305 | |
2bc7673f CS |
4306 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4307 | if (ospf_interface_neighbor_count(oi) == 0) | |
4308 | continue; | |
2bc7673f CS |
4309 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4310 | } | |
718e3744 | 4311 | |
d62a17ae | 4312 | if (use_json) { |
996c9314 | 4313 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
b1c3ae8c CS |
4314 | if (use_vrf) { |
4315 | if (ospf->vrf_id == VRF_DEFAULT) | |
4316 | json_object_object_add(json, "default", | |
4317 | json_vrf); | |
4318 | else | |
4319 | json_object_object_add(json, ospf->name, | |
4320 | json_vrf); | |
4321 | } | |
d62a17ae | 4322 | } else |
4323 | vty_out(vty, "\n"); | |
7c8ff89e | 4324 | |
d62a17ae | 4325 | return CMD_SUCCESS; |
718e3744 | 4326 | } |
4327 | ||
7c8ff89e DS |
4328 | DEFUN (show_ip_ospf_neighbor, |
4329 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4330 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4331 | SHOW_STR |
4332 | IP_STR | |
4333 | "OSPF information\n" | |
b5a8894d CS |
4334 | VRF_CMD_HELP_STR |
4335 | "All VRFs\n" | |
91756b38 | 4336 | "Neighbor list\n" |
9973d184 | 4337 | JSON_STR) |
718e3744 | 4338 | { |
d62a17ae | 4339 | struct ospf *ospf; |
9f049418 | 4340 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4341 | struct listnode *node = NULL; |
4342 | char *vrf_name = NULL; | |
2951a7a4 | 4343 | bool all_vrf = false; |
b5a8894d CS |
4344 | int ret = CMD_SUCCESS; |
4345 | int inst = 0; | |
4346 | int idx_vrf = 0; | |
d7c0a89a | 4347 | uint8_t use_vrf = 0; |
b1c3ae8c | 4348 | json_object *json = NULL; |
718e3744 | 4349 | |
43b8d1d8 | 4350 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4351 | |
b1c3ae8c CS |
4352 | if (uj) |
4353 | json = json_object_new_object(); | |
b5a8894d CS |
4354 | |
4355 | /* vrf input is provided could be all or specific vrf*/ | |
4356 | if (vrf_name) { | |
b1c3ae8c | 4357 | use_vrf = 1; |
b5a8894d CS |
4358 | if (all_vrf) { |
4359 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4360 | if (!ospf->oi_running) | |
4361 | continue; | |
996c9314 LB |
4362 | ret = show_ip_ospf_neighbor_common( |
4363 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4364 | } |
4365 | ||
4366 | if (uj) { | |
4367 | vty_out(vty, "%s\n", | |
996c9314 LB |
4368 | json_object_to_json_string_ext( |
4369 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4370 | json_object_free(json); |
9f049418 DS |
4371 | } else if (!ospf) |
4372 | vty_out(vty, "OSPF instance not found\n"); | |
b1c3ae8c | 4373 | |
b5a8894d CS |
4374 | return ret; |
4375 | } | |
b1c3ae8c | 4376 | |
b5a8894d | 4377 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4378 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4379 | if (uj) { |
4380 | vty_out(vty, "%s\n", | |
4381 | json_object_to_json_string_ext( | |
4382 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4383 | json_object_free(json); |
9f049418 DS |
4384 | } else |
4385 | vty_out(vty, "%% OSPF instance not found\n"); | |
4386 | ||
b5a8894d | 4387 | return CMD_SUCCESS; |
b1c3ae8c | 4388 | } |
b5a8894d CS |
4389 | } else { |
4390 | /* Display default ospf (instance 0) info */ | |
4391 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4392 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4393 | if (uj) { |
4394 | vty_out(vty, "%s\n", | |
4395 | json_object_to_json_string_ext( | |
4396 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4397 | json_object_free(json); |
9f049418 DS |
4398 | } else |
4399 | vty_out(vty, "%% OSPF instance not found\n"); | |
4400 | ||
b5a8894d | 4401 | return CMD_SUCCESS; |
b1c3ae8c | 4402 | } |
b5a8894d CS |
4403 | } |
4404 | ||
b1c3ae8c CS |
4405 | if (ospf) { |
4406 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4407 | use_vrf); | |
4408 | ||
4409 | if (uj) { | |
4410 | vty_out(vty, "%s\n", | |
996c9314 LB |
4411 | json_object_to_json_string_ext( |
4412 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4413 | } |
4414 | } | |
4415 | ||
4416 | if (uj) | |
4417 | json_object_free(json); | |
b5a8894d CS |
4418 | |
4419 | return ret; | |
7c8ff89e DS |
4420 | } |
4421 | ||
4422 | ||
4423 | DEFUN (show_ip_ospf_instance_neighbor, | |
4424 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4425 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4426 | SHOW_STR |
4427 | IP_STR | |
4428 | "OSPF information\n" | |
4429 | "Instance ID\n" | |
91756b38 | 4430 | "Neighbor list\n" |
9973d184 | 4431 | JSON_STR) |
7c8ff89e | 4432 | { |
d62a17ae | 4433 | int idx_number = 3; |
4434 | struct ospf *ospf; | |
d7c0a89a | 4435 | unsigned short instance = 0; |
9f049418 | 4436 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4437 | json_object *json = NULL; |
4438 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4439 | |
d62a17ae | 4440 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4441 | ospf = ospf_lookup_instance(instance); |
4442 | if (ospf == NULL) | |
4443 | return CMD_NOT_MY_INSTANCE; | |
4444 | ||
4445 | if (!ospf->oi_running) | |
d62a17ae | 4446 | return CMD_SUCCESS; |
7c8ff89e | 4447 | |
b1c3ae8c CS |
4448 | if (uj) |
4449 | json = json_object_new_object(); | |
b5a8894d | 4450 | |
b1c3ae8c CS |
4451 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4452 | ||
4453 | if (uj) { | |
996c9314 LB |
4454 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4455 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4456 | json_object_free(json); |
4457 | } | |
4458 | ||
4459 | return ret; | |
7c8ff89e DS |
4460 | } |
4461 | ||
d62a17ae | 4462 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4463 | json_object *json, bool use_json, |
d7c0a89a | 4464 | uint8_t use_vrf) |
d62a17ae | 4465 | { |
4466 | struct listnode *node; | |
4467 | struct ospf_interface *oi; | |
96b663a3 | 4468 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 4469 | json_object *json_vrf = NULL; |
d62a17ae | 4470 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4471 | |
d62a17ae | 4472 | if (use_json) { |
b1c3ae8c CS |
4473 | if (use_vrf) |
4474 | json_vrf = json_object_new_object(); | |
4475 | else | |
4476 | json_vrf = json; | |
d62a17ae | 4477 | json_neighbor_sub = json_object_new_object(); |
b5a8894d | 4478 | } |
d62a17ae | 4479 | |
b1c3ae8c CS |
4480 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4481 | if (!use_json) | |
4482 | show_ip_ospf_neighbour_header(vty); | |
4483 | ||
d62a17ae | 4484 | if (ospf->instance) { |
4485 | if (use_json) | |
b1c3ae8c | 4486 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4487 | ospf->instance); |
4488 | else | |
4489 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4490 | } | |
4491 | ||
4492 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4493 | struct listnode *nbr_node; | |
4494 | struct ospf_nbr_nbma *nbr_nbma; | |
4495 | ||
b1c3ae8c | 4496 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4497 | |
4498 | /* print Down neighbor status */ | |
4499 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4500 | if (nbr_nbma->nbr == NULL | |
4501 | || nbr_nbma->nbr->state == NSM_Down) { | |
4502 | if (use_json) { | |
4503 | json_object_int_add(json_neighbor_sub, | |
4504 | "nbrNbmaPriority", | |
4505 | nbr_nbma->priority); | |
4506 | json_object_boolean_true_add( | |
4507 | json_neighbor_sub, | |
4508 | "nbrNbmaDown"); | |
4509 | json_object_string_add( | |
4510 | json_neighbor_sub, | |
4511 | "nbrNbmaIfaceName", | |
4512 | IF_NAME(oi)); | |
4513 | json_object_int_add( | |
4514 | json_neighbor_sub, | |
4515 | "nbrNbmaRetransmitCounter", 0); | |
4516 | json_object_int_add( | |
4517 | json_neighbor_sub, | |
4518 | "nbrNbmaRequestCounter", 0); | |
4519 | json_object_int_add( | |
4520 | json_neighbor_sub, | |
4521 | "nbrNbmaDbSummaryCounter", 0); | |
4522 | json_object_object_add( | |
b1c3ae8c | 4523 | json_vrf, |
96b663a3 MS |
4524 | inet_ntop(AF_INET, |
4525 | &nbr_nbma->addr, buf, | |
4526 | sizeof(buf)), | |
d62a17ae | 4527 | json_neighbor_sub); |
4528 | } else { | |
4529 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4530 | "-", nbr_nbma->priority, "Down", | |
4531 | "-"); | |
4532 | vty_out(vty, | |
96b663a3 MS |
4533 | "%-32pI4 %-20s %5d %5d %5d\n", |
4534 | &nbr_nbma->addr, | |
d62a17ae | 4535 | IF_NAME(oi), 0, 0, 0); |
4536 | } | |
4537 | } | |
4538 | } | |
4539 | } | |
4540 | ||
4541 | if (use_json) { | |
b1c3ae8c CS |
4542 | if (use_vrf) { |
4543 | if (ospf->vrf_id == VRF_DEFAULT) | |
4544 | json_object_object_add(json, "default", | |
4545 | json_vrf); | |
4546 | else | |
4547 | json_object_object_add(json, ospf->name, | |
4548 | json_vrf); | |
4549 | } | |
d62a17ae | 4550 | } else |
4551 | vty_out(vty, "\n"); | |
4552 | ||
4553 | return CMD_SUCCESS; | |
718e3744 | 4554 | } |
4555 | ||
7c8ff89e DS |
4556 | DEFUN (show_ip_ospf_neighbor_all, |
4557 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4558 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4559 | SHOW_STR |
4560 | IP_STR | |
4561 | "OSPF information\n" | |
b5a8894d CS |
4562 | VRF_CMD_HELP_STR |
4563 | "All VRFs\n" | |
718e3744 | 4564 | "Neighbor list\n" |
91756b38 | 4565 | "include down status neighbor\n" |
9973d184 | 4566 | JSON_STR) |
7c8ff89e | 4567 | { |
d62a17ae | 4568 | struct ospf *ospf; |
9f049418 | 4569 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4570 | struct listnode *node = NULL; |
4571 | char *vrf_name = NULL; | |
2951a7a4 | 4572 | bool all_vrf = false; |
b5a8894d CS |
4573 | int ret = CMD_SUCCESS; |
4574 | int inst = 0; | |
4575 | int idx_vrf = 0; | |
d7c0a89a | 4576 | uint8_t use_vrf = 0; |
b1c3ae8c | 4577 | json_object *json = NULL; |
7c8ff89e | 4578 | |
43b8d1d8 | 4579 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4580 | |
b1c3ae8c CS |
4581 | if (uj) |
4582 | json = json_object_new_object(); | |
b5a8894d CS |
4583 | |
4584 | /* vrf input is provided could be all or specific vrf*/ | |
4585 | if (vrf_name) { | |
b1c3ae8c | 4586 | use_vrf = 1; |
b5a8894d CS |
4587 | if (all_vrf) { |
4588 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4589 | if (!ospf->oi_running) | |
4590 | continue; | |
996c9314 LB |
4591 | ret = show_ip_ospf_neighbor_all_common( |
4592 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4593 | } |
4594 | ||
4595 | if (uj) { | |
4596 | vty_out(vty, "%s\n", | |
996c9314 LB |
4597 | json_object_to_json_string_ext( |
4598 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4599 | json_object_free(json); |
b5a8894d | 4600 | } |
b1c3ae8c | 4601 | |
b5a8894d CS |
4602 | return ret; |
4603 | } | |
b1c3ae8c | 4604 | |
b5a8894d | 4605 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4606 | if (ospf == NULL || !ospf->oi_running) { |
4607 | if (uj) | |
4608 | json_object_free(json); | |
b5a8894d | 4609 | return CMD_SUCCESS; |
b1c3ae8c | 4610 | } |
b5a8894d CS |
4611 | } else { |
4612 | /* Display default ospf (instance 0) info */ | |
4613 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4614 | if (ospf == NULL || !ospf->oi_running) { |
4615 | if (uj) | |
4616 | json_object_free(json); | |
b5a8894d | 4617 | return CMD_SUCCESS; |
b1c3ae8c | 4618 | } |
b5a8894d CS |
4619 | } |
4620 | ||
b1c3ae8c CS |
4621 | if (ospf) { |
4622 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4623 | use_vrf); | |
4624 | if (uj) { | |
4625 | vty_out(vty, "%s\n", | |
996c9314 LB |
4626 | json_object_to_json_string_ext( |
4627 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4628 | } |
4629 | } | |
4630 | ||
4631 | if (uj) | |
4632 | json_object_free(json); | |
b5a8894d CS |
4633 | |
4634 | return ret; | |
7c8ff89e DS |
4635 | } |
4636 | ||
4637 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4638 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4639 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4640 | SHOW_STR |
4641 | IP_STR | |
4642 | "OSPF information\n" | |
4643 | "Instance ID\n" | |
4644 | "Neighbor list\n" | |
91756b38 | 4645 | "include down status neighbor\n" |
9973d184 | 4646 | JSON_STR) |
718e3744 | 4647 | { |
d62a17ae | 4648 | int idx_number = 3; |
4649 | struct ospf *ospf; | |
d7c0a89a | 4650 | unsigned short instance = 0; |
9f049418 | 4651 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4652 | json_object *json = NULL; |
4653 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4654 | |
d62a17ae | 4655 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4656 | ospf = ospf_lookup_instance(instance); |
4657 | if (ospf == NULL) | |
4658 | return CMD_NOT_MY_INSTANCE; | |
4659 | ||
4660 | if (!ospf->oi_running) | |
d62a17ae | 4661 | return CMD_SUCCESS; |
b1c3ae8c CS |
4662 | if (uj) |
4663 | json = json_object_new_object(); | |
4664 | ||
4665 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4666 | ||
4667 | if (uj) { | |
4668 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4669 | json, JSON_C_TO_STRING_PRETTY)); | |
4670 | json_object_free(json); | |
4671 | } | |
7c8ff89e | 4672 | |
b1c3ae8c | 4673 | return ret; |
7c8ff89e DS |
4674 | } |
4675 | ||
d62a17ae | 4676 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4677 | int arg_base, | |
4678 | struct cmd_token **argv, | |
9f049418 | 4679 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4680 | { |
4681 | struct interface *ifp; | |
4682 | struct route_node *rn; | |
4683 | json_object *json = NULL; | |
91756b38 | 4684 | |
d62a17ae | 4685 | if (use_json) |
4686 | json = json_object_new_object(); | |
d62a17ae | 4687 | |
4688 | if (ospf->instance) { | |
4689 | if (use_json) | |
4690 | json_object_int_add(json, "ospfInstance", | |
4691 | ospf->instance); | |
4692 | else | |
4693 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4694 | } | |
4695 | ||
b1c3ae8c | 4696 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4697 | |
a36898e7 | 4698 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4699 | if (!ifp) { |
4700 | if (use_json) | |
4701 | json_object_boolean_true_add(json, "noSuchIface"); | |
4702 | else | |
4703 | vty_out(vty, "No such interface.\n"); | |
4704 | return CMD_WARNING; | |
4705 | } | |
4706 | ||
4707 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4708 | struct ospf_interface *oi = rn->info; | |
4709 | ||
4710 | if (oi == NULL) | |
4711 | continue; | |
4712 | ||
4713 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4714 | } | |
4715 | ||
4716 | if (use_json) { | |
9d303b37 DL |
4717 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4718 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4719 | json_object_free(json); |
4720 | } else | |
4721 | vty_out(vty, "\n"); | |
4722 | ||
4723 | return CMD_SUCCESS; | |
718e3744 | 4724 | } |
4725 | ||
7c8ff89e DS |
4726 | DEFUN (show_ip_ospf_neighbor_int, |
4727 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4728 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4729 | SHOW_STR |
4730 | IP_STR | |
4731 | "OSPF information\n" | |
03ed9f02 | 4732 | VRF_CMD_HELP_STR |
7c8ff89e | 4733 | "Neighbor list\n" |
91756b38 | 4734 | "Interface name\n" |
9973d184 | 4735 | JSON_STR) |
7c8ff89e | 4736 | { |
d62a17ae | 4737 | struct ospf *ospf; |
03ed9f02 PG |
4738 | int idx_ifname = 0; |
4739 | int idx_vrf = 0; | |
9f049418 | 4740 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4741 | int ret = CMD_SUCCESS; |
4742 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4743 | char *vrf_name = NULL; |
4744 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4745 | struct vrf *vrf = NULL; | |
4746 | ||
4747 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4748 | vrf_name = argv[idx_vrf + 1]->arg; | |
4749 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4750 | vrf_name = NULL; | |
4751 | if (vrf_name) { | |
4752 | vrf = vrf_lookup_by_name(vrf_name); | |
4753 | if (vrf) | |
4754 | vrf_id = vrf->vrf_id; | |
4755 | } | |
4756 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4757 | ||
4758 | if (!ospf || !ospf->oi_running) | |
4759 | return ret; | |
7c8ff89e | 4760 | |
b5a8894d CS |
4761 | if (!uj) |
4762 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4763 | |
03ed9f02 | 4764 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4765 | |
a36898e7 | 4766 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4767 | if (!ifp) |
4768 | return ret; | |
4769 | ||
4770 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4771 | argv, uj, 0); | |
b5a8894d | 4772 | return ret; |
7c8ff89e DS |
4773 | } |
4774 | ||
4775 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4776 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4777 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4778 | SHOW_STR |
4779 | IP_STR | |
4780 | "OSPF information\n" | |
4781 | "Instance ID\n" | |
4782 | "Neighbor list\n" | |
91756b38 | 4783 | "Interface name\n" |
9973d184 | 4784 | JSON_STR) |
7c8ff89e | 4785 | { |
d62a17ae | 4786 | int idx_number = 3; |
b4e84315 | 4787 | int idx_ifname = 5; |
d62a17ae | 4788 | struct ospf *ospf; |
d7c0a89a | 4789 | unsigned short instance = 0; |
9f049418 | 4790 | bool uj = use_json(argc, argv); |
7c8ff89e | 4791 | |
b5a8894d CS |
4792 | if (!uj) |
4793 | show_ip_ospf_neighbour_header(vty); | |
4794 | ||
d62a17ae | 4795 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4796 | ospf = ospf_lookup_instance(instance); |
4797 | if (ospf == NULL) | |
4798 | return CMD_NOT_MY_INSTANCE; | |
4799 | ||
4800 | if (!ospf->oi_running) | |
d62a17ae | 4801 | return CMD_SUCCESS; |
7c8ff89e | 4802 | |
b5a8894d CS |
4803 | if (!uj) |
4804 | show_ip_ospf_neighbour_header(vty); | |
4805 | ||
996c9314 LB |
4806 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
4807 | 0); | |
718e3744 | 4808 | } |
4809 | ||
d62a17ae | 4810 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
4811 | struct ospf_interface *oi, | |
4812 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 4813 | bool use_json, json_object *json) |
d62a17ae | 4814 | { |
4815 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 4816 | char buf[PREFIX_STRLEN]; |
d62a17ae | 4817 | json_object *json_sub = NULL; |
718e3744 | 4818 | |
d62a17ae | 4819 | if (use_json) |
4820 | json_sub = json_object_new_object(); | |
4821 | else /* Show neighbor ID. */ | |
4822 | vty_out(vty, " Neighbor %s,", "-"); | |
4823 | ||
4824 | /* Show interface address. */ | |
4825 | if (use_json) | |
4826 | json_object_string_add(json_sub, "ifaceAddress", | |
96b663a3 MS |
4827 | inet_ntop(AF_INET, &nbr_nbma->addr, |
4828 | buf, sizeof(buf))); | |
d62a17ae | 4829 | else |
96b663a3 MS |
4830 | vty_out(vty, " interface address %pI4\n", |
4831 | &nbr_nbma->addr); | |
d62a17ae | 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}; | |
96b663a3 | 4901 | char buf[PREFIX_STRLEN]; |
d62a17ae | 4902 | |
cb0b2ac6 CS |
4903 | if (use_json) { |
4904 | if (prev_nbr && | |
4905 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
4906 | json_neigh_array = NULL; | |
4907 | } | |
4908 | ||
975a328e DA |
4909 | if (nbr->state == NSM_Attempt |
4910 | && nbr->router_id.s_addr == INADDR_ANY) | |
cb0b2ac6 CS |
4911 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
4912 | else | |
96b663a3 MS |
4913 | inet_ntop(AF_INET, &nbr->router_id, |
4914 | neigh_str, sizeof(neigh_str)); | |
cb0b2ac6 CS |
4915 | |
4916 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
4917 | ||
4918 | if (!json_neigh_array) { | |
4919 | json_neigh_array = json_object_new_array(); | |
4920 | json_object_object_add(json, neigh_str, | |
4921 | json_neigh_array); | |
4922 | } | |
4923 | ||
4924 | json_neigh = json_object_new_object(); | |
4925 | ||
4926 | } else { | |
d62a17ae | 4927 | /* Show neighbor ID. */ |
975a328e DA |
4928 | if (nbr->state == NSM_Attempt |
4929 | && nbr->router_id.s_addr == INADDR_ANY) | |
d62a17ae | 4930 | vty_out(vty, " Neighbor %s,", "-"); |
4931 | else | |
96b663a3 MS |
4932 | vty_out(vty, " Neighbor %pI4,", |
4933 | &nbr->router_id); | |
d62a17ae | 4934 | } |
4935 | ||
4936 | /* Show interface address. */ | |
4937 | if (use_json) | |
cb0b2ac6 | 4938 | json_object_string_add(json_neigh, "ifaceAddress", |
96b663a3 MS |
4939 | inet_ntop(AF_INET, |
4940 | &nbr->address.u.prefix4, | |
4941 | buf, sizeof(buf))); | |
d62a17ae | 4942 | else |
96b663a3 MS |
4943 | vty_out(vty, " interface address %pI4\n", |
4944 | &nbr->address.u.prefix4); | |
d62a17ae | 4945 | |
4946 | /* Show Area ID. */ | |
4947 | if (use_json) { | |
cb0b2ac6 | 4948 | json_object_string_add(json_neigh, "areaId", |
d62a17ae | 4949 | ospf_area_desc_string(oi->area)); |
cb0b2ac6 | 4950 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
d62a17ae | 4951 | } else |
4952 | vty_out(vty, " In the area %s via interface %s\n", | |
4953 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
4954 | ||
4955 | /* Show neighbor priority and state. */ | |
4956 | if (use_json) { | |
cb0b2ac6 | 4957 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
d62a17ae | 4958 | json_object_string_add( |
cb0b2ac6 | 4959 | json_neigh, "nbrState", |
d62a17ae | 4960 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); |
4961 | } else | |
4962 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4963 | nbr->priority, | |
4964 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4965 | ||
4966 | /* Show state changes. */ | |
4967 | if (use_json) | |
cb0b2ac6 | 4968 | json_object_int_add(json_neigh, "stateChangeCounter", |
d62a17ae | 4969 | nbr->state_change); |
4970 | else | |
4971 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
4972 | ||
4973 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
4974 | struct timeval res; | |
4975 | long time_store; | |
4976 | ||
4977 | time_store = | |
4978 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
4979 | if (use_json) { | |
cb0b2ac6 | 4980 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
d62a17ae | 4981 | time_store); |
4982 | } else { | |
4983 | vty_out(vty, | |
4984 | " Most recent state change statistics:\n"); | |
4985 | vty_out(vty, " Progressive change %s ago\n", | |
4986 | ospf_timeval_dump(&res, timebuf, | |
4987 | sizeof(timebuf))); | |
4988 | } | |
4989 | } | |
4990 | ||
4991 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
4992 | struct timeval res; | |
4993 | long time_store; | |
4994 | ||
4995 | time_store = | |
4996 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
4997 | if (use_json) { | |
cb0b2ac6 | 4998 | json_object_int_add(json_neigh, |
d62a17ae | 4999 | "lastRegressiveChangeMsec", |
5000 | time_store); | |
5001 | if (nbr->last_regress_str) | |
5002 | json_object_string_add( | |
cb0b2ac6 CS |
5003 | json_neigh, |
5004 | "lastRegressiveChangeReason", | |
d62a17ae | 5005 | nbr->last_regress_str); |
5006 | } else { | |
5007 | vty_out(vty, | |
5008 | " Regressive change %s ago, due to %s\n", | |
5009 | ospf_timeval_dump(&res, timebuf, | |
5010 | sizeof(timebuf)), | |
5011 | (nbr->last_regress_str ? nbr->last_regress_str | |
5012 | : "??")); | |
5013 | } | |
5014 | } | |
5015 | ||
5016 | /* Show Designated Rotuer ID. */ | |
5017 | if (use_json) | |
cb0b2ac6 | 5018 | json_object_string_add(json_neigh, "routerDesignatedId", |
96b663a3 MS |
5019 | inet_ntop(AF_INET, &nbr->d_router, |
5020 | buf, sizeof(buf))); | |
d62a17ae | 5021 | else |
96b663a3 | 5022 | vty_out(vty, " DR is %pI4,", &nbr->d_router); |
d62a17ae | 5023 | |
5024 | /* Show Backup Designated Rotuer ID. */ | |
5025 | if (use_json) | |
cb0b2ac6 | 5026 | json_object_string_add(json_neigh, "routerDesignatedBackupId", |
96b663a3 MS |
5027 | inet_ntop(AF_INET, &nbr->bd_router, |
5028 | buf, sizeof(buf))); | |
d62a17ae | 5029 | else |
96b663a3 | 5030 | vty_out(vty, " BDR is %pI4\n", &nbr->bd_router); |
d62a17ae | 5031 | |
5032 | /* Show options. */ | |
5033 | if (use_json) { | |
cb0b2ac6 CS |
5034 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5035 | json_object_string_add(json_neigh, "optionsList", | |
d62a17ae | 5036 | ospf_options_dump(nbr->options)); |
5037 | } else | |
5038 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5039 | ospf_options_dump(nbr->options)); | |
5040 | ||
5041 | /* Show Router Dead interval timer. */ | |
5042 | if (use_json) { | |
5043 | if (nbr->t_inactivity) { | |
5044 | long time_store; | |
5045 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5046 | NULL) | |
5047 | / 1000LL; | |
cb0b2ac6 | 5048 | json_object_int_add(json_neigh, |
d62a17ae | 5049 | "routerDeadIntervalTimerDueMsec", |
5050 | time_store); | |
5051 | } else | |
5052 | json_object_int_add( | |
cb0b2ac6 CS |
5053 | json_neigh, |
5054 | "routerDeadIntervalTimerDueMsec", -1); | |
d62a17ae | 5055 | } else |
5056 | vty_out(vty, " Dead timer due in %s\n", | |
5057 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5058 | sizeof(timebuf))); | |
5059 | ||
5060 | /* Show Database Summary list. */ | |
5061 | if (use_json) | |
cb0b2ac6 | 5062 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
d62a17ae | 5063 | ospf_db_summary_count(nbr)); |
5064 | else | |
5065 | vty_out(vty, " Database Summary List %d\n", | |
5066 | ospf_db_summary_count(nbr)); | |
5067 | ||
5068 | /* Show Link State Request list. */ | |
5069 | if (use_json) | |
cb0b2ac6 | 5070 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
d62a17ae | 5071 | ospf_ls_request_count(nbr)); |
5072 | else | |
5073 | vty_out(vty, " Link State Request List %ld\n", | |
5074 | ospf_ls_request_count(nbr)); | |
5075 | ||
5076 | /* Show Link State Retransmission list. */ | |
5077 | if (use_json) | |
cb0b2ac6 | 5078 | json_object_int_add(json_neigh, |
d62a17ae | 5079 | "linkStateRetransmissionListCounter", |
5080 | ospf_ls_retransmit_count(nbr)); | |
5081 | else | |
5082 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5083 | ospf_ls_retransmit_count(nbr)); | |
5084 | ||
5085 | /* Show inactivity timer thread. */ | |
5086 | if (use_json) { | |
5087 | if (nbr->t_inactivity != NULL) | |
cb0b2ac6 | 5088 | json_object_string_add(json_neigh, |
d62a17ae | 5089 | "threadInactivityTimer", "on"); |
5090 | } else | |
5091 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5092 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5093 | ||
5094 | /* Show Database Description retransmission thread. */ | |
5095 | if (use_json) { | |
5096 | if (nbr->t_db_desc != NULL) | |
5097 | json_object_string_add( | |
cb0b2ac6 | 5098 | json_neigh, |
d62a17ae | 5099 | "threadDatabaseDescriptionRetransmission", |
5100 | "on"); | |
5101 | } else | |
5102 | vty_out(vty, | |
5103 | " Thread Database Description Retransmision %s\n", | |
5104 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5105 | ||
5106 | /* Show Link State Request Retransmission thread. */ | |
5107 | if (use_json) { | |
5108 | if (nbr->t_ls_req != NULL) | |
5109 | json_object_string_add( | |
cb0b2ac6 | 5110 | json_neigh, |
d62a17ae | 5111 | "threadLinkStateRequestRetransmission", "on"); |
5112 | } else | |
5113 | vty_out(vty, | |
5114 | " Thread Link State Request Retransmission %s\n", | |
5115 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5116 | ||
5117 | /* Show Link State Update Retransmission thread. */ | |
5118 | if (use_json) { | |
5119 | if (nbr->t_ls_upd != NULL) | |
5120 | json_object_string_add( | |
cb0b2ac6 CS |
5121 | json_neigh, |
5122 | "threadLinkStateUpdateRetransmission", | |
d62a17ae | 5123 | "on"); |
5124 | } else | |
5125 | vty_out(vty, | |
5126 | " Thread Link State Update Retransmission %s\n\n", | |
5127 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5128 | ||
abd5b8c7 | 5129 | if (!use_json) { |
5130 | vty_out(vty, " Graceful restart Helper info:\n"); | |
5131 | ||
5132 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5133 | vty_out(vty, | |
5134 | " Graceful Restart HELPER Status : Inprogress.\n"); | |
5135 | ||
5136 | vty_out(vty, | |
5137 | " Graceful Restart grace period time: %d (seconds).\n", | |
5138 | nbr->gr_helper_info.recvd_grace_period); | |
5139 | vty_out(vty, " Graceful Restart reason: %s.\n", | |
d05d5280 MS |
5140 | ospf_restart_reason2str( |
5141 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5142 | } else { |
5143 | vty_out(vty, | |
5144 | " Graceful Restart HELPER Status : None\n"); | |
5145 | } | |
5146 | ||
5147 | if (nbr->gr_helper_info.rejected_reason | |
5148 | != OSPF_HELPER_REJECTED_NONE) | |
5149 | vty_out(vty, " Helper rejected reason: %s.\n", | |
d05d5280 MS |
5150 | ospf_rejected_reason2str( |
5151 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5152 | |
5153 | if (nbr->gr_helper_info.helper_exit_reason | |
5154 | != OSPF_GR_HELPER_EXIT_NONE) | |
5155 | vty_out(vty, " Last helper exit reason: %s.\n\n", | |
d05d5280 MS |
5156 | ospf_exit_reason2str( |
5157 | nbr->gr_helper_info.helper_exit_reason)); | |
abd5b8c7 | 5158 | else |
5159 | vty_out(vty, "\n"); | |
5160 | } else { | |
5161 | json_object_string_add(json_neigh, "grHelperStatus", | |
5162 | OSPF_GR_IS_ACTIVE_HELPER(nbr) ? | |
5163 | "Inprogress" | |
5164 | : "None"); | |
5165 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5166 | json_object_int_add( | |
5167 | json_neigh, "graceInterval", | |
5168 | nbr->gr_helper_info.recvd_grace_period); | |
5169 | json_object_string_add( | |
5170 | json_neigh, "grRestartReason", | |
d05d5280 MS |
5171 | ospf_restart_reason2str( |
5172 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5173 | } |
5174 | ||
5175 | if (nbr->gr_helper_info.rejected_reason | |
5176 | != OSPF_HELPER_REJECTED_NONE) | |
5177 | json_object_string_add( | |
5178 | json_neigh, "helperRejectReason", | |
d05d5280 MS |
5179 | ospf_rejected_reason2str( |
5180 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5181 | |
5182 | if (nbr->gr_helper_info.helper_exit_reason | |
5183 | != OSPF_GR_HELPER_EXIT_NONE) | |
5184 | json_object_string_add( | |
5185 | json_neigh, "helperExitReason", | |
d05d5280 MS |
5186 | ospf_exit_reason2str( |
5187 | nbr->gr_helper_info | |
5188 | .helper_exit_reason)); | |
abd5b8c7 | 5189 | } |
5190 | ||
cb0b2ac6 CS |
5191 | ospf_bfd_show_info(vty, nbr->bfd_info, json_neigh, use_json, 0); |
5192 | ||
5193 | if (use_json) | |
5194 | json_object_array_add(json_neigh_array, json_neigh); | |
d62a17ae | 5195 | |
d62a17ae | 5196 | } |
5197 | ||
5198 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5199 | struct in_addr *router_id, |
9f049418 | 5200 | bool use_json, uint8_t use_vrf) |
d62a17ae | 5201 | { |
5202 | struct listnode *node; | |
5203 | struct ospf_neighbor *nbr; | |
5204 | struct ospf_interface *oi; | |
d62a17ae | 5205 | json_object *json = NULL; |
5206 | ||
5207 | if (use_json) | |
5208 | json = json_object_new_object(); | |
5209 | ||
5210 | if (ospf->instance) { | |
5211 | if (use_json) | |
5212 | json_object_int_add(json, "ospfInstance", | |
5213 | ospf->instance); | |
5214 | else | |
5215 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5216 | } | |
5217 | ||
b1c3ae8c | 5218 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5219 | |
d62a17ae | 5220 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5221 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
cb0b2ac6 CS |
5222 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5223 | json, use_json); | |
d62a17ae | 5224 | } |
5225 | } | |
5226 | ||
5227 | if (use_json) { | |
9d303b37 DL |
5228 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5229 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5230 | json_object_free(json); |
5231 | } else | |
5232 | vty_out(vty, "\n"); | |
5233 | ||
5234 | return CMD_SUCCESS; | |
718e3744 | 5235 | } |
5236 | ||
986b87cb | 5237 | DEFPY (show_ip_ospf_neighbor_id, |
7c8ff89e | 5238 | show_ip_ospf_neighbor_id_cmd, |
986b87cb | 5239 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", |
718e3744 | 5240 | SHOW_STR |
5241 | IP_STR | |
5242 | "OSPF information\n" | |
5243 | "Neighbor list\n" | |
3ac237f8 | 5244 | "Neighbor ID\n" |
9973d184 | 5245 | JSON_STR) |
718e3744 | 5246 | { |
d62a17ae | 5247 | struct ospf *ospf; |
986b87cb | 5248 | struct listnode *node; |
b5a8894d | 5249 | int ret = CMD_SUCCESS; |
7c8ff89e | 5250 | |
b5a8894d CS |
5251 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5252 | if (!ospf->oi_running) | |
5253 | continue; | |
986b87cb RW |
5254 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
5255 | !!json, 0); | |
b5a8894d | 5256 | } |
7c8ff89e | 5257 | |
b5a8894d | 5258 | return ret; |
7c8ff89e DS |
5259 | } |
5260 | ||
986b87cb | 5261 | DEFPY (show_ip_ospf_instance_neighbor_id, |
7c8ff89e | 5262 | show_ip_ospf_instance_neighbor_id_cmd, |
986b87cb | 5263 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", |
7c8ff89e DS |
5264 | SHOW_STR |
5265 | IP_STR | |
5266 | "OSPF information\n" | |
5267 | "Instance ID\n" | |
5268 | "Neighbor list\n" | |
3ac237f8 | 5269 | "Neighbor ID\n" |
9973d184 | 5270 | JSON_STR) |
7c8ff89e | 5271 | { |
d62a17ae | 5272 | struct ospf *ospf; |
7c8ff89e | 5273 | |
ac28e4ec CS |
5274 | ospf = ospf_lookup_instance(instance); |
5275 | if (ospf == NULL) | |
5276 | return CMD_NOT_MY_INSTANCE; | |
5277 | ||
5278 | if (!ospf->oi_running) | |
d62a17ae | 5279 | return CMD_SUCCESS; |
7c8ff89e | 5280 | |
986b87cb RW |
5281 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, |
5282 | 0); | |
7c8ff89e DS |
5283 | } |
5284 | ||
d62a17ae | 5285 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5286 | struct ospf *ospf, | |
9f049418 | 5287 | json_object *json, bool use_json, |
d7c0a89a | 5288 | uint8_t use_vrf) |
d62a17ae | 5289 | { |
5290 | struct ospf_interface *oi; | |
5291 | struct listnode *node; | |
b1c3ae8c | 5292 | json_object *json_vrf = NULL; |
cb0b2ac6 | 5293 | json_object *json_nbr_sub = NULL; |
d62a17ae | 5294 | |
b1c3ae8c CS |
5295 | if (use_json) { |
5296 | if (use_vrf) | |
5297 | json_vrf = json_object_new_object(); | |
5298 | else | |
5299 | json_vrf = json; | |
cb0b2ac6 CS |
5300 | |
5301 | json_nbr_sub = json_object_new_object(); | |
b1c3ae8c | 5302 | } |
cb0b2ac6 | 5303 | |
d62a17ae | 5304 | if (ospf->instance) { |
5305 | if (use_json) | |
cb0b2ac6 | 5306 | json_object_int_add(json, "ospfInstance", |
d62a17ae | 5307 | ospf->instance); |
5308 | else | |
5309 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5310 | } | |
5311 | ||
b1c3ae8c | 5312 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5313 | |
d62a17ae | 5314 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5315 | struct route_node *rn; | |
cb0b2ac6 | 5316 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5317 | |
5318 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5319 | if ((nbr = rn->info)) { | |
5320 | if (nbr != oi->nbr_self) { | |
5321 | if (nbr->state != NSM_Down) { | |
5322 | show_ip_ospf_neighbor_detail_sub( | |
cb0b2ac6 CS |
5323 | vty, oi, nbr, prev_nbr, |
5324 | json_nbr_sub, use_json); | |
d62a17ae | 5325 | } |
5326 | } | |
cb0b2ac6 | 5327 | prev_nbr = nbr; |
d62a17ae | 5328 | } |
5329 | } | |
5330 | } | |
5331 | ||
5332 | if (use_json) { | |
cb0b2ac6 CS |
5333 | json_object_object_add(json_vrf, "neighbors", |
5334 | json_nbr_sub); | |
b1c3ae8c CS |
5335 | if (use_vrf) { |
5336 | if (ospf->vrf_id == VRF_DEFAULT) | |
5337 | json_object_object_add(json, "default", | |
5338 | json_vrf); | |
5339 | else | |
5340 | json_object_object_add(json, ospf->name, | |
5341 | json_vrf); | |
5342 | } | |
d62a17ae | 5343 | } else |
5344 | vty_out(vty, "\n"); | |
5345 | ||
5346 | return CMD_SUCCESS; | |
718e3744 | 5347 | } |
5348 | ||
7c8ff89e DS |
5349 | DEFUN (show_ip_ospf_neighbor_detail, |
5350 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5351 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5352 | SHOW_STR |
5353 | IP_STR | |
5354 | "OSPF information\n" | |
b5a8894d CS |
5355 | VRF_CMD_HELP_STR |
5356 | "All VRFs\n" | |
718e3744 | 5357 | "Neighbor list\n" |
3ac237f8 | 5358 | "detail of all neighbors\n" |
9973d184 | 5359 | JSON_STR) |
718e3744 | 5360 | { |
d62a17ae | 5361 | struct ospf *ospf; |
9f049418 | 5362 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5363 | struct listnode *node = NULL; |
5364 | char *vrf_name = NULL; | |
2951a7a4 | 5365 | bool all_vrf = false; |
b5a8894d CS |
5366 | int ret = CMD_SUCCESS; |
5367 | int inst = 0; | |
5368 | int idx_vrf = 0; | |
d7c0a89a | 5369 | uint8_t use_vrf = 0; |
b1c3ae8c | 5370 | json_object *json = NULL; |
7c8ff89e | 5371 | |
43b8d1d8 | 5372 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5373 | |
b1c3ae8c CS |
5374 | if (uj) |
5375 | json = json_object_new_object(); | |
5376 | ||
b5a8894d CS |
5377 | /* vrf input is provided could be all or specific vrf*/ |
5378 | if (vrf_name) { | |
b1c3ae8c | 5379 | use_vrf = 1; |
b5a8894d CS |
5380 | if (all_vrf) { |
5381 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5382 | if (!ospf->oi_running) | |
5383 | continue; | |
996c9314 LB |
5384 | ret = show_ip_ospf_neighbor_detail_common( |
5385 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
5386 | } |
5387 | if (uj) { | |
5388 | vty_out(vty, "%s\n", | |
996c9314 LB |
5389 | json_object_to_json_string_ext( |
5390 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 5391 | json_object_free(json); |
b5a8894d | 5392 | } |
b1c3ae8c | 5393 | |
b5a8894d CS |
5394 | return ret; |
5395 | } | |
5396 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5397 | if (ospf == NULL || !ospf->oi_running) { |
5398 | if (uj) | |
5399 | json_object_free(json); | |
b5a8894d | 5400 | return CMD_SUCCESS; |
b1c3ae8c | 5401 | } |
b5a8894d CS |
5402 | } else { |
5403 | /* Display default ospf (instance 0) info */ | |
5404 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5405 | if (ospf == NULL || !ospf->oi_running) { |
5406 | if (uj) | |
5407 | json_object_free(json); | |
b5a8894d | 5408 | return CMD_SUCCESS; |
b1c3ae8c | 5409 | } |
b5a8894d CS |
5410 | } |
5411 | ||
b1c3ae8c CS |
5412 | if (ospf) { |
5413 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5414 | use_vrf); | |
5415 | if (uj) { | |
5416 | vty_out(vty, "%s\n", | |
996c9314 LB |
5417 | json_object_to_json_string_ext( |
5418 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5419 | } |
5420 | } | |
5421 | ||
5422 | if (uj) | |
5423 | json_object_free(json); | |
b5a8894d CS |
5424 | |
5425 | return ret; | |
7c8ff89e DS |
5426 | } |
5427 | ||
5428 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5429 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5430 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5431 | SHOW_STR |
5432 | IP_STR | |
5433 | "OSPF information\n" | |
5434 | "Instance ID\n" | |
5435 | "Neighbor list\n" | |
3ac237f8 | 5436 | "detail of all neighbors\n" |
9973d184 | 5437 | JSON_STR) |
7c8ff89e | 5438 | { |
d62a17ae | 5439 | int idx_number = 3; |
5440 | struct ospf *ospf; | |
d7c0a89a | 5441 | unsigned short instance = 0; |
9f049418 | 5442 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5443 | json_object *json = NULL; |
5444 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5445 | |
d62a17ae | 5446 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5447 | ospf = ospf_lookup_instance(instance); |
5448 | if (ospf == NULL) | |
5449 | return CMD_NOT_MY_INSTANCE; | |
5450 | ||
5451 | if (!ospf->oi_running) | |
d62a17ae | 5452 | return CMD_SUCCESS; |
7c8ff89e | 5453 | |
b1c3ae8c CS |
5454 | if (uj) |
5455 | json = json_object_new_object(); | |
5456 | ||
5457 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5458 | ||
5459 | if (uj) { | |
5460 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5461 | json, JSON_C_TO_STRING_PRETTY)); | |
5462 | json_object_free(json); | |
5463 | } | |
5464 | ||
5465 | return ret; | |
7c8ff89e DS |
5466 | } |
5467 | ||
d62a17ae | 5468 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5469 | struct ospf *ospf, | |
b1c3ae8c | 5470 | json_object *json, |
9f049418 | 5471 | bool use_json, |
d7c0a89a | 5472 | uint8_t use_vrf) |
d62a17ae | 5473 | { |
5474 | struct listnode *node; | |
5475 | struct ospf_interface *oi; | |
b1c3ae8c | 5476 | json_object *json_vrf = NULL; |
718e3744 | 5477 | |
b1c3ae8c CS |
5478 | if (use_json) { |
5479 | if (use_vrf) | |
5480 | json_vrf = json_object_new_object(); | |
5481 | else | |
5482 | json_vrf = json; | |
5483 | } | |
d62a17ae | 5484 | |
5485 | if (ospf->instance) { | |
5486 | if (use_json) | |
5487 | json_object_int_add(json, "ospfInstance", | |
5488 | ospf->instance); | |
5489 | else | |
5490 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5491 | } | |
5492 | ||
b1c3ae8c | 5493 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5494 | |
d62a17ae | 5495 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5496 | struct route_node *rn; | |
cb0b2ac6 | 5497 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5498 | struct ospf_nbr_nbma *nbr_nbma; |
5499 | ||
cb0b2ac6 CS |
5500 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5501 | if ((nbr = rn->info)) { | |
d62a17ae | 5502 | if (nbr != oi->nbr_self) |
5503 | if (nbr->state != NSM_Down) | |
5504 | show_ip_ospf_neighbor_detail_sub( | |
5505 | vty, oi, rn->info, | |
cb0b2ac6 | 5506 | prev_nbr, |
b1c3ae8c | 5507 | json_vrf, use_json); |
cb0b2ac6 CS |
5508 | prev_nbr = nbr; |
5509 | } | |
5510 | } | |
d62a17ae | 5511 | |
5512 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5513 | struct listnode *nd; | |
5514 | ||
5515 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5516 | if (nbr_nbma->nbr == NULL | |
5517 | || nbr_nbma->nbr->state == NSM_Down) | |
5518 | show_ip_ospf_nbr_nbma_detail_sub( | |
5519 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5520 | json_vrf); |
d62a17ae | 5521 | } |
5522 | } | |
5523 | } | |
5524 | ||
5525 | if (use_json) { | |
b1c3ae8c CS |
5526 | if (use_vrf) { |
5527 | if (ospf->vrf_id == VRF_DEFAULT) | |
5528 | json_object_object_add(json, "default", | |
5529 | json_vrf); | |
5530 | else | |
5531 | json_object_object_add(json, ospf->name, | |
5532 | json_vrf); | |
5533 | } | |
d62a17ae | 5534 | } else { |
5535 | vty_out(vty, "\n"); | |
5536 | } | |
5537 | ||
5538 | return CMD_SUCCESS; | |
718e3744 | 5539 | } |
5540 | ||
7c8ff89e DS |
5541 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5542 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5543 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5544 | SHOW_STR |
5545 | IP_STR | |
5546 | "OSPF information\n" | |
b5a8894d CS |
5547 | VRF_CMD_HELP_STR |
5548 | "All VRFs\n" | |
718e3744 | 5549 | "Neighbor list\n" |
7c8ff89e | 5550 | "detail of all neighbors\n" |
3ac237f8 | 5551 | "include down status neighbor\n" |
9973d184 | 5552 | JSON_STR) |
718e3744 | 5553 | { |
d62a17ae | 5554 | struct ospf *ospf; |
9f049418 | 5555 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5556 | struct listnode *node = NULL; |
5557 | char *vrf_name = NULL; | |
2951a7a4 | 5558 | bool all_vrf = false; |
b5a8894d CS |
5559 | int ret = CMD_SUCCESS; |
5560 | int inst = 0; | |
5561 | int idx_vrf = 0; | |
d7c0a89a | 5562 | uint8_t use_vrf = 0; |
b1c3ae8c | 5563 | json_object *json = NULL; |
7c8ff89e | 5564 | |
43b8d1d8 | 5565 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5566 | |
b1c3ae8c CS |
5567 | if (uj) |
5568 | json = json_object_new_object(); | |
5569 | ||
b5a8894d CS |
5570 | /* vrf input is provided could be all or specific vrf*/ |
5571 | if (vrf_name) { | |
b1c3ae8c | 5572 | use_vrf = 1; |
b5a8894d CS |
5573 | if (all_vrf) { |
5574 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5575 | if (!ospf->oi_running) | |
5576 | continue; | |
996c9314 LB |
5577 | ret = show_ip_ospf_neighbor_detail_all_common( |
5578 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5579 | } |
b1c3ae8c CS |
5580 | |
5581 | if (uj) { | |
5582 | vty_out(vty, "%s\n", | |
996c9314 LB |
5583 | json_object_to_json_string_ext( |
5584 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5585 | json_object_free(json); |
5586 | } | |
5587 | ||
b5a8894d CS |
5588 | return ret; |
5589 | } | |
5590 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5591 | if (ospf == NULL || !ospf->oi_running) { |
5592 | if (uj) | |
5593 | json_object_free(json); | |
b5a8894d | 5594 | return CMD_SUCCESS; |
b1c3ae8c | 5595 | } |
b5a8894d CS |
5596 | } else { |
5597 | /* Display default ospf (instance 0) info */ | |
5598 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5599 | if (ospf == NULL || !ospf->oi_running) { |
5600 | if (uj) | |
5601 | json_object_free(json); | |
b5a8894d | 5602 | return CMD_SUCCESS; |
b1c3ae8c | 5603 | } |
b5a8894d CS |
5604 | } |
5605 | ||
b1c3ae8c CS |
5606 | if (ospf) { |
5607 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5608 | uj, use_vrf); | |
5609 | if (uj) { | |
5610 | vty_out(vty, "%s\n", | |
996c9314 LB |
5611 | json_object_to_json_string_ext( |
5612 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5613 | } |
5614 | } | |
5615 | ||
5616 | if (uj) | |
5617 | json_object_free(json); | |
b5a8894d CS |
5618 | |
5619 | return ret; | |
7c8ff89e DS |
5620 | } |
5621 | ||
5622 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5623 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5624 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5625 | SHOW_STR |
5626 | IP_STR | |
5627 | "OSPF information\n" | |
5628 | "Instance ID\n" | |
5629 | "Neighbor list\n" | |
5630 | "detail of all neighbors\n" | |
3ac237f8 | 5631 | "include down status neighbor\n" |
9973d184 | 5632 | JSON_STR) |
7c8ff89e | 5633 | { |
d62a17ae | 5634 | int idx_number = 3; |
5635 | struct ospf *ospf; | |
d7c0a89a | 5636 | unsigned short instance = 0; |
9f049418 | 5637 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5638 | json_object *json = NULL; |
5639 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5640 | |
d62a17ae | 5641 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5642 | ospf = ospf_lookup_instance(instance); |
5643 | if (ospf == NULL) | |
5644 | return CMD_NOT_MY_INSTANCE; | |
5645 | ||
5646 | if (!ospf->oi_running) | |
d62a17ae | 5647 | return CMD_SUCCESS; |
7c8ff89e | 5648 | |
b1c3ae8c CS |
5649 | if (uj) |
5650 | json = json_object_new_object(); | |
5651 | ||
5652 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5653 | ||
5654 | if (uj) { | |
996c9314 LB |
5655 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5656 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5657 | json_object_free(json); |
5658 | } | |
5659 | ||
5660 | return ret; | |
7c8ff89e DS |
5661 | } |
5662 | ||
d62a17ae | 5663 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5664 | struct ospf *ospf, | |
5665 | int arg_base, | |
5666 | struct cmd_token **argv, | |
9f049418 | 5667 | bool use_json) |
d62a17ae | 5668 | { |
5669 | struct ospf_interface *oi; | |
5670 | struct interface *ifp; | |
5671 | struct route_node *rn, *nrn; | |
5672 | struct ospf_neighbor *nbr; | |
5673 | json_object *json = NULL; | |
718e3744 | 5674 | |
d62a17ae | 5675 | if (use_json) |
5676 | json = json_object_new_object(); | |
5677 | ||
5678 | if (ospf->instance) { | |
5679 | if (use_json) | |
5680 | json_object_int_add(json, "ospfInstance", | |
5681 | ospf->instance); | |
5682 | else | |
5683 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5684 | } | |
5685 | ||
a36898e7 | 5686 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5687 | if (!ifp) { |
5688 | if (!use_json) | |
5689 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5690 | else { |
5691 | vty_out(vty, "{}\n"); | |
5692 | json_object_free(json); | |
5693 | } | |
d62a17ae | 5694 | return CMD_WARNING; |
5695 | } | |
5696 | ||
5697 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5698 | if ((oi = rn->info)) { | |
5699 | for (nrn = route_top(oi->nbrs); nrn; | |
5700 | nrn = route_next(nrn)) { | |
5701 | if ((nbr = nrn->info)) { | |
5702 | if (nbr != oi->nbr_self) { | |
5703 | if (nbr->state != NSM_Down) | |
5704 | show_ip_ospf_neighbor_detail_sub( | |
5705 | vty, oi, nbr, | |
cb0b2ac6 | 5706 | NULL, |
b1c3ae8c | 5707 | json, use_json); |
d62a17ae | 5708 | } |
5709 | } | |
5710 | } | |
5711 | } | |
5712 | } | |
5713 | ||
5714 | if (use_json) { | |
9d303b37 DL |
5715 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5716 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5717 | json_object_free(json); |
5718 | } else | |
5719 | vty_out(vty, "\n"); | |
5720 | ||
5721 | return CMD_SUCCESS; | |
718e3744 | 5722 | } |
5723 | ||
7c8ff89e DS |
5724 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5725 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5726 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5727 | SHOW_STR |
5728 | IP_STR | |
5729 | "OSPF information\n" | |
5730 | "Neighbor list\n" | |
5731 | "Interface name\n" | |
3ac237f8 | 5732 | "detail of all neighbors\n" |
9973d184 | 5733 | JSON_STR) |
7c8ff89e | 5734 | { |
d62a17ae | 5735 | struct ospf *ospf; |
9f049418 | 5736 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5737 | struct listnode *node = NULL; |
5738 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5739 | bool ospf_output = false; |
7c8ff89e | 5740 | |
b5a8894d CS |
5741 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5742 | if (!ospf->oi_running) | |
5743 | continue; | |
2951a7a4 | 5744 | ospf_output = true; |
cb0b2ac6 | 5745 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, |
b5a8894d CS |
5746 | argv, uj); |
5747 | } | |
7c8ff89e | 5748 | |
9f049418 DS |
5749 | if (!ospf_output) |
5750 | vty_out(vty, "%% OSPF instance not found\n"); | |
5751 | ||
b5a8894d | 5752 | return ret; |
7c8ff89e DS |
5753 | } |
5754 | ||
5755 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5756 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5757 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5758 | SHOW_STR |
5759 | IP_STR | |
5760 | "OSPF information\n" | |
5761 | "Instance ID\n" | |
5762 | "Neighbor list\n" | |
5763 | "Interface name\n" | |
3ac237f8 | 5764 | "detail of all neighbors\n" |
9973d184 | 5765 | JSON_STR) |
7c8ff89e | 5766 | { |
d62a17ae | 5767 | int idx_number = 3; |
b4e84315 | 5768 | int idx_ifname = 5; |
d62a17ae | 5769 | struct ospf *ospf; |
d7c0a89a | 5770 | unsigned short instance = 0; |
9f049418 | 5771 | bool uj = use_json(argc, argv); |
7c8ff89e | 5772 | |
d62a17ae | 5773 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5774 | ospf = ospf_lookup_instance(instance); |
5775 | if (ospf == NULL) | |
5776 | return CMD_NOT_MY_INSTANCE; | |
5777 | ||
5778 | if (!ospf->oi_running) | |
d62a17ae | 5779 | return CMD_SUCCESS; |
7c8ff89e | 5780 | |
996c9314 LB |
5781 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5782 | argv, uj); | |
7c8ff89e | 5783 | } |
6b0655a2 | 5784 | |
718e3744 | 5785 | /* Show functions */ |
f328dc60 | 5786 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self, |
5787 | json_object *json_lsa) | |
d62a17ae | 5788 | { |
5789 | struct router_lsa *rl; | |
5790 | struct summary_lsa *sl; | |
5791 | struct as_external_lsa *asel; | |
5792 | struct prefix_ipv4 p; | |
f328dc60 | 5793 | char buf[PREFIX2STR_BUFFER]; |
d62a17ae | 5794 | |
5795 | if (lsa != NULL) | |
5796 | /* If self option is set, check LSA self flag. */ | |
5797 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
f328dc60 | 5798 | |
5799 | if (!json_lsa) { | |
5800 | /* LSA common part show. */ | |
5801 | vty_out(vty, "%-15pI4", | |
5802 | &lsa->data->id); | |
5803 | vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", | |
5804 | inet_ntoa(lsa->data->adv_router), | |
5805 | LS_AGE(lsa), | |
5806 | (unsigned long)ntohl( | |
5807 | lsa->data->ls_seqnum), | |
5808 | ntohs(lsa->data->checksum)); | |
5809 | } else { | |
5810 | char seqnum[10]; | |
5811 | char checksum[10]; | |
5812 | ||
5813 | snprintf(seqnum, sizeof(seqnum), "%x", | |
5814 | ntohl(lsa->data->ls_seqnum)); | |
5815 | snprintf(checksum, sizeof(checksum), "%x", | |
5816 | ntohs(lsa->data->checksum)); | |
5817 | json_object_string_add( | |
5818 | json_lsa, "lsId", | |
5819 | inet_ntoa(lsa->data->id)); | |
5820 | json_object_string_add( | |
5821 | json_lsa, "advertisedRouter", | |
5822 | inet_ntoa(lsa->data->adv_router)); | |
5823 | json_object_int_add(json_lsa, "lsaAge", | |
5824 | LS_AGE(lsa)); | |
5825 | json_object_string_add( | |
5826 | json_lsa, "sequenceNumber", seqnum); | |
5827 | json_object_string_add(json_lsa, "checksum", | |
5828 | checksum); | |
5829 | } | |
5830 | ||
d62a17ae | 5831 | /* LSA specific part show. */ |
5832 | switch (lsa->data->type) { | |
5833 | case OSPF_ROUTER_LSA: | |
5834 | rl = (struct router_lsa *)lsa->data; | |
f328dc60 | 5835 | |
5836 | if (!json_lsa) | |
5837 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5838 | else | |
5839 | json_object_int_add(json_lsa, | |
5840 | "numOfRouterLinks", | |
5841 | ntohs(rl->links)); | |
d62a17ae | 5842 | break; |
5843 | case OSPF_SUMMARY_LSA: | |
5844 | sl = (struct summary_lsa *)lsa->data; | |
5845 | ||
5846 | p.family = AF_INET; | |
5847 | p.prefix = sl->header.id; | |
5848 | p.prefixlen = ip_masklen(sl->mask); | |
5849 | apply_mask_ipv4(&p); | |
5850 | ||
f328dc60 | 5851 | if (!json_lsa) |
5852 | vty_out(vty, " %pFX", &p); | |
5853 | else { | |
5854 | prefix2str(&p, buf, sizeof(buf)); | |
5855 | json_object_string_add(json_lsa, | |
5856 | "summaryAddress", | |
5857 | buf); | |
5858 | } | |
d62a17ae | 5859 | break; |
5860 | case OSPF_AS_EXTERNAL_LSA: | |
5861 | case OSPF_AS_NSSA_LSA: | |
5862 | asel = (struct as_external_lsa *)lsa->data; | |
5863 | ||
5864 | p.family = AF_INET; | |
5865 | p.prefix = asel->header.id; | |
5866 | p.prefixlen = ip_masklen(asel->mask); | |
5867 | apply_mask_ipv4(&p); | |
5868 | ||
f328dc60 | 5869 | if (!json_lsa) |
5870 | vty_out(vty, " %s %pFX [0x%lx]", | |
5871 | IS_EXTERNAL_METRIC( | |
5872 | asel->e[0].tos) | |
5873 | ? "E2" | |
5874 | : "E1", | |
5875 | &p, | |
5876 | (unsigned long)ntohl( | |
5877 | asel->e[0].route_tag)); | |
5878 | else { | |
5879 | prefix2str(&p, buf, sizeof(buf)); | |
5880 | json_object_string_add( | |
5881 | json_lsa, "metricType", | |
5882 | IS_EXTERNAL_METRIC( | |
5883 | asel->e[0].tos) | |
5884 | ? "E2" | |
5885 | : "E1"); | |
5886 | json_object_string_add(json_lsa, | |
5887 | "route", buf); | |
5888 | json_object_int_add( | |
5889 | json_lsa, "tag", | |
5890 | (unsigned long)ntohl( | |
5891 | asel->e[0].route_tag)); | |
5892 | } | |
d62a17ae | 5893 | break; |
5894 | case OSPF_NETWORK_LSA: | |
5895 | case OSPF_ASBR_SUMMARY_LSA: | |
5896 | case OSPF_OPAQUE_LINK_LSA: | |
5897 | case OSPF_OPAQUE_AREA_LSA: | |
5898 | case OSPF_OPAQUE_AS_LSA: | |
5899 | default: | |
5900 | break; | |
5901 | } | |
f328dc60 | 5902 | |
5903 | if (!json_lsa) | |
5904 | vty_out(vty, "\n"); | |
d62a17ae | 5905 | } |
718e3744 | 5906 | |
d62a17ae | 5907 | return 0; |
5908 | } | |
5909 | ||
2b64873d | 5910 | static const char *const show_database_desc[] = { |
d62a17ae | 5911 | "unknown", |
5912 | "Router Link States", | |
5913 | "Net Link States", | |
5914 | "Summary Link States", | |
5915 | "ASBR-Summary Link States", | |
5916 | "AS External Link States", | |
5917 | "Group Membership LSA", | |
5918 | "NSSA-external Link States", | |
5919 | "Type-8 LSA", | |
5920 | "Link-Local Opaque-LSA", | |
5921 | "Area-Local Opaque-LSA", | |
5922 | "AS-external Opaque-LSA", | |
718e3744 | 5923 | }; |
5924 | ||
f328dc60 | 5925 | static const char * const show_database_desc_json[] = { |
5926 | "unknown", | |
5927 | "routerLinkStates", | |
5928 | "networkLinkStates", | |
5929 | "summaryLinkStates", | |
5930 | "asbrSummaryLinkStates", | |
5931 | "asExternalLinkStates", | |
5932 | "groupMembershipLsa", | |
5933 | "nssaExternalLinkStates", | |
5934 | "type8Lsa", | |
5935 | "linkLocalOpaqueLsa", | |
5936 | "areaLocalOpaqueLsa", | |
5937 | "asExternalOpaqueLsa", | |
5938 | }; | |
5939 | ||
2b64873d | 5940 | static const char *const show_database_header[] = { |
d62a17ae | 5941 | "", |
5942 | "Link ID ADV Router Age Seq# CkSum Link count", | |
5943 | "Link ID ADV Router Age Seq# CkSum", | |
5944 | "Link ID ADV Router Age Seq# CkSum Route", | |
5945 | "Link ID ADV Router Age Seq# CkSum", | |
5946 | "Link ID ADV Router Age Seq# CkSum Route", | |
5947 | " --- header for Group Member ----", | |
5948 | "Link ID ADV Router Age Seq# CkSum Route", | |
5949 | " --- type-8 ---", | |
5950 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5951 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5952 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 5953 | }; |
5954 | ||
f328dc60 | 5955 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa, |
5956 | json_object *json) | |
d62a17ae | 5957 | { |
5958 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
5959 | ||
f328dc60 | 5960 | if (!json) { |
5961 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
5962 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
5963 | ospf_options_dump(lsa->data->options)); | |
5964 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
5965 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) | |
5966 | ? "(Translated from Type-7)" | |
5967 | : "")); | |
5968 | ||
5969 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
5970 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
5971 | ||
5972 | if (rlsa->flags) | |
5973 | vty_out(vty, " :%s%s%s%s", | |
5974 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" | |
5975 | : "", | |
5976 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" | |
5977 | : "", | |
5978 | IS_ROUTER_LSA_VIRTUAL(rlsa) | |
5979 | ? " VL-endpoint" | |
5980 | : "", | |
5981 | IS_ROUTER_LSA_SHORTCUT(rlsa) | |
5982 | ? " Shortcut" | |
5983 | : ""); | |
d62a17ae | 5984 | |
f328dc60 | 5985 | vty_out(vty, "\n"); |
5986 | } | |
5987 | vty_out(vty, " LS Type: %s\n", | |
5988 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
5989 | vty_out(vty, " Link State ID: %pI4 %s\n", | |
5990 | &lsa->data->id, | |
5991 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, | |
5992 | NULL)); | |
5993 | vty_out(vty, " Advertising Router: %pI4\n", | |
5994 | &lsa->data->adv_router); | |
5995 | vty_out(vty, " LS Seq Number: %08lx\n", | |
5996 | (unsigned long)ntohl(lsa->data->ls_seqnum)); | |
5997 | vty_out(vty, " Checksum: 0x%04x\n", | |
5998 | ntohs(lsa->data->checksum)); | |
5999 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
6000 | } else { | |
6001 | char seqnum[10]; | |
6002 | char checksum[10]; | |
6003 | ||
6004 | snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum)); | |
6005 | snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum)); | |
6006 | ||
6007 | json_object_int_add(json, "lsaAge", LS_AGE(lsa)); | |
6008 | json_object_string_add(json, "options", | |
6009 | ospf_options_dump(lsa->data->options)); | |
6010 | json_object_int_add(json, "lsaFlags", lsa->flags); | |
6011 | ||
6012 | if (lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6013 | json_object_boolean_true_add(json, | |
6014 | "translatedFromType7"); | |
6015 | ||
6016 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6017 | json_object_int_add(json, "flags", rlsa->flags); | |
6018 | ||
6019 | if (rlsa->flags) { | |
6020 | if (IS_ROUTER_LSA_BORDER(rlsa)) | |
6021 | json_object_boolean_true_add(json, | |
6022 | "abr"); | |
6023 | if (IS_ROUTER_LSA_EXTERNAL(rlsa)) | |
6024 | json_object_boolean_true_add(json, | |
6025 | "asbr"); | |
6026 | if (IS_ROUTER_LSA_VIRTUAL(rlsa)) | |
6027 | json_object_boolean_true_add( | |
6028 | json, "vlEndpoint"); | |
6029 | if (IS_ROUTER_LSA_SHORTCUT(rlsa)) | |
6030 | json_object_boolean_true_add( | |
6031 | json, "shortcut"); | |
6032 | } | |
6033 | } | |
6034 | ||
6035 | json_object_string_add( | |
6036 | json, "lsaType", | |
6037 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6038 | json_object_string_add(json, "linkStateId", | |
6039 | inet_ntoa(lsa->data->id)); | |
6040 | json_object_string_add(json, "advertisingRouter", | |
6041 | inet_ntoa(lsa->data->adv_router)); | |
6042 | json_object_string_add(json, "lsaSeqNumber", seqnum); | |
6043 | json_object_string_add(json, "checksum", checksum); | |
6044 | json_object_int_add(json, "length", ntohs(lsa->data->length)); | |
d62a17ae | 6045 | } |
d62a17ae | 6046 | } |
6047 | ||
2b64873d | 6048 | static const char *const link_type_desc[] = { |
d62a17ae | 6049 | "(null)", |
6050 | "another Router (point-to-point)", | |
6051 | "a Transit Network", | |
6052 | "Stub Network", | |
6053 | "a Virtual Link", | |
718e3744 | 6054 | }; |
6055 | ||
2b64873d | 6056 | static const char *const link_id_desc[] = { |
d62a17ae | 6057 | "(null)", "Neighboring Router ID", "Designated Router address", |
6058 | "Net", "Neighboring Router ID", | |
718e3744 | 6059 | }; |
6060 | ||
2b64873d | 6061 | static const char *const link_data_desc[] = { |
d62a17ae | 6062 | "(null)", "Router Interface address", "Router Interface address", |
6063 | "Network Mask", "Router Interface address", | |
718e3744 | 6064 | }; |
6065 | ||
f328dc60 | 6066 | static const char *const link_id_desc_json[] = { |
6067 | "null", "neighborRouterId", "designatedRouterAddress", | |
6068 | "networkAddress", "neighborRouterId", | |
6069 | }; | |
6070 | ||
6071 | static const char *const link_data_desc_json[] = { | |
6072 | "null", "routerInterfaceAddress", "routerInterfaceAddress", | |
6073 | "networkMask", "routerInterfaceAddress", | |
6074 | }; | |
6075 | ||
718e3744 | 6076 | /* Show router-LSA each Link information. */ |
d62a17ae | 6077 | static void show_ip_ospf_database_router_links(struct vty *vty, |
f328dc60 | 6078 | struct router_lsa *rl, |
6079 | json_object *json) | |
d62a17ae | 6080 | { |
6081 | int len, type; | |
f328dc60 | 6082 | unsigned short i; |
6083 | json_object *json_links = NULL; | |
6084 | json_object *json_link = NULL; | |
6085 | int metric = 0; | |
6086 | ||
6087 | if (json) | |
6088 | json_links = json_object_new_object(); | |
d62a17ae | 6089 | |
6090 | len = ntohs(rl->header.length) - 4; | |
6091 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
6092 | type = rl->link[i].type; | |
6093 | ||
f328dc60 | 6094 | if (json) { |
6095 | char link[16]; | |
6096 | ||
6097 | snprintf(link, sizeof(link), "link%u", i); | |
6098 | json_link = json_object_new_object(); | |
6099 | json_object_string_add(json_link, "linkType", | |
6100 | link_type_desc[type]); | |
6101 | json_object_string_add(json_link, | |
6102 | link_id_desc_json[type], | |
6103 | inet_ntoa(rl->link[i].link_id)); | |
6104 | json_object_string_add( | |
6105 | json_link, link_data_desc_json[type], | |
6106 | inet_ntoa(rl->link[i].link_data)); | |
6107 | json_object_int_add(json_link, "numOfTosMetrics", | |
6108 | metric); | |
6109 | json_object_int_add(json_link, "tos0Metric", | |
6110 | ntohs(rl->link[i].metric)); | |
6111 | json_object_object_add(json_links, link, json_link); | |
6112 | } else { | |
6113 | vty_out(vty, " Link connected to: %s\n", | |
6114 | link_type_desc[type]); | |
6115 | vty_out(vty, " (Link ID) %s: %pI4\n", | |
6116 | link_id_desc[type], | |
6117 | &rl->link[i].link_id); | |
6118 | vty_out(vty, " (Link Data) %s: %pI4\n", | |
6119 | link_data_desc[type], | |
6120 | &rl->link[i].link_data); | |
6121 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
6122 | vty_out(vty, " TOS 0 Metric: %d\n", | |
6123 | ntohs(rl->link[i].metric)); | |
6124 | vty_out(vty, "\n"); | |
6125 | } | |
d62a17ae | 6126 | } |
f328dc60 | 6127 | if (json) |
6128 | json_object_object_add(json, "routerLinks", json_links); | |
718e3744 | 6129 | } |
6130 | ||
6131 | /* Show router-LSA detail information. */ | |
f328dc60 | 6132 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6133 | json_object *json) | |
718e3744 | 6134 | { |
d62a17ae | 6135 | if (lsa != NULL) { |
6136 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 6137 | |
f328dc60 | 6138 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6139 | |
f328dc60 | 6140 | if (!json) |
6141 | vty_out(vty, " Number of Links: %d\n\n", | |
6142 | ntohs(rl->links)); | |
6143 | else | |
6144 | json_object_int_add(json, "numOfLinks", | |
6145 | ntohs(rl->links)); | |
718e3744 | 6146 | |
f328dc60 | 6147 | show_ip_ospf_database_router_links(vty, rl, json); |
6148 | ||
6149 | if (!json) | |
6150 | vty_out(vty, "\n"); | |
d62a17ae | 6151 | } |
6152 | ||
6153 | return 0; | |
718e3744 | 6154 | } |
6155 | ||
6156 | /* Show network-LSA detail information. */ | |
f328dc60 | 6157 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6158 | json_object *json) | |
718e3744 | 6159 | { |
d62a17ae | 6160 | int length, i; |
f328dc60 | 6161 | json_object *json_attached_rt = NULL; |
6162 | json_object *json_router = NULL; | |
6163 | ||
6164 | if (json) | |
6165 | json_attached_rt = json_object_new_object(); | |
718e3744 | 6166 | |
d62a17ae | 6167 | if (lsa != NULL) { |
6168 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
718e3744 | 6169 | |
f328dc60 | 6170 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6171 | |
f328dc60 | 6172 | if (!json) |
6173 | vty_out(vty, " Network Mask: /%d\n", | |
6174 | ip_masklen(nl->mask)); | |
6175 | else | |
6176 | json_object_int_add(json, "networkMask", | |
6177 | ip_masklen(nl->mask)); | |
718e3744 | 6178 | |
d62a17ae | 6179 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; |
718e3744 | 6180 | |
d62a17ae | 6181 | for (i = 0; length > 0; i++, length -= 4) |
f328dc60 | 6182 | if (!json) { |
6183 | vty_out(vty, " Attached Router: %pI4\n", | |
6184 | &nl->routers[i]); | |
6185 | vty_out(vty, "\n"); | |
6186 | } else { | |
6187 | json_router = json_object_new_object(); | |
6188 | json_object_string_add( | |
6189 | json_router, "attachedRouterId", | |
6190 | inet_ntoa(nl->routers[i])); | |
6191 | json_object_object_add( | |
6192 | json_attached_rt, | |
6193 | inet_ntoa(nl->routers[i]), json_router); | |
6194 | } | |
d62a17ae | 6195 | } |
718e3744 | 6196 | |
f328dc60 | 6197 | if (json) |
6198 | json_object_object_add(json, "attchedRouters", | |
6199 | json_attached_rt); | |
6200 | ||
d62a17ae | 6201 | return 0; |
718e3744 | 6202 | } |
6203 | ||
6204 | /* Show summary-LSA detail information. */ | |
f328dc60 | 6205 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6206 | json_object *json) | |
718e3744 | 6207 | { |
d62a17ae | 6208 | if (lsa != NULL) { |
6209 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6210 | |
f328dc60 | 6211 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6212 | |
f328dc60 | 6213 | if (!json) { |
6214 | vty_out(vty, " Network Mask: /%d\n", | |
6215 | ip_masklen(sl->mask)); | |
6216 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6217 | GET_METRIC(sl->metric)); | |
6218 | vty_out(vty, "\n"); | |
6219 | } else { | |
6220 | json_object_int_add(json, "networkMask", | |
6221 | ip_masklen(sl->mask)); | |
6222 | json_object_int_add(json, "tos0Metric", | |
6223 | GET_METRIC(sl->metric)); | |
6224 | } | |
d62a17ae | 6225 | } |
718e3744 | 6226 | |
d62a17ae | 6227 | return 0; |
718e3744 | 6228 | } |
6229 | ||
6230 | /* Show summary-ASBR-LSA detail information. */ | |
f328dc60 | 6231 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6232 | json_object *json) | |
718e3744 | 6233 | { |
d62a17ae | 6234 | if (lsa != NULL) { |
6235 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6236 | |
f328dc60 | 6237 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6238 | |
f328dc60 | 6239 | if (!json) { |
6240 | vty_out(vty, " Network Mask: /%d\n", | |
6241 | ip_masklen(sl->mask)); | |
6242 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6243 | GET_METRIC(sl->metric)); | |
6244 | vty_out(vty, "\n"); | |
6245 | } else { | |
6246 | json_object_int_add(json, "networkMask", | |
6247 | ip_masklen(sl->mask)); | |
6248 | json_object_int_add(json, "tos0Metric", | |
6249 | GET_METRIC(sl->metric)); | |
6250 | } | |
d62a17ae | 6251 | } |
718e3744 | 6252 | |
d62a17ae | 6253 | return 0; |
718e3744 | 6254 | } |
6255 | ||
6256 | /* Show AS-external-LSA detail information. */ | |
f328dc60 | 6257 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6258 | json_object *json) | |
d62a17ae | 6259 | { |
f328dc60 | 6260 | int tos = 0; |
6261 | ||
d62a17ae | 6262 | if (lsa != NULL) { |
6263 | struct as_external_lsa *al = | |
6264 | (struct as_external_lsa *)lsa->data; | |
6265 | ||
f328dc60 | 6266 | show_ip_ospf_database_header(vty, lsa, json); |
6267 | ||
6268 | if (!json) { | |
6269 | vty_out(vty, " Network Mask: /%d\n", | |
6270 | ip_masklen(al->mask)); | |
6271 | vty_out(vty, " Metric Type: %s\n", | |
6272 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6273 | ? "2 (Larger than any link state path)" | |
6274 | : "1"); | |
6275 | vty_out(vty, " TOS: 0\n"); | |
6276 | vty_out(vty, " Metric: %d\n", | |
6277 | GET_METRIC(al->e[0].metric)); | |
6278 | vty_out(vty, " Forward Address: %pI4\n", | |
6279 | &al->e[0].fwd_addr); | |
6280 | vty_out(vty, | |
6281 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6282 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6283 | } else { | |
6284 | json_object_int_add(json, "networkMask", | |
6285 | ip_masklen(al->mask)); | |
6286 | json_object_string_add( | |
6287 | json, "metricType", | |
6288 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6289 | ? "E2 (Larger than any link state path)" | |
6290 | : "E1"); | |
6291 | json_object_int_add(json, "tos", tos); | |
6292 | json_object_int_add(json, "metric", | |
6293 | GET_METRIC(al->e[0].metric)); | |
6294 | json_object_string_add(json, "forwardAddress", | |
6295 | inet_ntoa(al->e[0].fwd_addr)); | |
6296 | json_object_int_add( | |
6297 | json, "externalRouteTag", | |
6298 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6299 | } | |
d62a17ae | 6300 | } |
718e3744 | 6301 | |
d62a17ae | 6302 | return 0; |
718e3744 | 6303 | } |
075e12f5 | 6304 | #if 0 |
4dadc291 | 6305 | static int |
718e3744 | 6306 | show_as_external_lsa_stdvty (struct ospf_lsa *lsa) |
6307 | { | |
6308 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; | |
6309 | ||
6310 | /* show_ip_ospf_database_header (vty, lsa); */ | |
6311 | ||
2a42e285 | 6312 | zlog_debug( " Network Mask: /%d%s", |
718e3744 | 6313 | ip_masklen (al->mask), "\n"); |
2a42e285 | 6314 | zlog_debug( " Metric Type: %s%s", |
718e3744 | 6315 | IS_EXTERNAL_METRIC (al->e[0].tos) ? |
6316 | "2 (Larger than any link state path)" : "1", "\n"); | |
2a42e285 | 6317 | zlog_debug( " TOS: 0%s", "\n"); |
6318 | zlog_debug( " Metric: %d%s", | |
718e3744 | 6319 | GET_METRIC (al->e[0].metric), "\n"); |
96b663a3 MS |
6320 | zlog_debug( " Forward Address: %pI4%s", |
6321 | &al->e[0].fwd_addr, "\n"); | |
718e3744 | 6322 | |
dc9ffce8 CF |
6323 | zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s", |
6324 | (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n"); | |
718e3744 | 6325 | |
6326 | return 0; | |
6327 | } | |
075e12f5 | 6328 | #endif |
718e3744 | 6329 | /* Show AS-NSSA-LSA detail information. */ |
f328dc60 | 6330 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6331 | json_object *json) | |
d62a17ae | 6332 | { |
f328dc60 | 6333 | int tos = 0; |
6334 | ||
d62a17ae | 6335 | if (lsa != NULL) { |
6336 | struct as_external_lsa *al = | |
6337 | (struct as_external_lsa *)lsa->data; | |
6338 | ||
f328dc60 | 6339 | show_ip_ospf_database_header(vty, lsa, json); |
6340 | ||
6341 | if (!json) { | |
6342 | vty_out(vty, " Network Mask: /%d\n", | |
6343 | ip_masklen(al->mask)); | |
6344 | vty_out(vty, " Metric Type: %s\n", | |
6345 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6346 | ? "2 (Larger than any link state path)" | |
6347 | : "1"); | |
6348 | vty_out(vty, " TOS: 0\n"); | |
6349 | vty_out(vty, " Metric: %d\n", | |
6350 | GET_METRIC(al->e[0].metric)); | |
6351 | vty_out(vty, " NSSA: Forward Address: %pI4\n", | |
6352 | &al->e[0].fwd_addr); | |
6353 | vty_out(vty, | |
6354 | " External Route Tag: %" ROUTE_TAG_PRI | |
6355 | "\n\n", | |
6356 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6357 | } else { | |
6358 | json_object_int_add(json, "networkMask", | |
6359 | ip_masklen(al->mask)); | |
6360 | json_object_string_add( | |
6361 | json, "metricType", | |
6362 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6363 | ? "E2 (Larger than any link state path)" | |
6364 | : "E1"); | |
6365 | json_object_int_add(json, "tos", tos); | |
6366 | json_object_int_add(json, "metric", | |
6367 | GET_METRIC(al->e[0].metric)); | |
6368 | json_object_string_add(json, "nssaForwardAddress", | |
6369 | inet_ntoa(al->e[0].fwd_addr)); | |
6370 | json_object_int_add( | |
6371 | json, "externalRouteTag", | |
6372 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6373 | } | |
d62a17ae | 6374 | } |
718e3744 | 6375 | |
d62a17ae | 6376 | return 0; |
718e3744 | 6377 | } |
6378 | ||
f328dc60 | 6379 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa, |
6380 | json_object *json) | |
718e3744 | 6381 | { |
d62a17ae | 6382 | return 0; |
718e3744 | 6383 | } |
6384 | ||
f328dc60 | 6385 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6386 | json_object *json) | |
718e3744 | 6387 | { |
d62a17ae | 6388 | if (lsa != NULL) { |
f328dc60 | 6389 | show_ip_ospf_database_header(vty, lsa, json); |
6390 | show_opaque_info_detail(vty, lsa, json); | |
6391 | if (!json) | |
6392 | vty_out(vty, "\n"); | |
d62a17ae | 6393 | } |
6394 | return 0; | |
6395 | } | |
6396 | ||
f328dc60 | 6397 | int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = { |
d62a17ae | 6398 | NULL, |
6399 | show_router_lsa_detail, | |
6400 | show_network_lsa_detail, | |
6401 | show_summary_lsa_detail, | |
6402 | show_summary_asbr_lsa_detail, | |
6403 | show_as_external_lsa_detail, | |
6404 | show_func_dummy, | |
6405 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6406 | NULL, /* type-8 */ | |
6407 | show_opaque_lsa_detail, | |
6408 | show_opaque_lsa_detail, | |
6409 | show_opaque_lsa_detail, | |
6410 | }; | |
6411 | ||
6412 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6413 | struct in_addr *id, struct in_addr *adv_router) | |
6414 | { | |
6415 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6416 | lp->family = 0; | |
6417 | if (id == NULL) | |
6418 | lp->prefixlen = 0; | |
6419 | else if (adv_router == NULL) { | |
6420 | lp->prefixlen = 32; | |
6421 | lp->id = *id; | |
6422 | } else { | |
6423 | lp->prefixlen = 64; | |
6424 | lp->id = *id; | |
6425 | lp->adv_router = *adv_router; | |
6426 | } | |
718e3744 | 6427 | } |
718e3744 | 6428 | |
d62a17ae | 6429 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
f328dc60 | 6430 | struct in_addr *id, struct in_addr *adv_router, |
6431 | json_object *json) | |
d62a17ae | 6432 | { |
6433 | struct prefix_ls lp; | |
6434 | struct route_node *rn, *start; | |
6435 | struct ospf_lsa *lsa; | |
f328dc60 | 6436 | json_object *json_lsa = NULL; |
718e3744 | 6437 | |
d62a17ae | 6438 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6439 | start = route_node_get(rt, (struct prefix *)&lp); | |
6440 | if (start) { | |
6441 | route_lock_node(start); | |
6442 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6443 | if ((lsa = rn->info)) { | |
f328dc60 | 6444 | if (json) { |
6445 | json_lsa = json_object_new_object(); | |
6446 | json_object_array_add(json, json_lsa); | |
6447 | } | |
6448 | ||
d62a17ae | 6449 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6450 | show_function[lsa->data->type]( |
6451 | vty, lsa, json_lsa); | |
d62a17ae | 6452 | } |
6453 | route_unlock_node(start); | |
6454 | } | |
718e3744 | 6455 | } |
6456 | ||
6457 | /* Show detail LSA information | |
6458 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6459 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
f328dc60 | 6460 | struct in_addr *id, struct in_addr *adv_router, |
6461 | json_object *json) | |
d62a17ae | 6462 | { |
6463 | struct listnode *node; | |
6464 | struct ospf_area *area; | |
f328dc60 | 6465 | json_object *json_lsa_type = NULL; |
6466 | json_object *json_areas = NULL; | |
6467 | json_object *json_lsa_array = NULL; | |
6468 | ||
6469 | if (json) | |
6470 | json_lsa_type = json_object_new_object(); | |
d62a17ae | 6471 | |
6472 | switch (type) { | |
6473 | case OSPF_AS_EXTERNAL_LSA: | |
6474 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6475 | if (!json) |
6476 | vty_out(vty, " %s \n\n", | |
6477 | show_database_desc[type]); | |
6478 | else | |
6479 | json_lsa_array = json_object_new_array(); | |
6480 | ||
6481 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router, | |
6482 | json_lsa_array); | |
6483 | if (json) | |
6484 | json_object_object_add(json, | |
6485 | show_database_desc_json[type], | |
6486 | json_lsa_array); | |
6487 | ||
d62a17ae | 6488 | break; |
6489 | default: | |
f328dc60 | 6490 | if (json) |
6491 | json_areas = json_object_new_object(); | |
6492 | ||
d62a17ae | 6493 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6494 | if (!json) { |
6495 | vty_out(vty, | |
6496 | "\n %s (Area %s)\n\n", | |
6497 | show_database_desc[type], | |
6498 | ospf_area_desc_string(area)); | |
6499 | } else { | |
6500 | json_lsa_array = json_object_new_array(); | |
6501 | json_object_object_add(json_areas, | |
6502 | inet_ntoa(area->area_id), | |
6503 | json_lsa_array); | |
6504 | } | |
6505 | ||
d62a17ae | 6506 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, |
f328dc60 | 6507 | adv_router, json_lsa_array); |
6508 | } | |
6509 | ||
6510 | if (json) { | |
6511 | json_object_object_add(json_lsa_type, "areas", | |
6512 | json_areas); | |
6513 | json_object_object_add(json, | |
6514 | show_database_desc_json[type], | |
6515 | json_lsa_type); | |
d62a17ae | 6516 | } |
6517 | break; | |
718e3744 | 6518 | } |
6519 | } | |
6520 | ||
d62a17ae | 6521 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6522 | struct route_table *rt, | |
f328dc60 | 6523 | struct in_addr *adv_router, |
6524 | json_object *json) | |
d62a17ae | 6525 | { |
6526 | struct route_node *rn; | |
6527 | struct ospf_lsa *lsa; | |
6528 | ||
6529 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
f328dc60 | 6530 | if ((lsa = rn->info)) { |
6531 | json_object *json_lsa = NULL; | |
6532 | ||
d62a17ae | 6533 | if (IPV4_ADDR_SAME(adv_router, |
6534 | &lsa->data->adv_router)) { | |
6535 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6536 | continue; | |
f328dc60 | 6537 | if (json) |
6538 | json_lsa = json_object_new_object(); | |
6539 | ||
d62a17ae | 6540 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6541 | show_function[lsa->data->type]( |
6542 | vty, lsa, json_lsa); | |
6543 | if (json) | |
6544 | json_object_object_add( | |
6545 | json, inet_ntoa(lsa->data->id), | |
6546 | json_lsa); | |
d62a17ae | 6547 | } |
f328dc60 | 6548 | } |
d62a17ae | 6549 | } |
6550 | ||
718e3744 | 6551 | /* Show detail LSA information. */ |
d62a17ae | 6552 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
f328dc60 | 6553 | int type, struct in_addr *adv_router, |
6554 | json_object *json) | |
d62a17ae | 6555 | { |
6556 | struct listnode *node; | |
6557 | struct ospf_area *area; | |
f328dc60 | 6558 | json_object *json_lstype = NULL; |
6559 | json_object *json_area = NULL; | |
6560 | ||
6561 | if (json) | |
6562 | json_lstype = json_object_new_object(); | |
d62a17ae | 6563 | |
6564 | switch (type) { | |
6565 | case OSPF_AS_EXTERNAL_LSA: | |
6566 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6567 | if (!json) |
6568 | vty_out(vty, " %s \n\n", | |
6569 | show_database_desc[type]); | |
6570 | ||
d62a17ae | 6571 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), |
f328dc60 | 6572 | adv_router, json_lstype); |
d62a17ae | 6573 | break; |
6574 | default: | |
f328dc60 | 6575 | |
d62a17ae | 6576 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6577 | if (json) |
6578 | json_area = json_object_new_object(); | |
6579 | else | |
6580 | vty_out(vty, | |
6581 | "\n %s (Area %s)\n\n", | |
6582 | show_database_desc[type], | |
6583 | ospf_area_desc_string(area)); | |
6584 | show_lsa_detail_adv_router_proc(vty, | |
6585 | AREA_LSDB(area, type), | |
6586 | adv_router, json_area); | |
6587 | ||
6588 | if (json) | |
6589 | json_object_object_add(json_lstype, | |
6590 | inet_ntoa(area->area_id), | |
6591 | json_area); | |
d62a17ae | 6592 | } |
6593 | break; | |
6594 | } | |
f328dc60 | 6595 | |
6596 | if (json) | |
6597 | json_object_object_add(json, show_database_desc[type], | |
6598 | json_lstype); | |
d62a17ae | 6599 | } |
6600 | ||
6601 | static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, | |
f328dc60 | 6602 | int self, json_object *json) |
d62a17ae | 6603 | { |
6604 | struct ospf_lsa *lsa; | |
6605 | struct route_node *rn; | |
6606 | struct ospf_area *area; | |
6607 | struct listnode *node; | |
f328dc60 | 6608 | json_object *json_areas = NULL; |
6609 | json_object *json_area = NULL; | |
6610 | json_object *json_lsa = NULL; | |
d62a17ae | 6611 | int type; |
f328dc60 | 6612 | json_object *json_lsa_array = NULL; |
6613 | ||
6614 | if (json) | |
6615 | json_areas = json_object_new_object(); | |
d62a17ae | 6616 | |
6617 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
f328dc60 | 6618 | if (json) |
6619 | json_area = json_object_new_object(); | |
6620 | ||
d62a17ae | 6621 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6622 | switch (type) { | |
6623 | case OSPF_AS_EXTERNAL_LSA: | |
6624 | case OSPF_OPAQUE_AS_LSA: | |
6625 | continue; | |
6626 | default: | |
6627 | break; | |
6628 | } | |
6629 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6630 | || (!self | |
6631 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
d62a17ae | 6632 | |
f328dc60 | 6633 | if (!json) { |
6634 | vty_out(vty, | |
6635 | " %s (Area %s)\n\n", | |
6636 | show_database_desc[type], | |
6637 | ospf_area_desc_string(area)); | |
6638 | vty_out(vty, "%s\n", | |
6639 | show_database_header[type]); | |
6640 | } else { | |
6641 | json_lsa_array = | |
6642 | json_object_new_array(); | |
6643 | json_object_object_add( | |
6644 | json_area, | |
6645 | show_database_desc_json[type], | |
6646 | json_lsa_array); | |
6647 | } | |
6648 | ||
6649 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) { | |
6650 | if (json) { | |
6651 | json_lsa = | |
6652 | json_object_new_object(); | |
6653 | json_object_array_add( | |
6654 | json_lsa_array, | |
6655 | json_lsa); | |
6656 | } | |
d62a17ae | 6657 | |
f328dc60 | 6658 | show_lsa_summary(vty, lsa, self, |
6659 | json_lsa); | |
6660 | } | |
6661 | ||
6662 | if (!json) | |
6663 | vty_out(vty, "\n"); | |
d62a17ae | 6664 | } |
6665 | } | |
f328dc60 | 6666 | if (json) |
6667 | json_object_object_add(json_areas, | |
6668 | inet_ntoa(area->area_id), | |
6669 | json_area); | |
d62a17ae | 6670 | } |
6671 | ||
f328dc60 | 6672 | if (json) |
6673 | json_object_object_add(json, "areas", json_areas); | |
6674 | ||
d62a17ae | 6675 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6676 | switch (type) { | |
6677 | case OSPF_AS_EXTERNAL_LSA: | |
6678 | case OSPF_OPAQUE_AS_LSA: | |
6679 | break; | |
6680 | default: | |
6681 | continue; | |
6682 | } | |
6683 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6684 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
f328dc60 | 6685 | if (!json) { |
6686 | vty_out(vty, " %s\n\n", | |
6687 | show_database_desc[type]); | |
6688 | vty_out(vty, "%s\n", | |
6689 | show_database_header[type]); | |
6690 | } else { | |
6691 | json_lsa_array = json_object_new_array(); | |
6692 | json_object_object_add( | |
6693 | json, show_database_desc_json[type], | |
6694 | json_lsa_array); | |
6695 | } | |
d62a17ae | 6696 | |
f328dc60 | 6697 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) { |
6698 | if (json) { | |
6699 | json_lsa = json_object_new_object(); | |
6700 | json_object_array_add(json_lsa_array, | |
6701 | json_lsa); | |
6702 | } | |
d62a17ae | 6703 | |
f328dc60 | 6704 | show_lsa_summary(vty, lsa, self, json_lsa); |
6705 | } | |
6706 | ||
6707 | if (!json) | |
6708 | vty_out(vty, "\n"); | |
d62a17ae | 6709 | } |
6710 | } | |
6711 | ||
f328dc60 | 6712 | if (!json) |
6713 | vty_out(vty, "\n"); | |
d62a17ae | 6714 | } |
6715 | ||
f328dc60 | 6716 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf, |
6717 | json_object *json) | |
d62a17ae | 6718 | { |
6719 | struct route_node *rn; | |
f328dc60 | 6720 | json_object *json_maxage = NULL; |
d62a17ae | 6721 | |
f328dc60 | 6722 | if (!json) |
6723 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6724 | else | |
6725 | json_maxage = json_object_new_object(); | |
d62a17ae | 6726 | |
6727 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6728 | struct ospf_lsa *lsa; | |
f328dc60 | 6729 | json_object *json_lsa = NULL; |
d62a17ae | 6730 | |
6731 | if ((lsa = rn->info) != NULL) { | |
f328dc60 | 6732 | if (!json) { |
6733 | vty_out(vty, "Link type: %d\n", | |
6734 | lsa->data->type); | |
6735 | vty_out(vty, "Link State ID: %s\n", | |
6736 | inet_ntoa(lsa->data->id)); | |
6737 | vty_out(vty, "Advertising Router: %pI4\n", | |
6738 | &lsa->data->adv_router); | |
6739 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6740 | vty_out(vty, "\n"); | |
6741 | } else { | |
6742 | json_lsa = json_object_new_object(); | |
6743 | json_object_int_add(json_lsa, "linkType", | |
6744 | lsa->data->type); | |
6745 | json_object_string_add( | |
6746 | json_lsa, "linkStateId", | |
6747 | inet_ntoa(lsa->data->id)); | |
6748 | json_object_string_add( | |
6749 | json_lsa, "advertisingRouter", | |
6750 | inet_ntoa(lsa->data->adv_router)); | |
6751 | json_object_int_add(json_lsa, "lsaLockCount", | |
6752 | lsa->lock); | |
6753 | json_object_object_add(json_maxage, | |
6754 | inet_ntoa(lsa->data->id), | |
6755 | json_lsa); | |
6756 | } | |
d62a17ae | 6757 | } |
91e6a0e5 | 6758 | } |
f328dc60 | 6759 | if (json) |
6760 | json_object_object_add(json, "maxAgeLinkStates", json_maxage); | |
718e3744 | 6761 | } |
6762 | ||
718e3744 | 6763 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6764 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6765 | |
718e3744 | 6766 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6767 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6768 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6769 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6770 | |
d62a17ae | 6771 | #define OSPF_LSA_TYPES_DESC \ |
6772 | "ASBR summary link states\n" \ | |
6773 | "External link states\n" \ | |
6774 | "Network link states\n" \ | |
6775 | "Router link states\n" \ | |
6776 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6777 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6778 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6779 | ||
6780 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6781 | int arg_base, int argc, | |
d7c0a89a | 6782 | struct cmd_token **argv, |
f328dc60 | 6783 | uint8_t use_vrf, json_object *json, |
6784 | bool uj) | |
d62a17ae | 6785 | { |
6786 | int idx_type = 4; | |
6787 | int type, ret; | |
6788 | struct in_addr id, adv_router; | |
f328dc60 | 6789 | json_object *json_vrf = NULL; |
d62a17ae | 6790 | |
f328dc60 | 6791 | if (uj) { |
6792 | if (use_vrf) | |
6793 | json_vrf = json_object_new_object(); | |
6794 | else | |
6795 | json_vrf = json; | |
6796 | } | |
6797 | ||
6798 | if (ospf->instance) { | |
6799 | if (uj) | |
6800 | json_object_int_add(json_vrf, "ospfInstance", | |
6801 | ospf->instance); | |
6802 | else | |
6803 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
6804 | } | |
d62a17ae | 6805 | |
f328dc60 | 6806 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 6807 | |
f328dc60 | 6808 | /* Show Router ID. */ |
6809 | if (uj) { | |
6810 | json_object_string_add(json_vrf, "routerId", | |
6811 | inet_ntoa(ospf->router_id)); | |
6812 | } else { | |
6813 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
6814 | &ospf->router_id); | |
6815 | } | |
d62a17ae | 6816 | |
6817 | /* Show all LSA. */ | |
f328dc60 | 6818 | if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) { |
6819 | show_ip_ospf_database_summary(vty, ospf, 0, json_vrf); | |
6820 | if (json) { | |
6821 | if (use_vrf) { | |
6822 | if (ospf->vrf_id == VRF_DEFAULT) | |
6823 | json_object_object_add(json, "default", | |
6824 | json_vrf); | |
6825 | else | |
6826 | json_object_object_add(json, ospf->name, | |
6827 | json_vrf); | |
6828 | } | |
6829 | } | |
d62a17ae | 6830 | return CMD_SUCCESS; |
6831 | } | |
718e3744 | 6832 | |
d62a17ae | 6833 | /* Set database type to show. */ |
6834 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6835 | type = OSPF_ROUTER_LSA; | |
6836 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6837 | type = OSPF_NETWORK_LSA; | |
6838 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6839 | type = OSPF_AS_NSSA_LSA; | |
6840 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
6841 | type = OSPF_SUMMARY_LSA; | |
6842 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6843 | type = OSPF_ASBR_SUMMARY_LSA; | |
6844 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6845 | type = OSPF_AS_EXTERNAL_LSA; | |
6846 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
f328dc60 | 6847 | show_ip_ospf_database_summary(vty, ospf, 1, json_vrf); |
6848 | if (json) { | |
6849 | if (use_vrf) { | |
6850 | if (ospf->vrf_id == VRF_DEFAULT) | |
6851 | json_object_object_add(json, "default", | |
6852 | json_vrf); | |
6853 | else | |
6854 | json_object_object_add(json, ospf->name, | |
6855 | json_vrf); | |
6856 | } | |
6857 | } | |
d62a17ae | 6858 | return CMD_SUCCESS; |
6859 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
f328dc60 | 6860 | show_ip_ospf_database_maxage(vty, ospf, json_vrf); |
6861 | if (json) { | |
6862 | if (use_vrf) { | |
6863 | if (ospf->vrf_id == VRF_DEFAULT) | |
6864 | json_object_object_add(json, "default", | |
6865 | json_vrf); | |
6866 | else | |
6867 | json_object_object_add(json, ospf->name, | |
6868 | json_vrf); | |
6869 | } | |
6870 | } | |
d62a17ae | 6871 | return CMD_SUCCESS; |
6872 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6873 | type = OSPF_OPAQUE_LINK_LSA; | |
6874 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6875 | type = OSPF_OPAQUE_AREA_LSA; | |
6876 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6877 | type = OSPF_OPAQUE_AS_LSA; | |
6878 | else | |
718e3744 | 6879 | return CMD_WARNING; |
d62a17ae | 6880 | |
6881 | /* `show ip ospf database LSA'. */ | |
f328dc60 | 6882 | if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6))) |
6883 | show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf); | |
d62a17ae | 6884 | else if (argc >= arg_base + 6) { |
6885 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
6886 | if (!ret) | |
6887 | return CMD_WARNING; | |
6888 | ||
6889 | /* `show ip ospf database LSA ID'. */ | |
f328dc60 | 6890 | if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7))) |
6891 | show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf); | |
d62a17ae | 6892 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ |
f328dc60 | 6893 | else if ((argc == arg_base + 7) |
6894 | || (uj && (argc == arg_base + 8))) { | |
d62a17ae | 6895 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) |
6896 | adv_router = ospf->router_id; | |
6897 | else { | |
6898 | ret = inet_aton(argv[arg_base + 7]->arg, | |
6899 | &adv_router); | |
6900 | if (!ret) | |
6901 | return CMD_WARNING; | |
6902 | } | |
f328dc60 | 6903 | show_lsa_detail(vty, ospf, type, &id, &adv_router, |
6904 | json_vrf); | |
6905 | } | |
6906 | } | |
6907 | ||
6908 | if (json) { | |
6909 | if (use_vrf) { | |
6910 | if (ospf->vrf_id == VRF_DEFAULT) | |
6911 | json_object_object_add(json, "default", | |
6912 | json_vrf); | |
6913 | else | |
6914 | json_object_object_add(json, ospf->name, | |
6915 | json_vrf); | |
d62a17ae | 6916 | } |
718e3744 | 6917 | } |
718e3744 | 6918 | |
d62a17ae | 6919 | return CMD_SUCCESS; |
718e3744 | 6920 | } |
6921 | ||
7a7be519 | 6922 | DEFUN (show_ip_ospf_database_max, |
6923 | show_ip_ospf_database_max_cmd, | |
f328dc60 | 6924 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]", |
7a7be519 | 6925 | SHOW_STR |
6926 | IP_STR | |
6927 | "OSPF information\n" | |
b5a8894d CS |
6928 | VRF_CMD_HELP_STR |
6929 | "All VRFs\n" | |
7a7be519 | 6930 | "Database summary\n" |
6931 | "LSAs in MaxAge list\n" | |
f328dc60 | 6932 | "Self-originated link states\n" |
6933 | JSON_STR) | |
7a7be519 | 6934 | { |
b5a8894d CS |
6935 | struct ospf *ospf = NULL; |
6936 | struct listnode *node = NULL; | |
6937 | char *vrf_name = NULL; | |
2951a7a4 | 6938 | bool all_vrf = false; |
b5a8894d CS |
6939 | int ret = CMD_SUCCESS; |
6940 | int inst = 0; | |
6941 | int idx_vrf = 0; | |
d7c0a89a | 6942 | uint8_t use_vrf = 0; |
f328dc60 | 6943 | bool uj = use_json(argc, argv); |
6944 | json_object *json = NULL; | |
6945 | ||
6946 | if (uj) | |
6947 | json = json_object_new_object(); | |
f412b39a | 6948 | |
43b8d1d8 | 6949 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 6950 | |
b5a8894d | 6951 | if (vrf_name) { |
2951a7a4 | 6952 | bool ospf_output = false; |
874f58d8 | 6953 | |
b1c3ae8c | 6954 | use_vrf = 1; |
94d4c685 | 6955 | |
b5a8894d CS |
6956 | if (all_vrf) { |
6957 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6958 | if (!ospf->oi_running) | |
6959 | continue; | |
2951a7a4 | 6960 | ospf_output = true; |
996c9314 LB |
6961 | ret = show_ip_ospf_database_common( |
6962 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
f328dc60 | 6963 | use_vrf, json, uj); |
b5a8894d | 6964 | } |
9f049418 DS |
6965 | |
6966 | if (!ospf_output) | |
6967 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
6968 | } else { |
6969 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6970 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6971 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6972 | return CMD_SUCCESS; |
9f049418 | 6973 | } |
996c9314 | 6974 | ret = (show_ip_ospf_database_common( |
f328dc60 | 6975 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf, |
6976 | json, uj)); | |
b5a8894d CS |
6977 | } |
6978 | } else { | |
6979 | /* Display default ospf (instance 0) info */ | |
6980 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6981 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6982 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6983 | return CMD_SUCCESS; |
9f049418 DS |
6984 | } |
6985 | ||
b1c3ae8c | 6986 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
f328dc60 | 6987 | use_vrf, json, uj); |
6988 | } | |
6989 | ||
6990 | if (uj) { | |
6991 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
6992 | json_object_free(json); | |
b5a8894d CS |
6993 | } |
6994 | ||
6995 | return ret; | |
7a7be519 | 6996 | } |
f412b39a | 6997 | |
f412b39a DW |
6998 | DEFUN (show_ip_ospf_instance_database, |
6999 | show_ip_ospf_instance_database_cmd, | |
f328dc60 | 7000 | "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>]]] [json]", |
718e3744 | 7001 | SHOW_STR |
7002 | IP_STR | |
7003 | "OSPF information\n" | |
7c8ff89e | 7004 | "Instance ID\n" |
b5a8894d | 7005 | VRF_CMD_HELP_STR |
7a7be519 | 7006 | "Database summary\n" |
7007 | OSPF_LSA_TYPES_DESC | |
7008 | "Link State ID (as an IP address)\n" | |
7009 | "Self-originated link states\n" | |
7010 | "Advertising Router link states\n" | |
f328dc60 | 7011 | "Advertising Router (as an IP address)\n" |
7012 | JSON_STR) | |
7c8ff89e | 7013 | { |
d62a17ae | 7014 | struct ospf *ospf; |
d7c0a89a | 7015 | unsigned short instance = 0; |
b5a8894d CS |
7016 | struct listnode *node = NULL; |
7017 | char *vrf_name = NULL; | |
2951a7a4 | 7018 | bool all_vrf = false; |
b5a8894d CS |
7019 | int ret = CMD_SUCCESS; |
7020 | int inst = 0; | |
d62a17ae | 7021 | int idx = 0; |
d7c0a89a | 7022 | uint8_t use_vrf = 0; |
f328dc60 | 7023 | bool uj = use_json(argc, argv); |
7024 | json_object *json = NULL; | |
7025 | ||
7026 | if (uj) | |
7027 | json = json_object_new_object(); | |
b5a8894d | 7028 | |
d62a17ae | 7029 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
7030 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
7031 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
7032 | if (ospf == NULL) |
7033 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
7034 | if (!ospf->oi_running) |
7035 | return CMD_SUCCESS; | |
7036 | ||
f328dc60 | 7037 | return (show_ip_ospf_database_common( |
7038 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf, json, uj)); | |
b5a8894d CS |
7039 | } else if (argv_find(argv, argc, "vrf", &idx)) { |
7040 | vrf_name = argv[++idx]->arg; | |
7041 | all_vrf = strmatch(vrf_name, "all"); | |
d62a17ae | 7042 | } |
7c8ff89e | 7043 | |
b5a8894d | 7044 | if (vrf_name) { |
b1c3ae8c | 7045 | use_vrf = 1; |
b5a8894d CS |
7046 | if (all_vrf) { |
7047 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7048 | if (!ospf->oi_running) | |
7049 | continue; | |
996c9314 LB |
7050 | ret = (show_ip_ospf_database_common( |
7051 | vty, ospf, idx ? 2 : 0, argc, argv, | |
f328dc60 | 7052 | use_vrf, json, uj)); |
b5a8894d CS |
7053 | } |
7054 | } else { | |
7055 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7056 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 7057 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7058 | return CMD_SUCCESS; |
9f049418 DS |
7059 | } |
7060 | ||
996c9314 | 7061 | ret = (show_ip_ospf_database_common( |
f328dc60 | 7062 | vty, ospf, idx ? 2 : 0, argc, argv, use_vrf, |
7063 | json, uj)); | |
b5a8894d CS |
7064 | } |
7065 | } else { | |
7066 | /* Display default ospf (instance 0) info */ | |
7067 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7068 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7069 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7070 | return CMD_SUCCESS; |
9f049418 DS |
7071 | } |
7072 | ||
b1c3ae8c | 7073 | ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
f328dc60 | 7074 | use_vrf, json, uj)); |
7075 | } | |
7076 | ||
7077 | if (uj) { | |
7078 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7079 | json_object_free(json); | |
b5a8894d | 7080 | } |
7c8ff89e | 7081 | |
b5a8894d | 7082 | return ret; |
7c8ff89e DS |
7083 | } |
7084 | ||
7a7be519 | 7085 | DEFUN (show_ip_ospf_instance_database_max, |
7086 | show_ip_ospf_instance_database_max_cmd, | |
f328dc60 | 7087 | "show ip ospf (1-65535) database <max-age|self-originate> [json]", |
7a7be519 | 7088 | SHOW_STR |
7089 | IP_STR | |
7090 | "OSPF information\n" | |
7091 | "Instance ID\n" | |
7092 | "Database summary\n" | |
7093 | "LSAs in MaxAge list\n" | |
f328dc60 | 7094 | "Self-originated link states\n" |
7095 | JSON_STR) | |
7a7be519 | 7096 | { |
d62a17ae | 7097 | int idx_number = 3; |
7098 | struct ospf *ospf; | |
d7c0a89a | 7099 | unsigned short instance = 0; |
f328dc60 | 7100 | bool uj = use_json(argc, argv); |
7101 | json_object *json = NULL; | |
7102 | ||
7103 | if (uj) | |
7104 | json = json_object_new_object(); | |
d62a17ae | 7105 | |
7106 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7107 | ||
ac28e4ec CS |
7108 | ospf = ospf_lookup_instance(instance); |
7109 | if (ospf == NULL) | |
7110 | return CMD_NOT_MY_INSTANCE; | |
7111 | ||
9f049418 | 7112 | if (!ospf->oi_running) { |
94d4c685 | 7113 | vty_out(vty, "%% OSPF instance not found\n"); |
d62a17ae | 7114 | return CMD_SUCCESS; |
9f049418 | 7115 | } |
d62a17ae | 7116 | |
f328dc60 | 7117 | show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj); |
7118 | ||
7119 | if (uj) { | |
7120 | vty_out(vty, "%s\n", | |
7121 | json_object_to_json_string_ext( | |
7122 | json, JSON_C_TO_STRING_PRETTY)); | |
7123 | json_object_free(json); | |
7124 | } | |
7125 | ||
7126 | return CMD_SUCCESS; | |
d62a17ae | 7127 | } |
7128 | ||
7129 | ||
7130 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
7131 | struct ospf *ospf, | |
7132 | int arg_base, int argc, | |
b1c3ae8c | 7133 | struct cmd_token **argv, |
f328dc60 | 7134 | uint8_t use_vrf, |
7135 | json_object *json, | |
7136 | bool uj) | |
d62a17ae | 7137 | { |
7138 | int idx_type = 4; | |
7139 | int type, ret; | |
7140 | struct in_addr adv_router; | |
f328dc60 | 7141 | json_object *json_vrf = NULL; |
d62a17ae | 7142 | |
f328dc60 | 7143 | if (uj) { |
7144 | if (use_vrf) | |
7145 | json_vrf = json_object_new_object(); | |
7146 | else | |
7147 | json_vrf = json; | |
7148 | } | |
d62a17ae | 7149 | |
f328dc60 | 7150 | if (ospf->instance) { |
7151 | if (uj) | |
7152 | json_object_int_add(json, "ospfInstance", | |
7153 | ospf->instance); | |
7154 | else | |
7155 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7156 | } | |
87bd50e8 | 7157 | |
f328dc60 | 7158 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
7159 | ||
7160 | /* Show Router ID. */ | |
7161 | if (uj) { | |
7162 | json_object_string_add(json_vrf, "routerId", | |
7163 | inet_ntoa(ospf->router_id)); | |
7164 | } else { | |
7165 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7166 | &ospf->router_id); | |
7167 | } | |
d62a17ae | 7168 | |
7169 | /* Set database type to show. */ | |
7170 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7171 | type = OSPF_ROUTER_LSA; | |
7172 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7173 | type = OSPF_NETWORK_LSA; | |
7174 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7175 | type = OSPF_AS_NSSA_LSA; | |
7176 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
7177 | type = OSPF_SUMMARY_LSA; | |
7178 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7179 | type = OSPF_ASBR_SUMMARY_LSA; | |
7180 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7181 | type = OSPF_AS_EXTERNAL_LSA; | |
7182 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7183 | type = OSPF_OPAQUE_LINK_LSA; | |
7184 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7185 | type = OSPF_OPAQUE_AREA_LSA; | |
7186 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7187 | type = OSPF_OPAQUE_AS_LSA; | |
7188 | else | |
7189 | return CMD_WARNING; | |
7c8ff89e | 7190 | |
d62a17ae | 7191 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
7192 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
7193 | adv_router = ospf->router_id; | |
7194 | else { | |
7195 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
7196 | if (!ret) | |
7197 | return CMD_WARNING; | |
7198 | } | |
7c8ff89e | 7199 | |
f328dc60 | 7200 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf); |
7201 | ||
7202 | if (json) { | |
7203 | if (use_vrf) { | |
7204 | if (ospf->vrf_id == VRF_DEFAULT) | |
7205 | json_object_object_add(json, "default", | |
7206 | json_vrf); | |
7207 | else | |
7208 | json_object_object_add(json, ospf->name, | |
7209 | json_vrf); | |
7210 | } | |
7211 | } | |
7c8ff89e | 7212 | |
d62a17ae | 7213 | return CMD_SUCCESS; |
7c8ff89e DS |
7214 | } |
7215 | ||
7c8ff89e DS |
7216 | DEFUN (show_ip_ospf_instance_database_type_adv_router, |
7217 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
f328dc60 | 7218 | "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> [json]", |
7c8ff89e DS |
7219 | SHOW_STR |
7220 | IP_STR | |
7221 | "OSPF information\n" | |
7222 | "Instance ID\n" | |
b5a8894d | 7223 | VRF_CMD_HELP_STR |
7c8ff89e DS |
7224 | "Database summary\n" |
7225 | OSPF_LSA_TYPES_DESC | |
7226 | "Advertising Router link states\n" | |
3a2d747c | 7227 | "Advertising Router (as an IP address)\n" |
f328dc60 | 7228 | "Self-originated link states\n" |
7229 | JSON_STR) | |
7c8ff89e | 7230 | { |
b5a8894d | 7231 | struct ospf *ospf = NULL; |
d7c0a89a | 7232 | unsigned short instance = 0; |
b5a8894d CS |
7233 | struct listnode *node = NULL; |
7234 | char *vrf_name = NULL; | |
2951a7a4 | 7235 | bool all_vrf = false; |
b5a8894d CS |
7236 | int ret = CMD_SUCCESS; |
7237 | int inst = 0; | |
43b8d1d8 | 7238 | int idx = 0, idx_vrf = 0; |
d7c0a89a | 7239 | uint8_t use_vrf = 0; |
f328dc60 | 7240 | bool uj = use_json(argc, argv); |
7241 | json_object *json = NULL; | |
7242 | ||
7243 | if (uj) | |
7244 | json = json_object_new_object(); | |
7c8ff89e | 7245 | |
d62a17ae | 7246 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
7247 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
7248 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
7249 | if (ospf == NULL) |
7250 | return CMD_NOT_MY_INSTANCE; | |
9f049418 | 7251 | if (!ospf->oi_running) { |
94d4c685 | 7252 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7253 | return CMD_SUCCESS; |
9f049418 DS |
7254 | } |
7255 | ||
996c9314 | 7256 | return (show_ip_ospf_database_type_adv_router_common( |
f328dc60 | 7257 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf, json, uj)); |
b5a8894d | 7258 | } |
43b8d1d8 CS |
7259 | |
7260 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
7261 | ||
b5a8894d | 7262 | if (vrf_name) { |
2951a7a4 | 7263 | bool ospf_output = false; |
874f58d8 | 7264 | |
b1c3ae8c | 7265 | use_vrf = 1; |
94d4c685 | 7266 | |
b5a8894d CS |
7267 | if (all_vrf) { |
7268 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7269 | if (!ospf->oi_running) | |
7270 | continue; | |
2951a7a4 | 7271 | ospf_output = true; |
996c9314 LB |
7272 | ret = show_ip_ospf_database_type_adv_router_common( |
7273 | vty, ospf, idx ? 1 : 0, argc, argv, | |
f328dc60 | 7274 | use_vrf, json, uj); |
b5a8894d | 7275 | } |
9f049418 DS |
7276 | if (!ospf_output) |
7277 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7278 | } else { |
7279 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7280 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 7281 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7282 | return CMD_SUCCESS; |
9f049418 DS |
7283 | } |
7284 | ||
996c9314 | 7285 | ret = show_ip_ospf_database_type_adv_router_common( |
f328dc60 | 7286 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf, |
7287 | json, uj); | |
b5a8894d CS |
7288 | } |
7289 | } else { | |
7290 | /* Display default ospf (instance 0) info */ | |
7291 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7292 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7293 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7294 | return CMD_SUCCESS; |
9f049418 DS |
7295 | } |
7296 | ||
996c9314 | 7297 | ret = show_ip_ospf_database_type_adv_router_common( |
f328dc60 | 7298 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf, json, uj); |
b5a8894d | 7299 | } |
f328dc60 | 7300 | |
7301 | if (uj) { | |
7302 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7303 | json_object_free(json); | |
7304 | } | |
7305 | ||
b5a8894d CS |
7306 | return ret; |
7307 | /*return (show_ip_ospf_database_type_adv_router_common( | |
7308 | vty, ospf, idx ? 1 : 0, argc, argv));*/ | |
718e3744 | 7309 | } |
7310 | ||
718e3744 | 7311 | DEFUN (ip_ospf_authentication_args, |
7312 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7313 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 7314 | "IP Information\n" |
7315 | "OSPF interface commands\n" | |
7316 | "Enable authentication on this interface\n" | |
7317 | "Use null authentication\n" | |
7318 | "Use message-digest authentication\n" | |
7a7be519 | 7319 | "Address of interface\n") |
718e3744 | 7320 | { |
d62a17ae | 7321 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7322 | int idx_encryption = 3; | |
7323 | int idx_ipv4 = 4; | |
7324 | struct in_addr addr; | |
7325 | int ret; | |
7326 | struct ospf_if_params *params; | |
7327 | ||
7328 | params = IF_DEF_PARAMS(ifp); | |
7329 | ||
7330 | if (argc == 5) { | |
7331 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7332 | if (!ret) { | |
7333 | vty_out(vty, | |
7334 | "Please specify interface address by A.B.C.D\n"); | |
7335 | return CMD_WARNING_CONFIG_FAILED; | |
7336 | } | |
718e3744 | 7337 | |
d62a17ae | 7338 | params = ospf_get_if_params(ifp, addr); |
7339 | ospf_if_update_params(ifp, addr); | |
7340 | } | |
718e3744 | 7341 | |
d62a17ae | 7342 | /* Handle null authentication */ |
7343 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7344 | SET_IF_PARAM(params, auth_type); | |
7345 | params->auth_type = OSPF_AUTH_NULL; | |
7346 | return CMD_SUCCESS; | |
7347 | } | |
718e3744 | 7348 | |
d62a17ae | 7349 | /* Handle message-digest authentication */ |
7350 | if (argv[idx_encryption]->arg[0] == 'm') { | |
7351 | SET_IF_PARAM(params, auth_type); | |
7352 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7353 | return CMD_SUCCESS; | |
7354 | } | |
718e3744 | 7355 | |
d62a17ae | 7356 | vty_out(vty, "You shouldn't get here!\n"); |
7357 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7358 | } |
7359 | ||
718e3744 | 7360 | DEFUN (ip_ospf_authentication, |
7361 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7362 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 7363 | "IP Information\n" |
7364 | "OSPF interface commands\n" | |
7365 | "Enable authentication on this interface\n" | |
efd7904e | 7366 | "Address of interface\n") |
718e3744 | 7367 | { |
d62a17ae | 7368 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7369 | int idx_ipv4 = 3; | |
7370 | struct in_addr addr; | |
7371 | int ret; | |
7372 | struct ospf_if_params *params; | |
7373 | ||
7374 | params = IF_DEF_PARAMS(ifp); | |
7375 | ||
7376 | if (argc == 4) { | |
7377 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7378 | if (!ret) { | |
7379 | vty_out(vty, | |
7380 | "Please specify interface address by A.B.C.D\n"); | |
7381 | return CMD_WARNING_CONFIG_FAILED; | |
7382 | } | |
7383 | ||
7384 | params = ospf_get_if_params(ifp, addr); | |
7385 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7386 | } |
7387 | ||
d62a17ae | 7388 | SET_IF_PARAM(params, auth_type); |
7389 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 7390 | |
d62a17ae | 7391 | return CMD_SUCCESS; |
718e3744 | 7392 | } |
7393 | ||
b4a039bf DS |
7394 | DEFUN (no_ip_ospf_authentication_args, |
7395 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7396 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
7397 | NO_STR |
7398 | "IP Information\n" | |
7399 | "OSPF interface commands\n" | |
7400 | "Enable authentication on this interface\n" | |
7401 | "Use null authentication\n" | |
7402 | "Use message-digest authentication\n" | |
efd7904e | 7403 | "Address of interface\n") |
b4a039bf | 7404 | { |
d62a17ae | 7405 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7406 | int idx_encryption = 4; | |
7407 | int idx_ipv4 = 5; | |
7408 | struct in_addr addr; | |
7409 | int ret; | |
7410 | struct ospf_if_params *params; | |
7411 | struct route_node *rn; | |
7412 | int auth_type; | |
7413 | ||
7414 | params = IF_DEF_PARAMS(ifp); | |
7415 | ||
7416 | if (argc == 6) { | |
7417 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7418 | if (!ret) { | |
7419 | vty_out(vty, | |
7420 | "Please specify interface address by A.B.C.D\n"); | |
7421 | return CMD_WARNING_CONFIG_FAILED; | |
7422 | } | |
b4a039bf | 7423 | |
d62a17ae | 7424 | params = ospf_lookup_if_params(ifp, addr); |
7425 | if (params == NULL) { | |
7426 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7427 | return CMD_WARNING_CONFIG_FAILED; | |
7428 | } | |
7429 | params->auth_type = OSPF_AUTH_NOTSET; | |
7430 | UNSET_IF_PARAM(params, auth_type); | |
7431 | if (params != IF_DEF_PARAMS(ifp)) { | |
7432 | ospf_free_if_params(ifp, addr); | |
7433 | ospf_if_update_params(ifp, addr); | |
7434 | } | |
7435 | } else { | |
7436 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7437 | auth_type = OSPF_AUTH_NULL; | |
7438 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
7439 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7440 | } else { | |
7441 | vty_out(vty, "Unexpected input encountered\n"); | |
7442 | return CMD_WARNING_CONFIG_FAILED; | |
7443 | } | |
7444 | /* | |
7445 | * Here we have a case where the user has entered | |
7446 | * 'no ip ospf authentication (null | message_digest )' | |
7447 | * we need to find if we have any ip addresses underneath it | |
7448 | * that | |
7449 | * correspond to the associated type. | |
7450 | */ | |
7451 | if (params->auth_type == auth_type) { | |
7452 | params->auth_type = OSPF_AUTH_NOTSET; | |
7453 | UNSET_IF_PARAM(params, auth_type); | |
7454 | } | |
7455 | ||
7456 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
7457 | rn = route_next(rn)) { | |
7458 | if ((params = rn->info)) { | |
7459 | if (params->auth_type == auth_type) { | |
7460 | params->auth_type = OSPF_AUTH_NOTSET; | |
7461 | UNSET_IF_PARAM(params, auth_type); | |
7462 | if (params != IF_DEF_PARAMS(ifp)) { | |
7463 | ospf_free_if_params( | |
7464 | ifp, rn->p.u.prefix4); | |
7465 | ospf_if_update_params( | |
7466 | ifp, rn->p.u.prefix4); | |
7467 | } | |
7468 | } | |
7469 | } | |
b4a039bf | 7470 | } |
b4a039bf | 7471 | } |
b4a039bf | 7472 | |
d62a17ae | 7473 | return CMD_SUCCESS; |
b4a039bf DS |
7474 | } |
7475 | ||
718e3744 | 7476 | DEFUN (no_ip_ospf_authentication, |
7477 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7478 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 7479 | NO_STR |
7480 | "IP Information\n" | |
7481 | "OSPF interface commands\n" | |
7482 | "Enable authentication on this interface\n" | |
efd7904e | 7483 | "Address of interface\n") |
718e3744 | 7484 | { |
d62a17ae | 7485 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7486 | int idx_ipv4 = 4; | |
7487 | struct in_addr addr; | |
7488 | int ret; | |
7489 | struct ospf_if_params *params; | |
7490 | struct route_node *rn; | |
7491 | ||
7492 | params = IF_DEF_PARAMS(ifp); | |
7493 | ||
7494 | if (argc == 5) { | |
7495 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7496 | if (!ret) { | |
7497 | vty_out(vty, | |
7498 | "Please specify interface address by A.B.C.D\n"); | |
7499 | return CMD_WARNING_CONFIG_FAILED; | |
7500 | } | |
718e3744 | 7501 | |
d62a17ae | 7502 | params = ospf_lookup_if_params(ifp, addr); |
7503 | if (params == NULL) { | |
7504 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7505 | return CMD_WARNING_CONFIG_FAILED; | |
7506 | } | |
718e3744 | 7507 | |
d62a17ae | 7508 | params->auth_type = OSPF_AUTH_NOTSET; |
7509 | UNSET_IF_PARAM(params, auth_type); | |
7510 | if (params != IF_DEF_PARAMS(ifp)) { | |
7511 | ospf_free_if_params(ifp, addr); | |
7512 | ospf_if_update_params(ifp, addr); | |
7513 | } | |
7514 | } else { | |
7515 | /* | |
7516 | * When a user enters 'no ip ospf authentication' | |
7517 | * We should remove all authentication types from | |
7518 | * the interface. | |
7519 | */ | |
7520 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7521 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
7522 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
7523 | params->auth_type = OSPF_AUTH_NOTSET; | |
7524 | UNSET_IF_PARAM(params, auth_type); | |
7525 | } | |
813d4307 | 7526 | |
d62a17ae | 7527 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
7528 | rn = route_next(rn)) { | |
7529 | if ((params = rn->info)) { | |
7530 | ||
7531 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7532 | || (params->auth_type | |
7533 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
7534 | || (params->auth_type | |
7535 | == OSPF_AUTH_SIMPLE)) { | |
7536 | params->auth_type = OSPF_AUTH_NOTSET; | |
7537 | UNSET_IF_PARAM(params, auth_type); | |
7538 | if (params != IF_DEF_PARAMS(ifp)) { | |
7539 | ospf_free_if_params( | |
7540 | ifp, rn->p.u.prefix4); | |
7541 | ospf_if_update_params( | |
7542 | ifp, rn->p.u.prefix4); | |
7543 | } | |
7544 | } | |
7545 | } | |
b4a039bf | 7546 | } |
b4a039bf | 7547 | } |
d62a17ae | 7548 | |
7549 | return CMD_SUCCESS; | |
718e3744 | 7550 | } |
7551 | ||
0d829fa7 | 7552 | |
718e3744 | 7553 | DEFUN (ip_ospf_authentication_key, |
7554 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 7555 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 7556 | "IP Information\n" |
7557 | "OSPF interface commands\n" | |
7558 | "Authentication password (key)\n" | |
7559 | "The OSPF password (key)\n" | |
efd7904e | 7560 | "Address of interface\n") |
718e3744 | 7561 | { |
d62a17ae | 7562 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7563 | int idx = 0; | |
7564 | struct in_addr addr; | |
7565 | struct ospf_if_params *params; | |
718e3744 | 7566 | |
d62a17ae | 7567 | params = IF_DEF_PARAMS(ifp); |
7568 | ||
7569 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7570 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7571 | vty_out(vty, | |
7572 | "Please specify interface address by A.B.C.D\n"); | |
7573 | return CMD_WARNING_CONFIG_FAILED; | |
7574 | } | |
718e3744 | 7575 | |
d62a17ae | 7576 | params = ospf_get_if_params(ifp, addr); |
7577 | ospf_if_update_params(ifp, addr); | |
7578 | } | |
718e3744 | 7579 | |
4d65d927 QY |
7580 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
7581 | sizeof(params->auth_simple)); | |
d62a17ae | 7582 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 7583 | |
d62a17ae | 7584 | return CMD_SUCCESS; |
718e3744 | 7585 | } |
7586 | ||
7a7be519 | 7587 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 7588 | ospf_authentication_key_cmd, |
0d829fa7 | 7589 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 7590 | "OSPF interface commands\n" |
baf9eaad | 7591 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 7592 | "Address of interface\n") |
718e3744 | 7593 | { |
d62a17ae | 7594 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 7595 | } |
7596 | ||
7a7be519 | 7597 | DEFUN (no_ip_ospf_authentication_key, |
7598 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
7599 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7600 | NO_STR | |
7601 | "IP Information\n" | |
7602 | "OSPF interface commands\n" | |
baf9eaad CS |
7603 | VLINK_HELPSTR_AUTH_SIMPLE |
7604 | "Address of interface\n") | |
7a7be519 | 7605 | { |
d62a17ae | 7606 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7607 | int idx = 0; | |
7608 | struct in_addr addr; | |
7609 | struct ospf_if_params *params; | |
7610 | params = IF_DEF_PARAMS(ifp); | |
7611 | ||
7612 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7613 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7614 | vty_out(vty, | |
7615 | "Please specify interface address by A.B.C.D\n"); | |
7616 | return CMD_WARNING_CONFIG_FAILED; | |
7617 | } | |
7a7be519 | 7618 | |
d62a17ae | 7619 | params = ospf_lookup_if_params(ifp, addr); |
7620 | if (params == NULL) | |
7621 | return CMD_SUCCESS; | |
7a7be519 | 7622 | } |
813d4307 | 7623 | |
d62a17ae | 7624 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
7625 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 7626 | |
d62a17ae | 7627 | if (params != IF_DEF_PARAMS(ifp)) { |
7628 | ospf_free_if_params(ifp, addr); | |
7629 | ospf_if_update_params(ifp, addr); | |
7630 | } | |
813d4307 | 7631 | |
d62a17ae | 7632 | return CMD_SUCCESS; |
7a7be519 | 7633 | } |
813d4307 | 7634 | |
0d829fa7 QY |
7635 | DEFUN_HIDDEN (no_ospf_authentication_key, |
7636 | no_ospf_authentication_key_authkey_addr_cmd, | |
7637 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7638 | NO_STR | |
7639 | "OSPF interface commands\n" | |
baf9eaad CS |
7640 | VLINK_HELPSTR_AUTH_SIMPLE |
7641 | "Address of interface\n") | |
0d829fa7 | 7642 | { |
d62a17ae | 7643 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
7644 | } |
7645 | ||
718e3744 | 7646 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 7647 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 7648 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 7649 | "IP Information\n" |
7650 | "OSPF interface commands\n" | |
7651 | "Message digest authentication password (key)\n" | |
7652 | "Key ID\n" | |
7653 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
7654 | "The OSPF password (key)\n" |
7655 | "Address of interface\n") | |
718e3744 | 7656 | { |
d62a17ae | 7657 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7658 | struct crypt_key *ck; | |
d7c0a89a | 7659 | uint8_t key_id; |
d62a17ae | 7660 | struct in_addr addr; |
7661 | struct ospf_if_params *params; | |
7662 | ||
7663 | params = IF_DEF_PARAMS(ifp); | |
7664 | int idx = 0; | |
7665 | ||
7666 | argv_find(argv, argc, "(1-255)", &idx); | |
7667 | char *keyid = argv[idx]->arg; | |
7668 | argv_find(argv, argc, "KEY", &idx); | |
7669 | char *cryptkey = argv[idx]->arg; | |
7670 | ||
7671 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7672 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7673 | vty_out(vty, | |
7674 | "Please specify interface address by A.B.C.D\n"); | |
7675 | return CMD_WARNING_CONFIG_FAILED; | |
7676 | } | |
7677 | ||
7678 | params = ospf_get_if_params(ifp, addr); | |
7679 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7680 | } |
7681 | ||
d62a17ae | 7682 | key_id = strtol(keyid, NULL, 10); |
7683 | if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) { | |
7684 | vty_out(vty, "OSPF: Key %d already exists\n", key_id); | |
851fcbae | 7685 | return CMD_WARNING; |
d62a17ae | 7686 | } |
718e3744 | 7687 | |
d62a17ae | 7688 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7689 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7690 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7691 | |
d62a17ae | 7692 | ospf_crypt_key_add(params->auth_crypt, ck); |
7693 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7694 | |
d62a17ae | 7695 | return CMD_SUCCESS; |
718e3744 | 7696 | } |
7697 | ||
7a7be519 | 7698 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7699 | ospf_message_digest_key_cmd, |
0d829fa7 | 7700 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7701 | "OSPF interface commands\n" |
7702 | "Message digest authentication password (key)\n" | |
7703 | "Key ID\n" | |
7704 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7705 | "The OSPF password (key)\n" |
7706 | "Address of interface\n") | |
7a7be519 | 7707 | { |
d62a17ae | 7708 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7709 | } |
718e3744 | 7710 | |
537eae3f QY |
7711 | DEFUN (no_ip_ospf_message_digest_key, |
7712 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7713 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7714 | NO_STR |
7715 | "IP Information\n" | |
7716 | "OSPF interface commands\n" | |
7717 | "Message digest authentication password (key)\n" | |
7718 | "Key ID\n" | |
7719 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7720 | "The OSPF password (key)\n" |
7721 | "Address of interface\n") | |
813d4307 | 7722 | { |
d62a17ae | 7723 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7724 | int idx = 0; | |
7725 | struct crypt_key *ck; | |
7726 | int key_id; | |
7727 | struct in_addr addr; | |
7728 | struct ospf_if_params *params; | |
7729 | params = IF_DEF_PARAMS(ifp); | |
7730 | ||
7731 | argv_find(argv, argc, "(1-255)", &idx); | |
7732 | char *keyid = argv[idx]->arg; | |
7733 | ||
7734 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7735 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7736 | vty_out(vty, | |
7737 | "Please specify interface address by A.B.C.D\n"); | |
7738 | return CMD_WARNING_CONFIG_FAILED; | |
7739 | } | |
7a7be519 | 7740 | |
d62a17ae | 7741 | params = ospf_lookup_if_params(ifp, addr); |
7742 | if (params == NULL) | |
7743 | return CMD_SUCCESS; | |
7a7be519 | 7744 | } |
7745 | ||
d62a17ae | 7746 | key_id = strtol(keyid, NULL, 10); |
7747 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7748 | if (ck == NULL) { | |
7749 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7750 | return CMD_WARNING_CONFIG_FAILED; | |
7751 | } | |
7a7be519 | 7752 | |
d62a17ae | 7753 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7754 | |
d62a17ae | 7755 | if (params != IF_DEF_PARAMS(ifp)) { |
7756 | ospf_free_if_params(ifp, addr); | |
7757 | ospf_if_update_params(ifp, addr); | |
7758 | } | |
7a7be519 | 7759 | |
d62a17ae | 7760 | return CMD_SUCCESS; |
7a7be519 | 7761 | } |
813d4307 | 7762 | |
0d829fa7 | 7763 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7764 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7765 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7766 | NO_STR | |
7767 | "OSPF interface commands\n" | |
7768 | "Message digest authentication password (key)\n" | |
7769 | "Key ID\n" | |
efd7904e RW |
7770 | "Use MD5 algorithm\n" |
7771 | "The OSPF password (key)\n" | |
7772 | "Address of interface\n") | |
718e3744 | 7773 | { |
d62a17ae | 7774 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7775 | } |
7776 | ||
718e3744 | 7777 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7778 | ip_ospf_cost_cmd, |
7a7be519 | 7779 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7780 | "IP Information\n" |
7781 | "OSPF interface commands\n" | |
7782 | "Interface cost\n" | |
7783 | "Cost\n" | |
5c2fc921 | 7784 | "Address of interface\n") |
718e3744 | 7785 | { |
d62a17ae | 7786 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7787 | int idx = 0; | |
d7c0a89a | 7788 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7789 | struct in_addr addr; |
7790 | struct ospf_if_params *params; | |
7791 | params = IF_DEF_PARAMS(ifp); | |
7792 | ||
7793 | // get arguments | |
7794 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7795 | |
c31a793b VJ |
7796 | argv_find(argv, argc, "(1-65535)", &idx); |
7797 | coststr = argv[idx]->arg; | |
d62a17ae | 7798 | cost = strtol(coststr, NULL, 10); |
7799 | ||
c31a793b | 7800 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7801 | if (ifaddr) { |
7802 | if (!inet_aton(ifaddr, &addr)) { | |
7803 | vty_out(vty, | |
7804 | "Please specify interface address by A.B.C.D\n"); | |
7805 | return CMD_WARNING_CONFIG_FAILED; | |
7806 | } | |
718e3744 | 7807 | |
d62a17ae | 7808 | params = ospf_get_if_params(ifp, addr); |
7809 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7810 | } |
7811 | ||
d62a17ae | 7812 | SET_IF_PARAM(params, output_cost_cmd); |
7813 | params->output_cost_cmd = cost; | |
718e3744 | 7814 | |
d62a17ae | 7815 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 7816 | |
d62a17ae | 7817 | return CMD_SUCCESS; |
718e3744 | 7818 | } |
7819 | ||
7a7be519 | 7820 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
7821 | ospf_cost_cmd, |
7822 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
7823 | "OSPF interface commands\n" |
7824 | "Interface cost\n" | |
7825 | "Cost\n" | |
5c2fc921 | 7826 | "Address of interface\n") |
7a7be519 | 7827 | { |
d62a17ae | 7828 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 7829 | } |
9eff36b3 | 7830 | |
718e3744 | 7831 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
7832 | no_ip_ospf_cost_cmd, |
7833 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 7834 | NO_STR |
efd7904e | 7835 | "IP Information\n" |
718e3744 | 7836 | "OSPF interface commands\n" |
7837 | "Interface cost\n" | |
efd7904e RW |
7838 | "Cost\n" |
7839 | "Address of interface\n") | |
718e3744 | 7840 | { |
d62a17ae | 7841 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7842 | int idx = 0; | |
7843 | struct in_addr addr; | |
7844 | struct ospf_if_params *params; | |
7a7be519 | 7845 | |
d62a17ae | 7846 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7847 | |
d62a17ae | 7848 | // get arguments |
7849 | char *ifaddr = NULL; | |
7850 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 7851 | |
d62a17ae | 7852 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
7853 | * always treated as "no ip ospf cost" regardless of the actual value | |
7854 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 7855 | |
d62a17ae | 7856 | if (ifaddr) { |
7857 | if (!inet_aton(ifaddr, &addr)) { | |
7858 | vty_out(vty, | |
7859 | "Please specify interface address by A.B.C.D\n"); | |
7860 | return CMD_WARNING_CONFIG_FAILED; | |
7861 | } | |
7a7be519 | 7862 | |
d62a17ae | 7863 | params = ospf_lookup_if_params(ifp, addr); |
7864 | if (params == NULL) | |
7865 | return CMD_SUCCESS; | |
7866 | } | |
7a7be519 | 7867 | |
d62a17ae | 7868 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 7869 | |
d62a17ae | 7870 | if (params != IF_DEF_PARAMS(ifp)) { |
7871 | ospf_free_if_params(ifp, addr); | |
7872 | ospf_if_update_params(ifp, addr); | |
7873 | } | |
7a7be519 | 7874 | |
d62a17ae | 7875 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 7876 | |
d62a17ae | 7877 | return CMD_SUCCESS; |
7a7be519 | 7878 | } |
9eff36b3 | 7879 | |
5c2fc921 QY |
7880 | DEFUN_HIDDEN (no_ospf_cost, |
7881 | no_ospf_cost_cmd, | |
7882 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
7883 | NO_STR | |
7884 | "OSPF interface commands\n" | |
7885 | "Interface cost\n" | |
7886 | "Cost\n" | |
7887 | "Address of interface\n") | |
827341b7 | 7888 | { |
d62a17ae | 7889 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
7890 | } |
7891 | ||
d62a17ae | 7892 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 7893 | { |
d62a17ae | 7894 | struct route_node *rn; |
7895 | struct ospf_neighbor *nbr; | |
718e3744 | 7896 | |
d62a17ae | 7897 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
7898 | if ((nbr = rn->info)) { | |
7899 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
7900 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
7901 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
7902 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
7903 | } | |
718e3744 | 7904 | } |
7905 | ||
d62a17ae | 7906 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
7907 | const char *nbr_str, | |
7908 | const char *fast_hello_str) | |
7909 | { | |
7910 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
7911 | uint32_t seconds; |
7912 | uint8_t hellomult; | |
d62a17ae | 7913 | struct in_addr addr; |
7914 | int ret; | |
7915 | struct ospf_if_params *params; | |
7916 | struct ospf_interface *oi; | |
7917 | struct route_node *rn; | |
718e3744 | 7918 | |
d62a17ae | 7919 | params = IF_DEF_PARAMS(ifp); |
7920 | ||
7921 | if (nbr_str) { | |
7922 | ret = inet_aton(nbr_str, &addr); | |
7923 | if (!ret) { | |
7924 | vty_out(vty, | |
7925 | "Please specify interface address by A.B.C.D\n"); | |
7926 | return CMD_WARNING_CONFIG_FAILED; | |
7927 | } | |
7928 | ||
7929 | params = ospf_get_if_params(ifp, addr); | |
7930 | ospf_if_update_params(ifp, addr); | |
7931 | } | |
7932 | ||
7933 | if (interval_str) { | |
7934 | seconds = strtoul(interval_str, NULL, 10); | |
7935 | ||
7936 | /* reset fast_hello too, just to be sure */ | |
7937 | UNSET_IF_PARAM(params, fast_hello); | |
7938 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7939 | } else if (fast_hello_str) { | |
7940 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
7941 | /* 1s dead-interval with sub-second hellos desired */ | |
7942 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
7943 | SET_IF_PARAM(params, fast_hello); | |
7944 | params->fast_hello = hellomult; | |
7945 | } else { | |
7946 | vty_out(vty, | |
7947 | "Please specify dead-interval or hello-multiplier\n"); | |
7948 | return CMD_WARNING_CONFIG_FAILED; | |
7949 | } | |
7950 | ||
7951 | SET_IF_PARAM(params, v_wait); | |
7952 | params->v_wait = seconds; | |
182d6bdc | 7953 | params->is_v_wait_set = true; |
d62a17ae | 7954 | |
7955 | /* Update timer values in neighbor structure. */ | |
7956 | if (nbr_str) { | |
b5a8894d CS |
7957 | struct ospf *ospf = NULL; |
7958 | ||
a36898e7 | 7959 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 7960 | if (ospf) { |
d62a17ae | 7961 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7962 | if (oi) | |
7963 | ospf_nbr_timer_update(oi); | |
7964 | } | |
7965 | } else { | |
7966 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7967 | if ((oi = rn->info)) | |
7968 | ospf_nbr_timer_update(oi); | |
7969 | } | |
7970 | ||
7971 | return CMD_SUCCESS; | |
718e3744 | 7972 | } |
7973 | ||
f9ad937f | 7974 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 7975 | ip_ospf_dead_interval_cmd, |
7a7be519 | 7976 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 7977 | "IP Information\n" |
7978 | "OSPF interface commands\n" | |
99a522c7 | 7979 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7980 | "Seconds\n" |
7981 | "Address of interface\n") | |
7982 | { | |
d62a17ae | 7983 | int idx = 0; |
7984 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
7985 | ? argv[idx]->arg | |
7986 | : NULL; | |
7987 | char *ifaddr = | |
7988 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
7989 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 7990 | } |
7991 | ||
718e3744 | 7992 | |
7a7be519 | 7993 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 7994 | ospf_dead_interval_cmd, |
0d829fa7 | 7995 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 7996 | "OSPF interface commands\n" |
99a522c7 | 7997 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
7998 | "Seconds\n" |
7999 | "Address of interface\n") | |
7a7be519 | 8000 | { |
d62a17ae | 8001 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 8002 | } |
718e3744 | 8003 | |
f9ad937f | 8004 | DEFUN (ip_ospf_dead_interval_minimal, |
8005 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 8006 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 8007 | "IP Information\n" |
8008 | "OSPF interface commands\n" | |
99a522c7 | 8009 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8010 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8011 | "Hello multiplier factor\n" | |
8012 | "Number of Hellos to send each second\n" | |
8013 | "Address of interface\n") | |
8014 | { | |
d62a17ae | 8015 | int idx_number = 5; |
8016 | int idx_ipv4 = 6; | |
8017 | if (argc == 7) | |
8018 | return ospf_vty_dead_interval_set( | |
8019 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
8020 | else | |
8021 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
8022 | argv[idx_number]->arg); | |
f9ad937f | 8023 | } |
8024 | ||
718e3744 | 8025 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 8026 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 8027 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 8028 | NO_STR |
8029 | "IP Information\n" | |
8030 | "OSPF interface commands\n" | |
99a522c7 | 8031 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 8032 | "Seconds\n" |
efd7904e RW |
8033 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8034 | "Hello multiplier factor\n" | |
8035 | "Number of Hellos to send each second\n" | |
8036 | "Address of interface\n") | |
718e3744 | 8037 | { |
d62a17ae | 8038 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8039 | int idx_ipv4 = argc - 1; | |
8040 | struct in_addr addr = {.s_addr = 0L}; | |
8041 | int ret; | |
8042 | struct ospf_if_params *params; | |
8043 | struct ospf_interface *oi; | |
8044 | struct route_node *rn; | |
8045 | ||
8046 | params = IF_DEF_PARAMS(ifp); | |
8047 | ||
8048 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
8049 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8050 | if (!ret) { | |
8051 | vty_out(vty, | |
8052 | "Please specify interface address by A.B.C.D\n"); | |
8053 | return CMD_WARNING_CONFIG_FAILED; | |
8054 | } | |
020709f9 | 8055 | |
d62a17ae | 8056 | params = ospf_lookup_if_params(ifp, addr); |
8057 | if (params == NULL) | |
8058 | return CMD_SUCCESS; | |
8059 | } | |
718e3744 | 8060 | |
d62a17ae | 8061 | UNSET_IF_PARAM(params, v_wait); |
8062 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
182d6bdc | 8063 | params->is_v_wait_set = false; |
d62a17ae | 8064 | |
8065 | UNSET_IF_PARAM(params, fast_hello); | |
8066 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8067 | ||
8068 | if (params != IF_DEF_PARAMS(ifp)) { | |
8069 | ospf_free_if_params(ifp, addr); | |
8070 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8071 | } |
8072 | ||
d62a17ae | 8073 | /* Update timer values in neighbor structure. */ |
8074 | if (argc == 1) { | |
b5a8894d | 8075 | struct ospf *ospf = NULL; |
718e3744 | 8076 | |
a36898e7 | 8077 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8078 | if (ospf) { |
d62a17ae | 8079 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8080 | if (oi) | |
8081 | ospf_nbr_timer_update(oi); | |
8082 | } | |
8083 | } else { | |
8084 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8085 | if ((oi = rn->info)) | |
8086 | ospf_nbr_timer_update(oi); | |
8087 | } | |
8088 | ||
8089 | return CMD_SUCCESS; | |
718e3744 | 8090 | } |
8091 | ||
0d829fa7 QY |
8092 | DEFUN_HIDDEN (no_ospf_dead_interval, |
8093 | no_ospf_dead_interval_cmd, | |
8094 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
8095 | NO_STR | |
8096 | "OSPF interface commands\n" | |
99a522c7 | 8097 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 8098 | "Seconds\n" |
efd7904e RW |
8099 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8100 | "Hello multiplier factor\n" | |
8101 | "Number of Hellos to send each second\n" | |
8102 | "Address of interface\n") | |
0d829fa7 | 8103 | { |
d62a17ae | 8104 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
8105 | } |
8106 | ||
718e3744 | 8107 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 8108 | ip_ospf_hello_interval_cmd, |
7a7be519 | 8109 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 8110 | "IP Information\n" |
8111 | "OSPF interface commands\n" | |
8112 | "Time between HELLO packets\n" | |
8113 | "Seconds\n" | |
0d829fa7 | 8114 | "Address of interface\n") |
718e3744 | 8115 | { |
d62a17ae | 8116 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8117 | int idx = 0; | |
8118 | struct in_addr addr; | |
8119 | struct ospf_if_params *params; | |
8120 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 8121 | uint32_t seconds = 0; |
d62a17ae | 8122 | |
8123 | argv_find(argv, argc, "(1-65535)", &idx); | |
8124 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8125 | ||
8126 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8127 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8128 | vty_out(vty, | |
8129 | "Please specify interface address by A.B.C.D\n"); | |
8130 | return CMD_WARNING_CONFIG_FAILED; | |
8131 | } | |
718e3744 | 8132 | |
d62a17ae | 8133 | params = ospf_get_if_params(ifp, addr); |
8134 | ospf_if_update_params(ifp, addr); | |
8135 | } | |
718e3744 | 8136 | |
d62a17ae | 8137 | SET_IF_PARAM(params, v_hello); |
8138 | params->v_hello = seconds; | |
718e3744 | 8139 | |
182d6bdc K |
8140 | if (!params->is_v_wait_set) { |
8141 | SET_IF_PARAM(params, v_wait); | |
8142 | /* As per RFC 4062 | |
8143 | * The router dead interval should | |
8144 | * be some multiple of the HelloInterval (perhaps 4 times the | |
8145 | * hello interval) and must be the same for all routers | |
8146 | * attached to a common network. | |
8147 | */ | |
8148 | params->v_wait = 4 * seconds; | |
8149 | } | |
8150 | ||
d62a17ae | 8151 | return CMD_SUCCESS; |
718e3744 | 8152 | } |
8153 | ||
7a7be519 | 8154 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 8155 | ospf_hello_interval_cmd, |
0d829fa7 | 8156 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8157 | "OSPF interface commands\n" |
8158 | "Time between HELLO packets\n" | |
0d829fa7 QY |
8159 | "Seconds\n" |
8160 | "Address of interface\n") | |
7a7be519 | 8161 | { |
d62a17ae | 8162 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 8163 | } |
718e3744 | 8164 | |
8165 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
8166 | no_ip_ospf_hello_interval_cmd, |
8167 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 8168 | NO_STR |
8169 | "IP Information\n" | |
8170 | "OSPF interface commands\n" | |
0d829fa7 | 8171 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 8172 | "Seconds\n" |
0d829fa7 | 8173 | "Address of interface\n") |
718e3744 | 8174 | { |
d62a17ae | 8175 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8176 | int idx = 0; | |
8177 | struct in_addr addr; | |
8178 | struct ospf_if_params *params; | |
182d6bdc | 8179 | struct route_node *rn; |
df581cd3 | 8180 | |
d62a17ae | 8181 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8182 | |
d62a17ae | 8183 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8184 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8185 | vty_out(vty, | |
8186 | "Please specify interface address by A.B.C.D\n"); | |
8187 | return CMD_WARNING_CONFIG_FAILED; | |
8188 | } | |
718e3744 | 8189 | |
d62a17ae | 8190 | params = ospf_lookup_if_params(ifp, addr); |
8191 | if (params == NULL) | |
8192 | return CMD_SUCCESS; | |
8193 | } | |
718e3744 | 8194 | |
d62a17ae | 8195 | UNSET_IF_PARAM(params, v_hello); |
8196 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 8197 | |
182d6bdc K |
8198 | if (!params->is_v_wait_set) { |
8199 | UNSET_IF_PARAM(params, v_wait); | |
8200 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
8201 | } | |
8202 | ||
8203 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8204 | struct ospf_interface *oi = rn->info; | |
8205 | ||
8206 | if (!oi) | |
8207 | continue; | |
8208 | ||
8209 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
8210 | ||
8211 | if (oi->state > ISM_Down) { | |
8212 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8213 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8214 | } | |
8215 | } | |
8216 | ||
d62a17ae | 8217 | if (params != IF_DEF_PARAMS(ifp)) { |
8218 | ospf_free_if_params(ifp, addr); | |
8219 | ospf_if_update_params(ifp, addr); | |
8220 | } | |
718e3744 | 8221 | |
d62a17ae | 8222 | return CMD_SUCCESS; |
718e3744 | 8223 | } |
8224 | ||
0d829fa7 QY |
8225 | DEFUN_HIDDEN (no_ospf_hello_interval, |
8226 | no_ospf_hello_interval_cmd, | |
8227 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
8228 | NO_STR | |
8229 | "OSPF interface commands\n" | |
8230 | "Time between HELLO packets\n" // ignored | |
8231 | "Seconds\n" | |
8232 | "Address of interface\n") | |
8233 | { | |
d62a17ae | 8234 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 8235 | } |
718e3744 | 8236 | |
8237 | DEFUN (ip_ospf_network, | |
8238 | ip_ospf_network_cmd, | |
6147e2c6 | 8239 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
718e3744 | 8240 | "IP Information\n" |
8241 | "OSPF interface commands\n" | |
8242 | "Network type\n" | |
8243 | "Specify OSPF broadcast multi-access network\n" | |
8244 | "Specify OSPF NBMA network\n" | |
8245 | "Specify OSPF point-to-multipoint network\n" | |
8246 | "Specify OSPF point-to-point network\n") | |
8247 | { | |
d62a17ae | 8248 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8249 | int idx = 0; | |
8250 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
8251 | struct route_node *rn; | |
718e3744 | 8252 | |
d62a17ae | 8253 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
8254 | vty_out(vty, | |
8255 | "This is a loopback interface. Can't set network type.\n"); | |
8256 | return CMD_WARNING_CONFIG_FAILED; | |
8257 | } | |
718e3744 | 8258 | |
d62a17ae | 8259 | if (argv_find(argv, argc, "broadcast", &idx)) |
8260 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
8261 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
8262 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
8263 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
8264 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
8265 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
8266 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
718e3744 | 8267 | |
d62a17ae | 8268 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
8269 | return CMD_SUCCESS; | |
8270 | ||
8271 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
8272 | ||
8273 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8274 | struct ospf_interface *oi = rn->info; | |
8275 | ||
8276 | if (!oi) | |
8277 | continue; | |
8278 | ||
8279 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
8280 | ||
8281 | if (oi->state > ISM_Down) { | |
8282 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8283 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8284 | } | |
7a7be519 | 8285 | } |
7a7be519 | 8286 | |
d62a17ae | 8287 | return CMD_SUCCESS; |
7a7be519 | 8288 | } |
8289 | ||
8290 | DEFUN_HIDDEN (ospf_network, | |
8291 | ospf_network_cmd, | |
e83a9414 | 8292 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 8293 | "OSPF interface commands\n" |
8294 | "Network type\n" | |
8295 | "Specify OSPF broadcast multi-access network\n" | |
8296 | "Specify OSPF NBMA network\n" | |
8297 | "Specify OSPF point-to-multipoint network\n" | |
8298 | "Specify OSPF point-to-point network\n") | |
8299 | { | |
d62a17ae | 8300 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 8301 | } |
8302 | ||
8303 | DEFUN (no_ip_ospf_network, | |
8304 | no_ip_ospf_network_cmd, | |
8305 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8306 | NO_STR | |
8307 | "IP Information\n" | |
8308 | "OSPF interface commands\n" | |
8309 | "Network type\n" | |
8310 | "Specify OSPF broadcast multi-access network\n" | |
8311 | "Specify OSPF NBMA network\n" | |
8312 | "Specify OSPF point-to-multipoint network\n" | |
8313 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 8314 | { |
d62a17ae | 8315 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8316 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
8317 | struct route_node *rn; | |
7a7be519 | 8318 | |
d62a17ae | 8319 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
7a7be519 | 8320 | |
d62a17ae | 8321 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
8322 | return CMD_SUCCESS; | |
7a7be519 | 8323 | |
d62a17ae | 8324 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8325 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8326 | |
d62a17ae | 8327 | if (!oi) |
8328 | continue; | |
7a7be519 | 8329 | |
d62a17ae | 8330 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 8331 | |
d62a17ae | 8332 | if (oi->state > ISM_Down) { |
8333 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8334 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8335 | } | |
7a7be519 | 8336 | } |
7a7be519 | 8337 | |
d62a17ae | 8338 | return CMD_SUCCESS; |
7a7be519 | 8339 | } |
8340 | ||
0d829fa7 QY |
8341 | DEFUN_HIDDEN (no_ospf_network, |
8342 | no_ospf_network_cmd, | |
8343 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8344 | NO_STR | |
8345 | "OSPF interface commands\n" | |
8346 | "Network type\n" | |
8347 | "Specify OSPF broadcast multi-access network\n" | |
8348 | "Specify OSPF NBMA network\n" | |
8349 | "Specify OSPF point-to-multipoint network\n" | |
8350 | "Specify OSPF point-to-point network\n") | |
8351 | { | |
d62a17ae | 8352 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
8353 | } |
8354 | ||
7a7be519 | 8355 | DEFUN (ip_ospf_priority, |
537eae3f | 8356 | ip_ospf_priority_cmd, |
7a7be519 | 8357 | "ip ospf priority (0-255) [A.B.C.D]", |
8358 | "IP Information\n" | |
8359 | "OSPF interface commands\n" | |
8360 | "Router priority\n" | |
8361 | "Priority\n" | |
efd7904e | 8362 | "Address of interface\n") |
7a7be519 | 8363 | { |
d62a17ae | 8364 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8365 | int idx = 0; | |
8366 | long priority; | |
8367 | struct route_node *rn; | |
8368 | struct in_addr addr; | |
8369 | struct ospf_if_params *params; | |
8370 | params = IF_DEF_PARAMS(ifp); | |
8371 | ||
8372 | argv_find(argv, argc, "(0-255)", &idx); | |
8373 | priority = strtol(argv[idx]->arg, NULL, 10); | |
8374 | ||
8375 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8376 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8377 | vty_out(vty, | |
8378 | "Please specify interface address by A.B.C.D\n"); | |
8379 | return CMD_WARNING_CONFIG_FAILED; | |
8380 | } | |
7a7be519 | 8381 | |
d62a17ae | 8382 | params = ospf_get_if_params(ifp, addr); |
8383 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 8384 | } |
8385 | ||
d62a17ae | 8386 | SET_IF_PARAM(params, priority); |
8387 | params->priority = priority; | |
7a7be519 | 8388 | |
d62a17ae | 8389 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8390 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8391 | |
d62a17ae | 8392 | if (!oi) |
8393 | continue; | |
7a7be519 | 8394 | |
d62a17ae | 8395 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
8396 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8397 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8398 | } | |
718e3744 | 8399 | } |
718e3744 | 8400 | |
d62a17ae | 8401 | return CMD_SUCCESS; |
718e3744 | 8402 | } |
8403 | ||
7a7be519 | 8404 | DEFUN_HIDDEN (ospf_priority, |
8405 | ospf_priority_cmd, | |
0d829fa7 | 8406 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 8407 | "OSPF interface commands\n" |
8408 | "Router priority\n" | |
3a2d747c | 8409 | "Priority\n" |
efd7904e | 8410 | "Address of interface\n") |
718e3744 | 8411 | { |
d62a17ae | 8412 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 8413 | } |
8414 | ||
718e3744 | 8415 | DEFUN (no_ip_ospf_priority, |
537eae3f | 8416 | no_ip_ospf_priority_cmd, |
7a7be519 | 8417 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 8418 | NO_STR |
8419 | "IP Information\n" | |
8420 | "OSPF interface commands\n" | |
0d829fa7 | 8421 | "Router priority\n" // ignored |
813d4307 | 8422 | "Priority\n" |
efd7904e | 8423 | "Address of interface\n") |
718e3744 | 8424 | { |
d62a17ae | 8425 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8426 | int idx = 0; | |
8427 | struct route_node *rn; | |
8428 | struct in_addr addr; | |
8429 | struct ospf_if_params *params; | |
8430 | ||
8431 | params = IF_DEF_PARAMS(ifp); | |
8432 | ||
8433 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8434 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8435 | vty_out(vty, | |
8436 | "Please specify interface address by A.B.C.D\n"); | |
8437 | return CMD_WARNING_CONFIG_FAILED; | |
8438 | } | |
8439 | ||
8440 | params = ospf_lookup_if_params(ifp, addr); | |
8441 | if (params == NULL) | |
8442 | return CMD_SUCCESS; | |
718e3744 | 8443 | } |
8444 | ||
d62a17ae | 8445 | UNSET_IF_PARAM(params, priority); |
8446 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
8447 | ||
8448 | if (params != IF_DEF_PARAMS(ifp)) { | |
8449 | ospf_free_if_params(ifp, addr); | |
8450 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8451 | } |
d62a17ae | 8452 | |
8453 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8454 | struct ospf_interface *oi = rn->info; | |
8455 | ||
8456 | if (!oi) | |
8457 | continue; | |
8458 | ||
8459 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
8460 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8461 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8462 | } | |
8463 | } | |
8464 | ||
8465 | return CMD_SUCCESS; | |
718e3744 | 8466 | } |
8467 | ||
0d829fa7 | 8468 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 8469 | no_ospf_priority_cmd, |
0d829fa7 QY |
8470 | "no ospf priority [(0-255) [A.B.C.D]]", |
8471 | NO_STR | |
8472 | "OSPF interface commands\n" | |
8473 | "Router priority\n" | |
8474 | "Priority\n" | |
efd7904e | 8475 | "Address of interface\n") |
0d829fa7 | 8476 | { |
d62a17ae | 8477 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 8478 | } |
a1afa410 | 8479 | |
718e3744 | 8480 | DEFUN (ip_ospf_retransmit_interval, |
8481 | ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8482 | "ip ospf retransmit-interval (1-65535) [A.B.C.D]", |
718e3744 | 8483 | "IP Information\n" |
8484 | "OSPF interface commands\n" | |
8485 | "Time between retransmitting lost link state advertisements\n" | |
8486 | "Seconds\n" | |
efd7904e | 8487 | "Address of interface\n") |
718e3744 | 8488 | { |
d62a17ae | 8489 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8490 | int idx = 0; | |
d7c0a89a | 8491 | uint32_t seconds; |
d62a17ae | 8492 | struct in_addr addr; |
8493 | struct ospf_if_params *params; | |
8494 | params = IF_DEF_PARAMS(ifp); | |
8495 | ||
d4badaf6 | 8496 | argv_find(argv, argc, "(1-65535)", &idx); |
d62a17ae | 8497 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8498 | ||
8499 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8500 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8501 | vty_out(vty, | |
8502 | "Please specify interface address by A.B.C.D\n"); | |
8503 | return CMD_WARNING_CONFIG_FAILED; | |
8504 | } | |
718e3744 | 8505 | |
d62a17ae | 8506 | params = ospf_get_if_params(ifp, addr); |
8507 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8508 | } |
8509 | ||
d62a17ae | 8510 | SET_IF_PARAM(params, retransmit_interval); |
8511 | params->retransmit_interval = seconds; | |
718e3744 | 8512 | |
d62a17ae | 8513 | return CMD_SUCCESS; |
718e3744 | 8514 | } |
8515 | ||
7a7be519 | 8516 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 8517 | ospf_retransmit_interval_cmd, |
d4badaf6 | 8518 | "ospf retransmit-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8519 | "OSPF interface commands\n" |
8520 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 8521 | "Seconds\n" |
efd7904e | 8522 | "Address of interface\n") |
7a7be519 | 8523 | { |
d62a17ae | 8524 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 8525 | } |
718e3744 | 8526 | |
8527 | DEFUN (no_ip_ospf_retransmit_interval, | |
8528 | no_ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8529 | "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
718e3744 | 8530 | NO_STR |
8531 | "IP Information\n" | |
8532 | "OSPF interface commands\n" | |
3a2d747c QY |
8533 | "Time between retransmitting lost link state advertisements\n" |
8534 | "Seconds\n" | |
0d829fa7 | 8535 | "Address of interface\n") |
718e3744 | 8536 | { |
d62a17ae | 8537 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8538 | int idx = 0; | |
8539 | struct in_addr addr; | |
8540 | struct ospf_if_params *params; | |
47b91972 | 8541 | |
d62a17ae | 8542 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8543 | |
d62a17ae | 8544 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8545 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8546 | vty_out(vty, | |
8547 | "Please specify interface address by A.B.C.D\n"); | |
8548 | return CMD_WARNING_CONFIG_FAILED; | |
8549 | } | |
718e3744 | 8550 | |
d62a17ae | 8551 | params = ospf_lookup_if_params(ifp, addr); |
8552 | if (params == NULL) | |
8553 | return CMD_SUCCESS; | |
8554 | } | |
718e3744 | 8555 | |
d62a17ae | 8556 | UNSET_IF_PARAM(params, retransmit_interval); |
8557 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 8558 | |
d62a17ae | 8559 | if (params != IF_DEF_PARAMS(ifp)) { |
8560 | ospf_free_if_params(ifp, addr); | |
8561 | ospf_if_update_params(ifp, addr); | |
8562 | } | |
718e3744 | 8563 | |
d62a17ae | 8564 | return CMD_SUCCESS; |
718e3744 | 8565 | } |
8566 | ||
0d829fa7 QY |
8567 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
8568 | no_ospf_retransmit_interval_cmd, | |
d4badaf6 | 8569 | "no ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
0d829fa7 QY |
8570 | NO_STR |
8571 | "OSPF interface commands\n" | |
3a2d747c QY |
8572 | "Time between retransmitting lost link state advertisements\n" |
8573 | "Seconds\n" | |
8574 | "Address of interface\n") | |
0d829fa7 | 8575 | { |
d62a17ae | 8576 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 8577 | } |
813d4307 | 8578 | |
718e3744 | 8579 | DEFUN (ip_ospf_transmit_delay, |
8580 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 8581 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 8582 | "IP Information\n" |
8583 | "OSPF interface commands\n" | |
8584 | "Link state transmit delay\n" | |
8585 | "Seconds\n" | |
efd7904e | 8586 | "Address of interface\n") |
718e3744 | 8587 | { |
d62a17ae | 8588 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8589 | int idx = 0; | |
d7c0a89a | 8590 | uint32_t seconds; |
d62a17ae | 8591 | struct in_addr addr; |
8592 | struct ospf_if_params *params; | |
8593 | ||
8594 | params = IF_DEF_PARAMS(ifp); | |
8595 | argv_find(argv, argc, "(1-65535)", &idx); | |
8596 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8597 | ||
8598 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8599 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8600 | vty_out(vty, | |
8601 | "Please specify interface address by A.B.C.D\n"); | |
8602 | return CMD_WARNING_CONFIG_FAILED; | |
8603 | } | |
718e3744 | 8604 | |
d62a17ae | 8605 | params = ospf_get_if_params(ifp, addr); |
8606 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8607 | } |
8608 | ||
d62a17ae | 8609 | SET_IF_PARAM(params, transmit_delay); |
8610 | params->transmit_delay = seconds; | |
718e3744 | 8611 | |
d62a17ae | 8612 | return CMD_SUCCESS; |
718e3744 | 8613 | } |
8614 | ||
7a7be519 | 8615 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 8616 | ospf_transmit_delay_cmd, |
0d829fa7 | 8617 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
8618 | "OSPF interface commands\n" |
8619 | "Link state transmit delay\n" | |
3a2d747c | 8620 | "Seconds\n" |
efd7904e | 8621 | "Address of interface\n") |
7a7be519 | 8622 | { |
d62a17ae | 8623 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 8624 | } |
718e3744 | 8625 | |
8626 | DEFUN (no_ip_ospf_transmit_delay, | |
8627 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 8628 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 8629 | NO_STR |
8630 | "IP Information\n" | |
8631 | "OSPF interface commands\n" | |
8632 | "Link state transmit delay\n" | |
efd7904e RW |
8633 | "Seconds\n" |
8634 | "Address of interface\n") | |
718e3744 | 8635 | { |
d62a17ae | 8636 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8637 | int idx = 0; | |
8638 | struct in_addr addr; | |
8639 | struct ospf_if_params *params; | |
718e3744 | 8640 | |
d62a17ae | 8641 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8642 | |
d62a17ae | 8643 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8644 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8645 | vty_out(vty, | |
8646 | "Please specify interface address by A.B.C.D\n"); | |
8647 | return CMD_WARNING_CONFIG_FAILED; | |
8648 | } | |
718e3744 | 8649 | |
d62a17ae | 8650 | params = ospf_lookup_if_params(ifp, addr); |
8651 | if (params == NULL) | |
8652 | return CMD_SUCCESS; | |
8653 | } | |
718e3744 | 8654 | |
d62a17ae | 8655 | UNSET_IF_PARAM(params, transmit_delay); |
8656 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 8657 | |
d62a17ae | 8658 | if (params != IF_DEF_PARAMS(ifp)) { |
8659 | ospf_free_if_params(ifp, addr); | |
8660 | ospf_if_update_params(ifp, addr); | |
8661 | } | |
8662 | ||
8663 | return CMD_SUCCESS; | |
718e3744 | 8664 | } |
8665 | ||
813d4307 | 8666 | |
0d829fa7 QY |
8667 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
8668 | no_ospf_transmit_delay_cmd, | |
32573073 | 8669 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
8670 | NO_STR |
8671 | "OSPF interface commands\n" | |
32573073 QY |
8672 | "Link state transmit delay\n" |
8673 | "Seconds\n" | |
efd7904e | 8674 | "Address of interface\n") |
813d4307 | 8675 | { |
d62a17ae | 8676 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
8677 | } |
8678 | ||
e723861d DS |
8679 | DEFUN (ip_ospf_area, |
8680 | ip_ospf_area_cmd, | |
52c62ab8 | 8681 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
8682 | "IP Information\n" |
8683 | "OSPF interface commands\n" | |
7a7be519 | 8684 | "Instance ID\n" |
e723861d DS |
8685 | "Enable OSPF on this interface\n" |
8686 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8687 | "OSPF area ID as a decimal value\n" |
8688 | "Address of interface\n") | |
e723861d | 8689 | { |
d62a17ae | 8690 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8691 | int idx = 0; | |
8692 | int format, ret; | |
8693 | struct in_addr area_id; | |
8694 | struct in_addr addr; | |
35955c14 | 8695 | struct ospf_if_params *params = NULL; |
d62a17ae | 8696 | struct route_node *rn; |
b5a8894d | 8697 | struct ospf *ospf = NULL; |
d7c0a89a | 8698 | unsigned short instance = 0; |
d62a17ae | 8699 | char *areaid; |
15bf52d3 | 8700 | uint32_t count = 0; |
d62a17ae | 8701 | |
8702 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8703 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8704 | ||
8705 | argv_find(argv, argc, "area", &idx); | |
8706 | areaid = argv[idx + 1]->arg; | |
8707 | ||
a36898e7 DS |
8708 | if (ifp->vrf_id && !instance) |
8709 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
8710 | else |
8711 | ospf = ospf_lookup_instance(instance); | |
8712 | ||
aed7cc62 | 8713 | if (instance && ospf == NULL) { |
2b0a32da DS |
8714 | /* |
8715 | * At this point we know we have received | |
8716 | * an instance and there is no ospf instance | |
8717 | * associated with it. This means we are | |
8718 | * in a situation where we have an | |
8719 | * ospf command that is setup for a different | |
8720 | * process(instance). We need to safely | |
8721 | * remove the command from ourselves and | |
8722 | * allow the other instance(process) handle | |
8723 | * the configuration command. | |
8724 | */ | |
15bf52d3 IR |
8725 | count = 0; |
8726 | ||
d62a17ae | 8727 | params = IF_DEF_PARAMS(ifp); |
8728 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8729 | UNSET_IF_PARAM(params, if_area); | |
15bf52d3 IR |
8730 | count++; |
8731 | } | |
8732 | ||
8733 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) | |
8734 | if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8735 | UNSET_IF_PARAM(params, if_area); | |
8736 | count++; | |
8737 | } | |
8738 | ||
8739 | if (count > 0) { | |
8740 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
2b0a32da DS |
8741 | if (ospf) { |
8742 | ospf_interface_area_unset(ospf, ifp); | |
15bf52d3 | 8743 | ospf->if_ospf_cli_count -= count; |
2b0a32da | 8744 | } |
d62a17ae | 8745 | } |
15bf52d3 | 8746 | |
ac28e4ec | 8747 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8748 | } |
e723861d | 8749 | |
d62a17ae | 8750 | ret = str2area_id(areaid, &area_id, &format); |
8751 | if (ret < 0) { | |
8752 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8753 | return CMD_WARNING_CONFIG_FAILED; | |
8754 | } | |
8755 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8756 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8757 | return CMD_WARNING_CONFIG_FAILED; | |
8758 | } | |
8759 | ||
eb364867 IR |
8760 | if (ospf) { |
8761 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8762 | if (rn->info != NULL) { | |
8763 | vty_out(vty, | |
8764 | "Please remove all network commands first.\n"); | |
8765 | return CMD_WARNING_CONFIG_FAILED; | |
8766 | } | |
8767 | } | |
8768 | } | |
8769 | ||
d62a17ae | 8770 | params = IF_DEF_PARAMS(ifp); |
8771 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8772 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8773 | vty_out(vty, | |
8774 | "Must remove previous area config before changing ospf area \n"); | |
8775 | return CMD_WARNING_CONFIG_FAILED; | |
8776 | } | |
8777 | ||
8778 | // Check if we have an address arg and proccess it | |
8779 | if (argc == idx + 3) { | |
cc9b06ad | 8780 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8781 | vty_out(vty, |
8782 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8783 | return CMD_WARNING_CONFIG_FAILED; |
8784 | } | |
d62a17ae | 8785 | // update/create address-level params |
8786 | params = ospf_get_if_params((ifp), (addr)); | |
8787 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8788 | vty_out(vty, | |
e7378cb1 | 8789 | "Must remove previous area/address config before changing ospf area\n"); |
d62a17ae | 8790 | return CMD_WARNING_CONFIG_FAILED; |
8791 | } | |
8792 | ospf_if_update_params((ifp), (addr)); | |
8793 | } | |
8794 | ||
d62a17ae | 8795 | /* enable ospf on this interface with area_id */ |
35955c14 CS |
8796 | if (params) { |
8797 | SET_IF_PARAM(params, if_area); | |
8798 | params->if_area = area_id; | |
8799 | params->if_area_id_fmt = format; | |
8800 | } | |
aed7cc62 CS |
8801 | |
8802 | if (ospf) { | |
8803 | ospf_interface_area_set(ospf, ifp); | |
8804 | ospf->if_ospf_cli_count++; | |
8805 | } | |
d62a17ae | 8806 | |
8807 | return CMD_SUCCESS; | |
e723861d DS |
8808 | } |
8809 | ||
8810 | DEFUN (no_ip_ospf_area, | |
8811 | no_ip_ospf_area_cmd, | |
52c62ab8 | 8812 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
8813 | NO_STR |
8814 | "IP Information\n" | |
8815 | "OSPF interface commands\n" | |
3a2d747c | 8816 | "Instance ID\n" |
7a7be519 | 8817 | "Disable OSPF on this interface\n" |
8818 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8819 | "OSPF area ID as a decimal value\n" |
8820 | "Address of interface\n") | |
e723861d | 8821 | { |
d62a17ae | 8822 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8823 | int idx = 0; | |
8824 | struct ospf *ospf; | |
8825 | struct ospf_if_params *params; | |
d7c0a89a | 8826 | unsigned short instance = 0; |
d62a17ae | 8827 | struct in_addr addr; |
8828 | ||
8829 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8830 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8831 | ||
a36898e7 DS |
8832 | if (ifp->vrf_id && !instance) |
8833 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
8834 | else |
8835 | ospf = ospf_lookup_instance(instance); | |
8836 | ||
e4129293 | 8837 | if (instance && ospf == NULL) |
ac28e4ec | 8838 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8839 | |
8840 | argv_find(argv, argc, "area", &idx); | |
8841 | ||
8842 | // Check if we have an address arg and proccess it | |
8843 | if (argc == idx + 3) { | |
cc9b06ad | 8844 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8845 | vty_out(vty, |
8846 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8847 | return CMD_WARNING_CONFIG_FAILED; |
8848 | } | |
d62a17ae | 8849 | params = ospf_lookup_if_params(ifp, addr); |
8850 | if ((params) == NULL) | |
8851 | return CMD_SUCCESS; | |
8852 | } else | |
8853 | params = IF_DEF_PARAMS(ifp); | |
8854 | ||
8855 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8856 | vty_out(vty, | |
8857 | "Can't find specified interface area configuration.\n"); | |
8858 | return CMD_WARNING_CONFIG_FAILED; | |
8859 | } | |
813d4307 | 8860 | |
d62a17ae | 8861 | UNSET_IF_PARAM(params, if_area); |
8862 | if (params != IF_DEF_PARAMS((ifp))) { | |
8863 | ospf_free_if_params((ifp), (addr)); | |
8864 | ospf_if_update_params((ifp), (addr)); | |
8865 | } | |
8866 | ||
e4129293 IR |
8867 | if (ospf) { |
8868 | ospf_interface_area_unset(ospf, ifp); | |
8869 | ospf->if_ospf_cli_count--; | |
8870 | } | |
8871 | ||
d62a17ae | 8872 | return CMD_SUCCESS; |
813d4307 DW |
8873 | } |
8874 | ||
6f2a6703 CF |
8875 | DEFUN (ospf_redistribute_source, |
8876 | ospf_redistribute_source_cmd, | |
ea38ced1 | 8877 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
d1c65c21 | 8878 | REDIST_STR |
ab0181ee | 8879 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 8880 | "Metric for redistributed routes\n" |
8881 | "OSPF default metric\n" | |
8882 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8883 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8884 | "Route map reference\n" |
8885 | "Pointer to route-map entries\n") | |
8886 | { | |
a3d826f0 | 8887 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8888 | int idx_protocol = 1; |
8889 | int source; | |
8890 | int type = -1; | |
8891 | int metric = -1; | |
8892 | struct ospf_redist *red; | |
8893 | int idx = 0; | |
6f2a6703 | 8894 | |
d62a17ae | 8895 | /* Get distribute source. */ |
8896 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
8897 | if (source < 0) | |
8898 | return CMD_WARNING_CONFIG_FAILED; | |
8899 | ||
8900 | red = ospf_redist_add(ospf, source, 0); | |
8901 | ||
8902 | /* Get metric value. */ | |
8903 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
8904 | if (!str2metric(argv[idx]->arg, &metric)) | |
8905 | return CMD_WARNING_CONFIG_FAILED; | |
8906 | } | |
951da435 | 8907 | idx = 1; |
d62a17ae | 8908 | /* Get metric type. */ |
ea38ced1 | 8909 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 8910 | if (!str2metric_type(argv[idx]->arg, &type)) |
8911 | return CMD_WARNING_CONFIG_FAILED; | |
8912 | } | |
951da435 | 8913 | idx = 1; |
d62a17ae | 8914 | /* Get route-map */ |
ea38ced1 | 8915 | if (argv_find(argv, argc, "WORD", &idx)) { |
d62a17ae | 8916 | ospf_routemap_set(red, argv[idx]->arg); |
8917 | } else | |
8918 | ospf_routemap_unset(red); | |
7c8ff89e | 8919 | |
d62a17ae | 8920 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 8921 | } |
8922 | ||
718e3744 | 8923 | DEFUN (no_ospf_redistribute_source, |
8924 | no_ospf_redistribute_source_cmd, | |
ea38ced1 | 8925 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8926 | NO_STR |
d1c65c21 | 8927 | REDIST_STR |
ab0181ee | 8928 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
8929 | "Metric for redistributed routes\n" |
8930 | "OSPF default metric\n" | |
8931 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8932 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8933 | "Route map reference\n" |
8934 | "Pointer to route-map entries\n") | |
718e3744 | 8935 | { |
a3d826f0 | 8936 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8937 | int idx_protocol = 2; |
8938 | int source; | |
8939 | struct ospf_redist *red; | |
718e3744 | 8940 | |
d62a17ae | 8941 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
8942 | if (source < 0) | |
8943 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8944 | |
d62a17ae | 8945 | red = ospf_redist_lookup(ospf, source, 0); |
8946 | if (!red) | |
8947 | return CMD_SUCCESS; | |
7c8ff89e | 8948 | |
d62a17ae | 8949 | ospf_routemap_unset(red); |
766b826f DA |
8950 | ospf_redist_del(ospf, source, 0); |
8951 | ||
d62a17ae | 8952 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
8953 | } |
8954 | ||
8955 | DEFUN (ospf_redistribute_instance_source, | |
8956 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8957 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8958 | REDIST_STR |
8959 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8960 | "Non-main Kernel Routing Table\n" |
8961 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
8962 | "Metric for redistributed routes\n" |
8963 | "OSPF default metric\n" | |
8964 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8965 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8966 | "Route map reference\n" |
8967 | "Pointer to route-map entries\n") | |
8968 | { | |
a3d826f0 | 8969 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8970 | int idx_ospf_table = 1; |
8971 | int idx_number = 2; | |
8972 | int idx = 3; | |
8973 | int source; | |
8974 | int type = -1; | |
8975 | int metric = -1; | |
d7c0a89a | 8976 | unsigned short instance; |
d62a17ae | 8977 | struct ospf_redist *red; |
7c8ff89e | 8978 | |
d62a17ae | 8979 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 8980 | |
13f0e434 | 8981 | if (source < 0) { |
8982 | vty_out(vty, "Unknown instance redistribution\n"); | |
8983 | return CMD_WARNING_CONFIG_FAILED; | |
8984 | } | |
8985 | ||
d62a17ae | 8986 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 8987 | |
d62a17ae | 8988 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8989 | vty_out(vty, | |
8990 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8991 | return CMD_WARNING_CONFIG_FAILED; | |
8992 | } | |
7c8ff89e | 8993 | |
d62a17ae | 8994 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
8995 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8996 | return CMD_WARNING_CONFIG_FAILED; | |
8997 | } | |
7c8ff89e | 8998 | |
d62a17ae | 8999 | /* Get metric value. */ |
9000 | if (argv_find(argv, argc, "metric", &idx)) | |
9001 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
9002 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9003 | |
d62a17ae | 9004 | idx = 3; |
9005 | /* Get metric type. */ | |
9006 | if (argv_find(argv, argc, "metric-type", &idx)) | |
9007 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
9008 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9009 | |
d62a17ae | 9010 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 9011 | |
d62a17ae | 9012 | idx = 3; |
9013 | if (argv_find(argv, argc, "route-map", &idx)) | |
9014 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
9015 | else | |
9016 | ospf_routemap_unset(red); | |
7c8ff89e | 9017 | |
d62a17ae | 9018 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
9019 | } |
9020 | ||
9021 | DEFUN (no_ospf_redistribute_instance_source, | |
9022 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9023 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9024 | NO_STR |
9025 | REDIST_STR | |
9026 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9027 | "Non-main Kernel Routing Table\n" |
9028 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
9029 | "Metric for redistributed routes\n" |
9030 | "OSPF default metric\n" | |
9031 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9032 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9033 | "Route map reference\n" |
9034 | "Pointer to route-map entries\n") | |
9035 | { | |
a3d826f0 | 9036 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9037 | int idx_ospf_table = 2; |
9038 | int idx_number = 3; | |
d7c0a89a | 9039 | unsigned int instance; |
d62a17ae | 9040 | struct ospf_redist *red; |
9041 | int source; | |
9042 | ||
9043 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
9044 | source = ZEBRA_ROUTE_OSPF; | |
9045 | else | |
9046 | source = ZEBRA_ROUTE_TABLE; | |
9047 | ||
9048 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 9049 | |
d62a17ae | 9050 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9051 | vty_out(vty, | |
9052 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9053 | return CMD_WARNING_CONFIG_FAILED; | |
9054 | } | |
9055 | ||
9056 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
9057 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9058 | return CMD_WARNING_CONFIG_FAILED; | |
9059 | } | |
9060 | ||
9061 | red = ospf_redist_lookup(ospf, source, instance); | |
9062 | if (!red) | |
9063 | return CMD_SUCCESS; | |
9064 | ||
9065 | ospf_routemap_unset(red); | |
766b826f DA |
9066 | ospf_redist_del(ospf, source, instance); |
9067 | ||
d62a17ae | 9068 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 9069 | } |
9070 | ||
9071 | DEFUN (ospf_distribute_list_out, | |
9072 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 9073 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 9074 | "Filter networks in routing updates\n" |
6f2a6703 CF |
9075 | "Access-list name\n" |
9076 | OUT_STR | |
ab0181ee | 9077 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9078 | { |
a3d826f0 | 9079 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9080 | int idx_word = 1; |
9081 | int source; | |
718e3744 | 9082 | |
d62a17ae | 9083 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 9084 | |
d62a17ae | 9085 | /* Get distribute source. */ |
9086 | source = proto_redistnum(AFI_IP, proto); | |
9087 | if (source < 0) | |
9088 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9089 | |
d62a17ae | 9090 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 9091 | } |
9092 | ||
6f2a6703 CF |
9093 | DEFUN (no_ospf_distribute_list_out, |
9094 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 9095 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
9096 | NO_STR |
9097 | "Filter networks in routing updates\n" | |
9098 | "Access-list name\n" | |
9099 | OUT_STR | |
ab0181ee | 9100 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9101 | { |
a3d826f0 | 9102 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9103 | int idx_word = 2; |
9104 | int source; | |
020709f9 | 9105 | |
d62a17ae | 9106 | char *proto = argv[argc - 1]->text; |
9107 | source = proto_redistnum(AFI_IP, proto); | |
9108 | if (source < 0) | |
9109 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9110 | |
d62a17ae | 9111 | return ospf_distribute_list_out_unset(ospf, source, |
9112 | argv[idx_word]->arg); | |
718e3744 | 9113 | } |
9114 | ||
6f2a6703 CF |
9115 | /* Default information originate. */ |
9116 | DEFUN (ospf_default_information_originate, | |
9117 | ospf_default_information_originate_cmd, | |
ea38ced1 | 9118 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9119 | "Control distribution of default information\n" |
9120 | "Distribute a default route\n" | |
9121 | "Always advertise default route\n" | |
6f2a6703 CF |
9122 | "OSPF default metric\n" |
9123 | "OSPF metric\n" | |
718e3744 | 9124 | "OSPF metric type for default routes\n" |
7111c1a0 | 9125 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9126 | "Route map reference\n" |
9127 | "Pointer to route-map entries\n") | |
9128 | { | |
a3d826f0 | 9129 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9130 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
9131 | int type = -1; | |
9132 | int metric = -1; | |
9133 | struct ospf_redist *red; | |
9134 | int idx = 0; | |
1fb93326 | 9135 | int cur_originate = ospf->default_originate; |
9136 | int sameRtmap = 0; | |
9137 | char *rtmap = NULL; | |
d62a17ae | 9138 | |
9139 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
9140 | ||
9141 | /* Check whether "always" was specified */ | |
9142 | if (argv_find(argv, argc, "always", &idx)) | |
9143 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 9144 | idx = 1; |
d62a17ae | 9145 | /* Get metric value */ |
ea38ced1 | 9146 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 9147 | if (!str2metric(argv[idx]->arg, &metric)) |
9148 | return CMD_WARNING_CONFIG_FAILED; | |
9149 | } | |
951da435 | 9150 | idx = 1; |
d62a17ae | 9151 | /* Get metric type. */ |
ea38ced1 | 9152 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9153 | if (!str2metric_type(argv[idx]->arg, &type)) |
9154 | return CMD_WARNING_CONFIG_FAILED; | |
9155 | } | |
951da435 | 9156 | idx = 1; |
d62a17ae | 9157 | /* Get route-map */ |
ea38ced1 | 9158 | if (argv_find(argv, argc, "WORD", &idx)) |
1fb93326 | 9159 | rtmap = argv[idx]->arg; |
9160 | ||
9161 | /* To check ,if user is providing same route map */ | |
9162 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
9163 | (rtmap && ROUTEMAP_NAME(red) | |
9164 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
9165 | sameRtmap = 1; | |
9166 | ||
9167 | /* Don't allow if the same lsa is aleardy originated. */ | |
9168 | if ((sameRtmap) | |
9169 | && (red->dmetric.type == type) | |
9170 | && (red->dmetric.value == metric) | |
9171 | && (cur_originate == default_originate)) | |
9172 | return CMD_SUCCESS; | |
9173 | ||
9174 | /* Updating Metric details */ | |
9175 | red->dmetric.type = type; | |
9176 | red->dmetric.value = metric; | |
9177 | ||
9178 | /* updating route map details */ | |
9179 | if (rtmap) | |
9180 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 9181 | else |
9182 | ospf_routemap_unset(red); | |
9183 | ||
9184 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
9185 | metric); | |
718e3744 | 9186 | } |
9187 | ||
9188 | DEFUN (no_ospf_default_information_originate, | |
9189 | no_ospf_default_information_originate_cmd, | |
ea38ced1 | 9190 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9191 | NO_STR |
9192 | "Control distribution of default information\n" | |
813d4307 DW |
9193 | "Distribute a default route\n" |
9194 | "Always advertise default route\n" | |
9195 | "OSPF default metric\n" | |
9196 | "OSPF metric\n" | |
9197 | "OSPF metric type for default routes\n" | |
7111c1a0 | 9198 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9199 | "Route map reference\n" |
9200 | "Pointer to route-map entries\n") | |
718e3744 | 9201 | { |
a3d826f0 | 9202 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9203 | struct ospf_redist *red; |
7c8ff89e | 9204 | |
d62a17ae | 9205 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9206 | if (!red) | |
9207 | return CMD_SUCCESS; | |
7c8ff89e | 9208 | |
d62a17ae | 9209 | ospf_routemap_unset(red); |
766b826f DA |
9210 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
9211 | ||
d5eac1e0 DL |
9212 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
9213 | 0, 0); | |
718e3744 | 9214 | } |
9215 | ||
9216 | DEFUN (ospf_default_metric, | |
9217 | ospf_default_metric_cmd, | |
6147e2c6 | 9218 | "default-metric (0-16777214)", |
718e3744 | 9219 | "Set metric of redistributed routes\n" |
9220 | "Default metric\n") | |
9221 | { | |
a3d826f0 | 9222 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9223 | int idx_number = 1; |
9224 | int metric = -1; | |
718e3744 | 9225 | |
d62a17ae | 9226 | if (!str2metric(argv[idx_number]->arg, &metric)) |
9227 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9228 | |
d62a17ae | 9229 | ospf->default_metric = metric; |
718e3744 | 9230 | |
d62a17ae | 9231 | return CMD_SUCCESS; |
718e3744 | 9232 | } |
9233 | ||
9234 | DEFUN (no_ospf_default_metric, | |
9235 | no_ospf_default_metric_cmd, | |
7a7be519 | 9236 | "no default-metric [(0-16777214)]", |
718e3744 | 9237 | NO_STR |
7a7be519 | 9238 | "Set metric of redistributed routes\n" |
9239 | "Default metric\n") | |
718e3744 | 9240 | { |
a3d826f0 | 9241 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9242 | |
d62a17ae | 9243 | ospf->default_metric = -1; |
68980084 | 9244 | |
d62a17ae | 9245 | return CMD_SUCCESS; |
718e3744 | 9246 | } |
9247 | ||
718e3744 | 9248 | |
9249 | DEFUN (ospf_distance, | |
9250 | ospf_distance_cmd, | |
6147e2c6 | 9251 | "distance (1-255)", |
eaa1ae0d | 9252 | "Administrative distance\n" |
718e3744 | 9253 | "OSPF Administrative distance\n") |
9254 | { | |
a3d826f0 | 9255 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9256 | int idx_number = 1; |
68980084 | 9257 | |
d62a17ae | 9258 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 9259 | |
d62a17ae | 9260 | return CMD_SUCCESS; |
718e3744 | 9261 | } |
9262 | ||
9263 | DEFUN (no_ospf_distance, | |
9264 | no_ospf_distance_cmd, | |
6147e2c6 | 9265 | "no distance (1-255)", |
718e3744 | 9266 | NO_STR |
eaa1ae0d | 9267 | "Administrative distance\n" |
718e3744 | 9268 | "OSPF Administrative distance\n") |
9269 | { | |
a3d826f0 | 9270 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9271 | |
d62a17ae | 9272 | ospf->distance_all = 0; |
68980084 | 9273 | |
d62a17ae | 9274 | return CMD_SUCCESS; |
718e3744 | 9275 | } |
9276 | ||
9277 | DEFUN (no_ospf_distance_ospf, | |
9278 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 9279 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 9280 | NO_STR |
eaa1ae0d QY |
9281 | "Administrative distance\n" |
9282 | "OSPF administrative distance\n" | |
718e3744 | 9283 | "Intra-area routes\n" |
813d4307 | 9284 | "Distance for intra-area routes\n" |
718e3744 | 9285 | "Inter-area routes\n" |
813d4307 DW |
9286 | "Distance for inter-area routes\n" |
9287 | "External routes\n" | |
9288 | "Distance for external routes\n") | |
718e3744 | 9289 | { |
a3d826f0 | 9290 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9291 | int idx = 0; |
718e3744 | 9292 | |
d62a17ae | 9293 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
9294 | idx = ospf->distance_intra = 0; | |
9295 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
9296 | idx = ospf->distance_inter = 0; | |
9297 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
9298 | ospf->distance_external = 0; | |
718e3744 | 9299 | |
d62a17ae | 9300 | return CMD_SUCCESS; |
718e3744 | 9301 | } |
9302 | ||
6f2a6703 CF |
9303 | DEFUN (ospf_distance_ospf, |
9304 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
9305 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
9306 | "Administrative distance\n" | |
9307 | "OSPF administrative distance\n" | |
718e3744 | 9308 | "Intra-area routes\n" |
9309 | "Distance for intra-area routes\n" | |
718e3744 | 9310 | "Inter-area routes\n" |
9311 | "Distance for inter-area routes\n" | |
9312 | "External routes\n" | |
718e3744 | 9313 | "Distance for external routes\n") |
9314 | { | |
a3d826f0 | 9315 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9316 | int idx = 0; |
68980084 | 9317 | |
926b88f0 CS |
9318 | ospf->distance_intra = 0; |
9319 | ospf->distance_inter = 0; | |
9320 | ospf->distance_external = 0; | |
9321 | ||
d62a17ae | 9322 | if (argv_find(argv, argc, "intra-area", &idx)) |
9323 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
9324 | idx = 0; | |
9325 | if (argv_find(argv, argc, "inter-area", &idx)) | |
9326 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
9327 | idx = 0; | |
9328 | if (argv_find(argv, argc, "external", &idx)) | |
9329 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 9330 | |
d62a17ae | 9331 | return CMD_SUCCESS; |
718e3744 | 9332 | } |
9333 | ||
d7d73ffc | 9334 | #if 0 |
718e3744 | 9335 | DEFUN (ospf_distance_source, |
9336 | ospf_distance_source_cmd, | |
6147e2c6 | 9337 | "distance (1-255) A.B.C.D/M", |
718e3744 | 9338 | "Administrative distance\n" |
9339 | "Distance value\n" | |
9340 | "IP source prefix\n") | |
9341 | { | |
cdc2d765 | 9342 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
9343 | int idx_number = 1; |
9344 | int idx_ipv4_prefixlen = 2; | |
020709f9 | 9345 | |
8d769265 | 9346 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
68980084 | 9347 | |
718e3744 | 9348 | return CMD_SUCCESS; |
9349 | } | |
9350 | ||
9351 | DEFUN (no_ospf_distance_source, | |
9352 | no_ospf_distance_source_cmd, | |
6147e2c6 | 9353 | "no distance (1-255) A.B.C.D/M", |
718e3744 | 9354 | NO_STR |
9355 | "Administrative distance\n" | |
9356 | "Distance value\n" | |
9357 | "IP source prefix\n") | |
9358 | { | |
cdc2d765 | 9359 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
9360 | int idx_number = 2; |
9361 | int idx_ipv4_prefixlen = 3; | |
020709f9 | 9362 | |
8d769265 | 9363 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
020709f9 | 9364 | |
718e3744 | 9365 | return CMD_SUCCESS; |
9366 | } | |
9367 | ||
9368 | DEFUN (ospf_distance_source_access_list, | |
9369 | ospf_distance_source_access_list_cmd, | |
6147e2c6 | 9370 | "distance (1-255) A.B.C.D/M WORD", |
718e3744 | 9371 | "Administrative distance\n" |
9372 | "Distance value\n" | |
9373 | "IP source prefix\n" | |
9374 | "Access list name\n") | |
9375 | { | |
cdc2d765 | 9376 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
9377 | int idx_number = 1; |
9378 | int idx_ipv4_prefixlen = 2; | |
9379 | int idx_word = 3; | |
020709f9 | 9380 | |
8d769265 | 9381 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 9382 | |
718e3744 | 9383 | return CMD_SUCCESS; |
9384 | } | |
9385 | ||
9386 | DEFUN (no_ospf_distance_source_access_list, | |
9387 | no_ospf_distance_source_access_list_cmd, | |
6147e2c6 | 9388 | "no distance (1-255) A.B.C.D/M WORD", |
718e3744 | 9389 | NO_STR |
9390 | "Administrative distance\n" | |
9391 | "Distance value\n" | |
9392 | "IP source prefix\n" | |
9393 | "Access list name\n") | |
9394 | { | |
cdc2d765 | 9395 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
9396 | int idx_number = 2; |
9397 | int idx_ipv4_prefixlen = 3; | |
9398 | int idx_word = 4; | |
020709f9 | 9399 | |
8d769265 | 9400 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 9401 | |
718e3744 | 9402 | return CMD_SUCCESS; |
9403 | } | |
d7d73ffc | 9404 | #endif |
718e3744 | 9405 | |
ba682537 | 9406 | DEFUN (ip_ospf_mtu_ignore, |
9407 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9408 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 9409 | "IP Information\n" |
9410 | "OSPF interface commands\n" | |
99a522c7 | 9411 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9412 | "Address of interface\n") |
ba682537 | 9413 | { |
d62a17ae | 9414 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9415 | int idx_ipv4 = 3; | |
9416 | struct in_addr addr; | |
9417 | int ret; | |
9418 | ||
9419 | struct ospf_if_params *params; | |
9420 | params = IF_DEF_PARAMS(ifp); | |
9421 | ||
9422 | if (argc == 4) { | |
9423 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9424 | if (!ret) { | |
9425 | vty_out(vty, | |
9426 | "Please specify interface address by A.B.C.D\n"); | |
9427 | return CMD_WARNING_CONFIG_FAILED; | |
9428 | } | |
9429 | params = ospf_get_if_params(ifp, addr); | |
9430 | ospf_if_update_params(ifp, addr); | |
9431 | } | |
9432 | params->mtu_ignore = 1; | |
9433 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9434 | SET_IF_PARAM(params, mtu_ignore); | |
9435 | else { | |
9436 | UNSET_IF_PARAM(params, mtu_ignore); | |
9437 | if (params != IF_DEF_PARAMS(ifp)) { | |
9438 | ospf_free_if_params(ifp, addr); | |
9439 | ospf_if_update_params(ifp, addr); | |
9440 | } | |
9441 | } | |
9442 | return CMD_SUCCESS; | |
ba682537 | 9443 | } |
9444 | ||
ba682537 | 9445 | DEFUN (no_ip_ospf_mtu_ignore, |
9446 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9447 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 9448 | NO_STR |
ba682537 | 9449 | "IP Information\n" |
9450 | "OSPF interface commands\n" | |
99a522c7 | 9451 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9452 | "Address of interface\n") |
ba682537 | 9453 | { |
d62a17ae | 9454 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9455 | int idx_ipv4 = 4; | |
9456 | struct in_addr addr; | |
9457 | int ret; | |
9458 | ||
9459 | struct ospf_if_params *params; | |
9460 | params = IF_DEF_PARAMS(ifp); | |
9461 | ||
9462 | if (argc == 5) { | |
9463 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9464 | if (!ret) { | |
9465 | vty_out(vty, | |
9466 | "Please specify interface address by A.B.C.D\n"); | |
9467 | return CMD_WARNING_CONFIG_FAILED; | |
9468 | } | |
9469 | params = ospf_get_if_params(ifp, addr); | |
9470 | ospf_if_update_params(ifp, addr); | |
9471 | } | |
9472 | params->mtu_ignore = 0; | |
9473 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9474 | SET_IF_PARAM(params, mtu_ignore); | |
9475 | else { | |
9476 | UNSET_IF_PARAM(params, mtu_ignore); | |
9477 | if (params != IF_DEF_PARAMS(ifp)) { | |
9478 | ospf_free_if_params(ifp, addr); | |
9479 | ospf_if_update_params(ifp, addr); | |
9480 | } | |
9481 | } | |
9482 | return CMD_SUCCESS; | |
ba682537 | 9483 | } |
9484 | ||
6b0655a2 | 9485 | |
88d6cf37 | 9486 | DEFUN (ospf_max_metric_router_lsa_admin, |
9487 | ospf_max_metric_router_lsa_admin_cmd, | |
9488 | "max-metric router-lsa administrative", | |
9489 | "OSPF maximum / infinite-distance metric\n" | |
9490 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9491 | "Administratively applied, for an indefinite period\n") | |
9492 | { | |
a3d826f0 | 9493 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9494 | struct listnode *ln; |
9495 | struct ospf_area *area; | |
7c8ff89e | 9496 | |
d62a17ae | 9497 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9498 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 9499 | |
d62a17ae | 9500 | if (!CHECK_FLAG(area->stub_router_state, |
9501 | OSPF_AREA_IS_STUB_ROUTED)) | |
9502 | ospf_router_lsa_update_area(area); | |
9503 | } | |
4ba4fc85 | 9504 | |
d62a17ae | 9505 | /* Allows for areas configured later to get the property */ |
9506 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
9507 | ||
9508 | return CMD_SUCCESS; | |
88d6cf37 | 9509 | } |
9510 | ||
9511 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
9512 | no_ospf_max_metric_router_lsa_admin_cmd, | |
9513 | "no max-metric router-lsa administrative", | |
9514 | NO_STR | |
9515 | "OSPF maximum / infinite-distance metric\n" | |
9516 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9517 | "Administratively applied, for an indefinite period\n") | |
9518 | { | |
a3d826f0 | 9519 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9520 | struct listnode *ln; |
9521 | struct ospf_area *area; | |
9522 | ||
9523 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9524 | UNSET_FLAG(area->stub_router_state, | |
9525 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
9526 | ||
9527 | /* Don't trample on the start-up stub timer */ | |
9528 | if (CHECK_FLAG(area->stub_router_state, | |
9529 | OSPF_AREA_IS_STUB_ROUTED) | |
9530 | && !area->t_stub_router) { | |
9531 | UNSET_FLAG(area->stub_router_state, | |
9532 | OSPF_AREA_IS_STUB_ROUTED); | |
9533 | ospf_router_lsa_update_area(area); | |
9534 | } | |
9535 | } | |
9536 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
9537 | return CMD_SUCCESS; | |
88d6cf37 | 9538 | } |
9539 | ||
9540 | DEFUN (ospf_max_metric_router_lsa_startup, | |
9541 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 9542 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 9543 | "OSPF maximum / infinite-distance metric\n" |
9544 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9545 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
9546 | "Time (seconds) to advertise self as stub-router\n") | |
9547 | { | |
a3d826f0 | 9548 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9549 | int idx_number = 3; |
9550 | unsigned int seconds; | |
9551 | ||
b5a8894d | 9552 | if (argc < 4) { |
d62a17ae | 9553 | vty_out(vty, "%% Must supply stub-router period"); |
9554 | return CMD_WARNING_CONFIG_FAILED; | |
9555 | } | |
9556 | ||
9557 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9558 | ||
9559 | ospf->stub_router_startup_time = seconds; | |
9560 | ||
9561 | return CMD_SUCCESS; | |
88d6cf37 | 9562 | } |
9563 | ||
9564 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
9565 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 9566 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 9567 | NO_STR |
9568 | "OSPF maximum / infinite-distance metric\n" | |
9569 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9570 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
9571 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 9572 | { |
a3d826f0 | 9573 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9574 | struct listnode *ln; |
9575 | struct ospf_area *area; | |
9576 | ||
9577 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
9578 | ||
9579 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9580 | SET_FLAG(area->stub_router_state, | |
9581 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
9582 | OSPF_TIMER_OFF(area->t_stub_router); | |
9583 | ||
9584 | /* Don't trample on admin stub routed */ | |
9585 | if (!CHECK_FLAG(area->stub_router_state, | |
9586 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
9587 | UNSET_FLAG(area->stub_router_state, | |
9588 | OSPF_AREA_IS_STUB_ROUTED); | |
9589 | ospf_router_lsa_update_area(area); | |
9590 | } | |
9591 | } | |
9592 | return CMD_SUCCESS; | |
88d6cf37 | 9593 | } |
9594 | ||
a1afa410 | 9595 | |
88d6cf37 | 9596 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
9597 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 9598 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 9599 | "OSPF maximum / infinite-distance metric\n" |
9600 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9601 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
9602 | "Time (seconds) to wait till full shutdown\n") | |
9603 | { | |
a3d826f0 | 9604 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9605 | int idx_number = 3; |
9606 | unsigned int seconds; | |
9607 | ||
b5a8894d | 9608 | if (argc < 4) { |
d62a17ae | 9609 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
9610 | return CMD_WARNING_CONFIG_FAILED; | |
9611 | } | |
9612 | ||
9613 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9614 | ||
9615 | ospf->stub_router_shutdown_time = seconds; | |
9616 | ||
9617 | return CMD_SUCCESS; | |
88d6cf37 | 9618 | } |
9619 | ||
9620 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
9621 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 9622 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 9623 | NO_STR |
9624 | "OSPF maximum / infinite-distance metric\n" | |
9625 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9626 | "Advertise stub-router prior to full shutdown of OSPF\n" |
9627 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 9628 | { |
a3d826f0 | 9629 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 9630 | |
d62a17ae | 9631 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
9632 | ||
9633 | return CMD_SUCCESS; | |
88d6cf37 | 9634 | } |
9635 | ||
a92706bb JU |
9636 | DEFUN (ospf_proactive_arp, |
9637 | ospf_proactive_arp_cmd, | |
9638 | "proactive-arp", | |
9639 | "Allow sending ARP requests proactively\n") | |
9640 | { | |
9641 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9642 | ||
9643 | ospf->proactive_arp = true; | |
9644 | ||
9645 | return CMD_SUCCESS; | |
9646 | } | |
9647 | ||
9648 | DEFUN (no_ospf_proactive_arp, | |
9649 | no_ospf_proactive_arp_cmd, | |
9650 | "no proactive-arp", | |
9651 | NO_STR | |
9652 | "Disallow sending ARP requests proactively\n") | |
9653 | { | |
9654 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9655 | ||
9656 | ospf->proactive_arp = false; | |
9657 | ||
9658 | return CMD_SUCCESS; | |
9659 | } | |
9660 | ||
07b33add | 9661 | /* Graceful Restart HELPER Commands */ |
9662 | DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd, | |
9663 | "graceful-restart helper-only [A.B.C.D]", | |
9664 | "OSPF Graceful Restart\n" | |
9665 | "Enable Helper support\n" | |
9666 | "Advertising router id\n") | |
9667 | { | |
9668 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9669 | struct in_addr addr; | |
9670 | int ret; | |
9671 | ||
9672 | if (argc == 3) { | |
9673 | ret = inet_aton(argv[2]->arg, &addr); | |
9674 | if (!ret) { | |
9675 | vty_out(vty, | |
9676 | "Please specify the valid routerid address.\n"); | |
9677 | return CMD_WARNING_CONFIG_FAILED; | |
9678 | } | |
9679 | ||
9680 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE); | |
9681 | return CMD_SUCCESS; | |
9682 | } | |
9683 | ||
9684 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); | |
9685 | ||
9686 | return CMD_SUCCESS; | |
9687 | } | |
9688 | ||
9689 | DEFPY(no_ospf_gr_helper_enable, | |
9690 | no_ospf_gr_helper_enable_cmd, | |
9691 | "no graceful-restart helper-only [A.B.C.D]", | |
9692 | NO_STR | |
9693 | "OSPF Graceful Restart\n" | |
9694 | "Disable Helper support\n" | |
9695 | "Advertising router id\n") | |
9696 | { | |
9697 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9698 | struct in_addr addr; | |
9699 | int ret; | |
9700 | ||
9701 | if (argc == 4) { | |
9702 | ret = inet_aton(argv[3]->arg, &addr); | |
9703 | if (!ret) { | |
9704 | vty_out(vty, | |
9705 | "Please specify the valid routerid address.\n"); | |
9706 | return CMD_WARNING_CONFIG_FAILED; | |
9707 | } | |
9708 | ||
9709 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, | |
9710 | OSPF_GR_FALSE); | |
9711 | return CMD_SUCCESS; | |
9712 | } | |
9713 | ||
9714 | ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE); | |
9715 | return CMD_SUCCESS; | |
9716 | } | |
9717 | ||
9718 | DEFPY(ospf_gr_helper_enable_lsacheck, | |
9719 | ospf_gr_helper_enable_lsacheck_cmd, | |
9720 | "graceful-restart helper strict-lsa-checking", | |
9721 | "OSPF Graceful Restart\n" | |
9722 | "OSPF GR Helper\n" | |
9723 | "Enable strict LSA check\n") | |
9724 | { | |
9725 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9726 | ||
9727 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE); | |
9728 | return CMD_SUCCESS; | |
9729 | } | |
9730 | ||
9731 | DEFPY(no_ospf_gr_helper_enable_lsacheck, | |
9732 | no_ospf_gr_helper_enable_lsacheck_cmd, | |
9733 | "no graceful-restart helper strict-lsa-checking", | |
9734 | NO_STR | |
9735 | "OSPF Graceful Restart\n" | |
9736 | "OSPF GR Helper\n" | |
9737 | "Disable strict LSA check\n") | |
9738 | { | |
9739 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9740 | ||
9741 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE); | |
9742 | return CMD_SUCCESS; | |
9743 | } | |
9744 | ||
9745 | DEFPY(ospf_gr_helper_supported_grace_time, | |
9746 | ospf_gr_helper_supported_grace_time_cmd, | |
9747 | "graceful-restart helper supported-grace-time (10-1800)$interval", | |
9748 | "OSPF Graceful Restart\n" | |
9749 | "OSPF GR Helper\n" | |
9750 | "Supported grace timer\n" | |
9751 | "Grace interval(in seconds)\n") | |
9752 | { | |
9753 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9754 | ||
9755 | ospf_gr_helper_supported_gracetime_set(ospf, interval); | |
9756 | return CMD_SUCCESS; | |
9757 | } | |
9758 | ||
9759 | DEFPY(no_ospf_gr_helper_supported_grace_time, | |
9760 | no_ospf_gr_helper_supported_grace_time_cmd, | |
9761 | "no graceful-restart helper supported-grace-time (10-1800)$interval", | |
9762 | NO_STR | |
9763 | "OSPF Graceful Restart\n" | |
9764 | "OSPF GR Helper\n" | |
9765 | "Supported grace timer\n" | |
9766 | "Grace interval(in seconds)\n") | |
9767 | { | |
9768 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9769 | ||
9770 | ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL); | |
9771 | return CMD_SUCCESS; | |
9772 | } | |
9773 | ||
9774 | DEFPY(ospf_gr_helper_planned_only, | |
9775 | ospf_gr_helper_planned_only_cmd, | |
9776 | "graceful-restart helper planned-only", | |
9777 | "OSPF Graceful Restart\n" | |
9778 | "OSPF GR Helper\n" | |
9779 | "Supported only planned restart\n") | |
9780 | { | |
9781 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9782 | ||
9783 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE); | |
9784 | ||
9785 | return CMD_SUCCESS; | |
9786 | } | |
9787 | ||
423e71c4 | 9788 | /* External Route Aggregation */ |
9789 | DEFUN (ospf_external_route_aggregation, | |
9790 | ospf_external_route_aggregation_cmd, | |
9791 | "summary-address A.B.C.D/M [tag (1-4294967295)]", | |
9792 | "External summary address\n" | |
9793 | "Summary address prefix (a.b.c.d/m) \n" | |
9794 | "Router tag \n" | |
9795 | "Router tag value\n") | |
9796 | { | |
9797 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9798 | struct prefix_ipv4 p; | |
9799 | int idx = 1; | |
9800 | route_tag_t tag = 0; | |
9801 | int ret = OSPF_SUCCESS; | |
9802 | ||
9803 | str2prefix_ipv4(argv[idx]->arg, &p); | |
9804 | ||
9805 | if (is_prefix_default(&p)) { | |
9806 | vty_out(vty, | |
9807 | "Default address shouldn't be configured as summary address.\n"); | |
9808 | return CMD_SUCCESS; | |
9809 | } | |
9810 | ||
9811 | /* Apply mask for given prefix. */ | |
9812 | apply_mask((struct prefix *)&p); | |
9813 | ||
9814 | if (!is_valid_summary_addr(&p)) { | |
9815 | vty_out(vty, "Not a valid summary address.\n"); | |
9816 | return CMD_WARNING_CONFIG_FAILED; | |
9817 | } | |
9818 | ||
9819 | if (argc > 2) | |
9820 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
9821 | ||
9822 | ret = ospf_asbr_external_aggregator_set(ospf, &p, tag); | |
9823 | if (ret == OSPF_INVALID) | |
9824 | vty_out(vty, "Inavlid configuration!!\n"); | |
9825 | ||
9826 | return CMD_SUCCESS; | |
9827 | } | |
9828 | ||
9829 | DEFUN (no_ospf_external_route_aggregation, | |
9830 | no_ospf_external_route_aggregation_cmd, | |
9831 | "no summary-address A.B.C.D/M [tag (1-4294967295)]", | |
9832 | NO_STR | |
9833 | "External summary address\n" | |
9834 | "Summary address prefix (a.b.c.d/m)\n" | |
9835 | "Router tag\n" | |
9836 | "Router tag value\n") | |
9837 | { | |
9838 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9839 | struct prefix_ipv4 p; | |
9840 | int idx = 2; | |
9841 | route_tag_t tag = 0; | |
9842 | int ret = OSPF_SUCCESS; | |
9843 | ||
9844 | str2prefix_ipv4(argv[idx]->arg, &p); | |
9845 | ||
9846 | if (is_prefix_default(&p)) { | |
9847 | vty_out(vty, | |
9848 | "Default address shouldn't be configured as summary address.\n"); | |
9849 | return CMD_SUCCESS; | |
9850 | } | |
9851 | ||
9852 | /* Apply mask for given prefix. */ | |
9853 | apply_mask((struct prefix *)&p); | |
9854 | ||
9855 | if (!is_valid_summary_addr(&p)) { | |
9856 | vty_out(vty, "Not a valid summary address.\n"); | |
9857 | return CMD_WARNING_CONFIG_FAILED; | |
9858 | } | |
9859 | ||
9860 | if (argc > 3) | |
9861 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
9862 | ||
9863 | ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag); | |
9864 | if (ret == OSPF_INVALID) | |
9865 | vty_out(vty, "Inavlid configuration!!\n"); | |
9866 | ||
9867 | return CMD_SUCCESS; | |
9868 | } | |
9869 | ||
07b33add | 9870 | DEFPY(no_ospf_gr_helper_planned_only, |
9871 | no_ospf_gr_helper_planned_only_cmd, | |
9872 | "no graceful-restart helper planned-only", | |
9873 | NO_STR | |
9874 | "OSPF Graceful Restart\n" | |
9875 | "OSPF GR Helper\n" | |
9876 | "Supported only for planned restart\n") | |
9877 | { | |
9878 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9879 | ||
9880 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE); | |
9881 | ||
9882 | return CMD_SUCCESS; | |
9883 | } | |
abd5b8c7 | 9884 | |
9885 | static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *backet, | |
9886 | void *arg) | |
9887 | { | |
9888 | struct advRtr *rtr = backet->data; | |
9889 | struct vty *vty = (struct vty *)arg; | |
9890 | static unsigned int count; | |
9891 | ||
96b663a3 | 9892 | vty_out(vty, "%-6pI4,", &rtr->advRtrAddr); |
abd5b8c7 | 9893 | count++; |
9894 | ||
9895 | if (count % 5 == 0) | |
9896 | vty_out(vty, "\n"); | |
9897 | ||
9898 | return HASHWALK_CONTINUE; | |
9899 | } | |
9900 | ||
9901 | static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf, | |
9902 | uint8_t use_vrf, json_object *json, | |
9903 | bool uj, bool detail) | |
9904 | { | |
9905 | struct listnode *node; | |
9906 | struct ospf_interface *oi; | |
96b663a3 | 9907 | char buf[PREFIX_STRLEN]; |
abd5b8c7 | 9908 | json_object *json_vrf = NULL; |
9909 | ||
9910 | if (uj) { | |
9911 | if (use_vrf) | |
9912 | json_vrf = json_object_new_object(); | |
9913 | else | |
9914 | json_vrf = json; | |
9915 | } | |
9916 | ||
9917 | if (ospf->instance) { | |
9918 | if (uj) | |
9919 | json_object_int_add(json, "ospfInstance", | |
9920 | ospf->instance); | |
9921 | else | |
9922 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
9923 | } | |
9924 | ||
9925 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
9926 | ||
9927 | if (uj) { | |
9928 | if (use_vrf) { | |
9929 | if (ospf->vrf_id == VRF_DEFAULT) | |
9930 | json_object_object_add(json, "default", | |
9931 | json_vrf); | |
9932 | else | |
9933 | json_object_object_add(json, ospf->name, | |
9934 | json_vrf); | |
9935 | } | |
9936 | } else | |
9937 | vty_out(vty, "\n"); | |
9938 | ||
9939 | /* Show Router ID. */ | |
9940 | if (uj) { | |
9941 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
9942 | inet_ntop(AF_INET, &ospf->router_id, |
9943 | buf, sizeof(buf))); | |
abd5b8c7 | 9944 | } else { |
96b663a3 MS |
9945 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", |
9946 | &ospf->router_id); | |
abd5b8c7 | 9947 | } |
9948 | ||
9949 | if (!uj) { | |
9950 | ||
9951 | if (ospf->is_helper_supported) | |
9952 | vty_out(vty, | |
9953 | " Graceful restart helper support enabled.\n"); | |
9954 | else | |
9955 | vty_out(vty, | |
9956 | " Graceful restart helper support disabled.\n"); | |
9957 | ||
9958 | if (ospf->strict_lsa_check) | |
9959 | vty_out(vty, " Strict LSA check is enabled.\n"); | |
9960 | else | |
9961 | vty_out(vty, " Strict LSA check is disabled.\n"); | |
9962 | ||
9963 | if (ospf->only_planned_restart) | |
9964 | vty_out(vty, | |
9965 | " Helper supported for planned restarts only.\n"); | |
9966 | else | |
9967 | vty_out(vty, | |
9968 | " Helper supported for Planned and Unplanned Restarts.\n"); | |
9969 | ||
9970 | vty_out(vty, | |
9971 | " Supported Graceful restart interval: %d(in seconds).\n", | |
9972 | ospf->supported_grace_time); | |
9973 | ||
9974 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
9975 | vty_out(vty, " Enable Router list:\n"); | |
9976 | vty_out(vty, " "); | |
9977 | hash_walk(ospf->enable_rtr_list, | |
9978 | ospf_print_vty_helper_dis_rtr_walkcb, vty); | |
9979 | vty_out(vty, "\n\n"); | |
9980 | } | |
9981 | ||
9982 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) { | |
9983 | vty_out(vty, " Last Helper exit Reason :%s\n", | |
d05d5280 | 9984 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 9985 | } |
9986 | ||
9987 | if (ospf->active_restarter_cnt) | |
9988 | vty_out(vty, | |
9989 | " Number of Active neighbours in graceful restart: %d\n", | |
9990 | ospf->active_restarter_cnt); | |
9991 | else | |
9992 | vty_out(vty, "\n"); | |
9993 | ||
9994 | } else { | |
9995 | json_object_string_add( | |
9996 | json_vrf, "helperSupport", | |
9997 | (ospf->is_helper_supported) ? "Enabled" : "Disabled"); | |
9998 | json_object_string_add(json_vrf, "strictLsaCheck", | |
9999 | (ospf->strict_lsa_check) ? "Enabled" | |
10000 | : "Disabled"); | |
10001 | json_object_string_add( | |
10002 | json_vrf, "restartSupoort", | |
10003 | (ospf->only_planned_restart) | |
10004 | ? "Planned Restart only" | |
10005 | : "Planned and Unplanned Restarts"); | |
10006 | ||
10007 | json_object_int_add(json_vrf, "supportedGracePeriod", | |
10008 | ospf->supported_grace_time); | |
10009 | ||
10010 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) | |
10011 | json_object_string_add( | |
10012 | json_vrf, "LastExitReason", | |
d05d5280 | 10013 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10014 | |
10015 | if (ospf->active_restarter_cnt) | |
10016 | json_object_int_add(json_vrf, "activeRestarterCnt", | |
10017 | ospf->active_restarter_cnt); | |
10018 | } | |
10019 | ||
10020 | ||
10021 | if (detail) { | |
10022 | int cnt = 1; | |
10023 | json_object *json_neighbors = NULL; | |
10024 | ||
10025 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
10026 | struct route_node *rn; | |
10027 | struct ospf_neighbor *nbr; | |
10028 | json_object *json_neigh; | |
10029 | ||
10030 | if (ospf_interface_neighbor_count(oi) == 0) | |
10031 | continue; | |
10032 | ||
10033 | if (uj) { | |
10034 | json_object_object_get_ex(json_vrf, "Neighbors", | |
10035 | &json_neighbors); | |
10036 | if (!json_neighbors) { | |
10037 | json_neighbors = | |
10038 | json_object_new_object(); | |
10039 | json_object_object_add(json_vrf, | |
10040 | "Neighbors", | |
10041 | json_neighbors); | |
10042 | } | |
10043 | } | |
10044 | ||
10045 | for (rn = route_top(oi->nbrs); rn; | |
10046 | rn = route_next(rn)) { | |
10047 | ||
10048 | if (!rn->info) | |
10049 | continue; | |
10050 | ||
10051 | nbr = rn->info; | |
10052 | ||
10053 | if (!OSPF_GR_IS_ACTIVE_HELPER(nbr)) | |
10054 | continue; | |
10055 | ||
10056 | if (!uj) { | |
10057 | vty_out(vty, " Neighbour %d :\n", cnt); | |
96b663a3 MS |
10058 | vty_out(vty, " Address : %pI4\n", |
10059 | &nbr->address.u.prefix4); | |
10060 | vty_out(vty, " Routerid : %pI4\n", | |
10061 | &nbr->router_id); | |
abd5b8c7 | 10062 | vty_out(vty, |
10063 | " Received Grace period : %d(in seconds).\n", | |
10064 | nbr->gr_helper_info | |
10065 | .recvd_grace_period); | |
10066 | vty_out(vty, | |
10067 | " Actual Grace period : %d(in seconds)\n", | |
10068 | nbr->gr_helper_info | |
10069 | .actual_grace_period); | |
10070 | vty_out(vty, | |
10071 | " Remaining GraceTime:%ld(in seconds).\n", | |
10072 | thread_timer_remain_second( | |
10073 | nbr->gr_helper_info | |
10074 | .t_grace_timer)); | |
10075 | vty_out(vty, | |
10076 | " Graceful Restart reason: %s.\n\n", | |
d05d5280 MS |
10077 | ospf_restart_reason2str( |
10078 | nbr->gr_helper_info | |
10079 | .gr_restart_reason)); | |
abd5b8c7 | 10080 | cnt++; |
10081 | } else { | |
10082 | json_neigh = json_object_new_object(); | |
10083 | json_object_string_add( | |
10084 | json_neigh, "srcAddr", | |
96b663a3 MS |
10085 | inet_ntop(AF_INET, &nbr->src, |
10086 | buf, sizeof(buf))); | |
abd5b8c7 | 10087 | |
10088 | json_object_string_add( | |
10089 | json_neigh, "routerid", | |
96b663a3 MS |
10090 | inet_ntop(AF_INET, |
10091 | &nbr->router_id, | |
10092 | buf, sizeof(buf))); | |
abd5b8c7 | 10093 | json_object_int_add( |
10094 | json_neigh, | |
10095 | "recvdGraceInterval", | |
10096 | nbr->gr_helper_info | |
10097 | .recvd_grace_period); | |
10098 | json_object_int_add( | |
10099 | json_neigh, | |
10100 | "actualGraceInterval", | |
10101 | nbr->gr_helper_info | |
10102 | .actual_grace_period); | |
10103 | json_object_int_add( | |
10104 | json_neigh, "remainGracetime", | |
10105 | thread_timer_remain_second( | |
10106 | nbr->gr_helper_info | |
10107 | .t_grace_timer)); | |
10108 | json_object_string_add( | |
10109 | json_neigh, "restartReason", | |
d05d5280 MS |
10110 | ospf_restart_reason2str( |
10111 | nbr->gr_helper_info | |
10112 | .gr_restart_reason)); | |
abd5b8c7 | 10113 | json_object_object_add( |
10114 | json_neighbors, | |
96b663a3 MS |
10115 | inet_ntop(AF_INET, &nbr->src, |
10116 | buf, sizeof(buf)), | |
abd5b8c7 | 10117 | json_neigh); |
10118 | } | |
10119 | } | |
10120 | } | |
10121 | } | |
423e71c4 | 10122 | return CMD_SUCCESS; |
10123 | } | |
10124 | ||
10125 | DEFUN (ospf_external_route_aggregation_no_adrvertise, | |
10126 | ospf_external_route_aggregation_no_adrvertise_cmd, | |
10127 | "summary-address A.B.C.D/M no-advertise", | |
10128 | "External summary address\n" | |
10129 | "Summary address prefix (a.b.c.d/m) \n" | |
10130 | "Don't advertise summary route \n") | |
10131 | { | |
10132 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10133 | struct prefix_ipv4 p; | |
10134 | int idx = 1; | |
10135 | int ret = OSPF_SUCCESS; | |
10136 | ||
10137 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10138 | ||
10139 | if (is_prefix_default(&p)) { | |
10140 | vty_out(vty, | |
10141 | "Default address shouldn't be configured as summary address.\n"); | |
10142 | return CMD_SUCCESS; | |
10143 | } | |
10144 | ||
10145 | /* Apply mask for given prefix. */ | |
10146 | apply_mask((struct prefix *)&p); | |
10147 | ||
10148 | if (!is_valid_summary_addr(&p)) { | |
10149 | vty_out(vty, "Not a valid summary address.\n"); | |
10150 | return CMD_WARNING_CONFIG_FAILED; | |
10151 | } | |
10152 | ||
10153 | ret = ospf_asbr_external_rt_no_advertise(ospf, &p); | |
10154 | if (ret == OSPF_INVALID) | |
10155 | vty_out(vty, "Inavlid configuration!!\n"); | |
10156 | ||
10157 | return CMD_SUCCESS; | |
10158 | } | |
10159 | ||
10160 | DEFUN (no_ospf_external_route_aggregation_no_adrvertise, | |
10161 | no_ospf_external_route_aggregation_no_adrvertise_cmd, | |
10162 | "no summary-address A.B.C.D/M no-advertise", | |
10163 | NO_STR | |
10164 | "External summary address\n" | |
fbc48492 DS |
10165 | "Summary address prefix (a.b.c.d/m)\n" |
10166 | "Advertise summary route to the AS \n") | |
423e71c4 | 10167 | { |
10168 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10169 | struct prefix_ipv4 p; | |
10170 | int idx = 2; | |
10171 | int ret = OSPF_SUCCESS; | |
10172 | ||
10173 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10174 | ||
10175 | if (is_prefix_default(&p)) { | |
10176 | vty_out(vty, | |
10177 | "Default address shouldn't be configured as summary address.\n"); | |
10178 | return CMD_SUCCESS; | |
10179 | } | |
10180 | ||
10181 | /* Apply mask for given prefix. */ | |
10182 | apply_mask((struct prefix *)&p); | |
10183 | ||
10184 | if (!is_valid_summary_addr(&p)) { | |
10185 | vty_out(vty, "Not a valid summary address.\n"); | |
10186 | return CMD_WARNING_CONFIG_FAILED; | |
10187 | } | |
10188 | ||
10189 | ret = ospf_asbr_external_rt_advertise(ospf, &p); | |
10190 | if (ret == OSPF_INVALID) | |
10191 | vty_out(vty, "Inavlid configuration!!\n"); | |
10192 | ||
10193 | return CMD_SUCCESS; | |
10194 | } | |
10195 | ||
10196 | DEFUN (ospf_route_aggregation_timer, | |
10197 | ospf_route_aggregation_timer_cmd, | |
10198 | "aggregation timer (5-1800)", | |
10199 | "External route aggregation\n" | |
10200 | "Delay timer (in seconds)\n" | |
10201 | "Timer interval(in seconds)\n") | |
10202 | { | |
10203 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10204 | unsigned int interval = 0; | |
10205 | ||
10206 | interval = strtoul(argv[2]->arg, NULL, 10); | |
10207 | ||
10208 | ospf_external_aggregator_timer_set(ospf, interval); | |
abd5b8c7 | 10209 | |
10210 | return CMD_SUCCESS; | |
10211 | } | |
10212 | ||
10213 | DEFPY (show_ip_ospf_gr_helper, | |
10214 | show_ip_ospf_gr_helper_cmd, | |
10215 | "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]", | |
10216 | SHOW_STR | |
10217 | IP_STR | |
10218 | "OSPF information\n" | |
10219 | VRF_CMD_HELP_STR | |
10220 | "All VRFs\n" | |
10221 | "OSPF Graceful Restart\n" | |
10222 | "Helper details in the router\n" | |
10223 | "Detailed informtion\n" | |
10224 | JSON_STR) | |
10225 | { | |
10226 | char *vrf_name = NULL; | |
10227 | bool all_vrf = false; | |
10228 | int ret = CMD_SUCCESS; | |
10229 | int idx_vrf = 0; | |
10230 | int idx = 0; | |
10231 | uint8_t use_vrf = 0; | |
10232 | bool uj = use_json(argc, argv); | |
10233 | struct ospf *ospf = NULL; | |
10234 | json_object *json = NULL; | |
10235 | struct listnode *node = NULL; | |
10236 | int inst = 0; | |
10237 | bool detail = false; | |
10238 | ||
10239 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
10240 | ||
10241 | if (argv_find(argv, argc, "detail", &idx)) | |
10242 | detail = true; | |
10243 | ||
10244 | if (uj) | |
10245 | json = json_object_new_object(); | |
10246 | ||
10247 | /* vrf input is provided */ | |
10248 | if (vrf_name) { | |
10249 | use_vrf = 1; | |
10250 | ||
10251 | if (all_vrf) { | |
10252 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10253 | if (!ospf->oi_running) | |
10254 | continue; | |
10255 | ||
10256 | ret = ospf_show_gr_helper_details( | |
10257 | vty, ospf, use_vrf, json, uj, detail); | |
10258 | } | |
10259 | ||
10260 | if (uj) { | |
10261 | vty_out(vty, "%s\n", | |
10262 | json_object_to_json_string_ext( | |
10263 | json, JSON_C_TO_STRING_PRETTY)); | |
10264 | json_object_free(json); | |
10265 | } | |
10266 | ||
10267 | return ret; | |
10268 | } | |
10269 | ||
10270 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
10271 | ||
10272 | if (ospf == NULL || !ospf->oi_running) { | |
10273 | ||
10274 | if (uj) { | |
10275 | vty_out(vty, "%s\n", | |
10276 | json_object_to_json_string_ext( | |
10277 | json, JSON_C_TO_STRING_PRETTY)); | |
10278 | json_object_free(json); | |
10279 | } else | |
10280 | vty_out(vty, "%% OSPF instance not found\n"); | |
10281 | ||
10282 | return CMD_SUCCESS; | |
10283 | } | |
10284 | ||
10285 | } else { | |
10286 | /* Default Vrf */ | |
10287 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
10288 | ||
10289 | if (ospf == NULL || !ospf->oi_running) { | |
10290 | ||
10291 | if (uj) { | |
10292 | vty_out(vty, "%s\n", | |
10293 | json_object_to_json_string_ext( | |
10294 | json, JSON_C_TO_STRING_PRETTY)); | |
10295 | json_object_free(json); | |
10296 | } else | |
10297 | vty_out(vty, "%% OSPF instance not found\n"); | |
10298 | ||
10299 | return CMD_SUCCESS; | |
10300 | } | |
10301 | ||
10302 | ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, | |
10303 | detail); | |
10304 | } | |
10305 | ||
10306 | if (uj) { | |
10307 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
10308 | json, JSON_C_TO_STRING_PRETTY)); | |
10309 | json_object_free(json); | |
10310 | } | |
10311 | ||
10312 | return CMD_SUCCESS; | |
10313 | } | |
07b33add | 10314 | /* Graceful Restart HELPER commands end */ |
423e71c4 | 10315 | DEFUN (no_ospf_route_aggregation_timer, |
10316 | no_ospf_route_aggregation_timer_cmd, | |
10317 | "no aggregation timer", | |
10318 | NO_STR | |
10319 | "External route aggregation\n" | |
10320 | "Delay timer\n") | |
10321 | { | |
10322 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10323 | ||
10324 | ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY); | |
10325 | ||
10326 | return CMD_SUCCESS; | |
10327 | } | |
10328 | ||
10329 | /* External Route Aggregation End */ | |
07b33add | 10330 | |
d62a17ae | 10331 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
10332 | { | |
10333 | struct listnode *ln; | |
10334 | struct ospf_area *area; | |
10335 | ||
10336 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10337 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
10338 | ospf->stub_router_startup_time); | |
10339 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10340 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
10341 | ospf->stub_router_shutdown_time); | |
10342 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
10343 | if (CHECK_FLAG(area->stub_router_state, | |
10344 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
10345 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
10346 | break; | |
10347 | } | |
10348 | } | |
10349 | return; | |
10350 | } | |
10351 | ||
b5a8894d | 10352 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10353 | struct route_table *rt, |
10354 | json_object *json) | |
d62a17ae | 10355 | { |
10356 | struct route_node *rn; | |
10357 | struct ospf_route * or ; | |
10358 | struct listnode *pnode, *pnnode; | |
10359 | struct ospf_path *path; | |
96b663a3 | 10360 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10361 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10362 | *json_nexthop = NULL; | |
d62a17ae | 10363 | |
0f478e30 | 10364 | if (!json) |
996c9314 LB |
10365 | vty_out(vty, |
10366 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 10367 | |
0f478e30 | 10368 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
96b663a3 MS |
10369 | char buf1[PREFIX2STR_BUFFER]; |
10370 | ||
0f478e30 CS |
10371 | if ((or = rn->info) == NULL) |
10372 | continue; | |
0f478e30 | 10373 | |
0f478e30 CS |
10374 | prefix2str(&rn->p, buf1, sizeof(buf1)); |
10375 | ||
10376 | json_route = json_object_new_object(); | |
10377 | if (json) { | |
996c9314 LB |
10378 | json_object_object_add(json, buf1, json_route); |
10379 | json_object_to_json_string_ext( | |
10380 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 CS |
10381 | } |
10382 | ||
10383 | switch (or->path_type) { | |
10384 | case OSPF_PATH_INTER_AREA: | |
10385 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10386 | if (json) { | |
10387 | json_object_string_add(json_route, | |
996c9314 LB |
10388 | "routeType", |
10389 | "N IA"); | |
10390 | json_object_int_add(json_route, "cost", | |
0f478e30 CS |
10391 | or->cost); |
10392 | json_object_string_add( | |
996c9314 | 10393 | json_route, "area", |
96b663a3 MS |
10394 | inet_ntop(AF_INET, |
10395 | &or->u.std.area_id, | |
10396 | buf1, sizeof(buf1))); | |
0f478e30 | 10397 | } else { |
d62a17ae | 10398 | vty_out(vty, |
96b663a3 | 10399 | "N IA %-18s [%d] area: %pI4\n", |
d62a17ae | 10400 | buf1, or->cost, |
96b663a3 | 10401 | &or->u.std.area_id); |
0f478e30 | 10402 | } |
996c9314 | 10403 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
10404 | if (json) { |
10405 | json_object_string_add(json_route, | |
996c9314 LB |
10406 | "routeType", |
10407 | "D IA"); | |
0f478e30 | 10408 | } else { |
d62a17ae | 10409 | vty_out(vty, |
10410 | "D IA %-18s Discard entry\n", | |
10411 | buf1); | |
0f478e30 CS |
10412 | } |
10413 | } | |
10414 | break; | |
10415 | case OSPF_PATH_INTRA_AREA: | |
10416 | if (json) { | |
996c9314 LB |
10417 | json_object_string_add(json_route, "routeType", |
10418 | "N"); | |
0f478e30 | 10419 | json_object_int_add(json_route, "cost", |
996c9314 LB |
10420 | or->cost); |
10421 | json_object_string_add( | |
10422 | json_route, "area", | |
96b663a3 MS |
10423 | inet_ntop(AF_INET, &or->u.std.area_id, |
10424 | buf1, sizeof(buf1))); | |
0f478e30 | 10425 | } else { |
96b663a3 | 10426 | vty_out(vty, "N %-18s [%d] area: %pI4\n", |
d62a17ae | 10427 | buf1, or->cost, |
96b663a3 | 10428 | &or->u.std.area_id); |
0f478e30 CS |
10429 | } |
10430 | break; | |
10431 | default: | |
10432 | break; | |
10433 | } | |
10434 | ||
10435 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10436 | if (json) { | |
10437 | json_nexthop_array = json_object_new_array(); | |
10438 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10439 | json_nexthop_array); |
d62a17ae | 10440 | } |
10441 | ||
0f478e30 CS |
10442 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
10443 | path)) { | |
10444 | if (json) { | |
996c9314 LB |
10445 | json_nexthop = json_object_new_object(); |
10446 | json_object_array_add( | |
10447 | json_nexthop_array, | |
10448 | json_nexthop); | |
0f478e30 CS |
10449 | } |
10450 | if (if_lookup_by_index(path->ifindex, | |
10451 | ospf->vrf_id)) { | |
10452 | ||
10453 | if (path->nexthop.s_addr == 0) { | |
10454 | if (json) { | |
10455 | json_object_string_add( | |
10456 | json_nexthop, | |
996c9314 | 10457 | "ip", " "); |
0f478e30 CS |
10458 | json_object_string_add( |
10459 | json_nexthop, | |
10460 | "directly attached to", | |
d62a17ae | 10461 | ifindex2ifname( |
996c9314 LB |
10462 | path->ifindex, |
10463 | ospf->vrf_id)); | |
0f478e30 | 10464 | } else { |
d62a17ae | 10465 | vty_out(vty, |
996c9314 LB |
10466 | "%24s directly attached to %s\n", |
10467 | "", | |
10468 | ifindex2ifname( | |
10469 | path->ifindex, | |
10470 | ospf->vrf_id)); | |
0f478e30 CS |
10471 | } |
10472 | } else { | |
10473 | if (json) { | |
10474 | json_object_string_add( | |
10475 | json_nexthop, | |
10476 | "ip", | |
96b663a3 MS |
10477 | inet_ntop( |
10478 | AF_INET, | |
10479 | &path->nexthop, | |
10480 | buf, | |
10481 | sizeof(buf))); | |
0f478e30 CS |
10482 | json_object_string_add( |
10483 | json_nexthop, | |
10484 | "via", | |
d62a17ae | 10485 | ifindex2ifname( |
996c9314 LB |
10486 | path->ifindex, |
10487 | ospf->vrf_id)); | |
0f478e30 CS |
10488 | } else { |
10489 | vty_out(vty, | |
96b663a3 | 10490 | "%24s via %pI4, %s\n", |
996c9314 | 10491 | "", |
96b663a3 | 10492 | &path->nexthop, |
996c9314 LB |
10493 | ifindex2ifname( |
10494 | path->ifindex, | |
10495 | ospf->vrf_id)); | |
0f478e30 | 10496 | } |
d62a17ae | 10497 | } |
10498 | } | |
0f478e30 | 10499 | } |
d62a17ae | 10500 | } |
0f478e30 CS |
10501 | if (!json) |
10502 | json_object_free(json_route); | |
10503 | } | |
10504 | if (!json) | |
10505 | vty_out(vty, "\n"); | |
d62a17ae | 10506 | } |
10507 | ||
b5a8894d | 10508 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10509 | struct route_table *rtrs, |
10510 | json_object *json) | |
d62a17ae | 10511 | { |
10512 | struct route_node *rn; | |
10513 | struct ospf_route * or ; | |
10514 | struct listnode *pnode; | |
10515 | struct listnode *node; | |
10516 | struct ospf_path *path; | |
96b663a3 | 10517 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10518 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10519 | *json_nexthop = NULL; | |
d62a17ae | 10520 | |
0f478e30 | 10521 | if (!json) |
996c9314 LB |
10522 | vty_out(vty, |
10523 | "============ OSPF router routing table =============\n"); | |
d62a17ae | 10524 | |
0f478e30 CS |
10525 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
10526 | if (rn->info == NULL) | |
10527 | continue; | |
10528 | int flag = 0; | |
10529 | ||
10530 | json_route = json_object_new_object(); | |
10531 | if (json) { | |
96b663a3 MS |
10532 | json_object_object_add( |
10533 | json, inet_ntop(AF_INET, &rn->p.u.prefix4, | |
10534 | buf, sizeof(buf)), | |
10535 | json_route); | |
996c9314 | 10536 | json_object_string_add(json_route, "routeType", "R "); |
0f478e30 | 10537 | } else { |
96b663a3 MS |
10538 | vty_out(vty, "R %-15pI4 ", |
10539 | &rn->p.u.prefix4); | |
0f478e30 | 10540 | } |
d62a17ae | 10541 | |
996c9314 | 10542 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
10543 | if (flag++) { |
10544 | if (!json) | |
d62a17ae | 10545 | vty_out(vty, "%24s", ""); |
0f478e30 | 10546 | } |
d62a17ae | 10547 | |
0f478e30 CS |
10548 | /* Show path. */ |
10549 | if (json) { | |
10550 | json_object_int_add(json_route, "cost", | |
10551 | or->cost); | |
996c9314 LB |
10552 | json_object_string_add( |
10553 | json_route, "area", | |
96b663a3 MS |
10554 | inet_ntop(AF_INET, &or->u.std.area_id, |
10555 | buf, sizeof(buf))); | |
996c9314 LB |
10556 | if (or->path_type == OSPF_PATH_INTER_AREA) |
10557 | json_object_boolean_true_add(json_route, | |
10558 | "IA"); | |
0f478e30 | 10559 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
10560 | json_object_string_add(json_route, |
10561 | "routerType", | |
10562 | "abr"); | |
10563 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
10564 | json_object_string_add(json_route, | |
10565 | "routerType", | |
10566 | "asbr"); | |
0f478e30 | 10567 | } else { |
96b663a3 | 10568 | vty_out(vty, "%s [%d] area: %pI4", |
996c9314 LB |
10569 | (or->path_type == OSPF_PATH_INTER_AREA |
10570 | ? "IA" | |
10571 | : " "), | |
96b663a3 | 10572 | or->cost, &or->u.std.area_id); |
d62a17ae | 10573 | /* Show flags. */ |
10574 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
10575 | (or->u.std.flags & ROUTER_LSA_BORDER |
10576 | ? ", ABR" | |
10577 | : ""), | |
10578 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
10579 | ? ", ASBR" | |
10580 | : "")); | |
0f478e30 CS |
10581 | } |
10582 | ||
10583 | if (json) { | |
996c9314 | 10584 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 10585 | json_object_object_add(json_route, "nexthops", |
996c9314 | 10586 | json_nexthop_array); |
0f478e30 CS |
10587 | } |
10588 | ||
996c9314 | 10589 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 10590 | if (json) { |
996c9314 | 10591 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
10592 | json_object_array_add( |
10593 | json_nexthop_array, | |
10594 | json_nexthop); | |
10595 | } | |
10596 | if (if_lookup_by_index(path->ifindex, | |
10597 | ospf->vrf_id)) { | |
10598 | if (path->nexthop.s_addr == 0) { | |
10599 | if (json) { | |
10600 | json_object_string_add( | |
10601 | json_nexthop, | |
996c9314 | 10602 | "ip", " "); |
0f478e30 CS |
10603 | json_object_string_add( |
10604 | json_nexthop, | |
10605 | "directly attached to", | |
d62a17ae | 10606 | ifindex2ifname( |
10607 | path->ifindex, | |
b5a8894d | 10608 | ospf->vrf_id)); |
0f478e30 | 10609 | } else { |
d62a17ae | 10610 | vty_out(vty, |
996c9314 LB |
10611 | "%24s directly attached to %s\n", |
10612 | "", | |
10613 | ifindex2ifname( | |
10614 | path->ifindex, | |
10615 | ospf->vrf_id)); | |
0f478e30 CS |
10616 | } |
10617 | } else { | |
10618 | if (json) { | |
10619 | json_object_string_add( | |
10620 | json_nexthop, | |
10621 | "ip", | |
96b663a3 MS |
10622 | inet_ntop( |
10623 | AF_INET, | |
10624 | &path->nexthop, | |
10625 | buf, sizeof(buf))); | |
0f478e30 CS |
10626 | json_object_string_add( |
10627 | json_nexthop, | |
10628 | "via", | |
d62a17ae | 10629 | ifindex2ifname( |
10630 | path->ifindex, | |
b5a8894d | 10631 | ospf->vrf_id)); |
0f478e30 CS |
10632 | } else { |
10633 | vty_out(vty, | |
96b663a3 | 10634 | "%24s via %pI4, %s\n", |
996c9314 | 10635 | "", |
96b663a3 | 10636 | &path->nexthop, |
996c9314 LB |
10637 | ifindex2ifname( |
10638 | path->ifindex, | |
10639 | ospf->vrf_id)); | |
0f478e30 | 10640 | } |
d62a17ae | 10641 | } |
10642 | } | |
10643 | } | |
10644 | } | |
0f478e30 CS |
10645 | if (!json) |
10646 | json_object_free(json_route); | |
10647 | } | |
10648 | if (!json) | |
10649 | vty_out(vty, "\n"); | |
d62a17ae | 10650 | } |
10651 | ||
b5a8894d | 10652 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10653 | struct route_table *rt, |
10654 | json_object *json) | |
d62a17ae | 10655 | { |
10656 | struct route_node *rn; | |
10657 | struct ospf_route *er; | |
10658 | struct listnode *pnode, *pnnode; | |
10659 | struct ospf_path *path; | |
96b663a3 | 10660 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10661 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10662 | *json_nexthop = NULL; | |
d62a17ae | 10663 | |
0f478e30 | 10664 | if (!json) |
996c9314 LB |
10665 | vty_out(vty, |
10666 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
10667 | |
10668 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
10669 | if ((er = rn->info) == NULL) | |
10670 | continue; | |
10671 | ||
10672 | char buf1[19]; | |
10673 | ||
96b663a3 | 10674 | snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p); |
0f478e30 CS |
10675 | json_route = json_object_new_object(); |
10676 | if (json) { | |
996c9314 LB |
10677 | json_object_object_add(json, buf1, json_route); |
10678 | json_object_to_json_string_ext( | |
10679 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 | 10680 | } |
d62a17ae | 10681 | |
0f478e30 CS |
10682 | switch (er->path_type) { |
10683 | case OSPF_PATH_TYPE1_EXTERNAL: | |
10684 | if (json) { | |
996c9314 | 10685 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10686 | "N E1"); |
10687 | json_object_int_add(json_route, "cost", | |
996c9314 | 10688 | er->cost); |
0f478e30 | 10689 | } else { |
d62a17ae | 10690 | vty_out(vty, |
996c9314 LB |
10691 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
10692 | "\n", | |
10693 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
10694 | } |
10695 | break; | |
10696 | case OSPF_PATH_TYPE2_EXTERNAL: | |
10697 | if (json) { | |
996c9314 | 10698 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10699 | "N E2"); |
10700 | json_object_int_add(json_route, "cost", | |
996c9314 | 10701 | er->cost); |
0f478e30 | 10702 | } else { |
d62a17ae | 10703 | vty_out(vty, |
996c9314 LB |
10704 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
10705 | "\n", | |
10706 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 10707 | er->u.ext.tag); |
d62a17ae | 10708 | } |
0f478e30 CS |
10709 | break; |
10710 | } | |
d62a17ae | 10711 | |
0f478e30 CS |
10712 | if (json) { |
10713 | json_nexthop_array = json_object_new_array(); | |
10714 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10715 | json_nexthop_array); |
0f478e30 CS |
10716 | } |
10717 | ||
996c9314 | 10718 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
10719 | if (json) { |
10720 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
10721 | json_object_array_add(json_nexthop_array, |
10722 | json_nexthop); | |
0f478e30 CS |
10723 | } |
10724 | ||
996c9314 | 10725 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
0f478e30 CS |
10726 | if (path->nexthop.s_addr == 0) { |
10727 | if (json) { | |
10728 | json_object_string_add( | |
996c9314 LB |
10729 | json_nexthop, "ip", |
10730 | " "); | |
0f478e30 CS |
10731 | json_object_string_add( |
10732 | json_nexthop, | |
10733 | "directly attached to", | |
d62a17ae | 10734 | ifindex2ifname( |
996c9314 LB |
10735 | path->ifindex, |
10736 | ospf->vrf_id)); | |
0f478e30 | 10737 | } else { |
d62a17ae | 10738 | vty_out(vty, |
996c9314 LB |
10739 | "%24s directly attached to %s\n", |
10740 | "", | |
10741 | ifindex2ifname( | |
10742 | path->ifindex, | |
10743 | ospf->vrf_id)); | |
0f478e30 CS |
10744 | } |
10745 | } else { | |
10746 | if (json) { | |
10747 | json_object_string_add( | |
996c9314 | 10748 | json_nexthop, "ip", |
96b663a3 MS |
10749 | inet_ntop( |
10750 | AF_INET, | |
10751 | &path->nexthop, | |
10752 | buf, | |
10753 | sizeof(buf))); | |
0f478e30 | 10754 | json_object_string_add( |
996c9314 | 10755 | json_nexthop, "via", |
d62a17ae | 10756 | ifindex2ifname( |
996c9314 LB |
10757 | path->ifindex, |
10758 | ospf->vrf_id)); | |
0f478e30 CS |
10759 | } else { |
10760 | vty_out(vty, | |
96b663a3 | 10761 | "%24s via %pI4, %s\n", |
996c9314 | 10762 | "", |
96b663a3 | 10763 | &path->nexthop, |
996c9314 LB |
10764 | ifindex2ifname( |
10765 | path->ifindex, | |
10766 | ospf->vrf_id)); | |
0f478e30 | 10767 | } |
d62a17ae | 10768 | } |
54bedb55 | 10769 | } |
d62a17ae | 10770 | } |
0f478e30 CS |
10771 | if (!json) |
10772 | json_object_free(json_route); | |
10773 | } | |
10774 | if (!json) | |
10775 | vty_out(vty, "\n"); | |
718e3744 | 10776 | } |
10777 | ||
d62a17ae | 10778 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
10779 | struct ospf *ospf, |
10780 | uint8_t use_vrf) | |
718e3744 | 10781 | { |
d62a17ae | 10782 | if (ospf->instance) |
10783 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 10784 | |
b1c3ae8c | 10785 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 10786 | |
d62a17ae | 10787 | if (ospf->new_table == NULL) { |
10788 | vty_out(vty, "No OSPF routing information exist\n"); | |
10789 | return CMD_SUCCESS; | |
10790 | } | |
718e3744 | 10791 | |
d62a17ae | 10792 | /* Show Network routes. |
10793 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 10794 | |
d62a17ae | 10795 | /* Show Router routes. */ |
0f478e30 | 10796 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 10797 | |
d62a17ae | 10798 | vty_out(vty, "\n"); |
7c8ff89e | 10799 | |
d62a17ae | 10800 | return CMD_SUCCESS; |
718e3744 | 10801 | } |
718e3744 | 10802 | |
7c8ff89e DS |
10803 | DEFUN (show_ip_ospf_border_routers, |
10804 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 10805 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 10806 | SHOW_STR |
10807 | IP_STR | |
10808 | "OSPF information\n" | |
b5a8894d CS |
10809 | VRF_CMD_HELP_STR |
10810 | "All VRFs\n" | |
7c8ff89e | 10811 | "Show all the ABR's and ASBR's\n") |
718e3744 | 10812 | { |
b5a8894d CS |
10813 | struct ospf *ospf = NULL; |
10814 | struct listnode *node = NULL; | |
10815 | char *vrf_name = NULL; | |
2951a7a4 | 10816 | bool all_vrf = false; |
b5a8894d CS |
10817 | int ret = CMD_SUCCESS; |
10818 | int inst = 0; | |
10819 | int idx_vrf = 0; | |
d7c0a89a | 10820 | uint8_t use_vrf = 0; |
68980084 | 10821 | |
43b8d1d8 | 10822 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 10823 | |
b5a8894d | 10824 | if (vrf_name) { |
2951a7a4 | 10825 | bool ospf_output = false; |
874f58d8 | 10826 | |
b1c3ae8c | 10827 | use_vrf = 1; |
94d4c685 | 10828 | |
b5a8894d CS |
10829 | if (all_vrf) { |
10830 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10831 | if (!ospf->oi_running) | |
10832 | continue; | |
b5a8894d | 10833 | |
2951a7a4 | 10834 | ospf_output = true; |
996c9314 LB |
10835 | ret = show_ip_ospf_border_routers_common( |
10836 | vty, ospf, use_vrf); | |
b5a8894d | 10837 | } |
9f049418 DS |
10838 | |
10839 | if (!ospf_output) | |
94d4c685 | 10840 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d CS |
10841 | } else { |
10842 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 10843 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 10844 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 10845 | return CMD_SUCCESS; |
9f049418 | 10846 | } |
b5a8894d | 10847 | |
b1c3ae8c CS |
10848 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
10849 | use_vrf); | |
b5a8894d CS |
10850 | } |
10851 | } else { | |
10852 | /* Display default ospf (instance 0) info */ | |
10853 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 10854 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 10855 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 10856 | return CMD_SUCCESS; |
9f049418 DS |
10857 | } |
10858 | ||
b1c3ae8c | 10859 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
10860 | } |
10861 | ||
10862 | return ret; | |
7c8ff89e DS |
10863 | } |
10864 | ||
10865 | DEFUN (show_ip_ospf_instance_border_routers, | |
10866 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 10867 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
10868 | SHOW_STR |
10869 | IP_STR | |
10870 | "OSPF information\n" | |
10871 | "Instance ID\n" | |
10872 | "Show all the ABR's and ASBR's\n") | |
10873 | { | |
d62a17ae | 10874 | int idx_number = 3; |
10875 | struct ospf *ospf; | |
d7c0a89a | 10876 | unsigned short instance = 0; |
7c8ff89e | 10877 | |
d62a17ae | 10878 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
10879 | ospf = ospf_lookup_instance(instance); |
10880 | if (ospf == NULL) | |
10881 | return CMD_NOT_MY_INSTANCE; | |
10882 | ||
10883 | if (!ospf->oi_running) | |
d62a17ae | 10884 | return CMD_SUCCESS; |
7c8ff89e | 10885 | |
b1c3ae8c | 10886 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
10887 | } |
10888 | ||
b1c3ae8c | 10889 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 10890 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 10891 | { |
0f478e30 CS |
10892 | json_object *json_vrf = NULL; |
10893 | ||
d62a17ae | 10894 | if (ospf->instance) |
10895 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 10896 | |
0f478e30 CS |
10897 | |
10898 | if (json) { | |
10899 | if (use_vrf) | |
10900 | json_vrf = json_object_new_object(); | |
10901 | else | |
10902 | json_vrf = json; | |
10903 | } | |
10904 | ||
10905 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
87bd50e8 | 10906 | |
d62a17ae | 10907 | if (ospf->new_table == NULL) { |
10908 | vty_out(vty, "No OSPF routing information exist\n"); | |
10909 | return CMD_SUCCESS; | |
10910 | } | |
718e3744 | 10911 | |
d62a17ae | 10912 | /* Show Network routes. */ |
0f478e30 | 10913 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 10914 | |
d62a17ae | 10915 | /* Show Router routes. */ |
0f478e30 | 10916 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 10917 | |
d62a17ae | 10918 | /* Show AS External routes. */ |
0f478e30 CS |
10919 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
10920 | json_vrf); | |
718e3744 | 10921 | |
0f478e30 CS |
10922 | if (json) { |
10923 | if (use_vrf) { | |
996c9314 LB |
10924 | // json_object_object_add(json_vrf, "areas", |
10925 | // json_areas); | |
0f478e30 CS |
10926 | if (ospf->vrf_id == VRF_DEFAULT) |
10927 | json_object_object_add(json, "default", | |
10928 | json_vrf); | |
10929 | else | |
10930 | json_object_object_add(json, ospf->name, | |
10931 | json_vrf); | |
10932 | } | |
10933 | } else { | |
10934 | vty_out(vty, "\n"); | |
10935 | } | |
7c8ff89e | 10936 | |
d62a17ae | 10937 | return CMD_SUCCESS; |
718e3744 | 10938 | } |
10939 | ||
7c8ff89e DS |
10940 | DEFUN (show_ip_ospf_route, |
10941 | show_ip_ospf_route_cmd, | |
0f478e30 | 10942 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
10943 | SHOW_STR |
10944 | IP_STR | |
10945 | "OSPF information\n" | |
10946 | VRF_CMD_HELP_STR | |
10947 | "All VRFs\n" | |
0f478e30 CS |
10948 | "OSPF routing table\n" |
10949 | JSON_STR) | |
b5a8894d CS |
10950 | { |
10951 | struct ospf *ospf = NULL; | |
10952 | struct listnode *node = NULL; | |
10953 | char *vrf_name = NULL; | |
2951a7a4 | 10954 | bool all_vrf = false; |
b5a8894d CS |
10955 | int ret = CMD_SUCCESS; |
10956 | int inst = 0; | |
10957 | int idx_vrf = 0; | |
d7c0a89a | 10958 | uint8_t use_vrf = 0; |
9f049418 | 10959 | bool uj = use_json(argc, argv); |
0f478e30 CS |
10960 | json_object *json = NULL; |
10961 | ||
10962 | if (uj) | |
10963 | json = json_object_new_object(); | |
7c8ff89e | 10964 | |
43b8d1d8 | 10965 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 10966 | |
b5a8894d CS |
10967 | /* vrf input is provided could be all or specific vrf*/ |
10968 | if (vrf_name) { | |
2951a7a4 | 10969 | bool ospf_output = false; |
874f58d8 | 10970 | |
b1c3ae8c | 10971 | use_vrf = 1; |
94d4c685 | 10972 | |
b5a8894d CS |
10973 | if (all_vrf) { |
10974 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10975 | if (!ospf->oi_running) | |
10976 | continue; | |
2951a7a4 | 10977 | ospf_output = true; |
0f478e30 | 10978 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 10979 | use_vrf); |
b5a8894d | 10980 | } |
0f478e30 CS |
10981 | |
10982 | if (uj) { | |
1406159f | 10983 | /* Keep Non-pretty format */ |
0f478e30 | 10984 | vty_out(vty, "%s\n", |
1406159f | 10985 | json_object_to_json_string(json)); |
0f478e30 | 10986 | json_object_free(json); |
9f049418 DS |
10987 | } else if (!ospf_output) |
10988 | vty_out(vty, "%% OSPF instance not found\n"); | |
0f478e30 | 10989 | |
b5a8894d CS |
10990 | return ret; |
10991 | } | |
10992 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 10993 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
10994 | if (uj) { |
10995 | vty_out(vty, "%s\n", | |
10996 | json_object_to_json_string_ext( | |
10997 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 10998 | json_object_free(json); |
9f049418 | 10999 | } else |
94d4c685 | 11000 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11001 | |
b5a8894d | 11002 | return CMD_SUCCESS; |
0f478e30 | 11003 | } |
b5a8894d CS |
11004 | } else { |
11005 | /* Display default ospf (instance 0) info */ | |
11006 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 11007 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11008 | if (uj) { |
11009 | vty_out(vty, "%s\n", | |
11010 | json_object_to_json_string_ext( | |
11011 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 11012 | json_object_free(json); |
9f049418 | 11013 | } else |
94d4c685 | 11014 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11015 | |
b5a8894d | 11016 | return CMD_SUCCESS; |
0f478e30 CS |
11017 | } |
11018 | } | |
11019 | ||
11020 | if (ospf) { | |
11021 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 11022 | /* Keep Non-pretty format */ |
0f478e30 | 11023 | if (uj) |
1406159f | 11024 | vty_out(vty, "%s\n", json_object_to_json_string(json)); |
b5a8894d CS |
11025 | } |
11026 | ||
0f478e30 CS |
11027 | if (uj) |
11028 | json_object_free(json); | |
b5a8894d CS |
11029 | |
11030 | return ret; | |
7c8ff89e DS |
11031 | } |
11032 | ||
11033 | DEFUN (show_ip_ospf_instance_route, | |
11034 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 11035 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
11036 | SHOW_STR |
11037 | IP_STR | |
11038 | "OSPF information\n" | |
11039 | "Instance ID\n" | |
11040 | "OSPF routing table\n") | |
11041 | { | |
d62a17ae | 11042 | int idx_number = 3; |
11043 | struct ospf *ospf; | |
d7c0a89a | 11044 | unsigned short instance = 0; |
7c8ff89e | 11045 | |
d62a17ae | 11046 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
11047 | ospf = ospf_lookup_instance(instance); |
11048 | if (ospf == NULL) | |
11049 | return CMD_NOT_MY_INSTANCE; | |
11050 | ||
11051 | if (!ospf->oi_running) | |
d62a17ae | 11052 | return CMD_SUCCESS; |
7c8ff89e | 11053 | |
0f478e30 | 11054 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 11055 | } |
6b0655a2 | 11056 | |
b5a8894d CS |
11057 | |
11058 | DEFUN (show_ip_ospf_vrfs, | |
11059 | show_ip_ospf_vrfs_cmd, | |
11060 | "show ip ospf vrfs [json]", | |
11061 | SHOW_STR | |
11062 | IP_STR | |
11063 | "OSPF information\n" | |
11064 | "Show OSPF VRFs \n" | |
11065 | JSON_STR) | |
11066 | { | |
9f049418 | 11067 | bool uj = use_json(argc, argv); |
b5a8894d CS |
11068 | json_object *json = NULL; |
11069 | json_object *json_vrfs = NULL; | |
11070 | struct ospf *ospf = NULL; | |
11071 | struct listnode *node = NULL; | |
11072 | int count = 0; | |
96b663a3 | 11073 | char buf[PREFIX_STRLEN]; |
2b64873d | 11074 | static const char header[] = "Name Id RouterId "; |
b5a8894d CS |
11075 | |
11076 | if (uj) { | |
11077 | json = json_object_new_object(); | |
11078 | json_vrfs = json_object_new_object(); | |
11079 | } | |
11080 | ||
11081 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11082 | json_object *json_vrf = NULL; | |
11083 | const char *name = NULL; | |
fe3da9e7 | 11084 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
11085 | |
11086 | count++; | |
11087 | ||
11088 | if (!uj && count == 1) | |
11089 | vty_out(vty, "%s\n", header); | |
11090 | if (uj) | |
11091 | json_vrf = json_object_new_object(); | |
11092 | ||
946de1b9 | 11093 | if (ospf->vrf_id == VRF_DEFAULT) |
b5a8894d CS |
11094 | name = VRF_DEFAULT_NAME; |
11095 | else | |
11096 | name = ospf->name; | |
11097 | ||
996c9314 LB |
11098 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
11099 | ? -1 | |
11100 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
11101 | |
11102 | if (uj) { | |
11103 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
96b663a3 MS |
11104 | json_object_string_add( |
11105 | json_vrf, "routerId", | |
11106 | inet_ntop(AF_INET, &ospf->router_id, | |
11107 | buf, sizeof(buf))); | |
b5a8894d CS |
11108 | |
11109 | json_object_object_add(json_vrfs, name, json_vrf); | |
11110 | ||
11111 | } else { | |
96b663a3 MS |
11112 | vty_out(vty, "%-25s %-5d %-16pI4 \n", name, |
11113 | ospf->vrf_id, &ospf->router_id); | |
b5a8894d CS |
11114 | } |
11115 | } | |
11116 | ||
11117 | if (uj) { | |
11118 | json_object_object_add(json, "vrfs", json_vrfs); | |
11119 | json_object_int_add(json, "totalVrfs", count); | |
11120 | ||
996c9314 LB |
11121 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
11122 | json, JSON_C_TO_STRING_PRETTY)); | |
b5a8894d CS |
11123 | json_object_free(json); |
11124 | } else { | |
11125 | if (count) | |
34d6798f | 11126 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
11127 | count); |
11128 | } | |
11129 | ||
11130 | return CMD_SUCCESS; | |
11131 | } | |
11132 | ||
2b64873d DL |
11133 | static const char *const ospf_abr_type_str[] = { |
11134 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
11135 | }; | |
718e3744 | 11136 | |
2b64873d DL |
11137 | static const char *const ospf_shortcut_mode_str[] = { |
11138 | "default", "enable", "disable" | |
11139 | }; | |
53e44d05 | 11140 | static int ospf_vty_external_rt_walkcb(struct hash_bucket *backet, |
11141 | void *arg) | |
11142 | { | |
11143 | struct external_info *ei = backet->data; | |
11144 | struct vty *vty = (struct vty *)arg; | |
11145 | static unsigned int count; | |
11146 | ||
11147 | vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen); | |
11148 | count++; | |
11149 | ||
11150 | if (count % 5 == 0) | |
11151 | vty_out(vty, "\n"); | |
11152 | ||
11153 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11154 | count = 0; | |
11155 | ||
11156 | return HASHWALK_CONTINUE; | |
11157 | } | |
11158 | ||
11159 | static int ospf_json_external_rt_walkcb(struct hash_bucket *backet, | |
11160 | void *arg) | |
11161 | { | |
11162 | struct external_info *ei = backet->data; | |
11163 | struct json_object *json = (struct json_object *)arg; | |
11164 | char buf[PREFIX2STR_BUFFER]; | |
11165 | char exnalbuf[20]; | |
11166 | static unsigned int count; | |
11167 | ||
11168 | prefix2str(&ei->p, buf, sizeof(buf)); | |
11169 | ||
11170 | snprintf(exnalbuf, 20, "Exnl Addr-%d", count); | |
11171 | ||
11172 | json_object_string_add(json, exnalbuf, buf); | |
11173 | ||
11174 | count++; | |
11175 | ||
11176 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11177 | count = 0; | |
11178 | ||
11179 | return HASHWALK_CONTINUE; | |
11180 | } | |
11181 | ||
11182 | static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf, | |
11183 | uint8_t use_vrf, json_object *json, | |
11184 | bool uj, bool detail) | |
11185 | { | |
11186 | struct route_node *rn; | |
11187 | json_object *json_vrf = NULL; | |
11188 | int mtype = 0; | |
11189 | int mval = 0; | |
11190 | static char header[] = | |
11191 | "Summary-address Metric-type Metric Tag External_Rt_count\n"; | |
11192 | ||
11193 | mtype = metric_type(ospf, 0, ospf->instance); | |
11194 | mval = metric_value(ospf, 0, ospf->instance); | |
11195 | ||
11196 | if (!uj) | |
11197 | vty_out(vty, "%s\n", header); | |
11198 | ||
11199 | if (uj) { | |
11200 | if (use_vrf) | |
11201 | json_vrf = json_object_new_object(); | |
11202 | else | |
11203 | json_vrf = json; | |
11204 | } | |
11205 | ||
11206 | if (ospf->instance) { | |
11207 | if (uj) | |
11208 | json_object_int_add(json, "ospfInstance", | |
11209 | ospf->instance); | |
11210 | else | |
11211 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
11212 | } | |
11213 | ||
11214 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
11215 | ||
11216 | if (!uj) | |
11217 | vty_out(vty, "aggregation delay interval :%d(in seconds)\n\n", | |
11218 | ospf->aggr_delay_interval); | |
11219 | else | |
11220 | json_object_int_add(json_vrf, "aggregation delay interval", | |
11221 | ospf->aggr_delay_interval); | |
11222 | ||
11223 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
11224 | if (rn->info) { | |
11225 | struct ospf_external_aggr_rt *aggr = rn->info; | |
11226 | json_object *json_aggr = NULL; | |
11227 | char buf[PREFIX2STR_BUFFER]; | |
11228 | ||
11229 | prefix2str(&aggr->p, buf, sizeof(buf)); | |
11230 | ||
11231 | if (uj) { | |
11232 | ||
11233 | json_aggr = json_object_new_object(); | |
11234 | ||
11235 | json_object_object_add(json_vrf, buf, | |
11236 | json_aggr); | |
11237 | ||
11238 | json_object_string_add(json_aggr, | |
11239 | "Summary address", buf); | |
11240 | ||
11241 | json_object_string_add( | |
11242 | json_aggr, "Metric-type", | |
11243 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11244 | ? "E1" | |
11245 | : "E2"); | |
11246 | ||
11247 | json_object_int_add(json_aggr, "Metric", mval); | |
11248 | ||
11249 | json_object_int_add(json_aggr, "Tag", | |
11250 | aggr->tag); | |
11251 | ||
11252 | json_object_int_add( | |
11253 | json_aggr, "External route count", | |
11254 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11255 | ||
11256 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11257 | hash_walk( | |
11258 | aggr->match_extnl_hash, | |
11259 | ospf_json_external_rt_walkcb, | |
11260 | json_aggr); | |
11261 | } | |
11262 | ||
11263 | } else { | |
11264 | vty_out(vty, "%-20s", buf); | |
11265 | ||
11266 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11267 | ? vty_out(vty, "%-16s", "E1") | |
11268 | : vty_out(vty, "%-16s", "E2"); | |
11269 | vty_out(vty, "%-11d", mval); | |
11270 | ||
11271 | vty_out(vty, "%-12u", aggr->tag); | |
11272 | ||
11273 | vty_out(vty, "%-5ld\n", | |
11274 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11275 | ||
11276 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11277 | vty_out(vty, | |
11278 | "Matched External routes:\n"); | |
11279 | hash_walk( | |
11280 | aggr->match_extnl_hash, | |
11281 | ospf_vty_external_rt_walkcb, | |
11282 | vty); | |
11283 | vty_out(vty, "\n"); | |
11284 | } | |
11285 | ||
11286 | vty_out(vty, "\n"); | |
11287 | } | |
11288 | } | |
11289 | ||
11290 | if (uj) { | |
11291 | if (use_vrf) { | |
11292 | if (ospf->vrf_id == VRF_DEFAULT) | |
11293 | json_object_object_add(json, "default", | |
11294 | json_vrf); | |
11295 | else | |
11296 | json_object_object_add(json, ospf->name, | |
11297 | json_vrf); | |
11298 | } | |
11299 | } else | |
11300 | vty_out(vty, "\n"); | |
11301 | ||
11302 | return CMD_SUCCESS; | |
11303 | } | |
11304 | ||
11305 | DEFUN (show_ip_ospf_external_aggregator, | |
11306 | show_ip_ospf_external_aggregator_cmd, | |
11307 | "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]", | |
11308 | SHOW_STR IP_STR | |
11309 | "OSPF information\n" | |
11310 | VRF_CMD_HELP_STR | |
11311 | "All VRFs\n" | |
11312 | "Show external summary addresses\n" | |
11313 | "Detailed informtion\n" | |
11314 | JSON_STR) | |
11315 | { | |
11316 | char *vrf_name = NULL; | |
11317 | bool all_vrf = false; | |
11318 | int ret = CMD_SUCCESS; | |
11319 | int idx_vrf = 0; | |
11320 | int idx = 0; | |
11321 | uint8_t use_vrf = 0; | |
11322 | bool uj = use_json(argc, argv); | |
11323 | struct ospf *ospf = NULL; | |
11324 | json_object *json = NULL; | |
11325 | struct listnode *node = NULL; | |
11326 | int inst = 0; | |
11327 | bool detail = false; | |
11328 | ||
11329 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
11330 | ||
11331 | if (argv_find(argv, argc, "detail", &idx)) | |
11332 | detail = true; | |
11333 | ||
11334 | if (uj) | |
11335 | json = json_object_new_object(); | |
11336 | ||
11337 | /* vrf input is provided */ | |
11338 | if (vrf_name) { | |
11339 | use_vrf = 1; | |
11340 | if (all_vrf) { | |
11341 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11342 | if (!ospf->oi_running) | |
11343 | continue; | |
11344 | ret = ospf_show_summary_address( | |
11345 | vty, ospf, use_vrf, json, uj, detail); | |
11346 | } | |
11347 | ||
11348 | if (uj) { | |
11349 | vty_out(vty, "%s\n", | |
11350 | json_object_to_json_string_ext( | |
11351 | json, JSON_C_TO_STRING_PRETTY)); | |
11352 | json_object_free(json); | |
11353 | } | |
11354 | ||
11355 | return ret; | |
11356 | } | |
11357 | ||
11358 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
11359 | ||
11360 | if (ospf == NULL || !ospf->oi_running) { | |
11361 | if (uj) { | |
11362 | vty_out(vty, "%s\n", | |
11363 | json_object_to_json_string_ext( | |
11364 | json, JSON_C_TO_STRING_PRETTY)); | |
11365 | json_object_free(json); | |
11366 | } else | |
11367 | vty_out(vty, "%% OSPF instance not found\n"); | |
11368 | ||
11369 | return CMD_SUCCESS; | |
11370 | } | |
fddbafcc | 11371 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); |
53e44d05 | 11372 | |
11373 | } else { | |
11374 | /* Default Vrf */ | |
11375 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
11376 | if (ospf == NULL || !ospf->oi_running) { | |
11377 | if (uj) { | |
11378 | vty_out(vty, "%s\n", | |
11379 | json_object_to_json_string_ext( | |
11380 | json, JSON_C_TO_STRING_PRETTY)); | |
11381 | json_object_free(json); | |
11382 | } else | |
11383 | vty_out(vty, "%% OSPF instance not found\n"); | |
11384 | ||
11385 | return CMD_SUCCESS; | |
11386 | } | |
11387 | ||
11388 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); | |
11389 | } | |
11390 | ||
11391 | if (uj) { | |
11392 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
11393 | json, JSON_C_TO_STRING_PRETTY)); | |
11394 | json_object_free(json); | |
11395 | } | |
11396 | return CMD_SUCCESS; | |
11397 | } | |
718e3744 | 11398 | |
2b64873d DL |
11399 | static const char *const ospf_int_type_str[] = { |
11400 | "unknown", /* should never be used. */ | |
11401 | "point-to-point", | |
11402 | "broadcast", | |
11403 | "non-broadcast", | |
11404 | "point-to-multipoint", | |
11405 | "virtual-link", /* should never be used. */ | |
11406 | "loopback" | |
11407 | }; | |
718e3744 | 11408 | |
83cc5a1f DE |
11409 | static const char *interface_config_auth_str(struct ospf_if_params *params) |
11410 | { | |
11411 | if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
11412 | || params->auth_type == OSPF_AUTH_NOTSET) | |
11413 | return NULL; | |
11414 | ||
11415 | /* Translation tables are not that much help | |
11416 | * here due to syntax | |
11417 | * of the simple option */ | |
11418 | switch (params->auth_type) { | |
11419 | ||
11420 | case OSPF_AUTH_NULL: | |
11421 | return " null"; | |
11422 | ||
11423 | case OSPF_AUTH_SIMPLE: | |
11424 | return ""; | |
11425 | ||
11426 | case OSPF_AUTH_CRYPTOGRAPHIC: | |
11427 | return " message-digest"; | |
11428 | } | |
11429 | ||
11430 | return ""; | |
11431 | } | |
11432 | ||
545f0503 | 11433 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 11434 | { |
f4e14fdb | 11435 | struct listnode *node; |
d62a17ae | 11436 | struct interface *ifp; |
11437 | struct crypt_key *ck; | |
d62a17ae | 11438 | struct route_node *rn = NULL; |
11439 | struct ospf_if_params *params; | |
83cc5a1f | 11440 | const char *auth_str; |
43b8d1d8 | 11441 | int write = 0; |
545f0503 | 11442 | struct ospf *ospf = vrf->info; |
d62a17ae | 11443 | |
545f0503 | 11444 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 11445 | |
545f0503 CS |
11446 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
11447 | continue; | |
35955c14 | 11448 | |
545f0503 | 11449 | vty_frame(vty, "!\n"); |
a36898e7 | 11450 | if (ifp->vrf_id == VRF_DEFAULT) |
545f0503 CS |
11451 | vty_frame(vty, "interface %s\n", ifp->name); |
11452 | else | |
996c9314 LB |
11453 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, |
11454 | vrf->name); | |
545f0503 CS |
11455 | if (ifp->desc) |
11456 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 11457 | |
545f0503 | 11458 | write++; |
43b8d1d8 | 11459 | |
545f0503 | 11460 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 11461 | |
545f0503 CS |
11462 | do { |
11463 | /* Interface Network print. */ | |
11464 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
11465 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 11466 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
11467 | vty_out(vty, " ip ospf network %s", |
11468 | ospf_int_type_str | |
996c9314 | 11469 | [params->type]); |
e425c019 | 11470 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11471 | vty_out(vty, " %pI4", |
11472 | &rn->p.u.prefix4); | |
545f0503 | 11473 | vty_out(vty, "\n"); |
d62a17ae | 11474 | } |
545f0503 | 11475 | } |
d62a17ae | 11476 | |
545f0503 | 11477 | /* OSPF interface authentication print */ |
83cc5a1f DE |
11478 | auth_str = interface_config_auth_str(params); |
11479 | if (auth_str) { | |
545f0503 CS |
11480 | vty_out(vty, " ip ospf authentication%s", |
11481 | auth_str); | |
e425c019 | 11482 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11483 | vty_out(vty, " %pI4", |
11484 | &rn->p.u.prefix4); | |
545f0503 CS |
11485 | vty_out(vty, "\n"); |
11486 | } | |
d62a17ae | 11487 | |
545f0503 CS |
11488 | /* Simple Authentication Password print. */ |
11489 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 11490 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
11491 | vty_out(vty, " ip ospf authentication-key %s", |
11492 | params->auth_simple); | |
e425c019 | 11493 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11494 | vty_out(vty, " %pI4", |
11495 | &rn->p.u.prefix4); | |
545f0503 CS |
11496 | vty_out(vty, "\n"); |
11497 | } | |
c7fd72d2 | 11498 | |
545f0503 CS |
11499 | /* Cryptographic Authentication Key print. */ |
11500 | if (params && params->auth_crypt) { | |
996c9314 LB |
11501 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
11502 | node, ck)) { | |
545f0503 CS |
11503 | vty_out(vty, |
11504 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 11505 | ck->key_id, ck->auth_key); |
e425c019 | 11506 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11507 | vty_out(vty, " %pI4", |
11508 | &rn->p.u.prefix4); | |
c7fd72d2 CS |
11509 | vty_out(vty, "\n"); |
11510 | } | |
545f0503 | 11511 | } |
d62a17ae | 11512 | |
545f0503 | 11513 | /* Interface Output Cost print. */ |
996c9314 | 11514 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
11515 | vty_out(vty, " ip ospf cost %u", |
11516 | params->output_cost_cmd); | |
e425c019 | 11517 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11518 | vty_out(vty, " %pI4", |
11519 | &rn->p.u.prefix4); | |
545f0503 CS |
11520 | vty_out(vty, "\n"); |
11521 | } | |
d62a17ae | 11522 | |
545f0503 CS |
11523 | /* Hello Interval print. */ |
11524 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 11525 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
11526 | vty_out(vty, " ip ospf hello-interval %u", |
11527 | params->v_hello); | |
e425c019 | 11528 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11529 | vty_out(vty, " %pI4", |
11530 | &rn->p.u.prefix4); | |
545f0503 CS |
11531 | vty_out(vty, "\n"); |
11532 | } | |
d62a17ae | 11533 | |
d62a17ae | 11534 | |
545f0503 CS |
11535 | /* Router Dead Interval print. */ |
11536 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
996c9314 LB |
11537 | && params->v_wait |
11538 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
545f0503 | 11539 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 11540 | |
545f0503 CS |
11541 | /* fast hello ? */ |
11542 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 11543 | fast_hello)) |
545f0503 CS |
11544 | vty_out(vty, |
11545 | "minimal hello-multiplier %d", | |
11546 | params->fast_hello); | |
11547 | else | |
996c9314 | 11548 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 11549 | |
e425c019 | 11550 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11551 | vty_out(vty, " %pI4", |
11552 | &rn->p.u.prefix4); | |
545f0503 CS |
11553 | vty_out(vty, "\n"); |
11554 | } | |
d62a17ae | 11555 | |
545f0503 CS |
11556 | /* Router Priority print. */ |
11557 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
11558 | && params->priority |
11559 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
11560 | vty_out(vty, " ip ospf priority %u", |
11561 | params->priority); | |
e425c019 | 11562 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11563 | vty_out(vty, " %pI4", |
11564 | &rn->p.u.prefix4); | |
545f0503 CS |
11565 | vty_out(vty, "\n"); |
11566 | } | |
d62a17ae | 11567 | |
545f0503 CS |
11568 | /* Retransmit Interval print. */ |
11569 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
11570 | retransmit_interval) |
11571 | && params->retransmit_interval | |
11572 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
11573 | vty_out(vty, " ip ospf retransmit-interval %u", |
11574 | params->retransmit_interval); | |
e425c019 | 11575 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11576 | vty_out(vty, " %pI4", |
11577 | &rn->p.u.prefix4); | |
545f0503 CS |
11578 | vty_out(vty, "\n"); |
11579 | } | |
d62a17ae | 11580 | |
545f0503 | 11581 | /* Transmit Delay print. */ |
996c9314 LB |
11582 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
11583 | && params->transmit_delay | |
11584 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
11585 | vty_out(vty, " ip ospf transmit-delay %u", |
11586 | params->transmit_delay); | |
e425c019 | 11587 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11588 | vty_out(vty, " %pI4", |
11589 | &rn->p.u.prefix4); | |
545f0503 CS |
11590 | vty_out(vty, "\n"); |
11591 | } | |
d62a17ae | 11592 | |
545f0503 CS |
11593 | /* Area print. */ |
11594 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
11595 | if (ospf && ospf->instance) | |
11596 | vty_out(vty, " ip ospf %d", | |
11597 | ospf->instance); | |
11598 | else | |
11599 | vty_out(vty, " ip ospf"); | |
d62a17ae | 11600 | |
1f9d4e3d | 11601 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 11602 | |
996c9314 LB |
11603 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
11604 | params->if_area_id_fmt); | |
545f0503 | 11605 | vty_out(vty, " area %s", buf); |
e425c019 | 11606 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11607 | vty_out(vty, " %pI4", |
11608 | &rn->p.u.prefix4); | |
545f0503 CS |
11609 | vty_out(vty, "\n"); |
11610 | } | |
d62a17ae | 11611 | |
545f0503 | 11612 | /* bfd print. */ |
e89ffeee | 11613 | if (params && params->bfd_info) |
545f0503 | 11614 | ospf_bfd_write_config(vty, params); |
d62a17ae | 11615 | |
545f0503 CS |
11616 | /* MTU ignore print. */ |
11617 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 11618 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
11619 | if (params->mtu_ignore == 0) |
11620 | vty_out(vty, " no ip ospf mtu-ignore"); | |
11621 | else | |
11622 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 11623 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11624 | vty_out(vty, " %pI4", |
11625 | &rn->p.u.prefix4); | |
545f0503 CS |
11626 | vty_out(vty, "\n"); |
11627 | } | |
a8b828f3 | 11628 | |
132a782e | 11629 | /* LDP-Sync print */ |
11630 | if (params && params->ldp_sync_info) | |
11631 | ospf_ldp_sync_if_write_config(vty, params); | |
d62a17ae | 11632 | |
545f0503 CS |
11633 | while (1) { |
11634 | if (rn == NULL) | |
996c9314 | 11635 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
11636 | else |
11637 | rn = route_next(rn); | |
43b8d1d8 | 11638 | |
545f0503 CS |
11639 | if (rn == NULL) |
11640 | break; | |
11641 | params = rn->info; | |
11642 | if (params != NULL) | |
11643 | break; | |
11644 | } | |
11645 | } while (rn); | |
43b8d1d8 | 11646 | |
545f0503 CS |
11647 | ospf_opaque_config_write_if(vty, ifp); |
11648 | ||
11649 | vty_endframe(vty, NULL); | |
b5a8894d | 11650 | } |
545f0503 | 11651 | |
d62a17ae | 11652 | return write; |
718e3744 | 11653 | } |
11654 | ||
43b8d1d8 CS |
11655 | /* Configuration write function for ospfd. */ |
11656 | static int config_write_interface(struct vty *vty) | |
11657 | { | |
11658 | int write = 0; | |
545f0503 | 11659 | struct vrf *vrf = NULL; |
43b8d1d8 | 11660 | |
545f0503 CS |
11661 | /* Display all VRF aware OSPF interface configuration */ |
11662 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
11663 | write += config_write_interface_one(vty, vrf); | |
11664 | } | |
43b8d1d8 CS |
11665 | |
11666 | return write; | |
11667 | } | |
11668 | ||
d62a17ae | 11669 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 11670 | { |
d62a17ae | 11671 | struct route_node *rn; |
fc746f1c | 11672 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 11673 | |
d62a17ae | 11674 | /* `network area' print. */ |
11675 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
11676 | if (rn->info) { | |
11677 | struct ospf_network *n = rn->info; | |
718e3744 | 11678 | |
d62a17ae | 11679 | /* Create Area ID string by specified Area ID format. */ |
11680 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
fc746f1c | 11681 | inet_ntop(AF_INET, &n->area_id, buf, |
1f9d4e3d | 11682 | sizeof(buf)); |
d62a17ae | 11683 | else |
fc746f1c QY |
11684 | snprintf(buf, sizeof(buf), "%lu", |
11685 | (unsigned long int)ntohl( | |
11686 | n->area_id.s_addr)); | |
718e3744 | 11687 | |
d62a17ae | 11688 | /* Network print. */ |
96b663a3 | 11689 | vty_out(vty, " network %pFX area %s\n", &rn->p, buf); |
d62a17ae | 11690 | } |
718e3744 | 11691 | |
d62a17ae | 11692 | return 0; |
718e3744 | 11693 | } |
11694 | ||
d62a17ae | 11695 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 11696 | { |
d62a17ae | 11697 | struct listnode *node; |
11698 | struct ospf_area *area; | |
fc746f1c | 11699 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 11700 | |
d62a17ae | 11701 | /* Area configuration print. */ |
11702 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
11703 | struct route_node *rn1; | |
718e3744 | 11704 | |
fc746f1c | 11705 | area_id2str(buf, sizeof(buf), &area->area_id, |
d62a17ae | 11706 | area->area_id_fmt); |
718e3744 | 11707 | |
d62a17ae | 11708 | if (area->auth_type != OSPF_AUTH_NULL) { |
11709 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
11710 | vty_out(vty, " area %s authentication\n", buf); | |
11711 | else | |
11712 | vty_out(vty, | |
11713 | " area %s authentication message-digest\n", | |
11714 | buf); | |
11715 | } | |
718e3744 | 11716 | |
d62a17ae | 11717 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
11718 | vty_out(vty, " area %s shortcut %s\n", buf, | |
11719 | ospf_shortcut_mode_str | |
11720 | [area->shortcut_configured]); | |
11721 | ||
11722 | if ((area->external_routing == OSPF_AREA_STUB) | |
11723 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 11724 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 11725 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
11726 | if (area->no_summary) |
11727 | vty_out(vty, " no-summary\n"); | |
11728 | vty_out(vty, "\n"); | |
11729 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 11730 | switch (area->NSSATranslatorRole) { |
11731 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
11732 | vty_out(vty, |
11733 | " area %s nssa translate-never\n", | |
11734 | buf); | |
d62a17ae | 11735 | break; |
11736 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
11737 | vty_out(vty, |
11738 | " area %s nssa translate-always\n", | |
11739 | buf); | |
d62a17ae | 11740 | break; |
2643b2bc CS |
11741 | case OSPF_NSSA_ROLE_CANDIDATE: |
11742 | vty_out(vty, " area %s nssa \n", buf); | |
11743 | break; | |
d62a17ae | 11744 | } |
7ef56a73 CS |
11745 | if (area->no_summary) |
11746 | vty_out(vty, | |
11747 | " area %s nssa no-summary\n", | |
11748 | buf); | |
d62a17ae | 11749 | } |
718e3744 | 11750 | |
d62a17ae | 11751 | if (area->default_cost != 1) |
11752 | vty_out(vty, " area %s default-cost %d\n", buf, | |
11753 | area->default_cost); | |
11754 | } | |
718e3744 | 11755 | |
d62a17ae | 11756 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
11757 | if (rn1->info) { | |
11758 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 11759 | |
96b663a3 MS |
11760 | vty_out(vty, " area %s range %pFX", buf, |
11761 | &rn1->p); | |
718e3744 | 11762 | |
d62a17ae | 11763 | if (range->cost_config |
11764 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
11765 | vty_out(vty, " cost %d", | |
11766 | range->cost_config); | |
718e3744 | 11767 | |
d62a17ae | 11768 | if (!CHECK_FLAG(range->flags, |
11769 | OSPF_AREA_RANGE_ADVERTISE)) | |
11770 | vty_out(vty, " not-advertise"); | |
718e3744 | 11771 | |
d62a17ae | 11772 | if (CHECK_FLAG(range->flags, |
11773 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
96b663a3 MS |
11774 | vty_out(vty, " substitute %pI4/%d", |
11775 | &range->subst_addr, | |
d62a17ae | 11776 | range->subst_masklen); |
11777 | ||
11778 | vty_out(vty, "\n"); | |
11779 | } | |
11780 | ||
11781 | if (EXPORT_NAME(area)) | |
11782 | vty_out(vty, " area %s export-list %s\n", buf, | |
11783 | EXPORT_NAME(area)); | |
11784 | ||
11785 | if (IMPORT_NAME(area)) | |
11786 | vty_out(vty, " area %s import-list %s\n", buf, | |
11787 | IMPORT_NAME(area)); | |
11788 | ||
11789 | if (PREFIX_NAME_IN(area)) | |
11790 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
11791 | PREFIX_NAME_IN(area)); | |
11792 | ||
11793 | if (PREFIX_NAME_OUT(area)) | |
11794 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
11795 | buf, PREFIX_NAME_OUT(area)); | |
11796 | } | |
11797 | ||
11798 | return 0; | |
718e3744 | 11799 | } |
11800 | ||
d62a17ae | 11801 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 11802 | { |
d62a17ae | 11803 | struct ospf_nbr_nbma *nbr_nbma; |
11804 | struct route_node *rn; | |
718e3744 | 11805 | |
d62a17ae | 11806 | /* Static Neighbor configuration print. */ |
11807 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
11808 | if ((nbr_nbma = rn->info)) { | |
96b663a3 | 11809 | vty_out(vty, " neighbor %pI4", &nbr_nbma->addr); |
718e3744 | 11810 | |
d62a17ae | 11811 | if (nbr_nbma->priority |
11812 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
11813 | vty_out(vty, " priority %d", | |
11814 | nbr_nbma->priority); | |
718e3744 | 11815 | |
d62a17ae | 11816 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
11817 | vty_out(vty, " poll-interval %d", | |
11818 | nbr_nbma->v_poll); | |
11819 | ||
11820 | vty_out(vty, "\n"); | |
11821 | } | |
11822 | ||
11823 | return 0; | |
11824 | } | |
11825 | ||
11826 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
11827 | { | |
11828 | struct listnode *node; | |
11829 | struct ospf_vl_data *vl_data; | |
83cc5a1f | 11830 | const char *auth_str; |
d62a17ae | 11831 | char buf[INET_ADDRSTRLEN]; |
11832 | ||
11833 | /* Virtual-Link print */ | |
11834 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
11835 | struct listnode *n2; | |
11836 | struct crypt_key *ck; | |
11837 | struct ospf_interface *oi; | |
11838 | ||
11839 | if (vl_data != NULL) { | |
d62a17ae | 11840 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
11841 | vl_data->vl_area_id_fmt); | |
11842 | oi = vl_data->vl_oi; | |
11843 | ||
11844 | /* timers */ | |
11845 | if (OSPF_IF_PARAM(oi, v_hello) | |
11846 | != OSPF_HELLO_INTERVAL_DEFAULT | |
11847 | || OSPF_IF_PARAM(oi, v_wait) | |
11848 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
11849 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
11850 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
11851 | || OSPF_IF_PARAM(oi, transmit_delay) | |
11852 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
11853 | vty_out(vty, | |
96b663a3 MS |
11854 | " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", |
11855 | buf, &vl_data->vl_peer, | |
d62a17ae | 11856 | OSPF_IF_PARAM(oi, v_hello), |
11857 | OSPF_IF_PARAM(oi, retransmit_interval), | |
11858 | OSPF_IF_PARAM(oi, transmit_delay), | |
11859 | OSPF_IF_PARAM(oi, v_wait)); | |
11860 | else | |
96b663a3 MS |
11861 | vty_out(vty, " area %s virtual-link %pI4\n", buf, |
11862 | &vl_data->vl_peer); | |
83cc5a1f DE |
11863 | /* Auth type */ |
11864 | auth_str = interface_config_auth_str( | |
11865 | IF_DEF_PARAMS(oi->ifp)); | |
11866 | if (auth_str) | |
11867 | vty_out(vty, | |
11868 | " area %s virtual-link %pI4 authentication%s\n", | |
11869 | buf, &vl_data->vl_peer, auth_str); | |
d62a17ae | 11870 | /* Auth key */ |
11871 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
11872 | != '\0') | |
11873 | vty_out(vty, | |
96b663a3 MS |
11874 | " area %s virtual-link %pI4 authentication-key %s\n", |
11875 | buf, &vl_data->vl_peer, | |
d62a17ae | 11876 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) |
11877 | ->auth_simple); | |
11878 | /* md5 keys */ | |
11879 | for (ALL_LIST_ELEMENTS_RO( | |
11880 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
11881 | ->auth_crypt, | |
11882 | n2, ck)) | |
11883 | vty_out(vty, | |
96b663a3 MS |
11884 | " area %s virtual-link %pI4 message-digest-key %d md5 %s\n", |
11885 | buf, &vl_data->vl_peer, | |
d62a17ae | 11886 | ck->key_id, ck->auth_key); |
11887 | } | |
11888 | } | |
11889 | ||
11890 | return 0; | |
718e3744 | 11891 | } |
11892 | ||
6b0655a2 | 11893 | |
d62a17ae | 11894 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 11895 | { |
d62a17ae | 11896 | int type; |
718e3744 | 11897 | |
d62a17ae | 11898 | /* redistribute print. */ |
11899 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
11900 | struct list *red_list; | |
11901 | struct listnode *node; | |
11902 | struct ospf_redist *red; | |
718e3744 | 11903 | |
d62a17ae | 11904 | red_list = ospf->redist[type]; |
11905 | if (!red_list) | |
11906 | continue; | |
7c8ff89e | 11907 | |
d62a17ae | 11908 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
11909 | vty_out(vty, " redistribute %s", | |
11910 | zebra_route_string(type)); | |
11911 | if (red->instance) | |
11912 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 11913 | |
d62a17ae | 11914 | if (red->dmetric.value >= 0) |
11915 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 11916 | |
d62a17ae | 11917 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
11918 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 11919 | |
d62a17ae | 11920 | if (ROUTEMAP_NAME(red)) |
11921 | vty_out(vty, " route-map %s", | |
11922 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 11923 | |
d62a17ae | 11924 | vty_out(vty, "\n"); |
11925 | } | |
11926 | } | |
718e3744 | 11927 | |
d62a17ae | 11928 | return 0; |
718e3744 | 11929 | } |
11930 | ||
07b33add | 11931 | static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *backet, |
11932 | void *arg) | |
11933 | { | |
11934 | struct advRtr *rtr = backet->data; | |
11935 | struct vty *vty = (struct vty *)arg; | |
11936 | ||
96b663a3 MS |
11937 | vty_out(vty, " graceful-restart helper-only %pI4\n", |
11938 | &rtr->advRtrAddr); | |
07b33add | 11939 | return HASHWALK_CONTINUE; |
11940 | } | |
11941 | ||
11942 | static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf) | |
11943 | { | |
11944 | if (ospf->is_helper_supported) | |
11945 | vty_out(vty, " graceful-restart helper-only\n"); | |
11946 | ||
11947 | if (!ospf->strict_lsa_check) | |
96b663a3 MS |
11948 | vty_out(vty, |
11949 | " no graceful-restart helper strict-lsa-checking\n"); | |
07b33add | 11950 | |
11951 | if (ospf->only_planned_restart) | |
11952 | vty_out(vty, " graceful-restart helper planned-only\n"); | |
11953 | ||
11954 | if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL) | |
11955 | vty_out(vty, | |
11956 | " graceful-restart helper supported-grace-time %d\n", | |
11957 | ospf->supported_grace_time); | |
11958 | ||
11959 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
11960 | hash_walk(ospf->enable_rtr_list, | |
11961 | ospf_cfg_write_helper_dis_rtr_walkcb, vty); | |
11962 | } | |
423e71c4 | 11963 | return 0; |
11964 | } | |
11965 | ||
11966 | static int config_write_ospf_external_aggregator(struct vty *vty, | |
11967 | struct ospf *ospf) | |
11968 | { | |
11969 | struct route_node *rn; | |
11970 | ||
11971 | /* print 'summary-address A.B.C.D/M' */ | |
11972 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
11973 | if (rn->info) { | |
11974 | struct ospf_external_aggr_rt *aggr = rn->info; | |
11975 | ||
11976 | vty_out(vty, " summary-address %pI4/%d ", | |
11977 | &aggr->p.prefix, aggr->p.prefixlen); | |
11978 | if (aggr->tag) | |
11979 | vty_out(vty, " tag %u ", aggr->tag); | |
11980 | ||
11981 | if (CHECK_FLAG(aggr->flags, | |
11982 | OSPF_EXTERNAL_AGGRT_NO_ADVERTISE)) | |
11983 | vty_out(vty, " no-advertise"); | |
11984 | ||
11985 | vty_out(vty, "\n"); | |
11986 | } | |
07b33add | 11987 | |
11988 | return 0; | |
11989 | } | |
11990 | ||
d62a17ae | 11991 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 11992 | { |
d62a17ae | 11993 | if (ospf->default_metric != -1) |
11994 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
11995 | return 0; | |
718e3744 | 11996 | } |
11997 | ||
d62a17ae | 11998 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
11999 | { | |
12000 | int type; | |
12001 | struct ospf_redist *red; | |
718e3744 | 12002 | |
d62a17ae | 12003 | if (ospf) { |
12004 | /* distribute-list print. */ | |
12005 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
12006 | if (DISTRIBUTE_NAME(ospf, type)) | |
12007 | vty_out(vty, " distribute-list %s out %s\n", | |
12008 | DISTRIBUTE_NAME(ospf, type), | |
12009 | zebra_route_string(type)); | |
7c8ff89e | 12010 | |
d62a17ae | 12011 | /* default-information print. */ |
12012 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
12013 | vty_out(vty, " default-information originate"); | |
12014 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
12015 | vty_out(vty, " always"); | |
718e3744 | 12016 | |
d62a17ae | 12017 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
12018 | if (red) { | |
12019 | if (red->dmetric.value >= 0) | |
12020 | vty_out(vty, " metric %d", | |
12021 | red->dmetric.value); | |
951da435 | 12022 | |
d62a17ae | 12023 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12024 | vty_out(vty, " metric-type 1"); | |
718e3744 | 12025 | |
d62a17ae | 12026 | if (ROUTEMAP_NAME(red)) |
12027 | vty_out(vty, " route-map %s", | |
12028 | ROUTEMAP_NAME(red)); | |
12029 | } | |
12030 | ||
12031 | vty_out(vty, "\n"); | |
12032 | } | |
12033 | } | |
12034 | ||
12035 | return 0; | |
718e3744 | 12036 | } |
12037 | ||
d62a17ae | 12038 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
12039 | { | |
12040 | struct route_node *rn; | |
12041 | struct ospf_distance *odistance; | |
12042 | ||
12043 | if (ospf->distance_all) | |
12044 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
12045 | ||
12046 | if (ospf->distance_intra || ospf->distance_inter | |
12047 | || ospf->distance_external) { | |
12048 | vty_out(vty, " distance ospf"); | |
12049 | ||
12050 | if (ospf->distance_intra) | |
12051 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
12052 | if (ospf->distance_inter) | |
12053 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
12054 | if (ospf->distance_external) | |
12055 | vty_out(vty, " external %d", ospf->distance_external); | |
12056 | ||
12057 | vty_out(vty, "\n"); | |
12058 | } | |
12059 | ||
12060 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
12061 | if ((odistance = rn->info) != NULL) { | |
96b663a3 MS |
12062 | vty_out(vty, " distance %d %pFX %s\n", |
12063 | odistance->distance, &rn->p, | |
d62a17ae | 12064 | odistance->access_list ? odistance->access_list |
12065 | : ""); | |
12066 | } | |
12067 | return 0; | |
718e3744 | 12068 | } |
12069 | ||
43b8d1d8 | 12070 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 12071 | { |
f4e14fdb | 12072 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 12073 | struct interface *ifp; |
12074 | struct ospf_interface *oi; | |
43b8d1d8 | 12075 | struct listnode *node = NULL; |
d62a17ae | 12076 | int write = 0; |
12077 | ||
43b8d1d8 CS |
12078 | /* `router ospf' print. */ |
12079 | if (ospf->instance && ospf->name) { | |
996c9314 LB |
12080 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
12081 | ospf->name); | |
43b8d1d8 | 12082 | } else if (ospf->instance) { |
996c9314 | 12083 | vty_out(vty, "router ospf %d\n", ospf->instance); |
43b8d1d8 | 12084 | } else if (ospf->name) { |
996c9314 | 12085 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
12086 | } else |
12087 | vty_out(vty, "router ospf\n"); | |
12088 | ||
12089 | if (!ospf->networks) { | |
12090 | write++; | |
b5a8894d | 12091 | return write; |
43b8d1d8 | 12092 | } |
d62a17ae | 12093 | |
43b8d1d8 CS |
12094 | /* Router ID print. */ |
12095 | if (ospf->router_id_static.s_addr != 0) | |
96b663a3 MS |
12096 | vty_out(vty, " ospf router-id %pI4\n", |
12097 | &ospf->router_id_static); | |
d62a17ae | 12098 | |
43b8d1d8 CS |
12099 | /* ABR type print. */ |
12100 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
12101 | vty_out(vty, " ospf abr-type %s\n", | |
12102 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 12103 | |
43b8d1d8 CS |
12104 | /* log-adjacency-changes flag print. */ |
12105 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
12106 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
12107 | vty_out(vty, " log-adjacency-changes detail\n"); | |
c572fbfe | 12108 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
43b8d1d8 | 12109 | vty_out(vty, " log-adjacency-changes\n"); |
c572fbfe | 12110 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
43b8d1d8 CS |
12111 | vty_out(vty, " no log-adjacency-changes\n"); |
12112 | } | |
b5a8894d | 12113 | |
43b8d1d8 CS |
12114 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
12115 | * 12.1. */ | |
12116 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
12117 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 12118 | |
43b8d1d8 CS |
12119 | /* auto-cost reference-bandwidth configuration. */ |
12120 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
12121 | vty_out(vty, | |
3efd0893 | 12122 | "! Important: ensure reference bandwidth is consistent across all routers\n"); |
43b8d1d8 CS |
12123 | vty_out(vty, " auto-cost reference-bandwidth %d\n", |
12124 | ospf->ref_bandwidth); | |
12125 | } | |
d62a17ae | 12126 | |
43b8d1d8 CS |
12127 | /* SPF timers print. */ |
12128 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
12129 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
12130 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
12131 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
12132 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
12133 | |
12134 | /* LSA timers print. */ | |
12135 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
12136 | vty_out(vty, " timers throttle lsa all %d\n", | |
12137 | ospf->min_ls_interval); | |
12138 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
12139 | vty_out(vty, " timers lsa min-arrival %d\n", | |
12140 | ospf->min_ls_arrival); | |
12141 | ||
12142 | /* Write multiplier print. */ | |
12143 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
12144 | vty_out(vty, " ospf write-multiplier %d\n", | |
12145 | ospf->write_oi_count); | |
d62a17ae | 12146 | |
43b8d1d8 CS |
12147 | /* Max-metric router-lsa print */ |
12148 | config_write_stub_router(vty, ospf); | |
d62a17ae | 12149 | |
43b8d1d8 | 12150 | /* SPF refresh parameters print. */ |
996c9314 LB |
12151 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
12152 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 12153 | |
43b8d1d8 CS |
12154 | /* Redistribute information print. */ |
12155 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 12156 | |
07b33add | 12157 | /* Print gr helper configs */ |
12158 | config_write_ospf_gr_helper(vty, ospf); | |
12159 | ||
423e71c4 | 12160 | /* Print external route aggregation. */ |
12161 | config_write_ospf_external_aggregator(vty, ospf); | |
12162 | ||
43b8d1d8 CS |
12163 | /* passive-interface print. */ |
12164 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
12165 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 12166 | |
a92706bb JU |
12167 | /* proactive-arp print. */ |
12168 | if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) { | |
12169 | if (ospf->proactive_arp) | |
12170 | vty_out(vty, " proactive-arp\n"); | |
12171 | else | |
12172 | vty_out(vty, " no proactive-arp\n"); | |
12173 | } | |
12174 | ||
451fda4f | 12175 | FOR_ALL_INTERFACES (vrf, ifp) |
43b8d1d8 CS |
12176 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
12177 | passive_interface) | |
12178 | && IF_DEF_PARAMS(ifp)->passive_interface | |
996c9314 | 12179 | != ospf->passive_interface_default) { |
43b8d1d8 | 12180 | vty_out(vty, " %spassive-interface %s\n", |
996c9314 LB |
12181 | IF_DEF_PARAMS(ifp)->passive_interface ? "" |
12182 | : "no ", | |
43b8d1d8 CS |
12183 | ifp->name); |
12184 | } | |
12185 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
996c9314 | 12186 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) |
43b8d1d8 CS |
12187 | continue; |
12188 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
12189 | passive_interface)) { | |
12190 | if (oi->params->passive_interface | |
996c9314 | 12191 | == IF_DEF_PARAMS(oi->ifp)->passive_interface) |
43b8d1d8 CS |
12192 | continue; |
12193 | } else if (oi->params->passive_interface | |
12194 | == ospf->passive_interface_default) | |
12195 | continue; | |
d62a17ae | 12196 | |
96b663a3 | 12197 | vty_out(vty, " %spassive-interface %s %pI4\n", |
43b8d1d8 | 12198 | oi->params->passive_interface ? "" : "no ", |
96b663a3 | 12199 | oi->ifp->name, &oi->address->u.prefix4); |
43b8d1d8 | 12200 | } |
d62a17ae | 12201 | |
43b8d1d8 CS |
12202 | /* Network area print. */ |
12203 | config_write_network_area(vty, ospf); | |
d62a17ae | 12204 | |
43b8d1d8 CS |
12205 | /* Area config print. */ |
12206 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 12207 | |
43b8d1d8 CS |
12208 | /* static neighbor print. */ |
12209 | config_write_ospf_nbr_nbma(vty, ospf); | |
12210 | ||
12211 | /* Virtual-Link print. */ | |
12212 | config_write_virtual_link(vty, ospf); | |
12213 | ||
12214 | /* Default metric configuration. */ | |
12215 | config_write_ospf_default_metric(vty, ospf); | |
12216 | ||
12217 | /* Distribute-list and default-information print. */ | |
12218 | config_write_ospf_distribute(vty, ospf); | |
12219 | ||
12220 | /* Distance configuration. */ | |
12221 | config_write_ospf_distance(vty, ospf); | |
12222 | ||
12223 | ospf_opaque_config_write_router(vty, ospf); | |
12224 | ||
132a782e | 12225 | /* LDP-Sync print */ |
12226 | ospf_ldp_sync_write_config(vty, ospf); | |
12227 | ||
43b8d1d8 CS |
12228 | write++; |
12229 | return write; | |
12230 | } | |
12231 | ||
12232 | /* OSPF configuration write function. */ | |
12233 | static int ospf_config_write(struct vty *vty) | |
12234 | { | |
12235 | struct ospf *ospf; | |
12236 | struct listnode *ospf_node = NULL; | |
12237 | int write = 0; | |
12238 | ||
12239 | if (listcount(om->ospf) == 0) | |
12240 | return write; | |
12241 | ||
12242 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
12243 | /* VRF Default check if it is running. |
12244 | * Upon daemon start, there could be default instance | |
12245 | * in absence of 'router ospf'/oi_running is disabled. */ | |
12246 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
12247 | write += ospf_config_write_one(vty, ospf); | |
12248 | /* For Non-Default VRF simply display the configuration, | |
12249 | * even if it is not oi_running. */ | |
12250 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 12251 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 12252 | } |
d62a17ae | 12253 | return write; |
12254 | } | |
12255 | ||
12256 | void ospf_vty_show_init(void) | |
12257 | { | |
12258 | /* "show ip ospf" commands. */ | |
12259 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
12260 | ||
12261 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
12262 | ||
12263 | /* "show ip ospf database" commands. */ | |
12264 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
12265 | ||
12266 | install_element(VIEW_NODE, | |
12267 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
12268 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
12269 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
12270 | ||
12271 | /* "show ip ospf interface" commands. */ | |
12272 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
12273 | ||
12274 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
12275 | /* "show ip ospf interface traffic */ |
12276 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 12277 | |
12278 | /* "show ip ospf neighbor" commands. */ | |
12279 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
12280 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
12281 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
12282 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
12283 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
12284 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
12285 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
12286 | ||
12287 | install_element(VIEW_NODE, | |
12288 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
12289 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
12290 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
12291 | install_element(VIEW_NODE, | |
12292 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
12293 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
12294 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
12295 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
12296 | ||
12297 | /* "show ip ospf route" commands. */ | |
12298 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
12299 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
12300 | ||
12301 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
12302 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
12303 | |
12304 | /* "show ip ospf vrfs" commands. */ | |
12305 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
abd5b8c7 | 12306 | |
12307 | /* "show ip ospf gr-helper details" command */ | |
12308 | install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd); | |
718e3744 | 12309 | |
53e44d05 | 12310 | /* "show ip ospf summary-address" command */ |
12311 | install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd); | |
12312 | } | |
6b0655a2 | 12313 | |
612c2c15 | 12314 | static int config_write_interface(struct vty *vty); |
718e3744 | 12315 | /* ospfd's interface node. */ |
62b346ee | 12316 | static struct cmd_node interface_node = { |
f4b8291f | 12317 | .name = "interface", |
62b346ee | 12318 | .node = INTERFACE_NODE, |
24389580 | 12319 | .parent_node = CONFIG_NODE, |
62b346ee | 12320 | .prompt = "%s(config-if)# ", |
612c2c15 | 12321 | .config_write = config_write_interface, |
62b346ee | 12322 | }; |
718e3744 | 12323 | |
12324 | /* Initialization of OSPF interface. */ | |
d62a17ae | 12325 | static void ospf_vty_if_init(void) |
12326 | { | |
12327 | /* Install interface node. */ | |
612c2c15 | 12328 | install_node(&interface_node); |
d62a17ae | 12329 | if_cmd_init(); |
12330 | ||
12331 | /* "ip ospf authentication" commands. */ | |
12332 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
12333 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
12334 | install_element(INTERFACE_NODE, | |
12335 | &no_ip_ospf_authentication_args_addr_cmd); | |
12336 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
12337 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
12338 | install_element(INTERFACE_NODE, | |
12339 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
12340 | install_element(INTERFACE_NODE, | |
12341 | &no_ospf_authentication_key_authkey_addr_cmd); | |
12342 | ||
12343 | /* "ip ospf message-digest-key" commands. */ | |
12344 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
12345 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
12346 | ||
12347 | /* "ip ospf cost" commands. */ | |
12348 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
12349 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
12350 | ||
12351 | /* "ip ospf mtu-ignore" commands. */ | |
12352 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
12353 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
12354 | ||
12355 | /* "ip ospf dead-interval" commands. */ | |
12356 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
12357 | install_element(INTERFACE_NODE, | |
12358 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
12359 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
12360 | ||
12361 | /* "ip ospf hello-interval" commands. */ | |
12362 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
12363 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
12364 | ||
12365 | /* "ip ospf network" commands. */ | |
12366 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
12367 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
12368 | ||
12369 | /* "ip ospf priority" commands. */ | |
12370 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
12371 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
12372 | ||
12373 | /* "ip ospf retransmit-interval" commands. */ | |
12374 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
12375 | install_element(INTERFACE_NODE, | |
12376 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
12377 | ||
12378 | /* "ip ospf transmit-delay" commands. */ | |
12379 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
12380 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
12381 | ||
12382 | /* "ip ospf area" commands. */ | |
12383 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
12384 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
12385 | ||
12386 | /* These commands are compatibitliy for previous version. */ | |
12387 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
12388 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
12389 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
12390 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
12391 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
12392 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
12393 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
12394 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
12395 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
12396 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
12397 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
12398 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
12399 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
12400 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
12401 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
12402 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
12403 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
12404 | } | |
12405 | ||
12406 | static void ospf_vty_zebra_init(void) | |
12407 | { | |
12408 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
12409 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
12410 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
12411 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
12412 | ||
12413 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
12414 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
12415 | ||
12416 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
12417 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
12418 | ||
12419 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
12420 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
12421 | ||
12422 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
12423 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
12424 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
12425 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
07b33add | 12426 | |
12427 | /*Ospf garcefull restart helper configurations */ | |
12428 | install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd); | |
12429 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd); | |
12430 | install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd); | |
12431 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd); | |
12432 | install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd); | |
12433 | install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd); | |
12434 | install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd); | |
12435 | install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd); | |
423e71c4 | 12436 | |
12437 | /* External LSA summarisation config commands.*/ | |
12438 | install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd); | |
12439 | install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd); | |
12440 | install_element(OSPF_NODE, | |
12441 | &ospf_external_route_aggregation_no_adrvertise_cmd); | |
12442 | install_element(OSPF_NODE, | |
12443 | &no_ospf_external_route_aggregation_no_adrvertise_cmd); | |
12444 | install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd); | |
12445 | install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd); | |
12446 | ||
718e3744 | 12447 | #if 0 |
12448 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
12449 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
12450 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
12451 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
12452 | #endif /* 0 */ | |
12453 | } | |
12454 | ||
612c2c15 | 12455 | static int ospf_config_write(struct vty *vty); |
62b346ee | 12456 | static struct cmd_node ospf_node = { |
f4b8291f | 12457 | .name = "ospf", |
62b346ee | 12458 | .node = OSPF_NODE, |
24389580 | 12459 | .parent_node = CONFIG_NODE, |
62b346ee | 12460 | .prompt = "%s(config-router)# ", |
612c2c15 | 12461 | .config_write = ospf_config_write, |
62b346ee | 12462 | }; |
718e3744 | 12463 | |
d62a17ae | 12464 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 12465 | { |
d62a17ae | 12466 | if (!if_is_operative(ifp)) |
12467 | return; | |
09f35f8c | 12468 | |
d62a17ae | 12469 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
12470 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 12471 | |
d62a17ae | 12472 | ospf_if_reset(ifp); |
09f35f8c DS |
12473 | } |
12474 | ||
12475 | DEFUN (clear_ip_ospf_interface, | |
12476 | clear_ip_ospf_interface_cmd, | |
1e81afc3 | 12477 | "clear ip ospf [vrf NAME] interface [IFNAME]", |
09f35f8c DS |
12478 | CLEAR_STR |
12479 | IP_STR | |
12480 | "OSPF information\n" | |
03ed9f02 | 12481 | VRF_CMD_HELP_STR |
09f35f8c DS |
12482 | "Interface information\n" |
12483 | "Interface name\n") | |
12484 | { | |
03ed9f02 PG |
12485 | int idx_ifname = 0; |
12486 | int idx_vrf = 0; | |
d62a17ae | 12487 | struct interface *ifp; |
f4e14fdb | 12488 | struct listnode *node; |
b5a8894d | 12489 | struct ospf *ospf = NULL; |
03ed9f02 PG |
12490 | char *vrf_name = NULL; |
12491 | vrf_id_t vrf_id = VRF_DEFAULT; | |
12492 | struct vrf *vrf = NULL; | |
09f35f8c | 12493 | |
03ed9f02 PG |
12494 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
12495 | vrf_name = argv[idx_vrf + 1]->arg; | |
12496 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
12497 | vrf_name = NULL; | |
12498 | if (vrf_name) { | |
12499 | vrf = vrf_lookup_by_name(vrf_name); | |
12500 | if (vrf) | |
12501 | vrf_id = vrf->vrf_id; | |
12502 | } | |
12503 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
12504 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 12505 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
12506 | if (vrf_id != ospf->vrf_id) |
12507 | continue; | |
12508 | if (!vrf) | |
12509 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 12510 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
12511 | ospf_interface_clear(ifp); |
12512 | } | |
12513 | } else { | |
12514 | /* Interface name is specified. */ | |
a36898e7 | 12515 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 12516 | if (ifp == NULL) |
d62a17ae | 12517 | vty_out(vty, "No such interface name\n"); |
12518 | else | |
12519 | ospf_interface_clear(ifp); | |
12520 | } | |
12521 | ||
12522 | return CMD_SUCCESS; | |
09f35f8c DS |
12523 | } |
12524 | ||
d62a17ae | 12525 | void ospf_vty_clear_init(void) |
09f35f8c | 12526 | { |
d62a17ae | 12527 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
09f35f8c DS |
12528 | } |
12529 | ||
6b0655a2 | 12530 | |
718e3744 | 12531 | /* Install OSPF related vty commands. */ |
d62a17ae | 12532 | void ospf_vty_init(void) |
12533 | { | |
12534 | /* Install ospf top node. */ | |
612c2c15 | 12535 | install_node(&ospf_node); |
d62a17ae | 12536 | |
12537 | /* "router ospf" commands. */ | |
12538 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
12539 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
12540 | ||
12541 | ||
12542 | install_default(OSPF_NODE); | |
12543 | ||
12544 | /* "ospf router-id" commands. */ | |
12545 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
12546 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
12547 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
12548 | ||
12549 | /* "passive-interface" commands. */ | |
12550 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
12551 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
12552 | ||
12553 | /* "ospf abr-type" commands. */ | |
12554 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
12555 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
12556 | ||
12557 | /* "ospf log-adjacency-changes" commands. */ | |
12558 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
12559 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
12560 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
12561 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
12562 | ||
12563 | /* "ospf rfc1583-compatible" commands. */ | |
12564 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
12565 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
12566 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
12567 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
12568 | ||
12569 | /* "network area" commands. */ | |
12570 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
12571 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
12572 | ||
12573 | /* "area authentication" commands. */ | |
12574 | install_element(OSPF_NODE, | |
12575 | &ospf_area_authentication_message_digest_cmd); | |
12576 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
12577 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
12578 | ||
12579 | /* "area range" commands. */ | |
12580 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
12581 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
12582 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
12583 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
12584 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
12585 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
12586 | ||
12587 | /* "area virtual-link" commands. */ | |
12588 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
12589 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
12590 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
12591 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
12592 | ||
12593 | ||
12594 | /* "area stub" commands. */ | |
12595 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
12596 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
12597 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
12598 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
12599 | ||
12600 | /* "area nssa" commands. */ | |
12601 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 12602 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
12603 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 12604 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
d62a17ae | 12605 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
12606 | ||
12607 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
12608 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
12609 | ||
12610 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
12611 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
12612 | ||
12613 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
12614 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
12615 | ||
12616 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
12617 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
12618 | ||
12619 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
12620 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
12621 | ||
12622 | /* SPF timer commands */ | |
12623 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
12624 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
12625 | ||
12626 | /* LSA timers commands */ | |
12627 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
12628 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
12629 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
12630 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 12631 | |
12632 | /* refresh timer commands */ | |
12633 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
12634 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
12635 | ||
12636 | /* max-metric commands */ | |
12637 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
12638 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
12639 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
12640 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
12641 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
12642 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
12643 | ||
12644 | /* reference bandwidth commands */ | |
12645 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
12646 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
12647 | ||
12648 | /* "neighbor" commands. */ | |
12649 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
12650 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
12651 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
12652 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
12653 | ||
12654 | /* write multiplier commands */ | |
12655 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
12656 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
12657 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
12658 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
12659 | ||
a92706bb JU |
12660 | /* "proactive-arp" commands. */ |
12661 | install_element(OSPF_NODE, &ospf_proactive_arp_cmd); | |
12662 | install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd); | |
12663 | ||
d62a17ae | 12664 | /* Init interface related vty commands. */ |
12665 | ospf_vty_if_init(); | |
12666 | ||
12667 | /* Init zebra related vty commands. */ | |
12668 | ospf_vty_zebra_init(); | |
718e3744 | 12669 | } |