/src/frr/ospfd/ospf_vty.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | | /* OSPF VTY interface. |
3 | | * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com> |
4 | | * Copyright (C) 2000 Toshiaki Takada |
5 | | */ |
6 | | |
7 | | #include <zebra.h> |
8 | | #include <string.h> |
9 | | |
10 | | #include "printfrr.h" |
11 | | #include "monotime.h" |
12 | | #include "memory.h" |
13 | | #include "frrevent.h" |
14 | | #include "prefix.h" |
15 | | #include "table.h" |
16 | | #include "vty.h" |
17 | | #include "command.h" |
18 | | #include "plist.h" |
19 | | #include "log.h" |
20 | | #include "zclient.h" |
21 | | #include <lib/json.h> |
22 | | #include "defaults.h" |
23 | | #include "lib/printfrr.h" |
24 | | |
25 | | #include "ospfd/ospfd.h" |
26 | | #include "ospfd/ospf_asbr.h" |
27 | | #include "ospfd/ospf_lsa.h" |
28 | | #include "ospfd/ospf_lsdb.h" |
29 | | #include "ospfd/ospf_ism.h" |
30 | | #include "ospfd/ospf_interface.h" |
31 | | #include "ospfd/ospf_nsm.h" |
32 | | #include "ospfd/ospf_neighbor.h" |
33 | | #include "ospfd/ospf_flood.h" |
34 | | #include "ospfd/ospf_abr.h" |
35 | | #include "ospfd/ospf_spf.h" |
36 | | #include "ospfd/ospf_route.h" |
37 | | #include "ospfd/ospf_zebra.h" |
38 | | #include "ospfd/ospf_vty.h" |
39 | | #include "ospfd/ospf_dump.h" |
40 | | #include "ospfd/ospf_bfd.h" |
41 | | #include "ospfd/ospf_ldp_sync.h" |
42 | | #include "ospfd/ospf_network.h" |
43 | | |
44 | | FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES, |
45 | | { .val_bool = true, .match_profile = "datacenter", }, |
46 | | { .val_bool = false }, |
47 | | ); |
48 | | |
49 | | static const char *const ospf_network_type_str[] = { |
50 | | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", |
51 | | "VIRTUALLINK", "LOOPBACK"}; |
52 | | |
53 | | /* Utility functions. */ |
54 | | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) |
55 | 0 | { |
56 | 0 | char *ep; |
57 | |
|
58 | 0 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); |
59 | 0 | if (*ep && !inet_aton(str, area_id)) |
60 | 0 | return -1; |
61 | | |
62 | 0 | *area_id_fmt = |
63 | 0 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; |
64 | |
|
65 | 0 | return 0; |
66 | 0 | } |
67 | | |
68 | | static void area_id2str(char *buf, int length, struct in_addr *area_id, |
69 | | int area_id_fmt) |
70 | 0 | { |
71 | 0 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
72 | 0 | inet_ntop(AF_INET, area_id, buf, length); |
73 | 0 | else |
74 | 0 | snprintf(buf, length, "%lu", |
75 | 0 | (unsigned long)ntohl(area_id->s_addr)); |
76 | 0 | } |
77 | | |
78 | | static int str2metric(const char *str, int *metric) |
79 | 0 | { |
80 | | /* Sanity check. */ |
81 | 0 | if (str == NULL) |
82 | 0 | return 0; |
83 | | |
84 | 0 | *metric = strtol(str, NULL, 10); |
85 | 0 | if (*metric < 0 || *metric > 16777214) { |
86 | | /* vty_out (vty, "OSPF metric value is invalid\n"); */ |
87 | 0 | return 0; |
88 | 0 | } |
89 | | |
90 | 0 | return 1; |
91 | 0 | } |
92 | | |
93 | | static int str2metric_type(const char *str, int *metric_type) |
94 | 0 | { |
95 | | /* Sanity check. */ |
96 | 0 | if (str == NULL) |
97 | 0 | return 0; |
98 | | |
99 | 0 | if (strncmp(str, "1", 1) == 0) |
100 | 0 | *metric_type = EXTERNAL_METRIC_TYPE_1; |
101 | 0 | else if (strncmp(str, "2", 1) == 0) |
102 | 0 | *metric_type = EXTERNAL_METRIC_TYPE_2; |
103 | 0 | else |
104 | 0 | return 0; |
105 | | |
106 | 0 | return 1; |
107 | 0 | } |
108 | | |
109 | | int ospf_oi_count(struct interface *ifp) |
110 | 0 | { |
111 | 0 | struct route_node *rn; |
112 | 0 | int i = 0; |
113 | |
|
114 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
115 | 0 | if (rn->info) |
116 | 0 | i++; |
117 | |
|
118 | 0 | return i; |
119 | 0 | } |
120 | | |
121 | | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ |
122 | 0 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ |
123 | 0 | vrf_name = argv[idx_vrf + 1]->arg; \ |
124 | 0 | all_vrf = strmatch(vrf_name, "all"); \ |
125 | 0 | } |
126 | | |
127 | | static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[], |
128 | | const int argc, unsigned short *instance, |
129 | | const char **vrf_name) |
130 | 0 | { |
131 | 0 | int idx_vrf = 0, idx_inst = 0; |
132 | |
|
133 | 0 | *instance = 0; |
134 | 0 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) { |
135 | 0 | if (ospf_instance == 0) { |
136 | 0 | vty_out(vty, |
137 | 0 | "%% OSPF is not running in instance mode\n"); |
138 | 0 | return CMD_WARNING_CONFIG_FAILED; |
139 | 0 | } |
140 | | |
141 | 0 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); |
142 | 0 | } |
143 | | |
144 | 0 | *vrf_name = VRF_DEFAULT_NAME; |
145 | 0 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
146 | 0 | if (ospf_instance != 0) { |
147 | 0 | vty_out(vty, |
148 | 0 | "%% VRF is not supported in instance mode\n"); |
149 | 0 | return CMD_WARNING_CONFIG_FAILED; |
150 | 0 | } |
151 | | |
152 | 0 | *vrf_name = argv[idx_vrf + 1]->arg; |
153 | 0 | } |
154 | | |
155 | 0 | return CMD_SUCCESS; |
156 | 0 | } |
157 | | |
158 | | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
159 | | json_object *json, uint8_t use_vrf) |
160 | 0 | { |
161 | 0 | if (use_vrf) { |
162 | 0 | if (json) { |
163 | 0 | json_object_string_add(json, "vrfName", |
164 | 0 | ospf_get_name(ospf)); |
165 | 0 | json_object_int_add(json, "vrfId", ospf->vrf_id); |
166 | 0 | } else |
167 | 0 | vty_out(vty, "VRF Name: %s\n", ospf_get_name(ospf)); |
168 | 0 | } |
169 | 0 | } |
170 | | |
171 | | #include "ospfd/ospf_vty_clippy.c" |
172 | | |
173 | | DEFUN_NOSH (router_ospf, |
174 | | router_ospf_cmd, |
175 | | "router ospf [{(1-65535)|vrf NAME}]", |
176 | | "Enable a routing process\n" |
177 | | "Start OSPF configuration\n" |
178 | | "Instance ID\n" |
179 | | VRF_CMD_HELP_STR) |
180 | 0 | { |
181 | 0 | unsigned short instance; |
182 | 0 | const char *vrf_name; |
183 | 0 | bool created = false; |
184 | 0 | struct ospf *ospf; |
185 | 0 | int ret; |
186 | |
|
187 | 0 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
188 | 0 | if (ret != CMD_SUCCESS) |
189 | 0 | return ret; |
190 | | |
191 | 0 | if (instance != ospf_instance) { |
192 | 0 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
193 | 0 | return CMD_NOT_MY_INSTANCE; |
194 | 0 | } |
195 | | |
196 | 0 | ospf = ospf_get(instance, vrf_name, &created); |
197 | |
|
198 | 0 | if (created) |
199 | 0 | if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) |
200 | 0 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
201 | |
|
202 | 0 | if (IS_DEBUG_OSPF_EVENT) |
203 | 0 | zlog_debug( |
204 | 0 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", |
205 | 0 | ospf->instance, ospf_get_name(ospf), ospf->vrf_id, |
206 | 0 | ospf->oi_running); |
207 | |
|
208 | 0 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); |
209 | |
|
210 | 0 | return ret; |
211 | 0 | } |
212 | | |
213 | | DEFUN (no_router_ospf, |
214 | | no_router_ospf_cmd, |
215 | | "no router ospf [{(1-65535)|vrf NAME}]", |
216 | | NO_STR |
217 | | "Enable a routing process\n" |
218 | | "Start OSPF configuration\n" |
219 | | "Instance ID\n" |
220 | | VRF_CMD_HELP_STR) |
221 | 0 | { |
222 | 0 | unsigned short instance; |
223 | 0 | const char *vrf_name; |
224 | 0 | struct ospf *ospf; |
225 | 0 | int ret; |
226 | |
|
227 | 0 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
228 | 0 | if (ret != CMD_SUCCESS) |
229 | 0 | return ret; |
230 | | |
231 | 0 | if (instance != ospf_instance) |
232 | 0 | return CMD_NOT_MY_INSTANCE; |
233 | | |
234 | 0 | ospf = ospf_lookup(instance, vrf_name); |
235 | 0 | if (ospf) { |
236 | 0 | if (ospf->gr_info.restart_support) |
237 | 0 | ospf_gr_nvm_delete(ospf); |
238 | |
|
239 | 0 | ospf_finish(ospf); |
240 | 0 | } else |
241 | 0 | ret = CMD_WARNING_CONFIG_FAILED; |
242 | |
|
243 | 0 | return ret; |
244 | 0 | } |
245 | | |
246 | | |
247 | | DEFPY (ospf_router_id, |
248 | | ospf_router_id_cmd, |
249 | | "ospf router-id A.B.C.D", |
250 | | "OSPF specific commands\n" |
251 | | "router-id for the OSPF process\n" |
252 | | "OSPF router-id in IP address format\n") |
253 | 0 | { |
254 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
255 | |
|
256 | 0 | struct listnode *node; |
257 | 0 | struct ospf_area *area; |
258 | |
|
259 | 0 | ospf->router_id_static = router_id; |
260 | |
|
261 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
262 | 0 | if (area->full_nbrs) { |
263 | 0 | vty_out(vty, |
264 | 0 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
265 | 0 | return CMD_SUCCESS; |
266 | 0 | } |
267 | | |
268 | 0 | ospf_router_id_update(ospf); |
269 | |
|
270 | 0 | return CMD_SUCCESS; |
271 | 0 | } |
272 | | |
273 | | DEFUN_HIDDEN (ospf_router_id_old, |
274 | | ospf_router_id_old_cmd, |
275 | | "router-id A.B.C.D", |
276 | | "router-id for the OSPF process\n" |
277 | | "OSPF router-id in IP address format\n") |
278 | 0 | { |
279 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
280 | 0 | int idx_ipv4 = 1; |
281 | 0 | struct listnode *node; |
282 | 0 | struct ospf_area *area; |
283 | 0 | struct in_addr router_id; |
284 | 0 | int ret; |
285 | |
|
286 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); |
287 | 0 | if (!ret) { |
288 | 0 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); |
289 | 0 | return CMD_WARNING_CONFIG_FAILED; |
290 | 0 | } |
291 | | |
292 | 0 | ospf->router_id_static = router_id; |
293 | |
|
294 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
295 | 0 | if (area->full_nbrs) { |
296 | 0 | vty_out(vty, |
297 | 0 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
298 | 0 | return CMD_SUCCESS; |
299 | 0 | } |
300 | | |
301 | 0 | ospf_router_id_update(ospf); |
302 | |
|
303 | 0 | return CMD_SUCCESS; |
304 | 0 | } |
305 | | |
306 | | DEFPY (no_ospf_router_id, |
307 | | no_ospf_router_id_cmd, |
308 | | "no ospf router-id [A.B.C.D]", |
309 | | NO_STR |
310 | | "OSPF specific commands\n" |
311 | | "router-id for the OSPF process\n" |
312 | | "OSPF router-id in IP address format\n") |
313 | 0 | { |
314 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
315 | 0 | struct listnode *node; |
316 | 0 | struct ospf_area *area; |
317 | |
|
318 | 0 | if (router_id_str) { |
319 | 0 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { |
320 | 0 | vty_out(vty, "%% OSPF router-id doesn't match\n"); |
321 | 0 | return CMD_WARNING_CONFIG_FAILED; |
322 | 0 | } |
323 | 0 | } |
324 | | |
325 | 0 | ospf->router_id_static.s_addr = 0; |
326 | |
|
327 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
328 | 0 | if (area->full_nbrs) { |
329 | 0 | vty_out(vty, |
330 | 0 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
331 | 0 | return CMD_SUCCESS; |
332 | 0 | } |
333 | | |
334 | 0 | ospf_router_id_update(ospf); |
335 | |
|
336 | 0 | return CMD_SUCCESS; |
337 | 0 | } |
338 | | |
339 | | |
340 | | static void ospf_passive_interface_default_update(struct ospf *ospf, |
341 | | uint8_t newval) |
342 | 0 | { |
343 | 0 | struct listnode *ln; |
344 | 0 | struct ospf_interface *oi; |
345 | |
|
346 | 0 | ospf->passive_interface_default = newval; |
347 | | |
348 | | /* update multicast memberships */ |
349 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) |
350 | 0 | ospf_if_set_multicast(oi); |
351 | 0 | } |
352 | | |
353 | | static void ospf_passive_interface_update(struct interface *ifp, |
354 | | struct ospf_if_params *params, |
355 | | struct in_addr addr, uint8_t newval) |
356 | 0 | { |
357 | 0 | struct route_node *rn; |
358 | |
|
359 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, passive_interface)) { |
360 | 0 | if (params->passive_interface == newval) |
361 | 0 | return; |
362 | | |
363 | 0 | params->passive_interface = newval; |
364 | 0 | UNSET_IF_PARAM(params, passive_interface); |
365 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
366 | 0 | ospf_free_if_params(ifp, addr); |
367 | 0 | ospf_if_update_params(ifp, addr); |
368 | 0 | } |
369 | 0 | } else { |
370 | 0 | params->passive_interface = newval; |
371 | 0 | SET_IF_PARAM(params, passive_interface); |
372 | 0 | } |
373 | | |
374 | | /* |
375 | | * XXX We should call ospf_if_set_multicast on exactly those |
376 | | * interfaces for which the passive property changed. It is too much |
377 | | * work to determine this set, so we do this for every interface. |
378 | | * This is safe and reasonable because ospf_if_set_multicast uses a |
379 | | * record of joined groups to avoid systems calls if the desired |
380 | | * memberships match the current memership. |
381 | | */ |
382 | | |
383 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
384 | 0 | struct ospf_interface *oi = rn->info; |
385 | |
|
386 | 0 | if (oi) |
387 | 0 | ospf_if_set_multicast(oi); |
388 | 0 | } |
389 | | |
390 | | /* |
391 | | * XXX It is not clear what state transitions the interface needs to |
392 | | * undergo when going from active to passive and vice versa. Fixing |
393 | | * this will require precise identification of interfaces having such a |
394 | | * transition. |
395 | | */ |
396 | 0 | } |
397 | | |
398 | | DEFUN (ospf_passive_interface_default, |
399 | | ospf_passive_interface_default_cmd, |
400 | | "passive-interface default", |
401 | | "Suppress routing updates on an interface\n" |
402 | | "Suppress routing updates on interfaces by default\n") |
403 | 0 | { |
404 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
405 | |
|
406 | 0 | ospf_passive_interface_default_update(ospf, OSPF_IF_PASSIVE); |
407 | |
|
408 | 0 | return CMD_SUCCESS; |
409 | 0 | } |
410 | | |
411 | | DEFUN_HIDDEN (ospf_passive_interface_addr, |
412 | | ospf_passive_interface_addr_cmd, |
413 | | "passive-interface IFNAME [A.B.C.D]", |
414 | | "Suppress routing updates on an interface\n" |
415 | | "Interface's name\n" |
416 | | "IPv4 address\n") |
417 | 0 | { |
418 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
419 | 0 | int idx_ipv4 = 2; |
420 | 0 | struct interface *ifp = NULL; |
421 | 0 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
422 | 0 | struct ospf_if_params *params; |
423 | 0 | int ret; |
424 | |
|
425 | 0 | vty_out(vty, |
426 | 0 | "This command is deprecated, because it is not VRF-aware.\n"); |
427 | 0 | vty_out(vty, |
428 | 0 | "Please, use \"ip ospf passive\" on an interface instead.\n"); |
429 | |
|
430 | 0 | if (ospf->vrf_id != VRF_UNKNOWN) |
431 | 0 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, ospf->name); |
432 | |
|
433 | 0 | if (ifp == NULL) { |
434 | 0 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
435 | 0 | return CMD_WARNING_CONFIG_FAILED; |
436 | 0 | } |
437 | | |
438 | 0 | if (argc == 3) { |
439 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
440 | 0 | if (!ret) { |
441 | 0 | vty_out(vty, |
442 | 0 | "Please specify interface address by A.B.C.D\n"); |
443 | 0 | return CMD_WARNING_CONFIG_FAILED; |
444 | 0 | } |
445 | | |
446 | 0 | params = ospf_get_if_params(ifp, addr); |
447 | 0 | ospf_if_update_params(ifp, addr); |
448 | 0 | } else { |
449 | 0 | params = IF_DEF_PARAMS(ifp); |
450 | 0 | } |
451 | | |
452 | 0 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE); |
453 | |
|
454 | 0 | return CMD_SUCCESS; |
455 | 0 | } |
456 | | |
457 | | DEFUN (no_ospf_passive_interface_default, |
458 | | no_ospf_passive_interface_default_cmd, |
459 | | "no passive-interface default", |
460 | | NO_STR |
461 | | "Allow routing updates on an interface\n" |
462 | | "Allow routing updates on interfaces by default\n") |
463 | 0 | { |
464 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
465 | |
|
466 | 0 | ospf_passive_interface_default_update(ospf, OSPF_IF_ACTIVE); |
467 | |
|
468 | 0 | return CMD_SUCCESS; |
469 | 0 | } |
470 | | |
471 | | DEFUN_HIDDEN (no_ospf_passive_interface, |
472 | | no_ospf_passive_interface_addr_cmd, |
473 | | "no passive-interface IFNAME [A.B.C.D]", |
474 | | NO_STR |
475 | | "Allow routing updates on an interface\n" |
476 | | "Interface's name\n" |
477 | | "IPv4 address\n") |
478 | 0 | { |
479 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
480 | 0 | int idx_ipv4 = 3; |
481 | 0 | struct interface *ifp = NULL; |
482 | 0 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
483 | 0 | struct ospf_if_params *params; |
484 | 0 | int ret; |
485 | |
|
486 | 0 | vty_out(vty, |
487 | 0 | "This command is deprecated, because it is not VRF-aware.\n"); |
488 | 0 | vty_out(vty, |
489 | 0 | "Please, use \"no ip ospf passive\" on an interface instead.\n"); |
490 | |
|
491 | 0 | if (ospf->vrf_id != VRF_UNKNOWN) |
492 | 0 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, ospf->name); |
493 | |
|
494 | 0 | if (ifp == NULL) { |
495 | 0 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
496 | 0 | return CMD_WARNING_CONFIG_FAILED; |
497 | 0 | } |
498 | | |
499 | 0 | if (argc == 4) { |
500 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
501 | 0 | if (!ret) { |
502 | 0 | vty_out(vty, |
503 | 0 | "Please specify interface address by A.B.C.D\n"); |
504 | 0 | return CMD_WARNING_CONFIG_FAILED; |
505 | 0 | } |
506 | 0 | params = ospf_lookup_if_params(ifp, addr); |
507 | 0 | if (params == NULL) |
508 | 0 | return CMD_SUCCESS; |
509 | 0 | } else { |
510 | 0 | params = IF_DEF_PARAMS(ifp); |
511 | 0 | } |
512 | | |
513 | 0 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE); |
514 | |
|
515 | 0 | return CMD_SUCCESS; |
516 | 0 | } |
517 | | |
518 | | |
519 | | DEFUN (ospf_network_area, |
520 | | ospf_network_area_cmd, |
521 | | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
522 | | "Enable routing on an IP network\n" |
523 | | "OSPF network prefix\n" |
524 | | "Set the OSPF area ID\n" |
525 | | "OSPF area ID in IP address format\n" |
526 | | "OSPF area ID as a decimal value\n") |
527 | 0 | { |
528 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
529 | 0 | int idx_ipv4_prefixlen = 1; |
530 | 0 | int idx_ipv4_number = 3; |
531 | 0 | struct prefix_ipv4 p; |
532 | 0 | struct in_addr area_id; |
533 | 0 | int ret, format; |
534 | 0 | uint32_t count; |
535 | |
|
536 | 0 | if (ospf->instance) { |
537 | 0 | vty_out(vty, |
538 | 0 | "The network command is not supported in multi-instance ospf\n"); |
539 | 0 | return CMD_WARNING_CONFIG_FAILED; |
540 | 0 | } |
541 | | |
542 | 0 | count = ospf_count_area_params(ospf); |
543 | 0 | if (count > 0) { |
544 | 0 | vty_out(vty, |
545 | 0 | "Please remove all ip ospf area x.x.x.x commands first.\n"); |
546 | 0 | if (IS_DEBUG_OSPF_EVENT) |
547 | 0 | zlog_debug( |
548 | 0 | "%s ospf vrf %s num of %u ip ospf area x config", |
549 | 0 | __func__, ospf_get_name(ospf), count); |
550 | 0 | return CMD_WARNING_CONFIG_FAILED; |
551 | 0 | } |
552 | | |
553 | | /* Get network prefix and Area ID. */ |
554 | 0 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); |
555 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
556 | |
|
557 | 0 | ret = ospf_network_set(ospf, &p, area_id, format); |
558 | 0 | if (ret == 0) { |
559 | 0 | vty_out(vty, "There is already same network statement.\n"); |
560 | 0 | return CMD_WARNING_CONFIG_FAILED; |
561 | 0 | } |
562 | | |
563 | 0 | return CMD_SUCCESS; |
564 | 0 | } |
565 | | |
566 | | DEFUN (no_ospf_network_area, |
567 | | no_ospf_network_area_cmd, |
568 | | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
569 | | NO_STR |
570 | | "Enable routing on an IP network\n" |
571 | | "OSPF network prefix\n" |
572 | | "Set the OSPF area ID\n" |
573 | | "OSPF area ID in IP address format\n" |
574 | | "OSPF area ID as a decimal value\n") |
575 | 0 | { |
576 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
577 | 0 | int idx_ipv4_prefixlen = 2; |
578 | 0 | int idx_ipv4_number = 4; |
579 | 0 | struct prefix_ipv4 p; |
580 | 0 | struct in_addr area_id; |
581 | 0 | int ret, format; |
582 | |
|
583 | 0 | if (ospf->instance) { |
584 | 0 | vty_out(vty, |
585 | 0 | "The network command is not supported in multi-instance ospf\n"); |
586 | 0 | return CMD_WARNING_CONFIG_FAILED; |
587 | 0 | } |
588 | | |
589 | | /* Get network prefix and Area ID. */ |
590 | 0 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); |
591 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
592 | |
|
593 | 0 | ret = ospf_network_unset(ospf, &p, area_id); |
594 | 0 | if (ret == 0) { |
595 | 0 | vty_out(vty, |
596 | 0 | "Can't find specified network area configuration.\n"); |
597 | 0 | return CMD_WARNING_CONFIG_FAILED; |
598 | 0 | } |
599 | | |
600 | 0 | return CMD_SUCCESS; |
601 | 0 | } |
602 | | |
603 | | DEFUN (ospf_area_range, |
604 | | ospf_area_range_cmd, |
605 | | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
606 | | "OSPF area parameters\n" |
607 | | "OSPF area ID in IP address format\n" |
608 | | "OSPF area ID as a decimal value\n" |
609 | | "Summarize routes matching address/mask (border routers only)\n" |
610 | | "Area range prefix\n" |
611 | | "Advertise this range (default)\n" |
612 | | "User specified metric for this range\n" |
613 | | "Advertised metric for this range\n") |
614 | 0 | { |
615 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
616 | 0 | struct ospf_area *area; |
617 | 0 | int idx_ipv4_number = 1; |
618 | 0 | int idx_ipv4_prefixlen = 3; |
619 | 0 | int idx_cost = 6; |
620 | 0 | struct prefix_ipv4 p; |
621 | 0 | struct in_addr area_id; |
622 | 0 | int format; |
623 | 0 | uint32_t cost; |
624 | |
|
625 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
626 | 0 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); |
627 | |
|
628 | 0 | area = ospf_area_get(ospf, area_id); |
629 | 0 | ospf_area_display_format_set(ospf, area, format); |
630 | |
|
631 | 0 | ospf_area_range_set(ospf, area, area->ranges, &p, |
632 | 0 | OSPF_AREA_RANGE_ADVERTISE, false); |
633 | 0 | if (argc > 5) { |
634 | 0 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
635 | 0 | ospf_area_range_cost_set(ospf, area, area->ranges, &p, cost); |
636 | 0 | } |
637 | |
|
638 | 0 | return CMD_SUCCESS; |
639 | 0 | } |
640 | | |
641 | | DEFUN (ospf_area_range_cost, |
642 | | ospf_area_range_cost_cmd, |
643 | | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}", |
644 | | "OSPF area parameters\n" |
645 | | "OSPF area ID in IP address format\n" |
646 | | "OSPF area ID as a decimal value\n" |
647 | | "Summarize routes matching address/mask (border routers only)\n" |
648 | | "Area range prefix\n" |
649 | | "User specified metric for this range\n" |
650 | | "Advertised metric for this range\n" |
651 | | "Announce area range as another prefix\n" |
652 | | "Network prefix to be announced instead of range\n") |
653 | 0 | { |
654 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
655 | 0 | struct ospf_area *area; |
656 | 0 | int idx_ipv4_number = 1; |
657 | 0 | int idx_ipv4_prefixlen = 3; |
658 | 0 | int idx = 4; |
659 | 0 | struct prefix_ipv4 p, s; |
660 | 0 | struct in_addr area_id; |
661 | 0 | int format; |
662 | 0 | uint32_t cost; |
663 | |
|
664 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
665 | 0 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); |
666 | |
|
667 | 0 | area = ospf_area_get(ospf, area_id); |
668 | 0 | ospf_area_display_format_set(ospf, area, format); |
669 | |
|
670 | 0 | ospf_area_range_set(ospf, area, area->ranges, &p, |
671 | 0 | OSPF_AREA_RANGE_ADVERTISE, false); |
672 | 0 | if (argv_find(argv, argc, "cost", &idx)) { |
673 | 0 | cost = strtoul(argv[idx + 1]->arg, NULL, 10); |
674 | 0 | ospf_area_range_cost_set(ospf, area, area->ranges, &p, cost); |
675 | 0 | } |
676 | |
|
677 | 0 | idx = 4; |
678 | 0 | if (argv_find(argv, argc, "substitute", &idx)) { |
679 | 0 | str2prefix_ipv4(argv[idx + 1]->arg, &s); |
680 | 0 | ospf_area_range_substitute_set(ospf, area, &p, &s); |
681 | 0 | } |
682 | |
|
683 | 0 | return CMD_SUCCESS; |
684 | 0 | } |
685 | | |
686 | | DEFUN (ospf_area_range_not_advertise, |
687 | | ospf_area_range_not_advertise_cmd, |
688 | | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
689 | | "OSPF area parameters\n" |
690 | | "OSPF area ID in IP address format\n" |
691 | | "OSPF area ID as a decimal value\n" |
692 | | "Summarize routes matching address/mask (border routers only)\n" |
693 | | "Area range prefix\n" |
694 | | "DoNotAdvertise this range\n") |
695 | 0 | { |
696 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
697 | 0 | struct ospf_area *area; |
698 | 0 | int idx_ipv4_number = 1; |
699 | 0 | int idx_ipv4_prefixlen = 3; |
700 | 0 | struct prefix_ipv4 p; |
701 | 0 | struct in_addr area_id; |
702 | 0 | int format; |
703 | |
|
704 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
705 | 0 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); |
706 | |
|
707 | 0 | area = ospf_area_get(ospf, area_id); |
708 | 0 | ospf_area_display_format_set(ospf, area, format); |
709 | |
|
710 | 0 | ospf_area_range_set(ospf, area, area->ranges, &p, 0, false); |
711 | 0 | ospf_area_range_substitute_unset(ospf, area, &p); |
712 | |
|
713 | 0 | return CMD_SUCCESS; |
714 | 0 | } |
715 | | |
716 | | DEFUN (no_ospf_area_range, |
717 | | no_ospf_area_range_cmd, |
718 | | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
719 | | NO_STR |
720 | | "OSPF area parameters\n" |
721 | | "OSPF area ID in IP address format\n" |
722 | | "OSPF area ID as a decimal value\n" |
723 | | "Summarize routes matching address/mask (border routers only)\n" |
724 | | "Area range prefix\n" |
725 | | "User specified metric for this range\n" |
726 | | "Advertised metric for this range\n" |
727 | | "Advertise this range (default)\n" |
728 | | "User specified metric for this range\n" |
729 | | "Advertised metric for this range\n" |
730 | | "DoNotAdvertise this range\n") |
731 | 0 | { |
732 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
733 | 0 | struct ospf_area *area; |
734 | 0 | int idx_ipv4_number = 2; |
735 | 0 | int idx_ipv4_prefixlen = 4; |
736 | 0 | struct prefix_ipv4 p; |
737 | 0 | struct in_addr area_id; |
738 | 0 | int format; |
739 | |
|
740 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
741 | 0 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); |
742 | |
|
743 | 0 | area = ospf_area_get(ospf, area_id); |
744 | 0 | ospf_area_display_format_set(ospf, area, format); |
745 | |
|
746 | 0 | ospf_area_range_unset(ospf, area, area->ranges, &p); |
747 | |
|
748 | 0 | return CMD_SUCCESS; |
749 | 0 | } |
750 | | |
751 | | DEFUN (no_ospf_area_range_substitute, |
752 | | no_ospf_area_range_substitute_cmd, |
753 | | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
754 | | NO_STR |
755 | | "OSPF area parameters\n" |
756 | | "OSPF area ID in IP address format\n" |
757 | | "OSPF area ID as a decimal value\n" |
758 | | "Summarize routes matching address/mask (border routers only)\n" |
759 | | "Area range prefix\n" |
760 | | "Announce area range as another prefix\n" |
761 | | "Network prefix to be announced instead of range\n") |
762 | 0 | { |
763 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
764 | 0 | struct ospf_area *area; |
765 | 0 | int idx_ipv4_number = 2; |
766 | 0 | int idx_ipv4_prefixlen = 4; |
767 | 0 | int idx_ipv4_prefixlen_2 = 6; |
768 | 0 | struct prefix_ipv4 p, s; |
769 | 0 | struct in_addr area_id; |
770 | 0 | int format; |
771 | |
|
772 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
773 | 0 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); |
774 | 0 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); |
775 | |
|
776 | 0 | area = ospf_area_get(ospf, area_id); |
777 | 0 | ospf_area_display_format_set(ospf, area, format); |
778 | |
|
779 | 0 | ospf_area_range_substitute_unset(ospf, area, &p); |
780 | |
|
781 | 0 | return CMD_SUCCESS; |
782 | 0 | } |
783 | | |
784 | | |
785 | | /* Command Handler Logic in VLink stuff is delicate!! |
786 | | |
787 | | ALTER AT YOUR OWN RISK!!!! |
788 | | |
789 | | Various dummy values are used to represent 'NoChange' state for |
790 | | VLink configuration NOT being changed by a VLink command, and |
791 | | special syntax is used within the command strings so that the |
792 | | typed in command verbs can be seen in the configuration command |
793 | | bacckend handler. This is to drastically reduce the verbeage |
794 | | required to coe up with a reasonably compatible Cisco VLink command |
795 | | |
796 | | - Matthew Grant <grantma@anathoth.gen.nz> |
797 | | Wed, 21 Feb 2001 15:13:52 +1300 |
798 | | */ |
799 | | |
800 | | /* Configuration data for virtual links |
801 | | */ |
802 | | struct ospf_vl_config_data { |
803 | | struct vty *vty; /* vty stuff */ |
804 | | struct in_addr area_id; /* area ID from command line */ |
805 | | int area_id_fmt; /* command line area ID format */ |
806 | | struct in_addr vl_peer; /* command line vl_peer */ |
807 | | int auth_type; /* Authehntication type, if given */ |
808 | | char *auth_key; /* simple password if present */ |
809 | | int crypto_key_id; /* Cryptographic key ID */ |
810 | | char *md5_key; /* MD5 authentication key */ |
811 | | int hello_interval; /* Obvious what these are... */ |
812 | | int retransmit_interval; |
813 | | int transmit_delay; |
814 | | int dead_interval; |
815 | | }; |
816 | | |
817 | | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
818 | | struct vty *vty) |
819 | 0 | { |
820 | 0 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
821 | 0 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; |
822 | 0 | vl_config->vty = vty; |
823 | 0 | } |
824 | | |
825 | | static struct ospf_vl_data * |
826 | | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
827 | 0 | { |
828 | 0 | struct ospf_area *area; |
829 | 0 | struct ospf_vl_data *vl_data; |
830 | 0 | struct vty *vty; |
831 | 0 | struct in_addr area_id; |
832 | |
|
833 | 0 | vty = vl_config->vty; |
834 | 0 | area_id = vl_config->area_id; |
835 | |
|
836 | 0 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { |
837 | 0 | vty_out(vty, |
838 | 0 | "Configuring VLs over the backbone is not allowed\n"); |
839 | 0 | return NULL; |
840 | 0 | } |
841 | 0 | area = ospf_area_get(ospf, area_id); |
842 | 0 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); |
843 | |
|
844 | 0 | if (area->external_routing != OSPF_AREA_DEFAULT) { |
845 | 0 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
846 | 0 | vty_out(vty, "Area %pI4 is %s\n", &area_id, |
847 | 0 | area->external_routing == OSPF_AREA_NSSA |
848 | 0 | ? "nssa" |
849 | 0 | : "stub"); |
850 | 0 | else |
851 | 0 | vty_out(vty, "Area %ld is %s\n", |
852 | 0 | (unsigned long)ntohl(area_id.s_addr), |
853 | 0 | area->external_routing == OSPF_AREA_NSSA |
854 | 0 | ? "nssa" |
855 | 0 | : "stub"); |
856 | 0 | return NULL; |
857 | 0 | } |
858 | | |
859 | 0 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) |
860 | 0 | == NULL) { |
861 | 0 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); |
862 | 0 | if (vl_data->vl_oi == NULL) { |
863 | 0 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); |
864 | 0 | ospf_vl_add(ospf, vl_data); |
865 | 0 | ospf_spf_calculate_schedule(ospf, |
866 | 0 | SPF_FLAG_CONFIG_CHANGE); |
867 | 0 | } |
868 | 0 | } |
869 | 0 | return vl_data; |
870 | 0 | } |
871 | | |
872 | | |
873 | | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
874 | | struct ospf_vl_config_data *vl_config) |
875 | 0 | { |
876 | 0 | struct crypt_key *ck; |
877 | 0 | struct vty *vty; |
878 | 0 | struct interface *ifp = vl_data->vl_oi->ifp; |
879 | |
|
880 | 0 | vty = vl_config->vty; |
881 | |
|
882 | 0 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { |
883 | 0 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); |
884 | 0 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; |
885 | 0 | } |
886 | |
|
887 | 0 | if (vl_config->auth_key) { |
888 | 0 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, |
889 | 0 | OSPF_AUTH_SIMPLE_SIZE + 1); |
890 | 0 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
891 | 0 | vl_config->auth_key, |
892 | 0 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); |
893 | 0 | } else if (vl_config->md5_key) { |
894 | 0 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, |
895 | 0 | vl_config->crypto_key_id) |
896 | 0 | != NULL) { |
897 | 0 | vty_out(vty, "OSPF: Key %d already exists\n", |
898 | 0 | vl_config->crypto_key_id); |
899 | 0 | return CMD_WARNING; |
900 | 0 | } |
901 | 0 | ck = ospf_crypt_key_new(); |
902 | 0 | ck->key_id = vl_config->crypto_key_id; |
903 | 0 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); |
904 | 0 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
905 | 0 | sizeof(ck->auth_key)); |
906 | |
|
907 | 0 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); |
908 | 0 | } else if (vl_config->crypto_key_id != 0) { |
909 | | /* Delete a key */ |
910 | |
|
911 | 0 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, |
912 | 0 | vl_config->crypto_key_id) |
913 | 0 | == NULL) { |
914 | 0 | vty_out(vty, "OSPF: Key %d does not exist\n", |
915 | 0 | vl_config->crypto_key_id); |
916 | 0 | return CMD_WARNING_CONFIG_FAILED; |
917 | 0 | } |
918 | | |
919 | 0 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, |
920 | 0 | vl_config->crypto_key_id); |
921 | 0 | } |
922 | | |
923 | 0 | return CMD_SUCCESS; |
924 | 0 | } |
925 | | |
926 | | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
927 | | struct ospf_vl_config_data *vl_config) |
928 | 0 | { |
929 | 0 | struct interface *ifp = vl_data->vl_oi->ifp; |
930 | | /* Virtual Link data initialised to defaults, so only set |
931 | | if a value given */ |
932 | 0 | if (vl_config->hello_interval) { |
933 | 0 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); |
934 | 0 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; |
935 | 0 | } |
936 | |
|
937 | 0 | if (vl_config->dead_interval) { |
938 | 0 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); |
939 | 0 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; |
940 | 0 | } |
941 | |
|
942 | 0 | if (vl_config->retransmit_interval) { |
943 | 0 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); |
944 | 0 | IF_DEF_PARAMS(ifp)->retransmit_interval = |
945 | 0 | vl_config->retransmit_interval; |
946 | 0 | } |
947 | |
|
948 | 0 | if (vl_config->transmit_delay) { |
949 | 0 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); |
950 | 0 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; |
951 | 0 | } |
952 | |
|
953 | 0 | return CMD_SUCCESS; |
954 | 0 | } |
955 | | |
956 | | |
957 | | /* The business end of all of the above */ |
958 | | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
959 | 0 | { |
960 | 0 | struct ospf_vl_data *vl_data; |
961 | 0 | int ret; |
962 | |
|
963 | 0 | vl_data = ospf_find_vl_data(ospf, vl_config); |
964 | 0 | if (!vl_data) |
965 | 0 | return CMD_WARNING_CONFIG_FAILED; |
966 | | |
967 | | /* Process this one first as it can have a fatal result, which can |
968 | | only logically occur if the virtual link exists already |
969 | | Thus a command error does not result in a change to the |
970 | | running configuration such as unexpectedly altered timer |
971 | | values etc.*/ |
972 | 0 | ret = ospf_vl_set_security(vl_data, vl_config); |
973 | 0 | if (ret != CMD_SUCCESS) |
974 | 0 | return ret; |
975 | | |
976 | | /* Set any time based parameters, these area already range checked */ |
977 | | |
978 | 0 | ret = ospf_vl_set_timers(vl_data, vl_config); |
979 | 0 | if (ret != CMD_SUCCESS) |
980 | 0 | return ret; |
981 | | |
982 | 0 | return CMD_SUCCESS; |
983 | 0 | } |
984 | | |
985 | | /* This stuff exists to make specifying all the alias commands A LOT simpler |
986 | | */ |
987 | | #define VLINK_HELPSTR_IPADDR \ |
988 | | "OSPF area parameters\n" \ |
989 | | "OSPF area ID in IP address format\n" \ |
990 | | "OSPF area ID as a decimal value\n" \ |
991 | | "Configure a virtual link\n" \ |
992 | | "Router ID of the remote ABR\n" |
993 | | |
994 | | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ |
995 | | "Enable authentication on this virtual link\n" \ |
996 | | "dummy string \n" |
997 | | |
998 | | #define VLINK_HELPSTR_AUTHTYPE_ALL \ |
999 | | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ |
1000 | | "Use null authentication\n" \ |
1001 | | "Use message-digest authentication\n" |
1002 | | |
1003 | | #define VLINK_HELPSTR_TIME_PARAM \ |
1004 | | "Time between HELLO packets\n" \ |
1005 | | "Seconds\n" \ |
1006 | | "Time between retransmitting lost link state advertisements\n" \ |
1007 | | "Seconds\n" \ |
1008 | | "Link state transmit delay\n" \ |
1009 | | "Seconds\n" \ |
1010 | | "Interval time after which a neighbor is declared down\n" \ |
1011 | | "Seconds\n" |
1012 | | |
1013 | | #define VLINK_HELPSTR_AUTH_SIMPLE \ |
1014 | | "Authentication password (key)\n" \ |
1015 | | "The OSPF password (key)\n" |
1016 | | |
1017 | | #define VLINK_HELPSTR_AUTH_MD5 \ |
1018 | | "Message digest authentication password (key)\n" \ |
1019 | | "Key ID\n" \ |
1020 | | "Use MD5 algorithm\n" \ |
1021 | | "The OSPF password (key)\n" |
1022 | | |
1023 | | DEFUN (ospf_area_vlink, |
1024 | | ospf_area_vlink_cmd, |
1025 | | "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>]", |
1026 | | VLINK_HELPSTR_IPADDR |
1027 | | "Enable authentication on this virtual link\n" |
1028 | | "Use message-digest authentication\n" |
1029 | | "Use null authentication\n" |
1030 | | VLINK_HELPSTR_AUTH_MD5 |
1031 | | VLINK_HELPSTR_AUTH_SIMPLE) |
1032 | 0 | { |
1033 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1034 | 0 | int idx_ipv4_number = 1; |
1035 | 0 | int idx_ipv4 = 3; |
1036 | 0 | struct ospf_vl_config_data vl_config; |
1037 | 0 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; |
1038 | 0 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; |
1039 | 0 | int ret; |
1040 | 0 | int idx = 0; |
1041 | |
|
1042 | 0 | ospf_vl_config_data_init(&vl_config, vty); |
1043 | | |
1044 | | /* Read off first 2 parameters and check them */ |
1045 | 0 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, |
1046 | 0 | &vl_config.area_id_fmt); |
1047 | 0 | if (ret < 0) { |
1048 | 0 | vty_out(vty, "OSPF area ID is invalid\n"); |
1049 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1050 | 0 | } |
1051 | | |
1052 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1053 | 0 | if (!ret) { |
1054 | 0 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); |
1055 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1056 | 0 | } |
1057 | | |
1058 | 0 | if (argc <= 4) { |
1059 | | /* Thats all folks! - BUGS B. strikes again!!!*/ |
1060 | |
|
1061 | 0 | return ospf_vl_set(ospf, &vl_config); |
1062 | 0 | } |
1063 | | |
1064 | 0 | if (argv_find(argv, argc, "authentication", &idx)) { |
1065 | | /* authentication - this option can only occur |
1066 | | at start of command line */ |
1067 | 0 | vl_config.auth_type = OSPF_AUTH_SIMPLE; |
1068 | 0 | } |
1069 | |
|
1070 | 0 | if (argv_find(argv, argc, "message-digest", &idx)) { |
1071 | | /* authentication message-digest */ |
1072 | 0 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1073 | 0 | } else if (argv_find(argv, argc, "null", &idx)) { |
1074 | | /* "authentication null" */ |
1075 | 0 | vl_config.auth_type = OSPF_AUTH_NULL; |
1076 | 0 | } |
1077 | |
|
1078 | 0 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
1079 | 0 | vl_config.md5_key = NULL; |
1080 | 0 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
1081 | 0 | if (vl_config.crypto_key_id < 0) |
1082 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1083 | | |
1084 | 0 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
1085 | 0 | vl_config.md5_key = md5_key; |
1086 | 0 | } |
1087 | | |
1088 | 0 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
1089 | 0 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
1090 | 0 | vl_config.auth_key = auth_key; |
1091 | 0 | } |
1092 | | |
1093 | | /* Action configuration */ |
1094 | |
|
1095 | 0 | return ospf_vl_set(ospf, &vl_config); |
1096 | 0 | } |
1097 | | |
1098 | | DEFUN (no_ospf_area_vlink, |
1099 | | no_ospf_area_vlink_cmd, |
1100 | | "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>]", |
1101 | | NO_STR |
1102 | | VLINK_HELPSTR_IPADDR |
1103 | | "Enable authentication on this virtual link\n" |
1104 | | "Use message-digest authentication\n" |
1105 | | "Use null authentication\n" |
1106 | | VLINK_HELPSTR_AUTH_MD5 |
1107 | | VLINK_HELPSTR_AUTH_SIMPLE) |
1108 | 0 | { |
1109 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1110 | 0 | int idx_ipv4_number = 2; |
1111 | 0 | int idx_ipv4 = 4; |
1112 | 0 | struct ospf_area *area; |
1113 | 0 | struct ospf_vl_config_data vl_config; |
1114 | 0 | struct ospf_vl_data *vl_data = NULL; |
1115 | 0 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; |
1116 | 0 | int idx = 0; |
1117 | 0 | int ret, format; |
1118 | |
|
1119 | 0 | ospf_vl_config_data_init(&vl_config, vty); |
1120 | |
|
1121 | 0 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, |
1122 | 0 | &format); |
1123 | 0 | if (ret < 0) { |
1124 | 0 | vty_out(vty, "OSPF area ID is invalid\n"); |
1125 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1126 | 0 | } |
1127 | | |
1128 | 0 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); |
1129 | 0 | if (!area) { |
1130 | 0 | vty_out(vty, "Area does not exist\n"); |
1131 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1132 | 0 | } |
1133 | | |
1134 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1135 | 0 | if (!ret) { |
1136 | 0 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); |
1137 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1138 | 0 | } |
1139 | | |
1140 | 0 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1141 | 0 | if (!vl_data) { |
1142 | 0 | vty_out(vty, "Virtual link does not exist\n"); |
1143 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1144 | 0 | } |
1145 | | |
1146 | 0 | if (argc <= 5) { |
1147 | | /* Basic VLink no command */ |
1148 | | /* Thats all folks! - BUGS B. strikes again!!!*/ |
1149 | 0 | ospf_vl_delete(ospf, vl_data); |
1150 | 0 | ospf_area_check_free(ospf, vl_config.area_id); |
1151 | 0 | return CMD_SUCCESS; |
1152 | 0 | } |
1153 | | |
1154 | | /* If we are down here, we are reseting parameters */ |
1155 | | /* Deal with other parameters */ |
1156 | | |
1157 | 0 | if (argv_find(argv, argc, "authentication", &idx)) { |
1158 | | /* authentication - this option can only occur |
1159 | | at start of command line */ |
1160 | 0 | vl_config.auth_type = OSPF_AUTH_NOTSET; |
1161 | 0 | } |
1162 | |
|
1163 | 0 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
1164 | 0 | vl_config.md5_key = NULL; |
1165 | 0 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
1166 | 0 | if (vl_config.crypto_key_id < 0) |
1167 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1168 | 0 | } |
1169 | | |
1170 | 0 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
1171 | | /* Reset authentication-key to 0 */ |
1172 | 0 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1173 | 0 | vl_config.auth_key = auth_key; |
1174 | 0 | } |
1175 | | |
1176 | | /* Action configuration */ |
1177 | |
|
1178 | 0 | return ospf_vl_set(ospf, &vl_config); |
1179 | 0 | } |
1180 | | |
1181 | | DEFUN (ospf_area_vlink_intervals, |
1182 | | ospf_area_vlink_intervals_cmd, |
1183 | | "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)}", |
1184 | | VLINK_HELPSTR_IPADDR |
1185 | | VLINK_HELPSTR_TIME_PARAM) |
1186 | 0 | { |
1187 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1188 | 0 | struct ospf_vl_config_data vl_config; |
1189 | 0 | int ret = 0; |
1190 | |
|
1191 | 0 | ospf_vl_config_data_init(&vl_config, vty); |
1192 | |
|
1193 | 0 | char *area_id = argv[1]->arg; |
1194 | 0 | char *router_id = argv[3]->arg; |
1195 | |
|
1196 | 0 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); |
1197 | 0 | if (ret < 0) { |
1198 | 0 | vty_out(vty, "OSPF area ID is invalid\n"); |
1199 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1200 | 0 | } |
1201 | | |
1202 | 0 | ret = inet_aton(router_id, &vl_config.vl_peer); |
1203 | 0 | if (!ret) { |
1204 | 0 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); |
1205 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1206 | 0 | } |
1207 | | |
1208 | 0 | for (int idx = 4; idx < argc; idx++) { |
1209 | 0 | if (strmatch(argv[idx]->text, "hello-interval")) |
1210 | 0 | vl_config.hello_interval = |
1211 | 0 | strtol(argv[++idx]->arg, NULL, 10); |
1212 | 0 | else if (strmatch(argv[idx]->text, "retransmit-interval")) |
1213 | 0 | vl_config.retransmit_interval = |
1214 | 0 | strtol(argv[++idx]->arg, NULL, 10); |
1215 | 0 | else if (strmatch(argv[idx]->text, "transmit-delay")) |
1216 | 0 | vl_config.transmit_delay = |
1217 | 0 | strtol(argv[++idx]->arg, NULL, 10); |
1218 | 0 | else if (strmatch(argv[idx]->text, "dead-interval")) |
1219 | 0 | vl_config.dead_interval = |
1220 | 0 | strtol(argv[++idx]->arg, NULL, 10); |
1221 | 0 | } |
1222 | | |
1223 | | /* Action configuration */ |
1224 | 0 | return ospf_vl_set(ospf, &vl_config); |
1225 | 0 | } |
1226 | | |
1227 | | DEFUN (no_ospf_area_vlink_intervals, |
1228 | | no_ospf_area_vlink_intervals_cmd, |
1229 | | "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)}", |
1230 | | NO_STR |
1231 | | VLINK_HELPSTR_IPADDR |
1232 | | VLINK_HELPSTR_TIME_PARAM) |
1233 | 0 | { |
1234 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1235 | 0 | struct ospf_vl_config_data vl_config; |
1236 | 0 | int ret = 0; |
1237 | |
|
1238 | 0 | ospf_vl_config_data_init(&vl_config, vty); |
1239 | |
|
1240 | 0 | char *area_id = argv[2]->arg; |
1241 | 0 | char *router_id = argv[4]->arg; |
1242 | |
|
1243 | 0 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); |
1244 | 0 | if (ret < 0) { |
1245 | 0 | vty_out(vty, "OSPF area ID is invalid\n"); |
1246 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1247 | 0 | } |
1248 | | |
1249 | 0 | ret = inet_aton(router_id, &vl_config.vl_peer); |
1250 | 0 | if (!ret) { |
1251 | 0 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); |
1252 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1253 | 0 | } |
1254 | | |
1255 | 0 | for (int idx = 5; idx < argc; idx++) { |
1256 | 0 | if (strmatch(argv[idx]->text, "hello-interval")) |
1257 | 0 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; |
1258 | 0 | else if (strmatch(argv[idx]->text, "retransmit-interval")) |
1259 | 0 | vl_config.retransmit_interval = |
1260 | 0 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; |
1261 | 0 | else if (strmatch(argv[idx]->text, "transmit-delay")) |
1262 | 0 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; |
1263 | 0 | else if (strmatch(argv[idx]->text, "dead-interval")) |
1264 | 0 | vl_config.dead_interval = |
1265 | 0 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; |
1266 | 0 | } |
1267 | | |
1268 | | /* Action configuration */ |
1269 | 0 | return ospf_vl_set(ospf, &vl_config); |
1270 | 0 | } |
1271 | | |
1272 | | DEFUN (ospf_area_shortcut, |
1273 | | ospf_area_shortcut_cmd, |
1274 | | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
1275 | | "OSPF area parameters\n" |
1276 | | "OSPF area ID in IP address format\n" |
1277 | | "OSPF area ID as a decimal value\n" |
1278 | | "Configure the area's shortcutting mode\n" |
1279 | | "Set default shortcutting behavior\n" |
1280 | | "Enable shortcutting through the area\n" |
1281 | | "Disable shortcutting through the area\n") |
1282 | 0 | { |
1283 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1284 | 0 | int idx_ipv4_number = 1; |
1285 | 0 | int idx_enable_disable = 3; |
1286 | 0 | struct ospf_area *area; |
1287 | 0 | struct in_addr area_id; |
1288 | 0 | int mode; |
1289 | 0 | int format; |
1290 | |
|
1291 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1292 | 0 | argv[idx_ipv4_number]->arg); |
1293 | |
|
1294 | 0 | area = ospf_area_get(ospf, area_id); |
1295 | 0 | ospf_area_display_format_set(ospf, area, format); |
1296 | |
|
1297 | 0 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) |
1298 | 0 | mode = OSPF_SHORTCUT_DEFAULT; |
1299 | 0 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) |
1300 | 0 | mode = OSPF_SHORTCUT_DISABLE; |
1301 | 0 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) |
1302 | 0 | mode = OSPF_SHORTCUT_ENABLE; |
1303 | 0 | else |
1304 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1305 | | |
1306 | 0 | ospf_area_shortcut_set(ospf, area, mode); |
1307 | |
|
1308 | 0 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1309 | 0 | vty_out(vty, |
1310 | 0 | "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n"); |
1311 | |
|
1312 | 0 | return CMD_SUCCESS; |
1313 | 0 | } |
1314 | | |
1315 | | DEFUN (no_ospf_area_shortcut, |
1316 | | no_ospf_area_shortcut_cmd, |
1317 | | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
1318 | | NO_STR |
1319 | | "OSPF area parameters\n" |
1320 | | "OSPF area ID in IP address format\n" |
1321 | | "OSPF area ID as a decimal value\n" |
1322 | | "Deconfigure the area's shortcutting mode\n" |
1323 | | "Deconfigure enabled shortcutting through the area\n" |
1324 | | "Deconfigure disabled shortcutting through the area\n") |
1325 | 0 | { |
1326 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1327 | 0 | int idx_ipv4_number = 2; |
1328 | 0 | struct ospf_area *area; |
1329 | 0 | struct in_addr area_id; |
1330 | 0 | int format; |
1331 | |
|
1332 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1333 | 0 | argv[idx_ipv4_number]->arg); |
1334 | |
|
1335 | 0 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1336 | 0 | if (!area) |
1337 | 0 | return CMD_SUCCESS; |
1338 | | |
1339 | 0 | ospf_area_shortcut_unset(ospf, area); |
1340 | |
|
1341 | 0 | return CMD_SUCCESS; |
1342 | 0 | } |
1343 | | |
1344 | | |
1345 | | DEFUN (ospf_area_stub, |
1346 | | ospf_area_stub_cmd, |
1347 | | "area <A.B.C.D|(0-4294967295)> stub", |
1348 | | "OSPF area parameters\n" |
1349 | | "OSPF area ID in IP address format\n" |
1350 | | "OSPF area ID as a decimal value\n" |
1351 | | "Configure OSPF area as stub\n") |
1352 | 0 | { |
1353 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1354 | 0 | int idx_ipv4_number = 1; |
1355 | 0 | struct in_addr area_id; |
1356 | 0 | int ret, format; |
1357 | |
|
1358 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1359 | 0 | argv[idx_ipv4_number]->arg); |
1360 | |
|
1361 | 0 | ret = ospf_area_stub_set(ospf, area_id); |
1362 | 0 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
1363 | 0 | format); |
1364 | 0 | if (ret == 0) { |
1365 | 0 | vty_out(vty, |
1366 | 0 | "First deconfigure all virtual link through this area\n"); |
1367 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1368 | 0 | } |
1369 | | |
1370 | | /* Flush the external LSAs from the specified area */ |
1371 | 0 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); |
1372 | 0 | ospf_area_no_summary_unset(ospf, area_id); |
1373 | |
|
1374 | 0 | return CMD_SUCCESS; |
1375 | 0 | } |
1376 | | |
1377 | | DEFUN (ospf_area_stub_no_summary, |
1378 | | ospf_area_stub_no_summary_cmd, |
1379 | | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
1380 | | "OSPF stub parameters\n" |
1381 | | "OSPF area ID in IP address format\n" |
1382 | | "OSPF area ID as a decimal value\n" |
1383 | | "Configure OSPF area as stub\n" |
1384 | | "Do not inject inter-area routes into stub\n") |
1385 | 0 | { |
1386 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1387 | 0 | int idx_ipv4_number = 1; |
1388 | 0 | struct in_addr area_id; |
1389 | 0 | int ret, format; |
1390 | |
|
1391 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1392 | 0 | argv[idx_ipv4_number]->arg); |
1393 | |
|
1394 | 0 | ret = ospf_area_stub_set(ospf, area_id); |
1395 | 0 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
1396 | 0 | format); |
1397 | 0 | if (ret == 0) { |
1398 | 0 | vty_out(vty, |
1399 | 0 | "%% Area cannot be stub as it contains a virtual link\n"); |
1400 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1401 | 0 | } |
1402 | | |
1403 | 0 | ospf_area_no_summary_set(ospf, area_id); |
1404 | |
|
1405 | 0 | return CMD_SUCCESS; |
1406 | 0 | } |
1407 | | |
1408 | | DEFUN (no_ospf_area_stub, |
1409 | | no_ospf_area_stub_cmd, |
1410 | | "no area <A.B.C.D|(0-4294967295)> stub", |
1411 | | NO_STR |
1412 | | "OSPF area parameters\n" |
1413 | | "OSPF area ID in IP address format\n" |
1414 | | "OSPF area ID as a decimal value\n" |
1415 | | "Configure OSPF area as stub\n") |
1416 | 0 | { |
1417 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1418 | 0 | int idx_ipv4_number = 2; |
1419 | 0 | struct in_addr area_id; |
1420 | 0 | int format; |
1421 | |
|
1422 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1423 | 0 | argv[idx_ipv4_number]->arg); |
1424 | |
|
1425 | 0 | ospf_area_stub_unset(ospf, area_id); |
1426 | 0 | ospf_area_no_summary_unset(ospf, area_id); |
1427 | |
|
1428 | 0 | return CMD_SUCCESS; |
1429 | 0 | } |
1430 | | |
1431 | | DEFUN (no_ospf_area_stub_no_summary, |
1432 | | no_ospf_area_stub_no_summary_cmd, |
1433 | | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
1434 | | NO_STR |
1435 | | "OSPF area parameters\n" |
1436 | | "OSPF area ID in IP address format\n" |
1437 | | "OSPF area ID as a decimal value\n" |
1438 | | "Configure OSPF area as stub\n" |
1439 | | "Do not inject inter-area routes into area\n") |
1440 | 0 | { |
1441 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1442 | 0 | int idx_ipv4_number = 2; |
1443 | 0 | struct in_addr area_id; |
1444 | 0 | int format; |
1445 | |
|
1446 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1447 | 0 | argv[idx_ipv4_number]->arg); |
1448 | 0 | ospf_area_no_summary_unset(ospf, area_id); |
1449 | |
|
1450 | 0 | return CMD_SUCCESS; |
1451 | 0 | } |
1452 | | |
1453 | | DEFPY (ospf_area_nssa, |
1454 | | ospf_area_nssa_cmd, |
1455 | | "area <A.B.C.D|(0-4294967295)>$area_str nssa\ |
1456 | | [{\ |
1457 | | <translate-candidate|translate-never|translate-always>$translator_role\ |
1458 | | |default-information-originate$dflt_originate [{metric (0-16777214)$mval|metric-type (1-2)$mtype}]\ |
1459 | | |no-summary$no_summary\ |
1460 | | |suppress-fa$suppress_fa\ |
1461 | | }]", |
1462 | | "OSPF area parameters\n" |
1463 | | "OSPF area ID in IP address format\n" |
1464 | | "OSPF area ID as a decimal value\n" |
1465 | | "Configure OSPF area as nssa\n" |
1466 | | "Configure NSSA-ABR for translate election (default)\n" |
1467 | | "Configure NSSA-ABR to never translate\n" |
1468 | | "Configure NSSA-ABR to always translate\n" |
1469 | | "Originate Type 7 default into NSSA area\n" |
1470 | | "OSPF default metric\n" |
1471 | | "OSPF metric\n" |
1472 | | "OSPF metric type for default routes\n" |
1473 | | "Set OSPF External Type 1/2 metrics\n" |
1474 | | "Do not inject inter-area routes into nssa\n" |
1475 | | "Suppress forwarding address\n") |
1476 | 0 | { |
1477 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1478 | 0 | struct in_addr area_id; |
1479 | 0 | int ret, format; |
1480 | |
|
1481 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, area_str); |
1482 | |
|
1483 | 0 | ret = ospf_area_nssa_set(ospf, area_id); |
1484 | 0 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
1485 | 0 | format); |
1486 | 0 | if (ret == 0) { |
1487 | 0 | vty_out(vty, |
1488 | 0 | "%% Area cannot be nssa as it contains a virtual link\n"); |
1489 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1490 | 0 | } |
1491 | | |
1492 | 0 | if (translator_role) { |
1493 | 0 | if (strncmp(translator_role, "translate-c", 11) == 0) |
1494 | 0 | ospf_area_nssa_translator_role_set( |
1495 | 0 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); |
1496 | 0 | else if (strncmp(translator_role, "translate-n", 11) == 0) |
1497 | 0 | ospf_area_nssa_translator_role_set( |
1498 | 0 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); |
1499 | 0 | else if (strncmp(translator_role, "translate-a", 11) == 0) |
1500 | 0 | ospf_area_nssa_translator_role_set( |
1501 | 0 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); |
1502 | 0 | } else { |
1503 | 0 | ospf_area_nssa_translator_role_set(ospf, area_id, |
1504 | 0 | OSPF_NSSA_ROLE_CANDIDATE); |
1505 | 0 | } |
1506 | |
|
1507 | 0 | if (dflt_originate) { |
1508 | 0 | int metric_type = DEFAULT_METRIC_TYPE; |
1509 | |
|
1510 | 0 | if (mval_str == NULL) |
1511 | 0 | mval = -1; |
1512 | 0 | if (mtype_str) |
1513 | 0 | (void)str2metric_type(mtype_str, &metric_type); |
1514 | 0 | ospf_area_nssa_default_originate_set(ospf, area_id, mval, |
1515 | 0 | metric_type); |
1516 | 0 | } else |
1517 | 0 | ospf_area_nssa_default_originate_unset(ospf, area_id); |
1518 | |
|
1519 | 0 | if (no_summary) |
1520 | 0 | ospf_area_nssa_no_summary_set(ospf, area_id); |
1521 | 0 | else |
1522 | 0 | ospf_area_no_summary_unset(ospf, area_id); |
1523 | |
|
1524 | 0 | if (suppress_fa) |
1525 | 0 | ospf_area_nssa_suppress_fa_set(ospf, area_id); |
1526 | 0 | else |
1527 | 0 | ospf_area_nssa_suppress_fa_unset(ospf, area_id); |
1528 | | |
1529 | | /* Flush the external LSA for the specified area */ |
1530 | 0 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); |
1531 | 0 | ospf_schedule_abr_task(ospf); |
1532 | 0 | ospf_schedule_asbr_nssa_redist_update(ospf); |
1533 | |
|
1534 | 0 | return CMD_SUCCESS; |
1535 | 0 | } |
1536 | | |
1537 | | DEFPY (no_ospf_area_nssa, |
1538 | | no_ospf_area_nssa_cmd, |
1539 | | "no area <A.B.C.D|(0-4294967295)>$area_str nssa\ |
1540 | | [{\ |
1541 | | <translate-candidate|translate-never|translate-always>\ |
1542 | | |default-information-originate [{metric (0-16777214)|metric-type (1-2)}]\ |
1543 | | |no-summary\ |
1544 | | |suppress-fa\ |
1545 | | }]", |
1546 | | NO_STR |
1547 | | "OSPF area parameters\n" |
1548 | | "OSPF area ID in IP address format\n" |
1549 | | "OSPF area ID as a decimal value\n" |
1550 | | "Configure OSPF area as nssa\n" |
1551 | | "Configure NSSA-ABR for translate election (default)\n" |
1552 | | "Configure NSSA-ABR to never translate\n" |
1553 | | "Configure NSSA-ABR to always translate\n" |
1554 | | "Originate Type 7 default into NSSA area\n" |
1555 | | "OSPF default metric\n" |
1556 | | "OSPF metric\n" |
1557 | | "OSPF metric type for default routes\n" |
1558 | | "Set OSPF External Type 1/2 metrics\n" |
1559 | | "Do not inject inter-area routes into nssa\n" |
1560 | | "Suppress forwarding address\n") |
1561 | 0 | { |
1562 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1563 | 0 | struct in_addr area_id; |
1564 | 0 | int format; |
1565 | |
|
1566 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, area_str); |
1567 | | |
1568 | | /* Flush the NSSA LSA for the specified area */ |
1569 | 0 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA); |
1570 | 0 | ospf_area_no_summary_unset(ospf, area_id); |
1571 | 0 | ospf_area_nssa_default_originate_unset(ospf, area_id); |
1572 | 0 | ospf_area_nssa_suppress_fa_unset(ospf, area_id); |
1573 | 0 | ospf_area_nssa_unset(ospf, area_id); |
1574 | |
|
1575 | 0 | ospf_schedule_abr_task(ospf); |
1576 | |
|
1577 | 0 | return CMD_SUCCESS; |
1578 | 0 | } |
1579 | | |
1580 | | DEFPY (ospf_area_nssa_range, |
1581 | | ospf_area_nssa_range_cmd, |
1582 | | "area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise$not_adv|cost (0-16777215)$cost>]", |
1583 | | "OSPF area parameters\n" |
1584 | | "OSPF area ID in IP address format\n" |
1585 | | "OSPF area ID as a decimal value\n" |
1586 | | "Configure OSPF area as nssa\n" |
1587 | | "Configured address range\n" |
1588 | | "Specify IPv4 prefix\n" |
1589 | | "Do not advertise\n" |
1590 | | "User specified metric for this range\n" |
1591 | | "Advertised metric for this range\n") |
1592 | 0 | { |
1593 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1594 | 0 | struct ospf_area *area; |
1595 | 0 | struct in_addr area_id; |
1596 | 0 | int format; |
1597 | 0 | int advertise = 0; |
1598 | |
|
1599 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, area_str); |
1600 | 0 | area = ospf_area_get(ospf, area_id); |
1601 | 0 | ospf_area_display_format_set(ospf, area, format); |
1602 | |
|
1603 | 0 | if (area->external_routing != OSPF_AREA_NSSA) { |
1604 | 0 | vty_out(vty, "%% First configure %s as an NSSA area\n", |
1605 | 0 | area_str); |
1606 | 0 | return CMD_WARNING; |
1607 | 0 | } |
1608 | | |
1609 | 0 | if (!not_adv) |
1610 | 0 | advertise = OSPF_AREA_RANGE_ADVERTISE; |
1611 | |
|
1612 | 0 | ospf_area_range_set(ospf, area, area->nssa_ranges, |
1613 | 0 | (struct prefix_ipv4 *)prefix, advertise, true); |
1614 | 0 | if (cost_str) |
1615 | 0 | ospf_area_range_cost_set(ospf, area, area->nssa_ranges, |
1616 | 0 | (struct prefix_ipv4 *)prefix, cost); |
1617 | |
|
1618 | 0 | return CMD_SUCCESS; |
1619 | 0 | } |
1620 | | |
1621 | | DEFPY (no_ospf_area_nssa_range, |
1622 | | no_ospf_area_nssa_range_cmd, |
1623 | | "no area <A.B.C.D|(0-4294967295)>$area_str nssa range A.B.C.D/M$prefix [<not-advertise|cost (0-16777215)>]", |
1624 | | NO_STR |
1625 | | "OSPF area parameters\n" |
1626 | | "OSPF area ID in IP address format\n" |
1627 | | "OSPF area ID as a decimal value\n" |
1628 | | "Configure OSPF area as nssa\n" |
1629 | | "Configured address range\n" |
1630 | | "Specify IPv4 prefix\n" |
1631 | | "Do not advertise\n" |
1632 | | "User specified metric for this range\n" |
1633 | | "Advertised metric for this range\n") |
1634 | 0 | { |
1635 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1636 | 0 | struct ospf_area *area; |
1637 | 0 | struct in_addr area_id; |
1638 | 0 | int format; |
1639 | |
|
1640 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, area_str); |
1641 | 0 | area = ospf_area_get(ospf, area_id); |
1642 | 0 | ospf_area_display_format_set(ospf, area, format); |
1643 | |
|
1644 | 0 | if (area->external_routing != OSPF_AREA_NSSA) { |
1645 | 0 | vty_out(vty, "%% First configure %s as an NSSA area\n", |
1646 | 0 | area_str); |
1647 | 0 | return CMD_WARNING; |
1648 | 0 | } |
1649 | | |
1650 | 0 | ospf_area_range_unset(ospf, area, area->nssa_ranges, |
1651 | 0 | (struct prefix_ipv4 *)prefix); |
1652 | |
|
1653 | 0 | return CMD_SUCCESS; |
1654 | 0 | } |
1655 | | |
1656 | | DEFUN (ospf_area_default_cost, |
1657 | | ospf_area_default_cost_cmd, |
1658 | | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
1659 | | "OSPF area parameters\n" |
1660 | | "OSPF area ID in IP address format\n" |
1661 | | "OSPF area ID as a decimal value\n" |
1662 | | "Set the summary-default cost of a NSSA or stub area\n" |
1663 | | "Stub's advertised default summary cost\n") |
1664 | 0 | { |
1665 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1666 | 0 | int idx_ipv4_number = 1; |
1667 | 0 | int idx_number = 3; |
1668 | 0 | struct ospf_area *area; |
1669 | 0 | struct in_addr area_id; |
1670 | 0 | uint32_t cost; |
1671 | 0 | int format; |
1672 | 0 | struct prefix_ipv4 p; |
1673 | |
|
1674 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1675 | 0 | argv[idx_ipv4_number]->arg); |
1676 | 0 | cost = strtoul(argv[idx_number]->arg, NULL, 10); |
1677 | |
|
1678 | 0 | area = ospf_area_get(ospf, area_id); |
1679 | 0 | ospf_area_display_format_set(ospf, area, format); |
1680 | |
|
1681 | 0 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1682 | 0 | vty_out(vty, "The area is neither stub, nor NSSA\n"); |
1683 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1684 | 0 | } |
1685 | | |
1686 | 0 | area->default_cost = cost; |
1687 | |
|
1688 | 0 | p.family = AF_INET; |
1689 | 0 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; |
1690 | 0 | p.prefixlen = 0; |
1691 | 0 | if (IS_DEBUG_OSPF_EVENT) |
1692 | 0 | zlog_debug( |
1693 | 0 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1694 | 0 | &area->area_id); |
1695 | 0 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
1696 | |
|
1697 | 0 | return CMD_SUCCESS; |
1698 | 0 | } |
1699 | | |
1700 | | DEFUN (no_ospf_area_default_cost, |
1701 | | no_ospf_area_default_cost_cmd, |
1702 | | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
1703 | | NO_STR |
1704 | | "OSPF area parameters\n" |
1705 | | "OSPF area ID in IP address format\n" |
1706 | | "OSPF area ID as a decimal value\n" |
1707 | | "Set the summary-default cost of a NSSA or stub area\n" |
1708 | | "Stub's advertised default summary cost\n") |
1709 | 0 | { |
1710 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1711 | 0 | int idx_ipv4_number = 2; |
1712 | 0 | struct ospf_area *area; |
1713 | 0 | struct in_addr area_id; |
1714 | 0 | int format; |
1715 | 0 | struct prefix_ipv4 p; |
1716 | |
|
1717 | 0 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1718 | 0 | argv[idx_ipv4_number]->arg); |
1719 | |
|
1720 | 0 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1721 | 0 | if (area == NULL) |
1722 | 0 | return CMD_SUCCESS; |
1723 | | |
1724 | 0 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1725 | 0 | vty_out(vty, "The area is neither stub, nor NSSA\n"); |
1726 | 0 | return CMD_WARNING_CONFIG_FAILED; |
1727 | 0 | } |
1728 | | |
1729 | 0 | area->default_cost = 1; |
1730 | |
|
1731 | 0 | p.family = AF_INET; |
1732 | 0 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; |
1733 | 0 | p.prefixlen = 0; |
1734 | 0 | if (IS_DEBUG_OSPF_EVENT) |
1735 | 0 | zlog_debug( |
1736 | 0 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1737 | 0 | &area->area_id); |
1738 | 0 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
1739 | | |
1740 | |
|
1741 | 0 | ospf_area_check_free(ospf, area_id); |
1742 | |
|
1743 | 0 | return CMD_SUCCESS; |
1744 | 0 | } |
1745 | | |
1746 | | DEFUN (ospf_area_export_list, |
1747 | | ospf_area_export_list_cmd, |
1748 | | "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME", |
1749 | | "OSPF area parameters\n" |
1750 | | "OSPF area ID in IP address format\n" |
1751 | | "OSPF area ID as a decimal value\n" |
1752 | | "Set the filter for networks announced to other areas\n" |
1753 | | "Name of the access-list\n") |
1754 | 0 | { |
1755 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1756 | 0 | int idx_ipv4_number = 1; |
1757 | 0 | struct ospf_area *area; |
1758 | 0 | struct in_addr area_id; |
1759 | 0 | int format; |
1760 | |
|
1761 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
1762 | |
|
1763 | 0 | area = ospf_area_get(ospf, area_id); |
1764 | 0 | ospf_area_display_format_set(ospf, area, format); |
1765 | 0 | ospf_area_export_list_set(ospf, area, argv[3]->arg); |
1766 | |
|
1767 | 0 | return CMD_SUCCESS; |
1768 | 0 | } |
1769 | | |
1770 | | DEFUN (no_ospf_area_export_list, |
1771 | | no_ospf_area_export_list_cmd, |
1772 | | "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME", |
1773 | | NO_STR |
1774 | | "OSPF area parameters\n" |
1775 | | "OSPF area ID in IP address format\n" |
1776 | | "OSPF area ID as a decimal value\n" |
1777 | | "Unset the filter for networks announced to other areas\n" |
1778 | | "Name of the access-list\n") |
1779 | 0 | { |
1780 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1781 | 0 | int idx_ipv4_number = 2; |
1782 | 0 | struct ospf_area *area; |
1783 | 0 | struct in_addr area_id; |
1784 | 0 | int format; |
1785 | |
|
1786 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
1787 | |
|
1788 | 0 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1789 | 0 | if (area == NULL) |
1790 | 0 | return CMD_SUCCESS; |
1791 | | |
1792 | 0 | ospf_area_export_list_unset(ospf, area); |
1793 | |
|
1794 | 0 | return CMD_SUCCESS; |
1795 | 0 | } |
1796 | | |
1797 | | |
1798 | | DEFUN (ospf_area_import_list, |
1799 | | ospf_area_import_list_cmd, |
1800 | | "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME", |
1801 | | "OSPF area parameters\n" |
1802 | | "OSPF area ID in IP address format\n" |
1803 | | "OSPF area ID as a decimal value\n" |
1804 | | "Set the filter for networks from other areas announced to the specified one\n" |
1805 | | "Name of the access-list\n") |
1806 | 0 | { |
1807 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1808 | 0 | int idx_ipv4_number = 1; |
1809 | 0 | struct ospf_area *area; |
1810 | 0 | struct in_addr area_id; |
1811 | 0 | int format; |
1812 | |
|
1813 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
1814 | |
|
1815 | 0 | area = ospf_area_get(ospf, area_id); |
1816 | 0 | ospf_area_display_format_set(ospf, area, format); |
1817 | 0 | ospf_area_import_list_set(ospf, area, argv[3]->arg); |
1818 | |
|
1819 | 0 | return CMD_SUCCESS; |
1820 | 0 | } |
1821 | | |
1822 | | DEFUN (no_ospf_area_import_list, |
1823 | | no_ospf_area_import_list_cmd, |
1824 | | "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME", |
1825 | | NO_STR |
1826 | | "OSPF area parameters\n" |
1827 | | "OSPF area ID in IP address format\n" |
1828 | | "OSPF area ID as a decimal value\n" |
1829 | | "Unset the filter for networks announced to other areas\n" |
1830 | | "Name of the access-list\n") |
1831 | 0 | { |
1832 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1833 | 0 | int idx_ipv4_number = 2; |
1834 | 0 | struct ospf_area *area; |
1835 | 0 | struct in_addr area_id; |
1836 | 0 | int format; |
1837 | |
|
1838 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
1839 | |
|
1840 | 0 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1841 | 0 | if (area == NULL) |
1842 | 0 | return CMD_SUCCESS; |
1843 | | |
1844 | 0 | ospf_area_import_list_unset(ospf, area); |
1845 | |
|
1846 | 0 | return CMD_SUCCESS; |
1847 | 0 | } |
1848 | | |
1849 | | DEFUN (ospf_area_filter_list, |
1850 | | ospf_area_filter_list_cmd, |
1851 | | "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>", |
1852 | | "OSPF area parameters\n" |
1853 | | "OSPF area ID in IP address format\n" |
1854 | | "OSPF area ID as a decimal value\n" |
1855 | | "Filter networks between OSPF areas\n" |
1856 | | "Filter prefixes between OSPF areas\n" |
1857 | | "Name of an IP prefix-list\n" |
1858 | | "Filter networks sent to this area\n" |
1859 | | "Filter networks sent from this area\n") |
1860 | 0 | { |
1861 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1862 | 0 | int idx_ipv4_number = 1; |
1863 | 0 | int idx_word = 4; |
1864 | 0 | int idx_in_out = 5; |
1865 | 0 | struct ospf_area *area; |
1866 | 0 | struct in_addr area_id; |
1867 | 0 | struct prefix_list *plist; |
1868 | 0 | int format; |
1869 | |
|
1870 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
1871 | |
|
1872 | 0 | area = ospf_area_get(ospf, area_id); |
1873 | 0 | ospf_area_display_format_set(ospf, area, format); |
1874 | 0 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); |
1875 | 0 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1876 | 0 | PREFIX_LIST_IN(area) = plist; |
1877 | 0 | if (PREFIX_NAME_IN(area)) |
1878 | 0 | free(PREFIX_NAME_IN(area)); |
1879 | |
|
1880 | 0 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); |
1881 | 0 | ospf_schedule_abr_task(ospf); |
1882 | 0 | } else { |
1883 | 0 | PREFIX_LIST_OUT(area) = plist; |
1884 | 0 | if (PREFIX_NAME_OUT(area)) |
1885 | 0 | free(PREFIX_NAME_OUT(area)); |
1886 | |
|
1887 | 0 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); |
1888 | 0 | ospf_schedule_abr_task(ospf); |
1889 | 0 | } |
1890 | |
|
1891 | 0 | return CMD_SUCCESS; |
1892 | 0 | } |
1893 | | |
1894 | | DEFUN (no_ospf_area_filter_list, |
1895 | | no_ospf_area_filter_list_cmd, |
1896 | | "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>", |
1897 | | NO_STR |
1898 | | "OSPF area parameters\n" |
1899 | | "OSPF area ID in IP address format\n" |
1900 | | "OSPF area ID as a decimal value\n" |
1901 | | "Filter networks between OSPF areas\n" |
1902 | | "Filter prefixes between OSPF areas\n" |
1903 | | "Name of an IP prefix-list\n" |
1904 | | "Filter networks sent to this area\n" |
1905 | | "Filter networks sent from this area\n") |
1906 | 0 | { |
1907 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1908 | 0 | int idx_ipv4_number = 2; |
1909 | 0 | int idx_word = 5; |
1910 | 0 | int idx_in_out = 6; |
1911 | 0 | struct ospf_area *area; |
1912 | 0 | struct in_addr area_id; |
1913 | 0 | int format; |
1914 | |
|
1915 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
1916 | |
|
1917 | 0 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1918 | 0 | return CMD_SUCCESS; |
1919 | | |
1920 | 0 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1921 | 0 | if (PREFIX_NAME_IN(area)) |
1922 | 0 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) |
1923 | 0 | != 0) |
1924 | 0 | return CMD_SUCCESS; |
1925 | | |
1926 | 0 | PREFIX_LIST_IN(area) = NULL; |
1927 | 0 | if (PREFIX_NAME_IN(area)) |
1928 | 0 | free(PREFIX_NAME_IN(area)); |
1929 | |
|
1930 | 0 | PREFIX_NAME_IN(area) = NULL; |
1931 | |
|
1932 | 0 | ospf_schedule_abr_task(ospf); |
1933 | 0 | } else { |
1934 | 0 | if (PREFIX_NAME_OUT(area)) |
1935 | 0 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) |
1936 | 0 | != 0) |
1937 | 0 | return CMD_SUCCESS; |
1938 | | |
1939 | 0 | PREFIX_LIST_OUT(area) = NULL; |
1940 | 0 | if (PREFIX_NAME_OUT(area)) |
1941 | 0 | free(PREFIX_NAME_OUT(area)); |
1942 | |
|
1943 | 0 | PREFIX_NAME_OUT(area) = NULL; |
1944 | |
|
1945 | 0 | ospf_schedule_abr_task(ospf); |
1946 | 0 | } |
1947 | | |
1948 | 0 | return CMD_SUCCESS; |
1949 | 0 | } |
1950 | | |
1951 | | |
1952 | | DEFUN (ospf_area_authentication_message_digest, |
1953 | | ospf_area_authentication_message_digest_cmd, |
1954 | | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1955 | | NO_STR |
1956 | | "OSPF area parameters\n" |
1957 | | "OSPF area ID in IP address format\n" |
1958 | | "OSPF area ID as a decimal value\n" |
1959 | | "Enable authentication\n" |
1960 | | "Use message-digest authentication\n") |
1961 | 0 | { |
1962 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1963 | 0 | int idx = 0; |
1964 | 0 | struct ospf_area *area; |
1965 | 0 | struct in_addr area_id; |
1966 | 0 | int format; |
1967 | |
|
1968 | 0 | argv_find(argv, argc, "area", &idx); |
1969 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); |
1970 | |
|
1971 | 0 | area = ospf_area_get(ospf, area_id); |
1972 | 0 | ospf_area_display_format_set(ospf, area, format); |
1973 | 0 | area->auth_type = strmatch(argv[0]->text, "no") |
1974 | 0 | ? OSPF_AUTH_NULL |
1975 | 0 | : OSPF_AUTH_CRYPTOGRAPHIC; |
1976 | |
|
1977 | 0 | return CMD_SUCCESS; |
1978 | 0 | } |
1979 | | |
1980 | | DEFUN (ospf_area_authentication, |
1981 | | ospf_area_authentication_cmd, |
1982 | | "area <A.B.C.D|(0-4294967295)> authentication", |
1983 | | "OSPF area parameters\n" |
1984 | | "OSPF area ID in IP address format\n" |
1985 | | "OSPF area ID as a decimal value\n" |
1986 | | "Enable authentication\n") |
1987 | 0 | { |
1988 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
1989 | 0 | int idx_ipv4_number = 1; |
1990 | 0 | struct ospf_area *area; |
1991 | 0 | struct in_addr area_id; |
1992 | 0 | int format; |
1993 | |
|
1994 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
1995 | |
|
1996 | 0 | area = ospf_area_get(ospf, area_id); |
1997 | 0 | ospf_area_display_format_set(ospf, area, format); |
1998 | 0 | area->auth_type = OSPF_AUTH_SIMPLE; |
1999 | |
|
2000 | 0 | return CMD_SUCCESS; |
2001 | 0 | } |
2002 | | |
2003 | | DEFUN (no_ospf_area_authentication, |
2004 | | no_ospf_area_authentication_cmd, |
2005 | | "no area <A.B.C.D|(0-4294967295)> authentication", |
2006 | | NO_STR |
2007 | | "OSPF area parameters\n" |
2008 | | "OSPF area ID in IP address format\n" |
2009 | | "OSPF area ID as a decimal value\n" |
2010 | | "Enable authentication\n") |
2011 | 0 | { |
2012 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2013 | 0 | int idx_ipv4_number = 2; |
2014 | 0 | struct ospf_area *area; |
2015 | 0 | struct in_addr area_id; |
2016 | 0 | int format; |
2017 | |
|
2018 | 0 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
2019 | |
|
2020 | 0 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2021 | 0 | if (area == NULL) |
2022 | 0 | return CMD_SUCCESS; |
2023 | | |
2024 | 0 | area->auth_type = OSPF_AUTH_NULL; |
2025 | |
|
2026 | 0 | ospf_area_check_free(ospf, area_id); |
2027 | |
|
2028 | 0 | return CMD_SUCCESS; |
2029 | 0 | } |
2030 | | |
2031 | | |
2032 | | DEFUN (ospf_abr_type, |
2033 | | ospf_abr_type_cmd, |
2034 | | "ospf abr-type <cisco|ibm|shortcut|standard>", |
2035 | | "OSPF specific commands\n" |
2036 | | "Set OSPF ABR type\n" |
2037 | | "Alternative ABR, cisco implementation\n" |
2038 | | "Alternative ABR, IBM implementation\n" |
2039 | | "Shortcut ABR\n" |
2040 | | "Standard behavior (RFC2328)\n") |
2041 | 0 | { |
2042 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2043 | 0 | int idx_vendor = 2; |
2044 | 0 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
2045 | |
|
2046 | 0 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) |
2047 | 0 | abr_type = OSPF_ABR_CISCO; |
2048 | 0 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) |
2049 | 0 | abr_type = OSPF_ABR_IBM; |
2050 | 0 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) |
2051 | 0 | abr_type = OSPF_ABR_SHORTCUT; |
2052 | 0 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) |
2053 | 0 | abr_type = OSPF_ABR_STAND; |
2054 | 0 | else |
2055 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2056 | | |
2057 | | /* If ABR type value is changed, schedule ABR task. */ |
2058 | 0 | if (ospf->abr_type != abr_type) { |
2059 | 0 | ospf->abr_type = abr_type; |
2060 | 0 | ospf_schedule_abr_task(ospf); |
2061 | 0 | } |
2062 | |
|
2063 | 0 | return CMD_SUCCESS; |
2064 | 0 | } |
2065 | | |
2066 | | DEFUN (no_ospf_abr_type, |
2067 | | no_ospf_abr_type_cmd, |
2068 | | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
2069 | | NO_STR |
2070 | | "OSPF specific commands\n" |
2071 | | "Set OSPF ABR type\n" |
2072 | | "Alternative ABR, cisco implementation\n" |
2073 | | "Alternative ABR, IBM implementation\n" |
2074 | | "Shortcut ABR\n" |
2075 | | "Standard ABR\n") |
2076 | 0 | { |
2077 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2078 | 0 | int idx_vendor = 3; |
2079 | 0 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
2080 | |
|
2081 | 0 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) |
2082 | 0 | abr_type = OSPF_ABR_CISCO; |
2083 | 0 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) |
2084 | 0 | abr_type = OSPF_ABR_IBM; |
2085 | 0 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) |
2086 | 0 | abr_type = OSPF_ABR_SHORTCUT; |
2087 | 0 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) |
2088 | 0 | abr_type = OSPF_ABR_STAND; |
2089 | 0 | else |
2090 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2091 | | |
2092 | | /* If ABR type value is changed, schedule ABR task. */ |
2093 | 0 | if (ospf->abr_type == abr_type) { |
2094 | 0 | ospf->abr_type = OSPF_ABR_DEFAULT; |
2095 | 0 | ospf_schedule_abr_task(ospf); |
2096 | 0 | } |
2097 | |
|
2098 | 0 | return CMD_SUCCESS; |
2099 | 0 | } |
2100 | | |
2101 | | DEFUN (ospf_log_adjacency_changes, |
2102 | | ospf_log_adjacency_changes_cmd, |
2103 | | "log-adjacency-changes", |
2104 | | "Log changes in adjacency state\n") |
2105 | 0 | { |
2106 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2107 | |
|
2108 | 0 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2109 | 0 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2110 | 0 | return CMD_SUCCESS; |
2111 | 0 | } |
2112 | | |
2113 | | DEFUN (ospf_log_adjacency_changes_detail, |
2114 | | ospf_log_adjacency_changes_detail_cmd, |
2115 | | "log-adjacency-changes detail", |
2116 | | "Log changes in adjacency state\n" |
2117 | | "Log all state changes\n") |
2118 | 0 | { |
2119 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2120 | |
|
2121 | 0 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2122 | 0 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2123 | 0 | return CMD_SUCCESS; |
2124 | 0 | } |
2125 | | |
2126 | | DEFUN (no_ospf_log_adjacency_changes, |
2127 | | no_ospf_log_adjacency_changes_cmd, |
2128 | | "no log-adjacency-changes", |
2129 | | NO_STR |
2130 | | "Log changes in adjacency state\n") |
2131 | 0 | { |
2132 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2133 | |
|
2134 | 0 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2135 | 0 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2136 | 0 | return CMD_SUCCESS; |
2137 | 0 | } |
2138 | | |
2139 | | DEFUN (no_ospf_log_adjacency_changes_detail, |
2140 | | no_ospf_log_adjacency_changes_detail_cmd, |
2141 | | "no log-adjacency-changes detail", |
2142 | | NO_STR |
2143 | | "Log changes in adjacency state\n" |
2144 | | "Log all state changes\n") |
2145 | 0 | { |
2146 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2147 | |
|
2148 | 0 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2149 | 0 | return CMD_SUCCESS; |
2150 | 0 | } |
2151 | | |
2152 | | DEFUN (ospf_compatible_rfc1583, |
2153 | | ospf_compatible_rfc1583_cmd, |
2154 | | "compatible rfc1583", |
2155 | | "OSPF compatibility list\n" |
2156 | | "compatible with RFC 1583\n") |
2157 | 0 | { |
2158 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2159 | |
|
2160 | 0 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2161 | 0 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); |
2162 | 0 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2163 | 0 | } |
2164 | 0 | return CMD_SUCCESS; |
2165 | 0 | } |
2166 | | |
2167 | | DEFUN (no_ospf_compatible_rfc1583, |
2168 | | no_ospf_compatible_rfc1583_cmd, |
2169 | | "no compatible rfc1583", |
2170 | | NO_STR |
2171 | | "OSPF compatibility list\n" |
2172 | | "compatible with RFC 1583\n") |
2173 | 0 | { |
2174 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2175 | |
|
2176 | 0 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2177 | 0 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); |
2178 | 0 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2179 | 0 | } |
2180 | 0 | return CMD_SUCCESS; |
2181 | 0 | } |
2182 | | |
2183 | | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2184 | | "ospf rfc1583compatibility", |
2185 | | "OSPF specific commands\n" |
2186 | | "Enable the RFC1583Compatibility flag\n") |
2187 | | |
2188 | | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
2189 | | "no ospf rfc1583compatibility", NO_STR |
2190 | | "OSPF specific commands\n" |
2191 | | "Disable the RFC1583Compatibility flag\n") |
2192 | | |
2193 | | static void ospf_table_reinstall_routes(struct ospf *ospf, |
2194 | | struct route_table *rt) |
2195 | 0 | { |
2196 | 0 | struct route_node *rn; |
2197 | |
|
2198 | 0 | if (!rt) |
2199 | 0 | return; |
2200 | | |
2201 | 0 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
2202 | 0 | struct ospf_route *or; |
2203 | |
|
2204 | 0 | or = rn->info; |
2205 | 0 | if (!or) |
2206 | 0 | continue; |
2207 | | |
2208 | 0 | if (or->type == OSPF_DESTINATION_NETWORK) |
2209 | 0 | ospf_zebra_add(ospf, (struct prefix_ipv4 *)&rn->p, or); |
2210 | 0 | else if (or->type == OSPF_DESTINATION_DISCARD) |
2211 | 0 | ospf_zebra_add_discard(ospf, |
2212 | 0 | (struct prefix_ipv4 *)&rn->p); |
2213 | 0 | } |
2214 | 0 | } |
2215 | | |
2216 | | static void ospf_reinstall_routes(struct ospf *ospf) |
2217 | 0 | { |
2218 | 0 | ospf_table_reinstall_routes(ospf, ospf->new_table); |
2219 | 0 | ospf_table_reinstall_routes(ospf, ospf->new_external_route); |
2220 | 0 | } |
2221 | | |
2222 | | DEFPY (ospf_send_extra_data, |
2223 | | ospf_send_extra_data_cmd, |
2224 | | "[no] ospf send-extra-data zebra", |
2225 | | NO_STR |
2226 | | OSPF_STR |
2227 | | "Extra data to Zebra for display/use\n" |
2228 | | "To zebra\n") |
2229 | 0 | { |
2230 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2231 | |
|
2232 | 0 | if (no && CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) { |
2233 | 0 | UNSET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA); |
2234 | 0 | ospf_reinstall_routes(ospf); |
2235 | 0 | } else if (!CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) { |
2236 | 0 | SET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA); |
2237 | 0 | ospf_reinstall_routes(ospf); |
2238 | 0 | } |
2239 | |
|
2240 | 0 | return CMD_SUCCESS; |
2241 | 0 | } |
2242 | | |
2243 | | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2244 | | unsigned int hold, unsigned int max) |
2245 | 0 | { |
2246 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2247 | |
|
2248 | 0 | ospf->spf_delay = delay; |
2249 | 0 | ospf->spf_holdtime = hold; |
2250 | 0 | ospf->spf_max_holdtime = max; |
2251 | |
|
2252 | 0 | return CMD_SUCCESS; |
2253 | 0 | } |
2254 | | |
2255 | | DEFUN (ospf_timers_min_ls_interval, |
2256 | | ospf_timers_min_ls_interval_cmd, |
2257 | | "timers throttle lsa all (0-5000)", |
2258 | | "Adjust routing timers\n" |
2259 | | "Throttling adaptive timer\n" |
2260 | | "LSA delay between transmissions\n" |
2261 | | "All LSA types\n" |
2262 | | "Delay (msec) between sending LSAs\n") |
2263 | 0 | { |
2264 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2265 | 0 | int idx_number = 4; |
2266 | 0 | unsigned int interval; |
2267 | |
|
2268 | 0 | if (argc < 5) { |
2269 | 0 | vty_out(vty, "Insufficient arguments\n"); |
2270 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2271 | 0 | } |
2272 | | |
2273 | 0 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2274 | |
|
2275 | 0 | ospf->min_ls_interval = interval; |
2276 | |
|
2277 | 0 | return CMD_SUCCESS; |
2278 | 0 | } |
2279 | | |
2280 | | DEFUN (no_ospf_timers_min_ls_interval, |
2281 | | no_ospf_timers_min_ls_interval_cmd, |
2282 | | "no timers throttle lsa all [(0-5000)]", |
2283 | | NO_STR |
2284 | | "Adjust routing timers\n" |
2285 | | "Throttling adaptive timer\n" |
2286 | | "LSA delay between transmissions\n" |
2287 | | "All LSA types\n" |
2288 | | "Delay (msec) between sending LSAs\n") |
2289 | 0 | { |
2290 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2291 | 0 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
2292 | |
|
2293 | 0 | return CMD_SUCCESS; |
2294 | 0 | } |
2295 | | |
2296 | | DEFUN (ospf_timers_throttle_spf, |
2297 | | ospf_timers_throttle_spf_cmd, |
2298 | | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
2299 | | "Adjust routing timers\n" |
2300 | | "Throttling adaptive timer\n" |
2301 | | "OSPF SPF timers\n" |
2302 | | "Delay (msec) from first change received till SPF calculation\n" |
2303 | | "Initial hold time (msec) between consecutive SPF calculations\n" |
2304 | | "Maximum hold time (msec)\n") |
2305 | 0 | { |
2306 | 0 | int idx_number = 3; |
2307 | 0 | int idx_number_2 = 4; |
2308 | 0 | int idx_number_3 = 5; |
2309 | 0 | unsigned int delay, hold, max; |
2310 | |
|
2311 | 0 | if (argc < 6) { |
2312 | 0 | vty_out(vty, "Insufficient arguments\n"); |
2313 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2314 | 0 | } |
2315 | | |
2316 | 0 | delay = strtoul(argv[idx_number]->arg, NULL, 10); |
2317 | 0 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); |
2318 | 0 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); |
2319 | |
|
2320 | 0 | return ospf_timers_spf_set(vty, delay, hold, max); |
2321 | 0 | } |
2322 | | |
2323 | | DEFUN (no_ospf_timers_throttle_spf, |
2324 | | no_ospf_timers_throttle_spf_cmd, |
2325 | | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
2326 | | NO_STR |
2327 | | "Adjust routing timers\n" |
2328 | | "Throttling adaptive timer\n" |
2329 | | "OSPF SPF timers\n" |
2330 | | "Delay (msec) from first change received till SPF calculation\n" |
2331 | | "Initial hold time (msec) between consecutive SPF calculations\n" |
2332 | | "Maximum hold time (msec)\n") |
2333 | 0 | { |
2334 | 0 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2335 | 0 | OSPF_SPF_HOLDTIME_DEFAULT, |
2336 | 0 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); |
2337 | 0 | } |
2338 | | |
2339 | | |
2340 | | DEFUN (ospf_timers_lsa_min_arrival, |
2341 | | ospf_timers_lsa_min_arrival_cmd, |
2342 | | "timers lsa min-arrival (0-600000)", |
2343 | | "Adjust routing timers\n" |
2344 | | "OSPF LSA timers\n" |
2345 | | "Minimum delay in receiving new version of a LSA\n" |
2346 | | "Delay in milliseconds\n") |
2347 | 0 | { |
2348 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2349 | 0 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
2350 | 0 | return CMD_SUCCESS; |
2351 | 0 | } |
2352 | | |
2353 | | DEFUN (no_ospf_timers_lsa_min_arrival, |
2354 | | no_ospf_timers_lsa_min_arrival_cmd, |
2355 | | "no timers lsa min-arrival [(0-600000)]", |
2356 | | NO_STR |
2357 | | "Adjust routing timers\n" |
2358 | | "OSPF LSA timers\n" |
2359 | | "Minimum delay in receiving new version of a LSA\n" |
2360 | | "Delay in milliseconds\n") |
2361 | 0 | { |
2362 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2363 | 0 | unsigned int minarrival; |
2364 | |
|
2365 | 0 | if (argc > 4) { |
2366 | 0 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
2367 | |
|
2368 | 0 | if (ospf->min_ls_arrival != minarrival |
2369 | 0 | || minarrival == OSPF_MIN_LS_ARRIVAL) |
2370 | 0 | return CMD_SUCCESS; |
2371 | 0 | } |
2372 | | |
2373 | 0 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
2374 | |
|
2375 | 0 | return CMD_SUCCESS; |
2376 | 0 | } |
2377 | | |
2378 | | DEFUN (ospf_neighbor, |
2379 | | ospf_neighbor_cmd, |
2380 | | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
2381 | | NEIGHBOR_STR |
2382 | | "Neighbor IP address\n" |
2383 | | "Neighbor Priority\n" |
2384 | | "Priority\n" |
2385 | | "Dead Neighbor Polling interval\n" |
2386 | | "Seconds\n") |
2387 | 0 | { |
2388 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2389 | 0 | int idx_ipv4 = 1; |
2390 | 0 | int idx_pri = 3; |
2391 | 0 | int idx_poll = 5; |
2392 | 0 | struct in_addr nbr_addr; |
2393 | 0 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; |
2394 | 0 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; |
2395 | |
|
2396 | 0 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2397 | 0 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); |
2398 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2399 | 0 | } |
2400 | | |
2401 | 0 | if (argc > 2) |
2402 | 0 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); |
2403 | |
|
2404 | 0 | if (argc > 4) |
2405 | 0 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
2406 | |
|
2407 | 0 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2408 | |
|
2409 | 0 | if (argc > 2) |
2410 | 0 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); |
2411 | |
|
2412 | 0 | if (argc > 4) |
2413 | 0 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); |
2414 | |
|
2415 | 0 | return CMD_SUCCESS; |
2416 | 0 | } |
2417 | | |
2418 | | DEFUN (ospf_neighbor_poll_interval, |
2419 | | ospf_neighbor_poll_interval_cmd, |
2420 | | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
2421 | | NEIGHBOR_STR |
2422 | | "Neighbor IP address\n" |
2423 | | "Dead Neighbor Polling interval\n" |
2424 | | "Seconds\n" |
2425 | | "OSPF priority of non-broadcast neighbor\n" |
2426 | | "Priority\n") |
2427 | 0 | { |
2428 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2429 | 0 | int idx_ipv4 = 1; |
2430 | 0 | int idx_poll = 3; |
2431 | 0 | int idx_pri = 5; |
2432 | 0 | struct in_addr nbr_addr; |
2433 | 0 | unsigned int priority; |
2434 | 0 | unsigned int interval; |
2435 | |
|
2436 | 0 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2437 | 0 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); |
2438 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2439 | 0 | } |
2440 | | |
2441 | 0 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
2442 | |
|
2443 | 0 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2444 | 0 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; |
2445 | |
|
2446 | 0 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2447 | 0 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); |
2448 | |
|
2449 | 0 | if (argc > 4) |
2450 | 0 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); |
2451 | |
|
2452 | 0 | return CMD_SUCCESS; |
2453 | 0 | } |
2454 | | |
2455 | | DEFUN (no_ospf_neighbor, |
2456 | | no_ospf_neighbor_cmd, |
2457 | | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
2458 | | NO_STR |
2459 | | NEIGHBOR_STR |
2460 | | "Neighbor IP address\n" |
2461 | | "Neighbor Priority\n" |
2462 | | "Priority\n" |
2463 | | "Dead Neighbor Polling interval\n" |
2464 | | "Seconds\n") |
2465 | 0 | { |
2466 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2467 | 0 | int idx_ipv4 = 2; |
2468 | 0 | struct in_addr nbr_addr; |
2469 | |
|
2470 | 0 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2471 | 0 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); |
2472 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2473 | 0 | } |
2474 | | |
2475 | 0 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
2476 | |
|
2477 | 0 | return CMD_SUCCESS; |
2478 | 0 | } |
2479 | | |
2480 | | DEFUN (no_ospf_neighbor_poll, |
2481 | | no_ospf_neighbor_poll_cmd, |
2482 | | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
2483 | | NO_STR |
2484 | | NEIGHBOR_STR |
2485 | | "Neighbor IP address\n" |
2486 | | "Dead Neighbor Polling interval\n" |
2487 | | "Seconds\n" |
2488 | | "Neighbor Priority\n" |
2489 | | "Priority\n") |
2490 | 0 | { |
2491 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2492 | 0 | int idx_ipv4 = 2; |
2493 | 0 | struct in_addr nbr_addr; |
2494 | |
|
2495 | 0 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2496 | 0 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); |
2497 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2498 | 0 | } |
2499 | | |
2500 | 0 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
2501 | |
|
2502 | 0 | return CMD_SUCCESS; |
2503 | 0 | } |
2504 | | |
2505 | | DEFUN (ospf_refresh_timer, |
2506 | | ospf_refresh_timer_cmd, |
2507 | | "refresh timer (10-1800)", |
2508 | | "Adjust refresh parameters\n" |
2509 | | "Set refresh timer\n" |
2510 | | "Timer value in seconds\n") |
2511 | 0 | { |
2512 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2513 | 0 | int idx_number = 2; |
2514 | 0 | unsigned int interval; |
2515 | |
|
2516 | 0 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2517 | 0 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) |
2518 | 0 | * OSPF_LSA_REFRESHER_GRANULARITY; |
2519 | |
|
2520 | 0 | ospf_timers_refresh_set(ospf, interval); |
2521 | |
|
2522 | 0 | return CMD_SUCCESS; |
2523 | 0 | } |
2524 | | |
2525 | | DEFUN (no_ospf_refresh_timer, |
2526 | | no_ospf_refresh_timer_val_cmd, |
2527 | | "no refresh timer [(10-1800)]", |
2528 | | NO_STR |
2529 | | "Adjust refresh parameters\n" |
2530 | | "Unset refresh timer\n" |
2531 | | "Timer value in seconds\n") |
2532 | 0 | { |
2533 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2534 | 0 | int idx_number = 3; |
2535 | 0 | unsigned int interval; |
2536 | |
|
2537 | 0 | if (argc == 1) { |
2538 | 0 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2539 | |
|
2540 | 0 | if (ospf->lsa_refresh_interval != interval |
2541 | 0 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
2542 | 0 | return CMD_SUCCESS; |
2543 | 0 | } |
2544 | | |
2545 | 0 | ospf_timers_refresh_unset(ospf); |
2546 | |
|
2547 | 0 | return CMD_SUCCESS; |
2548 | 0 | } |
2549 | | |
2550 | | |
2551 | | DEFUN (ospf_auto_cost_reference_bandwidth, |
2552 | | ospf_auto_cost_reference_bandwidth_cmd, |
2553 | | "auto-cost reference-bandwidth (1-4294967)", |
2554 | | "Calculate OSPF interface cost according to bandwidth\n" |
2555 | | "Use reference bandwidth method to assign OSPF cost\n" |
2556 | | "The reference bandwidth in terms of Mbits per second\n") |
2557 | 0 | { |
2558 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2559 | 0 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
2560 | 0 | int idx_number = 2; |
2561 | 0 | uint32_t refbw; |
2562 | 0 | struct interface *ifp; |
2563 | |
|
2564 | 0 | refbw = strtol(argv[idx_number]->arg, NULL, 10); |
2565 | 0 | if (refbw < 1 || refbw > 4294967) { |
2566 | 0 | vty_out(vty, "reference-bandwidth value is invalid\n"); |
2567 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2568 | 0 | } |
2569 | | |
2570 | | /* If reference bandwidth is changed. */ |
2571 | 0 | if ((refbw) == ospf->ref_bandwidth) |
2572 | 0 | return CMD_SUCCESS; |
2573 | | |
2574 | 0 | ospf->ref_bandwidth = refbw; |
2575 | 0 | FOR_ALL_INTERFACES (vrf, ifp) |
2576 | 0 | ospf_if_recalculate_output_cost(ifp); |
2577 | |
|
2578 | 0 | return CMD_SUCCESS; |
2579 | 0 | } |
2580 | | |
2581 | | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2582 | | no_ospf_auto_cost_reference_bandwidth_cmd, |
2583 | | "no auto-cost reference-bandwidth [(1-4294967)]", |
2584 | | NO_STR |
2585 | | "Calculate OSPF interface cost according to bandwidth\n" |
2586 | | "Use reference bandwidth method to assign OSPF cost\n" |
2587 | | "The reference bandwidth in terms of Mbits per second\n") |
2588 | 0 | { |
2589 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2590 | 0 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
2591 | 0 | struct interface *ifp; |
2592 | |
|
2593 | 0 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2594 | 0 | return CMD_SUCCESS; |
2595 | | |
2596 | 0 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; |
2597 | 0 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); |
2598 | 0 | vty_out(vty, |
2599 | 0 | " Please ensure reference bandwidth is consistent across all routers\n"); |
2600 | |
|
2601 | 0 | FOR_ALL_INTERFACES (vrf, ifp) |
2602 | 0 | ospf_if_recalculate_output_cost(ifp); |
2603 | |
|
2604 | 0 | return CMD_SUCCESS; |
2605 | 0 | } |
2606 | | |
2607 | | DEFUN (ospf_write_multiplier, |
2608 | | ospf_write_multiplier_cmd, |
2609 | | "ospf write-multiplier (1-100)", |
2610 | | "OSPF specific commands\n" |
2611 | | "Write multiplier\n" |
2612 | | "Maximum number of interface serviced per write\n") |
2613 | 0 | { |
2614 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2615 | 0 | int idx_number; |
2616 | 0 | uint32_t write_oi_count; |
2617 | |
|
2618 | 0 | if (argc == 3) |
2619 | 0 | idx_number = 2; |
2620 | 0 | else |
2621 | 0 | idx_number = 1; |
2622 | |
|
2623 | 0 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); |
2624 | 0 | if (write_oi_count < 1 || write_oi_count > 100) { |
2625 | 0 | vty_out(vty, "write-multiplier value is invalid\n"); |
2626 | 0 | return CMD_WARNING_CONFIG_FAILED; |
2627 | 0 | } |
2628 | | |
2629 | 0 | ospf->write_oi_count = write_oi_count; |
2630 | 0 | return CMD_SUCCESS; |
2631 | 0 | } |
2632 | | |
2633 | | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2634 | | "Write multiplier\n" |
2635 | | "Maximum number of interface serviced per write\n") |
2636 | | |
2637 | | DEFUN (no_ospf_write_multiplier, |
2638 | | no_ospf_write_multiplier_cmd, |
2639 | | "no ospf write-multiplier (1-100)", |
2640 | | NO_STR |
2641 | | "OSPF specific commands\n" |
2642 | | "Write multiplier\n" |
2643 | | "Maximum number of interface serviced per write\n") |
2644 | 0 | { |
2645 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2646 | |
|
2647 | 0 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2648 | 0 | return CMD_SUCCESS; |
2649 | 0 | } |
2650 | | |
2651 | | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
2652 | | "no write-multiplier (1-100)", NO_STR |
2653 | | "Write multiplier\n" |
2654 | | "Maximum number of interface serviced per write\n") |
2655 | | |
2656 | | DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]", |
2657 | | "Fast Reroute for MPLS and IP resilience\n" |
2658 | | "Topology Independent LFA (Loop-Free Alternate)\n" |
2659 | | "TI-LFA node protection (default is link protection)\n") |
2660 | 0 | { |
2661 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2662 | |
|
2663 | 0 | ospf->ti_lfa_enabled = true; |
2664 | |
|
2665 | 0 | if (argc == 3) |
2666 | 0 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION; |
2667 | 0 | else |
2668 | 0 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION; |
2669 | |
|
2670 | 0 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2671 | |
|
2672 | 0 | return CMD_SUCCESS; |
2673 | 0 | } |
2674 | | |
2675 | | DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd, |
2676 | | "no fast-reroute ti-lfa [node-protection]", |
2677 | | NO_STR |
2678 | | "Fast Reroute for MPLS and IP resilience\n" |
2679 | | "Topology Independent LFA (Loop-Free Alternate)\n" |
2680 | | "TI-LFA node protection (default is link protection)\n") |
2681 | 0 | { |
2682 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2683 | |
|
2684 | 0 | ospf->ti_lfa_enabled = false; |
2685 | |
|
2686 | 0 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION; |
2687 | |
|
2688 | 0 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2689 | |
|
2690 | 0 | return CMD_SUCCESS; |
2691 | 0 | } |
2692 | | |
2693 | | static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths) |
2694 | 0 | { |
2695 | 0 | if (ospf->max_multipath == paths) |
2696 | 0 | return; |
2697 | | |
2698 | 0 | ospf->max_multipath = paths; |
2699 | | |
2700 | | /* Send deletion notification to zebra to delete all |
2701 | | * ospf specific routes and reinitiat SPF to reflect |
2702 | | * the new max multipath. |
2703 | | */ |
2704 | 0 | ospf_restart_spf(ospf); |
2705 | 0 | } |
2706 | | |
2707 | | /* Ospf Maximum multiple paths config support */ |
2708 | | DEFUN (ospf_max_multipath, |
2709 | | ospf_max_multipath_cmd, |
2710 | | "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), |
2711 | | "Max no of multiple paths for ECMP support\n" |
2712 | | "Number of paths\n") |
2713 | 0 | { |
2714 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2715 | 0 | int idx_number = 1; |
2716 | 0 | uint16_t maxpaths; |
2717 | |
|
2718 | 0 | maxpaths = strtol(argv[idx_number]->arg, NULL, 10); |
2719 | |
|
2720 | 0 | ospf_maxpath_set(vty, ospf, maxpaths); |
2721 | 0 | return CMD_SUCCESS; |
2722 | 0 | } |
2723 | | |
2724 | | DEFUN (no_ospf_max_multipath, |
2725 | | no_ospf_max_multipath_cmd, |
2726 | | "no maximum-paths", |
2727 | | NO_STR |
2728 | | "Max no of multiple paths for ECMP support\n") |
2729 | 0 | { |
2730 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2731 | 0 | uint16_t maxpaths = MULTIPATH_NUM; |
2732 | |
|
2733 | 0 | ospf_maxpath_set(vty, ospf, maxpaths); |
2734 | 0 | return CMD_SUCCESS; |
2735 | 0 | } |
2736 | | |
2737 | | static const char *const ospf_abr_type_descr_str[] = { |
2738 | | "Unknown", "Standard (RFC2328)", "Alternative IBM", |
2739 | | "Alternative Cisco", "Alternative Shortcut" |
2740 | | }; |
2741 | | |
2742 | | static const char *const ospf_shortcut_mode_descr_str[] = { |
2743 | | "Default", "Enabled", "Disabled" |
2744 | | }; |
2745 | | |
2746 | | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, |
2747 | | json_object *json_areas, bool use_json) |
2748 | 0 | { |
2749 | 0 | json_object *json_area = NULL; |
2750 | 0 | char buf[PREFIX_STRLEN]; |
2751 | |
|
2752 | 0 | if (use_json) |
2753 | 0 | json_area = json_object_new_object(); |
2754 | | |
2755 | | /* Show Area ID. */ |
2756 | 0 | if (!use_json) |
2757 | 0 | vty_out(vty, " Area ID: %pI4", &area->area_id); |
2758 | | |
2759 | | /* Show Area type/mode. */ |
2760 | 0 | if (OSPF_IS_AREA_BACKBONE(area)) { |
2761 | 0 | if (use_json) |
2762 | 0 | json_object_boolean_true_add(json_area, "backbone"); |
2763 | 0 | else |
2764 | 0 | vty_out(vty, " (Backbone)\n"); |
2765 | 0 | } else { |
2766 | 0 | if (use_json) { |
2767 | 0 | if (area->external_routing == OSPF_AREA_STUB) { |
2768 | 0 | if (area->no_summary) |
2769 | 0 | json_object_boolean_true_add( |
2770 | 0 | json_area, "stubNoSummary"); |
2771 | 0 | if (area->shortcut_configured) |
2772 | 0 | json_object_boolean_true_add( |
2773 | 0 | json_area, "stubShortcut"); |
2774 | 0 | } else if (area->external_routing == OSPF_AREA_NSSA) { |
2775 | 0 | if (area->no_summary) |
2776 | 0 | json_object_boolean_true_add( |
2777 | 0 | json_area, "nssaNoSummary"); |
2778 | 0 | if (area->shortcut_configured) |
2779 | 0 | json_object_boolean_true_add( |
2780 | 0 | json_area, "nssaShortcut"); |
2781 | 0 | } |
2782 | |
|
2783 | 0 | json_object_string_add( |
2784 | 0 | json_area, "shortcuttingMode", |
2785 | 0 | ospf_shortcut_mode_descr_str |
2786 | 0 | [area->shortcut_configured]); |
2787 | 0 | if (area->shortcut_capability) |
2788 | 0 | json_object_boolean_true_add(json_area, |
2789 | 0 | "sBitConcensus"); |
2790 | 0 | } else { |
2791 | 0 | if (area->external_routing == OSPF_AREA_STUB) |
2792 | 0 | vty_out(vty, " (Stub%s%s)", |
2793 | 0 | area->no_summary ? ", no summary" : "", |
2794 | 0 | area->shortcut_configured ? "; " : ""); |
2795 | 0 | else if (area->external_routing == OSPF_AREA_NSSA) |
2796 | 0 | vty_out(vty, " (NSSA%s%s)", |
2797 | 0 | area->no_summary ? ", no summary" : "", |
2798 | 0 | area->shortcut_configured ? "; " : ""); |
2799 | |
|
2800 | 0 | vty_out(vty, "\n"); |
2801 | 0 | vty_out(vty, " Shortcutting mode: %s", |
2802 | 0 | ospf_shortcut_mode_descr_str |
2803 | 0 | [area->shortcut_configured]); |
2804 | 0 | vty_out(vty, ", S-bit consensus: %s\n", |
2805 | 0 | area->shortcut_capability ? "ok" : "no"); |
2806 | 0 | } |
2807 | 0 | } |
2808 | | |
2809 | | /* Show number of interfaces */ |
2810 | 0 | if (use_json) { |
2811 | 0 | json_object_int_add(json_area, "areaIfTotalCounter", |
2812 | 0 | listcount(area->oiflist)); |
2813 | 0 | json_object_int_add(json_area, "areaIfActiveCounter", |
2814 | 0 | area->act_ints); |
2815 | 0 | } else |
2816 | 0 | vty_out(vty, |
2817 | 0 | " Number of interfaces in this area: Total: %d, Active: %d\n", |
2818 | 0 | listcount(area->oiflist), area->act_ints); |
2819 | |
|
2820 | 0 | if (area->external_routing == OSPF_AREA_NSSA) { |
2821 | 0 | if (use_json) { |
2822 | 0 | json_object_boolean_true_add(json_area, "nssa"); |
2823 | 0 | if (!IS_OSPF_ABR(area->ospf)) |
2824 | 0 | json_object_boolean_false_add(json_area, "abr"); |
2825 | 0 | else if (area->NSSATranslatorState) { |
2826 | 0 | json_object_boolean_true_add(json_area, "abr"); |
2827 | 0 | if (area->NSSATranslatorRole |
2828 | 0 | == OSPF_NSSA_ROLE_CANDIDATE) |
2829 | 0 | json_object_boolean_true_add( |
2830 | 0 | json_area, |
2831 | 0 | "nssaTranslatorElected"); |
2832 | 0 | else if (area->NSSATranslatorRole |
2833 | 0 | == OSPF_NSSA_ROLE_ALWAYS) |
2834 | 0 | json_object_boolean_true_add( |
2835 | 0 | json_area, |
2836 | 0 | "nssaTranslatorAlways"); |
2837 | 0 | else |
2838 | 0 | json_object_boolean_true_add( |
2839 | 0 | json_area, |
2840 | 0 | "nssaTranslatorNever"); |
2841 | 0 | } else { |
2842 | 0 | json_object_boolean_true_add(json_area, "abr"); |
2843 | 0 | if (area->NSSATranslatorRole |
2844 | 0 | == OSPF_NSSA_ROLE_CANDIDATE) |
2845 | 0 | json_object_boolean_false_add( |
2846 | 0 | json_area, |
2847 | 0 | "nssaTranslatorElected"); |
2848 | 0 | else |
2849 | 0 | json_object_boolean_true_add( |
2850 | 0 | json_area, |
2851 | 0 | "nssaTranslatorNever"); |
2852 | 0 | } |
2853 | 0 | } else { |
2854 | 0 | vty_out(vty, |
2855 | 0 | " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n"); |
2856 | 0 | if (!IS_OSPF_ABR(area->ospf)) |
2857 | 0 | vty_out(vty, |
2858 | 0 | " It is not ABR, therefore not Translator.\n"); |
2859 | 0 | else if (area->NSSATranslatorState) { |
2860 | 0 | vty_out(vty, " We are an ABR and "); |
2861 | 0 | if (area->NSSATranslatorRole |
2862 | 0 | == OSPF_NSSA_ROLE_CANDIDATE) |
2863 | 0 | vty_out(vty, |
2864 | 0 | "the NSSA Elected Translator.\n"); |
2865 | 0 | else if (area->NSSATranslatorRole |
2866 | 0 | == OSPF_NSSA_ROLE_ALWAYS) |
2867 | 0 | vty_out(vty, |
2868 | 0 | "always an NSSA Translator.\n"); |
2869 | 0 | else |
2870 | 0 | vty_out(vty, |
2871 | 0 | "never an NSSA Translator.\n"); |
2872 | 0 | } else { |
2873 | 0 | vty_out(vty, " We are an ABR, but "); |
2874 | 0 | if (area->NSSATranslatorRole |
2875 | 0 | == OSPF_NSSA_ROLE_CANDIDATE) |
2876 | 0 | vty_out(vty, |
2877 | 0 | "not the NSSA Elected Translator.\n"); |
2878 | 0 | else |
2879 | 0 | vty_out(vty, |
2880 | 0 | "never an NSSA Translator.\n"); |
2881 | 0 | } |
2882 | 0 | } |
2883 | 0 | } |
2884 | | |
2885 | | /* Stub-router state for this area */ |
2886 | 0 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { |
2887 | 0 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
2888 | |
|
2889 | 0 | if (use_json) { |
2890 | 0 | json_object_boolean_true_add( |
2891 | 0 | json_area, "originStubMaxDistRouterLsa"); |
2892 | 0 | if (CHECK_FLAG(area->stub_router_state, |
2893 | 0 | OSPF_AREA_ADMIN_STUB_ROUTED)) |
2894 | 0 | json_object_boolean_true_add( |
2895 | 0 | json_area, "indefiniteActiveAdmin"); |
2896 | 0 | if (area->t_stub_router) { |
2897 | 0 | long time_store; |
2898 | 0 | time_store = |
2899 | 0 | monotime_until( |
2900 | 0 | &area->t_stub_router->u.sands, |
2901 | 0 | NULL) |
2902 | 0 | / 1000LL; |
2903 | 0 | json_object_int_add( |
2904 | 0 | json_area, |
2905 | 0 | "activeStartupRemainderMsecs", |
2906 | 0 | time_store); |
2907 | 0 | } |
2908 | 0 | } else { |
2909 | 0 | vty_out(vty, |
2910 | 0 | " Originating stub / maximum-distance Router-LSA\n"); |
2911 | 0 | if (CHECK_FLAG(area->stub_router_state, |
2912 | 0 | OSPF_AREA_ADMIN_STUB_ROUTED)) |
2913 | 0 | vty_out(vty, |
2914 | 0 | " Administratively activated (indefinitely)\n"); |
2915 | 0 | if (area->t_stub_router) |
2916 | 0 | vty_out(vty, |
2917 | 0 | " Active from startup, %s remaining\n", |
2918 | 0 | ospf_timer_dump(area->t_stub_router, |
2919 | 0 | timebuf, |
2920 | 0 | sizeof(timebuf))); |
2921 | 0 | } |
2922 | 0 | } |
2923 | |
|
2924 | 0 | if (use_json) { |
2925 | | /* Show number of fully adjacent neighbors. */ |
2926 | 0 | json_object_int_add(json_area, "nbrFullAdjacentCounter", |
2927 | 0 | area->full_nbrs); |
2928 | | |
2929 | | /* Show authentication type. */ |
2930 | 0 | if (area->auth_type == OSPF_AUTH_NULL) |
2931 | 0 | json_object_string_add(json_area, "authentication", |
2932 | 0 | "authenticationNone"); |
2933 | 0 | else if (area->auth_type == OSPF_AUTH_SIMPLE) |
2934 | 0 | json_object_string_add(json_area, "authentication", |
2935 | 0 | "authenticationSimplePassword"); |
2936 | 0 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) |
2937 | 0 | json_object_string_add(json_area, "authentication", |
2938 | 0 | "authenticationMessageDigest"); |
2939 | |
|
2940 | 0 | if (!OSPF_IS_AREA_BACKBONE(area)) |
2941 | 0 | json_object_int_add(json_area, |
2942 | 0 | "virtualAdjacenciesPassingCounter", |
2943 | 0 | area->full_vls); |
2944 | | |
2945 | | /* Show SPF calculation times. */ |
2946 | 0 | json_object_int_add(json_area, "spfExecutedCounter", |
2947 | 0 | area->spf_calculation); |
2948 | 0 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); |
2949 | 0 | json_object_int_add( |
2950 | 0 | json_area, "lsaRouterNumber", |
2951 | 0 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); |
2952 | 0 | json_object_int_add( |
2953 | 0 | json_area, "lsaRouterChecksum", |
2954 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); |
2955 | 0 | json_object_int_add( |
2956 | 0 | json_area, "lsaNetworkNumber", |
2957 | 0 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); |
2958 | 0 | json_object_int_add( |
2959 | 0 | json_area, "lsaNetworkChecksum", |
2960 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); |
2961 | 0 | json_object_int_add( |
2962 | 0 | json_area, "lsaSummaryNumber", |
2963 | 0 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); |
2964 | 0 | json_object_int_add( |
2965 | 0 | json_area, "lsaSummaryChecksum", |
2966 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); |
2967 | 0 | json_object_int_add( |
2968 | 0 | json_area, "lsaAsbrNumber", |
2969 | 0 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); |
2970 | 0 | json_object_int_add( |
2971 | 0 | json_area, "lsaAsbrChecksum", |
2972 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); |
2973 | 0 | json_object_int_add( |
2974 | 0 | json_area, "lsaNssaNumber", |
2975 | 0 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); |
2976 | 0 | json_object_int_add( |
2977 | 0 | json_area, "lsaNssaChecksum", |
2978 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); |
2979 | 0 | } else { |
2980 | | /* Show number of fully adjacent neighbors. */ |
2981 | 0 | vty_out(vty, |
2982 | 0 | " Number of fully adjacent neighbors in this area: %d\n", |
2983 | 0 | area->full_nbrs); |
2984 | | |
2985 | | /* Show authentication type. */ |
2986 | 0 | vty_out(vty, " Area has "); |
2987 | 0 | if (area->auth_type == OSPF_AUTH_NULL) |
2988 | 0 | vty_out(vty, "no authentication\n"); |
2989 | 0 | else if (area->auth_type == OSPF_AUTH_SIMPLE) |
2990 | 0 | vty_out(vty, "simple password authentication\n"); |
2991 | 0 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) |
2992 | 0 | vty_out(vty, "message digest authentication\n"); |
2993 | |
|
2994 | 0 | if (!OSPF_IS_AREA_BACKBONE(area)) |
2995 | 0 | vty_out(vty, |
2996 | 0 | " Number of full virtual adjacencies going through this area: %d\n", |
2997 | 0 | area->full_vls); |
2998 | | |
2999 | | /* Show SPF calculation times. */ |
3000 | 0 | vty_out(vty, " SPF algorithm executed %d times\n", |
3001 | 0 | area->spf_calculation); |
3002 | | |
3003 | | /* Show number of LSA. */ |
3004 | 0 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); |
3005 | 0 | vty_out(vty, |
3006 | 0 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", |
3007 | 0 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), |
3008 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); |
3009 | 0 | vty_out(vty, |
3010 | 0 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", |
3011 | 0 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), |
3012 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); |
3013 | 0 | vty_out(vty, |
3014 | 0 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", |
3015 | 0 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), |
3016 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); |
3017 | 0 | vty_out(vty, |
3018 | 0 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", |
3019 | 0 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), |
3020 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); |
3021 | 0 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", |
3022 | 0 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), |
3023 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); |
3024 | 0 | } |
3025 | |
|
3026 | 0 | if (use_json) { |
3027 | 0 | json_object_int_add( |
3028 | 0 | json_area, "lsaOpaqueLinkNumber", |
3029 | 0 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); |
3030 | 0 | json_object_int_add( |
3031 | 0 | json_area, "lsaOpaqueLinkChecksum", |
3032 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); |
3033 | 0 | json_object_int_add( |
3034 | 0 | json_area, "lsaOpaqueAreaNumber", |
3035 | 0 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); |
3036 | 0 | json_object_int_add( |
3037 | 0 | json_area, "lsaOpaqueAreaChecksum", |
3038 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); |
3039 | 0 | } else { |
3040 | 0 | vty_out(vty, |
3041 | 0 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", |
3042 | 0 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), |
3043 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); |
3044 | 0 | vty_out(vty, |
3045 | 0 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", |
3046 | 0 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), |
3047 | 0 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); |
3048 | 0 | } |
3049 | |
|
3050 | 0 | if (area->fr_info.configured) { |
3051 | 0 | if (use_json) |
3052 | 0 | json_object_string_add(json_area, "areaFloodReduction", |
3053 | 0 | "configured"); |
3054 | 0 | else |
3055 | 0 | vty_out(vty, " Flood Reduction is configured.\n"); |
3056 | 0 | } |
3057 | |
|
3058 | 0 | if (area->fr_info.enabled) { |
3059 | 0 | if (use_json) { |
3060 | 0 | json_object_boolean_true_add( |
3061 | 0 | json_area, "areaFloodReductionEnabled"); |
3062 | 0 | if (area->fr_info.router_lsas_recv_dc_bit) |
3063 | 0 | json_object_boolean_true_add( |
3064 | 0 | json_area, "lsasRecvDCbitSet"); |
3065 | 0 | if (area->fr_info.area_ind_lsa_recvd) |
3066 | 0 | json_object_string_add(json_area, |
3067 | 0 | "areaIndicationLsaRecv", |
3068 | 0 | "received"); |
3069 | 0 | if (area->fr_info.indication_lsa_self) |
3070 | 0 | json_object_string_addf( |
3071 | 0 | json_area, "areaIndicationLsa", "%pI4", |
3072 | 0 | &area->fr_info.indication_lsa_self->data |
3073 | 0 | ->id); |
3074 | 0 | } else { |
3075 | 0 | vty_out(vty, " Flood Reduction is enabled.\n"); |
3076 | 0 | vty_out(vty, " No of LSAs rcv'd with DC bit set %d\n", |
3077 | 0 | area->fr_info.router_lsas_recv_dc_bit); |
3078 | 0 | if (area->fr_info.area_ind_lsa_recvd) |
3079 | 0 | vty_out(vty, " Ind LSA by other abr.\n"); |
3080 | 0 | if (area->fr_info.indication_lsa_self) |
3081 | 0 | vty_out(vty, " Ind LSA generated %pI4\n", |
3082 | 0 | &area->fr_info.indication_lsa_self->data |
3083 | 0 | ->id); |
3084 | 0 | } |
3085 | 0 | } |
3086 | |
|
3087 | 0 | if (use_json) |
3088 | 0 | json_object_object_add(json_areas, |
3089 | 0 | inet_ntop(AF_INET, &area->area_id, |
3090 | 0 | buf, sizeof(buf)), |
3091 | 0 | json_area); |
3092 | 0 | else |
3093 | 0 | vty_out(vty, "\n"); |
3094 | 0 | } |
3095 | | |
3096 | | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
3097 | | json_object *json, uint8_t use_vrf) |
3098 | 0 | { |
3099 | 0 | struct listnode *node, *nnode; |
3100 | 0 | struct ospf_area *area; |
3101 | 0 | struct timeval result; |
3102 | 0 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
3103 | 0 | json_object *json_vrf = NULL; |
3104 | 0 | json_object *json_areas = NULL; |
3105 | |
|
3106 | 0 | if (json) { |
3107 | 0 | if (use_vrf) |
3108 | 0 | json_vrf = json_object_new_object(); |
3109 | 0 | else |
3110 | 0 | json_vrf = json; |
3111 | 0 | json_areas = json_object_new_object(); |
3112 | 0 | } |
3113 | |
|
3114 | 0 | if (ospf->instance) { |
3115 | 0 | if (json) { |
3116 | 0 | json_object_int_add(json, "ospfInstance", |
3117 | 0 | ospf->instance); |
3118 | 0 | } else { |
3119 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
3120 | 0 | } |
3121 | 0 | } |
3122 | |
|
3123 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3124 | | |
3125 | | /* Show Router ID. */ |
3126 | 0 | if (json) { |
3127 | 0 | json_object_string_addf(json_vrf, "routerId", "%pI4", |
3128 | 0 | &ospf->router_id); |
3129 | 0 | } else { |
3130 | 0 | vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n", |
3131 | 0 | &ospf->router_id); |
3132 | 0 | } |
3133 | | |
3134 | | /* Graceful shutdown */ |
3135 | 0 | if (ospf->t_deferred_shutdown) { |
3136 | 0 | if (json) { |
3137 | 0 | long time_store; |
3138 | 0 | time_store = |
3139 | 0 | monotime_until( |
3140 | 0 | &ospf->t_deferred_shutdown->u.sands, |
3141 | 0 | NULL) |
3142 | 0 | / 1000LL; |
3143 | 0 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
3144 | 0 | time_store); |
3145 | 0 | } else { |
3146 | 0 | vty_out(vty, |
3147 | 0 | " Deferred shutdown in progress, %s remaining\n", |
3148 | 0 | ospf_timer_dump(ospf->t_deferred_shutdown, |
3149 | 0 | timebuf, sizeof(timebuf))); |
3150 | 0 | } |
3151 | 0 | } |
3152 | | |
3153 | | /* Show capability. */ |
3154 | 0 | if (json) { |
3155 | 0 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); |
3156 | 0 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); |
3157 | 0 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
3158 | 0 | json_object_boolean_true_add(json_vrf, |
3159 | 0 | "rfc1583Compatibility"); |
3160 | 0 | } |
3161 | 0 | } else { |
3162 | 0 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); |
3163 | 0 | vty_out(vty, " This implementation conforms to RFC2328\n"); |
3164 | 0 | vty_out(vty, " RFC1583Compatibility flag is %s\n", |
3165 | 0 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) |
3166 | 0 | ? "enabled" |
3167 | 0 | : "disabled"); |
3168 | 0 | } |
3169 | |
|
3170 | 0 | if (json) { |
3171 | 0 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
3172 | 0 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
3173 | 0 | } |
3174 | 0 | } else { |
3175 | 0 | vty_out(vty, " OpaqueCapability flag is %s\n", |
3176 | 0 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) |
3177 | 0 | ? "enabled" |
3178 | 0 | : "disabled"); |
3179 | 0 | } |
3180 | | |
3181 | | /* Show stub-router configuration */ |
3182 | 0 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED |
3183 | 0 | || ospf->stub_router_shutdown_time |
3184 | 0 | != OSPF_STUB_ROUTER_UNCONFIGURED) { |
3185 | 0 | if (json) { |
3186 | 0 | json_object_boolean_true_add(json_vrf, |
3187 | 0 | "stubAdvertisement"); |
3188 | 0 | if (ospf->stub_router_startup_time |
3189 | 0 | != OSPF_STUB_ROUTER_UNCONFIGURED) |
3190 | 0 | json_object_int_add( |
3191 | 0 | json_vrf, "postStartEnabledSecs", |
3192 | 0 | ospf->stub_router_startup_time); |
3193 | 0 | if (ospf->stub_router_shutdown_time |
3194 | 0 | != OSPF_STUB_ROUTER_UNCONFIGURED) |
3195 | 0 | json_object_int_add( |
3196 | 0 | json_vrf, "preShutdownEnabledSecs", |
3197 | 0 | ospf->stub_router_shutdown_time); |
3198 | 0 | } else { |
3199 | 0 | vty_out(vty, |
3200 | 0 | " Stub router advertisement is configured\n"); |
3201 | 0 | if (ospf->stub_router_startup_time |
3202 | 0 | != OSPF_STUB_ROUTER_UNCONFIGURED) |
3203 | 0 | vty_out(vty, |
3204 | 0 | " Enabled for %us after start-up\n", |
3205 | 0 | ospf->stub_router_startup_time); |
3206 | 0 | if (ospf->stub_router_shutdown_time |
3207 | 0 | != OSPF_STUB_ROUTER_UNCONFIGURED) |
3208 | 0 | vty_out(vty, |
3209 | 0 | " Enabled for %us prior to full shutdown\n", |
3210 | 0 | ospf->stub_router_shutdown_time); |
3211 | 0 | } |
3212 | 0 | } |
3213 | | |
3214 | | /* Show SPF timers. */ |
3215 | 0 | if (json) { |
3216 | 0 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", |
3217 | 0 | ospf->spf_delay); |
3218 | 0 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
3219 | 0 | ospf->spf_holdtime); |
3220 | 0 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
3221 | 0 | ospf->spf_max_holdtime); |
3222 | 0 | json_object_int_add(json_vrf, "holdtimeMultplier", |
3223 | 0 | ospf->spf_hold_multiplier); |
3224 | 0 | } else { |
3225 | 0 | vty_out(vty, |
3226 | 0 | " Initial SPF scheduling delay %d millisec(s)\n" |
3227 | 0 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" |
3228 | 0 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" |
3229 | 0 | " Hold time multiplier is currently %d\n", |
3230 | 0 | ospf->spf_delay, ospf->spf_holdtime, |
3231 | 0 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); |
3232 | 0 | } |
3233 | |
|
3234 | 0 | if (json) { |
3235 | 0 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3236 | 0 | long time_store = 0; |
3237 | |
|
3238 | 0 | time_store = |
3239 | 0 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; |
3240 | 0 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
3241 | 0 | time_store); |
3242 | |
|
3243 | 0 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) |
3244 | 0 | + (ospf->ts_spf_duration.tv_usec / 1000); |
3245 | 0 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
3246 | 0 | time_store); |
3247 | 0 | } else |
3248 | 0 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
3249 | 0 | } else { |
3250 | 0 | vty_out(vty, " SPF algorithm "); |
3251 | 0 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3252 | 0 | monotime_since(&ospf->ts_spf, &result); |
3253 | 0 | vty_out(vty, "last executed %s ago\n", |
3254 | 0 | ospf_timeval_dump(&result, timebuf, |
3255 | 0 | sizeof(timebuf))); |
3256 | 0 | vty_out(vty, " Last SPF duration %s\n", |
3257 | 0 | ospf_timeval_dump(&ospf->ts_spf_duration, |
3258 | 0 | timebuf, sizeof(timebuf))); |
3259 | 0 | } else |
3260 | 0 | vty_out(vty, "has not been run\n"); |
3261 | 0 | } |
3262 | |
|
3263 | 0 | if (json) { |
3264 | 0 | if (ospf->t_spf_calc) { |
3265 | 0 | long time_store; |
3266 | 0 | time_store = |
3267 | 0 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) |
3268 | 0 | / 1000LL; |
3269 | 0 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
3270 | 0 | time_store); |
3271 | 0 | } |
3272 | |
|
3273 | 0 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
3274 | 0 | ospf->min_ls_interval); |
3275 | 0 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
3276 | 0 | ospf->min_ls_arrival); |
3277 | | /* Show write multiplier values */ |
3278 | 0 | json_object_int_add(json_vrf, "writeMultiplier", |
3279 | 0 | ospf->write_oi_count); |
3280 | | /* Show refresh parameters. */ |
3281 | 0 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
3282 | 0 | ospf->lsa_refresh_interval * 1000); |
3283 | | |
3284 | | /* show max multipath */ |
3285 | 0 | json_object_int_add(json_vrf, "maximumPaths", |
3286 | 0 | ospf->max_multipath); |
3287 | | |
3288 | | /* show administrative distance */ |
3289 | 0 | json_object_int_add(json_vrf, "preference", |
3290 | 0 | ospf->distance_all |
3291 | 0 | ? ospf->distance_all |
3292 | 0 | : ZEBRA_OSPF_DISTANCE_DEFAULT); |
3293 | 0 | } else { |
3294 | 0 | vty_out(vty, " SPF timer %s%s\n", |
3295 | 0 | (ospf->t_spf_calc ? "due in " : "is "), |
3296 | 0 | ospf_timer_dump(ospf->t_spf_calc, timebuf, |
3297 | 0 | sizeof(timebuf))); |
3298 | |
|
3299 | 0 | vty_out(vty, " LSA minimum interval %d msecs\n", |
3300 | 0 | ospf->min_ls_interval); |
3301 | 0 | vty_out(vty, " LSA minimum arrival %d msecs\n", |
3302 | 0 | ospf->min_ls_arrival); |
3303 | | |
3304 | | /* Show write multiplier values */ |
3305 | 0 | vty_out(vty, " Write Multiplier set to %d \n", |
3306 | 0 | ospf->write_oi_count); |
3307 | | |
3308 | | /* Show refresh parameters. */ |
3309 | 0 | vty_out(vty, " Refresh timer %d secs\n", |
3310 | 0 | ospf->lsa_refresh_interval); |
3311 | | |
3312 | | /* show max multipath */ |
3313 | 0 | vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n", |
3314 | 0 | ospf->max_multipath); |
3315 | | |
3316 | | /* show administrative distance */ |
3317 | 0 | vty_out(vty, " Administrative distance %u\n", |
3318 | 0 | ospf->distance_all ? ospf->distance_all |
3319 | 0 | : ZEBRA_OSPF_DISTANCE_DEFAULT); |
3320 | 0 | } |
3321 | |
|
3322 | 0 | if (ospf->fr_configured) { |
3323 | 0 | if (json) |
3324 | 0 | json_object_string_add(json_vrf, "floodReduction", |
3325 | 0 | "configured"); |
3326 | 0 | else |
3327 | 0 | vty_out(vty, " Flood Reduction is configured.\n"); |
3328 | 0 | } |
3329 | | |
3330 | | /* Show ABR/ASBR flags. */ |
3331 | 0 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { |
3332 | 0 | if (json) |
3333 | 0 | json_object_string_add( |
3334 | 0 | json_vrf, "abrType", |
3335 | 0 | ospf_abr_type_descr_str[ospf->abr_type]); |
3336 | 0 | else |
3337 | 0 | vty_out(vty, |
3338 | 0 | " This router is an ABR, ABR type is: %s\n", |
3339 | 0 | ospf_abr_type_descr_str[ospf->abr_type]); |
3340 | 0 | } |
3341 | 0 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { |
3342 | 0 | if (json) |
3343 | 0 | json_object_string_add( |
3344 | 0 | json_vrf, "asbrRouter", |
3345 | 0 | "injectingExternalRoutingInformation"); |
3346 | 0 | else |
3347 | 0 | vty_out(vty, |
3348 | 0 | " This router is an ASBR (injecting external routing information)\n"); |
3349 | 0 | } |
3350 | | |
3351 | | /* Show Number of AS-external-LSAs. */ |
3352 | 0 | if (json) { |
3353 | 0 | json_object_int_add( |
3354 | 0 | json_vrf, "lsaExternalCounter", |
3355 | 0 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3356 | 0 | json_object_int_add( |
3357 | 0 | json_vrf, "lsaExternalChecksum", |
3358 | 0 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3359 | 0 | } else { |
3360 | 0 | vty_out(vty, |
3361 | 0 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", |
3362 | 0 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), |
3363 | 0 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3364 | 0 | } |
3365 | |
|
3366 | 0 | if (json) { |
3367 | 0 | json_object_int_add( |
3368 | 0 | json_vrf, "lsaAsopaqueCounter", |
3369 | 0 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3370 | 0 | json_object_int_add( |
3371 | 0 | json_vrf, "lsaAsOpaqueChecksum", |
3372 | 0 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3373 | 0 | } else { |
3374 | 0 | vty_out(vty, |
3375 | 0 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", |
3376 | 0 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), |
3377 | 0 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3378 | 0 | } |
3379 | | |
3380 | | /* Show number of areas attached. */ |
3381 | 0 | if (json) |
3382 | 0 | json_object_int_add(json_vrf, "attachedAreaCounter", |
3383 | 0 | listcount(ospf->areas)); |
3384 | 0 | else |
3385 | 0 | vty_out(vty, " Number of areas attached to this router: %d\n", |
3386 | 0 | listcount(ospf->areas)); |
3387 | |
|
3388 | 0 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { |
3389 | 0 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { |
3390 | 0 | if (json) |
3391 | 0 | json_object_boolean_true_add( |
3392 | 0 | json_vrf, "adjacencyChangesLoggedAll"); |
3393 | 0 | else |
3394 | 0 | vty_out(vty, |
3395 | 0 | " All adjacency changes are logged\n"); |
3396 | 0 | } else { |
3397 | 0 | if (json) |
3398 | 0 | json_object_boolean_true_add( |
3399 | 0 | json_vrf, "adjacencyChangesLogged"); |
3400 | 0 | else |
3401 | 0 | vty_out(vty, " Adjacency changes are logged\n"); |
3402 | 0 | } |
3403 | 0 | } |
3404 | | |
3405 | | /* show LDP-Sync status */ |
3406 | 0 | ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0); |
3407 | | |
3408 | | /* Socket buffer sizes */ |
3409 | 0 | if (json) { |
3410 | 0 | if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE) |
3411 | 0 | json_object_int_add(json_vrf, "recvSockBufsize", |
3412 | 0 | ospf->recv_sock_bufsize); |
3413 | 0 | if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE) |
3414 | 0 | json_object_int_add(json_vrf, "sendSockBufsize", |
3415 | 0 | ospf->send_sock_bufsize); |
3416 | 0 | } else { |
3417 | 0 | if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE) |
3418 | 0 | vty_out(vty, " Receive socket bufsize: %u\n", |
3419 | 0 | ospf->recv_sock_bufsize); |
3420 | 0 | if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE) |
3421 | 0 | vty_out(vty, " Send socket bufsize: %u\n", |
3422 | 0 | ospf->send_sock_bufsize); |
3423 | 0 | } |
3424 | | |
3425 | | /* Show each area status. */ |
3426 | 0 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) |
3427 | 0 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3428 | |
|
3429 | 0 | if (json) { |
3430 | 0 | if (use_vrf) { |
3431 | 0 | json_object_object_add(json_vrf, "areas", json_areas); |
3432 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
3433 | 0 | json_vrf); |
3434 | 0 | } else { |
3435 | 0 | json_object_object_add(json, "areas", json_areas); |
3436 | 0 | } |
3437 | 0 | } else |
3438 | 0 | vty_out(vty, "\n"); |
3439 | |
|
3440 | 0 | return CMD_SUCCESS; |
3441 | 0 | } |
3442 | | |
3443 | | DEFUN (show_ip_ospf, |
3444 | | show_ip_ospf_cmd, |
3445 | | "show ip ospf [vrf <NAME|all>] [json]", |
3446 | | SHOW_STR |
3447 | | IP_STR |
3448 | | "OSPF information\n" |
3449 | | VRF_CMD_HELP_STR |
3450 | | "All VRFs\n" |
3451 | | JSON_STR) |
3452 | 0 | { |
3453 | 0 | struct ospf *ospf; |
3454 | 0 | bool uj = use_json(argc, argv); |
3455 | 0 | struct listnode *node = NULL; |
3456 | 0 | char *vrf_name = NULL; |
3457 | 0 | bool all_vrf = false; |
3458 | 0 | int ret = CMD_SUCCESS; |
3459 | 0 | int inst = 0; |
3460 | 0 | int idx_vrf = 0; |
3461 | 0 | json_object *json = NULL; |
3462 | 0 | uint8_t use_vrf = 0; |
3463 | |
|
3464 | 0 | if (listcount(om->ospf) == 0) |
3465 | 0 | return CMD_SUCCESS; |
3466 | | |
3467 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
3468 | |
|
3469 | 0 | if (uj) |
3470 | 0 | json = json_object_new_object(); |
3471 | | |
3472 | | /* vrf input is provided could be all or specific vrf*/ |
3473 | 0 | if (vrf_name) { |
3474 | 0 | bool ospf_output = false; |
3475 | |
|
3476 | 0 | use_vrf = 1; |
3477 | |
|
3478 | 0 | if (all_vrf) { |
3479 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
3480 | 0 | if (!ospf->oi_running) |
3481 | 0 | continue; |
3482 | 0 | ospf_output = true; |
3483 | 0 | ret = show_ip_ospf_common(vty, ospf, json, |
3484 | 0 | use_vrf); |
3485 | 0 | } |
3486 | 0 | if (uj) |
3487 | 0 | vty_json(vty, json); |
3488 | 0 | else if (!ospf_output) |
3489 | 0 | vty_out(vty, "%% OSPF is not enabled\n"); |
3490 | 0 | return ret; |
3491 | 0 | } |
3492 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
3493 | 0 | if ((ospf == NULL) || !ospf->oi_running) { |
3494 | 0 | if (uj) |
3495 | 0 | vty_json(vty, json); |
3496 | 0 | else |
3497 | 0 | vty_out(vty, |
3498 | 0 | "%% OSPF is not enabled in vrf %s\n", |
3499 | 0 | vrf_name); |
3500 | |
|
3501 | 0 | return CMD_SUCCESS; |
3502 | 0 | } |
3503 | 0 | } else { |
3504 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
3505 | | /* Display default ospf (instance 0) info */ |
3506 | 0 | if (ospf == NULL || !ospf->oi_running) { |
3507 | 0 | if (uj) |
3508 | 0 | vty_json(vty, json); |
3509 | 0 | else |
3510 | 0 | vty_out(vty, |
3511 | 0 | "%% OSPF is not enabled in vrf default\n"); |
3512 | |
|
3513 | 0 | return CMD_SUCCESS; |
3514 | 0 | } |
3515 | 0 | } |
3516 | | |
3517 | 0 | if (ospf) { |
3518 | 0 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3519 | 0 | if (uj) |
3520 | 0 | vty_out(vty, "%s\n", |
3521 | 0 | json_object_to_json_string_ext( |
3522 | 0 | json, JSON_C_TO_STRING_PRETTY)); |
3523 | 0 | } |
3524 | |
|
3525 | 0 | if (uj) |
3526 | 0 | json_object_free(json); |
3527 | |
|
3528 | 0 | return ret; |
3529 | 0 | } |
3530 | | |
3531 | | DEFUN (show_ip_ospf_instance, |
3532 | | show_ip_ospf_instance_cmd, |
3533 | | "show ip ospf (1-65535) [json]", |
3534 | | SHOW_STR |
3535 | | IP_STR |
3536 | | "OSPF information\n" |
3537 | | "Instance ID\n" |
3538 | | JSON_STR) |
3539 | 0 | { |
3540 | 0 | int idx_number = 3; |
3541 | 0 | struct ospf *ospf; |
3542 | 0 | unsigned short instance = 0; |
3543 | 0 | bool uj = use_json(argc, argv); |
3544 | 0 | int ret = CMD_SUCCESS; |
3545 | 0 | json_object *json = NULL; |
3546 | |
|
3547 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
3548 | 0 | if (instance != ospf_instance) |
3549 | 0 | return CMD_NOT_MY_INSTANCE; |
3550 | | |
3551 | 0 | ospf = ospf_lookup_instance(instance); |
3552 | 0 | if (!ospf || !ospf->oi_running) |
3553 | 0 | return CMD_SUCCESS; |
3554 | | |
3555 | 0 | if (uj) |
3556 | 0 | json = json_object_new_object(); |
3557 | |
|
3558 | 0 | ret = show_ip_ospf_common(vty, ospf, json, 0); |
3559 | |
|
3560 | 0 | if (uj) |
3561 | 0 | vty_json(vty, json); |
3562 | |
|
3563 | 0 | return ret; |
3564 | 0 | } |
3565 | | |
3566 | | static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi, |
3567 | | json_object *json, bool use_json) |
3568 | 0 | { |
3569 | 0 | int auth_type; |
3570 | |
|
3571 | 0 | auth_type = OSPF_IF_PARAM(oi, auth_type); |
3572 | |
|
3573 | 0 | switch (auth_type) { |
3574 | 0 | case OSPF_AUTH_NULL: |
3575 | 0 | if (use_json) |
3576 | 0 | json_object_string_add(json, "authentication", |
3577 | 0 | "authenticationNone"); |
3578 | 0 | else |
3579 | 0 | vty_out(vty, " Authentication NULL is enabled\n"); |
3580 | 0 | break; |
3581 | 0 | case OSPF_AUTH_SIMPLE: { |
3582 | 0 | if (use_json) |
3583 | 0 | json_object_string_add(json, "authentication", |
3584 | 0 | "authenticationSimplePassword"); |
3585 | 0 | else |
3586 | 0 | vty_out(vty, |
3587 | 0 | " Simple password authentication enabled\n"); |
3588 | 0 | break; |
3589 | 0 | } |
3590 | 0 | case OSPF_AUTH_CRYPTOGRAPHIC: { |
3591 | 0 | struct crypt_key *ckey; |
3592 | |
|
3593 | 0 | if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) |
3594 | 0 | return; |
3595 | | |
3596 | 0 | ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); |
3597 | 0 | if (ckey) { |
3598 | 0 | if (use_json) { |
3599 | 0 | json_object_string_add(json, "authentication", |
3600 | 0 | "authenticationMessageDigest"); |
3601 | 0 | } else { |
3602 | 0 | vty_out(vty, |
3603 | 0 | " Cryptographic authentication enabled\n"); |
3604 | 0 | vty_out(vty, " Algorithm:MD5\n"); |
3605 | 0 | } |
3606 | 0 | } |
3607 | 0 | break; |
3608 | 0 | } |
3609 | 0 | default: |
3610 | 0 | break; |
3611 | 0 | } |
3612 | 0 | } |
3613 | | |
3614 | | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, |
3615 | | struct interface *ifp, |
3616 | | json_object *json_interface_sub, |
3617 | | bool use_json) |
3618 | 0 | { |
3619 | 0 | int is_up; |
3620 | 0 | struct ospf_neighbor *nbr; |
3621 | 0 | struct route_node *rn; |
3622 | 0 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; |
3623 | 0 | struct ospf_if_params *params; |
3624 | | |
3625 | | /* Is interface up? */ |
3626 | 0 | if (use_json) { |
3627 | 0 | is_up = if_is_operative(ifp); |
3628 | 0 | if (is_up) |
3629 | 0 | json_object_boolean_true_add(json_interface_sub, |
3630 | 0 | "ifUp"); |
3631 | 0 | else |
3632 | 0 | json_object_boolean_false_add(json_interface_sub, |
3633 | 0 | "ifDown"); |
3634 | |
|
3635 | 0 | json_object_int_add(json_interface_sub, "ifIndex", |
3636 | 0 | ifp->ifindex); |
3637 | 0 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); |
3638 | 0 | json_object_int_add(json_interface_sub, "bandwidthMbit", |
3639 | 0 | bandwidth); |
3640 | 0 | json_object_string_add(json_interface_sub, "ifFlags", |
3641 | 0 | if_flag_dump(ifp->flags)); |
3642 | 0 | } else { |
3643 | 0 | vty_out(vty, "%s is %s\n", ifp->name, |
3644 | 0 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); |
3645 | 0 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", |
3646 | 0 | ifp->ifindex, ifp->mtu, bandwidth, |
3647 | 0 | if_flag_dump(ifp->flags)); |
3648 | 0 | } |
3649 | | |
3650 | | /* Is interface OSPF enabled? */ |
3651 | 0 | if (use_json) { |
3652 | 0 | if (ospf_oi_count(ifp) == 0) { |
3653 | 0 | json_object_boolean_false_add(json_interface_sub, |
3654 | 0 | "ospfEnabled"); |
3655 | 0 | return; |
3656 | 0 | } else if (!is_up) { |
3657 | 0 | json_object_boolean_false_add(json_interface_sub, |
3658 | 0 | "ospfRunning"); |
3659 | 0 | return; |
3660 | 0 | } else |
3661 | 0 | json_object_boolean_true_add(json_interface_sub, |
3662 | 0 | "ospfEnabled"); |
3663 | 0 | } else { |
3664 | 0 | if (ospf_oi_count(ifp) == 0) { |
3665 | 0 | vty_out(vty, " OSPF not enabled on this interface\n"); |
3666 | 0 | return; |
3667 | 0 | } else if (!is_up) { |
3668 | 0 | vty_out(vty, |
3669 | 0 | " OSPF is enabled, but not running on this interface\n"); |
3670 | 0 | return; |
3671 | 0 | } |
3672 | 0 | } |
3673 | | |
3674 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
3675 | 0 | struct ospf_interface *oi = rn->info; |
3676 | |
|
3677 | 0 | if (oi == NULL) |
3678 | 0 | continue; |
3679 | | |
3680 | 0 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { |
3681 | 0 | if (use_json) |
3682 | 0 | json_object_boolean_true_add(json_interface_sub, |
3683 | 0 | "ifUnnumbered"); |
3684 | 0 | else |
3685 | 0 | vty_out(vty, " This interface is UNNUMBERED,"); |
3686 | 0 | } else { |
3687 | 0 | struct in_addr dest; |
3688 | 0 | const char *dstr; |
3689 | | |
3690 | | /* Show OSPF interface information. */ |
3691 | 0 | if (use_json) { |
3692 | 0 | json_object_string_addf( |
3693 | 0 | json_interface_sub, "ipAddress", "%pI4", |
3694 | 0 | &oi->address->u.prefix4); |
3695 | 0 | json_object_int_add(json_interface_sub, |
3696 | 0 | "ipAddressPrefixlen", |
3697 | 0 | oi->address->prefixlen); |
3698 | 0 | } else |
3699 | 0 | vty_out(vty, " Internet Address %pFX,", |
3700 | 0 | oi->address); |
3701 | | |
3702 | | /* For Vlinks, showing the peer address is |
3703 | | * probably more informative than the local |
3704 | | * interface that is being used */ |
3705 | 0 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { |
3706 | 0 | dstr = "Peer"; |
3707 | 0 | dest = oi->vl_data->peer_addr; |
3708 | 0 | } else if (CONNECTED_PEER(oi->connected) |
3709 | 0 | && oi->connected->destination) { |
3710 | 0 | dstr = "Peer"; |
3711 | 0 | dest = oi->connected->destination->u.prefix4; |
3712 | 0 | } else { |
3713 | 0 | dstr = "Broadcast"; |
3714 | 0 | dest.s_addr = ipv4_broadcast_addr( |
3715 | 0 | oi->connected->address->u.prefix4.s_addr, |
3716 | 0 | oi->connected->address->prefixlen); |
3717 | 0 | } |
3718 | |
|
3719 | 0 | if (use_json) { |
3720 | 0 | json_object_string_add( |
3721 | 0 | json_interface_sub, |
3722 | 0 | "ospfIfType", dstr); |
3723 | 0 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
3724 | 0 | json_object_string_addf( |
3725 | 0 | json_interface_sub, "vlinkPeer", |
3726 | 0 | "%pI4", &dest); |
3727 | 0 | else |
3728 | 0 | json_object_string_addf( |
3729 | 0 | json_interface_sub, |
3730 | 0 | "localIfUsed", "%pI4", &dest); |
3731 | 0 | } else |
3732 | 0 | vty_out(vty, " %s %pI4,", dstr, |
3733 | 0 | &dest); |
3734 | 0 | } |
3735 | 0 | if (use_json) { |
3736 | 0 | json_object_string_add(json_interface_sub, "area", |
3737 | 0 | ospf_area_desc_string(oi->area)); |
3738 | 0 | if (OSPF_IF_PARAM(oi, mtu_ignore)) |
3739 | 0 | json_object_boolean_true_add( |
3740 | 0 | json_interface_sub, |
3741 | 0 | "mtuMismatchDetect"); |
3742 | 0 | json_object_string_addf(json_interface_sub, "routerId", |
3743 | 0 | "%pI4", &ospf->router_id); |
3744 | 0 | json_object_string_add(json_interface_sub, |
3745 | 0 | "networkType", |
3746 | 0 | ospf_network_type_str[oi->type]); |
3747 | 0 | json_object_int_add(json_interface_sub, "cost", |
3748 | 0 | oi->output_cost); |
3749 | 0 | json_object_int_add( |
3750 | 0 | json_interface_sub, "transmitDelaySecs", |
3751 | 0 | OSPF_IF_PARAM(oi, transmit_delay)); |
3752 | 0 | json_object_string_add(json_interface_sub, "state", |
3753 | 0 | lookup_msg(ospf_ism_state_msg, |
3754 | 0 | oi->state, NULL)); |
3755 | 0 | json_object_int_add(json_interface_sub, "priority", |
3756 | 0 | PRIORITY(oi)); |
3757 | 0 | } else { |
3758 | 0 | vty_out(vty, " Area %s\n", |
3759 | 0 | ospf_area_desc_string(oi->area)); |
3760 | |
|
3761 | 0 | vty_out(vty, " MTU mismatch detection: %s\n", |
3762 | 0 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" |
3763 | 0 | : "enabled"); |
3764 | |
|
3765 | 0 | vty_out(vty, |
3766 | 0 | " Router ID %pI4, Network Type %s, Cost: %d\n", |
3767 | 0 | &ospf->router_id, |
3768 | 0 | ospf_network_type_str[oi->type], |
3769 | 0 | oi->output_cost); |
3770 | |
|
3771 | 0 | vty_out(vty, |
3772 | 0 | " Transmit Delay is %d sec, State %s, Priority %d\n", |
3773 | 0 | OSPF_IF_PARAM(oi, transmit_delay), |
3774 | 0 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), |
3775 | 0 | PRIORITY(oi)); |
3776 | 0 | } |
3777 | | |
3778 | | /* Show DR information. */ |
3779 | 0 | if (DR(oi).s_addr == INADDR_ANY) { |
3780 | 0 | if (!use_json) |
3781 | 0 | vty_out(vty, |
3782 | 0 | " No backup designated router on this network\n"); |
3783 | 0 | } else { |
3784 | 0 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi)); |
3785 | 0 | if (nbr) { |
3786 | 0 | if (use_json) { |
3787 | 0 | json_object_string_addf( |
3788 | 0 | json_interface_sub, "drId", |
3789 | 0 | "%pI4", &nbr->router_id); |
3790 | 0 | json_object_string_addf( |
3791 | 0 | json_interface_sub, "drAddress", |
3792 | 0 | "%pI4", |
3793 | 0 | &nbr->address.u.prefix4); |
3794 | 0 | } else { |
3795 | 0 | vty_out(vty, |
3796 | 0 | " Designated Router (ID) %pI4", |
3797 | 0 | &nbr->router_id); |
3798 | 0 | vty_out(vty, |
3799 | 0 | " Interface Address %pFX\n", |
3800 | 0 | &nbr->address); |
3801 | 0 | } |
3802 | 0 | } |
3803 | 0 | nbr = NULL; |
3804 | |
|
3805 | 0 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); |
3806 | 0 | if (nbr == NULL) { |
3807 | 0 | if (!use_json) |
3808 | 0 | vty_out(vty, |
3809 | 0 | " No backup designated router on this network\n"); |
3810 | 0 | } else { |
3811 | 0 | if (use_json) { |
3812 | 0 | json_object_string_addf( |
3813 | 0 | json_interface_sub, "bdrId", |
3814 | 0 | "%pI4", &nbr->router_id); |
3815 | 0 | json_object_string_addf( |
3816 | 0 | json_interface_sub, |
3817 | 0 | "bdrAddress", "%pI4", |
3818 | 0 | &nbr->address.u.prefix4); |
3819 | 0 | } else { |
3820 | 0 | vty_out(vty, |
3821 | 0 | " Backup Designated Router (ID) %pI4,", |
3822 | 0 | &nbr->router_id); |
3823 | 0 | vty_out(vty, " Interface Address %pI4\n", |
3824 | 0 | &nbr->address.u.prefix4); |
3825 | 0 | } |
3826 | 0 | } |
3827 | 0 | } |
3828 | | |
3829 | | /* Next network-LSA sequence number we'll use, if we're elected |
3830 | | * DR */ |
3831 | 0 | if (oi->params |
3832 | 0 | && ntohl(oi->params->network_lsa_seqnum) |
3833 | 0 | != OSPF_INITIAL_SEQUENCE_NUMBER) { |
3834 | 0 | if (use_json) |
3835 | 0 | json_object_int_add( |
3836 | 0 | json_interface_sub, |
3837 | 0 | "networkLsaSequence", |
3838 | 0 | ntohl(oi->params->network_lsa_seqnum)); |
3839 | 0 | else |
3840 | 0 | vty_out(vty, |
3841 | 0 | " Saved Network-LSA sequence number 0x%x\n", |
3842 | 0 | ntohl(oi->params->network_lsa_seqnum)); |
3843 | 0 | } |
3844 | |
|
3845 | 0 | if (use_json) { |
3846 | 0 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) |
3847 | 0 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { |
3848 | 0 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) |
3849 | 0 | json_object_boolean_true_add( |
3850 | 0 | json_interface_sub, |
3851 | 0 | "mcastMemberOspfAllRouters"); |
3852 | 0 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) |
3853 | 0 | json_object_boolean_true_add( |
3854 | 0 | json_interface_sub, |
3855 | 0 | "mcastMemberOspfDesignatedRouters"); |
3856 | 0 | } |
3857 | 0 | } else { |
3858 | 0 | vty_out(vty, " Multicast group memberships:"); |
3859 | 0 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) |
3860 | 0 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { |
3861 | 0 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) |
3862 | 0 | vty_out(vty, " OSPFAllRouters"); |
3863 | 0 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) |
3864 | 0 | vty_out(vty, " OSPFDesignatedRouters"); |
3865 | 0 | } else |
3866 | 0 | vty_out(vty, " <None>"); |
3867 | 0 | vty_out(vty, "\n"); |
3868 | 0 | } |
3869 | |
|
3870 | 0 | if (use_json) { |
3871 | 0 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) |
3872 | 0 | json_object_int_add( |
3873 | 0 | json_interface_sub, "timerMsecs", |
3874 | 0 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
3875 | 0 | else |
3876 | 0 | json_object_int_add( |
3877 | 0 | json_interface_sub, "timerMsecs", |
3878 | 0 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
3879 | 0 | json_object_int_add(json_interface_sub, |
3880 | 0 | "timerDeadSecs", |
3881 | 0 | OSPF_IF_PARAM(oi, v_wait)); |
3882 | 0 | json_object_int_add(json_interface_sub, |
3883 | 0 | "timerWaitSecs", |
3884 | 0 | OSPF_IF_PARAM(oi, v_wait)); |
3885 | 0 | json_object_int_add( |
3886 | 0 | json_interface_sub, "timerRetransmitSecs", |
3887 | 0 | OSPF_IF_PARAM(oi, retransmit_interval)); |
3888 | 0 | } else { |
3889 | 0 | vty_out(vty, " Timer intervals configured,"); |
3890 | 0 | vty_out(vty, " Hello "); |
3891 | 0 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) |
3892 | 0 | vty_out(vty, "%ds,", |
3893 | 0 | OSPF_IF_PARAM(oi, v_hello)); |
3894 | 0 | else |
3895 | 0 | vty_out(vty, "%dms,", |
3896 | 0 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
3897 | 0 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", |
3898 | 0 | OSPF_IF_PARAM(oi, v_wait), |
3899 | 0 | OSPF_IF_PARAM(oi, v_wait), |
3900 | 0 | OSPF_IF_PARAM(oi, retransmit_interval)); |
3901 | 0 | } |
3902 | |
|
3903 | 0 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { |
3904 | 0 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
3905 | 0 | if (use_json) { |
3906 | 0 | long time_store = 0; |
3907 | 0 | if (oi->t_hello) |
3908 | 0 | time_store = |
3909 | 0 | monotime_until( |
3910 | 0 | &oi->t_hello->u.sands, |
3911 | 0 | NULL) |
3912 | 0 | / 1000LL; |
3913 | 0 | json_object_int_add(json_interface_sub, |
3914 | 0 | "timerHelloInMsecs", |
3915 | 0 | time_store); |
3916 | 0 | } else |
3917 | 0 | vty_out(vty, " Hello due in %s\n", |
3918 | 0 | ospf_timer_dump(oi->t_hello, timebuf, |
3919 | 0 | sizeof(timebuf))); |
3920 | 0 | } else /* passive-interface is set */ |
3921 | 0 | { |
3922 | 0 | if (use_json) |
3923 | 0 | json_object_boolean_true_add( |
3924 | 0 | json_interface_sub, |
3925 | 0 | "timerPassiveIface"); |
3926 | 0 | else |
3927 | 0 | vty_out(vty, |
3928 | 0 | " No Hellos (Passive interface)\n"); |
3929 | 0 | } |
3930 | |
|
3931 | 0 | if (use_json) { |
3932 | 0 | json_object_int_add(json_interface_sub, "nbrCount", |
3933 | 0 | ospf_nbr_count(oi, 0)); |
3934 | 0 | json_object_int_add(json_interface_sub, |
3935 | 0 | "nbrAdjacentCount", |
3936 | 0 | ospf_nbr_count(oi, NSM_Full)); |
3937 | 0 | } else |
3938 | 0 | vty_out(vty, |
3939 | 0 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", |
3940 | 0 | ospf_nbr_count(oi, 0), |
3941 | 0 | ospf_nbr_count(oi, NSM_Full)); |
3942 | | |
3943 | |
|
3944 | 0 | params = IF_DEF_PARAMS(ifp); |
3945 | 0 | if (params && |
3946 | 0 | OSPF_IF_PARAM_CONFIGURED(params, v_gr_hello_delay)) { |
3947 | 0 | if (use_json) { |
3948 | 0 | json_object_int_add(json_interface_sub, |
3949 | 0 | "grHelloDelaySecs", |
3950 | 0 | params->v_gr_hello_delay); |
3951 | 0 | } else |
3952 | 0 | vty_out(vty, |
3953 | 0 | " Graceful Restart hello delay: %us\n", |
3954 | 0 | params->v_gr_hello_delay); |
3955 | 0 | } |
3956 | |
|
3957 | 0 | ospf_interface_bfd_show(vty, ifp, json_interface_sub); |
3958 | | |
3959 | | /* OSPF Authentication information */ |
3960 | 0 | ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); |
3961 | 0 | if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT) { |
3962 | 0 | if (use_json) |
3963 | 0 | json_object_boolean_add(json_interface_sub, |
3964 | 0 | "p2mpDelayReflood", |
3965 | 0 | oi->p2mp_delay_reflood); |
3966 | 0 | else |
3967 | 0 | vty_out(vty, |
3968 | 0 | " %sDelay reflooding LSAs received on P2MP interface\n", |
3969 | 0 | oi->p2mp_delay_reflood ? "" : "Don't "); |
3970 | 0 | } |
3971 | 0 | } |
3972 | 0 | } |
3973 | | |
3974 | | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
3975 | | char *intf_name, uint8_t use_vrf, |
3976 | | json_object *json, bool use_json) |
3977 | 0 | { |
3978 | 0 | struct interface *ifp; |
3979 | 0 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
3980 | 0 | json_object *json_vrf = NULL; |
3981 | 0 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
3982 | |
|
3983 | 0 | if (use_json) { |
3984 | 0 | if (use_vrf) |
3985 | 0 | json_vrf = json_object_new_object(); |
3986 | 0 | else |
3987 | 0 | json_vrf = json; |
3988 | 0 | json_interface = json_object_new_object(); |
3989 | 0 | } |
3990 | |
|
3991 | 0 | if (ospf->instance) { |
3992 | 0 | if (use_json) |
3993 | 0 | json_object_int_add(json, "ospfInstance", |
3994 | 0 | ospf->instance); |
3995 | 0 | else |
3996 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
3997 | 0 | } |
3998 | |
|
3999 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4000 | |
|
4001 | 0 | if (intf_name == NULL) { |
4002 | | /* Show All Interfaces.*/ |
4003 | 0 | FOR_ALL_INTERFACES (vrf, ifp) { |
4004 | 0 | if (ospf_oi_count(ifp)) { |
4005 | 0 | if (use_json) { |
4006 | 0 | json_interface_sub = |
4007 | 0 | json_object_new_object(); |
4008 | 0 | } |
4009 | 0 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
4010 | 0 | json_interface_sub, |
4011 | 0 | use_json); |
4012 | |
|
4013 | 0 | if (use_json) { |
4014 | 0 | json_object_object_add( |
4015 | 0 | json_interface, ifp->name, |
4016 | 0 | json_interface_sub); |
4017 | 0 | } |
4018 | 0 | } |
4019 | 0 | } |
4020 | 0 | if (use_json) |
4021 | 0 | json_object_object_add(json_vrf, "interfaces", |
4022 | 0 | json_interface); |
4023 | 0 | } else { |
4024 | | /* Interface name is specified. */ |
4025 | 0 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
4026 | 0 | if (ifp == NULL) { |
4027 | 0 | if (use_json) { |
4028 | 0 | json_object_boolean_true_add(json_vrf, |
4029 | 0 | "noSuchIface"); |
4030 | 0 | json_object_free(json_interface); |
4031 | 0 | } else |
4032 | 0 | vty_out(vty, "No such interface name\n"); |
4033 | 0 | } else { |
4034 | 0 | if (use_json) |
4035 | 0 | json_interface_sub = json_object_new_object(); |
4036 | |
|
4037 | 0 | show_ip_ospf_interface_sub( |
4038 | 0 | vty, ospf, ifp, json_interface_sub, use_json); |
4039 | |
|
4040 | 0 | if (use_json) { |
4041 | 0 | json_object_object_add(json_interface, |
4042 | 0 | ifp->name, |
4043 | 0 | json_interface_sub); |
4044 | 0 | json_object_object_add(json_vrf, "interfaces", |
4045 | 0 | json_interface); |
4046 | 0 | } |
4047 | 0 | } |
4048 | 0 | } |
4049 | |
|
4050 | 0 | if (use_json) { |
4051 | 0 | if (use_vrf) { |
4052 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
4053 | 0 | json_vrf); |
4054 | 0 | } |
4055 | 0 | } else |
4056 | 0 | vty_out(vty, "\n"); |
4057 | |
|
4058 | 0 | return CMD_SUCCESS; |
4059 | 0 | } |
4060 | | |
4061 | | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
4062 | | struct ospf_interface *oi, |
4063 | | json_object *json_interface_sub, |
4064 | | bool use_json) |
4065 | 0 | { |
4066 | 0 | if (use_json) { |
4067 | 0 | json_object_int_add(json_interface_sub, "ifIndex", |
4068 | 0 | oi->ifp->ifindex); |
4069 | 0 | json_object_int_add(json_interface_sub, "helloIn", |
4070 | 0 | oi->hello_in); |
4071 | 0 | json_object_int_add(json_interface_sub, "helloOut", |
4072 | 0 | oi->hello_out); |
4073 | 0 | json_object_int_add(json_interface_sub, "dbDescIn", |
4074 | 0 | oi->db_desc_in); |
4075 | 0 | json_object_int_add(json_interface_sub, "dbDescOut", |
4076 | 0 | oi->db_desc_out); |
4077 | 0 | json_object_int_add(json_interface_sub, "lsReqIn", |
4078 | 0 | oi->ls_req_in); |
4079 | 0 | json_object_int_add(json_interface_sub, "lsReqOut", |
4080 | 0 | oi->ls_req_out); |
4081 | 0 | json_object_int_add(json_interface_sub, "lsUpdIn", |
4082 | 0 | oi->ls_upd_in); |
4083 | 0 | json_object_int_add(json_interface_sub, "lsUpdOut", |
4084 | 0 | oi->ls_upd_out); |
4085 | 0 | json_object_int_add(json_interface_sub, "lsAckIn", |
4086 | 0 | oi->ls_ack_in); |
4087 | 0 | json_object_int_add(json_interface_sub, "lsAckOut", |
4088 | 0 | oi->ls_ack_out); |
4089 | 0 | json_object_int_add(json_interface_sub, "packetsQueued", |
4090 | 0 | listcount(oi->obuf)); |
4091 | 0 | } else { |
4092 | 0 | vty_out(vty, |
4093 | 0 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n", |
4094 | 0 | oi->ifp->name, oi->hello_in, oi->hello_out, |
4095 | 0 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, |
4096 | 0 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, |
4097 | 0 | oi->ls_ack_in, oi->ls_ack_out, listcount(oi->obuf)); |
4098 | 0 | } |
4099 | 0 | } |
4100 | | |
4101 | | /* OSPFv2 Packet Counters */ |
4102 | | static int show_ip_ospf_interface_traffic_common( |
4103 | | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, |
4104 | | int display_once, uint8_t use_vrf, bool use_json) |
4105 | 0 | { |
4106 | 0 | struct vrf *vrf = NULL; |
4107 | 0 | struct interface *ifp = NULL; |
4108 | 0 | json_object *json_vrf = NULL; |
4109 | 0 | json_object *json_interface_sub = NULL; |
4110 | |
|
4111 | 0 | if (!use_json && !display_once) { |
4112 | 0 | vty_out(vty, "\n"); |
4113 | 0 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n", |
4114 | 0 | "Interface", " HELLO", " DB-Desc", " LS-Req", |
4115 | 0 | " LS-Update", " LS-Ack", " Packets"); |
4116 | 0 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "", |
4117 | 0 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
4118 | 0 | " Rx/Tx", " Queued"); |
4119 | 0 | vty_out(vty, |
4120 | 0 | "-------------------------------------------------------------------------------------------------------------\n"); |
4121 | 0 | } else if (use_json) { |
4122 | 0 | if (use_vrf) |
4123 | 0 | json_vrf = json_object_new_object(); |
4124 | 0 | else |
4125 | 0 | json_vrf = json; |
4126 | 0 | } |
4127 | |
|
4128 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4129 | |
|
4130 | 0 | if (intf_name == NULL) { |
4131 | 0 | vrf = vrf_lookup_by_id(ospf->vrf_id); |
4132 | 0 | FOR_ALL_INTERFACES (vrf, ifp) { |
4133 | 0 | struct route_node *rn; |
4134 | 0 | struct ospf_interface *oi; |
4135 | |
|
4136 | 0 | if (ospf_oi_count(ifp) == 0) |
4137 | 0 | continue; |
4138 | | |
4139 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; |
4140 | 0 | rn = route_next(rn)) { |
4141 | 0 | oi = rn->info; |
4142 | |
|
4143 | 0 | if (oi == NULL) |
4144 | 0 | continue; |
4145 | | |
4146 | 0 | if (use_json) { |
4147 | 0 | json_interface_sub = |
4148 | 0 | json_object_new_object(); |
4149 | 0 | } |
4150 | |
|
4151 | 0 | show_ip_ospf_interface_traffic_sub( |
4152 | 0 | vty, oi, json_interface_sub, use_json); |
4153 | 0 | if (use_json) { |
4154 | 0 | json_object_object_add( |
4155 | 0 | json_vrf, ifp->name, |
4156 | 0 | json_interface_sub); |
4157 | 0 | } |
4158 | 0 | } |
4159 | 0 | } |
4160 | 0 | } else { |
4161 | | /* Interface name is specified. */ |
4162 | 0 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
4163 | 0 | if (ifp != NULL) { |
4164 | 0 | struct route_node *rn; |
4165 | 0 | struct ospf_interface *oi; |
4166 | |
|
4167 | 0 | if (ospf_oi_count(ifp) == 0) { |
4168 | 0 | vty_out(vty, |
4169 | 0 | " OSPF not enabled on this interface %s\n", |
4170 | 0 | ifp->name); |
4171 | 0 | return CMD_SUCCESS; |
4172 | 0 | } |
4173 | | |
4174 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; |
4175 | 0 | rn = route_next(rn)) { |
4176 | 0 | oi = rn->info; |
4177 | |
|
4178 | 0 | if (oi == NULL) |
4179 | 0 | continue; |
4180 | | |
4181 | 0 | if (use_json) { |
4182 | 0 | json_interface_sub = |
4183 | 0 | json_object_new_object(); |
4184 | 0 | } |
4185 | |
|
4186 | 0 | show_ip_ospf_interface_traffic_sub( |
4187 | 0 | vty, oi, json_interface_sub, use_json); |
4188 | 0 | if (use_json) { |
4189 | 0 | json_object_object_add( |
4190 | 0 | json_vrf, ifp->name, |
4191 | 0 | json_interface_sub); |
4192 | 0 | } |
4193 | 0 | } |
4194 | 0 | } |
4195 | 0 | } |
4196 | | |
4197 | 0 | if (use_json) { |
4198 | 0 | if (use_vrf) |
4199 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
4200 | 0 | json_vrf); |
4201 | 0 | } else |
4202 | 0 | vty_out(vty, "\n"); |
4203 | |
|
4204 | 0 | return CMD_SUCCESS; |
4205 | 0 | } |
4206 | | |
4207 | | DEFUN (show_ip_ospf_interface, |
4208 | | show_ip_ospf_interface_cmd, |
4209 | | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
4210 | | SHOW_STR |
4211 | | IP_STR |
4212 | | "OSPF information\n" |
4213 | | VRF_CMD_HELP_STR |
4214 | | "All VRFs\n" |
4215 | | "Interface information\n" |
4216 | | "Interface name\n" |
4217 | | JSON_STR) |
4218 | 0 | { |
4219 | 0 | struct ospf *ospf; |
4220 | 0 | bool uj = use_json(argc, argv); |
4221 | 0 | struct listnode *node = NULL; |
4222 | 0 | char *vrf_name = NULL, *intf_name = NULL; |
4223 | 0 | bool all_vrf = false; |
4224 | 0 | int ret = CMD_SUCCESS; |
4225 | 0 | int inst = 0; |
4226 | 0 | int idx_vrf = 0, idx_intf = 0; |
4227 | 0 | uint8_t use_vrf = 0; |
4228 | 0 | json_object *json = NULL; |
4229 | |
|
4230 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4231 | |
|
4232 | 0 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
4233 | 0 | intf_name = argv[idx_intf]->arg; |
4234 | |
|
4235 | 0 | if (uj) |
4236 | 0 | json = json_object_new_object(); |
4237 | | |
4238 | | /* vrf input is provided could be all or specific vrf*/ |
4239 | 0 | if (vrf_name) { |
4240 | 0 | use_vrf = 1; |
4241 | 0 | if (all_vrf) { |
4242 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
4243 | 0 | if (!ospf->oi_running) |
4244 | 0 | continue; |
4245 | 0 | ret = show_ip_ospf_interface_common( |
4246 | 0 | vty, ospf, intf_name, use_vrf, json, |
4247 | 0 | uj); |
4248 | 0 | } |
4249 | |
|
4250 | 0 | if (uj) |
4251 | 0 | vty_json(vty, json); |
4252 | 0 | else if (!ospf) |
4253 | 0 | vty_out(vty, "%% OSPF is not enabled\n"); |
4254 | |
|
4255 | 0 | return ret; |
4256 | 0 | } |
4257 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
4258 | 0 | if (ospf == NULL || !ospf->oi_running) { |
4259 | 0 | if (uj) |
4260 | 0 | vty_json(vty, json); |
4261 | 0 | else |
4262 | 0 | vty_out(vty, |
4263 | 0 | "%% OSPF is not enabled in vrf %s\n", |
4264 | 0 | vrf_name); |
4265 | |
|
4266 | 0 | return CMD_SUCCESS; |
4267 | 0 | } |
4268 | 0 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, |
4269 | 0 | use_vrf, json, uj); |
4270 | |
|
4271 | 0 | } else { |
4272 | | /* Display default ospf (instance 0) info */ |
4273 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
4274 | 0 | if (ospf == NULL || !ospf->oi_running) { |
4275 | 0 | if (uj) |
4276 | 0 | vty_json(vty, json); |
4277 | 0 | else |
4278 | 0 | vty_out(vty, |
4279 | 0 | "%% OSPF is not enabled in vrf default\n"); |
4280 | |
|
4281 | 0 | return CMD_SUCCESS; |
4282 | 0 | } |
4283 | 0 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, |
4284 | 0 | use_vrf, json, uj); |
4285 | 0 | } |
4286 | | |
4287 | 0 | if (uj) |
4288 | 0 | vty_json(vty, json); |
4289 | |
|
4290 | 0 | return ret; |
4291 | 0 | } |
4292 | | |
4293 | | DEFUN (show_ip_ospf_instance_interface, |
4294 | | show_ip_ospf_instance_interface_cmd, |
4295 | | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
4296 | | SHOW_STR |
4297 | | IP_STR |
4298 | | "OSPF information\n" |
4299 | | "Instance ID\n" |
4300 | | "Interface information\n" |
4301 | | "Interface name\n" |
4302 | | JSON_STR) |
4303 | 0 | { |
4304 | 0 | int idx_number = 3; |
4305 | 0 | int idx_intf = 0; |
4306 | 0 | struct ospf *ospf; |
4307 | 0 | unsigned short instance = 0; |
4308 | 0 | bool uj = use_json(argc, argv); |
4309 | 0 | char *intf_name = NULL; |
4310 | 0 | int ret = CMD_SUCCESS; |
4311 | 0 | json_object *json = NULL; |
4312 | |
|
4313 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
4314 | 0 | if (instance != ospf_instance) |
4315 | 0 | return CMD_NOT_MY_INSTANCE; |
4316 | | |
4317 | 0 | ospf = ospf_lookup_instance(instance); |
4318 | 0 | if (!ospf || !ospf->oi_running) |
4319 | 0 | return CMD_SUCCESS; |
4320 | | |
4321 | 0 | if (uj) |
4322 | 0 | json = json_object_new_object(); |
4323 | |
|
4324 | 0 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
4325 | 0 | intf_name = argv[idx_intf]->arg; |
4326 | |
|
4327 | 0 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); |
4328 | |
|
4329 | 0 | if (uj) |
4330 | 0 | vty_json(vty, json); |
4331 | |
|
4332 | 0 | return ret; |
4333 | 0 | } |
4334 | | |
4335 | | DEFUN (show_ip_ospf_interface_traffic, |
4336 | | show_ip_ospf_interface_traffic_cmd, |
4337 | | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", |
4338 | | SHOW_STR |
4339 | | IP_STR |
4340 | | "OSPF information\n" |
4341 | | VRF_CMD_HELP_STR |
4342 | | "All VRFs\n" |
4343 | | "Interface information\n" |
4344 | | "Protocol Packet counters\n" |
4345 | | "Interface name\n" |
4346 | | JSON_STR) |
4347 | 0 | { |
4348 | 0 | struct ospf *ospf = NULL; |
4349 | 0 | struct listnode *node = NULL; |
4350 | 0 | char *vrf_name = NULL, *intf_name = NULL; |
4351 | 0 | bool all_vrf = false; |
4352 | 0 | int inst = 0; |
4353 | 0 | int idx_vrf = 0, idx_intf = 0; |
4354 | 0 | bool uj = use_json(argc, argv); |
4355 | 0 | json_object *json = NULL; |
4356 | 0 | int ret = CMD_SUCCESS; |
4357 | 0 | int display_once = 0; |
4358 | 0 | uint8_t use_vrf = 0; |
4359 | |
|
4360 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4361 | |
|
4362 | 0 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
4363 | 0 | intf_name = argv[idx_intf]->arg; |
4364 | |
|
4365 | 0 | if (uj) |
4366 | 0 | json = json_object_new_object(); |
4367 | |
|
4368 | 0 | if (vrf_name) { |
4369 | 0 | use_vrf = 1; |
4370 | 0 | if (all_vrf) { |
4371 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
4372 | 0 | if (!ospf->oi_running) |
4373 | 0 | continue; |
4374 | | |
4375 | 0 | ret = show_ip_ospf_interface_traffic_common( |
4376 | 0 | vty, ospf, intf_name, json, |
4377 | 0 | display_once, use_vrf, uj); |
4378 | 0 | display_once = 1; |
4379 | 0 | } |
4380 | |
|
4381 | 0 | if (uj) |
4382 | 0 | vty_json(vty, json); |
4383 | |
|
4384 | 0 | return ret; |
4385 | 0 | } |
4386 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
4387 | 0 | if (ospf == NULL || !ospf->oi_running) { |
4388 | 0 | if (uj) |
4389 | 0 | json_object_free(json); |
4390 | 0 | return CMD_SUCCESS; |
4391 | 0 | } |
4392 | | |
4393 | 0 | ret = show_ip_ospf_interface_traffic_common( |
4394 | 0 | vty, ospf, intf_name, json, display_once, use_vrf, uj); |
4395 | 0 | } else { |
4396 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
4397 | 0 | if (ospf == NULL || !ospf->oi_running) { |
4398 | 0 | if (uj) |
4399 | 0 | json_object_free(json); |
4400 | 0 | return CMD_SUCCESS; |
4401 | 0 | } |
4402 | | |
4403 | 0 | ret = show_ip_ospf_interface_traffic_common( |
4404 | 0 | vty, ospf, intf_name, json, display_once, use_vrf, uj); |
4405 | 0 | } |
4406 | | |
4407 | 0 | if (uj) |
4408 | 0 | vty_json(vty, json); |
4409 | |
|
4410 | 0 | return ret; |
4411 | 0 | } |
4412 | | |
4413 | | |
4414 | | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4415 | 0 | { |
4416 | 0 | vty_out(vty, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n", |
4417 | 0 | "Neighbor ID", "Pri", "State", "Up Time", "Dead Time", |
4418 | 0 | "Address", "Interface", "RXmtL", "RqstL", "DBsmL"); |
4419 | 0 | } |
4420 | | |
4421 | | static void show_ip_ospf_neighbour_brief(struct vty *vty, |
4422 | | struct ospf_neighbor *nbr, |
4423 | | struct ospf_neighbor *prev_nbr, |
4424 | | json_object *json, bool use_json) |
4425 | 0 | { |
4426 | 0 | char msgbuf[16]; |
4427 | 0 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
4428 | 0 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
4429 | 0 | struct timeval res = {.tv_sec = 0, .tv_usec = 0}; |
4430 | 0 | long time_val = 0; |
4431 | 0 | char uptime[OSPF_TIME_DUMP_SIZE]; |
4432 | |
|
4433 | 0 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) |
4434 | 0 | time_val = |
4435 | 0 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; |
4436 | |
|
4437 | 0 | if (use_json) { |
4438 | 0 | char neigh_str[INET_ADDRSTRLEN]; |
4439 | |
|
4440 | 0 | if (prev_nbr && !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { |
4441 | | /* Start new neigh list */ |
4442 | 0 | json_neigh_array = NULL; |
4443 | 0 | } |
4444 | |
|
4445 | 0 | if (nbr->state == NSM_Attempt && |
4446 | 0 | nbr->router_id.s_addr == INADDR_ANY) |
4447 | 0 | strlcpy(neigh_str, "neighbor", sizeof(neigh_str)); |
4448 | 0 | else |
4449 | 0 | inet_ntop(AF_INET, &nbr->router_id, neigh_str, |
4450 | 0 | sizeof(neigh_str)); |
4451 | |
|
4452 | 0 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); |
4453 | |
|
4454 | 0 | if (!json_neigh_array) { |
4455 | 0 | json_neigh_array = json_object_new_array(); |
4456 | 0 | json_object_object_add(json, neigh_str, |
4457 | 0 | json_neigh_array); |
4458 | 0 | } |
4459 | |
|
4460 | 0 | json_neighbor = json_object_new_object(); |
4461 | |
|
4462 | 0 | ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf)); |
4463 | 0 | json_object_string_add(json_neighbor, "nbrState", msgbuf); |
4464 | |
|
4465 | 0 | json_object_int_add(json_neighbor, "nbrPriority", |
4466 | 0 | nbr->priority); |
4467 | |
|
4468 | 0 | json_object_string_add( |
4469 | 0 | json_neighbor, "converged", |
4470 | 0 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); |
4471 | 0 | json_object_string_add(json_neighbor, "role", |
4472 | 0 | lookup_msg(ospf_ism_state_msg, |
4473 | 0 | ospf_nbr_ism_state(nbr), |
4474 | 0 | NULL)); |
4475 | 0 | if (nbr->t_inactivity) { |
4476 | 0 | long time_store; |
4477 | |
|
4478 | 0 | time_store = monotime_until(&nbr->t_inactivity->u.sands, |
4479 | 0 | NULL) / |
4480 | 0 | 1000LL; |
4481 | 0 | json_object_int_add(json_neighbor, "upTimeInMsec", |
4482 | 0 | time_val); |
4483 | 0 | json_object_int_add(json_neighbor, |
4484 | 0 | "routerDeadIntervalTimerDueMsec", |
4485 | 0 | time_store); |
4486 | 0 | json_object_string_add( |
4487 | 0 | json_neighbor, "upTime", |
4488 | 0 | ospf_timeval_dump(&res, uptime, |
4489 | 0 | sizeof(uptime))); |
4490 | 0 | json_object_string_add( |
4491 | 0 | json_neighbor, "deadTime", |
4492 | 0 | ospf_timer_dump(nbr->t_inactivity, timebuf, |
4493 | 0 | sizeof(timebuf))); |
4494 | 0 | } else { |
4495 | 0 | json_object_string_add(json_neighbor, "deadTimeMsecs", |
4496 | 0 | "inactive"); |
4497 | 0 | json_object_string_add(json_neighbor, |
4498 | 0 | "routerDeadIntervalTimerDueMsec", |
4499 | 0 | "inactive"); |
4500 | 0 | } |
4501 | 0 | json_object_string_addf(json_neighbor, "ifaceAddress", "%pI4", |
4502 | 0 | &nbr->src); |
4503 | 0 | json_object_string_add(json_neighbor, "ifaceName", |
4504 | 0 | IF_NAME(nbr->oi)); |
4505 | 0 | json_object_int_add(json_neighbor, |
4506 | 0 | "linkStateRetransmissionListCounter", |
4507 | 0 | ospf_ls_retransmit_count(nbr)); |
4508 | 0 | json_object_int_add(json_neighbor, |
4509 | 0 | "linkStateRequestListCounter", |
4510 | 0 | ospf_ls_request_count(nbr)); |
4511 | 0 | json_object_int_add(json_neighbor, "databaseSummaryListCounter", |
4512 | 0 | ospf_db_summary_count(nbr)); |
4513 | |
|
4514 | 0 | json_object_array_add(json_neigh_array, json_neighbor); |
4515 | 0 | } else { |
4516 | 0 | ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf)); |
4517 | |
|
4518 | 0 | if (nbr->state == NSM_Attempt && |
4519 | 0 | nbr->router_id.s_addr == INADDR_ANY) |
4520 | 0 | vty_out(vty, "%-15s %3d %-15s ", "-", nbr->priority, |
4521 | 0 | msgbuf); |
4522 | 0 | else |
4523 | 0 | vty_out(vty, "%-15pI4 %3d %-15s ", &nbr->router_id, |
4524 | 0 | nbr->priority, msgbuf); |
4525 | |
|
4526 | 0 | vty_out(vty, "%-15s ", |
4527 | 0 | ospf_timeval_dump(&res, uptime, sizeof(uptime))); |
4528 | |
|
4529 | 0 | vty_out(vty, "%9s ", |
4530 | 0 | ospf_timer_dump(nbr->t_inactivity, timebuf, |
4531 | 0 | sizeof(timebuf))); |
4532 | 0 | vty_out(vty, "%-15pI4 ", &nbr->src); |
4533 | 0 | vty_out(vty, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr->oi), |
4534 | 0 | ospf_ls_retransmit_count(nbr), |
4535 | 0 | ospf_ls_request_count(nbr), ospf_db_summary_count(nbr)); |
4536 | 0 | } |
4537 | 0 | } |
4538 | | |
4539 | | static void show_ip_ospf_neighbor_sub(struct vty *vty, |
4540 | | struct ospf_interface *oi, |
4541 | | json_object *json, bool use_json) |
4542 | 0 | { |
4543 | 0 | struct route_node *rn; |
4544 | 0 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
4545 | |
|
4546 | 0 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
4547 | 0 | nbr = rn->info; |
4548 | |
|
4549 | 0 | if (!nbr) |
4550 | 0 | continue; |
4551 | | |
4552 | | /* Do not show myself. */ |
4553 | 0 | if (nbr == oi->nbr_self) |
4554 | 0 | continue; |
4555 | | /* Down state is not shown. */ |
4556 | 0 | if (nbr->state == NSM_Down) |
4557 | 0 | continue; |
4558 | | |
4559 | 0 | prev_nbr = nbr; |
4560 | |
|
4561 | 0 | show_ip_ospf_neighbour_brief(vty, nbr, prev_nbr, json, |
4562 | 0 | use_json); |
4563 | 0 | } |
4564 | 0 | } |
4565 | | |
4566 | | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, |
4567 | | json_object *json, bool use_json, |
4568 | | uint8_t use_vrf) |
4569 | 0 | { |
4570 | 0 | struct ospf_interface *oi; |
4571 | 0 | struct listnode *node; |
4572 | 0 | json_object *json_vrf = NULL; |
4573 | 0 | json_object *json_nbr_sub = NULL; |
4574 | |
|
4575 | 0 | if (use_json) { |
4576 | 0 | if (use_vrf) |
4577 | 0 | json_vrf = json_object_new_object(); |
4578 | 0 | else |
4579 | 0 | json_vrf = json; |
4580 | 0 | json_nbr_sub = json_object_new_object(); |
4581 | 0 | } |
4582 | |
|
4583 | 0 | if (ospf->instance) { |
4584 | 0 | if (use_json) |
4585 | 0 | json_object_int_add(json, "ospfInstance", |
4586 | 0 | ospf->instance); |
4587 | 0 | else |
4588 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
4589 | 0 | } |
4590 | |
|
4591 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4592 | 0 | if (!use_json) |
4593 | 0 | show_ip_ospf_neighbour_header(vty); |
4594 | |
|
4595 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4596 | 0 | if (ospf_interface_neighbor_count(oi) == 0) |
4597 | 0 | continue; |
4598 | 0 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4599 | 0 | } |
4600 | |
|
4601 | 0 | if (use_json) { |
4602 | 0 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
4603 | 0 | if (use_vrf) |
4604 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
4605 | 0 | json_vrf); |
4606 | 0 | } else |
4607 | 0 | vty_out(vty, "\n"); |
4608 | |
|
4609 | 0 | return CMD_SUCCESS; |
4610 | 0 | } |
4611 | | |
4612 | | DEFUN (show_ip_ospf_neighbor, |
4613 | | show_ip_ospf_neighbor_cmd, |
4614 | | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
4615 | | SHOW_STR |
4616 | | IP_STR |
4617 | | "OSPF information\n" |
4618 | | VRF_CMD_HELP_STR |
4619 | | "All VRFs\n" |
4620 | | "Neighbor list\n" |
4621 | | JSON_STR) |
4622 | 0 | { |
4623 | 0 | struct ospf *ospf; |
4624 | 0 | bool uj = use_json(argc, argv); |
4625 | 0 | struct listnode *node = NULL; |
4626 | 0 | char *vrf_name = NULL; |
4627 | 0 | bool all_vrf = false; |
4628 | 0 | int ret = CMD_SUCCESS; |
4629 | 0 | int inst = 0; |
4630 | 0 | int idx_vrf = 0; |
4631 | 0 | uint8_t use_vrf = 0; |
4632 | 0 | json_object *json = NULL; |
4633 | |
|
4634 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4635 | |
|
4636 | 0 | if (uj) |
4637 | 0 | json = json_object_new_object(); |
4638 | | |
4639 | | /* vrf input is provided could be all or specific vrf*/ |
4640 | 0 | if (vrf_name) { |
4641 | 0 | use_vrf = 1; |
4642 | 0 | if (all_vrf) { |
4643 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
4644 | 0 | if (!ospf->oi_running) |
4645 | 0 | continue; |
4646 | 0 | ret = show_ip_ospf_neighbor_common( |
4647 | 0 | vty, ospf, json, uj, use_vrf); |
4648 | 0 | } |
4649 | |
|
4650 | 0 | if (uj) |
4651 | 0 | vty_json(vty, json); |
4652 | 0 | else if (!ospf) |
4653 | 0 | vty_out(vty, "OSPF is not enabled\n"); |
4654 | |
|
4655 | 0 | return ret; |
4656 | 0 | } |
4657 | | |
4658 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
4659 | 0 | if (ospf == NULL || !ospf->oi_running) { |
4660 | 0 | if (uj) |
4661 | 0 | vty_json(vty, json); |
4662 | 0 | else |
4663 | 0 | vty_out(vty, |
4664 | 0 | "%% OSPF is not enabled in vrf %s\n", |
4665 | 0 | vrf_name); |
4666 | |
|
4667 | 0 | return CMD_SUCCESS; |
4668 | 0 | } |
4669 | 0 | } else { |
4670 | | /* Display default ospf (instance 0) info */ |
4671 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
4672 | 0 | if (ospf == NULL || !ospf->oi_running) { |
4673 | 0 | if (uj) |
4674 | 0 | vty_json(vty, json); |
4675 | 0 | else |
4676 | 0 | vty_out(vty, |
4677 | 0 | "%% OSPF is not enabled in vrf default\n"); |
4678 | |
|
4679 | 0 | return CMD_SUCCESS; |
4680 | 0 | } |
4681 | 0 | } |
4682 | | |
4683 | 0 | if (ospf) { |
4684 | 0 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, |
4685 | 0 | use_vrf); |
4686 | |
|
4687 | 0 | if (uj) { |
4688 | 0 | vty_out(vty, "%s\n", |
4689 | 0 | json_object_to_json_string_ext( |
4690 | 0 | json, JSON_C_TO_STRING_PRETTY)); |
4691 | 0 | } |
4692 | 0 | } |
4693 | |
|
4694 | 0 | if (uj) |
4695 | 0 | json_object_free(json); |
4696 | |
|
4697 | 0 | return ret; |
4698 | 0 | } |
4699 | | |
4700 | | |
4701 | | DEFUN (show_ip_ospf_instance_neighbor, |
4702 | | show_ip_ospf_instance_neighbor_cmd, |
4703 | | "show ip ospf (1-65535) neighbor [json]", |
4704 | | SHOW_STR |
4705 | | IP_STR |
4706 | | "OSPF information\n" |
4707 | | "Instance ID\n" |
4708 | | "Neighbor list\n" |
4709 | | JSON_STR) |
4710 | 0 | { |
4711 | 0 | int idx_number = 3; |
4712 | 0 | struct ospf *ospf; |
4713 | 0 | unsigned short instance = 0; |
4714 | 0 | bool uj = use_json(argc, argv); |
4715 | 0 | json_object *json = NULL; |
4716 | 0 | int ret = CMD_SUCCESS; |
4717 | |
|
4718 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
4719 | 0 | if (instance != ospf_instance) |
4720 | 0 | return CMD_NOT_MY_INSTANCE; |
4721 | | |
4722 | 0 | ospf = ospf_lookup_instance(instance); |
4723 | 0 | if (!ospf || !ospf->oi_running) |
4724 | 0 | return CMD_SUCCESS; |
4725 | | |
4726 | 0 | if (uj) |
4727 | 0 | json = json_object_new_object(); |
4728 | |
|
4729 | 0 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4730 | |
|
4731 | 0 | if (uj) |
4732 | 0 | vty_json(vty, json); |
4733 | |
|
4734 | 0 | return ret; |
4735 | 0 | } |
4736 | | |
4737 | | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
4738 | | json_object *json, bool use_json, |
4739 | | uint8_t use_vrf) |
4740 | 0 | { |
4741 | 0 | struct listnode *node; |
4742 | 0 | struct ospf_interface *oi; |
4743 | 0 | char buf[PREFIX_STRLEN]; |
4744 | 0 | json_object *json_vrf = NULL; |
4745 | 0 | json_object *json_neighbor_sub = NULL; |
4746 | |
|
4747 | 0 | if (use_json) { |
4748 | 0 | if (use_vrf) |
4749 | 0 | json_vrf = json_object_new_object(); |
4750 | 0 | else |
4751 | 0 | json_vrf = json; |
4752 | 0 | } |
4753 | |
|
4754 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4755 | 0 | if (!use_json) |
4756 | 0 | show_ip_ospf_neighbour_header(vty); |
4757 | |
|
4758 | 0 | if (ospf->instance) { |
4759 | 0 | if (use_json) |
4760 | 0 | json_object_int_add(json_vrf, "ospfInstance", |
4761 | 0 | ospf->instance); |
4762 | 0 | else |
4763 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
4764 | 0 | } |
4765 | |
|
4766 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4767 | 0 | struct listnode *nbr_node; |
4768 | 0 | struct ospf_nbr_nbma *nbr_nbma; |
4769 | |
|
4770 | 0 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
4771 | | |
4772 | | /* print Down neighbor status */ |
4773 | 0 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { |
4774 | 0 | if (nbr_nbma->nbr == NULL |
4775 | 0 | || nbr_nbma->nbr->state == NSM_Down) { |
4776 | 0 | if (use_json) { |
4777 | 0 | json_neighbor_sub = |
4778 | 0 | json_object_new_object(); |
4779 | 0 | json_object_int_add(json_neighbor_sub, |
4780 | 0 | "nbrNbmaPriority", |
4781 | 0 | nbr_nbma->priority); |
4782 | 0 | json_object_boolean_true_add( |
4783 | 0 | json_neighbor_sub, |
4784 | 0 | "nbrNbmaDown"); |
4785 | 0 | json_object_string_add( |
4786 | 0 | json_neighbor_sub, |
4787 | 0 | "nbrNbmaIfaceName", |
4788 | 0 | IF_NAME(oi)); |
4789 | 0 | json_object_int_add( |
4790 | 0 | json_neighbor_sub, |
4791 | 0 | "nbrNbmaRetransmitCounter", 0); |
4792 | 0 | json_object_int_add( |
4793 | 0 | json_neighbor_sub, |
4794 | 0 | "nbrNbmaRequestCounter", 0); |
4795 | 0 | json_object_int_add( |
4796 | 0 | json_neighbor_sub, |
4797 | 0 | "nbrNbmaDbSummaryCounter", 0); |
4798 | 0 | json_object_object_add( |
4799 | 0 | json_vrf, |
4800 | 0 | inet_ntop(AF_INET, |
4801 | 0 | &nbr_nbma->addr, buf, |
4802 | 0 | sizeof(buf)), |
4803 | 0 | json_neighbor_sub); |
4804 | 0 | } else { |
4805 | 0 | vty_out(vty, "%-15s %3d %-15s %9s ", |
4806 | 0 | "-", nbr_nbma->priority, "Down", |
4807 | 0 | "-"); |
4808 | 0 | vty_out(vty, |
4809 | 0 | "%-32pI4 %-20s %5d %5d %5d\n", |
4810 | 0 | &nbr_nbma->addr, |
4811 | 0 | IF_NAME(oi), 0, 0, 0); |
4812 | 0 | } |
4813 | 0 | } |
4814 | 0 | } |
4815 | 0 | } |
4816 | |
|
4817 | 0 | if (use_json) { |
4818 | 0 | if (use_vrf) |
4819 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
4820 | 0 | json_vrf); |
4821 | 0 | } else |
4822 | 0 | vty_out(vty, "\n"); |
4823 | |
|
4824 | 0 | return CMD_SUCCESS; |
4825 | 0 | } |
4826 | | |
4827 | | DEFUN (show_ip_ospf_neighbor_all, |
4828 | | show_ip_ospf_neighbor_all_cmd, |
4829 | | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
4830 | | SHOW_STR |
4831 | | IP_STR |
4832 | | "OSPF information\n" |
4833 | | VRF_CMD_HELP_STR |
4834 | | "All VRFs\n" |
4835 | | "Neighbor list\n" |
4836 | | "include down status neighbor\n" |
4837 | | JSON_STR) |
4838 | 0 | { |
4839 | 0 | struct ospf *ospf; |
4840 | 0 | bool uj = use_json(argc, argv); |
4841 | 0 | struct listnode *node = NULL; |
4842 | 0 | char *vrf_name = NULL; |
4843 | 0 | bool all_vrf = false; |
4844 | 0 | int ret = CMD_SUCCESS; |
4845 | 0 | int inst = 0; |
4846 | 0 | int idx_vrf = 0; |
4847 | 0 | uint8_t use_vrf = 0; |
4848 | 0 | json_object *json = NULL; |
4849 | |
|
4850 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4851 | |
|
4852 | 0 | if (uj) |
4853 | 0 | json = json_object_new_object(); |
4854 | | |
4855 | | /* vrf input is provided could be all or specific vrf*/ |
4856 | 0 | if (vrf_name) { |
4857 | 0 | use_vrf = 1; |
4858 | 0 | if (all_vrf) { |
4859 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
4860 | 0 | if (!ospf->oi_running) |
4861 | 0 | continue; |
4862 | 0 | ret = show_ip_ospf_neighbor_all_common( |
4863 | 0 | vty, ospf, json, uj, use_vrf); |
4864 | 0 | } |
4865 | |
|
4866 | 0 | if (uj) |
4867 | 0 | vty_json(vty, json); |
4868 | |
|
4869 | 0 | return ret; |
4870 | 0 | } |
4871 | | |
4872 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
4873 | 0 | if (ospf == NULL || !ospf->oi_running) { |
4874 | 0 | if (uj) |
4875 | 0 | json_object_free(json); |
4876 | 0 | return CMD_SUCCESS; |
4877 | 0 | } |
4878 | 0 | } else { |
4879 | | /* Display default ospf (instance 0) info */ |
4880 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
4881 | 0 | if (ospf == NULL || !ospf->oi_running) { |
4882 | 0 | if (uj) |
4883 | 0 | json_object_free(json); |
4884 | 0 | return CMD_SUCCESS; |
4885 | 0 | } |
4886 | 0 | } |
4887 | | |
4888 | 0 | if (ospf) { |
4889 | 0 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, |
4890 | 0 | use_vrf); |
4891 | 0 | if (uj) { |
4892 | 0 | vty_out(vty, "%s\n", |
4893 | 0 | json_object_to_json_string_ext( |
4894 | 0 | json, JSON_C_TO_STRING_PRETTY)); |
4895 | 0 | } |
4896 | 0 | } |
4897 | |
|
4898 | 0 | if (uj) |
4899 | 0 | json_object_free(json); |
4900 | |
|
4901 | 0 | return ret; |
4902 | 0 | } |
4903 | | |
4904 | | DEFUN (show_ip_ospf_instance_neighbor_all, |
4905 | | show_ip_ospf_instance_neighbor_all_cmd, |
4906 | | "show ip ospf (1-65535) neighbor all [json]", |
4907 | | SHOW_STR |
4908 | | IP_STR |
4909 | | "OSPF information\n" |
4910 | | "Instance ID\n" |
4911 | | "Neighbor list\n" |
4912 | | "include down status neighbor\n" |
4913 | | JSON_STR) |
4914 | 0 | { |
4915 | 0 | int idx_number = 3; |
4916 | 0 | struct ospf *ospf; |
4917 | 0 | unsigned short instance = 0; |
4918 | 0 | bool uj = use_json(argc, argv); |
4919 | 0 | json_object *json = NULL; |
4920 | 0 | int ret = CMD_SUCCESS; |
4921 | |
|
4922 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
4923 | 0 | if (instance != ospf_instance) |
4924 | 0 | return CMD_NOT_MY_INSTANCE; |
4925 | | |
4926 | 0 | ospf = ospf_lookup_instance(instance); |
4927 | 0 | if (!ospf || !ospf->oi_running) |
4928 | 0 | return CMD_SUCCESS; |
4929 | 0 | if (uj) |
4930 | 0 | json = json_object_new_object(); |
4931 | |
|
4932 | 0 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); |
4933 | |
|
4934 | 0 | if (uj) |
4935 | 0 | vty_json(vty, json); |
4936 | |
|
4937 | 0 | return ret; |
4938 | 0 | } |
4939 | | |
4940 | | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4941 | | const char *ifname, bool use_json, |
4942 | | uint8_t use_vrf) |
4943 | 0 | { |
4944 | 0 | struct interface *ifp; |
4945 | 0 | struct route_node *rn; |
4946 | 0 | json_object *json = NULL; |
4947 | |
|
4948 | 0 | if (use_json) |
4949 | 0 | json = json_object_new_object(); |
4950 | |
|
4951 | 0 | if (ospf->instance) { |
4952 | 0 | if (use_json) |
4953 | 0 | json_object_int_add(json, "ospfInstance", |
4954 | 0 | ospf->instance); |
4955 | 0 | else |
4956 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
4957 | 0 | } |
4958 | |
|
4959 | 0 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
4960 | |
|
4961 | 0 | ifp = if_lookup_by_name(ifname, ospf->vrf_id); |
4962 | 0 | if (!ifp) { |
4963 | 0 | if (use_json) |
4964 | 0 | json_object_boolean_true_add(json, "noSuchIface"); |
4965 | 0 | else |
4966 | 0 | vty_out(vty, "No such interface.\n"); |
4967 | 0 | return CMD_WARNING; |
4968 | 0 | } |
4969 | | |
4970 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
4971 | 0 | struct ospf_interface *oi = rn->info; |
4972 | |
|
4973 | 0 | if (oi == NULL) |
4974 | 0 | continue; |
4975 | | |
4976 | 0 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); |
4977 | 0 | } |
4978 | |
|
4979 | 0 | if (use_json) |
4980 | 0 | vty_json(vty, json); |
4981 | 0 | else |
4982 | 0 | vty_out(vty, "\n"); |
4983 | |
|
4984 | 0 | return CMD_SUCCESS; |
4985 | 0 | } |
4986 | | |
4987 | | DEFPY(show_ip_ospf_instance_neighbor_int, |
4988 | | show_ip_ospf_instance_neighbor_int_cmd, |
4989 | | "show ip ospf (1-65535)$instance neighbor IFNAME$ifname [json$json]", |
4990 | | SHOW_STR |
4991 | | IP_STR |
4992 | | "OSPF information\n" |
4993 | | "Instance ID\n" |
4994 | | "Neighbor list\n" |
4995 | | "Interface name\n" |
4996 | | JSON_STR) |
4997 | 0 | { |
4998 | 0 | struct ospf *ospf; |
4999 | |
|
5000 | 0 | if (!json) |
5001 | 0 | show_ip_ospf_neighbour_header(vty); |
5002 | |
|
5003 | 0 | if (instance != ospf_instance) |
5004 | 0 | return CMD_NOT_MY_INSTANCE; |
5005 | | |
5006 | 0 | ospf = ospf_lookup_instance(instance); |
5007 | 0 | if (!ospf || !ospf->oi_running) |
5008 | 0 | return CMD_SUCCESS; |
5009 | | |
5010 | 0 | if (!json) |
5011 | 0 | show_ip_ospf_neighbour_header(vty); |
5012 | |
|
5013 | 0 | return show_ip_ospf_neighbor_int_common(vty, ospf, ifname, !!json, 0); |
5014 | 0 | } |
5015 | | |
5016 | | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
5017 | | struct ospf_interface *oi, |
5018 | | struct ospf_nbr_nbma *nbr_nbma, |
5019 | | bool use_json, json_object *json) |
5020 | 0 | { |
5021 | 0 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
5022 | 0 | json_object *json_sub = NULL; |
5023 | |
|
5024 | 0 | if (use_json) |
5025 | 0 | json_sub = json_object_new_object(); |
5026 | 0 | else /* Show neighbor ID. */ |
5027 | 0 | vty_out(vty, " Neighbor %s,", "-"); |
5028 | | |
5029 | | /* Show interface address. */ |
5030 | 0 | if (use_json) |
5031 | 0 | json_object_string_addf(json_sub, "ifaceAddress", "%pI4", |
5032 | 0 | &nbr_nbma->addr); |
5033 | 0 | else |
5034 | 0 | vty_out(vty, " interface address %pI4\n", |
5035 | 0 | &nbr_nbma->addr); |
5036 | | |
5037 | | /* Show Area ID. */ |
5038 | 0 | if (use_json) { |
5039 | 0 | json_object_string_add(json_sub, "areaId", |
5040 | 0 | ospf_area_desc_string(oi->area)); |
5041 | 0 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); |
5042 | 0 | } else |
5043 | 0 | vty_out(vty, " In the area %s via interface %s\n", |
5044 | 0 | ospf_area_desc_string(oi->area), IF_NAME(oi)); |
5045 | | |
5046 | | /* Show neighbor priority and state. */ |
5047 | 0 | if (use_json) { |
5048 | 0 | json_object_int_add(json_sub, "nbrPriority", |
5049 | 0 | nbr_nbma->priority); |
5050 | 0 | json_object_string_add(json_sub, "nbrState", "down"); |
5051 | 0 | } else |
5052 | 0 | vty_out(vty, " Neighbor priority is %d, State is %s,", |
5053 | 0 | nbr_nbma->priority, "Down"); |
5054 | | |
5055 | | /* Show state changes. */ |
5056 | 0 | if (use_json) |
5057 | 0 | json_object_int_add(json_sub, "stateChangeCounter", |
5058 | 0 | nbr_nbma->state_change); |
5059 | 0 | else |
5060 | 0 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); |
5061 | | |
5062 | | /* Show PollInterval */ |
5063 | 0 | if (use_json) |
5064 | 0 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); |
5065 | 0 | else |
5066 | 0 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); |
5067 | | |
5068 | | /* Show poll-interval timer. */ |
5069 | 0 | if (nbr_nbma->t_poll) { |
5070 | 0 | if (use_json) { |
5071 | 0 | long time_store; |
5072 | 0 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, |
5073 | 0 | NULL) / 1000LL; |
5074 | 0 | json_object_int_add(json_sub, |
5075 | 0 | "pollIntervalTimerDueMsec", |
5076 | 0 | time_store); |
5077 | 0 | } else |
5078 | 0 | vty_out(vty, " Poll timer due in %s\n", |
5079 | 0 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, |
5080 | 0 | sizeof(timebuf))); |
5081 | 0 | } |
5082 | | |
5083 | | /* Show poll-interval timer thread. */ |
5084 | 0 | if (use_json) { |
5085 | 0 | if (nbr_nbma->t_poll != NULL) |
5086 | 0 | json_object_string_add(json_sub, |
5087 | 0 | "pollIntervalTimerThread", "on"); |
5088 | 0 | } else |
5089 | 0 | vty_out(vty, " Thread Poll Timer %s\n", |
5090 | 0 | nbr_nbma->t_poll != NULL ? "on" : "off"); |
5091 | |
|
5092 | 0 | if (use_json) |
5093 | 0 | json_object_object_add(json, "noNbrId", json_sub); |
5094 | 0 | } |
5095 | | |
5096 | | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, |
5097 | | struct ospf_interface *oi, |
5098 | | struct ospf_neighbor *nbr, |
5099 | | struct ospf_neighbor *prev_nbr, |
5100 | | json_object *json, bool use_json) |
5101 | 0 | { |
5102 | 0 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
5103 | 0 | json_object *json_neigh = NULL, *json_neigh_array = NULL; |
5104 | 0 | char neigh_str[INET_ADDRSTRLEN] = {0}; |
5105 | 0 | char neigh_state[16] = {0}; |
5106 | 0 | struct ospf_neighbor *nbr_dr, *nbr_bdr; |
5107 | |
|
5108 | 0 | if (use_json) { |
5109 | 0 | if (prev_nbr && |
5110 | 0 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { |
5111 | 0 | json_neigh_array = NULL; |
5112 | 0 | } |
5113 | |
|
5114 | 0 | if (nbr->state == NSM_Attempt |
5115 | 0 | && nbr->router_id.s_addr == INADDR_ANY) |
5116 | 0 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
5117 | 0 | else |
5118 | 0 | inet_ntop(AF_INET, &nbr->router_id, |
5119 | 0 | neigh_str, sizeof(neigh_str)); |
5120 | |
|
5121 | 0 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); |
5122 | |
|
5123 | 0 | if (!json_neigh_array) { |
5124 | 0 | json_neigh_array = json_object_new_array(); |
5125 | 0 | json_object_object_add(json, neigh_str, |
5126 | 0 | json_neigh_array); |
5127 | 0 | } |
5128 | |
|
5129 | 0 | json_neigh = json_object_new_object(); |
5130 | |
|
5131 | 0 | } else { |
5132 | | /* Show neighbor ID. */ |
5133 | 0 | if (nbr->state == NSM_Attempt |
5134 | 0 | && nbr->router_id.s_addr == INADDR_ANY) |
5135 | 0 | vty_out(vty, " Neighbor %s,", "-"); |
5136 | 0 | else |
5137 | 0 | vty_out(vty, " Neighbor %pI4,", |
5138 | 0 | &nbr->router_id); |
5139 | 0 | } |
5140 | | |
5141 | | /* Show interface address. */ |
5142 | 0 | if (use_json) |
5143 | 0 | json_object_string_addf(json_neigh, "ifaceAddress", "%pI4", |
5144 | 0 | &nbr->address.u.prefix4); |
5145 | 0 | else |
5146 | 0 | vty_out(vty, " interface address %pI4\n", |
5147 | 0 | &nbr->address.u.prefix4); |
5148 | | |
5149 | | /* Show Area ID. */ |
5150 | 0 | if (use_json) { |
5151 | 0 | json_object_string_add(json_neigh, "areaId", |
5152 | 0 | ospf_area_desc_string(oi->area)); |
5153 | 0 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
5154 | 0 | if (oi->address) |
5155 | 0 | json_object_string_addf(json_neigh, "localIfaceAddress", |
5156 | 0 | "%pI4", |
5157 | 0 | &oi->address->u.prefix4); |
5158 | 0 | } else { |
5159 | 0 | vty_out(vty, " In the area %s via interface %s", |
5160 | 0 | ospf_area_desc_string(oi->area), oi->ifp->name); |
5161 | 0 | if (oi->address) |
5162 | 0 | vty_out(vty, " local interface IP %pI4\n", |
5163 | 0 | &oi->address->u.prefix4); |
5164 | 0 | else |
5165 | 0 | vty_out(vty, "\n"); |
5166 | 0 | } |
5167 | | |
5168 | | /* Show neighbor priority and state. */ |
5169 | 0 | ospf_nbr_ism_state_message(nbr, neigh_state, sizeof(neigh_state)); |
5170 | 0 | if (use_json) { |
5171 | 0 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
5172 | 0 | json_object_string_add(json_neigh, "nbrState", neigh_state); |
5173 | 0 | json_object_string_add(json_neigh, "role", |
5174 | 0 | lookup_msg(ospf_ism_state_msg, |
5175 | 0 | ospf_nbr_ism_state(nbr), |
5176 | 0 | NULL)); |
5177 | 0 | } else { |
5178 | 0 | vty_out(vty, |
5179 | 0 | " Neighbor priority is %d, State is %s, Role is %s,", |
5180 | 0 | nbr->priority, neigh_state, |
5181 | 0 | lookup_msg(ospf_ism_state_msg, ospf_nbr_ism_state(nbr), |
5182 | 0 | NULL)); |
5183 | 0 | } |
5184 | | /* Show state changes. */ |
5185 | 0 | if (use_json) |
5186 | 0 | json_object_int_add(json_neigh, "stateChangeCounter", |
5187 | 0 | nbr->state_change); |
5188 | 0 | else |
5189 | 0 | vty_out(vty, " %d state changes\n", nbr->state_change); |
5190 | |
|
5191 | 0 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { |
5192 | 0 | struct timeval res; |
5193 | 0 | long time_store; |
5194 | |
|
5195 | 0 | time_store = |
5196 | 0 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; |
5197 | 0 | if (use_json) { |
5198 | 0 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
5199 | 0 | time_store); |
5200 | 0 | } else { |
5201 | 0 | vty_out(vty, |
5202 | 0 | " Most recent state change statistics:\n"); |
5203 | 0 | vty_out(vty, " Progressive change %s ago\n", |
5204 | 0 | ospf_timeval_dump(&res, timebuf, |
5205 | 0 | sizeof(timebuf))); |
5206 | 0 | } |
5207 | 0 | } |
5208 | |
|
5209 | 0 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { |
5210 | 0 | struct timeval res; |
5211 | 0 | long time_store; |
5212 | |
|
5213 | 0 | time_store = |
5214 | 0 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; |
5215 | 0 | if (use_json) { |
5216 | 0 | json_object_int_add(json_neigh, |
5217 | 0 | "lastRegressiveChangeMsec", |
5218 | 0 | time_store); |
5219 | 0 | if (nbr->last_regress_str) |
5220 | 0 | json_object_string_add( |
5221 | 0 | json_neigh, |
5222 | 0 | "lastRegressiveChangeReason", |
5223 | 0 | nbr->last_regress_str); |
5224 | 0 | } else { |
5225 | 0 | vty_out(vty, |
5226 | 0 | " Regressive change %s ago, due to %s\n", |
5227 | 0 | ospf_timeval_dump(&res, timebuf, |
5228 | 0 | sizeof(timebuf)), |
5229 | 0 | (nbr->last_regress_str ? nbr->last_regress_str |
5230 | 0 | : "??")); |
5231 | 0 | } |
5232 | 0 | } |
5233 | | |
5234 | | /* Show Designated Router ID. */ |
5235 | 0 | if (DR(oi).s_addr == INADDR_ANY) { |
5236 | 0 | if (!use_json) |
5237 | 0 | vty_out(vty, |
5238 | 0 | " No designated router on this network\n"); |
5239 | 0 | } else { |
5240 | 0 | nbr_dr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi)); |
5241 | 0 | if (nbr_dr) { |
5242 | 0 | if (use_json) |
5243 | 0 | json_object_string_addf( |
5244 | 0 | json_neigh, "routerDesignatedId", |
5245 | 0 | "%pI4", &nbr_dr->router_id); |
5246 | 0 | else |
5247 | 0 | vty_out(vty, " DR is %pI4,", |
5248 | 0 | &nbr_dr->router_id); |
5249 | 0 | } |
5250 | 0 | } |
5251 | | |
5252 | | /* Show Backup Designated Router ID. */ |
5253 | 0 | nbr_bdr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); |
5254 | 0 | if (nbr_bdr == NULL) { |
5255 | 0 | if (!use_json) |
5256 | 0 | vty_out(vty, |
5257 | 0 | " No backup designated router on this network\n"); |
5258 | 0 | } else { |
5259 | 0 | if (use_json) |
5260 | 0 | json_object_string_addf(json_neigh, |
5261 | 0 | "routerDesignatedBackupId", |
5262 | 0 | "%pI4", &nbr_bdr->router_id); |
5263 | 0 | else |
5264 | 0 | vty_out(vty, " BDR is %pI4\n", &nbr_bdr->router_id); |
5265 | 0 | } |
5266 | | |
5267 | | /* Show options. */ |
5268 | 0 | if (use_json) { |
5269 | 0 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5270 | 0 | json_object_string_add(json_neigh, "optionsList", |
5271 | 0 | ospf_options_dump(nbr->options)); |
5272 | 0 | } else |
5273 | 0 | vty_out(vty, " Options %d %s\n", nbr->options, |
5274 | 0 | ospf_options_dump(nbr->options)); |
5275 | | |
5276 | | /* Show Router Dead interval timer. */ |
5277 | 0 | if (use_json) { |
5278 | 0 | if (nbr->t_inactivity) { |
5279 | 0 | long time_store; |
5280 | 0 | time_store = monotime_until(&nbr->t_inactivity->u.sands, |
5281 | 0 | NULL) |
5282 | 0 | / 1000LL; |
5283 | 0 | json_object_int_add(json_neigh, |
5284 | 0 | "routerDeadIntervalTimerDueMsec", |
5285 | 0 | time_store); |
5286 | 0 | } else |
5287 | 0 | json_object_int_add( |
5288 | 0 | json_neigh, |
5289 | 0 | "routerDeadIntervalTimerDueMsec", -1); |
5290 | 0 | } else |
5291 | 0 | vty_out(vty, " Dead timer due in %s\n", |
5292 | 0 | ospf_timer_dump(nbr->t_inactivity, timebuf, |
5293 | 0 | sizeof(timebuf))); |
5294 | | |
5295 | | /* Show Database Summary list. */ |
5296 | 0 | if (use_json) |
5297 | 0 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
5298 | 0 | ospf_db_summary_count(nbr)); |
5299 | 0 | else |
5300 | 0 | vty_out(vty, " Database Summary List %d\n", |
5301 | 0 | ospf_db_summary_count(nbr)); |
5302 | | |
5303 | | /* Show Link State Request list. */ |
5304 | 0 | if (use_json) |
5305 | 0 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
5306 | 0 | ospf_ls_request_count(nbr)); |
5307 | 0 | else |
5308 | 0 | vty_out(vty, " Link State Request List %ld\n", |
5309 | 0 | ospf_ls_request_count(nbr)); |
5310 | | |
5311 | | /* Show Link State Retransmission list. */ |
5312 | 0 | if (use_json) |
5313 | 0 | json_object_int_add(json_neigh, |
5314 | 0 | "linkStateRetransmissionListCounter", |
5315 | 0 | ospf_ls_retransmit_count(nbr)); |
5316 | 0 | else |
5317 | 0 | vty_out(vty, " Link State Retransmission List %ld\n", |
5318 | 0 | ospf_ls_retransmit_count(nbr)); |
5319 | | |
5320 | | /* Show inactivity timer thread. */ |
5321 | 0 | if (use_json) { |
5322 | 0 | if (nbr->t_inactivity != NULL) |
5323 | 0 | json_object_string_add(json_neigh, |
5324 | 0 | "threadInactivityTimer", "on"); |
5325 | 0 | } else |
5326 | 0 | vty_out(vty, " Thread Inactivity Timer %s\n", |
5327 | 0 | nbr->t_inactivity != NULL ? "on" : "off"); |
5328 | | |
5329 | | /* Show Database Description retransmission thread. */ |
5330 | 0 | if (use_json) { |
5331 | 0 | if (nbr->t_db_desc != NULL) |
5332 | 0 | json_object_string_add( |
5333 | 0 | json_neigh, |
5334 | 0 | "threadDatabaseDescriptionRetransmission", |
5335 | 0 | "on"); |
5336 | 0 | } else |
5337 | 0 | vty_out(vty, |
5338 | 0 | " Thread Database Description Retransmision %s\n", |
5339 | 0 | nbr->t_db_desc != NULL ? "on" : "off"); |
5340 | | |
5341 | | /* Show Link State Request Retransmission thread. */ |
5342 | 0 | if (use_json) { |
5343 | 0 | if (nbr->t_ls_req != NULL) |
5344 | 0 | json_object_string_add( |
5345 | 0 | json_neigh, |
5346 | 0 | "threadLinkStateRequestRetransmission", "on"); |
5347 | 0 | } else |
5348 | 0 | vty_out(vty, |
5349 | 0 | " Thread Link State Request Retransmission %s\n", |
5350 | 0 | nbr->t_ls_req != NULL ? "on" : "off"); |
5351 | | |
5352 | | /* Show Link State Update Retransmission thread. */ |
5353 | 0 | if (use_json) { |
5354 | 0 | if (nbr->t_ls_upd != NULL) |
5355 | 0 | json_object_string_add( |
5356 | 0 | json_neigh, |
5357 | 0 | "threadLinkStateUpdateRetransmission", |
5358 | 0 | "on"); |
5359 | 0 | } else |
5360 | 0 | vty_out(vty, |
5361 | 0 | " Thread Link State Update Retransmission %s\n\n", |
5362 | 0 | nbr->t_ls_upd != NULL ? "on" : "off"); |
5363 | |
|
5364 | 0 | if (!use_json) { |
5365 | 0 | vty_out(vty, " Graceful restart Helper info:\n"); |
5366 | |
|
5367 | 0 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { |
5368 | 0 | vty_out(vty, |
5369 | 0 | " Graceful Restart HELPER Status : Inprogress.\n"); |
5370 | |
|
5371 | 0 | vty_out(vty, |
5372 | 0 | " Graceful Restart grace period time: %d (seconds).\n", |
5373 | 0 | nbr->gr_helper_info.recvd_grace_period); |
5374 | 0 | vty_out(vty, " Graceful Restart reason: %s.\n", |
5375 | 0 | ospf_restart_reason2str( |
5376 | 0 | nbr->gr_helper_info.gr_restart_reason)); |
5377 | 0 | } else { |
5378 | 0 | vty_out(vty, |
5379 | 0 | " Graceful Restart HELPER Status : None\n"); |
5380 | 0 | } |
5381 | |
|
5382 | 0 | if (nbr->gr_helper_info.rejected_reason |
5383 | 0 | != OSPF_HELPER_REJECTED_NONE) |
5384 | 0 | vty_out(vty, " Helper rejected reason: %s.\n", |
5385 | 0 | ospf_rejected_reason2str( |
5386 | 0 | nbr->gr_helper_info.rejected_reason)); |
5387 | |
|
5388 | 0 | if (nbr->gr_helper_info.helper_exit_reason |
5389 | 0 | != OSPF_GR_HELPER_EXIT_NONE) |
5390 | 0 | vty_out(vty, " Last helper exit reason: %s.\n\n", |
5391 | 0 | ospf_exit_reason2str( |
5392 | 0 | nbr->gr_helper_info.helper_exit_reason)); |
5393 | 0 | else |
5394 | 0 | vty_out(vty, "\n"); |
5395 | 0 | } else { |
5396 | 0 | json_object_string_add(json_neigh, "grHelperStatus", |
5397 | 0 | OSPF_GR_IS_ACTIVE_HELPER(nbr) ? |
5398 | 0 | "Inprogress" |
5399 | 0 | : "None"); |
5400 | 0 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { |
5401 | 0 | json_object_int_add( |
5402 | 0 | json_neigh, "graceInterval", |
5403 | 0 | nbr->gr_helper_info.recvd_grace_period); |
5404 | 0 | json_object_string_add( |
5405 | 0 | json_neigh, "grRestartReason", |
5406 | 0 | ospf_restart_reason2str( |
5407 | 0 | nbr->gr_helper_info.gr_restart_reason)); |
5408 | 0 | } |
5409 | |
|
5410 | 0 | if (nbr->gr_helper_info.rejected_reason |
5411 | 0 | != OSPF_HELPER_REJECTED_NONE) |
5412 | 0 | json_object_string_add( |
5413 | 0 | json_neigh, "helperRejectReason", |
5414 | 0 | ospf_rejected_reason2str( |
5415 | 0 | nbr->gr_helper_info.rejected_reason)); |
5416 | |
|
5417 | 0 | if (nbr->gr_helper_info.helper_exit_reason |
5418 | 0 | != OSPF_GR_HELPER_EXIT_NONE) |
5419 | 0 | json_object_string_add( |
5420 | 0 | json_neigh, "helperExitReason", |
5421 | 0 | ospf_exit_reason2str( |
5422 | 0 | nbr->gr_helper_info |
5423 | 0 | .helper_exit_reason)); |
5424 | 0 | } |
5425 | |
|
5426 | 0 | bfd_sess_show(vty, json_neigh, nbr->bfd_session); |
5427 | |
|
5428 | 0 | if (use_json) |
5429 | 0 | json_object_array_add(json_neigh_array, json_neigh); |
5430 | |
|
5431 | 0 | } |
5432 | | |
5433 | | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, |
5434 | | struct in_addr *router_id, |
5435 | | bool use_json, uint8_t use_vrf, |
5436 | | bool is_detail, |
5437 | | json_object *json_vrf) |
5438 | 0 | { |
5439 | 0 | struct listnode *node; |
5440 | 0 | struct ospf_neighbor *nbr; |
5441 | 0 | struct ospf_interface *oi; |
5442 | 0 | json_object *json = NULL; |
5443 | |
|
5444 | 0 | if (use_json) |
5445 | 0 | json = json_object_new_object(); |
5446 | |
|
5447 | 0 | if (ospf->instance) { |
5448 | 0 | if (use_json) |
5449 | 0 | json_object_int_add(json, "ospfInstance", |
5450 | 0 | ospf->instance); |
5451 | 0 | else |
5452 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
5453 | 0 | } |
5454 | |
|
5455 | 0 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
5456 | |
|
5457 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5458 | 0 | nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id); |
5459 | |
|
5460 | 0 | if (!nbr) |
5461 | 0 | continue; |
5462 | | |
5463 | 0 | if (is_detail) |
5464 | 0 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5465 | 0 | json, use_json); |
5466 | 0 | else |
5467 | 0 | show_ip_ospf_neighbour_brief(vty, nbr, NULL, json, |
5468 | 0 | use_json); |
5469 | 0 | } |
5470 | |
|
5471 | 0 | if (json_vrf && use_json) { |
5472 | 0 | json_object_object_add( |
5473 | 0 | json_vrf, |
5474 | 0 | (ospf->vrf_id == VRF_DEFAULT) ? "default" : ospf->name, |
5475 | 0 | json); |
5476 | 0 | return CMD_SUCCESS; |
5477 | 0 | } |
5478 | | |
5479 | 0 | if (use_json) |
5480 | 0 | vty_json(vty, json); |
5481 | 0 | else |
5482 | 0 | vty_out(vty, "\n"); |
5483 | |
|
5484 | 0 | return CMD_SUCCESS; |
5485 | 0 | } |
5486 | | |
5487 | | DEFPY(show_ip_ospf_neighbor_id, |
5488 | | show_ip_ospf_neighbor_id_cmd, |
5489 | | "show ip ospf [vrf NAME$vrf_name] neighbor A.B.C.D$router_id [detail$detail] [json$json]", |
5490 | | SHOW_STR |
5491 | | IP_STR |
5492 | | "OSPF information\n" |
5493 | | VRF_CMD_HELP_STR |
5494 | | "Neighbor list\n" |
5495 | | "Neighbor ID\n" |
5496 | | "Detailed output\n" |
5497 | | JSON_STR) |
5498 | 0 | { |
5499 | 0 | struct ospf *ospf; |
5500 | 0 | struct listnode *node; |
5501 | 0 | int ret = CMD_SUCCESS; |
5502 | 0 | int inst = 0; |
5503 | |
|
5504 | 0 | if (vrf_name && !strmatch(vrf_name, "all")) { |
5505 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
5506 | 0 | if (ospf == NULL || !ospf->oi_running) { |
5507 | 0 | if (!json) |
5508 | 0 | vty_out(vty, |
5509 | 0 | "%% OSPF is not enabled in vrf %s\n", |
5510 | 0 | vrf_name); |
5511 | 0 | else |
5512 | 0 | vty_json_empty(vty); |
5513 | 0 | return CMD_SUCCESS; |
5514 | 0 | } |
5515 | 0 | ret = show_ip_ospf_neighbor_id_common( |
5516 | 0 | vty, ospf, &router_id, !!json, 0, !!detail, NULL); |
5517 | 0 | } else { |
5518 | 0 | json_object *json_vrf = NULL; |
5519 | |
|
5520 | 0 | if (json) |
5521 | 0 | json_vrf = json_object_new_object(); |
5522 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5523 | 0 | if (!ospf->oi_running) |
5524 | 0 | continue; |
5525 | 0 | ret = show_ip_ospf_neighbor_id_common( |
5526 | 0 | vty, ospf, &router_id, !!json, 0, !!detail, |
5527 | 0 | json_vrf); |
5528 | 0 | } |
5529 | 0 | if (json) |
5530 | 0 | vty_json(vty, json_vrf); |
5531 | 0 | } |
5532 | | |
5533 | 0 | return ret; |
5534 | 0 | } |
5535 | | |
5536 | | DEFPY(show_ip_ospf_instance_neighbor_id, show_ip_ospf_instance_neighbor_id_cmd, |
5537 | | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]", |
5538 | | SHOW_STR IP_STR |
5539 | | "OSPF information\n" |
5540 | | "Instance ID\n" |
5541 | | "Neighbor list\n" |
5542 | | "Neighbor ID\n" |
5543 | | "Detailed output\n" JSON_STR) |
5544 | 0 | { |
5545 | 0 | struct ospf *ospf; |
5546 | |
|
5547 | 0 | if (instance != ospf_instance) |
5548 | 0 | return CMD_NOT_MY_INSTANCE; |
5549 | | |
5550 | 0 | ospf = ospf_lookup_instance(instance); |
5551 | 0 | if (!ospf || !ospf->oi_running) |
5552 | 0 | return CMD_SUCCESS; |
5553 | | |
5554 | 0 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, 0, |
5555 | 0 | !!detail, NULL); |
5556 | 0 | } |
5557 | | |
5558 | | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5559 | | struct ospf *ospf, |
5560 | | json_object *json, bool use_json, |
5561 | | uint8_t use_vrf) |
5562 | 0 | { |
5563 | 0 | struct ospf_interface *oi; |
5564 | 0 | struct listnode *node; |
5565 | 0 | json_object *json_vrf = NULL; |
5566 | 0 | json_object *json_nbr_sub = NULL; |
5567 | |
|
5568 | 0 | if (use_json) { |
5569 | 0 | if (use_vrf) |
5570 | 0 | json_vrf = json_object_new_object(); |
5571 | 0 | else |
5572 | 0 | json_vrf = json; |
5573 | |
|
5574 | 0 | json_nbr_sub = json_object_new_object(); |
5575 | 0 | } |
5576 | |
|
5577 | 0 | if (ospf->instance) { |
5578 | 0 | if (use_json) |
5579 | 0 | json_object_int_add(json, "ospfInstance", |
5580 | 0 | ospf->instance); |
5581 | 0 | else |
5582 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
5583 | 0 | } |
5584 | |
|
5585 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
5586 | |
|
5587 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5588 | 0 | struct route_node *rn; |
5589 | 0 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
5590 | |
|
5591 | 0 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5592 | 0 | nbr = rn->info; |
5593 | |
|
5594 | 0 | if (!nbr) |
5595 | 0 | continue; |
5596 | | |
5597 | 0 | if (nbr != oi->nbr_self) { |
5598 | 0 | if (nbr->state != NSM_Down) { |
5599 | 0 | show_ip_ospf_neighbor_detail_sub( |
5600 | 0 | vty, oi, nbr, prev_nbr, |
5601 | 0 | json_nbr_sub, use_json); |
5602 | 0 | } |
5603 | 0 | } |
5604 | 0 | prev_nbr = nbr; |
5605 | 0 | } |
5606 | 0 | } |
5607 | |
|
5608 | 0 | if (use_json) { |
5609 | 0 | json_object_object_add(json_vrf, "neighbors", |
5610 | 0 | json_nbr_sub); |
5611 | 0 | if (use_vrf) |
5612 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
5613 | 0 | json_vrf); |
5614 | 0 | } else |
5615 | 0 | vty_out(vty, "\n"); |
5616 | |
|
5617 | 0 | return CMD_SUCCESS; |
5618 | 0 | } |
5619 | | |
5620 | | DEFPY(show_ip_ospf_neighbor_detail, |
5621 | | show_ip_ospf_neighbor_detail_cmd, |
5622 | | "show ip ospf [vrf <NAME|all>$vrf_name] neighbor detail [json$json]", |
5623 | | SHOW_STR |
5624 | | IP_STR |
5625 | | "OSPF information\n" |
5626 | | VRF_CMD_HELP_STR |
5627 | | "All VRFs\n" |
5628 | | "Neighbor list\n" |
5629 | | "detail of all neighbors\n" |
5630 | | JSON_STR) |
5631 | 0 | { |
5632 | 0 | struct ospf *ospf; |
5633 | 0 | struct listnode *node = NULL; |
5634 | 0 | int ret = CMD_SUCCESS; |
5635 | 0 | int inst = 0; |
5636 | 0 | uint8_t use_vrf = 0; |
5637 | 0 | json_object *json_vrf = NULL; |
5638 | |
|
5639 | 0 | if (json) |
5640 | 0 | json_vrf = json_object_new_object(); |
5641 | | |
5642 | | /* vrf input is provided could be all or specific vrf*/ |
5643 | 0 | if (vrf_name) { |
5644 | 0 | use_vrf = 1; |
5645 | 0 | if (strmatch(vrf_name, "all")) { |
5646 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5647 | 0 | if (!ospf->oi_running) |
5648 | 0 | continue; |
5649 | 0 | ret = show_ip_ospf_neighbor_detail_common( |
5650 | 0 | vty, ospf, json_vrf, !!json, use_vrf); |
5651 | 0 | } |
5652 | 0 | if (json) |
5653 | 0 | vty_json(vty, json_vrf); |
5654 | |
|
5655 | 0 | return ret; |
5656 | 0 | } |
5657 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
5658 | 0 | if (ospf == NULL || !ospf->oi_running) { |
5659 | 0 | if (json) |
5660 | 0 | vty_json(vty, json_vrf); |
5661 | 0 | else |
5662 | 0 | vty_out(vty, |
5663 | 0 | "%% OSPF is not enabled in vrf %s\n", |
5664 | 0 | vrf_name); |
5665 | 0 | return CMD_SUCCESS; |
5666 | 0 | } |
5667 | 0 | } else { |
5668 | | /* Display default ospf (instance 0) info */ |
5669 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
5670 | 0 | if (ospf == NULL || !ospf->oi_running) { |
5671 | 0 | if (json) |
5672 | 0 | vty_json(vty, json_vrf); |
5673 | 0 | else |
5674 | 0 | vty_out(vty, "%% OSPF is not enabled\n"); |
5675 | 0 | return CMD_SUCCESS; |
5676 | 0 | } |
5677 | 0 | } |
5678 | | |
5679 | 0 | if (ospf) |
5680 | 0 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json_vrf, |
5681 | 0 | !!json, use_vrf); |
5682 | |
|
5683 | 0 | if (json) |
5684 | 0 | vty_json(vty, json_vrf); |
5685 | |
|
5686 | 0 | return ret; |
5687 | 0 | } |
5688 | | |
5689 | | DEFUN (show_ip_ospf_instance_neighbor_detail, |
5690 | | show_ip_ospf_instance_neighbor_detail_cmd, |
5691 | | "show ip ospf (1-65535) neighbor detail [json]", |
5692 | | SHOW_STR |
5693 | | IP_STR |
5694 | | "OSPF information\n" |
5695 | | "Instance ID\n" |
5696 | | "Neighbor list\n" |
5697 | | "detail of all neighbors\n" |
5698 | | JSON_STR) |
5699 | 0 | { |
5700 | 0 | int idx_number = 3; |
5701 | 0 | struct ospf *ospf; |
5702 | 0 | unsigned short instance = 0; |
5703 | 0 | bool uj = use_json(argc, argv); |
5704 | 0 | json_object *json = NULL; |
5705 | 0 | int ret = CMD_SUCCESS; |
5706 | |
|
5707 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
5708 | 0 | if (instance != ospf_instance) |
5709 | 0 | return CMD_NOT_MY_INSTANCE; |
5710 | | |
5711 | 0 | ospf = ospf_lookup_instance(instance); |
5712 | 0 | if (!ospf || !ospf->oi_running) |
5713 | 0 | return CMD_SUCCESS; |
5714 | | |
5715 | 0 | if (uj) |
5716 | 0 | json = json_object_new_object(); |
5717 | |
|
5718 | 0 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); |
5719 | |
|
5720 | 0 | if (uj) |
5721 | 0 | vty_json(vty, json); |
5722 | |
|
5723 | 0 | return ret; |
5724 | 0 | } |
5725 | | |
5726 | | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5727 | | struct ospf *ospf, |
5728 | | json_object *json, |
5729 | | bool use_json, |
5730 | | uint8_t use_vrf) |
5731 | 0 | { |
5732 | 0 | struct listnode *node; |
5733 | 0 | struct ospf_interface *oi; |
5734 | 0 | json_object *json_vrf = NULL; |
5735 | |
|
5736 | 0 | if (use_json) { |
5737 | 0 | if (use_vrf) |
5738 | 0 | json_vrf = json_object_new_object(); |
5739 | 0 | else |
5740 | 0 | json_vrf = json; |
5741 | 0 | } |
5742 | |
|
5743 | 0 | if (ospf->instance) { |
5744 | 0 | if (use_json) |
5745 | 0 | json_object_int_add(json, "ospfInstance", |
5746 | 0 | ospf->instance); |
5747 | 0 | else |
5748 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
5749 | 0 | } |
5750 | |
|
5751 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
5752 | |
|
5753 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5754 | 0 | struct route_node *rn; |
5755 | 0 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
5756 | 0 | struct ospf_nbr_nbma *nbr_nbma; |
5757 | |
|
5758 | 0 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5759 | 0 | nbr = rn->info; |
5760 | |
|
5761 | 0 | if (!nbr) |
5762 | 0 | continue; |
5763 | | |
5764 | 0 | if (nbr != oi->nbr_self) |
5765 | 0 | if (nbr->state != NSM_Down) |
5766 | 0 | show_ip_ospf_neighbor_detail_sub( |
5767 | 0 | vty, oi, rn->info, prev_nbr, |
5768 | 0 | json_vrf, use_json); |
5769 | 0 | prev_nbr = nbr; |
5770 | 0 | } |
5771 | |
|
5772 | 0 | if (oi->type != OSPF_IFTYPE_NBMA) |
5773 | 0 | continue; |
5774 | | |
5775 | 0 | struct listnode *nd; |
5776 | |
|
5777 | 0 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { |
5778 | 0 | if (nbr_nbma->nbr == NULL || |
5779 | 0 | nbr_nbma->nbr->state == NSM_Down) |
5780 | 0 | show_ip_ospf_nbr_nbma_detail_sub( |
5781 | 0 | vty, oi, nbr_nbma, use_json, json_vrf); |
5782 | 0 | } |
5783 | 0 | } |
5784 | |
|
5785 | 0 | if (use_json) { |
5786 | 0 | if (use_vrf) |
5787 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
5788 | 0 | json_vrf); |
5789 | 0 | } else { |
5790 | 0 | vty_out(vty, "\n"); |
5791 | 0 | } |
5792 | |
|
5793 | 0 | return CMD_SUCCESS; |
5794 | 0 | } |
5795 | | |
5796 | | DEFUN (show_ip_ospf_neighbor_detail_all, |
5797 | | show_ip_ospf_neighbor_detail_all_cmd, |
5798 | | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
5799 | | SHOW_STR |
5800 | | IP_STR |
5801 | | "OSPF information\n" |
5802 | | VRF_CMD_HELP_STR |
5803 | | "All VRFs\n" |
5804 | | "Neighbor list\n" |
5805 | | "detail of all neighbors\n" |
5806 | | "include down status neighbor\n" |
5807 | | JSON_STR) |
5808 | 0 | { |
5809 | 0 | struct ospf *ospf; |
5810 | 0 | bool uj = use_json(argc, argv); |
5811 | 0 | struct listnode *node = NULL; |
5812 | 0 | char *vrf_name = NULL; |
5813 | 0 | bool all_vrf = false; |
5814 | 0 | int ret = CMD_SUCCESS; |
5815 | 0 | int inst = 0; |
5816 | 0 | int idx_vrf = 0; |
5817 | 0 | uint8_t use_vrf = 0; |
5818 | 0 | json_object *json = NULL; |
5819 | |
|
5820 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
5821 | |
|
5822 | 0 | if (uj) |
5823 | 0 | json = json_object_new_object(); |
5824 | | |
5825 | | /* vrf input is provided could be all or specific vrf*/ |
5826 | 0 | if (vrf_name) { |
5827 | 0 | use_vrf = 1; |
5828 | 0 | if (all_vrf) { |
5829 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5830 | 0 | if (!ospf->oi_running) |
5831 | 0 | continue; |
5832 | 0 | ret = show_ip_ospf_neighbor_detail_all_common( |
5833 | 0 | vty, ospf, json, uj, use_vrf); |
5834 | 0 | } |
5835 | |
|
5836 | 0 | if (uj) |
5837 | 0 | vty_json(vty, json); |
5838 | |
|
5839 | 0 | return ret; |
5840 | 0 | } |
5841 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
5842 | 0 | if (ospf == NULL || !ospf->oi_running) { |
5843 | 0 | if (uj) |
5844 | 0 | json_object_free(json); |
5845 | 0 | return CMD_SUCCESS; |
5846 | 0 | } |
5847 | 0 | } else { |
5848 | | /* Display default ospf (instance 0) info */ |
5849 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
5850 | 0 | if (ospf == NULL || !ospf->oi_running) { |
5851 | 0 | if (uj) |
5852 | 0 | json_object_free(json); |
5853 | 0 | return CMD_SUCCESS; |
5854 | 0 | } |
5855 | 0 | } |
5856 | | |
5857 | 0 | if (ospf) { |
5858 | 0 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, |
5859 | 0 | uj, use_vrf); |
5860 | 0 | if (uj) { |
5861 | 0 | vty_out(vty, "%s\n", |
5862 | 0 | json_object_to_json_string_ext( |
5863 | 0 | json, JSON_C_TO_STRING_PRETTY)); |
5864 | 0 | } |
5865 | 0 | } |
5866 | |
|
5867 | 0 | if (uj) |
5868 | 0 | json_object_free(json); |
5869 | |
|
5870 | 0 | return ret; |
5871 | 0 | } |
5872 | | |
5873 | | DEFUN (show_ip_ospf_instance_neighbor_detail_all, |
5874 | | show_ip_ospf_instance_neighbor_detail_all_cmd, |
5875 | | "show ip ospf (1-65535) neighbor detail all [json]", |
5876 | | SHOW_STR |
5877 | | IP_STR |
5878 | | "OSPF information\n" |
5879 | | "Instance ID\n" |
5880 | | "Neighbor list\n" |
5881 | | "detail of all neighbors\n" |
5882 | | "include down status neighbor\n" |
5883 | | JSON_STR) |
5884 | 0 | { |
5885 | 0 | int idx_number = 3; |
5886 | 0 | struct ospf *ospf; |
5887 | 0 | unsigned short instance = 0; |
5888 | 0 | bool uj = use_json(argc, argv); |
5889 | 0 | json_object *json = NULL; |
5890 | 0 | int ret = CMD_SUCCESS; |
5891 | |
|
5892 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
5893 | 0 | if (instance != ospf_instance) |
5894 | 0 | return CMD_NOT_MY_INSTANCE; |
5895 | | |
5896 | 0 | ospf = ospf_lookup_instance(instance); |
5897 | 0 | if (!ospf || !ospf->oi_running) |
5898 | 0 | return CMD_SUCCESS; |
5899 | | |
5900 | 0 | if (uj) |
5901 | 0 | json = json_object_new_object(); |
5902 | |
|
5903 | 0 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); |
5904 | |
|
5905 | 0 | if (uj) |
5906 | 0 | vty_json(vty, json); |
5907 | |
|
5908 | 0 | return ret; |
5909 | 0 | } |
5910 | | |
5911 | | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5912 | | struct ospf *ospf, |
5913 | | const char *ifname, |
5914 | | bool use_json, |
5915 | | json_object *json_vrf) |
5916 | 0 | { |
5917 | 0 | struct ospf_interface *oi; |
5918 | 0 | struct interface *ifp; |
5919 | 0 | struct route_node *rn, *nrn; |
5920 | 0 | struct ospf_neighbor *nbr; |
5921 | 0 | json_object *json = NULL; |
5922 | |
|
5923 | 0 | if (use_json) { |
5924 | 0 | json = json_object_new_object(); |
5925 | 0 | if (json_vrf) |
5926 | 0 | json_object_object_add(json_vrf, |
5927 | 0 | (ospf->vrf_id == VRF_DEFAULT) |
5928 | 0 | ? "default" |
5929 | 0 | : ospf->name, |
5930 | 0 | json); |
5931 | 0 | } |
5932 | |
|
5933 | 0 | if (ospf->instance) { |
5934 | 0 | if (use_json) |
5935 | 0 | json_object_int_add(json, "ospfInstance", |
5936 | 0 | ospf->instance); |
5937 | 0 | else |
5938 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
5939 | 0 | } |
5940 | |
|
5941 | 0 | ifp = if_lookup_by_name(ifname, ospf->vrf_id); |
5942 | 0 | if (!ifp) { |
5943 | 0 | if (!use_json) { |
5944 | 0 | vty_out(vty, "No such interface.\n"); |
5945 | 0 | } else { |
5946 | 0 | if (!json_vrf) |
5947 | 0 | vty_json(vty, json); |
5948 | 0 | } |
5949 | 0 | return CMD_WARNING; |
5950 | 0 | } |
5951 | | |
5952 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
5953 | 0 | oi = rn->info; |
5954 | |
|
5955 | 0 | if (!oi) |
5956 | 0 | continue; |
5957 | | |
5958 | 0 | for (nrn = route_top(oi->nbrs); nrn; nrn = route_next(nrn)) { |
5959 | 0 | nbr = nrn->info; |
5960 | |
|
5961 | 0 | if (!nbr) |
5962 | 0 | continue; |
5963 | | |
5964 | 0 | if (nbr == oi->nbr_self) |
5965 | 0 | continue; |
5966 | | |
5967 | 0 | if (nbr->state == NSM_Down) |
5968 | 0 | continue; |
5969 | | |
5970 | 0 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5971 | 0 | json, use_json); |
5972 | 0 | } |
5973 | 0 | } |
5974 | |
|
5975 | 0 | if (use_json) { |
5976 | 0 | if (!json_vrf) |
5977 | 0 | vty_json(vty, json); |
5978 | 0 | } else { |
5979 | 0 | vty_out(vty, "\n"); |
5980 | 0 | } |
5981 | |
|
5982 | 0 | return CMD_SUCCESS; |
5983 | 0 | } |
5984 | | |
5985 | | DEFPY(show_ip_ospf_neighbor_int, |
5986 | | show_ip_ospf_neighbor_int_cmd, |
5987 | | "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname [json$json]", |
5988 | | SHOW_STR |
5989 | | IP_STR |
5990 | | "OSPF information\n" |
5991 | | VRF_CMD_HELP_STR |
5992 | | "Neighbor list\n" |
5993 | | "Interface name\n" |
5994 | | JSON_STR) |
5995 | 0 | { |
5996 | 0 | struct ospf *ospf; |
5997 | 0 | int ret = CMD_SUCCESS; |
5998 | 0 | struct interface *ifp = NULL; |
5999 | 0 | vrf_id_t vrf_id = VRF_DEFAULT; |
6000 | 0 | struct vrf *vrf = NULL; |
6001 | |
|
6002 | 0 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) |
6003 | 0 | vrf_name = NULL; |
6004 | 0 | if (vrf_name) { |
6005 | 0 | vrf = vrf_lookup_by_name(vrf_name); |
6006 | 0 | if (vrf) |
6007 | 0 | vrf_id = vrf->vrf_id; |
6008 | 0 | } |
6009 | 0 | ospf = ospf_lookup_by_vrf_id(vrf_id); |
6010 | |
|
6011 | 0 | if (!ospf || !ospf->oi_running) { |
6012 | 0 | if (json) |
6013 | 0 | vty_json_empty(vty); |
6014 | 0 | return ret; |
6015 | 0 | } |
6016 | | |
6017 | 0 | if (!json) |
6018 | 0 | show_ip_ospf_neighbour_header(vty); |
6019 | |
|
6020 | 0 | ifp = if_lookup_by_name(ifname, vrf_id); |
6021 | 0 | if (!ifp) { |
6022 | 0 | if (json) |
6023 | 0 | vty_json_empty(vty); |
6024 | 0 | else |
6025 | 0 | vty_out(vty, "No such interface.\n"); |
6026 | 0 | return ret; |
6027 | 0 | } |
6028 | | |
6029 | 0 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, ifname, !!json, 0); |
6030 | 0 | return ret; |
6031 | 0 | } |
6032 | | |
6033 | | DEFPY(show_ip_ospf_neighbor_int_detail, |
6034 | | show_ip_ospf_neighbor_int_detail_cmd, |
6035 | | "show ip ospf [vrf NAME$vrf_name] neighbor IFNAME$ifname detail [json$json]", |
6036 | | SHOW_STR |
6037 | | IP_STR |
6038 | | "OSPF information\n" |
6039 | | VRF_CMD_HELP_STR |
6040 | | "Neighbor list\n" |
6041 | | "Interface name\n" |
6042 | | "detail of all neighbors\n" |
6043 | | JSON_STR) |
6044 | 0 | { |
6045 | 0 | struct ospf *ospf; |
6046 | 0 | struct listnode *node = NULL; |
6047 | 0 | int ret = CMD_SUCCESS; |
6048 | 0 | bool ospf_output = false; |
6049 | |
|
6050 | 0 | if (vrf_name && !strmatch(vrf_name, "all")) { |
6051 | 0 | int inst = 0; |
6052 | |
|
6053 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
6054 | 0 | if (ospf == NULL || !ospf->oi_running) { |
6055 | 0 | if (!json) |
6056 | 0 | vty_out(vty, |
6057 | 0 | "%% OSPF is not enabled in vrf %s\n", |
6058 | 0 | vrf_name); |
6059 | 0 | else |
6060 | 0 | vty_json_empty(vty); |
6061 | 0 | return CMD_SUCCESS; |
6062 | 0 | } |
6063 | 0 | return show_ip_ospf_neighbor_int_detail_common( |
6064 | 0 | vty, ospf, ifname, !!json, NULL); |
6065 | 0 | } |
6066 | | |
6067 | 0 | json_object *json_vrf = NULL; |
6068 | |
|
6069 | 0 | if (json) |
6070 | 0 | json_vrf = json_object_new_object(); |
6071 | |
|
6072 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
6073 | 0 | if (!ospf->oi_running) |
6074 | 0 | continue; |
6075 | 0 | ospf_output = true; |
6076 | 0 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, ifname, |
6077 | 0 | !!json, json_vrf); |
6078 | 0 | } |
6079 | |
|
6080 | 0 | if (json) { |
6081 | 0 | vty_json(vty, json_vrf); |
6082 | 0 | return ret; |
6083 | 0 | } |
6084 | | |
6085 | 0 | if (!ospf_output) |
6086 | 0 | vty_out(vty, "%% OSPF instance not found\n"); |
6087 | |
|
6088 | 0 | return ret; |
6089 | 0 | } |
6090 | | |
6091 | | DEFPY(show_ip_ospf_instance_neighbor_int_detail, |
6092 | | show_ip_ospf_instance_neighbor_int_detail_cmd, |
6093 | | "show ip ospf (1-65535)$instance neighbor IFNAME$ifname detail [json$json]", |
6094 | | SHOW_STR |
6095 | | IP_STR |
6096 | | "OSPF information\n" |
6097 | | "Instance ID\n" |
6098 | | "Neighbor list\n" |
6099 | | "Interface name\n" |
6100 | | "detail of all neighbors\n" |
6101 | | JSON_STR) |
6102 | 0 | { |
6103 | 0 | struct ospf *ospf; |
6104 | |
|
6105 | 0 | if (instance != ospf_instance) |
6106 | 0 | return CMD_NOT_MY_INSTANCE; |
6107 | | |
6108 | 0 | ospf = ospf_lookup_instance(instance); |
6109 | 0 | if (!ospf || !ospf->oi_running) |
6110 | 0 | return CMD_SUCCESS; |
6111 | | |
6112 | 0 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, ifname, |
6113 | 0 | !!json, NULL); |
6114 | 0 | } |
6115 | | |
6116 | | /* Show functions */ |
6117 | | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self, |
6118 | | json_object *json_lsa) |
6119 | 0 | { |
6120 | 0 | struct router_lsa *rl; |
6121 | 0 | struct summary_lsa *sl; |
6122 | 0 | struct as_external_lsa *asel; |
6123 | 0 | struct prefix_ipv4 p; |
6124 | |
|
6125 | 0 | if (lsa == NULL) |
6126 | 0 | return 0; |
6127 | | |
6128 | | /* If self option is set, check LSA self flag. */ |
6129 | 0 | if (self == 0 || IS_LSA_SELF(lsa)) { |
6130 | |
|
6131 | 0 | if (!json_lsa) { |
6132 | | /* LSA common part show. */ |
6133 | 0 | vty_out(vty, "%-15pI4", &lsa->data->id); |
6134 | 0 | vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x", |
6135 | 0 | &lsa->data->adv_router, LS_AGE(lsa), |
6136 | 0 | (unsigned long)ntohl(lsa->data->ls_seqnum), |
6137 | 0 | ntohs(lsa->data->checksum)); |
6138 | 0 | } else { |
6139 | 0 | char seqnum[10]; |
6140 | 0 | char checksum[10]; |
6141 | |
|
6142 | 0 | snprintf(seqnum, sizeof(seqnum), "%x", |
6143 | 0 | ntohl(lsa->data->ls_seqnum)); |
6144 | 0 | snprintf(checksum, sizeof(checksum), "%x", |
6145 | 0 | ntohs(lsa->data->checksum)); |
6146 | 0 | json_object_string_addf(json_lsa, "lsId", "%pI4", |
6147 | 0 | &lsa->data->id); |
6148 | 0 | json_object_string_addf(json_lsa, "advertisedRouter", |
6149 | 0 | "%pI4", &lsa->data->adv_router); |
6150 | 0 | json_object_int_add(json_lsa, "lsaAge", LS_AGE(lsa)); |
6151 | 0 | json_object_string_add(json_lsa, "sequenceNumber", |
6152 | 0 | seqnum); |
6153 | 0 | json_object_string_add(json_lsa, "checksum", checksum); |
6154 | 0 | } |
6155 | | |
6156 | | /* LSA specific part show. */ |
6157 | 0 | switch (lsa->data->type) { |
6158 | 0 | case OSPF_ROUTER_LSA: |
6159 | 0 | rl = (struct router_lsa *)lsa->data; |
6160 | |
|
6161 | 0 | if (!json_lsa) |
6162 | 0 | vty_out(vty, " %-d", ntohs(rl->links)); |
6163 | 0 | else |
6164 | 0 | json_object_int_add(json_lsa, |
6165 | 0 | "numOfRouterLinks", |
6166 | 0 | ntohs(rl->links)); |
6167 | 0 | break; |
6168 | 0 | case OSPF_SUMMARY_LSA: |
6169 | 0 | sl = (struct summary_lsa *)lsa->data; |
6170 | |
|
6171 | 0 | p.family = AF_INET; |
6172 | 0 | p.prefix = sl->header.id; |
6173 | 0 | p.prefixlen = ip_masklen(sl->mask); |
6174 | 0 | apply_mask_ipv4(&p); |
6175 | |
|
6176 | 0 | if (!json_lsa) |
6177 | 0 | vty_out(vty, " %pFX", &p); |
6178 | 0 | else { |
6179 | 0 | json_object_string_addf( |
6180 | 0 | json_lsa, "summaryAddress", "%pFX", &p); |
6181 | 0 | } |
6182 | 0 | break; |
6183 | 0 | case OSPF_AS_EXTERNAL_LSA: |
6184 | 0 | case OSPF_AS_NSSA_LSA: |
6185 | 0 | asel = (struct as_external_lsa *)lsa->data; |
6186 | |
|
6187 | 0 | p.family = AF_INET; |
6188 | 0 | p.prefix = asel->header.id; |
6189 | 0 | p.prefixlen = ip_masklen(asel->mask); |
6190 | 0 | apply_mask_ipv4(&p); |
6191 | |
|
6192 | 0 | if (!json_lsa) |
6193 | 0 | vty_out(vty, " %s %pFX [0x%lx]", |
6194 | 0 | IS_EXTERNAL_METRIC(asel->e[0].tos) |
6195 | 0 | ? "E2" |
6196 | 0 | : "E1", |
6197 | 0 | &p, |
6198 | 0 | (unsigned long)ntohl( |
6199 | 0 | asel->e[0].route_tag)); |
6200 | 0 | else { |
6201 | 0 | json_object_string_add( |
6202 | 0 | json_lsa, "metricType", |
6203 | 0 | IS_EXTERNAL_METRIC(asel->e[0].tos) |
6204 | 0 | ? "E2" |
6205 | 0 | : "E1"); |
6206 | 0 | json_object_string_addf(json_lsa, "route", |
6207 | 0 | "%pFX", &p); |
6208 | 0 | json_object_int_add( |
6209 | 0 | json_lsa, "tag", |
6210 | 0 | (unsigned long)ntohl( |
6211 | 0 | asel->e[0].route_tag)); |
6212 | 0 | } |
6213 | 0 | break; |
6214 | 0 | case OSPF_NETWORK_LSA: |
6215 | 0 | case OSPF_ASBR_SUMMARY_LSA: |
6216 | 0 | case OSPF_OPAQUE_LINK_LSA: |
6217 | 0 | case OSPF_OPAQUE_AREA_LSA: |
6218 | 0 | case OSPF_OPAQUE_AS_LSA: |
6219 | 0 | default: |
6220 | 0 | break; |
6221 | 0 | } |
6222 | | |
6223 | 0 | if (!json_lsa) |
6224 | 0 | vty_out(vty, "\n"); |
6225 | 0 | } |
6226 | | |
6227 | 0 | return 1; |
6228 | 0 | } |
6229 | | |
6230 | | static const char *const show_database_desc[] = { |
6231 | | "unknown", |
6232 | | "Router Link States", |
6233 | | "Net Link States", |
6234 | | "Summary Link States", |
6235 | | "ASBR-Summary Link States", |
6236 | | "AS External Link States", |
6237 | | "Group Membership LSA", |
6238 | | "NSSA-external Link States", |
6239 | | "Type-8 LSA", |
6240 | | "Link-Local Opaque-LSA", |
6241 | | "Area-Local Opaque-LSA", |
6242 | | "AS-external Opaque-LSA", |
6243 | | }; |
6244 | | |
6245 | | static const char * const show_database_desc_json[] = { |
6246 | | "unknown", |
6247 | | "routerLinkStates", |
6248 | | "networkLinkStates", |
6249 | | "summaryLinkStates", |
6250 | | "asbrSummaryLinkStates", |
6251 | | "asExternalLinkStates", |
6252 | | "groupMembershipLsa", |
6253 | | "nssaExternalLinkStates", |
6254 | | "type8Lsa", |
6255 | | "linkLocalOpaqueLsa", |
6256 | | "areaLocalOpaqueLsa", |
6257 | | "asExternalOpaqueLsa", |
6258 | | }; |
6259 | | |
6260 | | static const char *const show_database_desc_count_json[] = { |
6261 | | "unknownCount", |
6262 | | "routerLinkStatesCount", |
6263 | | "networkLinkStatesCount", |
6264 | | "summaryLinkStatesCount", |
6265 | | "asbrSummaryLinkStatesCount", |
6266 | | "asExternalLinkStatesCount", |
6267 | | "groupMembershipLsaCount", |
6268 | | "nssaExternalLinkStatesCount", |
6269 | | "type8LsaCount", |
6270 | | "linkLocalOpaqueLsaCount", |
6271 | | "areaLocalOpaqueLsaCount", |
6272 | | "asExternalOpaqueLsaCount", |
6273 | | }; |
6274 | | |
6275 | | static const char *const show_database_header[] = { |
6276 | | "", |
6277 | | "Link ID ADV Router Age Seq# CkSum Link count", |
6278 | | "Link ID ADV Router Age Seq# CkSum", |
6279 | | "Link ID ADV Router Age Seq# CkSum Route", |
6280 | | "Link ID ADV Router Age Seq# CkSum", |
6281 | | "Link ID ADV Router Age Seq# CkSum Route", |
6282 | | " --- header for Group Member ----", |
6283 | | "Link ID ADV Router Age Seq# CkSum Route", |
6284 | | " --- type-8 ---", |
6285 | | "Opaque-Type/Id ADV Router Age Seq# CkSum", |
6286 | | "Opaque-Type/Id ADV Router Age Seq# CkSum", |
6287 | | "Opaque-Type/Id ADV Router Age Seq# CkSum", |
6288 | | }; |
6289 | | |
6290 | | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa, |
6291 | | json_object *json) |
6292 | 0 | { |
6293 | 0 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; |
6294 | |
|
6295 | 0 | if (!json) { |
6296 | 0 | if (IS_LSA_SELF(lsa)) |
6297 | 0 | vty_out(vty, " LS age: %d%s\n", LS_AGE(lsa), |
6298 | 0 | CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE) |
6299 | 0 | ? "(S-DNA)" |
6300 | 0 | : ""); |
6301 | 0 | else |
6302 | 0 | vty_out(vty, " LS age: %d%s\n", LS_AGE(lsa), |
6303 | 0 | CHECK_FLAG(lsa->data->ls_age, DO_NOT_AGE) |
6304 | 0 | ? "(DNA)" |
6305 | 0 | : ""); |
6306 | 0 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, |
6307 | 0 | ospf_options_dump(lsa->data->options)); |
6308 | 0 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, |
6309 | 0 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) |
6310 | 0 | ? "(Translated from Type-7)" |
6311 | 0 | : "")); |
6312 | |
|
6313 | 0 | if (lsa->data->type == OSPF_ROUTER_LSA) { |
6314 | 0 | vty_out(vty, " Flags: 0x%x", rlsa->flags); |
6315 | |
|
6316 | 0 | if (rlsa->flags) |
6317 | 0 | vty_out(vty, " :%s%s%s%s", |
6318 | 0 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" |
6319 | 0 | : "", |
6320 | 0 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" |
6321 | 0 | : "", |
6322 | 0 | IS_ROUTER_LSA_VIRTUAL(rlsa) |
6323 | 0 | ? " VL-endpoint" |
6324 | 0 | : "", |
6325 | 0 | IS_ROUTER_LSA_SHORTCUT(rlsa) |
6326 | 0 | ? " Shortcut" |
6327 | 0 | : ""); |
6328 | |
|
6329 | 0 | vty_out(vty, "\n"); |
6330 | 0 | } |
6331 | 0 | vty_out(vty, " LS Type: %s\n", |
6332 | 0 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); |
6333 | 0 | vty_out(vty, " Link State ID: %pI4 %s\n", |
6334 | 0 | &lsa->data->id, |
6335 | 0 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, |
6336 | 0 | NULL)); |
6337 | 0 | vty_out(vty, " Advertising Router: %pI4\n", |
6338 | 0 | &lsa->data->adv_router); |
6339 | 0 | vty_out(vty, " LS Seq Number: %08lx\n", |
6340 | 0 | (unsigned long)ntohl(lsa->data->ls_seqnum)); |
6341 | 0 | vty_out(vty, " Checksum: 0x%04x\n", |
6342 | 0 | ntohs(lsa->data->checksum)); |
6343 | 0 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); |
6344 | 0 | } else { |
6345 | 0 | char seqnum[10]; |
6346 | 0 | char checksum[10]; |
6347 | |
|
6348 | 0 | snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum)); |
6349 | 0 | snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum)); |
6350 | |
|
6351 | 0 | json_object_int_add(json, "lsaAge", LS_AGE(lsa)); |
6352 | 0 | json_object_string_add(json, "options", |
6353 | 0 | ospf_options_dump(lsa->data->options)); |
6354 | 0 | json_object_int_add(json, "lsaFlags", lsa->flags); |
6355 | |
|
6356 | 0 | if (lsa->flags & OSPF_LSA_LOCAL_XLT) |
6357 | 0 | json_object_boolean_true_add(json, |
6358 | 0 | "translatedFromType7"); |
6359 | |
|
6360 | 0 | if (lsa->data->type == OSPF_ROUTER_LSA) { |
6361 | 0 | json_object_int_add(json, "flags", rlsa->flags); |
6362 | |
|
6363 | 0 | if (rlsa->flags) { |
6364 | 0 | if (IS_ROUTER_LSA_BORDER(rlsa)) |
6365 | 0 | json_object_boolean_true_add(json, |
6366 | 0 | "abr"); |
6367 | 0 | if (IS_ROUTER_LSA_EXTERNAL(rlsa)) |
6368 | 0 | json_object_boolean_true_add(json, |
6369 | 0 | "asbr"); |
6370 | 0 | if (IS_ROUTER_LSA_VIRTUAL(rlsa)) |
6371 | 0 | json_object_boolean_true_add( |
6372 | 0 | json, "vlEndpoint"); |
6373 | 0 | if (IS_ROUTER_LSA_SHORTCUT(rlsa)) |
6374 | 0 | json_object_boolean_true_add( |
6375 | 0 | json, "shortcut"); |
6376 | 0 | } |
6377 | 0 | } |
6378 | |
|
6379 | 0 | json_object_string_add( |
6380 | 0 | json, "lsaType", |
6381 | 0 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); |
6382 | 0 | json_object_string_addf(json, "linkStateId", "%pI4", |
6383 | 0 | &lsa->data->id); |
6384 | 0 | json_object_string_addf(json, "advertisingRouter", "%pI4", |
6385 | 0 | &lsa->data->adv_router); |
6386 | 0 | json_object_string_add(json, "lsaSeqNumber", seqnum); |
6387 | 0 | json_object_string_add(json, "checksum", checksum); |
6388 | 0 | json_object_int_add(json, "length", ntohs(lsa->data->length)); |
6389 | 0 | } |
6390 | 0 | } |
6391 | | |
6392 | | static const char *const link_type_desc[] = { |
6393 | | "(null)", |
6394 | | "another Router (point-to-point)", |
6395 | | "a Transit Network", |
6396 | | "Stub Network", |
6397 | | "a Virtual Link", |
6398 | | }; |
6399 | | |
6400 | | static const char *const link_id_desc[] = { |
6401 | | "(null)", "Neighboring Router ID", "Designated Router address", |
6402 | | "Net", "Neighboring Router ID", |
6403 | | }; |
6404 | | |
6405 | | static const char *const link_data_desc[] = { |
6406 | | "(null)", "Router Interface address", "Router Interface address", |
6407 | | "Network Mask", "Router Interface address", |
6408 | | }; |
6409 | | |
6410 | | static const char *const link_id_desc_json[] = { |
6411 | | "null", "neighborRouterId", "designatedRouterAddress", |
6412 | | "networkAddress", "neighborRouterId", |
6413 | | }; |
6414 | | |
6415 | | static const char *const link_data_desc_json[] = { |
6416 | | "null", "routerInterfaceAddress", "routerInterfaceAddress", |
6417 | | "networkMask", "routerInterfaceAddress", |
6418 | | }; |
6419 | | |
6420 | | /* Show router-LSA each Link information. */ |
6421 | | static void show_ip_ospf_database_router_links(struct vty *vty, |
6422 | | struct router_lsa *rl, |
6423 | | json_object *json) |
6424 | 0 | { |
6425 | 0 | int len, type; |
6426 | 0 | unsigned short i; |
6427 | 0 | json_object *json_links = NULL; |
6428 | 0 | json_object *json_link = NULL; |
6429 | 0 | int metric = 0; |
6430 | 0 | char buf[PREFIX_STRLEN]; |
6431 | |
|
6432 | 0 | if (json) |
6433 | 0 | json_links = json_object_new_object(); |
6434 | |
|
6435 | 0 | len = ntohs(rl->header.length) - 4; |
6436 | 0 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { |
6437 | 0 | type = rl->link[i].type; |
6438 | |
|
6439 | 0 | if (json) { |
6440 | 0 | char link[16]; |
6441 | |
|
6442 | 0 | snprintf(link, sizeof(link), "link%u", i); |
6443 | 0 | json_link = json_object_new_object(); |
6444 | 0 | json_object_string_add(json_link, "linkType", |
6445 | 0 | link_type_desc[type]); |
6446 | 0 | json_object_string_add(json_link, |
6447 | 0 | link_id_desc_json[type], |
6448 | 0 | inet_ntop(AF_INET, |
6449 | 0 | &rl->link[i].link_id, |
6450 | 0 | buf, sizeof(buf))); |
6451 | 0 | json_object_string_add( |
6452 | 0 | json_link, link_data_desc_json[type], |
6453 | 0 | inet_ntop(AF_INET, &rl->link[i].link_data, |
6454 | 0 | buf, sizeof(buf))); |
6455 | 0 | json_object_int_add(json_link, "numOfTosMetrics", |
6456 | 0 | metric); |
6457 | 0 | json_object_int_add(json_link, "tos0Metric", |
6458 | 0 | ntohs(rl->link[i].metric)); |
6459 | 0 | json_object_object_add(json_links, link, json_link); |
6460 | 0 | } else { |
6461 | 0 | vty_out(vty, " Link connected to: %s\n", |
6462 | 0 | link_type_desc[type]); |
6463 | 0 | vty_out(vty, " (Link ID) %s: %pI4\n", |
6464 | 0 | link_id_desc[type], |
6465 | 0 | &rl->link[i].link_id); |
6466 | 0 | vty_out(vty, " (Link Data) %s: %pI4\n", |
6467 | 0 | link_data_desc[type], |
6468 | 0 | &rl->link[i].link_data); |
6469 | 0 | vty_out(vty, " Number of TOS metrics: 0\n"); |
6470 | 0 | vty_out(vty, " TOS 0 Metric: %d\n", |
6471 | 0 | ntohs(rl->link[i].metric)); |
6472 | 0 | vty_out(vty, "\n"); |
6473 | 0 | } |
6474 | 0 | } |
6475 | 0 | if (json) |
6476 | 0 | json_object_object_add(json, "routerLinks", json_links); |
6477 | 0 | } |
6478 | | |
6479 | | /* Show router-LSA detail information. */ |
6480 | | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6481 | | json_object *json) |
6482 | 0 | { |
6483 | 0 | if (lsa != NULL) { |
6484 | 0 | struct router_lsa *rl = (struct router_lsa *)lsa->data; |
6485 | |
|
6486 | 0 | show_ip_ospf_database_header(vty, lsa, json); |
6487 | |
|
6488 | 0 | if (!json) |
6489 | 0 | vty_out(vty, " Number of Links: %d\n\n", |
6490 | 0 | ntohs(rl->links)); |
6491 | 0 | else |
6492 | 0 | json_object_int_add(json, "numOfLinks", |
6493 | 0 | ntohs(rl->links)); |
6494 | |
|
6495 | 0 | show_ip_ospf_database_router_links(vty, rl, json); |
6496 | |
|
6497 | 0 | if (!json) |
6498 | 0 | vty_out(vty, "\n"); |
6499 | 0 | } |
6500 | |
|
6501 | 0 | return 0; |
6502 | 0 | } |
6503 | | |
6504 | | /* Show network-LSA detail information. */ |
6505 | | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6506 | | json_object *json) |
6507 | 0 | { |
6508 | 0 | int length, i; |
6509 | 0 | char buf[PREFIX_STRLEN]; |
6510 | 0 | json_object *json_attached_rt = NULL; |
6511 | 0 | json_object *json_router = NULL; |
6512 | |
|
6513 | 0 | if (json) |
6514 | 0 | json_attached_rt = json_object_new_object(); |
6515 | |
|
6516 | 0 | if (lsa != NULL) { |
6517 | 0 | struct network_lsa *nl = (struct network_lsa *)lsa->data; |
6518 | 0 | struct in_addr *addr; |
6519 | |
|
6520 | 0 | show_ip_ospf_database_header(vty, lsa, json); |
6521 | |
|
6522 | 0 | if (!json) |
6523 | 0 | vty_out(vty, " Network Mask: /%d\n", |
6524 | 0 | ip_masklen(nl->mask)); |
6525 | 0 | else |
6526 | 0 | json_object_int_add(json, "networkMask", |
6527 | 0 | ip_masklen(nl->mask)); |
6528 | |
|
6529 | 0 | length = lsa->size - OSPF_LSA_HEADER_SIZE - 4; |
6530 | 0 | addr = &nl->routers[0]; |
6531 | 0 | for (i = 0; length > 0 && addr; |
6532 | 0 | length -= 4, addr = &nl->routers[++i]) |
6533 | 0 | if (!json) { |
6534 | 0 | vty_out(vty, " Attached Router: %pI4\n", |
6535 | 0 | addr); |
6536 | 0 | vty_out(vty, "\n"); |
6537 | 0 | } else { |
6538 | 0 | json_router = json_object_new_object(); |
6539 | 0 | json_object_string_add( |
6540 | 0 | json_router, "attachedRouterId", |
6541 | 0 | inet_ntop(AF_INET, addr, buf, |
6542 | 0 | sizeof(buf))); |
6543 | 0 | json_object_object_add(json_attached_rt, |
6544 | 0 | inet_ntop(AF_INET, addr, |
6545 | 0 | buf, |
6546 | 0 | sizeof(buf)), |
6547 | 0 | json_router); |
6548 | 0 | } |
6549 | 0 | } |
6550 | |
|
6551 | 0 | if (json) |
6552 | 0 | json_object_object_add(json, "attchedRouters", |
6553 | 0 | json_attached_rt); |
6554 | |
|
6555 | 0 | return 0; |
6556 | 0 | } |
6557 | | |
6558 | | /* Show summary-LSA detail information. */ |
6559 | | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6560 | | json_object *json) |
6561 | 0 | { |
6562 | 0 | if (lsa != NULL) { |
6563 | 0 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; |
6564 | |
|
6565 | 0 | show_ip_ospf_database_header(vty, lsa, json); |
6566 | |
|
6567 | 0 | if (!json) { |
6568 | 0 | vty_out(vty, " Network Mask: /%d\n", |
6569 | 0 | ip_masklen(sl->mask)); |
6570 | 0 | vty_out(vty, " TOS: 0 Metric: %d\n", |
6571 | 0 | GET_METRIC(sl->metric)); |
6572 | 0 | vty_out(vty, "\n"); |
6573 | 0 | } else { |
6574 | 0 | json_object_int_add(json, "networkMask", |
6575 | 0 | ip_masklen(sl->mask)); |
6576 | 0 | json_object_int_add(json, "tos0Metric", |
6577 | 0 | GET_METRIC(sl->metric)); |
6578 | 0 | } |
6579 | 0 | } |
6580 | |
|
6581 | 0 | return 0; |
6582 | 0 | } |
6583 | | |
6584 | | /* Show summary-ASBR-LSA detail information. */ |
6585 | | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6586 | | json_object *json) |
6587 | 0 | { |
6588 | 0 | if (lsa != NULL) { |
6589 | 0 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; |
6590 | |
|
6591 | 0 | show_ip_ospf_database_header(vty, lsa, json); |
6592 | |
|
6593 | 0 | if (!json) { |
6594 | 0 | vty_out(vty, " Network Mask: /%d\n", |
6595 | 0 | ip_masklen(sl->mask)); |
6596 | 0 | vty_out(vty, " TOS: 0 Metric: %d\n", |
6597 | 0 | GET_METRIC(sl->metric)); |
6598 | 0 | vty_out(vty, "\n"); |
6599 | 0 | } else { |
6600 | 0 | json_object_int_add(json, "networkMask", |
6601 | 0 | ip_masklen(sl->mask)); |
6602 | 0 | json_object_int_add(json, "tos0Metric", |
6603 | 0 | GET_METRIC(sl->metric)); |
6604 | 0 | } |
6605 | 0 | } |
6606 | |
|
6607 | 0 | return 0; |
6608 | 0 | } |
6609 | | |
6610 | | /* Show AS-external-LSA detail information. */ |
6611 | | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6612 | | json_object *json) |
6613 | 0 | { |
6614 | 0 | int tos = 0; |
6615 | |
|
6616 | 0 | if (lsa != NULL) { |
6617 | 0 | struct as_external_lsa *al = |
6618 | 0 | (struct as_external_lsa *)lsa->data; |
6619 | |
|
6620 | 0 | show_ip_ospf_database_header(vty, lsa, json); |
6621 | |
|
6622 | 0 | if (!json) { |
6623 | 0 | vty_out(vty, " Network Mask: /%d\n", |
6624 | 0 | ip_masklen(al->mask)); |
6625 | 0 | vty_out(vty, " Metric Type: %s\n", |
6626 | 0 | IS_EXTERNAL_METRIC(al->e[0].tos) |
6627 | 0 | ? "2 (Larger than any link state path)" |
6628 | 0 | : "1"); |
6629 | 0 | vty_out(vty, " TOS: 0\n"); |
6630 | 0 | vty_out(vty, " Metric: %d\n", |
6631 | 0 | GET_METRIC(al->e[0].metric)); |
6632 | 0 | vty_out(vty, " Forward Address: %pI4\n", |
6633 | 0 | &al->e[0].fwd_addr); |
6634 | 0 | vty_out(vty, |
6635 | 0 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", |
6636 | 0 | (route_tag_t)ntohl(al->e[0].route_tag)); |
6637 | 0 | } else { |
6638 | 0 | json_object_int_add(json, "networkMask", |
6639 | 0 | ip_masklen(al->mask)); |
6640 | 0 | json_object_string_add( |
6641 | 0 | json, "metricType", |
6642 | 0 | IS_EXTERNAL_METRIC(al->e[0].tos) |
6643 | 0 | ? "E2 (Larger than any link state path)" |
6644 | 0 | : "E1"); |
6645 | 0 | json_object_int_add(json, "tos", tos); |
6646 | 0 | json_object_int_add(json, "metric", |
6647 | 0 | GET_METRIC(al->e[0].metric)); |
6648 | 0 | json_object_string_addf(json, "forwardAddress", "%pI4", |
6649 | 0 | &(al->e[0].fwd_addr)); |
6650 | 0 | json_object_int_add( |
6651 | 0 | json, "externalRouteTag", |
6652 | 0 | (route_tag_t)ntohl(al->e[0].route_tag)); |
6653 | 0 | } |
6654 | 0 | } |
6655 | |
|
6656 | 0 | return 0; |
6657 | 0 | } |
6658 | | |
6659 | | /* Show AS-NSSA-LSA detail information. */ |
6660 | | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6661 | | json_object *json) |
6662 | 0 | { |
6663 | 0 | int tos = 0; |
6664 | |
|
6665 | 0 | if (lsa != NULL) { |
6666 | 0 | struct as_external_lsa *al = |
6667 | 0 | (struct as_external_lsa *)lsa->data; |
6668 | |
|
6669 | 0 | show_ip_ospf_database_header(vty, lsa, json); |
6670 | |
|
6671 | 0 | if (!json) { |
6672 | 0 | vty_out(vty, " Network Mask: /%d\n", |
6673 | 0 | ip_masklen(al->mask)); |
6674 | 0 | vty_out(vty, " Metric Type: %s\n", |
6675 | 0 | IS_EXTERNAL_METRIC(al->e[0].tos) |
6676 | 0 | ? "2 (Larger than any link state path)" |
6677 | 0 | : "1"); |
6678 | 0 | vty_out(vty, " TOS: 0\n"); |
6679 | 0 | vty_out(vty, " Metric: %d\n", |
6680 | 0 | GET_METRIC(al->e[0].metric)); |
6681 | 0 | vty_out(vty, " NSSA: Forward Address: %pI4\n", |
6682 | 0 | &al->e[0].fwd_addr); |
6683 | 0 | vty_out(vty, |
6684 | 0 | " External Route Tag: %" ROUTE_TAG_PRI |
6685 | 0 | "\n\n", |
6686 | 0 | (route_tag_t)ntohl(al->e[0].route_tag)); |
6687 | 0 | } else { |
6688 | 0 | json_object_int_add(json, "networkMask", |
6689 | 0 | ip_masklen(al->mask)); |
6690 | 0 | json_object_string_add( |
6691 | 0 | json, "metricType", |
6692 | 0 | IS_EXTERNAL_METRIC(al->e[0].tos) |
6693 | 0 | ? "E2 (Larger than any link state path)" |
6694 | 0 | : "E1"); |
6695 | 0 | json_object_int_add(json, "tos", tos); |
6696 | 0 | json_object_int_add(json, "metric", |
6697 | 0 | GET_METRIC(al->e[0].metric)); |
6698 | 0 | json_object_string_addf(json, "nssaForwardAddress", |
6699 | 0 | "%pI4", &al->e[0].fwd_addr); |
6700 | 0 | json_object_int_add( |
6701 | 0 | json, "externalRouteTag", |
6702 | 0 | (route_tag_t)ntohl(al->e[0].route_tag)); |
6703 | 0 | } |
6704 | 0 | } |
6705 | |
|
6706 | 0 | return 0; |
6707 | 0 | } |
6708 | | |
6709 | | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa, |
6710 | | json_object *json) |
6711 | 0 | { |
6712 | 0 | return 0; |
6713 | 0 | } |
6714 | | |
6715 | | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6716 | | json_object *json) |
6717 | 0 | { |
6718 | 0 | if (lsa != NULL) { |
6719 | 0 | show_ip_ospf_database_header(vty, lsa, json); |
6720 | 0 | show_opaque_info_detail(vty, lsa, json); |
6721 | 0 | if (!json) |
6722 | 0 | vty_out(vty, "\n"); |
6723 | 0 | } |
6724 | 0 | return 0; |
6725 | 0 | } |
6726 | | |
6727 | | int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = { |
6728 | | NULL, |
6729 | | show_router_lsa_detail, |
6730 | | show_network_lsa_detail, |
6731 | | show_summary_lsa_detail, |
6732 | | show_summary_asbr_lsa_detail, |
6733 | | show_as_external_lsa_detail, |
6734 | | show_func_dummy, |
6735 | | show_as_nssa_lsa_detail, /* almost same as external */ |
6736 | | NULL, /* type-8 */ |
6737 | | show_opaque_lsa_detail, |
6738 | | show_opaque_lsa_detail, |
6739 | | show_opaque_lsa_detail, |
6740 | | }; |
6741 | | |
6742 | | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, |
6743 | | struct in_addr *id, struct in_addr *adv_router) |
6744 | 0 | { |
6745 | 0 | memset(lp, 0, sizeof(struct prefix_ls)); |
6746 | 0 | lp->family = AF_UNSPEC; |
6747 | 0 | if (id == NULL) |
6748 | 0 | lp->prefixlen = 0; |
6749 | 0 | else if (adv_router == NULL) { |
6750 | 0 | lp->prefixlen = IPV4_MAX_BITLEN; |
6751 | 0 | lp->id = *id; |
6752 | 0 | } else { |
6753 | 0 | lp->prefixlen = 64; |
6754 | 0 | lp->id = *id; |
6755 | 0 | lp->adv_router = *adv_router; |
6756 | 0 | } |
6757 | 0 | } |
6758 | | |
6759 | | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
6760 | | struct in_addr *id, struct in_addr *adv_router, |
6761 | | json_object *json) |
6762 | 0 | { |
6763 | 0 | struct prefix_ls lp; |
6764 | 0 | struct route_node *rn, *start; |
6765 | 0 | struct ospf_lsa *lsa; |
6766 | 0 | json_object *json_lsa = NULL; |
6767 | |
|
6768 | 0 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6769 | 0 | start = route_node_get(rt, (struct prefix *)&lp); |
6770 | 0 | if (start) { |
6771 | 0 | route_lock_node(start); |
6772 | 0 | for (rn = start; rn; rn = route_next_until(rn, start)) |
6773 | 0 | if ((lsa = rn->info)) { |
6774 | 0 | if (show_function[lsa->data->type] != NULL) { |
6775 | 0 | if (json) { |
6776 | 0 | json_lsa = |
6777 | 0 | json_object_new_object(); |
6778 | 0 | json_object_array_add(json, |
6779 | 0 | json_lsa); |
6780 | 0 | } |
6781 | |
|
6782 | 0 | show_function[lsa->data->type]( |
6783 | 0 | vty, lsa, json_lsa); |
6784 | 0 | } |
6785 | 0 | } |
6786 | 0 | route_unlock_node(start); |
6787 | 0 | } |
6788 | 0 | } |
6789 | | |
6790 | | /* Show detail LSA information |
6791 | | -- if id is NULL then show all LSAs. */ |
6792 | | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
6793 | | struct in_addr *id, struct in_addr *adv_router, |
6794 | | json_object *json) |
6795 | 0 | { |
6796 | 0 | struct listnode *node; |
6797 | 0 | struct ospf_area *area; |
6798 | 0 | char buf[PREFIX_STRLEN]; |
6799 | 0 | json_object *json_lsa_type = NULL; |
6800 | 0 | json_object *json_areas = NULL; |
6801 | 0 | json_object *json_lsa_array = NULL; |
6802 | |
|
6803 | 0 | switch (type) { |
6804 | 0 | case OSPF_AS_EXTERNAL_LSA: |
6805 | 0 | case OSPF_OPAQUE_AS_LSA: |
6806 | 0 | if (!json) |
6807 | 0 | vty_out(vty, " %s \n\n", |
6808 | 0 | show_database_desc[type]); |
6809 | 0 | else |
6810 | 0 | json_lsa_array = json_object_new_array(); |
6811 | |
|
6812 | 0 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router, |
6813 | 0 | json_lsa_array); |
6814 | 0 | if (json) |
6815 | 0 | json_object_object_add(json, |
6816 | 0 | show_database_desc_json[type], |
6817 | 0 | json_lsa_array); |
6818 | |
|
6819 | 0 | break; |
6820 | 0 | default: |
6821 | 0 | if (json) |
6822 | 0 | json_areas = json_object_new_object(); |
6823 | |
|
6824 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
6825 | 0 | if (!json) { |
6826 | 0 | vty_out(vty, |
6827 | 0 | "\n %s (Area %s)\n\n", |
6828 | 0 | show_database_desc[type], |
6829 | 0 | ospf_area_desc_string(area)); |
6830 | 0 | } else { |
6831 | 0 | json_lsa_array = json_object_new_array(); |
6832 | 0 | json_object_object_add(json_areas, |
6833 | 0 | inet_ntop(AF_INET, |
6834 | 0 | &area->area_id, |
6835 | 0 | buf, |
6836 | 0 | sizeof(buf)), |
6837 | 0 | json_lsa_array); |
6838 | 0 | } |
6839 | |
|
6840 | 0 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, |
6841 | 0 | adv_router, json_lsa_array); |
6842 | 0 | } |
6843 | |
|
6844 | 0 | if (json) { |
6845 | 0 | json_lsa_type = json_object_new_object(); |
6846 | 0 | json_object_object_add(json_lsa_type, "areas", |
6847 | 0 | json_areas); |
6848 | 0 | json_object_object_add(json, |
6849 | 0 | show_database_desc_json[type], |
6850 | 0 | json_lsa_type); |
6851 | 0 | } |
6852 | 0 | break; |
6853 | 0 | } |
6854 | 0 | } |
6855 | | |
6856 | | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6857 | | struct route_table *rt, |
6858 | | struct in_addr *adv_router, |
6859 | | json_object *json) |
6860 | 0 | { |
6861 | 0 | struct route_node *rn; |
6862 | 0 | struct ospf_lsa *lsa; |
6863 | 0 | json_object *json_lsa = NULL; |
6864 | |
|
6865 | 0 | for (rn = route_top(rt); rn; rn = route_next(rn)) |
6866 | 0 | if ((lsa = rn->info)) { |
6867 | 0 | if (IPV4_ADDR_SAME(adv_router, |
6868 | 0 | &lsa->data->adv_router)) { |
6869 | 0 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) |
6870 | 0 | continue; |
6871 | 0 | if (json) { |
6872 | 0 | json_lsa = json_object_new_object(); |
6873 | 0 | json_object_array_add(json, json_lsa); |
6874 | 0 | } |
6875 | |
|
6876 | 0 | if (show_function[lsa->data->type] != NULL) |
6877 | 0 | show_function[lsa->data->type]( |
6878 | 0 | vty, lsa, json_lsa); |
6879 | 0 | } |
6880 | 0 | } |
6881 | 0 | } |
6882 | | |
6883 | | /* Show detail LSA information. */ |
6884 | | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
6885 | | int type, struct in_addr *adv_router, |
6886 | | json_object *json) |
6887 | 0 | { |
6888 | 0 | struct listnode *node; |
6889 | 0 | struct ospf_area *area; |
6890 | 0 | char buf[PREFIX_STRLEN]; |
6891 | 0 | json_object *json_lsa_type = NULL; |
6892 | 0 | json_object *json_areas = NULL; |
6893 | 0 | json_object *json_lsa_array = NULL; |
6894 | |
|
6895 | 0 | if (json) |
6896 | 0 | json_lsa_type = json_object_new_object(); |
6897 | |
|
6898 | 0 | switch (type) { |
6899 | 0 | case OSPF_AS_EXTERNAL_LSA: |
6900 | 0 | case OSPF_OPAQUE_AS_LSA: |
6901 | 0 | if (!json) |
6902 | 0 | vty_out(vty, " %s \n\n", |
6903 | 0 | show_database_desc[type]); |
6904 | 0 | else |
6905 | 0 | json_lsa_array = json_object_new_array(); |
6906 | |
|
6907 | 0 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), |
6908 | 0 | adv_router, json_lsa_array); |
6909 | 0 | if (json) |
6910 | 0 | json_object_object_add(json, |
6911 | 0 | show_database_desc_json[type], |
6912 | 0 | json_lsa_array); |
6913 | 0 | break; |
6914 | 0 | default: |
6915 | 0 | if (json) |
6916 | 0 | json_areas = json_object_new_object(); |
6917 | |
|
6918 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
6919 | 0 | if (!json) { |
6920 | 0 | vty_out(vty, |
6921 | 0 | "\n %s (Area %s)\n\n", |
6922 | 0 | show_database_desc[type], |
6923 | 0 | ospf_area_desc_string(area)); |
6924 | 0 | } else { |
6925 | 0 | json_lsa_array = json_object_new_array(); |
6926 | 0 | json_object_object_add( |
6927 | 0 | json_areas, |
6928 | 0 | inet_ntop(AF_INET, &area->area_id, buf, |
6929 | 0 | sizeof(buf)), |
6930 | 0 | json_lsa_array); |
6931 | 0 | } |
6932 | |
|
6933 | 0 | show_lsa_detail_adv_router_proc( |
6934 | 0 | vty, AREA_LSDB(area, type), adv_router, |
6935 | 0 | json_lsa_array); |
6936 | 0 | } |
6937 | |
|
6938 | 0 | if (json) { |
6939 | 0 | json_object_object_add(json_lsa_type, "areas", |
6940 | 0 | json_areas); |
6941 | 0 | json_object_object_add(json, |
6942 | 0 | show_database_desc_json[type], |
6943 | 0 | json_lsa_type); |
6944 | 0 | } |
6945 | 0 | break; |
6946 | 0 | } |
6947 | 0 | } |
6948 | | |
6949 | | void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self, |
6950 | | json_object *json) |
6951 | 0 | { |
6952 | 0 | struct ospf_lsa *lsa; |
6953 | 0 | struct route_node *rn; |
6954 | 0 | struct ospf_area *area; |
6955 | 0 | struct listnode *node; |
6956 | 0 | char buf[PREFIX_STRLEN]; |
6957 | 0 | json_object *json_areas = NULL; |
6958 | 0 | json_object *json_area = NULL; |
6959 | 0 | json_object *json_lsa = NULL; |
6960 | 0 | int type; |
6961 | 0 | json_object *json_lsa_array = NULL; |
6962 | 0 | uint32_t count; |
6963 | |
|
6964 | 0 | if (json) |
6965 | 0 | json_areas = json_object_new_object(); |
6966 | |
|
6967 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
6968 | 0 | if (json) |
6969 | 0 | json_area = json_object_new_object(); |
6970 | |
|
6971 | 0 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6972 | 0 | count = 0; |
6973 | 0 | switch (type) { |
6974 | 0 | case OSPF_AS_EXTERNAL_LSA: |
6975 | 0 | case OSPF_OPAQUE_AS_LSA: |
6976 | 0 | continue; |
6977 | 0 | default: |
6978 | 0 | break; |
6979 | 0 | } |
6980 | 0 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 |
6981 | 0 | || (!self |
6982 | 0 | && ospf_lsdb_count(area->lsdb, type) > 0)) { |
6983 | |
|
6984 | 0 | if (!json) { |
6985 | 0 | vty_out(vty, |
6986 | 0 | " %s (Area %s)\n\n", |
6987 | 0 | show_database_desc[type], |
6988 | 0 | ospf_area_desc_string(area)); |
6989 | 0 | vty_out(vty, "%s\n", |
6990 | 0 | show_database_header[type]); |
6991 | 0 | } else { |
6992 | 0 | json_lsa_array = |
6993 | 0 | json_object_new_array(); |
6994 | 0 | json_object_object_add( |
6995 | 0 | json_area, |
6996 | 0 | show_database_desc_json[type], |
6997 | 0 | json_lsa_array); |
6998 | 0 | } |
6999 | |
|
7000 | 0 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) { |
7001 | 0 | if (json) { |
7002 | 0 | json_lsa = |
7003 | 0 | json_object_new_object(); |
7004 | 0 | json_object_array_add( |
7005 | 0 | json_lsa_array, |
7006 | 0 | json_lsa); |
7007 | 0 | } |
7008 | |
|
7009 | 0 | count += show_lsa_summary( |
7010 | 0 | vty, lsa, self, json_lsa); |
7011 | 0 | } |
7012 | |
|
7013 | 0 | if (!json) |
7014 | 0 | vty_out(vty, "\n"); |
7015 | 0 | else |
7016 | 0 | json_object_int_add( |
7017 | 0 | json_area, |
7018 | |
|
7019 | 0 | show_database_desc_count_json |
7020 | 0 | [type], |
7021 | 0 | count); |
7022 | 0 | } |
7023 | 0 | } |
7024 | 0 | if (json) |
7025 | 0 | json_object_object_add(json_areas, |
7026 | 0 | inet_ntop(AF_INET, |
7027 | 0 | &area->area_id, |
7028 | 0 | buf, sizeof(buf)), |
7029 | 0 | json_area); |
7030 | 0 | } |
7031 | | |
7032 | 0 | if (json) |
7033 | 0 | json_object_object_add(json, "areas", json_areas); |
7034 | |
|
7035 | 0 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
7036 | 0 | count = 0; |
7037 | 0 | switch (type) { |
7038 | 0 | case OSPF_AS_EXTERNAL_LSA: |
7039 | 0 | case OSPF_OPAQUE_AS_LSA: |
7040 | 0 | break; |
7041 | 0 | default: |
7042 | 0 | continue; |
7043 | 0 | } |
7044 | 0 | if (ospf_lsdb_count_self(ospf->lsdb, type) |
7045 | 0 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { |
7046 | 0 | if (!json) { |
7047 | 0 | vty_out(vty, " %s\n\n", |
7048 | 0 | show_database_desc[type]); |
7049 | 0 | vty_out(vty, "%s\n", |
7050 | 0 | show_database_header[type]); |
7051 | 0 | } else { |
7052 | 0 | json_lsa_array = json_object_new_array(); |
7053 | 0 | json_object_object_add( |
7054 | 0 | json, show_database_desc_json[type], |
7055 | 0 | json_lsa_array); |
7056 | 0 | } |
7057 | |
|
7058 | 0 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) { |
7059 | 0 | if (json) { |
7060 | 0 | json_lsa = json_object_new_object(); |
7061 | 0 | json_object_array_add(json_lsa_array, |
7062 | 0 | json_lsa); |
7063 | 0 | } |
7064 | |
|
7065 | 0 | count += show_lsa_summary(vty, lsa, self, |
7066 | 0 | json_lsa); |
7067 | 0 | } |
7068 | |
|
7069 | 0 | if (!json) |
7070 | 0 | vty_out(vty, "\n"); |
7071 | 0 | else |
7072 | 0 | json_object_int_add( |
7073 | 0 | json, |
7074 | 0 | show_database_desc_count_json[type], |
7075 | 0 | count); |
7076 | 0 | } |
7077 | 0 | } |
7078 | | |
7079 | 0 | if (!json) |
7080 | 0 | vty_out(vty, "\n"); |
7081 | 0 | } |
7082 | | |
7083 | | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf, |
7084 | | json_object *json) |
7085 | 0 | { |
7086 | 0 | struct route_node *rn; |
7087 | 0 | char buf[PREFIX_STRLEN]; |
7088 | 0 | json_object *json_maxage = NULL; |
7089 | |
|
7090 | 0 | if (!json) |
7091 | 0 | vty_out(vty, "\n MaxAge Link States:\n\n"); |
7092 | 0 | else |
7093 | 0 | json_maxage = json_object_new_object(); |
7094 | |
|
7095 | 0 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { |
7096 | 0 | struct ospf_lsa *lsa; |
7097 | 0 | json_object *json_lsa = NULL; |
7098 | |
|
7099 | 0 | if ((lsa = rn->info) != NULL) { |
7100 | 0 | if (!json) { |
7101 | 0 | vty_out(vty, "Link type: %d\n", |
7102 | 0 | lsa->data->type); |
7103 | 0 | vty_out(vty, "Link State ID: %pI4\n", |
7104 | 0 | &lsa->data->id); |
7105 | 0 | vty_out(vty, "Advertising Router: %pI4\n", |
7106 | 0 | &lsa->data->adv_router); |
7107 | 0 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); |
7108 | 0 | vty_out(vty, "\n"); |
7109 | 0 | } else { |
7110 | 0 | json_lsa = json_object_new_object(); |
7111 | 0 | json_object_int_add(json_lsa, "linkType", |
7112 | 0 | lsa->data->type); |
7113 | 0 | json_object_string_addf(json_lsa, "linkStateId", |
7114 | 0 | "%pI4", &lsa->data->id); |
7115 | 0 | json_object_string_addf( |
7116 | 0 | json_lsa, "advertisingRouter", "%pI4", |
7117 | 0 | &lsa->data->adv_router); |
7118 | 0 | json_object_int_add(json_lsa, "lsaLockCount", |
7119 | 0 | lsa->lock); |
7120 | 0 | json_object_object_add( |
7121 | 0 | json_maxage, |
7122 | 0 | inet_ntop(AF_INET, |
7123 | 0 | &lsa->data->id, |
7124 | 0 | buf, sizeof(buf)), |
7125 | 0 | json_lsa); |
7126 | 0 | } |
7127 | 0 | } |
7128 | 0 | } |
7129 | 0 | if (json) |
7130 | 0 | json_object_object_add(json, "maxAgeLinkStates", json_maxage); |
7131 | 0 | } |
7132 | | |
7133 | | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
7134 | | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" |
7135 | | |
7136 | | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
7137 | | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" |
7138 | | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" |
7139 | | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" |
7140 | | |
7141 | | #define OSPF_LSA_TYPES_DESC \ |
7142 | | "ASBR summary link states\n" \ |
7143 | | "External link states\n" \ |
7144 | | "Network link states\n" \ |
7145 | | "Router link states\n" \ |
7146 | | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ |
7147 | | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ |
7148 | | OSPF_LSA_TYPE_OPAQUE_AS_DESC |
7149 | | |
7150 | | static int |
7151 | | show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, bool maxage, |
7152 | | bool self, bool detail, const char *type_name, |
7153 | | struct in_addr *lsid, struct in_addr *adv_router, |
7154 | | bool use_vrf, json_object *json, bool uj) |
7155 | 0 | { |
7156 | 0 | int type; |
7157 | 0 | json_object *json_vrf = NULL; |
7158 | |
|
7159 | 0 | if (uj) { |
7160 | 0 | if (use_vrf) |
7161 | 0 | json_vrf = json_object_new_object(); |
7162 | 0 | else |
7163 | 0 | json_vrf = json; |
7164 | 0 | } |
7165 | |
|
7166 | 0 | if (ospf->instance) { |
7167 | 0 | if (uj) |
7168 | 0 | json_object_int_add(json_vrf, "ospfInstance", |
7169 | 0 | ospf->instance); |
7170 | 0 | else |
7171 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
7172 | 0 | } |
7173 | |
|
7174 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
7175 | | |
7176 | | /* Show Router ID. */ |
7177 | 0 | if (uj) { |
7178 | 0 | json_object_string_addf(json_vrf, "routerId", "%pI4", |
7179 | 0 | &ospf->router_id); |
7180 | 0 | } else { |
7181 | 0 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", |
7182 | 0 | &ospf->router_id); |
7183 | 0 | } |
7184 | | |
7185 | | /* Show MaxAge LSAs */ |
7186 | 0 | if (maxage) { |
7187 | 0 | show_ip_ospf_database_maxage(vty, ospf, json_vrf); |
7188 | 0 | if (json) { |
7189 | 0 | if (use_vrf) { |
7190 | 0 | if (ospf->vrf_id == VRF_DEFAULT) |
7191 | 0 | json_object_object_add(json, "default", |
7192 | 0 | json_vrf); |
7193 | 0 | else |
7194 | 0 | json_object_object_add(json, ospf->name, |
7195 | 0 | json_vrf); |
7196 | 0 | } |
7197 | 0 | } |
7198 | 0 | return CMD_SUCCESS; |
7199 | 0 | } |
7200 | | |
7201 | | /* Show all LSAs. */ |
7202 | 0 | if (!type_name) { |
7203 | 0 | if (detail) { |
7204 | 0 | for (int i = OSPF_ROUTER_LSA; i <= OSPF_OPAQUE_AS_LSA; |
7205 | 0 | i++) { |
7206 | 0 | switch (i) { |
7207 | 0 | case OSPF_GROUP_MEMBER_LSA: |
7208 | 0 | case OSPF_EXTERNAL_ATTRIBUTES_LSA: |
7209 | | /* ignore deprecated LSA types */ |
7210 | 0 | continue; |
7211 | 0 | default: |
7212 | 0 | break; |
7213 | 0 | } |
7214 | | |
7215 | 0 | if (adv_router && !lsid) |
7216 | 0 | show_lsa_detail_adv_router(vty, ospf, i, |
7217 | 0 | adv_router, |
7218 | 0 | json_vrf); |
7219 | 0 | else |
7220 | 0 | show_lsa_detail(vty, ospf, i, lsid, |
7221 | 0 | adv_router, json_vrf); |
7222 | 0 | } |
7223 | 0 | } else |
7224 | 0 | show_ip_ospf_database_summary(vty, ospf, self, |
7225 | 0 | json_vrf); |
7226 | | |
7227 | 0 | if (json) { |
7228 | 0 | if (use_vrf) { |
7229 | 0 | if (ospf->vrf_id == VRF_DEFAULT) |
7230 | 0 | json_object_object_add(json, "default", |
7231 | 0 | json_vrf); |
7232 | 0 | else |
7233 | 0 | json_object_object_add(json, ospf->name, |
7234 | 0 | json_vrf); |
7235 | 0 | } |
7236 | 0 | } |
7237 | 0 | return CMD_SUCCESS; |
7238 | 0 | } |
7239 | | |
7240 | | /* Set database type to show. */ |
7241 | 0 | if (strncmp(type_name, "r", 1) == 0) |
7242 | 0 | type = OSPF_ROUTER_LSA; |
7243 | 0 | else if (strncmp(type_name, "ne", 2) == 0) |
7244 | 0 | type = OSPF_NETWORK_LSA; |
7245 | 0 | else if (strncmp(type_name, "ns", 2) == 0) |
7246 | 0 | type = OSPF_AS_NSSA_LSA; |
7247 | 0 | else if (strncmp(type_name, "su", 2) == 0) |
7248 | 0 | type = OSPF_SUMMARY_LSA; |
7249 | 0 | else if (strncmp(type_name, "a", 1) == 0) |
7250 | 0 | type = OSPF_ASBR_SUMMARY_LSA; |
7251 | 0 | else if (strncmp(type_name, "e", 1) == 0) |
7252 | 0 | type = OSPF_AS_EXTERNAL_LSA; |
7253 | 0 | else if (strncmp(type_name, "opaque-l", 8) == 0) |
7254 | 0 | type = OSPF_OPAQUE_LINK_LSA; |
7255 | 0 | else if (strncmp(type_name, "opaque-ar", 9) == 0) |
7256 | 0 | type = OSPF_OPAQUE_AREA_LSA; |
7257 | 0 | else if (strncmp(type_name, "opaque-as", 9) == 0) |
7258 | 0 | type = OSPF_OPAQUE_AS_LSA; |
7259 | 0 | else { |
7260 | 0 | if (uj) { |
7261 | 0 | if (use_vrf) |
7262 | 0 | json_object_free(json_vrf); |
7263 | 0 | } |
7264 | 0 | return CMD_WARNING; |
7265 | 0 | } |
7266 | | |
7267 | 0 | if (adv_router && !lsid) |
7268 | 0 | show_lsa_detail_adv_router(vty, ospf, type, adv_router, |
7269 | 0 | json_vrf); |
7270 | 0 | else |
7271 | 0 | show_lsa_detail(vty, ospf, type, lsid, adv_router, json_vrf); |
7272 | |
|
7273 | 0 | if (json) { |
7274 | 0 | if (use_vrf) { |
7275 | 0 | if (ospf->vrf_id == VRF_DEFAULT) |
7276 | 0 | json_object_object_add(json, "default", |
7277 | 0 | json_vrf); |
7278 | 0 | else |
7279 | 0 | json_object_object_add(json, ospf->name, |
7280 | 0 | json_vrf); |
7281 | 0 | } |
7282 | 0 | } |
7283 | |
|
7284 | 0 | return CMD_SUCCESS; |
7285 | 0 | } |
7286 | | |
7287 | | DEFPY (show_ip_ospf_database, |
7288 | | show_ip_ospf_database_cmd, |
7289 | | "show ip ospf [(1-65535)$instance_id] [vrf <NAME|all>$vrf_name] database\ |
7290 | | [<\ |
7291 | | max-age$maxage\ |
7292 | | |self-originate$selforig\ |
7293 | | |<\ |
7294 | | detail$detail\ |
7295 | | |<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as>$type_name\ |
7296 | | >\ |
7297 | | [{\ |
7298 | | A.B.C.D$lsid\ |
7299 | | |<adv-router A.B.C.D$adv_router|self-originate$adv_router_self>\ |
7300 | | }]\ |
7301 | | >]\ |
7302 | | [json]", |
7303 | | SHOW_STR |
7304 | | IP_STR |
7305 | | "OSPF information\n" |
7306 | | "Instance ID\n" |
7307 | | VRF_CMD_HELP_STR |
7308 | | "All VRFs\n" |
7309 | | "Database summary\n" |
7310 | | "LSAs in MaxAge list\n" |
7311 | | "Self-originated link states\n" |
7312 | | "Show detailed information\n" |
7313 | | OSPF_LSA_TYPES_DESC |
7314 | | "Link State ID (as an IP address)\n" |
7315 | | "Advertising Router link states\n" |
7316 | | "Advertising Router (as an IP address)\n" |
7317 | | "Self-originated link states\n" |
7318 | | JSON_STR) |
7319 | 0 | { |
7320 | 0 | struct ospf *ospf; |
7321 | 0 | int ret = CMD_SUCCESS; |
7322 | 0 | bool use_vrf = !!vrf_name; |
7323 | 0 | bool uj = use_json(argc, argv); |
7324 | 0 | struct in_addr *lsid_p = NULL; |
7325 | 0 | struct in_addr *adv_router_p = NULL; |
7326 | 0 | json_object *json = NULL; |
7327 | |
|
7328 | 0 | if (uj) |
7329 | 0 | json = json_object_new_object(); |
7330 | 0 | if (lsid_str) |
7331 | 0 | lsid_p = &lsid; |
7332 | 0 | if (adv_router_str) |
7333 | 0 | adv_router_p = &adv_router; |
7334 | |
|
7335 | 0 | if (vrf_name && strmatch(vrf_name, "all")) { |
7336 | 0 | struct listnode *node; |
7337 | 0 | bool ospf_output = false; |
7338 | |
|
7339 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
7340 | 0 | if (!ospf->oi_running) |
7341 | 0 | continue; |
7342 | 0 | if (ospf->instance != instance_id) |
7343 | 0 | continue; |
7344 | | |
7345 | 0 | if (adv_router_self) |
7346 | 0 | adv_router_p = &ospf->router_id; |
7347 | |
|
7348 | 0 | ospf_output = true; |
7349 | 0 | ret = show_ip_ospf_database_common( |
7350 | 0 | vty, ospf, !!maxage, !!selforig, !!detail, |
7351 | 0 | type_name, lsid_p, adv_router_p, use_vrf, json, |
7352 | 0 | uj); |
7353 | 0 | } |
7354 | |
|
7355 | 0 | if (!ospf_output && !uj) |
7356 | 0 | vty_out(vty, "%% OSPF is not enabled\n"); |
7357 | 0 | } else { |
7358 | 0 | if (!vrf_name) |
7359 | 0 | vrf_name = VRF_DEFAULT_NAME; |
7360 | 0 | ospf = ospf_lookup_by_inst_name(instance_id, vrf_name); |
7361 | 0 | if (ospf == NULL || !ospf->oi_running) { |
7362 | 0 | if (uj) |
7363 | 0 | vty_json(vty, json); |
7364 | 0 | else |
7365 | 0 | vty_out(vty, "%% OSPF instance not found\n"); |
7366 | 0 | return CMD_SUCCESS; |
7367 | 0 | } |
7368 | 0 | if (adv_router_self) |
7369 | 0 | adv_router_p = &ospf->router_id; |
7370 | |
|
7371 | 0 | ret = (show_ip_ospf_database_common( |
7372 | 0 | vty, ospf, !!maxage, !!selforig, !!detail, type_name, |
7373 | 0 | lsid_p, adv_router_p, use_vrf, json, uj)); |
7374 | 0 | } |
7375 | | |
7376 | 0 | if (uj) |
7377 | 0 | vty_json(vty, json); |
7378 | |
|
7379 | 0 | return ret; |
7380 | 0 | } |
7381 | | |
7382 | | DEFUN (ip_ospf_authentication_args, |
7383 | | ip_ospf_authentication_args_addr_cmd, |
7384 | | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
7385 | | "IP Information\n" |
7386 | | "OSPF interface commands\n" |
7387 | | "Enable authentication on this interface\n" |
7388 | | "Use null authentication\n" |
7389 | | "Use message-digest authentication\n" |
7390 | | "Address of interface\n") |
7391 | 0 | { |
7392 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7393 | 0 | int idx_encryption = 3; |
7394 | 0 | int idx_ipv4 = 4; |
7395 | 0 | struct in_addr addr; |
7396 | 0 | int ret; |
7397 | 0 | struct ospf_if_params *params; |
7398 | |
|
7399 | 0 | params = IF_DEF_PARAMS(ifp); |
7400 | |
|
7401 | 0 | if (argc == 5) { |
7402 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
7403 | 0 | if (!ret) { |
7404 | 0 | vty_out(vty, |
7405 | 0 | "Please specify interface address by A.B.C.D\n"); |
7406 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7407 | 0 | } |
7408 | | |
7409 | 0 | params = ospf_get_if_params(ifp, addr); |
7410 | 0 | ospf_if_update_params(ifp, addr); |
7411 | 0 | } |
7412 | | |
7413 | | /* Handle null authentication */ |
7414 | 0 | if (argv[idx_encryption]->arg[0] == 'n') { |
7415 | 0 | SET_IF_PARAM(params, auth_type); |
7416 | 0 | params->auth_type = OSPF_AUTH_NULL; |
7417 | 0 | return CMD_SUCCESS; |
7418 | 0 | } |
7419 | | |
7420 | | /* Handle message-digest authentication */ |
7421 | 0 | if (argv[idx_encryption]->arg[0] == 'm') { |
7422 | 0 | SET_IF_PARAM(params, auth_type); |
7423 | 0 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
7424 | 0 | return CMD_SUCCESS; |
7425 | 0 | } |
7426 | | |
7427 | 0 | vty_out(vty, "You shouldn't get here!\n"); |
7428 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7429 | 0 | } |
7430 | | |
7431 | | DEFUN (ip_ospf_authentication, |
7432 | | ip_ospf_authentication_addr_cmd, |
7433 | | "ip ospf authentication [A.B.C.D]", |
7434 | | "IP Information\n" |
7435 | | "OSPF interface commands\n" |
7436 | | "Enable authentication on this interface\n" |
7437 | | "Address of interface\n") |
7438 | 0 | { |
7439 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7440 | 0 | int idx_ipv4 = 3; |
7441 | 0 | struct in_addr addr; |
7442 | 0 | int ret; |
7443 | 0 | struct ospf_if_params *params; |
7444 | |
|
7445 | 0 | params = IF_DEF_PARAMS(ifp); |
7446 | |
|
7447 | 0 | if (argc == 4) { |
7448 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
7449 | 0 | if (!ret) { |
7450 | 0 | vty_out(vty, |
7451 | 0 | "Please specify interface address by A.B.C.D\n"); |
7452 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7453 | 0 | } |
7454 | | |
7455 | 0 | params = ospf_get_if_params(ifp, addr); |
7456 | 0 | ospf_if_update_params(ifp, addr); |
7457 | 0 | } |
7458 | | |
7459 | 0 | SET_IF_PARAM(params, auth_type); |
7460 | 0 | params->auth_type = OSPF_AUTH_SIMPLE; |
7461 | |
|
7462 | 0 | return CMD_SUCCESS; |
7463 | 0 | } |
7464 | | |
7465 | | DEFUN (no_ip_ospf_authentication_args, |
7466 | | no_ip_ospf_authentication_args_addr_cmd, |
7467 | | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
7468 | | NO_STR |
7469 | | "IP Information\n" |
7470 | | "OSPF interface commands\n" |
7471 | | "Enable authentication on this interface\n" |
7472 | | "Use null authentication\n" |
7473 | | "Use message-digest authentication\n" |
7474 | | "Address of interface\n") |
7475 | 0 | { |
7476 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7477 | 0 | int idx_encryption = 4; |
7478 | 0 | int idx_ipv4 = 5; |
7479 | 0 | struct in_addr addr; |
7480 | 0 | int ret; |
7481 | 0 | struct ospf_if_params *params; |
7482 | 0 | struct route_node *rn; |
7483 | 0 | int auth_type; |
7484 | |
|
7485 | 0 | params = IF_DEF_PARAMS(ifp); |
7486 | |
|
7487 | 0 | if (argc == 6) { |
7488 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
7489 | 0 | if (!ret) { |
7490 | 0 | vty_out(vty, |
7491 | 0 | "Please specify interface address by A.B.C.D\n"); |
7492 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7493 | 0 | } |
7494 | | |
7495 | 0 | params = ospf_lookup_if_params(ifp, addr); |
7496 | 0 | if (params == NULL) { |
7497 | 0 | vty_out(vty, "Ip Address specified is unknown\n"); |
7498 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7499 | 0 | } |
7500 | 0 | params->auth_type = OSPF_AUTH_NOTSET; |
7501 | 0 | UNSET_IF_PARAM(params, auth_type); |
7502 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
7503 | 0 | ospf_free_if_params(ifp, addr); |
7504 | 0 | ospf_if_update_params(ifp, addr); |
7505 | 0 | } |
7506 | 0 | } else { |
7507 | 0 | if (argv[idx_encryption]->arg[0] == 'n') { |
7508 | 0 | auth_type = OSPF_AUTH_NULL; |
7509 | 0 | } else if (argv[idx_encryption]->arg[0] == 'm') { |
7510 | 0 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
7511 | 0 | } else { |
7512 | 0 | vty_out(vty, "Unexpected input encountered\n"); |
7513 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7514 | 0 | } |
7515 | | /* |
7516 | | * Here we have a case where the user has entered |
7517 | | * 'no ip ospf authentication (null | message_digest )' |
7518 | | * we need to find if we have any ip addresses underneath it |
7519 | | * that |
7520 | | * correspond to the associated type. |
7521 | | */ |
7522 | 0 | if (params->auth_type == auth_type) { |
7523 | 0 | params->auth_type = OSPF_AUTH_NOTSET; |
7524 | 0 | UNSET_IF_PARAM(params, auth_type); |
7525 | 0 | } |
7526 | |
|
7527 | 0 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
7528 | 0 | rn = route_next(rn)) { |
7529 | 0 | if ((params = rn->info)) { |
7530 | 0 | if (params->auth_type == auth_type) { |
7531 | 0 | params->auth_type = OSPF_AUTH_NOTSET; |
7532 | 0 | UNSET_IF_PARAM(params, auth_type); |
7533 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
7534 | 0 | ospf_free_if_params( |
7535 | 0 | ifp, rn->p.u.prefix4); |
7536 | 0 | ospf_if_update_params( |
7537 | 0 | ifp, rn->p.u.prefix4); |
7538 | 0 | } |
7539 | 0 | } |
7540 | 0 | } |
7541 | 0 | } |
7542 | 0 | } |
7543 | | |
7544 | 0 | return CMD_SUCCESS; |
7545 | 0 | } |
7546 | | |
7547 | | DEFUN (no_ip_ospf_authentication, |
7548 | | no_ip_ospf_authentication_addr_cmd, |
7549 | | "no ip ospf authentication [A.B.C.D]", |
7550 | | NO_STR |
7551 | | "IP Information\n" |
7552 | | "OSPF interface commands\n" |
7553 | | "Enable authentication on this interface\n" |
7554 | | "Address of interface\n") |
7555 | 0 | { |
7556 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7557 | 0 | int idx_ipv4 = 4; |
7558 | 0 | struct in_addr addr; |
7559 | 0 | int ret; |
7560 | 0 | struct ospf_if_params *params; |
7561 | 0 | struct route_node *rn; |
7562 | |
|
7563 | 0 | params = IF_DEF_PARAMS(ifp); |
7564 | |
|
7565 | 0 | if (argc == 5) { |
7566 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
7567 | 0 | if (!ret) { |
7568 | 0 | vty_out(vty, |
7569 | 0 | "Please specify interface address by A.B.C.D\n"); |
7570 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7571 | 0 | } |
7572 | | |
7573 | 0 | params = ospf_lookup_if_params(ifp, addr); |
7574 | 0 | if (params == NULL) { |
7575 | 0 | vty_out(vty, "Ip Address specified is unknown\n"); |
7576 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7577 | 0 | } |
7578 | | |
7579 | 0 | params->auth_type = OSPF_AUTH_NOTSET; |
7580 | 0 | UNSET_IF_PARAM(params, auth_type); |
7581 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
7582 | 0 | ospf_free_if_params(ifp, addr); |
7583 | 0 | ospf_if_update_params(ifp, addr); |
7584 | 0 | } |
7585 | 0 | } else { |
7586 | | /* |
7587 | | * When a user enters 'no ip ospf authentication' |
7588 | | * We should remove all authentication types from |
7589 | | * the interface. |
7590 | | */ |
7591 | 0 | if ((params->auth_type == OSPF_AUTH_NULL) |
7592 | 0 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) |
7593 | 0 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { |
7594 | 0 | params->auth_type = OSPF_AUTH_NOTSET; |
7595 | 0 | UNSET_IF_PARAM(params, auth_type); |
7596 | 0 | } |
7597 | |
|
7598 | 0 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
7599 | 0 | rn = route_next(rn)) { |
7600 | 0 | if ((params = rn->info)) { |
7601 | |
|
7602 | 0 | if ((params->auth_type == OSPF_AUTH_NULL) |
7603 | 0 | || (params->auth_type |
7604 | 0 | == OSPF_AUTH_CRYPTOGRAPHIC) |
7605 | 0 | || (params->auth_type |
7606 | 0 | == OSPF_AUTH_SIMPLE)) { |
7607 | 0 | params->auth_type = OSPF_AUTH_NOTSET; |
7608 | 0 | UNSET_IF_PARAM(params, auth_type); |
7609 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
7610 | 0 | ospf_free_if_params( |
7611 | 0 | ifp, rn->p.u.prefix4); |
7612 | 0 | ospf_if_update_params( |
7613 | 0 | ifp, rn->p.u.prefix4); |
7614 | 0 | } |
7615 | 0 | } |
7616 | 0 | } |
7617 | 0 | } |
7618 | 0 | } |
7619 | | |
7620 | 0 | return CMD_SUCCESS; |
7621 | 0 | } |
7622 | | |
7623 | | |
7624 | | DEFUN (ip_ospf_authentication_key, |
7625 | | ip_ospf_authentication_key_addr_cmd, |
7626 | | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
7627 | | "IP Information\n" |
7628 | | "OSPF interface commands\n" |
7629 | | "Authentication password (key)\n" |
7630 | | "The OSPF password (key)\n" |
7631 | | "Address of interface\n") |
7632 | 0 | { |
7633 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7634 | 0 | int idx = 0; |
7635 | 0 | struct in_addr addr; |
7636 | 0 | struct ospf_if_params *params; |
7637 | |
|
7638 | 0 | params = IF_DEF_PARAMS(ifp); |
7639 | |
|
7640 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7641 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
7642 | 0 | vty_out(vty, |
7643 | 0 | "Please specify interface address by A.B.C.D\n"); |
7644 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7645 | 0 | } |
7646 | | |
7647 | 0 | params = ospf_get_if_params(ifp, addr); |
7648 | 0 | ospf_if_update_params(ifp, addr); |
7649 | 0 | } |
7650 | | |
7651 | 0 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
7652 | 0 | sizeof(params->auth_simple)); |
7653 | 0 | SET_IF_PARAM(params, auth_simple); |
7654 | |
|
7655 | 0 | return CMD_SUCCESS; |
7656 | 0 | } |
7657 | | |
7658 | | DEFUN_HIDDEN (ospf_authentication_key, |
7659 | | ospf_authentication_key_cmd, |
7660 | | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
7661 | | "OSPF interface commands\n" |
7662 | | VLINK_HELPSTR_AUTH_SIMPLE |
7663 | | "Address of interface\n") |
7664 | 0 | { |
7665 | 0 | return ip_ospf_authentication_key(self, vty, argc, argv); |
7666 | 0 | } |
7667 | | |
7668 | | DEFUN (no_ip_ospf_authentication_key, |
7669 | | no_ip_ospf_authentication_key_authkey_addr_cmd, |
7670 | | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", |
7671 | | NO_STR |
7672 | | "IP Information\n" |
7673 | | "OSPF interface commands\n" |
7674 | | VLINK_HELPSTR_AUTH_SIMPLE |
7675 | | "Address of interface\n") |
7676 | 0 | { |
7677 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7678 | 0 | int idx = 0; |
7679 | 0 | struct in_addr addr; |
7680 | 0 | struct ospf_if_params *params; |
7681 | 0 | params = IF_DEF_PARAMS(ifp); |
7682 | |
|
7683 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7684 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
7685 | 0 | vty_out(vty, |
7686 | 0 | "Please specify interface address by A.B.C.D\n"); |
7687 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7688 | 0 | } |
7689 | | |
7690 | 0 | params = ospf_lookup_if_params(ifp, addr); |
7691 | 0 | if (params == NULL) |
7692 | 0 | return CMD_SUCCESS; |
7693 | 0 | } |
7694 | | |
7695 | 0 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
7696 | 0 | UNSET_IF_PARAM(params, auth_simple); |
7697 | |
|
7698 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
7699 | 0 | ospf_free_if_params(ifp, addr); |
7700 | 0 | ospf_if_update_params(ifp, addr); |
7701 | 0 | } |
7702 | |
|
7703 | 0 | return CMD_SUCCESS; |
7704 | 0 | } |
7705 | | |
7706 | | DEFUN_HIDDEN (no_ospf_authentication_key, |
7707 | | no_ospf_authentication_key_authkey_addr_cmd, |
7708 | | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", |
7709 | | NO_STR |
7710 | | "OSPF interface commands\n" |
7711 | | VLINK_HELPSTR_AUTH_SIMPLE |
7712 | | "Address of interface\n") |
7713 | 0 | { |
7714 | 0 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
7715 | 0 | } |
7716 | | |
7717 | | DEFUN (ip_ospf_message_digest_key, |
7718 | | ip_ospf_message_digest_key_cmd, |
7719 | | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
7720 | | "IP Information\n" |
7721 | | "OSPF interface commands\n" |
7722 | | "Message digest authentication password (key)\n" |
7723 | | "Key ID\n" |
7724 | | "Use MD5 algorithm\n" |
7725 | | "The OSPF password (key)\n" |
7726 | | "Address of interface\n") |
7727 | 0 | { |
7728 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7729 | 0 | struct crypt_key *ck; |
7730 | 0 | uint8_t key_id; |
7731 | 0 | struct in_addr addr; |
7732 | 0 | struct ospf_if_params *params; |
7733 | |
|
7734 | 0 | params = IF_DEF_PARAMS(ifp); |
7735 | 0 | int idx = 0; |
7736 | |
|
7737 | 0 | argv_find(argv, argc, "(1-255)", &idx); |
7738 | 0 | char *keyid = argv[idx]->arg; |
7739 | 0 | argv_find(argv, argc, "KEY", &idx); |
7740 | 0 | char *cryptkey = argv[idx]->arg; |
7741 | |
|
7742 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7743 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
7744 | 0 | vty_out(vty, |
7745 | 0 | "Please specify interface address by A.B.C.D\n"); |
7746 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7747 | 0 | } |
7748 | | |
7749 | 0 | params = ospf_get_if_params(ifp, addr); |
7750 | 0 | ospf_if_update_params(ifp, addr); |
7751 | 0 | } |
7752 | | |
7753 | 0 | key_id = strtol(keyid, NULL, 10); |
7754 | | |
7755 | | /* Remove existing key, if any */ |
7756 | 0 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7757 | |
|
7758 | 0 | ck = ospf_crypt_key_new(); |
7759 | 0 | ck->key_id = (uint8_t)key_id; |
7760 | 0 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
7761 | |
|
7762 | 0 | ospf_crypt_key_add(params->auth_crypt, ck); |
7763 | 0 | SET_IF_PARAM(params, auth_crypt); |
7764 | |
|
7765 | 0 | return CMD_SUCCESS; |
7766 | 0 | } |
7767 | | |
7768 | | DEFUN_HIDDEN (ospf_message_digest_key, |
7769 | | ospf_message_digest_key_cmd, |
7770 | | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
7771 | | "OSPF interface commands\n" |
7772 | | "Message digest authentication password (key)\n" |
7773 | | "Key ID\n" |
7774 | | "Use MD5 algorithm\n" |
7775 | | "The OSPF password (key)\n" |
7776 | | "Address of interface\n") |
7777 | 0 | { |
7778 | 0 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7779 | 0 | } |
7780 | | |
7781 | | DEFUN (no_ip_ospf_message_digest_key, |
7782 | | no_ip_ospf_message_digest_key_cmd, |
7783 | | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7784 | | NO_STR |
7785 | | "IP Information\n" |
7786 | | "OSPF interface commands\n" |
7787 | | "Message digest authentication password (key)\n" |
7788 | | "Key ID\n" |
7789 | | "Use MD5 algorithm\n" |
7790 | | "The OSPF password (key)\n" |
7791 | | "Address of interface\n") |
7792 | 0 | { |
7793 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7794 | 0 | int idx = 0; |
7795 | 0 | struct crypt_key *ck; |
7796 | 0 | int key_id; |
7797 | 0 | struct in_addr addr; |
7798 | 0 | struct ospf_if_params *params; |
7799 | 0 | params = IF_DEF_PARAMS(ifp); |
7800 | |
|
7801 | 0 | argv_find(argv, argc, "(1-255)", &idx); |
7802 | 0 | char *keyid = argv[idx]->arg; |
7803 | |
|
7804 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7805 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
7806 | 0 | vty_out(vty, |
7807 | 0 | "Please specify interface address by A.B.C.D\n"); |
7808 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7809 | 0 | } |
7810 | | |
7811 | 0 | params = ospf_lookup_if_params(ifp, addr); |
7812 | 0 | if (params == NULL) |
7813 | 0 | return CMD_SUCCESS; |
7814 | 0 | } |
7815 | | |
7816 | 0 | key_id = strtol(keyid, NULL, 10); |
7817 | 0 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); |
7818 | 0 | if (ck == NULL) { |
7819 | 0 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); |
7820 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7821 | 0 | } |
7822 | | |
7823 | 0 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7824 | |
|
7825 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
7826 | 0 | ospf_free_if_params(ifp, addr); |
7827 | 0 | ospf_if_update_params(ifp, addr); |
7828 | 0 | } |
7829 | |
|
7830 | 0 | return CMD_SUCCESS; |
7831 | 0 | } |
7832 | | |
7833 | | DEFUN_HIDDEN (no_ospf_message_digest_key, |
7834 | | no_ospf_message_digest_key_cmd, |
7835 | | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7836 | | NO_STR |
7837 | | "OSPF interface commands\n" |
7838 | | "Message digest authentication password (key)\n" |
7839 | | "Key ID\n" |
7840 | | "Use MD5 algorithm\n" |
7841 | | "The OSPF password (key)\n" |
7842 | | "Address of interface\n") |
7843 | 0 | { |
7844 | 0 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
7845 | 0 | } |
7846 | | |
7847 | | DEFUN (ip_ospf_cost, |
7848 | | ip_ospf_cost_cmd, |
7849 | | "ip ospf cost (1-65535) [A.B.C.D]", |
7850 | | "IP Information\n" |
7851 | | "OSPF interface commands\n" |
7852 | | "Interface cost\n" |
7853 | | "Cost\n" |
7854 | | "Address of interface\n") |
7855 | 0 | { |
7856 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7857 | 0 | int idx = 0; |
7858 | 0 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
7859 | 0 | struct in_addr addr; |
7860 | 0 | struct ospf_if_params *params; |
7861 | 0 | params = IF_DEF_PARAMS(ifp); |
7862 | | |
7863 | | // get arguments |
7864 | 0 | char *coststr = NULL, *ifaddr = NULL; |
7865 | |
|
7866 | 0 | argv_find(argv, argc, "(1-65535)", &idx); |
7867 | 0 | coststr = argv[idx]->arg; |
7868 | 0 | cost = strtol(coststr, NULL, 10); |
7869 | |
|
7870 | 0 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
7871 | 0 | if (ifaddr) { |
7872 | 0 | if (!inet_aton(ifaddr, &addr)) { |
7873 | 0 | vty_out(vty, |
7874 | 0 | "Please specify interface address by A.B.C.D\n"); |
7875 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7876 | 0 | } |
7877 | | |
7878 | 0 | params = ospf_get_if_params(ifp, addr); |
7879 | 0 | ospf_if_update_params(ifp, addr); |
7880 | 0 | } |
7881 | | |
7882 | 0 | SET_IF_PARAM(params, output_cost_cmd); |
7883 | 0 | params->output_cost_cmd = cost; |
7884 | |
|
7885 | 0 | ospf_if_recalculate_output_cost(ifp); |
7886 | |
|
7887 | 0 | return CMD_SUCCESS; |
7888 | 0 | } |
7889 | | |
7890 | | DEFUN_HIDDEN (ospf_cost, |
7891 | | ospf_cost_cmd, |
7892 | | "ospf cost (1-65535) [A.B.C.D]", |
7893 | | "OSPF interface commands\n" |
7894 | | "Interface cost\n" |
7895 | | "Cost\n" |
7896 | | "Address of interface\n") |
7897 | 0 | { |
7898 | 0 | return ip_ospf_cost(self, vty, argc, argv); |
7899 | 0 | } |
7900 | | |
7901 | | DEFUN (no_ip_ospf_cost, |
7902 | | no_ip_ospf_cost_cmd, |
7903 | | "no ip ospf cost [(1-65535)] [A.B.C.D]", |
7904 | | NO_STR |
7905 | | "IP Information\n" |
7906 | | "OSPF interface commands\n" |
7907 | | "Interface cost\n" |
7908 | | "Cost\n" |
7909 | | "Address of interface\n") |
7910 | 0 | { |
7911 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7912 | 0 | int idx = 0; |
7913 | 0 | struct in_addr addr; |
7914 | 0 | struct ospf_if_params *params; |
7915 | |
|
7916 | 0 | params = IF_DEF_PARAMS(ifp); |
7917 | | |
7918 | | // get arguments |
7919 | 0 | char *ifaddr = NULL; |
7920 | 0 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
7921 | | |
7922 | | /* According to the semantics we are mimicking "no ip ospf cost N" is |
7923 | | * always treated as "no ip ospf cost" regardless of the actual value |
7924 | | * of N already configured for the interface. Thus ignore cost. */ |
7925 | |
|
7926 | 0 | if (ifaddr) { |
7927 | 0 | if (!inet_aton(ifaddr, &addr)) { |
7928 | 0 | vty_out(vty, |
7929 | 0 | "Please specify interface address by A.B.C.D\n"); |
7930 | 0 | return CMD_WARNING_CONFIG_FAILED; |
7931 | 0 | } |
7932 | | |
7933 | 0 | params = ospf_lookup_if_params(ifp, addr); |
7934 | 0 | if (params == NULL) |
7935 | 0 | return CMD_SUCCESS; |
7936 | 0 | } |
7937 | | |
7938 | 0 | UNSET_IF_PARAM(params, output_cost_cmd); |
7939 | |
|
7940 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
7941 | 0 | ospf_free_if_params(ifp, addr); |
7942 | 0 | ospf_if_update_params(ifp, addr); |
7943 | 0 | } |
7944 | |
|
7945 | 0 | ospf_if_recalculate_output_cost(ifp); |
7946 | |
|
7947 | 0 | return CMD_SUCCESS; |
7948 | 0 | } |
7949 | | |
7950 | | DEFUN_HIDDEN (no_ospf_cost, |
7951 | | no_ospf_cost_cmd, |
7952 | | "no ospf cost [(1-65535)] [A.B.C.D]", |
7953 | | NO_STR |
7954 | | "OSPF interface commands\n" |
7955 | | "Interface cost\n" |
7956 | | "Cost\n" |
7957 | | "Address of interface\n") |
7958 | 0 | { |
7959 | 0 | return no_ip_ospf_cost(self, vty, argc, argv); |
7960 | 0 | } |
7961 | | |
7962 | | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
7963 | 0 | { |
7964 | 0 | struct route_node *rn; |
7965 | 0 | struct ospf_neighbor *nbr; |
7966 | |
|
7967 | 0 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
7968 | 0 | nbr = rn->info; |
7969 | |
|
7970 | 0 | if (!nbr) |
7971 | 0 | continue; |
7972 | | |
7973 | 0 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); |
7974 | 0 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); |
7975 | 0 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); |
7976 | 0 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); |
7977 | 0 | } |
7978 | 0 | } |
7979 | | |
7980 | | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
7981 | | const char *nbr_str, |
7982 | | const char *fast_hello_str) |
7983 | 0 | { |
7984 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7985 | 0 | uint32_t seconds; |
7986 | 0 | uint8_t hellomult; |
7987 | 0 | struct in_addr addr; |
7988 | 0 | int ret; |
7989 | 0 | struct ospf_if_params *params; |
7990 | 0 | struct ospf_interface *oi; |
7991 | 0 | struct route_node *rn; |
7992 | |
|
7993 | 0 | params = IF_DEF_PARAMS(ifp); |
7994 | |
|
7995 | 0 | if (nbr_str) { |
7996 | 0 | ret = inet_aton(nbr_str, &addr); |
7997 | 0 | if (!ret) { |
7998 | 0 | vty_out(vty, |
7999 | 0 | "Please specify interface address by A.B.C.D\n"); |
8000 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8001 | 0 | } |
8002 | | |
8003 | 0 | params = ospf_get_if_params(ifp, addr); |
8004 | 0 | ospf_if_update_params(ifp, addr); |
8005 | 0 | } |
8006 | | |
8007 | 0 | if (interval_str) { |
8008 | 0 | seconds = strtoul(interval_str, NULL, 10); |
8009 | | |
8010 | | /* reset fast_hello too, just to be sure */ |
8011 | 0 | UNSET_IF_PARAM(params, fast_hello); |
8012 | 0 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; |
8013 | 0 | } else if (fast_hello_str) { |
8014 | 0 | hellomult = strtoul(fast_hello_str, NULL, 10); |
8015 | | /* 1s dead-interval with sub-second hellos desired */ |
8016 | 0 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; |
8017 | 0 | SET_IF_PARAM(params, fast_hello); |
8018 | 0 | params->fast_hello = hellomult; |
8019 | 0 | } else { |
8020 | 0 | vty_out(vty, |
8021 | 0 | "Please specify dead-interval or hello-multiplier\n"); |
8022 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8023 | 0 | } |
8024 | | |
8025 | 0 | SET_IF_PARAM(params, v_wait); |
8026 | 0 | params->v_wait = seconds; |
8027 | 0 | params->is_v_wait_set = true; |
8028 | | |
8029 | | /* Update timer values in neighbor structure. */ |
8030 | 0 | if (nbr_str) { |
8031 | 0 | struct ospf *ospf = NULL; |
8032 | |
|
8033 | 0 | ospf = ifp->vrf->info; |
8034 | 0 | if (ospf) { |
8035 | 0 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8036 | 0 | if (oi) |
8037 | 0 | ospf_nbr_timer_update(oi); |
8038 | 0 | } |
8039 | 0 | } else { |
8040 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
8041 | 0 | if ((oi = rn->info)) |
8042 | 0 | ospf_nbr_timer_update(oi); |
8043 | 0 | } |
8044 | |
|
8045 | 0 | return CMD_SUCCESS; |
8046 | 0 | } |
8047 | | |
8048 | | DEFUN (ip_ospf_dead_interval, |
8049 | | ip_ospf_dead_interval_cmd, |
8050 | | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
8051 | | "IP Information\n" |
8052 | | "OSPF interface commands\n" |
8053 | | "Interval time after which a neighbor is declared down\n" |
8054 | | "Seconds\n" |
8055 | | "Address of interface\n") |
8056 | 0 | { |
8057 | 0 | int idx = 0; |
8058 | 0 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) |
8059 | 0 | ? argv[idx]->arg |
8060 | 0 | : NULL; |
8061 | 0 | char *ifaddr = |
8062 | 0 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
8063 | 0 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); |
8064 | 0 | } |
8065 | | |
8066 | | |
8067 | | DEFUN_HIDDEN (ospf_dead_interval, |
8068 | | ospf_dead_interval_cmd, |
8069 | | "ospf dead-interval (1-65535) [A.B.C.D]", |
8070 | | "OSPF interface commands\n" |
8071 | | "Interval time after which a neighbor is declared down\n" |
8072 | | "Seconds\n" |
8073 | | "Address of interface\n") |
8074 | 0 | { |
8075 | 0 | return ip_ospf_dead_interval(self, vty, argc, argv); |
8076 | 0 | } |
8077 | | |
8078 | | DEFUN (ip_ospf_dead_interval_minimal, |
8079 | | ip_ospf_dead_interval_minimal_addr_cmd, |
8080 | | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
8081 | | "IP Information\n" |
8082 | | "OSPF interface commands\n" |
8083 | | "Interval time after which a neighbor is declared down\n" |
8084 | | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8085 | | "Hello multiplier factor\n" |
8086 | | "Number of Hellos to send each second\n" |
8087 | | "Address of interface\n") |
8088 | 0 | { |
8089 | 0 | int idx_number = 5; |
8090 | 0 | int idx_ipv4 = 6; |
8091 | 0 | if (argc == 7) |
8092 | 0 | return ospf_vty_dead_interval_set( |
8093 | 0 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); |
8094 | 0 | else |
8095 | 0 | return ospf_vty_dead_interval_set(vty, NULL, NULL, |
8096 | 0 | argv[idx_number]->arg); |
8097 | 0 | } |
8098 | | |
8099 | | DEFUN (no_ip_ospf_dead_interval, |
8100 | | no_ip_ospf_dead_interval_cmd, |
8101 | | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
8102 | | NO_STR |
8103 | | "IP Information\n" |
8104 | | "OSPF interface commands\n" |
8105 | | "Interval time after which a neighbor is declared down\n" |
8106 | | "Seconds\n" |
8107 | | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8108 | | "Hello multiplier factor\n" |
8109 | | "Number of Hellos to send each second\n" |
8110 | | "Address of interface\n") |
8111 | 0 | { |
8112 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8113 | 0 | int idx_ipv4 = argc - 1; |
8114 | 0 | struct in_addr addr = {.s_addr = 0L}; |
8115 | 0 | int ret; |
8116 | 0 | struct ospf_if_params *params; |
8117 | 0 | struct ospf_interface *oi; |
8118 | 0 | struct route_node *rn; |
8119 | |
|
8120 | 0 | params = IF_DEF_PARAMS(ifp); |
8121 | |
|
8122 | 0 | if (argv[idx_ipv4]->type == IPV4_TKN) { |
8123 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
8124 | 0 | if (!ret) { |
8125 | 0 | vty_out(vty, |
8126 | 0 | "Please specify interface address by A.B.C.D\n"); |
8127 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8128 | 0 | } |
8129 | | |
8130 | 0 | params = ospf_lookup_if_params(ifp, addr); |
8131 | 0 | if (params == NULL) |
8132 | 0 | return CMD_SUCCESS; |
8133 | 0 | } |
8134 | | |
8135 | 0 | UNSET_IF_PARAM(params, v_wait); |
8136 | 0 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; |
8137 | 0 | params->is_v_wait_set = false; |
8138 | |
|
8139 | 0 | UNSET_IF_PARAM(params, fast_hello); |
8140 | 0 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; |
8141 | |
|
8142 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
8143 | 0 | ospf_free_if_params(ifp, addr); |
8144 | 0 | ospf_if_update_params(ifp, addr); |
8145 | 0 | } |
8146 | | |
8147 | | /* Update timer values in neighbor structure. */ |
8148 | 0 | if (argc == 1) { |
8149 | 0 | struct ospf *ospf = NULL; |
8150 | |
|
8151 | 0 | ospf = ifp->vrf->info; |
8152 | 0 | if (ospf) { |
8153 | 0 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8154 | 0 | if (oi) |
8155 | 0 | ospf_nbr_timer_update(oi); |
8156 | 0 | } |
8157 | 0 | } else { |
8158 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
8159 | 0 | if ((oi = rn->info)) |
8160 | 0 | ospf_nbr_timer_update(oi); |
8161 | 0 | } |
8162 | |
|
8163 | 0 | return CMD_SUCCESS; |
8164 | 0 | } |
8165 | | |
8166 | | DEFUN_HIDDEN (no_ospf_dead_interval, |
8167 | | no_ospf_dead_interval_cmd, |
8168 | | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
8169 | | NO_STR |
8170 | | "OSPF interface commands\n" |
8171 | | "Interval time after which a neighbor is declared down\n" |
8172 | | "Seconds\n" |
8173 | | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8174 | | "Hello multiplier factor\n" |
8175 | | "Number of Hellos to send each second\n" |
8176 | | "Address of interface\n") |
8177 | 0 | { |
8178 | 0 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
8179 | 0 | } |
8180 | | |
8181 | | DEFUN (ip_ospf_hello_interval, |
8182 | | ip_ospf_hello_interval_cmd, |
8183 | | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
8184 | | "IP Information\n" |
8185 | | "OSPF interface commands\n" |
8186 | | "Time between HELLO packets\n" |
8187 | | "Seconds\n" |
8188 | | "Address of interface\n") |
8189 | 0 | { |
8190 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8191 | 0 | int idx = 0; |
8192 | 0 | struct in_addr addr = {.s_addr = 0L}; |
8193 | 0 | struct ospf_if_params *params; |
8194 | 0 | params = IF_DEF_PARAMS(ifp); |
8195 | 0 | uint32_t seconds = 0; |
8196 | 0 | bool is_addr = false; |
8197 | 0 | uint32_t old_interval = 0; |
8198 | |
|
8199 | 0 | argv_find(argv, argc, "(1-65535)", &idx); |
8200 | 0 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8201 | |
|
8202 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8203 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
8204 | 0 | vty_out(vty, |
8205 | 0 | "Please specify interface address by A.B.C.D\n"); |
8206 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8207 | 0 | } |
8208 | | |
8209 | 0 | params = ospf_get_if_params(ifp, addr); |
8210 | 0 | ospf_if_update_params(ifp, addr); |
8211 | 0 | is_addr = true; |
8212 | 0 | } |
8213 | | |
8214 | 0 | old_interval = params->v_hello; |
8215 | | |
8216 | | /* Return, if same interval is configured. */ |
8217 | 0 | if (old_interval == seconds) |
8218 | 0 | return CMD_SUCCESS; |
8219 | | |
8220 | 0 | SET_IF_PARAM(params, v_hello); |
8221 | 0 | params->v_hello = seconds; |
8222 | |
|
8223 | 0 | if (!params->is_v_wait_set) { |
8224 | 0 | SET_IF_PARAM(params, v_wait); |
8225 | | /* As per RFC 4062 |
8226 | | * The router dead interval should |
8227 | | * be some multiple of the HelloInterval (perhaps 4 times the |
8228 | | * hello interval) and must be the same for all routers |
8229 | | * attached to a common network. |
8230 | | */ |
8231 | 0 | params->v_wait = 4 * seconds; |
8232 | 0 | } |
8233 | |
|
8234 | 0 | ospf_reset_hello_timer(ifp, addr, is_addr); |
8235 | |
|
8236 | 0 | return CMD_SUCCESS; |
8237 | 0 | } |
8238 | | |
8239 | | DEFUN_HIDDEN (ospf_hello_interval, |
8240 | | ospf_hello_interval_cmd, |
8241 | | "ospf hello-interval (1-65535) [A.B.C.D]", |
8242 | | "OSPF interface commands\n" |
8243 | | "Time between HELLO packets\n" |
8244 | | "Seconds\n" |
8245 | | "Address of interface\n") |
8246 | 0 | { |
8247 | 0 | return ip_ospf_hello_interval(self, vty, argc, argv); |
8248 | 0 | } |
8249 | | |
8250 | | DEFUN (no_ip_ospf_hello_interval, |
8251 | | no_ip_ospf_hello_interval_cmd, |
8252 | | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", |
8253 | | NO_STR |
8254 | | "IP Information\n" |
8255 | | "OSPF interface commands\n" |
8256 | | "Time between HELLO packets\n" // ignored |
8257 | | "Seconds\n" |
8258 | | "Address of interface\n") |
8259 | 0 | { |
8260 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8261 | 0 | int idx = 0; |
8262 | 0 | struct in_addr addr = {.s_addr = 0L}; |
8263 | 0 | struct ospf_if_params *params; |
8264 | 0 | struct route_node *rn; |
8265 | |
|
8266 | 0 | params = IF_DEF_PARAMS(ifp); |
8267 | |
|
8268 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8269 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
8270 | 0 | vty_out(vty, |
8271 | 0 | "Please specify interface address by A.B.C.D\n"); |
8272 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8273 | 0 | } |
8274 | | |
8275 | 0 | params = ospf_lookup_if_params(ifp, addr); |
8276 | 0 | if (params == NULL) |
8277 | 0 | return CMD_SUCCESS; |
8278 | 0 | } |
8279 | | |
8280 | 0 | UNSET_IF_PARAM(params, v_hello); |
8281 | 0 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; |
8282 | |
|
8283 | 0 | if (!params->is_v_wait_set) { |
8284 | 0 | UNSET_IF_PARAM(params, v_wait); |
8285 | 0 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; |
8286 | 0 | } |
8287 | |
|
8288 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8289 | 0 | struct ospf_interface *oi = rn->info; |
8290 | |
|
8291 | 0 | if (!oi) |
8292 | 0 | continue; |
8293 | | |
8294 | 0 | oi->type = IF_DEF_PARAMS(ifp)->type; |
8295 | 0 | oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
8296 | |
|
8297 | 0 | if (oi->state > ISM_Down) { |
8298 | 0 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); |
8299 | 0 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); |
8300 | 0 | } |
8301 | 0 | } |
8302 | |
|
8303 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
8304 | 0 | ospf_free_if_params(ifp, addr); |
8305 | 0 | ospf_if_update_params(ifp, addr); |
8306 | 0 | } |
8307 | |
|
8308 | 0 | return CMD_SUCCESS; |
8309 | 0 | } |
8310 | | |
8311 | | DEFUN_HIDDEN (no_ospf_hello_interval, |
8312 | | no_ospf_hello_interval_cmd, |
8313 | | "no ospf hello-interval [(1-65535) [A.B.C.D]]", |
8314 | | NO_STR |
8315 | | "OSPF interface commands\n" |
8316 | | "Time between HELLO packets\n" // ignored |
8317 | | "Seconds\n" |
8318 | | "Address of interface\n") |
8319 | 0 | { |
8320 | 0 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
8321 | 0 | } |
8322 | | |
8323 | | DEFUN(ip_ospf_network, ip_ospf_network_cmd, |
8324 | | "ip ospf network <broadcast|" |
8325 | | "non-broadcast|" |
8326 | | "point-to-multipoint [delay-reflood]|" |
8327 | | "point-to-point [dmvpn]>", |
8328 | | "IP Information\n" |
8329 | | "OSPF interface commands\n" |
8330 | | "Network type\n" |
8331 | | "Specify OSPF broadcast multi-access network\n" |
8332 | | "Specify OSPF NBMA network\n" |
8333 | | "Specify OSPF point-to-multipoint network\n" |
8334 | | "Specify OSPF delayed reflooding of LSAs received on P2MP interface\n" |
8335 | | "Specify OSPF point-to-point network\n" |
8336 | | "Specify OSPF point-to-point DMVPN network\n") |
8337 | 0 | { |
8338 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8339 | 0 | int idx = 0; |
8340 | 0 | int old_type = IF_DEF_PARAMS(ifp)->type; |
8341 | 0 | uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
8342 | 0 | uint8_t old_p2mp_delay_reflood = IF_DEF_PARAMS(ifp)->p2mp_delay_reflood; |
8343 | 0 | struct route_node *rn; |
8344 | |
|
8345 | 0 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
8346 | 0 | vty_out(vty, |
8347 | 0 | "This is a loopback interface. Can't set network type.\n"); |
8348 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8349 | 0 | } |
8350 | | |
8351 | 0 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
8352 | 0 | IF_DEF_PARAMS(ifp)->p2mp_delay_reflood = |
8353 | 0 | OSPF_P2MP_DELAY_REFLOOD_DEFAULT; |
8354 | |
|
8355 | 0 | if (argv_find(argv, argc, "broadcast", &idx)) |
8356 | 0 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; |
8357 | 0 | else if (argv_find(argv, argc, "non-broadcast", &idx)) |
8358 | 0 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; |
8359 | 0 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) { |
8360 | 0 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; |
8361 | 0 | if (argv_find(argv, argc, "delay-reflood", &idx)) |
8362 | 0 | IF_DEF_PARAMS(ifp)->p2mp_delay_reflood = true; |
8363 | 0 | } else if (argv_find(argv, argc, "point-to-point", &idx)) { |
8364 | 0 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; |
8365 | 0 | if (argv_find(argv, argc, "dmvpn", &idx)) |
8366 | 0 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1; |
8367 | 0 | } |
8368 | |
|
8369 | 0 | if (IF_DEF_PARAMS(ifp)->type == old_type && |
8370 | 0 | IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn && |
8371 | 0 | IF_DEF_PARAMS(ifp)->p2mp_delay_reflood == old_p2mp_delay_reflood) |
8372 | 0 | return CMD_SUCCESS; |
8373 | | |
8374 | 0 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); |
8375 | |
|
8376 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8377 | 0 | struct ospf_interface *oi = rn->info; |
8378 | |
|
8379 | 0 | if (!oi) |
8380 | 0 | continue; |
8381 | | |
8382 | 0 | oi->type = IF_DEF_PARAMS(ifp)->type; |
8383 | 0 | oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
8384 | 0 | oi->p2mp_delay_reflood = IF_DEF_PARAMS(ifp)->p2mp_delay_reflood; |
8385 | | |
8386 | | /* |
8387 | | * The OSPF interface only needs to be flapped if the network |
8388 | | * type or DMVPN parameter changes. |
8389 | | */ |
8390 | 0 | if (IF_DEF_PARAMS(ifp)->type != old_type || |
8391 | 0 | IF_DEF_PARAMS(ifp)->ptp_dmvpn != old_ptp_dmvpn) { |
8392 | 0 | if (oi->state > ISM_Down) { |
8393 | 0 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); |
8394 | 0 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); |
8395 | 0 | } |
8396 | 0 | } |
8397 | 0 | } |
8398 | |
|
8399 | 0 | return CMD_SUCCESS; |
8400 | 0 | } |
8401 | | |
8402 | | DEFUN_HIDDEN (ospf_network, |
8403 | | ospf_network_cmd, |
8404 | | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
8405 | | "OSPF interface commands\n" |
8406 | | "Network type\n" |
8407 | | "Specify OSPF broadcast multi-access network\n" |
8408 | | "Specify OSPF NBMA network\n" |
8409 | | "Specify OSPF point-to-multipoint network\n" |
8410 | | "Specify OSPF point-to-point network\n") |
8411 | 0 | { |
8412 | 0 | return ip_ospf_network(self, vty, argc, argv); |
8413 | 0 | } |
8414 | | |
8415 | | DEFUN (no_ip_ospf_network, |
8416 | | no_ip_ospf_network_cmd, |
8417 | | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", |
8418 | | NO_STR |
8419 | | "IP Information\n" |
8420 | | "OSPF interface commands\n" |
8421 | | "Network type\n" |
8422 | | "Specify OSPF broadcast multi-access network\n" |
8423 | | "Specify OSPF NBMA network\n" |
8424 | | "Specify OSPF point-to-multipoint network\n" |
8425 | | "Specify OSPF point-to-point network\n") |
8426 | 0 | { |
8427 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8428 | 0 | int old_type = IF_DEF_PARAMS(ifp)->type; |
8429 | 0 | struct route_node *rn; |
8430 | |
|
8431 | 0 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
8432 | 0 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
8433 | 0 | IF_DEF_PARAMS(ifp)->p2mp_delay_reflood = |
8434 | 0 | OSPF_P2MP_DELAY_REFLOOD_DEFAULT; |
8435 | |
|
8436 | 0 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
8437 | 0 | return CMD_SUCCESS; |
8438 | | |
8439 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8440 | 0 | struct ospf_interface *oi = rn->info; |
8441 | |
|
8442 | 0 | if (!oi) |
8443 | 0 | continue; |
8444 | | |
8445 | 0 | oi->type = IF_DEF_PARAMS(ifp)->type; |
8446 | 0 | oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
8447 | 0 | oi->p2mp_delay_reflood = IF_DEF_PARAMS(ifp)->p2mp_delay_reflood; |
8448 | |
|
8449 | 0 | if (oi->state > ISM_Down) { |
8450 | 0 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); |
8451 | 0 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); |
8452 | 0 | } |
8453 | 0 | } |
8454 | |
|
8455 | 0 | return CMD_SUCCESS; |
8456 | 0 | } |
8457 | | |
8458 | | DEFUN_HIDDEN (no_ospf_network, |
8459 | | no_ospf_network_cmd, |
8460 | | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", |
8461 | | NO_STR |
8462 | | "OSPF interface commands\n" |
8463 | | "Network type\n" |
8464 | | "Specify OSPF broadcast multi-access network\n" |
8465 | | "Specify OSPF NBMA network\n" |
8466 | | "Specify OSPF point-to-multipoint network\n" |
8467 | | "Specify OSPF point-to-point network\n") |
8468 | 0 | { |
8469 | 0 | return no_ip_ospf_network(self, vty, argc, argv); |
8470 | 0 | } |
8471 | | |
8472 | | DEFUN (ip_ospf_priority, |
8473 | | ip_ospf_priority_cmd, |
8474 | | "ip ospf priority (0-255) [A.B.C.D]", |
8475 | | "IP Information\n" |
8476 | | "OSPF interface commands\n" |
8477 | | "Router priority\n" |
8478 | | "Priority\n" |
8479 | | "Address of interface\n") |
8480 | 0 | { |
8481 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8482 | 0 | int idx = 0; |
8483 | 0 | long priority; |
8484 | 0 | struct route_node *rn; |
8485 | 0 | struct in_addr addr; |
8486 | 0 | struct ospf_if_params *params; |
8487 | 0 | params = IF_DEF_PARAMS(ifp); |
8488 | |
|
8489 | 0 | argv_find(argv, argc, "(0-255)", &idx); |
8490 | 0 | priority = strtol(argv[idx]->arg, NULL, 10); |
8491 | |
|
8492 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8493 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
8494 | 0 | vty_out(vty, |
8495 | 0 | "Please specify interface address by A.B.C.D\n"); |
8496 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8497 | 0 | } |
8498 | | |
8499 | 0 | params = ospf_get_if_params(ifp, addr); |
8500 | 0 | ospf_if_update_params(ifp, addr); |
8501 | 0 | } |
8502 | | |
8503 | 0 | SET_IF_PARAM(params, priority); |
8504 | 0 | params->priority = priority; |
8505 | |
|
8506 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8507 | 0 | struct ospf_interface *oi = rn->info; |
8508 | |
|
8509 | 0 | if (!oi) |
8510 | 0 | continue; |
8511 | | |
8512 | 0 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
8513 | 0 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); |
8514 | 0 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); |
8515 | 0 | } |
8516 | 0 | } |
8517 | |
|
8518 | 0 | return CMD_SUCCESS; |
8519 | 0 | } |
8520 | | |
8521 | | DEFUN_HIDDEN (ospf_priority, |
8522 | | ospf_priority_cmd, |
8523 | | "ospf priority (0-255) [A.B.C.D]", |
8524 | | "OSPF interface commands\n" |
8525 | | "Router priority\n" |
8526 | | "Priority\n" |
8527 | | "Address of interface\n") |
8528 | 0 | { |
8529 | 0 | return ip_ospf_priority(self, vty, argc, argv); |
8530 | 0 | } |
8531 | | |
8532 | | DEFUN (no_ip_ospf_priority, |
8533 | | no_ip_ospf_priority_cmd, |
8534 | | "no ip ospf priority [(0-255) [A.B.C.D]]", |
8535 | | NO_STR |
8536 | | "IP Information\n" |
8537 | | "OSPF interface commands\n" |
8538 | | "Router priority\n" // ignored |
8539 | | "Priority\n" |
8540 | | "Address of interface\n") |
8541 | 0 | { |
8542 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8543 | 0 | int idx = 0; |
8544 | 0 | struct route_node *rn; |
8545 | 0 | struct in_addr addr; |
8546 | 0 | struct ospf_if_params *params; |
8547 | |
|
8548 | 0 | params = IF_DEF_PARAMS(ifp); |
8549 | |
|
8550 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8551 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
8552 | 0 | vty_out(vty, |
8553 | 0 | "Please specify interface address by A.B.C.D\n"); |
8554 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8555 | 0 | } |
8556 | | |
8557 | 0 | params = ospf_lookup_if_params(ifp, addr); |
8558 | 0 | if (params == NULL) |
8559 | 0 | return CMD_SUCCESS; |
8560 | 0 | } |
8561 | | |
8562 | 0 | UNSET_IF_PARAM(params, priority); |
8563 | 0 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; |
8564 | |
|
8565 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
8566 | 0 | ospf_free_if_params(ifp, addr); |
8567 | 0 | ospf_if_update_params(ifp, addr); |
8568 | 0 | } |
8569 | |
|
8570 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8571 | 0 | struct ospf_interface *oi = rn->info; |
8572 | |
|
8573 | 0 | if (!oi) |
8574 | 0 | continue; |
8575 | | |
8576 | 0 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
8577 | 0 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); |
8578 | 0 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); |
8579 | 0 | } |
8580 | 0 | } |
8581 | |
|
8582 | 0 | return CMD_SUCCESS; |
8583 | 0 | } |
8584 | | |
8585 | | DEFUN_HIDDEN (no_ospf_priority, |
8586 | | no_ospf_priority_cmd, |
8587 | | "no ospf priority [(0-255) [A.B.C.D]]", |
8588 | | NO_STR |
8589 | | "OSPF interface commands\n" |
8590 | | "Router priority\n" |
8591 | | "Priority\n" |
8592 | | "Address of interface\n") |
8593 | 0 | { |
8594 | 0 | return no_ip_ospf_priority(self, vty, argc, argv); |
8595 | 0 | } |
8596 | | |
8597 | | DEFUN (ip_ospf_retransmit_interval, |
8598 | | ip_ospf_retransmit_interval_addr_cmd, |
8599 | | "ip ospf retransmit-interval (1-65535) [A.B.C.D]", |
8600 | | "IP Information\n" |
8601 | | "OSPF interface commands\n" |
8602 | | "Time between retransmitting lost link state advertisements\n" |
8603 | | "Seconds\n" |
8604 | | "Address of interface\n") |
8605 | 0 | { |
8606 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8607 | 0 | int idx = 0; |
8608 | 0 | uint32_t seconds; |
8609 | 0 | struct in_addr addr; |
8610 | 0 | struct ospf_if_params *params; |
8611 | 0 | params = IF_DEF_PARAMS(ifp); |
8612 | |
|
8613 | 0 | argv_find(argv, argc, "(1-65535)", &idx); |
8614 | 0 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8615 | |
|
8616 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8617 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
8618 | 0 | vty_out(vty, |
8619 | 0 | "Please specify interface address by A.B.C.D\n"); |
8620 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8621 | 0 | } |
8622 | | |
8623 | 0 | params = ospf_get_if_params(ifp, addr); |
8624 | 0 | ospf_if_update_params(ifp, addr); |
8625 | 0 | } |
8626 | | |
8627 | 0 | SET_IF_PARAM(params, retransmit_interval); |
8628 | 0 | params->retransmit_interval = seconds; |
8629 | |
|
8630 | 0 | return CMD_SUCCESS; |
8631 | 0 | } |
8632 | | |
8633 | | DEFUN_HIDDEN (ospf_retransmit_interval, |
8634 | | ospf_retransmit_interval_cmd, |
8635 | | "ospf retransmit-interval (1-65535) [A.B.C.D]", |
8636 | | "OSPF interface commands\n" |
8637 | | "Time between retransmitting lost link state advertisements\n" |
8638 | | "Seconds\n" |
8639 | | "Address of interface\n") |
8640 | 0 | { |
8641 | 0 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
8642 | 0 | } |
8643 | | |
8644 | | DEFUN (no_ip_ospf_retransmit_interval, |
8645 | | no_ip_ospf_retransmit_interval_addr_cmd, |
8646 | | "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
8647 | | NO_STR |
8648 | | "IP Information\n" |
8649 | | "OSPF interface commands\n" |
8650 | | "Time between retransmitting lost link state advertisements\n" |
8651 | | "Seconds\n" |
8652 | | "Address of interface\n") |
8653 | 0 | { |
8654 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8655 | 0 | int idx = 0; |
8656 | 0 | struct in_addr addr; |
8657 | 0 | struct ospf_if_params *params; |
8658 | |
|
8659 | 0 | params = IF_DEF_PARAMS(ifp); |
8660 | |
|
8661 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8662 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
8663 | 0 | vty_out(vty, |
8664 | 0 | "Please specify interface address by A.B.C.D\n"); |
8665 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8666 | 0 | } |
8667 | | |
8668 | 0 | params = ospf_lookup_if_params(ifp, addr); |
8669 | 0 | if (params == NULL) |
8670 | 0 | return CMD_SUCCESS; |
8671 | 0 | } |
8672 | | |
8673 | 0 | UNSET_IF_PARAM(params, retransmit_interval); |
8674 | 0 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; |
8675 | |
|
8676 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
8677 | 0 | ospf_free_if_params(ifp, addr); |
8678 | 0 | ospf_if_update_params(ifp, addr); |
8679 | 0 | } |
8680 | |
|
8681 | 0 | return CMD_SUCCESS; |
8682 | 0 | } |
8683 | | |
8684 | | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
8685 | | no_ospf_retransmit_interval_cmd, |
8686 | | "no ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
8687 | | NO_STR |
8688 | | "OSPF interface commands\n" |
8689 | | "Time between retransmitting lost link state advertisements\n" |
8690 | | "Seconds\n" |
8691 | | "Address of interface\n") |
8692 | 0 | { |
8693 | 0 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
8694 | 0 | } |
8695 | | |
8696 | | DEFPY (ip_ospf_gr_hdelay, |
8697 | | ip_ospf_gr_hdelay_cmd, |
8698 | | "ip ospf graceful-restart hello-delay (1-1800)", |
8699 | | IP_STR |
8700 | | "OSPF interface commands\n" |
8701 | | "Graceful Restart parameters\n" |
8702 | | "Delay the sending of the first hello packets.\n" |
8703 | | "Delay in seconds\n") |
8704 | 0 | { |
8705 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8706 | 0 | struct ospf_if_params *params; |
8707 | |
|
8708 | 0 | params = IF_DEF_PARAMS(ifp); |
8709 | | |
8710 | | /* Note: new or updated value won't affect ongoing graceful restart. */ |
8711 | 0 | SET_IF_PARAM(params, v_gr_hello_delay); |
8712 | 0 | params->v_gr_hello_delay = hello_delay; |
8713 | |
|
8714 | 0 | return CMD_SUCCESS; |
8715 | 0 | } |
8716 | | |
8717 | | DEFPY (no_ip_ospf_gr_hdelay, |
8718 | | no_ip_ospf_gr_hdelay_cmd, |
8719 | | "no ip ospf graceful-restart hello-delay [(1-1800)]", |
8720 | | NO_STR |
8721 | | IP_STR |
8722 | | "OSPF interface commands\n" |
8723 | | "Graceful Restart parameters\n" |
8724 | | "Delay the sending of the first hello packets.\n" |
8725 | | "Delay in seconds\n") |
8726 | 0 | { |
8727 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8728 | 0 | struct ospf_if_params *params; |
8729 | 0 | struct route_node *rn; |
8730 | |
|
8731 | 0 | params = IF_DEF_PARAMS(ifp); |
8732 | 0 | UNSET_IF_PARAM(params, v_gr_hello_delay); |
8733 | 0 | params->v_gr_hello_delay = OSPF_HELLO_DELAY_DEFAULT; |
8734 | |
|
8735 | 0 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8736 | 0 | struct ospf_interface *oi; |
8737 | |
|
8738 | 0 | oi = rn->info; |
8739 | 0 | if (!oi) |
8740 | 0 | continue; |
8741 | | |
8742 | 0 | oi->gr.hello_delay.elapsed_seconds = 0; |
8743 | 0 | EVENT_OFF(oi->gr.hello_delay.t_grace_send); |
8744 | 0 | } |
8745 | |
|
8746 | 0 | return CMD_SUCCESS; |
8747 | 0 | } |
8748 | | |
8749 | | DEFUN (ip_ospf_transmit_delay, |
8750 | | ip_ospf_transmit_delay_addr_cmd, |
8751 | | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
8752 | | "IP Information\n" |
8753 | | "OSPF interface commands\n" |
8754 | | "Link state transmit delay\n" |
8755 | | "Seconds\n" |
8756 | | "Address of interface\n") |
8757 | 0 | { |
8758 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8759 | 0 | int idx = 0; |
8760 | 0 | uint32_t seconds; |
8761 | 0 | struct in_addr addr; |
8762 | 0 | struct ospf_if_params *params; |
8763 | |
|
8764 | 0 | params = IF_DEF_PARAMS(ifp); |
8765 | 0 | argv_find(argv, argc, "(1-65535)", &idx); |
8766 | 0 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8767 | |
|
8768 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8769 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
8770 | 0 | vty_out(vty, |
8771 | 0 | "Please specify interface address by A.B.C.D\n"); |
8772 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8773 | 0 | } |
8774 | | |
8775 | 0 | params = ospf_get_if_params(ifp, addr); |
8776 | 0 | ospf_if_update_params(ifp, addr); |
8777 | 0 | } |
8778 | | |
8779 | 0 | SET_IF_PARAM(params, transmit_delay); |
8780 | 0 | params->transmit_delay = seconds; |
8781 | |
|
8782 | 0 | return CMD_SUCCESS; |
8783 | 0 | } |
8784 | | |
8785 | | DEFUN_HIDDEN (ospf_transmit_delay, |
8786 | | ospf_transmit_delay_cmd, |
8787 | | "ospf transmit-delay (1-65535) [A.B.C.D]", |
8788 | | "OSPF interface commands\n" |
8789 | | "Link state transmit delay\n" |
8790 | | "Seconds\n" |
8791 | | "Address of interface\n") |
8792 | 0 | { |
8793 | 0 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
8794 | 0 | } |
8795 | | |
8796 | | DEFUN (no_ip_ospf_transmit_delay, |
8797 | | no_ip_ospf_transmit_delay_addr_cmd, |
8798 | | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
8799 | | NO_STR |
8800 | | "IP Information\n" |
8801 | | "OSPF interface commands\n" |
8802 | | "Link state transmit delay\n" |
8803 | | "Seconds\n" |
8804 | | "Address of interface\n") |
8805 | 0 | { |
8806 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8807 | 0 | int idx = 0; |
8808 | 0 | struct in_addr addr; |
8809 | 0 | struct ospf_if_params *params; |
8810 | |
|
8811 | 0 | params = IF_DEF_PARAMS(ifp); |
8812 | |
|
8813 | 0 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8814 | 0 | if (!inet_aton(argv[idx]->arg, &addr)) { |
8815 | 0 | vty_out(vty, |
8816 | 0 | "Please specify interface address by A.B.C.D\n"); |
8817 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8818 | 0 | } |
8819 | | |
8820 | 0 | params = ospf_lookup_if_params(ifp, addr); |
8821 | 0 | if (params == NULL) |
8822 | 0 | return CMD_SUCCESS; |
8823 | 0 | } |
8824 | | |
8825 | 0 | UNSET_IF_PARAM(params, transmit_delay); |
8826 | 0 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; |
8827 | |
|
8828 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
8829 | 0 | ospf_free_if_params(ifp, addr); |
8830 | 0 | ospf_if_update_params(ifp, addr); |
8831 | 0 | } |
8832 | |
|
8833 | 0 | return CMD_SUCCESS; |
8834 | 0 | } |
8835 | | |
8836 | | |
8837 | | DEFUN_HIDDEN (no_ospf_transmit_delay, |
8838 | | no_ospf_transmit_delay_cmd, |
8839 | | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
8840 | | NO_STR |
8841 | | "OSPF interface commands\n" |
8842 | | "Link state transmit delay\n" |
8843 | | "Seconds\n" |
8844 | | "Address of interface\n") |
8845 | 0 | { |
8846 | 0 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
8847 | 0 | } |
8848 | | |
8849 | | DEFUN (ip_ospf_area, |
8850 | | ip_ospf_area_cmd, |
8851 | | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
8852 | | "IP Information\n" |
8853 | | "OSPF interface commands\n" |
8854 | | "Instance ID\n" |
8855 | | "Enable OSPF on this interface\n" |
8856 | | "OSPF area ID in IP address format\n" |
8857 | | "OSPF area ID as a decimal value\n" |
8858 | | "Address of interface\n") |
8859 | 0 | { |
8860 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8861 | 0 | int idx = 0; |
8862 | 0 | int format, ret; |
8863 | 0 | struct in_addr area_id; |
8864 | 0 | struct in_addr addr; |
8865 | 0 | struct ospf_if_params *params = NULL; |
8866 | 0 | struct route_node *rn; |
8867 | 0 | struct ospf *ospf = NULL; |
8868 | 0 | unsigned short instance = 0; |
8869 | 0 | char *areaid; |
8870 | 0 | uint32_t count = 0; |
8871 | |
|
8872 | 0 | if (argv_find(argv, argc, "(1-65535)", &idx)) |
8873 | 0 | instance = strtol(argv[idx]->arg, NULL, 10); |
8874 | |
|
8875 | 0 | argv_find(argv, argc, "area", &idx); |
8876 | 0 | areaid = argv[idx + 1]->arg; |
8877 | |
|
8878 | 0 | if (!instance) |
8879 | 0 | ospf = ifp->vrf->info; |
8880 | 0 | else |
8881 | 0 | ospf = ospf_lookup_instance(instance); |
8882 | |
|
8883 | 0 | if (instance && instance != ospf_instance) { |
8884 | | /* |
8885 | | * At this point we know we have received |
8886 | | * an instance and there is no ospf instance |
8887 | | * associated with it. This means we are |
8888 | | * in a situation where we have an |
8889 | | * ospf command that is setup for a different |
8890 | | * process(instance). We need to safely |
8891 | | * remove the command from ourselves and |
8892 | | * allow the other instance(process) handle |
8893 | | * the configuration command. |
8894 | | */ |
8895 | 0 | count = 0; |
8896 | |
|
8897 | 0 | params = IF_DEF_PARAMS(ifp); |
8898 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
8899 | 0 | UNSET_IF_PARAM(params, if_area); |
8900 | 0 | count++; |
8901 | 0 | } |
8902 | |
|
8903 | 0 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) |
8904 | 0 | if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
8905 | 0 | UNSET_IF_PARAM(params, if_area); |
8906 | 0 | count++; |
8907 | 0 | } |
8908 | |
|
8909 | 0 | if (count > 0) { |
8910 | 0 | ospf = ifp->vrf->info; |
8911 | 0 | if (ospf) |
8912 | 0 | ospf_interface_area_unset(ospf, ifp); |
8913 | 0 | } |
8914 | |
|
8915 | 0 | return CMD_NOT_MY_INSTANCE; |
8916 | 0 | } |
8917 | | |
8918 | 0 | ret = str2area_id(areaid, &area_id, &format); |
8919 | 0 | if (ret < 0) { |
8920 | 0 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); |
8921 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8922 | 0 | } |
8923 | 0 | if (memcmp(ifp->name, "VLINK", 5) == 0) { |
8924 | 0 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); |
8925 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8926 | 0 | } |
8927 | | |
8928 | 0 | if (ospf) { |
8929 | 0 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { |
8930 | 0 | if (rn->info != NULL) { |
8931 | 0 | vty_out(vty, |
8932 | 0 | "Please remove all network commands first.\n"); |
8933 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8934 | 0 | } |
8935 | 0 | } |
8936 | 0 | } |
8937 | | |
8938 | 0 | params = IF_DEF_PARAMS(ifp); |
8939 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) |
8940 | 0 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { |
8941 | 0 | vty_out(vty, |
8942 | 0 | "Must remove previous area config before changing ospf area \n"); |
8943 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8944 | 0 | } |
8945 | | |
8946 | | // Check if we have an address arg and proccess it |
8947 | 0 | if (argc == idx + 3) { |
8948 | 0 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
8949 | 0 | vty_out(vty, |
8950 | 0 | "Please specify Intf Address by A.B.C.D\n"); |
8951 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8952 | 0 | } |
8953 | | // update/create address-level params |
8954 | 0 | params = ospf_get_if_params((ifp), (addr)); |
8955 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
8956 | 0 | if (!IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { |
8957 | 0 | vty_out(vty, |
8958 | 0 | "Must remove previous area/address config before changing ospf area\n"); |
8959 | 0 | return CMD_WARNING_CONFIG_FAILED; |
8960 | 0 | } else |
8961 | 0 | return CMD_SUCCESS; |
8962 | 0 | } |
8963 | 0 | ospf_if_update_params((ifp), (addr)); |
8964 | 0 | } |
8965 | | |
8966 | | /* enable ospf on this interface with area_id */ |
8967 | 0 | if (params) { |
8968 | 0 | SET_IF_PARAM(params, if_area); |
8969 | 0 | params->if_area = area_id; |
8970 | 0 | params->if_area_id_fmt = format; |
8971 | 0 | } |
8972 | |
|
8973 | 0 | if (ospf) |
8974 | 0 | ospf_interface_area_set(ospf, ifp); |
8975 | |
|
8976 | 0 | return CMD_SUCCESS; |
8977 | 0 | } |
8978 | | |
8979 | | DEFUN (no_ip_ospf_area, |
8980 | | no_ip_ospf_area_cmd, |
8981 | | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
8982 | | NO_STR |
8983 | | "IP Information\n" |
8984 | | "OSPF interface commands\n" |
8985 | | "Instance ID\n" |
8986 | | "Disable OSPF on this interface\n" |
8987 | | "OSPF area ID in IP address format\n" |
8988 | | "OSPF area ID as a decimal value\n" |
8989 | | "Address of interface\n") |
8990 | 0 | { |
8991 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8992 | 0 | int idx = 0; |
8993 | 0 | struct ospf *ospf; |
8994 | 0 | struct ospf_if_params *params; |
8995 | 0 | unsigned short instance = 0; |
8996 | 0 | struct in_addr addr; |
8997 | 0 | struct in_addr area_id; |
8998 | |
|
8999 | 0 | if (argv_find(argv, argc, "(1-65535)", &idx)) |
9000 | 0 | instance = strtol(argv[idx]->arg, NULL, 10); |
9001 | |
|
9002 | 0 | if (!instance) |
9003 | 0 | ospf = ifp->vrf->info; |
9004 | 0 | else |
9005 | 0 | ospf = ospf_lookup_instance(instance); |
9006 | |
|
9007 | 0 | if (instance && instance != ospf_instance) |
9008 | 0 | return CMD_NOT_MY_INSTANCE; |
9009 | | |
9010 | 0 | argv_find(argv, argc, "area", &idx); |
9011 | | |
9012 | | // Check if we have an address arg and proccess it |
9013 | 0 | if (argc == idx + 3) { |
9014 | 0 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
9015 | 0 | vty_out(vty, |
9016 | 0 | "Please specify Intf Address by A.B.C.D\n"); |
9017 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9018 | 0 | } |
9019 | 0 | params = ospf_lookup_if_params(ifp, addr); |
9020 | 0 | if ((params) == NULL) |
9021 | 0 | return CMD_SUCCESS; |
9022 | 0 | } else |
9023 | 0 | params = IF_DEF_PARAMS(ifp); |
9024 | | |
9025 | 0 | area_id = params->if_area; |
9026 | 0 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
9027 | 0 | vty_out(vty, |
9028 | 0 | "Can't find specified interface area configuration.\n"); |
9029 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9030 | 0 | } |
9031 | | |
9032 | 0 | UNSET_IF_PARAM(params, if_area); |
9033 | 0 | if (params != IF_DEF_PARAMS((ifp))) { |
9034 | 0 | ospf_free_if_params((ifp), (addr)); |
9035 | 0 | ospf_if_update_params((ifp), (addr)); |
9036 | 0 | } |
9037 | |
|
9038 | 0 | if (ospf) { |
9039 | 0 | ospf_interface_area_unset(ospf, ifp); |
9040 | 0 | ospf_area_check_free(ospf, area_id); |
9041 | 0 | } |
9042 | |
|
9043 | 0 | return CMD_SUCCESS; |
9044 | 0 | } |
9045 | | |
9046 | | DEFUN (ip_ospf_passive, |
9047 | | ip_ospf_passive_cmd, |
9048 | | "ip ospf passive [A.B.C.D]", |
9049 | | "IP Information\n" |
9050 | | "OSPF interface commands\n" |
9051 | | "Suppress routing updates on an interface\n" |
9052 | | "Address of interface\n") |
9053 | 0 | { |
9054 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9055 | 0 | int idx_ipv4 = 3; |
9056 | 0 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
9057 | 0 | struct ospf_if_params *params; |
9058 | 0 | int ret; |
9059 | |
|
9060 | 0 | if (argc == 4) { |
9061 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
9062 | 0 | if (!ret) { |
9063 | 0 | vty_out(vty, |
9064 | 0 | "Please specify interface address by A.B.C.D\n"); |
9065 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9066 | 0 | } |
9067 | 0 | params = ospf_get_if_params(ifp, addr); |
9068 | 0 | ospf_if_update_params(ifp, addr); |
9069 | 0 | } else { |
9070 | 0 | params = IF_DEF_PARAMS(ifp); |
9071 | 0 | } |
9072 | | |
9073 | 0 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE); |
9074 | |
|
9075 | 0 | return CMD_SUCCESS; |
9076 | 0 | } |
9077 | | |
9078 | | DEFUN (no_ip_ospf_passive, |
9079 | | no_ip_ospf_passive_cmd, |
9080 | | "no ip ospf passive [A.B.C.D]", |
9081 | | NO_STR |
9082 | | "IP Information\n" |
9083 | | "OSPF interface commands\n" |
9084 | | "Enable routing updates on an interface\n" |
9085 | | "Address of interface\n") |
9086 | 0 | { |
9087 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9088 | 0 | int idx_ipv4 = 4; |
9089 | 0 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
9090 | 0 | struct ospf_if_params *params; |
9091 | 0 | int ret; |
9092 | |
|
9093 | 0 | if (argc == 5) { |
9094 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
9095 | 0 | if (!ret) { |
9096 | 0 | vty_out(vty, |
9097 | 0 | "Please specify interface address by A.B.C.D\n"); |
9098 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9099 | 0 | } |
9100 | 0 | params = ospf_lookup_if_params(ifp, addr); |
9101 | 0 | if (params == NULL) |
9102 | 0 | return CMD_SUCCESS; |
9103 | 0 | } else { |
9104 | 0 | params = IF_DEF_PARAMS(ifp); |
9105 | 0 | } |
9106 | | |
9107 | 0 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE); |
9108 | |
|
9109 | 0 | return CMD_SUCCESS; |
9110 | 0 | } |
9111 | | |
9112 | | DEFUN (ospf_redistribute_source, |
9113 | | ospf_redistribute_source_cmd, |
9114 | | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
9115 | | REDIST_STR |
9116 | | FRR_REDIST_HELP_STR_OSPFD |
9117 | | "Metric for redistributed routes\n" |
9118 | | "OSPF default metric\n" |
9119 | | "OSPF exterior metric type for redistributed routes\n" |
9120 | | "Set OSPF External Type 1/2 metrics\n" |
9121 | | "Route map reference\n" |
9122 | | "Pointer to route-map entries\n") |
9123 | 0 | { |
9124 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9125 | 0 | int idx_protocol = 1; |
9126 | 0 | int source; |
9127 | 0 | int type = -1; |
9128 | 0 | int metric = -1; |
9129 | 0 | struct ospf_redist *red; |
9130 | 0 | int idx = 0; |
9131 | 0 | bool update = false; |
9132 | | |
9133 | | /* Get distribute source. */ |
9134 | 0 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
9135 | 0 | if (source < 0) |
9136 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9137 | | |
9138 | | /* Get metric value. */ |
9139 | 0 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
9140 | 0 | if (!str2metric(argv[idx]->arg, &metric)) |
9141 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9142 | 0 | } |
9143 | 0 | idx = 1; |
9144 | | /* Get metric type. */ |
9145 | 0 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
9146 | 0 | if (!str2metric_type(argv[idx]->arg, &type)) |
9147 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9148 | 0 | } |
9149 | 0 | idx = 1; |
9150 | |
|
9151 | 0 | red = ospf_redist_lookup(ospf, source, 0); |
9152 | 0 | if (!red) |
9153 | 0 | red = ospf_redist_add(ospf, source, 0); |
9154 | 0 | else |
9155 | 0 | update = true; |
9156 | | |
9157 | | /* Get route-map */ |
9158 | 0 | if (argv_find(argv, argc, "route-map", &idx)) { |
9159 | 0 | ospf_routemap_set(red, argv[idx + 1]->arg); |
9160 | 0 | } else |
9161 | 0 | ospf_routemap_unset(red); |
9162 | |
|
9163 | 0 | if (update) |
9164 | 0 | return ospf_redistribute_update(ospf, red, source, 0, type, |
9165 | 0 | metric); |
9166 | 0 | else |
9167 | 0 | return ospf_redistribute_set(ospf, red, source, 0, type, |
9168 | 0 | metric); |
9169 | 0 | } |
9170 | | |
9171 | | DEFUN (no_ospf_redistribute_source, |
9172 | | no_ospf_redistribute_source_cmd, |
9173 | | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
9174 | | NO_STR |
9175 | | REDIST_STR |
9176 | | FRR_REDIST_HELP_STR_OSPFD |
9177 | | "Metric for redistributed routes\n" |
9178 | | "OSPF default metric\n" |
9179 | | "OSPF exterior metric type for redistributed routes\n" |
9180 | | "Set OSPF External Type 1/2 metrics\n" |
9181 | | "Route map reference\n" |
9182 | | "Pointer to route-map entries\n") |
9183 | 0 | { |
9184 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9185 | 0 | int idx_protocol = 2; |
9186 | 0 | int source; |
9187 | 0 | struct ospf_redist *red; |
9188 | |
|
9189 | 0 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
9190 | 0 | if (source < 0) |
9191 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9192 | | |
9193 | 0 | red = ospf_redist_lookup(ospf, source, 0); |
9194 | 0 | if (!red) |
9195 | 0 | return CMD_SUCCESS; |
9196 | | |
9197 | 0 | ospf_routemap_unset(red); |
9198 | 0 | ospf_redist_del(ospf, source, 0); |
9199 | |
|
9200 | 0 | return ospf_redistribute_unset(ospf, source, 0); |
9201 | 0 | } |
9202 | | |
9203 | | DEFUN (ospf_redistribute_instance_source, |
9204 | | ospf_redistribute_instance_source_cmd, |
9205 | | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
9206 | | REDIST_STR |
9207 | | "Open Shortest Path First\n" |
9208 | | "Non-main Kernel Routing Table\n" |
9209 | | "Instance ID/Table ID\n" |
9210 | | "Metric for redistributed routes\n" |
9211 | | "OSPF default metric\n" |
9212 | | "OSPF exterior metric type for redistributed routes\n" |
9213 | | "Set OSPF External Type 1/2 metrics\n" |
9214 | | "Route map reference\n" |
9215 | | "Pointer to route-map entries\n") |
9216 | 0 | { |
9217 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9218 | 0 | int idx_ospf_table = 1; |
9219 | 0 | int idx_number = 2; |
9220 | 0 | int idx = 3; |
9221 | 0 | int source; |
9222 | 0 | int type = -1; |
9223 | 0 | int metric = -1; |
9224 | 0 | unsigned short instance; |
9225 | 0 | struct ospf_redist *red; |
9226 | 0 | bool update = false; |
9227 | |
|
9228 | 0 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
9229 | |
|
9230 | 0 | if (source < 0) { |
9231 | 0 | vty_out(vty, "Unknown instance redistribution\n"); |
9232 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9233 | 0 | } |
9234 | | |
9235 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
9236 | |
|
9237 | 0 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9238 | 0 | vty_out(vty, |
9239 | 0 | "Instance redistribution in non-instanced OSPF not allowed\n"); |
9240 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9241 | 0 | } |
9242 | | |
9243 | 0 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
9244 | 0 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); |
9245 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9246 | 0 | } |
9247 | | |
9248 | | /* Get metric value. */ |
9249 | 0 | if (argv_find(argv, argc, "metric", &idx)) |
9250 | 0 | if (!str2metric(argv[idx + 1]->arg, &metric)) |
9251 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9252 | | |
9253 | 0 | idx = 3; |
9254 | | /* Get metric type. */ |
9255 | 0 | if (argv_find(argv, argc, "metric-type", &idx)) |
9256 | 0 | if (!str2metric_type(argv[idx + 1]->arg, &type)) |
9257 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9258 | | |
9259 | 0 | red = ospf_redist_lookup(ospf, source, instance); |
9260 | 0 | if (!red) |
9261 | 0 | red = ospf_redist_add(ospf, source, instance); |
9262 | 0 | else |
9263 | 0 | update = true; |
9264 | |
|
9265 | 0 | idx = 3; |
9266 | 0 | if (argv_find(argv, argc, "route-map", &idx)) |
9267 | 0 | ospf_routemap_set(red, argv[idx + 1]->arg); |
9268 | 0 | else |
9269 | 0 | ospf_routemap_unset(red); |
9270 | |
|
9271 | 0 | if (update) |
9272 | 0 | return ospf_redistribute_update(ospf, red, source, instance, |
9273 | 0 | type, metric); |
9274 | 0 | else |
9275 | 0 | return ospf_redistribute_set(ospf, red, source, instance, type, |
9276 | 0 | metric); |
9277 | 0 | } |
9278 | | |
9279 | | DEFUN (no_ospf_redistribute_instance_source, |
9280 | | no_ospf_redistribute_instance_source_cmd, |
9281 | | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
9282 | | NO_STR |
9283 | | REDIST_STR |
9284 | | "Open Shortest Path First\n" |
9285 | | "Non-main Kernel Routing Table\n" |
9286 | | "Instance ID/Table Id\n" |
9287 | | "Metric for redistributed routes\n" |
9288 | | "OSPF default metric\n" |
9289 | | "OSPF exterior metric type for redistributed routes\n" |
9290 | | "Set OSPF External Type 1/2 metrics\n" |
9291 | | "Route map reference\n" |
9292 | | "Pointer to route-map entries\n") |
9293 | 0 | { |
9294 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9295 | 0 | int idx_ospf_table = 2; |
9296 | 0 | int idx_number = 3; |
9297 | 0 | unsigned int instance; |
9298 | 0 | struct ospf_redist *red; |
9299 | 0 | int source; |
9300 | |
|
9301 | 0 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) |
9302 | 0 | source = ZEBRA_ROUTE_OSPF; |
9303 | 0 | else |
9304 | 0 | source = ZEBRA_ROUTE_TABLE; |
9305 | |
|
9306 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
9307 | |
|
9308 | 0 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9309 | 0 | vty_out(vty, |
9310 | 0 | "Instance redistribution in non-instanced OSPF not allowed\n"); |
9311 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9312 | 0 | } |
9313 | | |
9314 | 0 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
9315 | 0 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); |
9316 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9317 | 0 | } |
9318 | | |
9319 | 0 | red = ospf_redist_lookup(ospf, source, instance); |
9320 | 0 | if (!red) |
9321 | 0 | return CMD_SUCCESS; |
9322 | | |
9323 | 0 | ospf_routemap_unset(red); |
9324 | 0 | ospf_redist_del(ospf, source, instance); |
9325 | |
|
9326 | 0 | return ospf_redistribute_unset(ospf, source, instance); |
9327 | 0 | } |
9328 | | |
9329 | | DEFUN (ospf_distribute_list_out, |
9330 | | ospf_distribute_list_out_cmd, |
9331 | | "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD, |
9332 | | "Filter networks in routing updates\n" |
9333 | | "Access-list name\n" |
9334 | | OUT_STR |
9335 | | FRR_REDIST_HELP_STR_OSPFD) |
9336 | 0 | { |
9337 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9338 | 0 | int idx_word = 1; |
9339 | 0 | int source; |
9340 | |
|
9341 | 0 | char *proto = argv[argc - 1]->text; |
9342 | | |
9343 | | /* Get distribute source. */ |
9344 | 0 | source = proto_redistnum(AFI_IP, proto); |
9345 | 0 | if (source < 0) |
9346 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9347 | | |
9348 | 0 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
9349 | 0 | } |
9350 | | |
9351 | | DEFUN (no_ospf_distribute_list_out, |
9352 | | no_ospf_distribute_list_out_cmd, |
9353 | | "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD, |
9354 | | NO_STR |
9355 | | "Filter networks in routing updates\n" |
9356 | | "Access-list name\n" |
9357 | | OUT_STR |
9358 | | FRR_REDIST_HELP_STR_OSPFD) |
9359 | 0 | { |
9360 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9361 | 0 | int idx_word = 2; |
9362 | 0 | int source; |
9363 | |
|
9364 | 0 | char *proto = argv[argc - 1]->text; |
9365 | 0 | source = proto_redistnum(AFI_IP, proto); |
9366 | 0 | if (source < 0) |
9367 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9368 | | |
9369 | 0 | return ospf_distribute_list_out_unset(ospf, source, |
9370 | 0 | argv[idx_word]->arg); |
9371 | 0 | } |
9372 | | |
9373 | | /* Default information originate. */ |
9374 | | DEFUN (ospf_default_information_originate, |
9375 | | ospf_default_information_originate_cmd, |
9376 | | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
9377 | | "Control distribution of default information\n" |
9378 | | "Distribute a default route\n" |
9379 | | "Always advertise default route\n" |
9380 | | "OSPF default metric\n" |
9381 | | "OSPF metric\n" |
9382 | | "OSPF metric type for default routes\n" |
9383 | | "Set OSPF External Type 1/2 metrics\n" |
9384 | | "Route map reference\n" |
9385 | | "Pointer to route-map entries\n") |
9386 | 0 | { |
9387 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9388 | 0 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
9389 | 0 | int type = -1; |
9390 | 0 | int metric = -1; |
9391 | 0 | struct ospf_redist *red; |
9392 | 0 | int idx = 0; |
9393 | 0 | int cur_originate = ospf->default_originate; |
9394 | 0 | bool sameRtmap = false; |
9395 | 0 | char *rtmap = NULL; |
9396 | |
|
9397 | 0 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); |
9398 | | |
9399 | | /* Check whether "always" was specified */ |
9400 | 0 | if (argv_find(argv, argc, "always", &idx)) |
9401 | 0 | default_originate = DEFAULT_ORIGINATE_ALWAYS; |
9402 | 0 | idx = 1; |
9403 | | /* Get metric value */ |
9404 | 0 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
9405 | 0 | if (!str2metric(argv[idx]->arg, &metric)) |
9406 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9407 | 0 | } |
9408 | 0 | idx = 1; |
9409 | | /* Get metric type. */ |
9410 | 0 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
9411 | 0 | if (!str2metric_type(argv[idx]->arg, &type)) |
9412 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9413 | 0 | } |
9414 | 0 | idx = 1; |
9415 | | /* Get route-map */ |
9416 | 0 | if (argv_find(argv, argc, "route-map", &idx)) |
9417 | 0 | rtmap = argv[idx + 1]->arg; |
9418 | | |
9419 | | /* To check if user is providing same route map */ |
9420 | 0 | if ((!rtmap && !ROUTEMAP_NAME(red)) || |
9421 | 0 | (rtmap && ROUTEMAP_NAME(red) && |
9422 | 0 | (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) |
9423 | 0 | sameRtmap = true; |
9424 | | |
9425 | | /* Don't allow if the same lsa is already originated. */ |
9426 | 0 | if ((sameRtmap) |
9427 | 0 | && (red->dmetric.type == type) |
9428 | 0 | && (red->dmetric.value == metric) |
9429 | 0 | && (cur_originate == default_originate)) |
9430 | 0 | return CMD_SUCCESS; |
9431 | | |
9432 | | /* Updating Metric details */ |
9433 | 0 | red->dmetric.type = type; |
9434 | 0 | red->dmetric.value = metric; |
9435 | | |
9436 | | /* updating route map details */ |
9437 | 0 | if (rtmap) |
9438 | 0 | ospf_routemap_set(red, rtmap); |
9439 | 0 | else |
9440 | 0 | ospf_routemap_unset(red); |
9441 | |
|
9442 | 0 | return ospf_redistribute_default_set(ospf, default_originate, type, |
9443 | 0 | metric); |
9444 | 0 | } |
9445 | | |
9446 | | DEFUN (no_ospf_default_information_originate, |
9447 | | no_ospf_default_information_originate_cmd, |
9448 | | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
9449 | | NO_STR |
9450 | | "Control distribution of default information\n" |
9451 | | "Distribute a default route\n" |
9452 | | "Always advertise default route\n" |
9453 | | "OSPF default metric\n" |
9454 | | "OSPF metric\n" |
9455 | | "OSPF metric type for default routes\n" |
9456 | | "Set OSPF External Type 1/2 metrics\n" |
9457 | | "Route map reference\n" |
9458 | | "Pointer to route-map entries\n") |
9459 | 0 | { |
9460 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9461 | 0 | struct ospf_redist *red; |
9462 | |
|
9463 | 0 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9464 | 0 | if (!red) |
9465 | 0 | return CMD_SUCCESS; |
9466 | | |
9467 | 0 | ospf_routemap_unset(red); |
9468 | 0 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
9469 | |
|
9470 | 0 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
9471 | 0 | 0, 0); |
9472 | 0 | } |
9473 | | |
9474 | | DEFUN (ospf_default_metric, |
9475 | | ospf_default_metric_cmd, |
9476 | | "default-metric (0-16777214)", |
9477 | | "Set metric of redistributed routes\n" |
9478 | | "Default metric\n") |
9479 | 0 | { |
9480 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9481 | 0 | int idx_number = 1; |
9482 | 0 | int metric = -1; |
9483 | |
|
9484 | 0 | if (!str2metric(argv[idx_number]->arg, &metric)) |
9485 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9486 | | |
9487 | 0 | ospf->default_metric = metric; |
9488 | |
|
9489 | 0 | return CMD_SUCCESS; |
9490 | 0 | } |
9491 | | |
9492 | | DEFUN (no_ospf_default_metric, |
9493 | | no_ospf_default_metric_cmd, |
9494 | | "no default-metric [(0-16777214)]", |
9495 | | NO_STR |
9496 | | "Set metric of redistributed routes\n" |
9497 | | "Default metric\n") |
9498 | 0 | { |
9499 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9500 | |
|
9501 | 0 | ospf->default_metric = -1; |
9502 | |
|
9503 | 0 | return CMD_SUCCESS; |
9504 | 0 | } |
9505 | | |
9506 | | |
9507 | | DEFUN (ospf_distance, |
9508 | | ospf_distance_cmd, |
9509 | | "distance (1-255)", |
9510 | | "Administrative distance\n" |
9511 | | "OSPF Administrative distance\n") |
9512 | 0 | { |
9513 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9514 | 0 | int idx_number = 1; |
9515 | 0 | uint8_t distance; |
9516 | |
|
9517 | 0 | distance = atoi(argv[idx_number]->arg); |
9518 | 0 | if (ospf->distance_all != distance) { |
9519 | 0 | ospf->distance_all = distance; |
9520 | 0 | ospf_restart_spf(ospf); |
9521 | 0 | } |
9522 | |
|
9523 | 0 | return CMD_SUCCESS; |
9524 | 0 | } |
9525 | | |
9526 | | DEFUN (no_ospf_distance, |
9527 | | no_ospf_distance_cmd, |
9528 | | "no distance (1-255)", |
9529 | | NO_STR |
9530 | | "Administrative distance\n" |
9531 | | "OSPF Administrative distance\n") |
9532 | 0 | { |
9533 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9534 | |
|
9535 | 0 | if (ospf->distance_all) { |
9536 | 0 | ospf->distance_all = 0; |
9537 | 0 | ospf_restart_spf(ospf); |
9538 | 0 | } |
9539 | |
|
9540 | 0 | return CMD_SUCCESS; |
9541 | 0 | } |
9542 | | |
9543 | | DEFUN (no_ospf_distance_ospf, |
9544 | | no_ospf_distance_ospf_cmd, |
9545 | | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
9546 | | NO_STR |
9547 | | "Administrative distance\n" |
9548 | | "OSPF administrative distance\n" |
9549 | | "Intra-area routes\n" |
9550 | | "Distance for intra-area routes\n" |
9551 | | "Inter-area routes\n" |
9552 | | "Distance for inter-area routes\n" |
9553 | | "External routes\n" |
9554 | | "Distance for external routes\n") |
9555 | 0 | { |
9556 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9557 | 0 | int idx = 0; |
9558 | |
|
9559 | 0 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
9560 | 0 | idx = ospf->distance_intra = 0; |
9561 | 0 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) |
9562 | 0 | idx = ospf->distance_inter = 0; |
9563 | 0 | if (argv_find(argv, argc, "external", &idx) || argc == 3) |
9564 | 0 | ospf->distance_external = 0; |
9565 | |
|
9566 | 0 | return CMD_SUCCESS; |
9567 | 0 | } |
9568 | | |
9569 | | DEFUN (ospf_distance_ospf, |
9570 | | ospf_distance_ospf_cmd, |
9571 | | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
9572 | | "Administrative distance\n" |
9573 | | "OSPF administrative distance\n" |
9574 | | "Intra-area routes\n" |
9575 | | "Distance for intra-area routes\n" |
9576 | | "Inter-area routes\n" |
9577 | | "Distance for inter-area routes\n" |
9578 | | "External routes\n" |
9579 | | "Distance for external routes\n") |
9580 | 0 | { |
9581 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9582 | 0 | int idx = 0; |
9583 | |
|
9584 | 0 | ospf->distance_intra = 0; |
9585 | 0 | ospf->distance_inter = 0; |
9586 | 0 | ospf->distance_external = 0; |
9587 | |
|
9588 | 0 | if (argv_find(argv, argc, "intra-area", &idx)) |
9589 | 0 | ospf->distance_intra = atoi(argv[idx + 1]->arg); |
9590 | 0 | idx = 0; |
9591 | 0 | if (argv_find(argv, argc, "inter-area", &idx)) |
9592 | 0 | ospf->distance_inter = atoi(argv[idx + 1]->arg); |
9593 | 0 | idx = 0; |
9594 | 0 | if (argv_find(argv, argc, "external", &idx)) |
9595 | 0 | ospf->distance_external = atoi(argv[idx + 1]->arg); |
9596 | |
|
9597 | 0 | return CMD_SUCCESS; |
9598 | 0 | } |
9599 | | |
9600 | | DEFUN (ip_ospf_mtu_ignore, |
9601 | | ip_ospf_mtu_ignore_addr_cmd, |
9602 | | "ip ospf mtu-ignore [A.B.C.D]", |
9603 | | "IP Information\n" |
9604 | | "OSPF interface commands\n" |
9605 | | "Disable MTU mismatch detection on this interface\n" |
9606 | | "Address of interface\n") |
9607 | 0 | { |
9608 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9609 | 0 | int idx_ipv4 = 3; |
9610 | 0 | struct in_addr addr; |
9611 | 0 | int ret; |
9612 | |
|
9613 | 0 | struct ospf_if_params *params; |
9614 | 0 | params = IF_DEF_PARAMS(ifp); |
9615 | |
|
9616 | 0 | if (argc == 4) { |
9617 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
9618 | 0 | if (!ret) { |
9619 | 0 | vty_out(vty, |
9620 | 0 | "Please specify interface address by A.B.C.D\n"); |
9621 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9622 | 0 | } |
9623 | 0 | params = ospf_get_if_params(ifp, addr); |
9624 | 0 | ospf_if_update_params(ifp, addr); |
9625 | 0 | } |
9626 | 0 | params->mtu_ignore = 1; |
9627 | 0 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) |
9628 | 0 | SET_IF_PARAM(params, mtu_ignore); |
9629 | 0 | else { |
9630 | 0 | UNSET_IF_PARAM(params, mtu_ignore); |
9631 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
9632 | 0 | ospf_free_if_params(ifp, addr); |
9633 | 0 | ospf_if_update_params(ifp, addr); |
9634 | 0 | } |
9635 | 0 | } |
9636 | 0 | return CMD_SUCCESS; |
9637 | 0 | } |
9638 | | |
9639 | | DEFUN (no_ip_ospf_mtu_ignore, |
9640 | | no_ip_ospf_mtu_ignore_addr_cmd, |
9641 | | "no ip ospf mtu-ignore [A.B.C.D]", |
9642 | | NO_STR |
9643 | | "IP Information\n" |
9644 | | "OSPF interface commands\n" |
9645 | | "Disable MTU mismatch detection on this interface\n" |
9646 | | "Address of interface\n") |
9647 | 0 | { |
9648 | 0 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9649 | 0 | int idx_ipv4 = 4; |
9650 | 0 | struct in_addr addr; |
9651 | 0 | int ret; |
9652 | |
|
9653 | 0 | struct ospf_if_params *params; |
9654 | 0 | params = IF_DEF_PARAMS(ifp); |
9655 | |
|
9656 | 0 | if (argc == 5) { |
9657 | 0 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); |
9658 | 0 | if (!ret) { |
9659 | 0 | vty_out(vty, |
9660 | 0 | "Please specify interface address by A.B.C.D\n"); |
9661 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9662 | 0 | } |
9663 | 0 | params = ospf_get_if_params(ifp, addr); |
9664 | 0 | ospf_if_update_params(ifp, addr); |
9665 | 0 | } |
9666 | 0 | params->mtu_ignore = 0; |
9667 | 0 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) |
9668 | 0 | SET_IF_PARAM(params, mtu_ignore); |
9669 | 0 | else { |
9670 | 0 | UNSET_IF_PARAM(params, mtu_ignore); |
9671 | 0 | if (params != IF_DEF_PARAMS(ifp)) { |
9672 | 0 | ospf_free_if_params(ifp, addr); |
9673 | 0 | ospf_if_update_params(ifp, addr); |
9674 | 0 | } |
9675 | 0 | } |
9676 | 0 | return CMD_SUCCESS; |
9677 | 0 | } |
9678 | | |
9679 | | |
9680 | | DEFUN (ospf_max_metric_router_lsa_admin, |
9681 | | ospf_max_metric_router_lsa_admin_cmd, |
9682 | | "max-metric router-lsa administrative", |
9683 | | "OSPF maximum / infinite-distance metric\n" |
9684 | | "Advertise own Router-LSA with infinite distance (stub router)\n" |
9685 | | "Administratively applied, for an indefinite period\n") |
9686 | 0 | { |
9687 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9688 | 0 | struct listnode *ln; |
9689 | 0 | struct ospf_area *area; |
9690 | |
|
9691 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9692 | 0 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); |
9693 | |
|
9694 | 0 | if (!CHECK_FLAG(area->stub_router_state, |
9695 | 0 | OSPF_AREA_IS_STUB_ROUTED)) |
9696 | 0 | ospf_router_lsa_update_area(area); |
9697 | 0 | } |
9698 | | |
9699 | | /* Allows for areas configured later to get the property */ |
9700 | 0 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; |
9701 | |
|
9702 | 0 | return CMD_SUCCESS; |
9703 | 0 | } |
9704 | | |
9705 | | DEFUN (no_ospf_max_metric_router_lsa_admin, |
9706 | | no_ospf_max_metric_router_lsa_admin_cmd, |
9707 | | "no max-metric router-lsa administrative", |
9708 | | NO_STR |
9709 | | "OSPF maximum / infinite-distance metric\n" |
9710 | | "Advertise own Router-LSA with infinite distance (stub router)\n" |
9711 | | "Administratively applied, for an indefinite period\n") |
9712 | 0 | { |
9713 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9714 | 0 | struct listnode *ln; |
9715 | 0 | struct ospf_area *area; |
9716 | |
|
9717 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9718 | 0 | UNSET_FLAG(area->stub_router_state, |
9719 | 0 | OSPF_AREA_ADMIN_STUB_ROUTED); |
9720 | | |
9721 | | /* Don't trample on the start-up stub timer */ |
9722 | 0 | if (CHECK_FLAG(area->stub_router_state, |
9723 | 0 | OSPF_AREA_IS_STUB_ROUTED) |
9724 | 0 | && !area->t_stub_router) { |
9725 | 0 | UNSET_FLAG(area->stub_router_state, |
9726 | 0 | OSPF_AREA_IS_STUB_ROUTED); |
9727 | 0 | ospf_router_lsa_update_area(area); |
9728 | 0 | } |
9729 | 0 | } |
9730 | 0 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; |
9731 | 0 | return CMD_SUCCESS; |
9732 | 0 | } |
9733 | | |
9734 | | DEFUN (ospf_max_metric_router_lsa_startup, |
9735 | | ospf_max_metric_router_lsa_startup_cmd, |
9736 | | "max-metric router-lsa on-startup (5-86400)", |
9737 | | "OSPF maximum / infinite-distance metric\n" |
9738 | | "Advertise own Router-LSA with infinite distance (stub router)\n" |
9739 | | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
9740 | | "Time (seconds) to advertise self as stub-router\n") |
9741 | 0 | { |
9742 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9743 | 0 | int idx_number = 3; |
9744 | 0 | unsigned int seconds; |
9745 | |
|
9746 | 0 | if (argc < 4) { |
9747 | 0 | vty_out(vty, "%% Must supply stub-router period\n"); |
9748 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9749 | 0 | } |
9750 | | |
9751 | 0 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); |
9752 | |
|
9753 | 0 | ospf->stub_router_startup_time = seconds; |
9754 | |
|
9755 | 0 | return CMD_SUCCESS; |
9756 | 0 | } |
9757 | | |
9758 | | DEFUN (no_ospf_max_metric_router_lsa_startup, |
9759 | | no_ospf_max_metric_router_lsa_startup_cmd, |
9760 | | "no max-metric router-lsa on-startup [(5-86400)]", |
9761 | | NO_STR |
9762 | | "OSPF maximum / infinite-distance metric\n" |
9763 | | "Advertise own Router-LSA with infinite distance (stub router)\n" |
9764 | | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
9765 | | "Time (seconds) to advertise self as stub-router\n") |
9766 | 0 | { |
9767 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9768 | 0 | struct listnode *ln; |
9769 | 0 | struct ospf_area *area; |
9770 | |
|
9771 | 0 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
9772 | |
|
9773 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9774 | 0 | SET_FLAG(area->stub_router_state, |
9775 | 0 | OSPF_AREA_WAS_START_STUB_ROUTED); |
9776 | 0 | EVENT_OFF(area->t_stub_router); |
9777 | | |
9778 | | /* Don't trample on admin stub routed */ |
9779 | 0 | if (!CHECK_FLAG(area->stub_router_state, |
9780 | 0 | OSPF_AREA_ADMIN_STUB_ROUTED)) { |
9781 | 0 | UNSET_FLAG(area->stub_router_state, |
9782 | 0 | OSPF_AREA_IS_STUB_ROUTED); |
9783 | 0 | ospf_router_lsa_update_area(area); |
9784 | 0 | } |
9785 | 0 | } |
9786 | 0 | return CMD_SUCCESS; |
9787 | 0 | } |
9788 | | |
9789 | | |
9790 | | DEFUN (ospf_max_metric_router_lsa_shutdown, |
9791 | | ospf_max_metric_router_lsa_shutdown_cmd, |
9792 | | "max-metric router-lsa on-shutdown (5-100)", |
9793 | | "OSPF maximum / infinite-distance metric\n" |
9794 | | "Advertise own Router-LSA with infinite distance (stub router)\n" |
9795 | | "Advertise stub-router prior to full shutdown of OSPF\n" |
9796 | | "Time (seconds) to wait till full shutdown\n") |
9797 | 0 | { |
9798 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9799 | 0 | int idx_number = 3; |
9800 | 0 | unsigned int seconds; |
9801 | |
|
9802 | 0 | if (argc < 4) { |
9803 | 0 | vty_out(vty, "%% Must supply stub-router shutdown period\n"); |
9804 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9805 | 0 | } |
9806 | | |
9807 | 0 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); |
9808 | |
|
9809 | 0 | ospf->stub_router_shutdown_time = seconds; |
9810 | |
|
9811 | 0 | return CMD_SUCCESS; |
9812 | 0 | } |
9813 | | |
9814 | | DEFUN (no_ospf_max_metric_router_lsa_shutdown, |
9815 | | no_ospf_max_metric_router_lsa_shutdown_cmd, |
9816 | | "no max-metric router-lsa on-shutdown [(5-100)]", |
9817 | | NO_STR |
9818 | | "OSPF maximum / infinite-distance metric\n" |
9819 | | "Advertise own Router-LSA with infinite distance (stub router)\n" |
9820 | | "Advertise stub-router prior to full shutdown of OSPF\n" |
9821 | | "Time (seconds) to wait till full shutdown\n") |
9822 | 0 | { |
9823 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9824 | |
|
9825 | 0 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
9826 | |
|
9827 | 0 | return CMD_SUCCESS; |
9828 | 0 | } |
9829 | | |
9830 | | DEFUN (ospf_proactive_arp, |
9831 | | ospf_proactive_arp_cmd, |
9832 | | "proactive-arp", |
9833 | | "Allow sending ARP requests proactively\n") |
9834 | 0 | { |
9835 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9836 | |
|
9837 | 0 | ospf->proactive_arp = true; |
9838 | |
|
9839 | 0 | return CMD_SUCCESS; |
9840 | 0 | } |
9841 | | |
9842 | | DEFUN (no_ospf_proactive_arp, |
9843 | | no_ospf_proactive_arp_cmd, |
9844 | | "no proactive-arp", |
9845 | | NO_STR |
9846 | | "Disallow sending ARP requests proactively\n") |
9847 | 0 | { |
9848 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9849 | |
|
9850 | 0 | ospf->proactive_arp = false; |
9851 | |
|
9852 | 0 | return CMD_SUCCESS; |
9853 | 0 | } |
9854 | | |
9855 | | /* Graceful Restart HELPER Commands */ |
9856 | | DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd, |
9857 | | "graceful-restart helper enable [A.B.C.D$address]", |
9858 | | "OSPF Graceful Restart\n" |
9859 | | "OSPF GR Helper\n" |
9860 | | "Enable Helper support\n" |
9861 | | "Advertising Router-ID\n") |
9862 | 0 | { |
9863 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9864 | |
|
9865 | 0 | if (address_str) { |
9866 | 0 | ospf_gr_helper_support_set_per_routerid(ospf, &address, |
9867 | 0 | OSPF_GR_TRUE); |
9868 | 0 | return CMD_SUCCESS; |
9869 | 0 | } |
9870 | | |
9871 | 0 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); |
9872 | |
|
9873 | 0 | return CMD_SUCCESS; |
9874 | 0 | } |
9875 | | |
9876 | | DEFPY(no_ospf_gr_helper_enable, |
9877 | | no_ospf_gr_helper_enable_cmd, |
9878 | | "no graceful-restart helper enable [A.B.C.D$address]", |
9879 | | NO_STR |
9880 | | "OSPF Graceful Restart\n" |
9881 | | "OSPF GR Helper\n" |
9882 | | "Enable Helper support\n" |
9883 | | "Advertising Router-ID\n") |
9884 | 0 | { |
9885 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9886 | |
|
9887 | 0 | if (address_str) { |
9888 | 0 | ospf_gr_helper_support_set_per_routerid(ospf, &address, |
9889 | 0 | OSPF_GR_FALSE); |
9890 | 0 | return CMD_SUCCESS; |
9891 | 0 | } |
9892 | | |
9893 | 0 | ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE); |
9894 | 0 | return CMD_SUCCESS; |
9895 | 0 | } |
9896 | | |
9897 | | DEFPY(ospf_gr_helper_enable_lsacheck, |
9898 | | ospf_gr_helper_enable_lsacheck_cmd, |
9899 | | "graceful-restart helper strict-lsa-checking", |
9900 | | "OSPF Graceful Restart\n" |
9901 | | "OSPF GR Helper\n" |
9902 | | "Enable strict LSA check\n") |
9903 | 0 | { |
9904 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9905 | |
|
9906 | 0 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE); |
9907 | 0 | return CMD_SUCCESS; |
9908 | 0 | } |
9909 | | |
9910 | | DEFPY(no_ospf_gr_helper_enable_lsacheck, |
9911 | | no_ospf_gr_helper_enable_lsacheck_cmd, |
9912 | | "no graceful-restart helper strict-lsa-checking", |
9913 | | NO_STR |
9914 | | "OSPF Graceful Restart\n" |
9915 | | "OSPF GR Helper\n" |
9916 | | "Disable strict LSA check\n") |
9917 | 0 | { |
9918 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9919 | |
|
9920 | 0 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE); |
9921 | 0 | return CMD_SUCCESS; |
9922 | 0 | } |
9923 | | |
9924 | | DEFPY(ospf_gr_helper_supported_grace_time, |
9925 | | ospf_gr_helper_supported_grace_time_cmd, |
9926 | | "graceful-restart helper supported-grace-time (10-1800)$interval", |
9927 | | "OSPF Graceful Restart\n" |
9928 | | "OSPF GR Helper\n" |
9929 | | "Supported grace timer\n" |
9930 | | "Grace interval(in seconds)\n") |
9931 | 0 | { |
9932 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9933 | |
|
9934 | 0 | ospf_gr_helper_supported_gracetime_set(ospf, interval); |
9935 | 0 | return CMD_SUCCESS; |
9936 | 0 | } |
9937 | | |
9938 | | DEFPY(no_ospf_gr_helper_supported_grace_time, |
9939 | | no_ospf_gr_helper_supported_grace_time_cmd, |
9940 | | "no graceful-restart helper supported-grace-time (10-1800)$interval", |
9941 | | NO_STR |
9942 | | "OSPF Graceful Restart\n" |
9943 | | "OSPF GR Helper\n" |
9944 | | "Supported grace timer\n" |
9945 | | "Grace interval(in seconds)\n") |
9946 | 0 | { |
9947 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9948 | |
|
9949 | 0 | ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL); |
9950 | 0 | return CMD_SUCCESS; |
9951 | 0 | } |
9952 | | |
9953 | | DEFPY(ospf_gr_helper_planned_only, |
9954 | | ospf_gr_helper_planned_only_cmd, |
9955 | | "graceful-restart helper planned-only", |
9956 | | "OSPF Graceful Restart\n" |
9957 | | "OSPF GR Helper\n" |
9958 | | "Supported only planned restart\n") |
9959 | 0 | { |
9960 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9961 | |
|
9962 | 0 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE); |
9963 | |
|
9964 | 0 | return CMD_SUCCESS; |
9965 | 0 | } |
9966 | | |
9967 | | /* External Route Aggregation */ |
9968 | | DEFUN (ospf_external_route_aggregation, |
9969 | | ospf_external_route_aggregation_cmd, |
9970 | | "summary-address A.B.C.D/M [tag (1-4294967295)]", |
9971 | | "External summary address\n" |
9972 | | "Summary address prefix\n" |
9973 | | "Router tag \n" |
9974 | | "Router tag value\n") |
9975 | 0 | { |
9976 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
9977 | 0 | struct prefix_ipv4 p; |
9978 | 0 | int idx = 1; |
9979 | 0 | route_tag_t tag = 0; |
9980 | 0 | int ret = OSPF_SUCCESS; |
9981 | |
|
9982 | 0 | str2prefix_ipv4(argv[idx]->arg, &p); |
9983 | |
|
9984 | 0 | if (is_default_prefix4(&p)) { |
9985 | 0 | vty_out(vty, |
9986 | 0 | "Default address shouldn't be configured as summary address.\n"); |
9987 | 0 | return CMD_SUCCESS; |
9988 | 0 | } |
9989 | | |
9990 | | /* Apply mask for given prefix. */ |
9991 | 0 | apply_mask(&p); |
9992 | |
|
9993 | 0 | if (!is_valid_summary_addr(&p)) { |
9994 | 0 | vty_out(vty, "Not a valid summary address.\n"); |
9995 | 0 | return CMD_WARNING_CONFIG_FAILED; |
9996 | 0 | } |
9997 | | |
9998 | 0 | if (argc > 2) |
9999 | 0 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); |
10000 | |
|
10001 | 0 | ret = ospf_asbr_external_aggregator_set(ospf, &p, tag); |
10002 | 0 | if (ret == OSPF_INVALID) |
10003 | 0 | vty_out(vty, "Invalid configuration!!\n"); |
10004 | |
|
10005 | 0 | return CMD_SUCCESS; |
10006 | 0 | } |
10007 | | |
10008 | | DEFUN (no_ospf_external_route_aggregation, |
10009 | | no_ospf_external_route_aggregation_cmd, |
10010 | | "no summary-address A.B.C.D/M [tag (1-4294967295)]", |
10011 | | NO_STR |
10012 | | "External summary address\n" |
10013 | | "Summary address prefix\n" |
10014 | | "Router tag\n" |
10015 | | "Router tag value\n") |
10016 | 0 | { |
10017 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
10018 | 0 | struct prefix_ipv4 p; |
10019 | 0 | int idx = 2; |
10020 | 0 | route_tag_t tag = 0; |
10021 | 0 | int ret = OSPF_SUCCESS; |
10022 | |
|
10023 | 0 | str2prefix_ipv4(argv[idx]->arg, &p); |
10024 | |
|
10025 | 0 | if (is_default_prefix4(&p)) { |
10026 | 0 | vty_out(vty, |
10027 | 0 | "Default address shouldn't be configured as summary address.\n"); |
10028 | 0 | return CMD_SUCCESS; |
10029 | 0 | } |
10030 | | |
10031 | | /* Apply mask for given prefix. */ |
10032 | 0 | apply_mask(&p); |
10033 | |
|
10034 | 0 | if (!is_valid_summary_addr(&p)) { |
10035 | 0 | vty_out(vty, "Not a valid summary address.\n"); |
10036 | 0 | return CMD_WARNING_CONFIG_FAILED; |
10037 | 0 | } |
10038 | | |
10039 | 0 | if (argc > 3) |
10040 | 0 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); |
10041 | |
|
10042 | 0 | ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag); |
10043 | 0 | if (ret == OSPF_INVALID) |
10044 | 0 | vty_out(vty, "Invalid configuration!!\n"); |
10045 | |
|
10046 | 0 | return CMD_SUCCESS; |
10047 | 0 | } |
10048 | | |
10049 | | DEFPY(no_ospf_gr_helper_planned_only, |
10050 | | no_ospf_gr_helper_planned_only_cmd, |
10051 | | "no graceful-restart helper planned-only", |
10052 | | NO_STR |
10053 | | "OSPF Graceful Restart\n" |
10054 | | "OSPF GR Helper\n" |
10055 | | "Supported only for planned restart\n") |
10056 | 0 | { |
10057 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
10058 | |
|
10059 | 0 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE); |
10060 | |
|
10061 | 0 | return CMD_SUCCESS; |
10062 | 0 | } |
10063 | | |
10064 | | static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
10065 | | void *arg) |
10066 | 0 | { |
10067 | 0 | struct advRtr *rtr = bucket->data; |
10068 | 0 | struct vty *vty = (struct vty *)arg; |
10069 | 0 | static unsigned int count; |
10070 | |
|
10071 | 0 | vty_out(vty, "%-6pI4,", &rtr->advRtrAddr); |
10072 | 0 | count++; |
10073 | |
|
10074 | 0 | if (count % 5 == 0) |
10075 | 0 | vty_out(vty, "\n"); |
10076 | |
|
10077 | 0 | return HASHWALK_CONTINUE; |
10078 | 0 | } |
10079 | | |
10080 | | static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket *bucket, |
10081 | | void *arg) |
10082 | 0 | { |
10083 | 0 | struct advRtr *rtr = bucket->data; |
10084 | 0 | struct json_object *json_rid_array = arg; |
10085 | 0 | struct json_object *json_rid; |
10086 | |
|
10087 | 0 | json_rid = json_object_new_object(); |
10088 | |
|
10089 | 0 | json_object_string_addf(json_rid, "routerId", "%pI4", &rtr->advRtrAddr); |
10090 | 0 | json_object_array_add(json_rid_array, json_rid); |
10091 | |
|
10092 | 0 | return HASHWALK_CONTINUE; |
10093 | 0 | } |
10094 | | |
10095 | | static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf, |
10096 | | uint8_t use_vrf, json_object *json, |
10097 | | bool uj, bool detail) |
10098 | 0 | { |
10099 | 0 | struct listnode *node; |
10100 | 0 | struct ospf_interface *oi; |
10101 | 0 | char buf[PREFIX_STRLEN]; |
10102 | 0 | json_object *json_vrf = NULL; |
10103 | |
|
10104 | 0 | if (uj) { |
10105 | 0 | if (use_vrf) |
10106 | 0 | json_vrf = json_object_new_object(); |
10107 | 0 | else |
10108 | 0 | json_vrf = json; |
10109 | 0 | } |
10110 | |
|
10111 | 0 | if (ospf->instance) { |
10112 | 0 | if (uj) |
10113 | 0 | json_object_int_add(json, "ospfInstance", |
10114 | 0 | ospf->instance); |
10115 | 0 | else |
10116 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
10117 | 0 | } |
10118 | |
|
10119 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
10120 | |
|
10121 | 0 | if (uj) { |
10122 | 0 | if (use_vrf) |
10123 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
10124 | 0 | json_vrf); |
10125 | 0 | } else |
10126 | 0 | vty_out(vty, "\n"); |
10127 | | |
10128 | | /* Show Router ID. */ |
10129 | 0 | if (uj) { |
10130 | 0 | json_object_string_add(json_vrf, "routerId", |
10131 | 0 | inet_ntop(AF_INET, &ospf->router_id, |
10132 | 0 | buf, sizeof(buf))); |
10133 | 0 | } else { |
10134 | 0 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", |
10135 | 0 | &ospf->router_id); |
10136 | 0 | } |
10137 | |
|
10138 | 0 | if (!uj) { |
10139 | |
|
10140 | 0 | if (ospf->is_helper_supported) |
10141 | 0 | vty_out(vty, |
10142 | 0 | " Graceful restart helper support enabled.\n"); |
10143 | 0 | else |
10144 | 0 | vty_out(vty, |
10145 | 0 | " Graceful restart helper support disabled.\n"); |
10146 | |
|
10147 | 0 | if (ospf->strict_lsa_check) |
10148 | 0 | vty_out(vty, " Strict LSA check is enabled.\n"); |
10149 | 0 | else |
10150 | 0 | vty_out(vty, " Strict LSA check is disabled.\n"); |
10151 | |
|
10152 | 0 | if (ospf->only_planned_restart) |
10153 | 0 | vty_out(vty, |
10154 | 0 | " Helper supported for planned restarts only.\n"); |
10155 | 0 | else |
10156 | 0 | vty_out(vty, |
10157 | 0 | " Helper supported for Planned and Unplanned Restarts.\n"); |
10158 | |
|
10159 | 0 | vty_out(vty, |
10160 | 0 | " Supported Graceful restart interval: %d(in seconds).\n", |
10161 | 0 | ospf->supported_grace_time); |
10162 | |
|
10163 | 0 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { |
10164 | 0 | vty_out(vty, " Enable Router list:\n"); |
10165 | 0 | vty_out(vty, " "); |
10166 | 0 | hash_walk(ospf->enable_rtr_list, |
10167 | 0 | ospf_print_vty_helper_dis_rtr_walkcb, vty); |
10168 | 0 | vty_out(vty, "\n\n"); |
10169 | 0 | } |
10170 | |
|
10171 | 0 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) { |
10172 | 0 | vty_out(vty, " Last Helper exit Reason :%s\n", |
10173 | 0 | ospf_exit_reason2str(ospf->last_exit_reason)); |
10174 | 0 | } |
10175 | |
|
10176 | 0 | if (ospf->active_restarter_cnt) |
10177 | 0 | vty_out(vty, |
10178 | 0 | " Number of Active neighbours in graceful restart: %d\n", |
10179 | 0 | ospf->active_restarter_cnt); |
10180 | 0 | else |
10181 | 0 | vty_out(vty, "\n"); |
10182 | |
|
10183 | 0 | } else { |
10184 | 0 | json_object_string_add( |
10185 | 0 | json_vrf, "helperSupport", |
10186 | 0 | (ospf->is_helper_supported) ? "Enabled" : "Disabled"); |
10187 | 0 | json_object_string_add(json_vrf, "strictLsaCheck", |
10188 | 0 | (ospf->strict_lsa_check) ? "Enabled" |
10189 | 0 | : "Disabled"); |
10190 | | #if CONFDATE > 20240401 |
10191 | | CPP_NOTICE("Remove deprecated json key: restartSupoort") |
10192 | | #endif |
10193 | 0 | json_object_string_add( |
10194 | 0 | json_vrf, "restartSupoort", |
10195 | 0 | (ospf->only_planned_restart) |
10196 | 0 | ? "Planned Restart only" |
10197 | 0 | : "Planned and Unplanned Restarts"); |
10198 | |
|
10199 | 0 | json_object_string_add( |
10200 | 0 | json_vrf, "restartSupport", |
10201 | 0 | (ospf->only_planned_restart) |
10202 | 0 | ? "Planned Restart only" |
10203 | 0 | : "Planned and Unplanned Restarts"); |
10204 | |
|
10205 | 0 | json_object_int_add(json_vrf, "supportedGracePeriod", |
10206 | 0 | ospf->supported_grace_time); |
10207 | |
|
10208 | 0 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) |
10209 | 0 | json_object_string_add( |
10210 | 0 | json_vrf, "lastExitReason", |
10211 | 0 | ospf_exit_reason2str(ospf->last_exit_reason)); |
10212 | |
|
10213 | 0 | if (ospf->active_restarter_cnt) |
10214 | 0 | json_object_int_add(json_vrf, "activeRestarterCnt", |
10215 | 0 | ospf->active_restarter_cnt); |
10216 | |
|
10217 | 0 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { |
10218 | 0 | struct json_object *json_rid_array = |
10219 | 0 | json_object_new_array(); |
10220 | |
|
10221 | 0 | json_object_object_add(json_vrf, "enabledRouterIds", |
10222 | 0 | json_rid_array); |
10223 | |
|
10224 | 0 | hash_walk(ospf->enable_rtr_list, |
10225 | 0 | ospf_print_json_helper_enabled_rtr_walkcb, |
10226 | 0 | json_rid_array); |
10227 | 0 | } |
10228 | 0 | } |
10229 | | |
10230 | |
|
10231 | 0 | if (detail) { |
10232 | 0 | int cnt = 1; |
10233 | 0 | json_object *json_neighbors = NULL; |
10234 | |
|
10235 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
10236 | 0 | struct route_node *rn; |
10237 | 0 | struct ospf_neighbor *nbr; |
10238 | 0 | json_object *json_neigh; |
10239 | |
|
10240 | 0 | if (ospf_interface_neighbor_count(oi) == 0) |
10241 | 0 | continue; |
10242 | | |
10243 | 0 | if (uj) { |
10244 | 0 | json_object_object_get_ex(json_vrf, "neighbors", |
10245 | 0 | &json_neighbors); |
10246 | 0 | if (!json_neighbors) { |
10247 | 0 | json_neighbors = |
10248 | 0 | json_object_new_object(); |
10249 | 0 | json_object_object_add(json_vrf, |
10250 | 0 | "neighbors", |
10251 | 0 | json_neighbors); |
10252 | 0 | } |
10253 | 0 | } |
10254 | |
|
10255 | 0 | for (rn = route_top(oi->nbrs); rn; |
10256 | 0 | rn = route_next(rn)) { |
10257 | |
|
10258 | 0 | if (!rn->info) |
10259 | 0 | continue; |
10260 | | |
10261 | 0 | nbr = rn->info; |
10262 | |
|
10263 | 0 | if (!OSPF_GR_IS_ACTIVE_HELPER(nbr)) |
10264 | 0 | continue; |
10265 | | |
10266 | 0 | if (!uj) { |
10267 | 0 | vty_out(vty, " Neighbour %d :\n", cnt); |
10268 | 0 | vty_out(vty, " Address : %pI4\n", |
10269 | 0 | &nbr->address.u.prefix4); |
10270 | 0 | vty_out(vty, " Routerid : %pI4\n", |
10271 | 0 | &nbr->router_id); |
10272 | 0 | vty_out(vty, |
10273 | 0 | " Received Grace period : %d(in seconds).\n", |
10274 | 0 | nbr->gr_helper_info |
10275 | 0 | .recvd_grace_period); |
10276 | 0 | vty_out(vty, |
10277 | 0 | " Actual Grace period : %d(in seconds)\n", |
10278 | 0 | nbr->gr_helper_info |
10279 | 0 | .actual_grace_period); |
10280 | 0 | vty_out(vty, |
10281 | 0 | " Remaining GraceTime:%ld(in seconds).\n", |
10282 | 0 | event_timer_remain_second( |
10283 | 0 | nbr->gr_helper_info |
10284 | 0 | .t_grace_timer)); |
10285 | 0 | vty_out(vty, |
10286 | 0 | " Graceful Restart reason: %s.\n\n", |
10287 | 0 | ospf_restart_reason2str( |
10288 | 0 | nbr->gr_helper_info |
10289 | 0 | .gr_restart_reason)); |
10290 | 0 | cnt++; |
10291 | 0 | } else { |
10292 | 0 | json_neigh = json_object_new_object(); |
10293 | 0 | json_object_string_add( |
10294 | 0 | json_neigh, "srcAddr", |
10295 | 0 | inet_ntop(AF_INET, &nbr->src, |
10296 | 0 | buf, sizeof(buf))); |
10297 | |
|
10298 | 0 | json_object_string_add( |
10299 | 0 | json_neigh, "routerid", |
10300 | 0 | inet_ntop(AF_INET, |
10301 | 0 | &nbr->router_id, |
10302 | 0 | buf, sizeof(buf))); |
10303 | 0 | json_object_int_add( |
10304 | 0 | json_neigh, |
10305 | 0 | "recvdGraceInterval", |
10306 | 0 | nbr->gr_helper_info |
10307 | 0 | .recvd_grace_period); |
10308 | 0 | json_object_int_add( |
10309 | 0 | json_neigh, |
10310 | 0 | "actualGraceInterval", |
10311 | 0 | nbr->gr_helper_info |
10312 | 0 | .actual_grace_period); |
10313 | 0 | json_object_int_add( |
10314 | 0 | json_neigh, "remainGracetime", |
10315 | 0 | event_timer_remain_second( |
10316 | 0 | nbr->gr_helper_info |
10317 | 0 | .t_grace_timer)); |
10318 | 0 | json_object_string_add( |
10319 | 0 | json_neigh, "restartReason", |
10320 | 0 | ospf_restart_reason2str( |
10321 | 0 | nbr->gr_helper_info |
10322 | 0 | .gr_restart_reason)); |
10323 | 0 | json_object_object_add( |
10324 | 0 | json_neighbors, |
10325 | 0 | inet_ntop(AF_INET, &nbr->src, |
10326 | 0 | buf, sizeof(buf)), |
10327 | 0 | json_neigh); |
10328 | 0 | } |
10329 | 0 | } |
10330 | 0 | } |
10331 | 0 | } |
10332 | 0 | return CMD_SUCCESS; |
10333 | 0 | } |
10334 | | |
10335 | | DEFUN (ospf_external_route_aggregation_no_adrvertise, |
10336 | | ospf_external_route_aggregation_no_adrvertise_cmd, |
10337 | | "summary-address A.B.C.D/M no-advertise", |
10338 | | "External summary address\n" |
10339 | | "Summary address prefix\n" |
10340 | | "Don't advertise summary route \n") |
10341 | 0 | { |
10342 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
10343 | 0 | struct prefix_ipv4 p; |
10344 | 0 | int idx = 1; |
10345 | 0 | int ret = OSPF_SUCCESS; |
10346 | |
|
10347 | 0 | str2prefix_ipv4(argv[idx]->arg, &p); |
10348 | |
|
10349 | 0 | if (is_default_prefix4(&p)) { |
10350 | 0 | vty_out(vty, |
10351 | 0 | "Default address shouldn't be configured as summary address.\n"); |
10352 | 0 | return CMD_SUCCESS; |
10353 | 0 | } |
10354 | | |
10355 | | /* Apply mask for given prefix. */ |
10356 | 0 | apply_mask(&p); |
10357 | |
|
10358 | 0 | if (!is_valid_summary_addr(&p)) { |
10359 | 0 | vty_out(vty, "Not a valid summary address.\n"); |
10360 | 0 | return CMD_WARNING_CONFIG_FAILED; |
10361 | 0 | } |
10362 | | |
10363 | 0 | ret = ospf_asbr_external_rt_no_advertise(ospf, &p); |
10364 | 0 | if (ret == OSPF_INVALID) |
10365 | 0 | vty_out(vty, "Invalid configuration!!\n"); |
10366 | |
|
10367 | 0 | return CMD_SUCCESS; |
10368 | 0 | } |
10369 | | |
10370 | | DEFUN (no_ospf_external_route_aggregation_no_adrvertise, |
10371 | | no_ospf_external_route_aggregation_no_adrvertise_cmd, |
10372 | | "no summary-address A.B.C.D/M no-advertise", |
10373 | | NO_STR |
10374 | | "External summary address\n" |
10375 | | "Summary address prefix\n" |
10376 | | "Advertise summary route to the AS \n") |
10377 | 0 | { |
10378 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
10379 | 0 | struct prefix_ipv4 p; |
10380 | 0 | int idx = 2; |
10381 | 0 | int ret = OSPF_SUCCESS; |
10382 | |
|
10383 | 0 | str2prefix_ipv4(argv[idx]->arg, &p); |
10384 | |
|
10385 | 0 | if (is_default_prefix4(&p)) { |
10386 | 0 | vty_out(vty, |
10387 | 0 | "Default address shouldn't be configured as summary address.\n"); |
10388 | 0 | return CMD_SUCCESS; |
10389 | 0 | } |
10390 | | |
10391 | | /* Apply mask for given prefix. */ |
10392 | 0 | apply_mask(&p); |
10393 | |
|
10394 | 0 | if (!is_valid_summary_addr(&p)) { |
10395 | 0 | vty_out(vty, "Not a valid summary address.\n"); |
10396 | 0 | return CMD_WARNING_CONFIG_FAILED; |
10397 | 0 | } |
10398 | | |
10399 | 0 | ret = ospf_asbr_external_rt_advertise(ospf, &p); |
10400 | 0 | if (ret == OSPF_INVALID) |
10401 | 0 | vty_out(vty, "Invalid configuration!!\n"); |
10402 | |
|
10403 | 0 | return CMD_SUCCESS; |
10404 | 0 | } |
10405 | | |
10406 | | DEFUN (ospf_route_aggregation_timer, |
10407 | | ospf_route_aggregation_timer_cmd, |
10408 | | "aggregation timer (5-1800)", |
10409 | | "External route aggregation\n" |
10410 | | "Delay timer (in seconds)\n" |
10411 | | "Timer interval(in seconds)\n") |
10412 | 0 | { |
10413 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
10414 | 0 | uint16_t interval = 0; |
10415 | |
|
10416 | 0 | interval = strtoul(argv[2]->arg, NULL, 10); |
10417 | |
|
10418 | 0 | ospf_external_aggregator_timer_set(ospf, interval); |
10419 | |
|
10420 | 0 | return CMD_SUCCESS; |
10421 | 0 | } |
10422 | | |
10423 | | DEFPY (show_ip_ospf_gr_helper, |
10424 | | show_ip_ospf_gr_helper_cmd, |
10425 | | "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]", |
10426 | | SHOW_STR |
10427 | | IP_STR |
10428 | | "OSPF information\n" |
10429 | | VRF_CMD_HELP_STR |
10430 | | "All VRFs\n" |
10431 | | "OSPF Graceful Restart\n" |
10432 | | "Helper details in the router\n" |
10433 | | "Detailed information\n" |
10434 | | JSON_STR) |
10435 | 0 | { |
10436 | 0 | char *vrf_name = NULL; |
10437 | 0 | bool all_vrf = false; |
10438 | 0 | int ret = CMD_SUCCESS; |
10439 | 0 | int idx_vrf = 0; |
10440 | 0 | int idx = 0; |
10441 | 0 | uint8_t use_vrf = 0; |
10442 | 0 | bool uj = use_json(argc, argv); |
10443 | 0 | struct ospf *ospf = NULL; |
10444 | 0 | json_object *json = NULL; |
10445 | 0 | struct listnode *node = NULL; |
10446 | 0 | int inst = 0; |
10447 | 0 | bool detail = false; |
10448 | |
|
10449 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
10450 | |
|
10451 | 0 | if (argv_find(argv, argc, "detail", &idx)) |
10452 | 0 | detail = true; |
10453 | |
|
10454 | 0 | if (uj) |
10455 | 0 | json = json_object_new_object(); |
10456 | | |
10457 | | /* vrf input is provided */ |
10458 | 0 | if (vrf_name) { |
10459 | 0 | use_vrf = 1; |
10460 | |
|
10461 | 0 | if (all_vrf) { |
10462 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
10463 | 0 | if (!ospf->oi_running) |
10464 | 0 | continue; |
10465 | | |
10466 | 0 | ret = ospf_show_gr_helper_details( |
10467 | 0 | vty, ospf, use_vrf, json, uj, detail); |
10468 | 0 | } |
10469 | |
|
10470 | 0 | if (uj) |
10471 | 0 | vty_json(vty, json); |
10472 | |
|
10473 | 0 | return ret; |
10474 | 0 | } |
10475 | | |
10476 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
10477 | |
|
10478 | 0 | if (ospf == NULL || !ospf->oi_running) { |
10479 | |
|
10480 | 0 | if (uj) |
10481 | 0 | vty_json(vty, json); |
10482 | 0 | else |
10483 | 0 | vty_out(vty, |
10484 | 0 | "%% OSPF is not enabled in vrf %s\n", |
10485 | 0 | vrf_name); |
10486 | |
|
10487 | 0 | return CMD_SUCCESS; |
10488 | 0 | } |
10489 | |
|
10490 | 0 | } else { |
10491 | | /* Default Vrf */ |
10492 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
10493 | |
|
10494 | 0 | if (ospf == NULL || !ospf->oi_running) { |
10495 | |
|
10496 | 0 | if (uj) |
10497 | 0 | vty_json(vty, json); |
10498 | 0 | else |
10499 | 0 | vty_out(vty, |
10500 | 0 | "%% OSPF is not enabled in vrf default\n"); |
10501 | |
|
10502 | 0 | return CMD_SUCCESS; |
10503 | 0 | } |
10504 | | |
10505 | 0 | ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, |
10506 | 0 | detail); |
10507 | 0 | } |
10508 | | |
10509 | 0 | if (uj) |
10510 | 0 | vty_json(vty, json); |
10511 | |
|
10512 | 0 | return CMD_SUCCESS; |
10513 | 0 | } |
10514 | | /* Graceful Restart HELPER commands end */ |
10515 | | DEFUN (no_ospf_route_aggregation_timer, |
10516 | | no_ospf_route_aggregation_timer_cmd, |
10517 | | "no aggregation timer", |
10518 | | NO_STR |
10519 | | "External route aggregation\n" |
10520 | | "Delay timer\n") |
10521 | 0 | { |
10522 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
10523 | |
|
10524 | 0 | ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY); |
10525 | |
|
10526 | 0 | return CMD_SUCCESS; |
10527 | 0 | } |
10528 | | |
10529 | | /* External Route Aggregation End */ |
10530 | | |
10531 | | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
10532 | 0 | { |
10533 | 0 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) |
10534 | 0 | vty_out(vty, " max-metric router-lsa on-startup %u\n", |
10535 | 0 | ospf->stub_router_startup_time); |
10536 | 0 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) |
10537 | 0 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", |
10538 | 0 | ospf->stub_router_shutdown_time); |
10539 | 0 | if (ospf->stub_router_admin_set == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET) |
10540 | 0 | vty_out(vty, " max-metric router-lsa administrative\n"); |
10541 | |
|
10542 | 0 | return; |
10543 | 0 | } |
10544 | | |
10545 | | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
10546 | | struct route_table *rt, |
10547 | | json_object *json) |
10548 | 0 | { |
10549 | 0 | struct route_node *rn; |
10550 | 0 | struct ospf_route * or ; |
10551 | 0 | struct listnode *pnode, *pnnode; |
10552 | 0 | struct ospf_path *path; |
10553 | 0 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10554 | 0 | *json_nexthop = NULL; |
10555 | |
|
10556 | 0 | if (!json) |
10557 | 0 | vty_out(vty, |
10558 | 0 | "============ OSPF network routing table ============\n"); |
10559 | |
|
10560 | 0 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
10561 | 0 | char buf1[PREFIX2STR_BUFFER]; |
10562 | |
|
10563 | 0 | if ((or = rn->info) == NULL) |
10564 | 0 | continue; |
10565 | | |
10566 | 0 | prefix2str(&rn->p, buf1, sizeof(buf1)); |
10567 | |
|
10568 | 0 | if (json) { |
10569 | 0 | json_route = json_object_new_object(); |
10570 | 0 | json_object_object_add(json, buf1, json_route); |
10571 | 0 | } |
10572 | |
|
10573 | 0 | switch (or->path_type) { |
10574 | 0 | case OSPF_PATH_INTER_AREA: |
10575 | 0 | if (or->type == OSPF_DESTINATION_NETWORK) { |
10576 | 0 | if (json) { |
10577 | 0 | json_object_string_add(json_route, |
10578 | 0 | "routeType", |
10579 | 0 | "N IA"); |
10580 | 0 | json_object_int_add(json_route, "cost", |
10581 | 0 | or->cost); |
10582 | 0 | json_object_string_addf( |
10583 | 0 | json_route, "area", "%pI4", |
10584 | 0 | &or->u.std.area_id); |
10585 | 0 | } else { |
10586 | 0 | vty_out(vty, |
10587 | 0 | "N IA %-18s [%d] area: %pI4\n", |
10588 | 0 | buf1, or->cost, |
10589 | 0 | &or->u.std.area_id); |
10590 | 0 | } |
10591 | 0 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
10592 | 0 | if (json) { |
10593 | 0 | json_object_string_add(json_route, |
10594 | 0 | "routeType", |
10595 | 0 | "D IA"); |
10596 | 0 | } else { |
10597 | 0 | vty_out(vty, |
10598 | 0 | "D IA %-18s Discard entry\n", |
10599 | 0 | buf1); |
10600 | 0 | } |
10601 | 0 | } |
10602 | 0 | break; |
10603 | 0 | case OSPF_PATH_INTRA_AREA: |
10604 | 0 | if (json) { |
10605 | 0 | json_object_string_add(json_route, "routeType", |
10606 | 0 | "N"); |
10607 | 0 | json_object_int_add(json_route, "cost", |
10608 | 0 | or->cost); |
10609 | 0 | json_object_string_addf(json_route, "area", |
10610 | 0 | "%pI4", |
10611 | 0 | &or->u.std.area_id); |
10612 | 0 | } else { |
10613 | 0 | vty_out(vty, "N %-18s [%d] area: %pI4\n", |
10614 | 0 | buf1, or->cost, |
10615 | 0 | &or->u.std.area_id); |
10616 | 0 | } |
10617 | 0 | break; |
10618 | 0 | default: |
10619 | 0 | break; |
10620 | 0 | } |
10621 | | |
10622 | 0 | if (or->type == OSPF_DESTINATION_NETWORK) { |
10623 | 0 | if (json) { |
10624 | 0 | json_nexthop_array = json_object_new_array(); |
10625 | 0 | json_object_object_add(json_route, "nexthops", |
10626 | 0 | json_nexthop_array); |
10627 | 0 | } |
10628 | |
|
10629 | 0 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
10630 | 0 | path)) { |
10631 | 0 | if (json) { |
10632 | 0 | json_nexthop = json_object_new_object(); |
10633 | 0 | json_object_array_add( |
10634 | 0 | json_nexthop_array, |
10635 | 0 | json_nexthop); |
10636 | 0 | } |
10637 | 0 | if (if_lookup_by_index(path->ifindex, |
10638 | 0 | ospf->vrf_id)) { |
10639 | |
|
10640 | 0 | if (path->nexthop.s_addr |
10641 | 0 | == INADDR_ANY) { |
10642 | 0 | if (json) { |
10643 | 0 | json_object_string_add( |
10644 | 0 | json_nexthop, |
10645 | 0 | "ip", " "); |
10646 | 0 | json_object_string_add( |
10647 | 0 | json_nexthop, |
10648 | 0 | "directlyAttachedTo", |
10649 | 0 | ifindex2ifname( |
10650 | 0 | path->ifindex, |
10651 | 0 | ospf->vrf_id)); |
10652 | 0 | } else { |
10653 | 0 | vty_out(vty, |
10654 | 0 | "%24s directly attached to %s\n", |
10655 | 0 | "", |
10656 | 0 | ifindex2ifname( |
10657 | 0 | path->ifindex, |
10658 | 0 | ospf->vrf_id)); |
10659 | 0 | } |
10660 | 0 | } else { |
10661 | 0 | if (json) { |
10662 | 0 | json_object_string_addf( |
10663 | 0 | json_nexthop, |
10664 | 0 | "ip", "%pI4", |
10665 | 0 | &path->nexthop); |
10666 | 0 | json_object_string_add( |
10667 | 0 | json_nexthop, |
10668 | 0 | "via", |
10669 | 0 | ifindex2ifname( |
10670 | 0 | path->ifindex, |
10671 | 0 | ospf->vrf_id)); |
10672 | 0 | } else { |
10673 | 0 | vty_out(vty, |
10674 | 0 | "%24s via %pI4, %s\n", |
10675 | 0 | "", |
10676 | 0 | &path->nexthop, |
10677 | 0 | ifindex2ifname( |
10678 | 0 | path->ifindex, |
10679 | 0 | ospf->vrf_id)); |
10680 | 0 | } |
10681 | 0 | } |
10682 | 0 | } |
10683 | 0 | } |
10684 | 0 | } |
10685 | 0 | } |
10686 | 0 | if (!json) |
10687 | 0 | vty_out(vty, "\n"); |
10688 | 0 | } |
10689 | | |
10690 | | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
10691 | | struct route_table *rtrs, |
10692 | | json_object *json) |
10693 | 0 | { |
10694 | 0 | struct route_node *rn; |
10695 | 0 | struct ospf_route * or ; |
10696 | 0 | struct listnode *pnode; |
10697 | 0 | struct listnode *node; |
10698 | 0 | struct ospf_path *path; |
10699 | 0 | char buf[PREFIX_STRLEN]; |
10700 | 0 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10701 | 0 | *json_nexthop = NULL; |
10702 | |
|
10703 | 0 | if (!json) |
10704 | 0 | vty_out(vty, "============ OSPF %s table =============\n", |
10705 | 0 | ospf->all_rtrs == rtrs ? "reachable routers" |
10706 | 0 | : "router routing"); |
10707 | |
|
10708 | 0 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
10709 | 0 | if (rn->info == NULL) |
10710 | 0 | continue; |
10711 | 0 | int flag = 0; |
10712 | |
|
10713 | 0 | if (json) { |
10714 | 0 | json_route = json_object_new_object(); |
10715 | 0 | json_object_object_add( |
10716 | 0 | json, inet_ntop(AF_INET, &rn->p.u.prefix4, |
10717 | 0 | buf, sizeof(buf)), |
10718 | 0 | json_route); |
10719 | 0 | json_object_string_add(json_route, "routeType", "R "); |
10720 | 0 | } else { |
10721 | 0 | vty_out(vty, "R %-15pI4 ", |
10722 | 0 | &rn->p.u.prefix4); |
10723 | 0 | } |
10724 | |
|
10725 | 0 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
10726 | 0 | if (flag++) { |
10727 | 0 | if (!json) |
10728 | 0 | vty_out(vty, "%24s", ""); |
10729 | 0 | } |
10730 | | |
10731 | | /* Show path. */ |
10732 | 0 | if (json) { |
10733 | 0 | json_object_int_add(json_route, "cost", |
10734 | 0 | or->cost); |
10735 | 0 | json_object_string_addf(json_route, "area", |
10736 | 0 | "%pI4", |
10737 | 0 | &or->u.std.area_id); |
10738 | 0 | if (or->path_type == OSPF_PATH_INTER_AREA) { |
10739 | 0 | json_object_boolean_true_add(json_route, |
10740 | 0 | "IA"); |
10741 | 0 | json_object_boolean_true_add(json_route, |
10742 | 0 | "ia"); |
10743 | 0 | } |
10744 | 0 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
10745 | 0 | json_object_string_add(json_route, |
10746 | 0 | "routerType", |
10747 | 0 | "abr"); |
10748 | 0 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) |
10749 | 0 | json_object_string_add(json_route, |
10750 | 0 | "routerType", |
10751 | 0 | "asbr"); |
10752 | 0 | } else { |
10753 | 0 | vty_out(vty, "%s [%d] area: %pI4", |
10754 | 0 | (or->path_type == OSPF_PATH_INTER_AREA |
10755 | 0 | ? "IA" |
10756 | 0 | : " "), |
10757 | 0 | or->cost, &or->u.std.area_id); |
10758 | | /* Show flags. */ |
10759 | 0 | vty_out(vty, "%s%s\n", |
10760 | 0 | (or->u.std.flags & ROUTER_LSA_BORDER |
10761 | 0 | ? ", ABR" |
10762 | 0 | : ""), |
10763 | 0 | (or->u.std.flags & ROUTER_LSA_EXTERNAL |
10764 | 0 | ? ", ASBR" |
10765 | 0 | : "")); |
10766 | 0 | } |
10767 | |
|
10768 | 0 | if (json) { |
10769 | 0 | json_nexthop_array = json_object_new_array(); |
10770 | 0 | json_object_object_add(json_route, "nexthops", |
10771 | 0 | json_nexthop_array); |
10772 | 0 | } |
10773 | |
|
10774 | 0 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
10775 | 0 | if (json) { |
10776 | 0 | json_nexthop = json_object_new_object(); |
10777 | 0 | json_object_array_add( |
10778 | 0 | json_nexthop_array, |
10779 | 0 | json_nexthop); |
10780 | 0 | } |
10781 | 0 | if (if_lookup_by_index(path->ifindex, |
10782 | 0 | ospf->vrf_id)) { |
10783 | 0 | if (path->nexthop.s_addr |
10784 | 0 | == INADDR_ANY) { |
10785 | 0 | if (json) { |
10786 | 0 | json_object_string_add( |
10787 | 0 | json_nexthop, |
10788 | 0 | "ip", " "); |
10789 | 0 | json_object_string_add( |
10790 | 0 | json_nexthop, |
10791 | 0 | "directlyAttachedTo", |
10792 | 0 | ifindex2ifname( |
10793 | 0 | path->ifindex, |
10794 | 0 | ospf->vrf_id)); |
10795 | 0 | } else { |
10796 | 0 | vty_out(vty, |
10797 | 0 | "%24s directly attached to %s\n", |
10798 | 0 | "", |
10799 | 0 | ifindex2ifname( |
10800 | 0 | path->ifindex, |
10801 | 0 | ospf->vrf_id)); |
10802 | 0 | } |
10803 | 0 | } else { |
10804 | 0 | if (json) { |
10805 | 0 | json_object_string_addf( |
10806 | 0 | json_nexthop, |
10807 | 0 | "ip", "%pI4", |
10808 | 0 | &path->nexthop); |
10809 | 0 | json_object_string_add( |
10810 | 0 | json_nexthop, |
10811 | 0 | "via", |
10812 | 0 | ifindex2ifname( |
10813 | 0 | path->ifindex, |
10814 | 0 | ospf->vrf_id)); |
10815 | 0 | } else { |
10816 | 0 | vty_out(vty, |
10817 | 0 | "%24s via %pI4, %s\n", |
10818 | 0 | "", |
10819 | 0 | &path->nexthop, |
10820 | 0 | ifindex2ifname( |
10821 | 0 | path->ifindex, |
10822 | 0 | ospf->vrf_id)); |
10823 | 0 | } |
10824 | 0 | } |
10825 | 0 | } |
10826 | 0 | } |
10827 | 0 | } |
10828 | 0 | } |
10829 | 0 | if (!json) |
10830 | 0 | vty_out(vty, "\n"); |
10831 | 0 | } |
10832 | | |
10833 | | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
10834 | | struct route_table *rt, |
10835 | | json_object *json) |
10836 | 0 | { |
10837 | 0 | struct route_node *rn; |
10838 | 0 | struct ospf_route *er; |
10839 | 0 | struct listnode *pnode, *pnnode; |
10840 | 0 | struct ospf_path *path; |
10841 | 0 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10842 | 0 | *json_nexthop = NULL; |
10843 | |
|
10844 | 0 | if (!json) |
10845 | 0 | vty_out(vty, |
10846 | 0 | "============ OSPF external routing table ===========\n"); |
10847 | |
|
10848 | 0 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
10849 | 0 | if ((er = rn->info) == NULL) |
10850 | 0 | continue; |
10851 | | |
10852 | 0 | char buf1[19]; |
10853 | |
|
10854 | 0 | snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p); |
10855 | 0 | if (json) { |
10856 | 0 | json_route = json_object_new_object(); |
10857 | 0 | json_object_object_add(json, buf1, json_route); |
10858 | 0 | } |
10859 | |
|
10860 | 0 | switch (er->path_type) { |
10861 | 0 | case OSPF_PATH_TYPE1_EXTERNAL: |
10862 | 0 | if (json) { |
10863 | 0 | json_object_string_add(json_route, "routeType", |
10864 | 0 | "N E1"); |
10865 | 0 | json_object_int_add(json_route, "cost", |
10866 | 0 | er->cost); |
10867 | 0 | json_object_int_add(json_route, "tag", |
10868 | 0 | er->u.ext.tag); |
10869 | 0 | } else { |
10870 | 0 | vty_out(vty, |
10871 | 0 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
10872 | 0 | "\n", |
10873 | 0 | buf1, er->cost, er->u.ext.tag); |
10874 | 0 | } |
10875 | 0 | break; |
10876 | 0 | case OSPF_PATH_TYPE2_EXTERNAL: |
10877 | 0 | if (json) { |
10878 | 0 | json_object_string_add(json_route, "routeType", |
10879 | 0 | "N E2"); |
10880 | 0 | json_object_int_add(json_route, "cost", |
10881 | 0 | er->cost); |
10882 | 0 | json_object_int_add(json_route, "type2cost", |
10883 | 0 | er->u.ext.type2_cost); |
10884 | 0 | json_object_int_add(json_route, "tag", |
10885 | 0 | er->u.ext.tag); |
10886 | 0 | } else { |
10887 | 0 | vty_out(vty, |
10888 | 0 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
10889 | 0 | "\n", |
10890 | 0 | buf1, er->cost, er->u.ext.type2_cost, |
10891 | 0 | er->u.ext.tag); |
10892 | 0 | } |
10893 | 0 | break; |
10894 | 0 | } |
10895 | | |
10896 | 0 | if (json) { |
10897 | 0 | json_nexthop_array = json_object_new_array(); |
10898 | 0 | json_object_object_add(json_route, "nexthops", |
10899 | 0 | json_nexthop_array); |
10900 | 0 | } |
10901 | |
|
10902 | 0 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
10903 | 0 | if (json) { |
10904 | 0 | json_nexthop = json_object_new_object(); |
10905 | 0 | json_object_array_add(json_nexthop_array, |
10906 | 0 | json_nexthop); |
10907 | 0 | } |
10908 | |
|
10909 | 0 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
10910 | 0 | if (path->nexthop.s_addr == INADDR_ANY) { |
10911 | 0 | if (json) { |
10912 | 0 | json_object_string_add( |
10913 | 0 | json_nexthop, "ip", |
10914 | 0 | " "); |
10915 | 0 | json_object_string_add( |
10916 | 0 | json_nexthop, |
10917 | 0 | "directlyAttachedTo", |
10918 | 0 | ifindex2ifname( |
10919 | 0 | path->ifindex, |
10920 | 0 | ospf->vrf_id)); |
10921 | 0 | } else { |
10922 | 0 | vty_out(vty, |
10923 | 0 | "%24s directly attached to %s\n", |
10924 | 0 | "", |
10925 | 0 | ifindex2ifname( |
10926 | 0 | path->ifindex, |
10927 | 0 | ospf->vrf_id)); |
10928 | 0 | } |
10929 | 0 | } else { |
10930 | 0 | if (json) { |
10931 | 0 | json_object_string_addf( |
10932 | 0 | json_nexthop, "ip", |
10933 | 0 | "%pI4", &path->nexthop); |
10934 | 0 | json_object_string_add( |
10935 | 0 | json_nexthop, "via", |
10936 | 0 | ifindex2ifname( |
10937 | 0 | path->ifindex, |
10938 | 0 | ospf->vrf_id)); |
10939 | 0 | } else { |
10940 | 0 | vty_out(vty, |
10941 | 0 | "%24s via %pI4, %s\n", |
10942 | 0 | "", |
10943 | 0 | &path->nexthop, |
10944 | 0 | ifindex2ifname( |
10945 | 0 | path->ifindex, |
10946 | 0 | ospf->vrf_id)); |
10947 | 0 | } |
10948 | 0 | } |
10949 | 0 | } |
10950 | 0 | } |
10951 | 0 | } |
10952 | 0 | if (!json) |
10953 | 0 | vty_out(vty, "\n"); |
10954 | 0 | } |
10955 | | |
10956 | | static int show_ip_ospf_reachable_routers_common(struct vty *vty, |
10957 | | struct ospf *ospf, |
10958 | | uint8_t use_vrf) |
10959 | 0 | { |
10960 | 0 | if (ospf->instance) |
10961 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
10962 | |
|
10963 | 0 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
10964 | |
|
10965 | 0 | if (ospf->all_rtrs == NULL) { |
10966 | 0 | vty_out(vty, "No OSPF reachable router information exist\n"); |
10967 | 0 | return CMD_SUCCESS; |
10968 | 0 | } |
10969 | | |
10970 | | /* Show Router routes. */ |
10971 | 0 | show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, NULL); |
10972 | |
|
10973 | 0 | vty_out(vty, "\n"); |
10974 | |
|
10975 | 0 | return CMD_SUCCESS; |
10976 | 0 | } |
10977 | | |
10978 | | DEFUN (show_ip_ospf_reachable_routers, |
10979 | | show_ip_ospf_reachable_routers_cmd, |
10980 | | "show ip ospf [vrf <NAME|all>] reachable-routers", |
10981 | | SHOW_STR |
10982 | | IP_STR |
10983 | | "OSPF information\n" |
10984 | | VRF_CMD_HELP_STR |
10985 | | "All VRFs\n" |
10986 | | "Show all the reachable OSPF routers\n") |
10987 | 0 | { |
10988 | 0 | struct ospf *ospf = NULL; |
10989 | 0 | struct listnode *node = NULL; |
10990 | 0 | char *vrf_name = NULL; |
10991 | 0 | bool all_vrf = false; |
10992 | 0 | int ret = CMD_SUCCESS; |
10993 | 0 | int inst = 0; |
10994 | 0 | int idx_vrf = 0; |
10995 | 0 | uint8_t use_vrf = 0; |
10996 | |
|
10997 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
10998 | |
|
10999 | 0 | if (vrf_name) { |
11000 | 0 | bool ospf_output = false; |
11001 | |
|
11002 | 0 | use_vrf = 1; |
11003 | |
|
11004 | 0 | if (all_vrf) { |
11005 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
11006 | 0 | if (!ospf->oi_running) |
11007 | 0 | continue; |
11008 | | |
11009 | 0 | ospf_output = true; |
11010 | 0 | ret = show_ip_ospf_reachable_routers_common( |
11011 | 0 | vty, ospf, use_vrf); |
11012 | 0 | } |
11013 | |
|
11014 | 0 | if (!ospf_output) |
11015 | 0 | vty_out(vty, "%% OSPF instance not found\n"); |
11016 | 0 | } else { |
11017 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
11018 | 0 | if (ospf == NULL || !ospf->oi_running) { |
11019 | 0 | vty_out(vty, "%% OSPF instance not found\n"); |
11020 | 0 | return CMD_SUCCESS; |
11021 | 0 | } |
11022 | | |
11023 | 0 | ret = show_ip_ospf_reachable_routers_common(vty, ospf, |
11024 | 0 | use_vrf); |
11025 | 0 | } |
11026 | 0 | } else { |
11027 | | /* Display default ospf (instance 0) info */ |
11028 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
11029 | 0 | if (ospf == NULL || !ospf->oi_running) { |
11030 | 0 | vty_out(vty, "%% OSPF instance not found\n"); |
11031 | 0 | return CMD_SUCCESS; |
11032 | 0 | } |
11033 | | |
11034 | 0 | ret = show_ip_ospf_reachable_routers_common(vty, ospf, use_vrf); |
11035 | 0 | } |
11036 | | |
11037 | 0 | return ret; |
11038 | 0 | } |
11039 | | |
11040 | | DEFUN (show_ip_ospf_instance_reachable_routers, |
11041 | | show_ip_ospf_instance_reachable_routers_cmd, |
11042 | | "show ip ospf (1-65535) reachable-routers", |
11043 | | SHOW_STR |
11044 | | IP_STR |
11045 | | "OSPF information\n" |
11046 | | "Instance ID\n" |
11047 | | "Show all the reachable OSPF routers\n") |
11048 | 0 | { |
11049 | 0 | int idx_number = 3; |
11050 | 0 | struct ospf *ospf; |
11051 | 0 | unsigned short instance = 0; |
11052 | |
|
11053 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
11054 | 0 | if (instance != ospf_instance) |
11055 | 0 | return CMD_NOT_MY_INSTANCE; |
11056 | | |
11057 | 0 | ospf = ospf_lookup_instance(instance); |
11058 | 0 | if (!ospf || !ospf->oi_running) |
11059 | 0 | return CMD_SUCCESS; |
11060 | | |
11061 | 0 | return show_ip_ospf_reachable_routers_common(vty, ospf, 0); |
11062 | 0 | } |
11063 | | |
11064 | | static int show_ip_ospf_border_routers_common(struct vty *vty, |
11065 | | struct ospf *ospf, |
11066 | | uint8_t use_vrf, |
11067 | | json_object *json) |
11068 | 0 | { |
11069 | 0 | json_object *json_vrf = NULL; |
11070 | 0 | json_object *json_router = NULL; |
11071 | |
|
11072 | 0 | if (json) { |
11073 | 0 | if (use_vrf) |
11074 | 0 | json_vrf = json_object_new_object(); |
11075 | 0 | else |
11076 | 0 | json_vrf = json; |
11077 | 0 | json_router = json_object_new_object(); |
11078 | 0 | } |
11079 | |
|
11080 | 0 | if (ospf->instance) { |
11081 | 0 | if (!json) |
11082 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
11083 | 0 | else |
11084 | 0 | json_object_int_add(json_vrf, "ospfInstance", |
11085 | 0 | ospf->instance); |
11086 | 0 | } |
11087 | |
|
11088 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
11089 | |
|
11090 | 0 | if (ospf->new_table == NULL) { |
11091 | 0 | if (!json) |
11092 | 0 | vty_out(vty, "No OSPF routing information exist\n"); |
11093 | 0 | else { |
11094 | 0 | json_object_free(json_router); |
11095 | 0 | if (use_vrf) |
11096 | 0 | json_object_free(json_vrf); |
11097 | 0 | } |
11098 | 0 | return CMD_SUCCESS; |
11099 | 0 | } |
11100 | | |
11101 | | /* Show Network routes. |
11102 | | show_ip_ospf_route_network (vty, ospf->new_table); */ |
11103 | | |
11104 | | /* Show Router routes. */ |
11105 | 0 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_router); |
11106 | |
|
11107 | 0 | if (json) { |
11108 | 0 | json_object_object_add(json_vrf, "routers", json_router); |
11109 | 0 | if (use_vrf) { |
11110 | 0 | if (ospf->vrf_id == VRF_DEFAULT) |
11111 | 0 | json_object_object_add(json, "default", |
11112 | 0 | json_vrf); |
11113 | 0 | else |
11114 | 0 | json_object_object_add(json, ospf->name, |
11115 | 0 | json_vrf); |
11116 | 0 | } |
11117 | 0 | } else { |
11118 | 0 | vty_out(vty, "\n"); |
11119 | 0 | } |
11120 | |
|
11121 | 0 | return CMD_SUCCESS; |
11122 | 0 | } |
11123 | | |
11124 | | DEFPY (show_ip_ospf_border_routers, |
11125 | | show_ip_ospf_border_routers_cmd, |
11126 | | "show ip ospf [vrf <NAME|all>] border-routers [json]", |
11127 | | SHOW_STR |
11128 | | IP_STR |
11129 | | "OSPF information\n" |
11130 | | VRF_CMD_HELP_STR |
11131 | | "All VRFs\n" |
11132 | | "Show all the ABR's and ASBR's\n" |
11133 | | JSON_STR) |
11134 | 0 | { |
11135 | 0 | struct ospf *ospf = NULL; |
11136 | 0 | struct listnode *node = NULL; |
11137 | 0 | char *vrf_name = NULL; |
11138 | 0 | bool all_vrf = false; |
11139 | 0 | int ret = CMD_SUCCESS; |
11140 | 0 | int inst = 0; |
11141 | 0 | int idx_vrf = 0; |
11142 | 0 | uint8_t use_vrf = 0; |
11143 | 0 | bool uj = use_json(argc, argv); |
11144 | 0 | json_object *json = NULL; |
11145 | |
|
11146 | 0 | if (uj) |
11147 | 0 | json = json_object_new_object(); |
11148 | |
|
11149 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
11150 | |
|
11151 | 0 | if (vrf_name) { |
11152 | 0 | bool ospf_output = false; |
11153 | |
|
11154 | 0 | use_vrf = 1; |
11155 | |
|
11156 | 0 | if (all_vrf) { |
11157 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
11158 | 0 | if (!ospf->oi_running) |
11159 | 0 | continue; |
11160 | | |
11161 | 0 | ospf_output = true; |
11162 | 0 | ret = show_ip_ospf_border_routers_common( |
11163 | 0 | vty, ospf, use_vrf, json); |
11164 | 0 | } |
11165 | |
|
11166 | 0 | if (uj) |
11167 | 0 | vty_json(vty, json); |
11168 | 0 | else if (!ospf_output) |
11169 | 0 | vty_out(vty, "%% OSPF is not enabled\n"); |
11170 | |
|
11171 | 0 | return ret; |
11172 | 0 | } else { |
11173 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
11174 | 0 | if (ospf == NULL || !ospf->oi_running) { |
11175 | 0 | if (uj) |
11176 | 0 | vty_json(vty, json); |
11177 | 0 | else |
11178 | 0 | vty_out(vty, |
11179 | 0 | "%% OSPF is not enabled in vrf %s\n", |
11180 | 0 | vrf_name); |
11181 | |
|
11182 | 0 | return CMD_SUCCESS; |
11183 | 0 | } |
11184 | 0 | } |
11185 | 0 | } else { |
11186 | | /* Display default ospf (instance 0) info */ |
11187 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
11188 | 0 | if (ospf == NULL || !ospf->oi_running) { |
11189 | 0 | if (uj) |
11190 | 0 | vty_json(vty, json); |
11191 | 0 | else |
11192 | 0 | vty_out(vty, |
11193 | 0 | "%% OSPF is not enabled in vrf default\n"); |
11194 | |
|
11195 | 0 | return CMD_SUCCESS; |
11196 | 0 | } |
11197 | 0 | } |
11198 | | |
11199 | 0 | if (ospf) { |
11200 | 0 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf, |
11201 | 0 | json); |
11202 | 0 | if (uj) |
11203 | 0 | vty_json(vty, json); |
11204 | 0 | } |
11205 | |
|
11206 | 0 | return ret; |
11207 | 0 | } |
11208 | | |
11209 | | DEFUN (show_ip_ospf_instance_border_routers, |
11210 | | show_ip_ospf_instance_border_routers_cmd, |
11211 | | "show ip ospf (1-65535) border-routers", |
11212 | | SHOW_STR |
11213 | | IP_STR |
11214 | | "OSPF information\n" |
11215 | | "Instance ID\n" |
11216 | | "Show all the ABR's and ASBR's\n") |
11217 | 0 | { |
11218 | 0 | int idx_number = 3; |
11219 | 0 | struct ospf *ospf; |
11220 | 0 | unsigned short instance = 0; |
11221 | |
|
11222 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
11223 | 0 | if (instance != ospf_instance) |
11224 | 0 | return CMD_NOT_MY_INSTANCE; |
11225 | | |
11226 | 0 | ospf = ospf_lookup_instance(instance); |
11227 | 0 | if (!ospf || !ospf->oi_running) |
11228 | 0 | return CMD_SUCCESS; |
11229 | | |
11230 | 0 | return show_ip_ospf_border_routers_common(vty, ospf, 0, NULL); |
11231 | 0 | } |
11232 | | |
11233 | | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
11234 | | json_object *json, uint8_t use_vrf) |
11235 | 0 | { |
11236 | 0 | json_object *json_vrf = NULL; |
11237 | |
|
11238 | 0 | if (ospf->instance) |
11239 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
11240 | | |
11241 | |
|
11242 | 0 | if (json) { |
11243 | 0 | if (use_vrf) |
11244 | 0 | json_vrf = json_object_new_object(); |
11245 | 0 | else |
11246 | 0 | json_vrf = json; |
11247 | 0 | } |
11248 | |
|
11249 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
11250 | |
|
11251 | 0 | if (ospf->new_table == NULL) { |
11252 | 0 | if (json) { |
11253 | 0 | if (use_vrf) |
11254 | 0 | json_object_free(json_vrf); |
11255 | 0 | } else { |
11256 | 0 | vty_out(vty, "No OSPF routing information exist\n"); |
11257 | 0 | } |
11258 | 0 | return CMD_SUCCESS; |
11259 | 0 | } |
11260 | | |
11261 | | /* Show Network routes. */ |
11262 | 0 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
11263 | | |
11264 | | /* Show Router routes. */ |
11265 | 0 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
11266 | | |
11267 | | /* Show Router routes. */ |
11268 | 0 | if (ospf->all_rtrs) |
11269 | 0 | show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, json_vrf); |
11270 | | |
11271 | | /* Show AS External routes. */ |
11272 | 0 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
11273 | 0 | json_vrf); |
11274 | |
|
11275 | 0 | if (json) { |
11276 | 0 | if (use_vrf) { |
11277 | | // json_object_object_add(json_vrf, "areas", |
11278 | | // json_areas); |
11279 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
11280 | 0 | json_vrf); |
11281 | 0 | } |
11282 | 0 | } else { |
11283 | 0 | vty_out(vty, "\n"); |
11284 | 0 | } |
11285 | |
|
11286 | 0 | return CMD_SUCCESS; |
11287 | 0 | } |
11288 | | |
11289 | | DEFUN (show_ip_ospf_route, |
11290 | | show_ip_ospf_route_cmd, |
11291 | | "show ip ospf [vrf <NAME|all>] route [json]", |
11292 | | SHOW_STR |
11293 | | IP_STR |
11294 | | "OSPF information\n" |
11295 | | VRF_CMD_HELP_STR |
11296 | | "All VRFs\n" |
11297 | | "OSPF routing table\n" |
11298 | | JSON_STR) |
11299 | 0 | { |
11300 | 0 | struct ospf *ospf = NULL; |
11301 | 0 | struct listnode *node = NULL; |
11302 | 0 | char *vrf_name = NULL; |
11303 | 0 | bool all_vrf = false; |
11304 | 0 | int ret = CMD_SUCCESS; |
11305 | 0 | int inst = 0; |
11306 | 0 | int idx_vrf = 0; |
11307 | 0 | uint8_t use_vrf = 0; |
11308 | 0 | bool uj = use_json(argc, argv); |
11309 | 0 | json_object *json = NULL; |
11310 | |
|
11311 | 0 | if (uj) |
11312 | 0 | json = json_object_new_object(); |
11313 | |
|
11314 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
11315 | | |
11316 | | /* vrf input is provided could be all or specific vrf*/ |
11317 | 0 | if (vrf_name) { |
11318 | 0 | bool ospf_output = false; |
11319 | |
|
11320 | 0 | use_vrf = 1; |
11321 | |
|
11322 | 0 | if (all_vrf) { |
11323 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
11324 | 0 | if (!ospf->oi_running) |
11325 | 0 | continue; |
11326 | 0 | ospf_output = true; |
11327 | 0 | ret = show_ip_ospf_route_common(vty, ospf, json, |
11328 | 0 | use_vrf); |
11329 | 0 | } |
11330 | |
|
11331 | 0 | if (uj) { |
11332 | | /* Keep Non-pretty format */ |
11333 | 0 | vty_json(vty, json); |
11334 | 0 | } else if (!ospf_output) |
11335 | 0 | vty_out(vty, "%% OSPF is not enabled\n"); |
11336 | |
|
11337 | 0 | return ret; |
11338 | 0 | } |
11339 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
11340 | 0 | if (ospf == NULL || !ospf->oi_running) { |
11341 | 0 | if (uj) |
11342 | 0 | vty_json(vty, json); |
11343 | 0 | else |
11344 | 0 | vty_out(vty, |
11345 | 0 | "%% OSPF is not enabled in vrf %s\n", |
11346 | 0 | vrf_name); |
11347 | |
|
11348 | 0 | return CMD_SUCCESS; |
11349 | 0 | } |
11350 | 0 | } else { |
11351 | | /* Display default ospf (instance 0) info */ |
11352 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
11353 | 0 | if (ospf == NULL || !ospf->oi_running) { |
11354 | 0 | if (uj) |
11355 | 0 | vty_json(vty, json); |
11356 | 0 | else |
11357 | 0 | vty_out(vty, |
11358 | 0 | "%% OSPF is not enabled in vrf default\n"); |
11359 | |
|
11360 | 0 | return CMD_SUCCESS; |
11361 | 0 | } |
11362 | 0 | } |
11363 | | |
11364 | 0 | if (ospf) { |
11365 | 0 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); |
11366 | | /* Keep Non-pretty format */ |
11367 | 0 | if (uj) |
11368 | 0 | vty_out(vty, "%s\n", |
11369 | 0 | json_object_to_json_string_ext( |
11370 | 0 | json, JSON_C_TO_STRING_NOSLASHESCAPE)); |
11371 | 0 | } |
11372 | |
|
11373 | 0 | if (uj) |
11374 | 0 | json_object_free(json); |
11375 | |
|
11376 | 0 | return ret; |
11377 | 0 | } |
11378 | | |
11379 | | DEFUN (show_ip_ospf_instance_route, |
11380 | | show_ip_ospf_instance_route_cmd, |
11381 | | "show ip ospf (1-65535) route", |
11382 | | SHOW_STR |
11383 | | IP_STR |
11384 | | "OSPF information\n" |
11385 | | "Instance ID\n" |
11386 | | "OSPF routing table\n") |
11387 | 0 | { |
11388 | 0 | int idx_number = 3; |
11389 | 0 | struct ospf *ospf; |
11390 | 0 | unsigned short instance = 0; |
11391 | |
|
11392 | 0 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
11393 | 0 | if (instance != ospf_instance) |
11394 | 0 | return CMD_NOT_MY_INSTANCE; |
11395 | | |
11396 | 0 | ospf = ospf_lookup_instance(instance); |
11397 | 0 | if (!ospf || !ospf->oi_running) |
11398 | 0 | return CMD_SUCCESS; |
11399 | | |
11400 | 0 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
11401 | 0 | } |
11402 | | |
11403 | | |
11404 | | DEFUN (show_ip_ospf_vrfs, |
11405 | | show_ip_ospf_vrfs_cmd, |
11406 | | "show ip ospf vrfs [json]", |
11407 | | SHOW_STR |
11408 | | IP_STR |
11409 | | "OSPF information\n" |
11410 | | "Show OSPF VRFs \n" |
11411 | | JSON_STR) |
11412 | 0 | { |
11413 | 0 | bool uj = use_json(argc, argv); |
11414 | 0 | json_object *json = NULL; |
11415 | 0 | json_object *json_vrfs = NULL; |
11416 | 0 | struct ospf *ospf = NULL; |
11417 | 0 | struct listnode *node = NULL; |
11418 | 0 | int count = 0; |
11419 | 0 | static const char header[] = "Name Id RouterId "; |
11420 | |
|
11421 | 0 | if (uj) { |
11422 | 0 | json = json_object_new_object(); |
11423 | 0 | json_vrfs = json_object_new_object(); |
11424 | 0 | } |
11425 | |
|
11426 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
11427 | 0 | json_object *json_vrf = NULL; |
11428 | 0 | const char *name = NULL; |
11429 | 0 | int64_t vrf_id_ui = 0; |
11430 | |
|
11431 | 0 | count++; |
11432 | |
|
11433 | 0 | if (!uj && count == 1) |
11434 | 0 | vty_out(vty, "%s\n", header); |
11435 | 0 | if (uj) |
11436 | 0 | json_vrf = json_object_new_object(); |
11437 | |
|
11438 | 0 | name = ospf_get_name(ospf); |
11439 | |
|
11440 | 0 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
11441 | 0 | ? -1 |
11442 | 0 | : (int64_t)ospf->vrf_id; |
11443 | |
|
11444 | 0 | if (uj) { |
11445 | 0 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); |
11446 | 0 | json_object_string_addf(json_vrf, "routerId", "%pI4", |
11447 | 0 | &ospf->router_id); |
11448 | |
|
11449 | 0 | json_object_object_add(json_vrfs, name, json_vrf); |
11450 | |
|
11451 | 0 | } else { |
11452 | 0 | vty_out(vty, "%-25s %-5d %-16pI4 \n", name, |
11453 | 0 | ospf->vrf_id, &ospf->router_id); |
11454 | 0 | } |
11455 | 0 | } |
11456 | |
|
11457 | 0 | if (uj) { |
11458 | 0 | json_object_object_add(json, "vrfs", json_vrfs); |
11459 | 0 | json_object_int_add(json, "totalVrfs", count); |
11460 | |
|
11461 | 0 | vty_json(vty, json); |
11462 | 0 | } else { |
11463 | 0 | if (count) |
11464 | 0 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
11465 | 0 | count); |
11466 | 0 | } |
11467 | |
|
11468 | 0 | return CMD_SUCCESS; |
11469 | 0 | } |
11470 | | DEFPY (clear_ip_ospf_neighbor, |
11471 | | clear_ip_ospf_neighbor_cmd, |
11472 | | "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]", |
11473 | | CLEAR_STR |
11474 | | IP_STR |
11475 | | "OSPF information\n" |
11476 | | "Instance ID\n" |
11477 | | "Reset OSPF Neighbor\n" |
11478 | | "Neighbor ID\n") |
11479 | 0 | { |
11480 | 0 | struct listnode *node; |
11481 | 0 | struct ospf *ospf = NULL; |
11482 | | |
11483 | | /* If user does not specify the arguments, |
11484 | | * instance = 0 and nbr_id = 0.0.0.0 |
11485 | | */ |
11486 | 0 | if (instance != 0) { |
11487 | | /* This means clear only the particular ospf process */ |
11488 | 0 | if (instance != ospf_instance) |
11489 | 0 | return CMD_NOT_MY_INSTANCE; |
11490 | 0 | } |
11491 | | |
11492 | | /* Clear all the ospf processes */ |
11493 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
11494 | 0 | if (!ospf->oi_running) |
11495 | 0 | continue; |
11496 | | |
11497 | 0 | if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) { |
11498 | 0 | vty_out(vty, "Self router-id is not allowed.\r\n "); |
11499 | 0 | return CMD_SUCCESS; |
11500 | 0 | } |
11501 | | |
11502 | 0 | ospf_neighbor_reset(ospf, nbr_id, nbr_id_str); |
11503 | 0 | } |
11504 | | |
11505 | 0 | return CMD_SUCCESS; |
11506 | 0 | } |
11507 | | |
11508 | | DEFPY (clear_ip_ospf_process, |
11509 | | clear_ip_ospf_process_cmd, |
11510 | | "clear ip ospf [(1-65535)]$instance process", |
11511 | | CLEAR_STR |
11512 | | IP_STR |
11513 | | "OSPF information\n" |
11514 | | "Instance ID\n" |
11515 | | "Reset OSPF Process\n") |
11516 | 0 | { |
11517 | 0 | struct listnode *node; |
11518 | 0 | struct ospf *ospf = NULL; |
11519 | | |
11520 | | /* Check if instance is not passed as an argument */ |
11521 | 0 | if (instance != 0) { |
11522 | | /* This means clear only the particular ospf process */ |
11523 | 0 | if (instance != ospf_instance) |
11524 | 0 | return CMD_NOT_MY_INSTANCE; |
11525 | 0 | } |
11526 | | |
11527 | | /* Clear all the ospf processes */ |
11528 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
11529 | 0 | if (!ospf->oi_running) |
11530 | 0 | continue; |
11531 | | |
11532 | 0 | ospf_process_reset(ospf); |
11533 | 0 | } |
11534 | |
|
11535 | 0 | return CMD_SUCCESS; |
11536 | 0 | } |
11537 | | |
11538 | | static const char *const ospf_abr_type_str[] = { |
11539 | | "unknown", "standard", "ibm", "cisco", "shortcut" |
11540 | | }; |
11541 | | |
11542 | | static const char *const ospf_shortcut_mode_str[] = { |
11543 | | "default", "enable", "disable" |
11544 | | }; |
11545 | | static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket, |
11546 | | void *arg) |
11547 | 0 | { |
11548 | 0 | struct external_info *ei = bucket->data; |
11549 | 0 | struct vty *vty = (struct vty *)arg; |
11550 | 0 | static unsigned int count; |
11551 | |
|
11552 | 0 | vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen); |
11553 | 0 | count++; |
11554 | |
|
11555 | 0 | if (count % 5 == 0) |
11556 | 0 | vty_out(vty, "\n"); |
11557 | |
|
11558 | 0 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) |
11559 | 0 | count = 0; |
11560 | |
|
11561 | 0 | return HASHWALK_CONTINUE; |
11562 | 0 | } |
11563 | | |
11564 | | static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket, |
11565 | | void *arg) |
11566 | 0 | { |
11567 | 0 | struct external_info *ei = bucket->data; |
11568 | 0 | struct json_object *json = (struct json_object *)arg; |
11569 | 0 | char buf[PREFIX2STR_BUFFER]; |
11570 | 0 | char exnalbuf[20]; |
11571 | 0 | static unsigned int count; |
11572 | |
|
11573 | 0 | prefix2str(&ei->p, buf, sizeof(buf)); |
11574 | |
|
11575 | 0 | snprintf(exnalbuf, 20, "Exnl Addr-%d", count); |
11576 | |
|
11577 | 0 | json_object_string_add(json, exnalbuf, buf); |
11578 | |
|
11579 | 0 | count++; |
11580 | |
|
11581 | 0 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) |
11582 | 0 | count = 0; |
11583 | |
|
11584 | 0 | return HASHWALK_CONTINUE; |
11585 | 0 | } |
11586 | | |
11587 | | static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf, |
11588 | | uint8_t use_vrf, json_object *json, |
11589 | | bool uj, bool detail) |
11590 | 0 | { |
11591 | 0 | struct route_node *rn; |
11592 | 0 | json_object *json_vrf = NULL; |
11593 | 0 | int mtype = 0; |
11594 | 0 | int mval = 0; |
11595 | 0 | static char header[] = |
11596 | 0 | "Summary-address Metric-type Metric Tag External_Rt_count\n"; |
11597 | |
|
11598 | 0 | mtype = metric_type(ospf, 0, ospf->instance); |
11599 | 0 | mval = metric_value(ospf, 0, ospf->instance); |
11600 | |
|
11601 | 0 | if (!uj) |
11602 | 0 | vty_out(vty, "%s\n", header); |
11603 | |
|
11604 | 0 | if (uj) { |
11605 | 0 | if (use_vrf) |
11606 | 0 | json_vrf = json_object_new_object(); |
11607 | 0 | else |
11608 | 0 | json_vrf = json; |
11609 | 0 | } |
11610 | |
|
11611 | 0 | if (ospf->instance) { |
11612 | 0 | if (uj) |
11613 | 0 | json_object_int_add(json, "ospfInstance", |
11614 | 0 | ospf->instance); |
11615 | 0 | else |
11616 | 0 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); |
11617 | 0 | } |
11618 | |
|
11619 | 0 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
11620 | |
|
11621 | 0 | if (!uj) { |
11622 | 0 | vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n", |
11623 | 0 | ospf->aggr_delay_interval); |
11624 | 0 | } else { |
11625 | 0 | json_object_int_add(json_vrf, "aggregationDelayInterval", |
11626 | 0 | ospf->aggr_delay_interval); |
11627 | 0 | } |
11628 | |
|
11629 | 0 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) |
11630 | 0 | if (rn->info) { |
11631 | 0 | struct ospf_external_aggr_rt *aggr = rn->info; |
11632 | 0 | json_object *json_aggr = NULL; |
11633 | 0 | char buf[PREFIX2STR_BUFFER]; |
11634 | |
|
11635 | 0 | prefix2str(&aggr->p, buf, sizeof(buf)); |
11636 | |
|
11637 | 0 | if (uj) { |
11638 | |
|
11639 | 0 | json_aggr = json_object_new_object(); |
11640 | |
|
11641 | 0 | json_object_object_add(json_vrf, buf, |
11642 | 0 | json_aggr); |
11643 | 0 | json_object_string_add(json_aggr, |
11644 | 0 | "summaryAddress", buf); |
11645 | 0 | json_object_string_add( |
11646 | 0 | json_aggr, "metricType", |
11647 | 0 | (mtype == EXTERNAL_METRIC_TYPE_1) |
11648 | 0 | ? "E1" |
11649 | 0 | : "E2"); |
11650 | |
|
11651 | 0 | json_object_int_add(json_aggr, "metric", mval); |
11652 | 0 | json_object_int_add(json_aggr, "tag", |
11653 | 0 | aggr->tag); |
11654 | 0 | json_object_int_add( |
11655 | 0 | json_aggr, "externalRouteCount", |
11656 | 0 | OSPF_EXTERNAL_RT_COUNT(aggr)); |
11657 | |
|
11658 | 0 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { |
11659 | 0 | hash_walk( |
11660 | 0 | aggr->match_extnl_hash, |
11661 | 0 | ospf_json_external_rt_walkcb, |
11662 | 0 | json_aggr); |
11663 | 0 | } |
11664 | |
|
11665 | 0 | } else { |
11666 | 0 | vty_out(vty, "%-20s", buf); |
11667 | |
|
11668 | 0 | (mtype == EXTERNAL_METRIC_TYPE_1) |
11669 | 0 | ? vty_out(vty, "%-16s", "E1") |
11670 | 0 | : vty_out(vty, "%-16s", "E2"); |
11671 | 0 | vty_out(vty, "%-11d", mval); |
11672 | |
|
11673 | 0 | vty_out(vty, "%-12u", aggr->tag); |
11674 | |
|
11675 | 0 | vty_out(vty, "%-5ld\n", |
11676 | 0 | OSPF_EXTERNAL_RT_COUNT(aggr)); |
11677 | |
|
11678 | 0 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { |
11679 | 0 | vty_out(vty, |
11680 | 0 | "Matched External routes:\n"); |
11681 | 0 | hash_walk( |
11682 | 0 | aggr->match_extnl_hash, |
11683 | 0 | ospf_vty_external_rt_walkcb, |
11684 | 0 | vty); |
11685 | 0 | vty_out(vty, "\n"); |
11686 | 0 | } |
11687 | |
|
11688 | 0 | vty_out(vty, "\n"); |
11689 | 0 | } |
11690 | 0 | } |
11691 | |
|
11692 | 0 | if (uj) { |
11693 | 0 | if (use_vrf) |
11694 | 0 | json_object_object_add(json, ospf_get_name(ospf), |
11695 | 0 | json_vrf); |
11696 | 0 | } else |
11697 | 0 | vty_out(vty, "\n"); |
11698 | |
|
11699 | 0 | return CMD_SUCCESS; |
11700 | 0 | } |
11701 | | |
11702 | | DEFUN (show_ip_ospf_external_aggregator, |
11703 | | show_ip_ospf_external_aggregator_cmd, |
11704 | | "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]", |
11705 | | SHOW_STR IP_STR |
11706 | | "OSPF information\n" |
11707 | | VRF_CMD_HELP_STR |
11708 | | "All VRFs\n" |
11709 | | "Show external summary addresses\n" |
11710 | | "Detailed information\n" |
11711 | | JSON_STR) |
11712 | 0 | { |
11713 | 0 | char *vrf_name = NULL; |
11714 | 0 | bool all_vrf = false; |
11715 | 0 | int ret = CMD_SUCCESS; |
11716 | 0 | int idx_vrf = 0; |
11717 | 0 | int idx = 0; |
11718 | 0 | uint8_t use_vrf = 0; |
11719 | 0 | bool uj = use_json(argc, argv); |
11720 | 0 | struct ospf *ospf = NULL; |
11721 | 0 | json_object *json = NULL; |
11722 | 0 | struct listnode *node = NULL; |
11723 | 0 | int inst = 0; |
11724 | 0 | bool detail = false; |
11725 | |
|
11726 | 0 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
11727 | |
|
11728 | 0 | if (argv_find(argv, argc, "detail", &idx)) |
11729 | 0 | detail = true; |
11730 | |
|
11731 | 0 | if (uj) |
11732 | 0 | json = json_object_new_object(); |
11733 | | |
11734 | | /* vrf input is provided */ |
11735 | 0 | if (vrf_name) { |
11736 | 0 | use_vrf = 1; |
11737 | 0 | if (all_vrf) { |
11738 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
11739 | 0 | if (!ospf->oi_running) |
11740 | 0 | continue; |
11741 | 0 | ret = ospf_show_summary_address( |
11742 | 0 | vty, ospf, use_vrf, json, uj, detail); |
11743 | 0 | } |
11744 | |
|
11745 | 0 | if (uj) |
11746 | 0 | vty_json(vty, json); |
11747 | |
|
11748 | 0 | return ret; |
11749 | 0 | } |
11750 | | |
11751 | 0 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
11752 | |
|
11753 | 0 | if (ospf == NULL || !ospf->oi_running) { |
11754 | 0 | if (uj) |
11755 | 0 | vty_json(vty, json); |
11756 | 0 | else |
11757 | 0 | vty_out(vty, |
11758 | 0 | "%% OSPF is not enabled in vrf %s\n", |
11759 | 0 | vrf_name); |
11760 | |
|
11761 | 0 | return CMD_SUCCESS; |
11762 | 0 | } |
11763 | 0 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); |
11764 | |
|
11765 | 0 | } else { |
11766 | | /* Default Vrf */ |
11767 | 0 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
11768 | 0 | if (ospf == NULL || !ospf->oi_running) { |
11769 | 0 | if (uj) |
11770 | 0 | vty_json(vty, json); |
11771 | 0 | else |
11772 | 0 | vty_out(vty, |
11773 | 0 | "%% OSPF is not enabled in vrf default\n"); |
11774 | |
|
11775 | 0 | return CMD_SUCCESS; |
11776 | 0 | } |
11777 | | |
11778 | 0 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); |
11779 | 0 | } |
11780 | | |
11781 | 0 | if (uj) |
11782 | 0 | vty_json(vty, json); |
11783 | 0 | return CMD_SUCCESS; |
11784 | 0 | } |
11785 | | |
11786 | | static const char *const ospf_int_type_str[] = { |
11787 | | "unknown", /* should never be used. */ |
11788 | | "point-to-point", |
11789 | | "broadcast", |
11790 | | "non-broadcast", |
11791 | | "point-to-multipoint", |
11792 | | "virtual-link", /* should never be used. */ |
11793 | | "loopback" |
11794 | | }; |
11795 | | |
11796 | | static const char *interface_config_auth_str(struct ospf_if_params *params) |
11797 | 0 | { |
11798 | 0 | if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type) |
11799 | 0 | || params->auth_type == OSPF_AUTH_NOTSET) |
11800 | 0 | return NULL; |
11801 | | |
11802 | | /* Translation tables are not that much help |
11803 | | * here due to syntax |
11804 | | * of the simple option */ |
11805 | 0 | switch (params->auth_type) { |
11806 | | |
11807 | 0 | case OSPF_AUTH_NULL: |
11808 | 0 | return " null"; |
11809 | | |
11810 | 0 | case OSPF_AUTH_SIMPLE: |
11811 | 0 | return ""; |
11812 | | |
11813 | 0 | case OSPF_AUTH_CRYPTOGRAPHIC: |
11814 | 0 | return " message-digest"; |
11815 | 0 | } |
11816 | | |
11817 | 0 | return ""; |
11818 | 0 | } |
11819 | | |
11820 | | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
11821 | 0 | { |
11822 | 0 | struct listnode *node; |
11823 | 0 | struct interface *ifp; |
11824 | 0 | struct crypt_key *ck; |
11825 | 0 | struct route_node *rn = NULL; |
11826 | 0 | struct ospf_if_params *params; |
11827 | 0 | const char *auth_str; |
11828 | 0 | int write = 0; |
11829 | |
|
11830 | 0 | FOR_ALL_INTERFACES (vrf, ifp) { |
11831 | |
|
11832 | 0 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
11833 | 0 | continue; |
11834 | | |
11835 | 0 | if_vty_config_start(vty, ifp); |
11836 | |
|
11837 | 0 | if (ifp->desc) |
11838 | 0 | vty_out(vty, " description %s\n", ifp->desc); |
11839 | |
|
11840 | 0 | write++; |
11841 | |
|
11842 | 0 | params = IF_DEF_PARAMS(ifp); |
11843 | |
|
11844 | 0 | do { |
11845 | | /* Interface Network print. */ |
11846 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, type) |
11847 | 0 | && params->type != OSPF_IFTYPE_LOOPBACK) { |
11848 | 0 | if (params->type != ospf_default_iftype(ifp)) { |
11849 | 0 | vty_out(vty, " ip ospf network %s", |
11850 | 0 | ospf_int_type_str |
11851 | 0 | [params->type]); |
11852 | 0 | if (params->type |
11853 | 0 | == OSPF_IFTYPE_POINTOPOINT |
11854 | 0 | && params->ptp_dmvpn) |
11855 | 0 | vty_out(vty, " dmvpn"); |
11856 | 0 | if (params->type == |
11857 | 0 | OSPF_IFTYPE_POINTOMULTIPOINT && |
11858 | 0 | params->p2mp_delay_reflood) |
11859 | 0 | vty_out(vty, " delay-reflood"); |
11860 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11861 | 0 | vty_out(vty, " %pI4", |
11862 | 0 | &rn->p.u.prefix4); |
11863 | 0 | vty_out(vty, "\n"); |
11864 | 0 | } |
11865 | 0 | } |
11866 | | |
11867 | | /* OSPF interface authentication print */ |
11868 | 0 | auth_str = interface_config_auth_str(params); |
11869 | 0 | if (auth_str) { |
11870 | 0 | vty_out(vty, " ip ospf authentication%s", |
11871 | 0 | auth_str); |
11872 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11873 | 0 | vty_out(vty, " %pI4", |
11874 | 0 | &rn->p.u.prefix4); |
11875 | 0 | vty_out(vty, "\n"); |
11876 | 0 | } |
11877 | | |
11878 | | /* Simple Authentication Password print. */ |
11879 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) |
11880 | 0 | && params->auth_simple[0] != '\0') { |
11881 | 0 | vty_out(vty, " ip ospf authentication-key %s", |
11882 | 0 | params->auth_simple); |
11883 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11884 | 0 | vty_out(vty, " %pI4", |
11885 | 0 | &rn->p.u.prefix4); |
11886 | 0 | vty_out(vty, "\n"); |
11887 | 0 | } |
11888 | | |
11889 | | /* Cryptographic Authentication Key print. */ |
11890 | 0 | if (params && params->auth_crypt) { |
11891 | 0 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
11892 | 0 | node, ck)) { |
11893 | 0 | vty_out(vty, |
11894 | 0 | " ip ospf message-digest-key %d md5 %s", |
11895 | 0 | ck->key_id, ck->auth_key); |
11896 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11897 | 0 | vty_out(vty, " %pI4", |
11898 | 0 | &rn->p.u.prefix4); |
11899 | 0 | vty_out(vty, "\n"); |
11900 | 0 | } |
11901 | 0 | } |
11902 | | |
11903 | | /* Interface Output Cost print. */ |
11904 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
11905 | 0 | vty_out(vty, " ip ospf cost %u", |
11906 | 0 | params->output_cost_cmd); |
11907 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11908 | 0 | vty_out(vty, " %pI4", |
11909 | 0 | &rn->p.u.prefix4); |
11910 | 0 | vty_out(vty, "\n"); |
11911 | 0 | } |
11912 | | |
11913 | | /* Hello Interval print. */ |
11914 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) |
11915 | 0 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
11916 | 0 | vty_out(vty, " ip ospf hello-interval %u", |
11917 | 0 | params->v_hello); |
11918 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11919 | 0 | vty_out(vty, " %pI4", |
11920 | 0 | &rn->p.u.prefix4); |
11921 | 0 | vty_out(vty, "\n"); |
11922 | 0 | } |
11923 | | |
11924 | | |
11925 | | /* Router Dead Interval print. */ |
11926 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) |
11927 | 0 | && params->is_v_wait_set) { |
11928 | 0 | vty_out(vty, " ip ospf dead-interval "); |
11929 | | |
11930 | | /* fast hello ? */ |
11931 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, |
11932 | 0 | fast_hello)) |
11933 | 0 | vty_out(vty, |
11934 | 0 | "minimal hello-multiplier %d", |
11935 | 0 | params->fast_hello); |
11936 | 0 | else |
11937 | 0 | vty_out(vty, "%u", params->v_wait); |
11938 | |
|
11939 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11940 | 0 | vty_out(vty, " %pI4", |
11941 | 0 | &rn->p.u.prefix4); |
11942 | 0 | vty_out(vty, "\n"); |
11943 | 0 | } |
11944 | | |
11945 | | /* Hello Graceful-Restart Delay print. */ |
11946 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, |
11947 | 0 | v_gr_hello_delay) && |
11948 | 0 | params->v_gr_hello_delay != |
11949 | 0 | OSPF_HELLO_DELAY_DEFAULT) |
11950 | 0 | vty_out(vty, |
11951 | 0 | " ip ospf graceful-restart hello-delay %u\n", |
11952 | 0 | params->v_gr_hello_delay); |
11953 | | |
11954 | | /* Router Priority print. */ |
11955 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) |
11956 | 0 | && params->priority |
11957 | 0 | != OSPF_ROUTER_PRIORITY_DEFAULT) { |
11958 | 0 | vty_out(vty, " ip ospf priority %u", |
11959 | 0 | params->priority); |
11960 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11961 | 0 | vty_out(vty, " %pI4", |
11962 | 0 | &rn->p.u.prefix4); |
11963 | 0 | vty_out(vty, "\n"); |
11964 | 0 | } |
11965 | | |
11966 | | /* Retransmit Interval print. */ |
11967 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, |
11968 | 0 | retransmit_interval) |
11969 | 0 | && params->retransmit_interval |
11970 | 0 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { |
11971 | 0 | vty_out(vty, " ip ospf retransmit-interval %u", |
11972 | 0 | params->retransmit_interval); |
11973 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11974 | 0 | vty_out(vty, " %pI4", |
11975 | 0 | &rn->p.u.prefix4); |
11976 | 0 | vty_out(vty, "\n"); |
11977 | 0 | } |
11978 | | |
11979 | | /* Transmit Delay print. */ |
11980 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
11981 | 0 | && params->transmit_delay |
11982 | 0 | != OSPF_TRANSMIT_DELAY_DEFAULT) { |
11983 | 0 | vty_out(vty, " ip ospf transmit-delay %u", |
11984 | 0 | params->transmit_delay); |
11985 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11986 | 0 | vty_out(vty, " %pI4", |
11987 | 0 | &rn->p.u.prefix4); |
11988 | 0 | vty_out(vty, "\n"); |
11989 | 0 | } |
11990 | | |
11991 | | /* Area print. */ |
11992 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
11993 | 0 | if (ospf_instance) |
11994 | 0 | vty_out(vty, " ip ospf %d", |
11995 | 0 | ospf_instance); |
11996 | 0 | else |
11997 | 0 | vty_out(vty, " ip ospf"); |
11998 | |
|
11999 | 0 | char buf[INET_ADDRSTRLEN]; |
12000 | |
|
12001 | 0 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
12002 | 0 | params->if_area_id_fmt); |
12003 | 0 | vty_out(vty, " area %s", buf); |
12004 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
12005 | 0 | vty_out(vty, " %pI4", |
12006 | 0 | &rn->p.u.prefix4); |
12007 | 0 | vty_out(vty, "\n"); |
12008 | 0 | } |
12009 | | |
12010 | | /* bfd print. */ |
12011 | 0 | if (params && params->bfd_config) |
12012 | 0 | ospf_bfd_write_config(vty, params); |
12013 | | |
12014 | | /* MTU ignore print. */ |
12015 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) |
12016 | 0 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
12017 | 0 | if (params->mtu_ignore == 0) |
12018 | 0 | vty_out(vty, " no ip ospf mtu-ignore"); |
12019 | 0 | else |
12020 | 0 | vty_out(vty, " ip ospf mtu-ignore"); |
12021 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
12022 | 0 | vty_out(vty, " %pI4", |
12023 | 0 | &rn->p.u.prefix4); |
12024 | 0 | vty_out(vty, "\n"); |
12025 | 0 | } |
12026 | |
|
12027 | 0 | if (OSPF_IF_PARAM_CONFIGURED(params, |
12028 | 0 | passive_interface)) { |
12029 | 0 | vty_out(vty, " %sip ospf passive", |
12030 | 0 | params->passive_interface |
12031 | 0 | == OSPF_IF_ACTIVE |
12032 | 0 | ? "no " |
12033 | 0 | : ""); |
12034 | 0 | if (params != IF_DEF_PARAMS(ifp) && rn) |
12035 | 0 | vty_out(vty, " %pI4", &rn->p.u.prefix4); |
12036 | 0 | vty_out(vty, "\n"); |
12037 | 0 | } |
12038 | | |
12039 | | /* LDP-Sync print */ |
12040 | 0 | if (params && params->ldp_sync_info) |
12041 | 0 | ospf_ldp_sync_if_write_config(vty, params); |
12042 | |
|
12043 | 0 | while (1) { |
12044 | 0 | if (rn == NULL) |
12045 | 0 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
12046 | 0 | else |
12047 | 0 | rn = route_next(rn); |
12048 | |
|
12049 | 0 | if (rn == NULL) |
12050 | 0 | break; |
12051 | 0 | params = rn->info; |
12052 | 0 | if (params != NULL) |
12053 | 0 | break; |
12054 | 0 | } |
12055 | 0 | } while (rn); |
12056 | |
|
12057 | 0 | ospf_opaque_config_write_if(vty, ifp); |
12058 | |
|
12059 | 0 | if_vty_config_end(vty); |
12060 | 0 | } |
12061 | |
|
12062 | 0 | return write; |
12063 | 0 | } |
12064 | | |
12065 | | /* Configuration write function for ospfd. */ |
12066 | | static int config_write_interface(struct vty *vty) |
12067 | 0 | { |
12068 | 0 | int write = 0; |
12069 | 0 | struct vrf *vrf = NULL; |
12070 | | |
12071 | | /* Display all VRF aware OSPF interface configuration */ |
12072 | 0 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { |
12073 | 0 | write += config_write_interface_one(vty, vrf); |
12074 | 0 | } |
12075 | |
|
12076 | 0 | return write; |
12077 | 0 | } |
12078 | | |
12079 | | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
12080 | 0 | { |
12081 | 0 | struct route_node *rn; |
12082 | 0 | char buf[INET_ADDRSTRLEN]; |
12083 | | |
12084 | | /* `network area' print. */ |
12085 | 0 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) |
12086 | 0 | if (rn->info) { |
12087 | 0 | struct ospf_network *n = rn->info; |
12088 | | |
12089 | | /* Create Area ID string by specified Area ID format. */ |
12090 | 0 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
12091 | 0 | inet_ntop(AF_INET, &n->area_id, buf, |
12092 | 0 | sizeof(buf)); |
12093 | 0 | else |
12094 | 0 | snprintf(buf, sizeof(buf), "%lu", |
12095 | 0 | (unsigned long int)ntohl( |
12096 | 0 | n->area_id.s_addr)); |
12097 | | |
12098 | | /* Network print. */ |
12099 | 0 | vty_out(vty, " network %pFX area %s\n", &rn->p, buf); |
12100 | 0 | } |
12101 | |
|
12102 | 0 | return 0; |
12103 | 0 | } |
12104 | | |
12105 | | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
12106 | 0 | { |
12107 | 0 | struct listnode *node; |
12108 | 0 | struct ospf_area *area; |
12109 | 0 | char buf[INET_ADDRSTRLEN]; |
12110 | | |
12111 | | /* Area configuration print. */ |
12112 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
12113 | 0 | struct route_node *rn1; |
12114 | |
|
12115 | 0 | area_id2str(buf, sizeof(buf), &area->area_id, |
12116 | 0 | area->area_id_fmt); |
12117 | |
|
12118 | 0 | if (area->auth_type != OSPF_AUTH_NULL) { |
12119 | 0 | if (area->auth_type == OSPF_AUTH_SIMPLE) |
12120 | 0 | vty_out(vty, " area %s authentication\n", buf); |
12121 | 0 | else |
12122 | 0 | vty_out(vty, |
12123 | 0 | " area %s authentication message-digest\n", |
12124 | 0 | buf); |
12125 | 0 | } |
12126 | |
|
12127 | 0 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
12128 | 0 | vty_out(vty, " area %s shortcut %s\n", buf, |
12129 | 0 | ospf_shortcut_mode_str |
12130 | 0 | [area->shortcut_configured]); |
12131 | |
|
12132 | 0 | if ((area->external_routing == OSPF_AREA_STUB) |
12133 | 0 | || (area->external_routing == OSPF_AREA_NSSA)) { |
12134 | 0 | if (area->external_routing == OSPF_AREA_STUB) { |
12135 | 0 | vty_out(vty, " area %s stub", buf); |
12136 | 0 | if (area->no_summary) |
12137 | 0 | vty_out(vty, " no-summary\n"); |
12138 | 0 | vty_out(vty, "\n"); |
12139 | 0 | } else if (area->external_routing == OSPF_AREA_NSSA) { |
12140 | 0 | vty_out(vty, " area %s nssa", buf); |
12141 | |
|
12142 | 0 | switch (area->NSSATranslatorRole) { |
12143 | 0 | case OSPF_NSSA_ROLE_NEVER: |
12144 | 0 | vty_out(vty, " translate-never"); |
12145 | 0 | break; |
12146 | 0 | case OSPF_NSSA_ROLE_ALWAYS: |
12147 | 0 | vty_out(vty, " translate-always"); |
12148 | 0 | break; |
12149 | 0 | case OSPF_NSSA_ROLE_CANDIDATE: |
12150 | 0 | break; |
12151 | 0 | } |
12152 | | |
12153 | 0 | if (area->nssa_default_originate.enabled) { |
12154 | 0 | vty_out(vty, |
12155 | 0 | " default-information-originate"); |
12156 | 0 | if (area->nssa_default_originate |
12157 | 0 | .metric_value != -1) |
12158 | 0 | vty_out(vty, " metric %d", |
12159 | 0 | area->nssa_default_originate |
12160 | 0 | .metric_value); |
12161 | 0 | if (area->nssa_default_originate |
12162 | 0 | .metric_type != |
12163 | 0 | DEFAULT_METRIC_TYPE) |
12164 | 0 | vty_out(vty, " metric-type 1"); |
12165 | 0 | } |
12166 | |
|
12167 | 0 | if (area->no_summary) |
12168 | 0 | vty_out(vty, " no-summary"); |
12169 | 0 | if (area->suppress_fa) |
12170 | 0 | vty_out(vty, " suppress-fa"); |
12171 | 0 | vty_out(vty, "\n"); |
12172 | |
|
12173 | 0 | for (rn1 = route_top(area->nssa_ranges); rn1; |
12174 | 0 | rn1 = route_next(rn1)) { |
12175 | 0 | struct ospf_area_range *range; |
12176 | |
|
12177 | 0 | range = rn1->info; |
12178 | 0 | if (!range) |
12179 | 0 | continue; |
12180 | | |
12181 | 0 | vty_out(vty, " area %s nssa range %pFX", |
12182 | 0 | buf, &rn1->p); |
12183 | |
|
12184 | 0 | if (range->cost_config != |
12185 | 0 | OSPF_AREA_RANGE_COST_UNSPEC) |
12186 | 0 | vty_out(vty, " cost %u", |
12187 | 0 | range->cost_config); |
12188 | |
|
12189 | 0 | if (!CHECK_FLAG( |
12190 | 0 | range->flags, |
12191 | 0 | OSPF_AREA_RANGE_ADVERTISE)) |
12192 | 0 | vty_out(vty, " not-advertise"); |
12193 | |
|
12194 | 0 | vty_out(vty, "\n"); |
12195 | 0 | } |
12196 | 0 | } |
12197 | | |
12198 | 0 | if (area->default_cost != 1) |
12199 | 0 | vty_out(vty, " area %s default-cost %d\n", buf, |
12200 | 0 | area->default_cost); |
12201 | 0 | } |
12202 | | |
12203 | 0 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
12204 | 0 | if (rn1->info) { |
12205 | 0 | struct ospf_area_range *range = rn1->info; |
12206 | |
|
12207 | 0 | vty_out(vty, " area %s range %pFX", buf, |
12208 | 0 | &rn1->p); |
12209 | |
|
12210 | 0 | if (range->cost_config |
12211 | 0 | != OSPF_AREA_RANGE_COST_UNSPEC) |
12212 | 0 | vty_out(vty, " cost %d", |
12213 | 0 | range->cost_config); |
12214 | |
|
12215 | 0 | if (!CHECK_FLAG(range->flags, |
12216 | 0 | OSPF_AREA_RANGE_ADVERTISE)) |
12217 | 0 | vty_out(vty, " not-advertise"); |
12218 | |
|
12219 | 0 | if (CHECK_FLAG(range->flags, |
12220 | 0 | OSPF_AREA_RANGE_SUBSTITUTE)) |
12221 | 0 | vty_out(vty, " substitute %pI4/%d", |
12222 | 0 | &range->subst_addr, |
12223 | 0 | range->subst_masklen); |
12224 | |
|
12225 | 0 | vty_out(vty, "\n"); |
12226 | 0 | } |
12227 | |
|
12228 | 0 | if (EXPORT_NAME(area)) |
12229 | 0 | vty_out(vty, " area %s export-list %s\n", buf, |
12230 | 0 | EXPORT_NAME(area)); |
12231 | |
|
12232 | 0 | if (IMPORT_NAME(area)) |
12233 | 0 | vty_out(vty, " area %s import-list %s\n", buf, |
12234 | 0 | IMPORT_NAME(area)); |
12235 | |
|
12236 | 0 | if (PREFIX_NAME_IN(area)) |
12237 | 0 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, |
12238 | 0 | PREFIX_NAME_IN(area)); |
12239 | |
|
12240 | 0 | if (PREFIX_NAME_OUT(area)) |
12241 | 0 | vty_out(vty, " area %s filter-list prefix %s out\n", |
12242 | 0 | buf, PREFIX_NAME_OUT(area)); |
12243 | |
|
12244 | 0 | if (area->fr_info.configured) |
12245 | 0 | vty_out(vty, " area %s flood-reduction\n", buf); |
12246 | 0 | } |
12247 | | |
12248 | 0 | return 0; |
12249 | 0 | } |
12250 | | |
12251 | | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
12252 | 0 | { |
12253 | 0 | struct ospf_nbr_nbma *nbr_nbma; |
12254 | 0 | struct route_node *rn; |
12255 | | |
12256 | | /* Static Neighbor configuration print. */ |
12257 | 0 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) |
12258 | 0 | if ((nbr_nbma = rn->info)) { |
12259 | 0 | vty_out(vty, " neighbor %pI4", &nbr_nbma->addr); |
12260 | |
|
12261 | 0 | if (nbr_nbma->priority |
12262 | 0 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) |
12263 | 0 | vty_out(vty, " priority %d", |
12264 | 0 | nbr_nbma->priority); |
12265 | |
|
12266 | 0 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
12267 | 0 | vty_out(vty, " poll-interval %d", |
12268 | 0 | nbr_nbma->v_poll); |
12269 | |
|
12270 | 0 | vty_out(vty, "\n"); |
12271 | 0 | } |
12272 | |
|
12273 | 0 | return 0; |
12274 | 0 | } |
12275 | | |
12276 | | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) |
12277 | 0 | { |
12278 | 0 | struct listnode *node; |
12279 | 0 | struct ospf_vl_data *vl_data; |
12280 | 0 | const char *auth_str; |
12281 | 0 | char buf[INET_ADDRSTRLEN]; |
12282 | | |
12283 | | /* Virtual-Link print */ |
12284 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { |
12285 | 0 | struct listnode *n2; |
12286 | 0 | struct crypt_key *ck; |
12287 | 0 | struct ospf_interface *oi; |
12288 | |
|
12289 | 0 | if (vl_data != NULL) { |
12290 | 0 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
12291 | 0 | vl_data->vl_area_id_fmt); |
12292 | 0 | oi = vl_data->vl_oi; |
12293 | | |
12294 | | /* timers */ |
12295 | 0 | if (OSPF_IF_PARAM(oi, v_hello) |
12296 | 0 | != OSPF_HELLO_INTERVAL_DEFAULT |
12297 | 0 | || OSPF_IF_PARAM(oi, v_wait) |
12298 | 0 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT |
12299 | 0 | || OSPF_IF_PARAM(oi, retransmit_interval) |
12300 | 0 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT |
12301 | 0 | || OSPF_IF_PARAM(oi, transmit_delay) |
12302 | 0 | != OSPF_TRANSMIT_DELAY_DEFAULT) |
12303 | 0 | vty_out(vty, |
12304 | 0 | " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", |
12305 | 0 | buf, &vl_data->vl_peer, |
12306 | 0 | OSPF_IF_PARAM(oi, v_hello), |
12307 | 0 | OSPF_IF_PARAM(oi, retransmit_interval), |
12308 | 0 | OSPF_IF_PARAM(oi, transmit_delay), |
12309 | 0 | OSPF_IF_PARAM(oi, v_wait)); |
12310 | 0 | else |
12311 | 0 | vty_out(vty, " area %s virtual-link %pI4\n", buf, |
12312 | 0 | &vl_data->vl_peer); |
12313 | | /* Auth type */ |
12314 | 0 | auth_str = interface_config_auth_str( |
12315 | 0 | IF_DEF_PARAMS(oi->ifp)); |
12316 | 0 | if (auth_str) |
12317 | 0 | vty_out(vty, |
12318 | 0 | " area %s virtual-link %pI4 authentication%s\n", |
12319 | 0 | buf, &vl_data->vl_peer, auth_str); |
12320 | | /* Auth key */ |
12321 | 0 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] |
12322 | 0 | != '\0') |
12323 | 0 | vty_out(vty, |
12324 | 0 | " area %s virtual-link %pI4 authentication-key %s\n", |
12325 | 0 | buf, &vl_data->vl_peer, |
12326 | 0 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) |
12327 | 0 | ->auth_simple); |
12328 | | /* md5 keys */ |
12329 | 0 | for (ALL_LIST_ELEMENTS_RO( |
12330 | 0 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) |
12331 | 0 | ->auth_crypt, |
12332 | 0 | n2, ck)) |
12333 | 0 | vty_out(vty, |
12334 | 0 | " area %s virtual-link %pI4 message-digest-key %d md5 %s\n", |
12335 | 0 | buf, &vl_data->vl_peer, |
12336 | 0 | ck->key_id, ck->auth_key); |
12337 | 0 | } |
12338 | 0 | } |
12339 | |
|
12340 | 0 | return 0; |
12341 | 0 | } |
12342 | | |
12343 | | |
12344 | | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
12345 | 0 | { |
12346 | 0 | int type; |
12347 | | |
12348 | | /* redistribute print. */ |
12349 | 0 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { |
12350 | 0 | struct list *red_list; |
12351 | 0 | struct listnode *node; |
12352 | 0 | struct ospf_redist *red; |
12353 | |
|
12354 | 0 | red_list = ospf->redist[type]; |
12355 | 0 | if (!red_list) |
12356 | 0 | continue; |
12357 | | |
12358 | 0 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
12359 | 0 | vty_out(vty, " redistribute %s", |
12360 | 0 | zebra_route_string(type)); |
12361 | 0 | if (red->instance) |
12362 | 0 | vty_out(vty, " %d", red->instance); |
12363 | |
|
12364 | 0 | if (red->dmetric.value >= 0) |
12365 | 0 | vty_out(vty, " metric %d", red->dmetric.value); |
12366 | |
|
12367 | 0 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12368 | 0 | vty_out(vty, " metric-type 1"); |
12369 | |
|
12370 | 0 | if (ROUTEMAP_NAME(red)) |
12371 | 0 | vty_out(vty, " route-map %s", |
12372 | 0 | ROUTEMAP_NAME(red)); |
12373 | |
|
12374 | 0 | vty_out(vty, "\n"); |
12375 | 0 | } |
12376 | 0 | } |
12377 | |
|
12378 | 0 | return 0; |
12379 | 0 | } |
12380 | | |
12381 | | static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
12382 | | void *arg) |
12383 | 0 | { |
12384 | 0 | struct advRtr *rtr = bucket->data; |
12385 | 0 | struct vty *vty = (struct vty *)arg; |
12386 | |
|
12387 | 0 | vty_out(vty, " graceful-restart helper enable %pI4\n", |
12388 | 0 | &rtr->advRtrAddr); |
12389 | 0 | return HASHWALK_CONTINUE; |
12390 | 0 | } |
12391 | | |
12392 | | static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf) |
12393 | 0 | { |
12394 | 0 | if (!ospf->gr_info.restart_support) |
12395 | 0 | return; |
12396 | | |
12397 | 0 | if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL) |
12398 | 0 | vty_out(vty, " graceful-restart\n"); |
12399 | 0 | else |
12400 | 0 | vty_out(vty, " graceful-restart grace-period %u\n", |
12401 | 0 | ospf->gr_info.grace_period); |
12402 | 0 | } |
12403 | | |
12404 | | static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf) |
12405 | 0 | { |
12406 | 0 | if (ospf->is_helper_supported) |
12407 | 0 | vty_out(vty, " graceful-restart helper enable\n"); |
12408 | |
|
12409 | 0 | if (!ospf->strict_lsa_check) |
12410 | 0 | vty_out(vty, |
12411 | 0 | " no graceful-restart helper strict-lsa-checking\n"); |
12412 | |
|
12413 | 0 | if (ospf->only_planned_restart) |
12414 | 0 | vty_out(vty, " graceful-restart helper planned-only\n"); |
12415 | |
|
12416 | 0 | if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL) |
12417 | 0 | vty_out(vty, |
12418 | 0 | " graceful-restart helper supported-grace-time %d\n", |
12419 | 0 | ospf->supported_grace_time); |
12420 | |
|
12421 | 0 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { |
12422 | 0 | hash_walk(ospf->enable_rtr_list, |
12423 | 0 | ospf_cfg_write_helper_dis_rtr_walkcb, vty); |
12424 | 0 | } |
12425 | 0 | return 0; |
12426 | 0 | } |
12427 | | |
12428 | | static int config_write_ospf_external_aggregator(struct vty *vty, |
12429 | | struct ospf *ospf) |
12430 | 0 | { |
12431 | 0 | struct route_node *rn; |
12432 | |
|
12433 | 0 | if (ospf->aggr_delay_interval != OSPF_EXTL_AGGR_DEFAULT_DELAY) |
12434 | 0 | vty_out(vty, " aggregation timer %u\n", |
12435 | 0 | ospf->aggr_delay_interval); |
12436 | | |
12437 | | /* print 'summary-address A.B.C.D/M' */ |
12438 | 0 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) |
12439 | 0 | if (rn->info) { |
12440 | 0 | struct ospf_external_aggr_rt *aggr = rn->info; |
12441 | |
|
12442 | 0 | vty_out(vty, " summary-address %pI4/%d", |
12443 | 0 | &aggr->p.prefix, aggr->p.prefixlen); |
12444 | 0 | if (aggr->tag) |
12445 | 0 | vty_out(vty, " tag %u", aggr->tag); |
12446 | |
|
12447 | 0 | if (CHECK_FLAG(aggr->flags, |
12448 | 0 | OSPF_EXTERNAL_AGGRT_NO_ADVERTISE)) |
12449 | 0 | vty_out(vty, " no-advertise"); |
12450 | |
|
12451 | 0 | vty_out(vty, "\n"); |
12452 | 0 | } |
12453 | |
|
12454 | 0 | return 0; |
12455 | 0 | } |
12456 | | |
12457 | | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
12458 | 0 | { |
12459 | 0 | if (ospf->default_metric != -1) |
12460 | 0 | vty_out(vty, " default-metric %d\n", ospf->default_metric); |
12461 | 0 | return 0; |
12462 | 0 | } |
12463 | | |
12464 | | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
12465 | 0 | { |
12466 | 0 | int type; |
12467 | 0 | struct ospf_redist *red; |
12468 | |
|
12469 | 0 | if (ospf) { |
12470 | | /* distribute-list print. */ |
12471 | 0 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) |
12472 | 0 | if (DISTRIBUTE_NAME(ospf, type)) |
12473 | 0 | vty_out(vty, " distribute-list %s out %s\n", |
12474 | 0 | DISTRIBUTE_NAME(ospf, type), |
12475 | 0 | zebra_route_string(type)); |
12476 | | |
12477 | | /* default-information print. */ |
12478 | 0 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { |
12479 | 0 | vty_out(vty, " default-information originate"); |
12480 | 0 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) |
12481 | 0 | vty_out(vty, " always"); |
12482 | |
|
12483 | 0 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
12484 | 0 | if (red) { |
12485 | 0 | if (red->dmetric.value >= 0) |
12486 | 0 | vty_out(vty, " metric %d", |
12487 | 0 | red->dmetric.value); |
12488 | |
|
12489 | 0 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12490 | 0 | vty_out(vty, " metric-type 1"); |
12491 | |
|
12492 | 0 | if (ROUTEMAP_NAME(red)) |
12493 | 0 | vty_out(vty, " route-map %s", |
12494 | 0 | ROUTEMAP_NAME(red)); |
12495 | 0 | } |
12496 | |
|
12497 | 0 | vty_out(vty, "\n"); |
12498 | 0 | } |
12499 | 0 | } |
12500 | |
|
12501 | 0 | return 0; |
12502 | 0 | } |
12503 | | |
12504 | | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
12505 | 0 | { |
12506 | 0 | struct route_node *rn; |
12507 | 0 | struct ospf_distance *odistance; |
12508 | |
|
12509 | 0 | if (ospf->distance_all) |
12510 | 0 | vty_out(vty, " distance %d\n", ospf->distance_all); |
12511 | |
|
12512 | 0 | if (ospf->distance_intra || ospf->distance_inter |
12513 | 0 | || ospf->distance_external) { |
12514 | 0 | vty_out(vty, " distance ospf"); |
12515 | |
|
12516 | 0 | if (ospf->distance_intra) |
12517 | 0 | vty_out(vty, " intra-area %d", ospf->distance_intra); |
12518 | 0 | if (ospf->distance_inter) |
12519 | 0 | vty_out(vty, " inter-area %d", ospf->distance_inter); |
12520 | 0 | if (ospf->distance_external) |
12521 | 0 | vty_out(vty, " external %d", ospf->distance_external); |
12522 | |
|
12523 | 0 | vty_out(vty, "\n"); |
12524 | 0 | } |
12525 | |
|
12526 | 0 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) |
12527 | 0 | if ((odistance = rn->info) != NULL) { |
12528 | 0 | vty_out(vty, " distance %d %pFX %s\n", |
12529 | 0 | odistance->distance, &rn->p, |
12530 | 0 | odistance->access_list ? odistance->access_list |
12531 | 0 | : ""); |
12532 | 0 | } |
12533 | 0 | return 0; |
12534 | 0 | } |
12535 | | |
12536 | | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
12537 | 0 | { |
12538 | 0 | int write = 0; |
12539 | | |
12540 | | /* `router ospf' print. */ |
12541 | 0 | if (ospf->instance && strcmp(ospf->name, VRF_DEFAULT_NAME)) { |
12542 | 0 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
12543 | 0 | ospf->name); |
12544 | 0 | } else if (ospf->instance) { |
12545 | 0 | vty_out(vty, "router ospf %d\n", ospf->instance); |
12546 | 0 | } else if (strcmp(ospf->name, VRF_DEFAULT_NAME)) { |
12547 | 0 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
12548 | 0 | } else |
12549 | 0 | vty_out(vty, "router ospf\n"); |
12550 | |
|
12551 | 0 | if (!ospf->networks) { |
12552 | 0 | write++; |
12553 | 0 | return write; |
12554 | 0 | } |
12555 | | |
12556 | | /* Router ID print. */ |
12557 | 0 | if (ospf->router_id_static.s_addr != INADDR_ANY) |
12558 | 0 | vty_out(vty, " ospf router-id %pI4\n", |
12559 | 0 | &ospf->router_id_static); |
12560 | | |
12561 | | /* zebra opaque attributes configuration. */ |
12562 | 0 | if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) |
12563 | 0 | vty_out(vty, " ospf send-extra-data zebra\n"); |
12564 | | |
12565 | | /* ABR type print. */ |
12566 | 0 | if (ospf->abr_type != OSPF_ABR_DEFAULT) |
12567 | 0 | vty_out(vty, " ospf abr-type %s\n", |
12568 | 0 | ospf_abr_type_str[ospf->abr_type]); |
12569 | | |
12570 | | /* log-adjacency-changes flag print. */ |
12571 | 0 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { |
12572 | 0 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) |
12573 | 0 | vty_out(vty, " log-adjacency-changes detail\n"); |
12574 | 0 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
12575 | 0 | vty_out(vty, " log-adjacency-changes\n"); |
12576 | 0 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
12577 | 0 | vty_out(vty, " no log-adjacency-changes\n"); |
12578 | 0 | } |
12579 | | |
12580 | | /* RFC1583 compatibility flag print -- Compatible with CISCO |
12581 | | * 12.1. */ |
12582 | 0 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) |
12583 | 0 | vty_out(vty, " compatible rfc1583\n"); |
12584 | | |
12585 | | /* auto-cost reference-bandwidth configuration. */ |
12586 | 0 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { |
12587 | 0 | vty_out(vty, |
12588 | 0 | "! Important: ensure reference bandwidth is consistent across all routers\n"); |
12589 | 0 | vty_out(vty, " auto-cost reference-bandwidth %d\n", |
12590 | 0 | ospf->ref_bandwidth); |
12591 | 0 | } |
12592 | | |
12593 | | /* SPF timers print. */ |
12594 | 0 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT |
12595 | 0 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT |
12596 | 0 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) |
12597 | 0 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
12598 | 0 | ospf->spf_holdtime, ospf->spf_max_holdtime); |
12599 | | |
12600 | | /* LSA timers print. */ |
12601 | 0 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) |
12602 | 0 | vty_out(vty, " timers throttle lsa all %d\n", |
12603 | 0 | ospf->min_ls_interval); |
12604 | 0 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) |
12605 | 0 | vty_out(vty, " timers lsa min-arrival %d\n", |
12606 | 0 | ospf->min_ls_arrival); |
12607 | | |
12608 | | /* Write multiplier print. */ |
12609 | 0 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) |
12610 | 0 | vty_out(vty, " ospf write-multiplier %d\n", |
12611 | 0 | ospf->write_oi_count); |
12612 | |
|
12613 | 0 | if (ospf->max_multipath != MULTIPATH_NUM) |
12614 | 0 | vty_out(vty, " maximum-paths %d\n", ospf->max_multipath); |
12615 | | |
12616 | | /* Max-metric router-lsa print */ |
12617 | 0 | config_write_stub_router(vty, ospf); |
12618 | | |
12619 | | /* SPF refresh parameters print. */ |
12620 | 0 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
12621 | 0 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); |
12622 | |
|
12623 | 0 | if (ospf->fr_configured) |
12624 | 0 | vty_out(vty, " flood-reduction\n"); |
12625 | |
|
12626 | 0 | if (!ospf->intf_socket_enabled) |
12627 | 0 | vty_out(vty, " no socket-per-interface\n"); |
12628 | | |
12629 | | /* Redistribute information print. */ |
12630 | 0 | config_write_ospf_redistribute(vty, ospf); |
12631 | | |
12632 | | /* Graceful Restart print */ |
12633 | 0 | config_write_ospf_gr(vty, ospf); |
12634 | 0 | config_write_ospf_gr_helper(vty, ospf); |
12635 | | |
12636 | | /* Print external route aggregation. */ |
12637 | 0 | config_write_ospf_external_aggregator(vty, ospf); |
12638 | | |
12639 | | /* passive-interface print. */ |
12640 | 0 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) |
12641 | 0 | vty_out(vty, " passive-interface default\n"); |
12642 | | |
12643 | | /* proactive-arp print. */ |
12644 | 0 | if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) { |
12645 | 0 | if (ospf->proactive_arp) |
12646 | 0 | vty_out(vty, " proactive-arp\n"); |
12647 | 0 | else |
12648 | 0 | vty_out(vty, " no proactive-arp\n"); |
12649 | 0 | } |
12650 | | |
12651 | | /* TI-LFA print. */ |
12652 | 0 | if (ospf->ti_lfa_enabled) { |
12653 | 0 | if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION) |
12654 | 0 | vty_out(vty, " fast-reroute ti-lfa node-protection\n"); |
12655 | 0 | else |
12656 | 0 | vty_out(vty, " fast-reroute ti-lfa\n"); |
12657 | 0 | } |
12658 | | |
12659 | | /* Network area print. */ |
12660 | 0 | config_write_network_area(vty, ospf); |
12661 | | |
12662 | | /* Area config print. */ |
12663 | 0 | config_write_ospf_area(vty, ospf); |
12664 | | |
12665 | | /* static neighbor print. */ |
12666 | 0 | config_write_ospf_nbr_nbma(vty, ospf); |
12667 | | |
12668 | | /* Virtual-Link print. */ |
12669 | 0 | config_write_virtual_link(vty, ospf); |
12670 | | |
12671 | | /* Default metric configuration. */ |
12672 | 0 | config_write_ospf_default_metric(vty, ospf); |
12673 | | |
12674 | | /* Distribute-list and default-information print. */ |
12675 | 0 | config_write_ospf_distribute(vty, ospf); |
12676 | | |
12677 | | /* Distance configuration. */ |
12678 | 0 | config_write_ospf_distance(vty, ospf); |
12679 | |
|
12680 | 0 | ospf_opaque_config_write_router(vty, ospf); |
12681 | | |
12682 | | /* LDP-Sync print */ |
12683 | 0 | ospf_ldp_sync_write_config(vty, ospf); |
12684 | | |
12685 | | /* Socket buffer sizes */ |
12686 | 0 | if (ospf->recv_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE) { |
12687 | 0 | if (ospf->send_sock_bufsize == ospf->recv_sock_bufsize) |
12688 | 0 | vty_out(vty, " socket buffer all %u\n", |
12689 | 0 | ospf->recv_sock_bufsize); |
12690 | 0 | else |
12691 | 0 | vty_out(vty, " socket buffer recv %u\n", |
12692 | 0 | ospf->recv_sock_bufsize); |
12693 | 0 | } |
12694 | |
|
12695 | 0 | if (ospf->send_sock_bufsize != OSPF_DEFAULT_SOCK_BUFSIZE && |
12696 | 0 | ospf->send_sock_bufsize != ospf->recv_sock_bufsize) |
12697 | 0 | vty_out(vty, " socket buffer send %u\n", |
12698 | 0 | ospf->send_sock_bufsize); |
12699 | | |
12700 | |
|
12701 | 0 | vty_out(vty, "exit\n"); |
12702 | |
|
12703 | 0 | write++; |
12704 | 0 | return write; |
12705 | 0 | } |
12706 | | |
12707 | | /* OSPF configuration write function. */ |
12708 | | static int ospf_config_write(struct vty *vty) |
12709 | 0 | { |
12710 | 0 | struct ospf *ospf; |
12711 | 0 | struct listnode *ospf_node = NULL; |
12712 | 0 | int write = 0; |
12713 | |
|
12714 | 0 | if (listcount(om->ospf) == 0) |
12715 | 0 | return write; |
12716 | | |
12717 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { |
12718 | | /* VRF Default check if it is running. |
12719 | | * Upon daemon start, there could be default instance |
12720 | | * in absence of 'router ospf'/oi_running is disabled. */ |
12721 | 0 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) |
12722 | 0 | write += ospf_config_write_one(vty, ospf); |
12723 | | /* For Non-Default VRF simply display the configuration, |
12724 | | * even if it is not oi_running. */ |
12725 | 0 | else if (ospf->vrf_id != VRF_DEFAULT) |
12726 | 0 | write += ospf_config_write_one(vty, ospf); |
12727 | 0 | } |
12728 | 0 | return write; |
12729 | 0 | } |
12730 | | |
12731 | | void ospf_vty_show_init(void) |
12732 | 0 | { |
12733 | | /* "show ip ospf" commands. */ |
12734 | 0 | install_element(VIEW_NODE, &show_ip_ospf_cmd); |
12735 | |
|
12736 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); |
12737 | | |
12738 | | /* "show ip ospf database" commands. */ |
12739 | 0 | install_element(VIEW_NODE, &show_ip_ospf_database_cmd); |
12740 | | |
12741 | | /* "show ip ospf interface" commands. */ |
12742 | 0 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); |
12743 | |
|
12744 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); |
12745 | | /* "show ip ospf interface traffic */ |
12746 | 0 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); |
12747 | | |
12748 | | /* "show ip ospf neighbor" commands. */ |
12749 | 0 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); |
12750 | 0 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); |
12751 | 0 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); |
12752 | 0 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); |
12753 | 0 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); |
12754 | 0 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); |
12755 | 0 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); |
12756 | |
|
12757 | 0 | install_element(VIEW_NODE, |
12758 | 0 | &show_ip_ospf_instance_neighbor_int_detail_cmd); |
12759 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); |
12760 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); |
12761 | 0 | install_element(VIEW_NODE, |
12762 | 0 | &show_ip_ospf_instance_neighbor_detail_all_cmd); |
12763 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); |
12764 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); |
12765 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); |
12766 | | |
12767 | | /* "show ip ospf route" commands. */ |
12768 | 0 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); |
12769 | 0 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); |
12770 | 0 | install_element(VIEW_NODE, &show_ip_ospf_reachable_routers_cmd); |
12771 | |
|
12772 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); |
12773 | 0 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); |
12774 | 0 | install_element(VIEW_NODE, |
12775 | 0 | &show_ip_ospf_instance_reachable_routers_cmd); |
12776 | | |
12777 | | /* "show ip ospf vrfs" commands. */ |
12778 | 0 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); |
12779 | | |
12780 | | /* "show ip ospf gr-helper details" command */ |
12781 | 0 | install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd); |
12782 | | |
12783 | | /* "show ip ospf summary-address" command */ |
12784 | 0 | install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd); |
12785 | 0 | } |
12786 | | |
12787 | | /* Initialization of OSPF interface. */ |
12788 | | static void ospf_vty_if_init(void) |
12789 | 0 | { |
12790 | | /* Install interface node. */ |
12791 | 0 | if_cmd_init(config_write_interface); |
12792 | | |
12793 | | /* "ip ospf authentication" commands. */ |
12794 | 0 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); |
12795 | 0 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); |
12796 | 0 | install_element(INTERFACE_NODE, |
12797 | 0 | &no_ip_ospf_authentication_args_addr_cmd); |
12798 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); |
12799 | 0 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); |
12800 | 0 | install_element(INTERFACE_NODE, |
12801 | 0 | &no_ip_ospf_authentication_key_authkey_addr_cmd); |
12802 | 0 | install_element(INTERFACE_NODE, |
12803 | 0 | &no_ospf_authentication_key_authkey_addr_cmd); |
12804 | | |
12805 | | /* "ip ospf message-digest-key" commands. */ |
12806 | 0 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); |
12807 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); |
12808 | | |
12809 | | /* "ip ospf cost" commands. */ |
12810 | 0 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); |
12811 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); |
12812 | | |
12813 | | /* "ip ospf mtu-ignore" commands. */ |
12814 | 0 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); |
12815 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); |
12816 | | |
12817 | | /* "ip ospf dead-interval" commands. */ |
12818 | 0 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); |
12819 | 0 | install_element(INTERFACE_NODE, |
12820 | 0 | &ip_ospf_dead_interval_minimal_addr_cmd); |
12821 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); |
12822 | | |
12823 | | /* "ip ospf hello-interval" commands. */ |
12824 | 0 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); |
12825 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); |
12826 | | |
12827 | | /* "ip ospf network" commands. */ |
12828 | 0 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); |
12829 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); |
12830 | | |
12831 | | /* "ip ospf priority" commands. */ |
12832 | 0 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); |
12833 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); |
12834 | | |
12835 | | /* "ip ospf retransmit-interval" commands. */ |
12836 | 0 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); |
12837 | 0 | install_element(INTERFACE_NODE, |
12838 | 0 | &no_ip_ospf_retransmit_interval_addr_cmd); |
12839 | | |
12840 | | /* "ip ospf transmit-delay" commands. */ |
12841 | 0 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); |
12842 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); |
12843 | | |
12844 | | /* "ip ospf area" commands. */ |
12845 | 0 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); |
12846 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); |
12847 | | |
12848 | | /* "ip ospf passive" commands. */ |
12849 | 0 | install_element(INTERFACE_NODE, &ip_ospf_passive_cmd); |
12850 | 0 | install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd); |
12851 | | |
12852 | | /* These commands are compatibitliy for previous version. */ |
12853 | 0 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); |
12854 | 0 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); |
12855 | 0 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); |
12856 | 0 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); |
12857 | 0 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); |
12858 | 0 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); |
12859 | 0 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); |
12860 | 0 | install_element(INTERFACE_NODE, &ospf_cost_cmd); |
12861 | 0 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); |
12862 | 0 | install_element(INTERFACE_NODE, &ospf_network_cmd); |
12863 | 0 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); |
12864 | 0 | install_element(INTERFACE_NODE, &ospf_priority_cmd); |
12865 | 0 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); |
12866 | 0 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); |
12867 | 0 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); |
12868 | 0 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); |
12869 | 0 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); |
12870 | 0 | } |
12871 | | |
12872 | | static void ospf_vty_zebra_init(void) |
12873 | 0 | { |
12874 | 0 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); |
12875 | 0 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); |
12876 | 0 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); |
12877 | 0 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); |
12878 | |
|
12879 | 0 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); |
12880 | 0 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); |
12881 | |
|
12882 | 0 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); |
12883 | 0 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); |
12884 | |
|
12885 | 0 | install_element(OSPF_NODE, &ospf_default_metric_cmd); |
12886 | 0 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); |
12887 | |
|
12888 | 0 | install_element(OSPF_NODE, &ospf_distance_cmd); |
12889 | 0 | install_element(OSPF_NODE, &no_ospf_distance_cmd); |
12890 | 0 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); |
12891 | 0 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); |
12892 | | |
12893 | | /*Ospf garcefull restart helper configurations */ |
12894 | 0 | install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd); |
12895 | 0 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd); |
12896 | 0 | install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd); |
12897 | 0 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd); |
12898 | 0 | install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd); |
12899 | 0 | install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd); |
12900 | 0 | install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd); |
12901 | 0 | install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd); |
12902 | | |
12903 | | /* External LSA summarisation config commands.*/ |
12904 | 0 | install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd); |
12905 | 0 | install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd); |
12906 | 0 | install_element(OSPF_NODE, |
12907 | 0 | &ospf_external_route_aggregation_no_adrvertise_cmd); |
12908 | 0 | install_element(OSPF_NODE, |
12909 | 0 | &no_ospf_external_route_aggregation_no_adrvertise_cmd); |
12910 | 0 | install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd); |
12911 | 0 | install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd); |
12912 | 0 | } |
12913 | | |
12914 | | static int ospf_config_write(struct vty *vty); |
12915 | | static struct cmd_node ospf_node = { |
12916 | | .name = "ospf", |
12917 | | .node = OSPF_NODE, |
12918 | | .parent_node = CONFIG_NODE, |
12919 | | .prompt = "%s(config-router)# ", |
12920 | | .config_write = ospf_config_write, |
12921 | | }; |
12922 | | |
12923 | | static void ospf_interface_clear(struct interface *ifp) |
12924 | 0 | { |
12925 | 0 | if (!if_is_operative(ifp)) |
12926 | 0 | return; |
12927 | | |
12928 | 0 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
12929 | 0 | zlog_debug("ISM[%s]: clear by reset", ifp->name); |
12930 | |
|
12931 | 0 | ospf_if_reset(ifp); |
12932 | 0 | } |
12933 | | |
12934 | | DEFUN (clear_ip_ospf_interface, |
12935 | | clear_ip_ospf_interface_cmd, |
12936 | | "clear ip ospf [vrf NAME] interface [IFNAME]", |
12937 | | CLEAR_STR |
12938 | | IP_STR |
12939 | | "OSPF information\n" |
12940 | | VRF_CMD_HELP_STR |
12941 | | "Interface information\n" |
12942 | | "Interface name\n") |
12943 | 0 | { |
12944 | 0 | int idx_ifname = 0; |
12945 | 0 | int idx_vrf = 0; |
12946 | 0 | struct interface *ifp; |
12947 | 0 | struct listnode *node; |
12948 | 0 | struct ospf *ospf = NULL; |
12949 | 0 | char *vrf_name = NULL; |
12950 | 0 | vrf_id_t vrf_id = VRF_DEFAULT; |
12951 | 0 | struct vrf *vrf = NULL; |
12952 | |
|
12953 | 0 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
12954 | 0 | vrf_name = argv[idx_vrf + 1]->arg; |
12955 | 0 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) |
12956 | 0 | vrf_name = NULL; |
12957 | 0 | if (vrf_name) { |
12958 | 0 | vrf = vrf_lookup_by_name(vrf_name); |
12959 | 0 | if (vrf) |
12960 | 0 | vrf_id = vrf->vrf_id; |
12961 | 0 | } |
12962 | 0 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { |
12963 | | /* Clear all the ospfv2 interfaces. */ |
12964 | 0 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
12965 | 0 | if (vrf_id != ospf->vrf_id) |
12966 | 0 | continue; |
12967 | 0 | if (!vrf) |
12968 | 0 | vrf = vrf_lookup_by_id(ospf->vrf_id); |
12969 | 0 | FOR_ALL_INTERFACES (vrf, ifp) |
12970 | 0 | ospf_interface_clear(ifp); |
12971 | 0 | } |
12972 | 0 | } else { |
12973 | | /* Interface name is specified. */ |
12974 | 0 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
12975 | 0 | if (ifp == NULL) |
12976 | 0 | vty_out(vty, "No such interface name\n"); |
12977 | 0 | else |
12978 | 0 | ospf_interface_clear(ifp); |
12979 | 0 | } |
12980 | |
|
12981 | 0 | return CMD_SUCCESS; |
12982 | 0 | } |
12983 | | |
12984 | | DEFPY_HIDDEN(ospf_lsa_refresh_timer, ospf_lsa_refresh_timer_cmd, |
12985 | | "[no$no] ospf lsa-refresh [(120-1800)]$value", |
12986 | | NO_STR OSPF_STR |
12987 | | "OSPF lsa refresh timer\n" |
12988 | | "timer value in seconds\n") |
12989 | 0 | { |
12990 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf) |
12991 | |
|
12992 | 0 | if (no) |
12993 | 0 | ospf->lsa_refresh_timer = OSPF_LS_REFRESH_TIME; |
12994 | 0 | else |
12995 | 0 | ospf->lsa_refresh_timer = value; |
12996 | |
|
12997 | 0 | return CMD_SUCCESS; |
12998 | 0 | } |
12999 | | |
13000 | | DEFPY_HIDDEN(ospf_maxage_delay_timer, ospf_maxage_delay_timer_cmd, |
13001 | | "[no$no] ospf maxage-delay [(0-60)]$value", |
13002 | | NO_STR OSPF_STR |
13003 | | "OSPF lsa maxage delay timer\n" |
13004 | | "timer value in seconds\n") |
13005 | 0 | { |
13006 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf) |
13007 | |
|
13008 | 0 | if (no) |
13009 | 0 | ospf->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT; |
13010 | 0 | else |
13011 | 0 | ospf->maxage_delay = value; |
13012 | |
|
13013 | 0 | EVENT_OFF(ospf->t_maxage); |
13014 | 0 | OSPF_TIMER_ON(ospf->t_maxage, ospf_maxage_lsa_remover, |
13015 | 0 | ospf->maxage_delay); |
13016 | |
|
13017 | 0 | return CMD_SUCCESS; |
13018 | 0 | } |
13019 | | |
13020 | | /* |
13021 | | * ------------------------------------------------------------------------* |
13022 | | * Following is (vty) configuration functions for flood-reduction handling. |
13023 | | * ------------------------------------------------------------------------ |
13024 | | */ |
13025 | | |
13026 | | DEFPY(flood_reduction, flood_reduction_cmd, "flood-reduction", |
13027 | | "flood reduction feature\n") |
13028 | 0 | { |
13029 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf) |
13030 | 0 | struct ospf_area *area; |
13031 | 0 | struct listnode *node; |
13032 | | |
13033 | | /* Turn on the Flood Reduction feature for the router. */ |
13034 | 0 | if (!ospf->fr_configured) { |
13035 | 0 | ospf->fr_configured = true; |
13036 | 0 | OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT, |
13037 | 0 | "Flood Reduction: OFF -> ON"); |
13038 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
13039 | 0 | if (area) { |
13040 | 0 | ospf_area_update_fr_state(area); |
13041 | 0 | ospf_refresh_area_self_lsas(area); |
13042 | 0 | } |
13043 | 0 | } |
13044 | 0 | } |
13045 | |
|
13046 | 0 | return CMD_SUCCESS; |
13047 | 0 | } |
13048 | | |
13049 | | DEFPY(flood_reduction_area, flood_reduction_area_cmd, |
13050 | | "area <A.B.C.D|(0-4294967295)> flood-reduction", |
13051 | | "OSPF area parameters\n" |
13052 | | "OSPF area ID in IP address format\n" |
13053 | | "OSPF area ID as a decimal value\n" |
13054 | | "Enable flood reduction for area\n") |
13055 | 0 | { |
13056 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf) |
13057 | 0 | struct ospf_area *oa; |
13058 | 0 | int idx = 1; |
13059 | 0 | int format; |
13060 | 0 | int ret; |
13061 | 0 | const char *areaid; |
13062 | 0 | struct in_addr area_id; |
13063 | |
|
13064 | 0 | areaid = argv[idx]->arg; |
13065 | |
|
13066 | 0 | ret = str2area_id(areaid, &area_id, &format); |
13067 | 0 | if (ret < 0) { |
13068 | 0 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); |
13069 | 0 | return CMD_WARNING_CONFIG_FAILED; |
13070 | 0 | } |
13071 | | |
13072 | 0 | oa = ospf_area_lookup_by_area_id(ospf, area_id); |
13073 | 0 | if (!oa) { |
13074 | 0 | vty_out(vty, "OSPF area ID not present\n"); |
13075 | 0 | return CMD_WARNING_CONFIG_FAILED; |
13076 | 0 | } |
13077 | | |
13078 | | /* Turn on the Flood Reduction feature for the area. */ |
13079 | 0 | if (!oa->fr_info.configured) { |
13080 | 0 | oa->fr_info.configured = true; |
13081 | 0 | OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT, |
13082 | 0 | "Flood Reduction area %pI4 : OFF -> ON", |
13083 | 0 | &oa->area_id); |
13084 | 0 | ospf_area_update_fr_state(oa); |
13085 | 0 | ospf_refresh_area_self_lsas(oa); |
13086 | 0 | } |
13087 | |
|
13088 | 0 | return CMD_SUCCESS; |
13089 | 0 | } |
13090 | | |
13091 | | DEFPY(no_flood_reduction, no_flood_reduction_cmd, "no flood-reduction", |
13092 | | NO_STR "flood reduction feature\n") |
13093 | 0 | { |
13094 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf) |
13095 | 0 | struct listnode *node; |
13096 | 0 | struct ospf_area *area; |
13097 | | |
13098 | | /* Turn off the Flood Reduction feature for the router. */ |
13099 | 0 | if (ospf->fr_configured) { |
13100 | 0 | ospf->fr_configured = false; |
13101 | 0 | OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT, |
13102 | 0 | "Flood Reduction: ON -> OFF"); |
13103 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
13104 | 0 | if (area) { |
13105 | 0 | ospf_area_update_fr_state(area); |
13106 | 0 | ospf_refresh_area_self_lsas(area); |
13107 | 0 | } |
13108 | 0 | } |
13109 | 0 | } |
13110 | |
|
13111 | 0 | return CMD_SUCCESS; |
13112 | 0 | } |
13113 | | |
13114 | | DEFPY(no_flood_reduction_area, no_flood_reduction_area_cmd, |
13115 | | "no area <A.B.C.D|(0-4294967295)> flood-reduction", |
13116 | | NO_STR |
13117 | | "OSPF area parameters\n" |
13118 | | "OSPF area ID in IP address format\n" |
13119 | | "OSPF area ID as a decimal value\n" |
13120 | | "Disable flood reduction for area\n") |
13121 | 0 | { |
13122 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf) |
13123 | 0 | struct ospf_area *oa; |
13124 | 0 | int idx = 2; |
13125 | 0 | int format; |
13126 | 0 | int ret; |
13127 | 0 | const char *areaid; |
13128 | 0 | struct in_addr area_id; |
13129 | |
|
13130 | 0 | areaid = argv[idx]->arg; |
13131 | |
|
13132 | 0 | ret = str2area_id(areaid, &area_id, &format); |
13133 | 0 | if (ret < 0) { |
13134 | 0 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); |
13135 | 0 | return CMD_WARNING_CONFIG_FAILED; |
13136 | 0 | } |
13137 | | |
13138 | 0 | oa = ospf_area_lookup_by_area_id(ospf, area_id); |
13139 | 0 | if (!oa) { |
13140 | 0 | vty_out(vty, "OSPF area ID not present\n"); |
13141 | 0 | return CMD_WARNING_CONFIG_FAILED; |
13142 | 0 | } |
13143 | | |
13144 | | /* Turn off the Flood Reduction feature for the area. */ |
13145 | 0 | if (oa->fr_info.configured) { |
13146 | 0 | oa->fr_info.configured = false; |
13147 | 0 | OSPF_LOG_DEBUG(IS_DEBUG_OSPF_EVENT, |
13148 | 0 | "Flood Reduction area %pI4 : ON -> OFF", |
13149 | 0 | &oa->area_id); |
13150 | 0 | ospf_area_update_fr_state(oa); |
13151 | 0 | ospf_refresh_area_self_lsas(oa); |
13152 | 0 | } |
13153 | |
|
13154 | 0 | return CMD_SUCCESS; |
13155 | 0 | } |
13156 | | |
13157 | | DEFPY(ospf_socket_bufsizes, |
13158 | | ospf_socket_bufsizes_cmd, |
13159 | | "[no] socket buffer <send$send_val | recv$recv_val | all$all_val> \ |
13160 | | ![(1-4000000000)$bufsize]", |
13161 | | NO_STR |
13162 | | "Socket parameters\n" |
13163 | | "Buffer size configuration\n" |
13164 | | "Send buffer size\n" |
13165 | | "Receive buffer size\n" |
13166 | | "Both send and receive buffer sizes\n" |
13167 | | "Buffer size, in bytes\n") |
13168 | 0 | { |
13169 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
13170 | 0 | uint32_t recvsz, sendsz; |
13171 | |
|
13172 | 0 | if (no) |
13173 | 0 | bufsize = OSPF_DEFAULT_SOCK_BUFSIZE; |
13174 | |
|
13175 | 0 | if (all_val) { |
13176 | 0 | recvsz = bufsize; |
13177 | 0 | sendsz = bufsize; |
13178 | 0 | } else if (send_val) { |
13179 | 0 | sendsz = bufsize; |
13180 | 0 | recvsz = ospf->recv_sock_bufsize; |
13181 | 0 | } else if (recv_val) { |
13182 | 0 | recvsz = bufsize; |
13183 | 0 | sendsz = ospf->send_sock_bufsize; |
13184 | 0 | } else |
13185 | 0 | return CMD_SUCCESS; |
13186 | | |
13187 | | /* React to a change by modifying existing sockets */ |
13188 | 0 | ospf_update_bufsize(ospf, recvsz, sendsz); |
13189 | |
|
13190 | 0 | return CMD_SUCCESS; |
13191 | 0 | } |
13192 | | |
13193 | | DEFPY (per_intf_socket, |
13194 | | per_intf_socket_cmd, |
13195 | | "[no] socket-per-interface", |
13196 | | NO_STR |
13197 | | "Use write socket per interface\n") |
13198 | 0 | { |
13199 | 0 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
13200 | 0 | struct listnode *node; |
13201 | 0 | struct ospf_interface *oi; |
13202 | |
|
13203 | 0 | if (no) { |
13204 | 0 | if (ospf->intf_socket_enabled) { |
13205 | 0 | ospf->intf_socket_enabled = false; |
13206 | | |
13207 | | /* Iterate and close any sockets */ |
13208 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) |
13209 | 0 | ospf_ifp_sock_close(oi->ifp); |
13210 | 0 | } |
13211 | 0 | } else if (!ospf->intf_socket_enabled) { |
13212 | 0 | ospf->intf_socket_enabled = true; |
13213 | | |
13214 | | /* Iterate and open sockets */ |
13215 | 0 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) |
13216 | 0 | ospf_ifp_sock_init(oi->ifp); |
13217 | 0 | } |
13218 | |
|
13219 | 0 | return CMD_SUCCESS; |
13220 | 0 | } |
13221 | | |
13222 | | void ospf_vty_clear_init(void) |
13223 | 0 | { |
13224 | 0 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
13225 | 0 | install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd); |
13226 | 0 | install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd); |
13227 | 0 | } |
13228 | | |
13229 | | |
13230 | | /* Install OSPF related vty commands. */ |
13231 | | void ospf_vty_init(void) |
13232 | 0 | { |
13233 | | /* Install ospf top node. */ |
13234 | 0 | install_node(&ospf_node); |
13235 | | |
13236 | | /* "router ospf" commands. */ |
13237 | 0 | install_element(CONFIG_NODE, &router_ospf_cmd); |
13238 | 0 | install_element(CONFIG_NODE, &no_router_ospf_cmd); |
13239 | | |
13240 | |
|
13241 | 0 | install_default(OSPF_NODE); |
13242 | | |
13243 | | /* "ospf router-id" commands. */ |
13244 | 0 | install_element(OSPF_NODE, &ospf_router_id_cmd); |
13245 | 0 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); |
13246 | 0 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); |
13247 | | |
13248 | | /* "passive-interface" commands. */ |
13249 | 0 | install_element(OSPF_NODE, &ospf_passive_interface_default_cmd); |
13250 | 0 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); |
13251 | 0 | install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd); |
13252 | 0 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); |
13253 | | |
13254 | | /* "ospf abr-type" commands. */ |
13255 | 0 | install_element(OSPF_NODE, &ospf_abr_type_cmd); |
13256 | 0 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); |
13257 | | |
13258 | | /* "ospf log-adjacency-changes" commands. */ |
13259 | 0 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); |
13260 | 0 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); |
13261 | 0 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); |
13262 | 0 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); |
13263 | | |
13264 | | /* "ospf rfc1583-compatible" commands. */ |
13265 | 0 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); |
13266 | 0 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); |
13267 | 0 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); |
13268 | 0 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); |
13269 | | |
13270 | | /* "ospf send-extra-data zebra" commands. */ |
13271 | 0 | install_element(OSPF_NODE, &ospf_send_extra_data_cmd); |
13272 | | |
13273 | | /* "network area" commands. */ |
13274 | 0 | install_element(OSPF_NODE, &ospf_network_area_cmd); |
13275 | 0 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); |
13276 | | |
13277 | | /* "area authentication" commands. */ |
13278 | 0 | install_element(OSPF_NODE, |
13279 | 0 | &ospf_area_authentication_message_digest_cmd); |
13280 | 0 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); |
13281 | 0 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); |
13282 | | |
13283 | | /* "area range" commands. */ |
13284 | 0 | install_element(OSPF_NODE, &ospf_area_range_cmd); |
13285 | 0 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); |
13286 | 0 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); |
13287 | 0 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); |
13288 | 0 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); |
13289 | | |
13290 | | /* "area virtual-link" commands. */ |
13291 | 0 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); |
13292 | 0 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); |
13293 | 0 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); |
13294 | 0 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); |
13295 | | |
13296 | | |
13297 | | /* "area stub" commands. */ |
13298 | 0 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); |
13299 | 0 | install_element(OSPF_NODE, &ospf_area_stub_cmd); |
13300 | 0 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); |
13301 | 0 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); |
13302 | | |
13303 | | /* "area nssa" commands. */ |
13304 | 0 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); |
13305 | 0 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
13306 | 0 | install_element(OSPF_NODE, &ospf_area_nssa_range_cmd); |
13307 | 0 | install_element(OSPF_NODE, &no_ospf_area_nssa_range_cmd); |
13308 | |
|
13309 | 0 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); |
13310 | 0 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); |
13311 | |
|
13312 | 0 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); |
13313 | 0 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); |
13314 | |
|
13315 | 0 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); |
13316 | 0 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); |
13317 | |
|
13318 | 0 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); |
13319 | 0 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); |
13320 | |
|
13321 | 0 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); |
13322 | 0 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); |
13323 | | |
13324 | | /* SPF timer commands */ |
13325 | 0 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); |
13326 | 0 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); |
13327 | | |
13328 | | /* LSA timers commands */ |
13329 | 0 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); |
13330 | 0 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); |
13331 | 0 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
13332 | 0 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); |
13333 | | |
13334 | | /* refresh timer commands */ |
13335 | 0 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); |
13336 | 0 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); |
13337 | | |
13338 | | /* max-metric commands */ |
13339 | 0 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); |
13340 | 0 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); |
13341 | 0 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); |
13342 | 0 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); |
13343 | 0 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); |
13344 | 0 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); |
13345 | | |
13346 | | /* reference bandwidth commands */ |
13347 | 0 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); |
13348 | 0 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); |
13349 | | |
13350 | | /* "neighbor" commands. */ |
13351 | 0 | install_element(OSPF_NODE, &ospf_neighbor_cmd); |
13352 | 0 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); |
13353 | 0 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); |
13354 | 0 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); |
13355 | | |
13356 | | /* write multiplier commands */ |
13357 | 0 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); |
13358 | 0 | install_element(OSPF_NODE, &write_multiplier_cmd); |
13359 | 0 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); |
13360 | 0 | install_element(OSPF_NODE, &no_write_multiplier_cmd); |
13361 | | |
13362 | | /* "proactive-arp" commands. */ |
13363 | 0 | install_element(OSPF_NODE, &ospf_proactive_arp_cmd); |
13364 | 0 | install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd); |
13365 | | |
13366 | | /* TI-LFA commands */ |
13367 | 0 | install_element(OSPF_NODE, &ospf_ti_lfa_cmd); |
13368 | 0 | install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd); |
13369 | | |
13370 | | /* Max path configurations */ |
13371 | 0 | install_element(OSPF_NODE, &ospf_max_multipath_cmd); |
13372 | 0 | install_element(OSPF_NODE, &no_ospf_max_multipath_cmd); |
13373 | |
|
13374 | 0 | vrf_cmd_init(NULL); |
13375 | |
|
13376 | 0 | install_element(OSPF_NODE, &ospf_lsa_refresh_timer_cmd); |
13377 | 0 | install_element(OSPF_NODE, &ospf_maxage_delay_timer_cmd); |
13378 | | |
13379 | | /* Flood Reduction commands */ |
13380 | 0 | install_element(OSPF_NODE, &flood_reduction_cmd); |
13381 | 0 | install_element(OSPF_NODE, &no_flood_reduction_cmd); |
13382 | 0 | install_element(OSPF_NODE, &flood_reduction_area_cmd); |
13383 | 0 | install_element(OSPF_NODE, &no_flood_reduction_area_cmd); |
13384 | |
|
13385 | 0 | install_element(OSPF_NODE, &ospf_socket_bufsizes_cmd); |
13386 | 0 | install_element(OSPF_NODE, &per_intf_socket_cmd); |
13387 | | |
13388 | | /* Init interface related vty commands. */ |
13389 | 0 | ospf_vty_if_init(); |
13390 | | |
13391 | | /* Init zebra related vty commands. */ |
13392 | 0 | ospf_vty_zebra_init(); |
13393 | 0 | } |