]>
Commit | Line | Data |
---|---|---|
1 | /* OSPF VTY interface. | |
2 | * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com> | |
3 | * Copyright (C) 2000 Toshiaki Takada | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along | |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | */ | |
21 | ||
22 | #include <zebra.h> | |
23 | #include <string.h> | |
24 | ||
25 | #include "monotime.h" | |
26 | #include "memory.h" | |
27 | #include "thread.h" | |
28 | #include "prefix.h" | |
29 | #include "table.h" | |
30 | #include "vty.h" | |
31 | #include "command.h" | |
32 | #include "plist.h" | |
33 | #include "log.h" | |
34 | #include "zclient.h" | |
35 | #include <lib/json.h> | |
36 | #include "defaults.h" | |
37 | ||
38 | #include "ospfd/ospfd.h" | |
39 | #include "ospfd/ospf_asbr.h" | |
40 | #include "ospfd/ospf_lsa.h" | |
41 | #include "ospfd/ospf_lsdb.h" | |
42 | #include "ospfd/ospf_ism.h" | |
43 | #include "ospfd/ospf_interface.h" | |
44 | #include "ospfd/ospf_nsm.h" | |
45 | #include "ospfd/ospf_neighbor.h" | |
46 | #include "ospfd/ospf_flood.h" | |
47 | #include "ospfd/ospf_abr.h" | |
48 | #include "ospfd/ospf_spf.h" | |
49 | #include "ospfd/ospf_route.h" | |
50 | #include "ospfd/ospf_zebra.h" | |
51 | /*#include "ospfd/ospf_routemap.h" */ | |
52 | #include "ospfd/ospf_vty.h" | |
53 | #include "ospfd/ospf_dump.h" | |
54 | #include "ospfd/ospf_bfd.h" | |
55 | ||
56 | static const char *const ospf_network_type_str[] = { | |
57 | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", | |
58 | "VIRTUALLINK", "LOOPBACK"}; | |
59 | ||
60 | /* Utility functions. */ | |
61 | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) | |
62 | { | |
63 | char *ep; | |
64 | ||
65 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); | |
66 | if (*ep && !inet_aton(str, area_id)) | |
67 | return -1; | |
68 | ||
69 | *area_id_fmt = | |
70 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; | |
71 | ||
72 | return 0; | |
73 | } | |
74 | ||
75 | static void area_id2str(char *buf, int length, struct in_addr *area_id, | |
76 | int area_id_fmt) | |
77 | { | |
78 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
79 | inet_ntop(AF_INET, area_id, buf, length); | |
80 | else | |
81 | sprintf(buf, "%lu", (unsigned long)ntohl(area_id->s_addr)); | |
82 | } | |
83 | ||
84 | static int str2metric(const char *str, int *metric) | |
85 | { | |
86 | /* Sanity check. */ | |
87 | if (str == NULL) | |
88 | return 0; | |
89 | ||
90 | *metric = strtol(str, NULL, 10); | |
91 | if (*metric < 0 && *metric > 16777214) { | |
92 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ | |
93 | return 0; | |
94 | } | |
95 | ||
96 | return 1; | |
97 | } | |
98 | ||
99 | static int str2metric_type(const char *str, int *metric_type) | |
100 | { | |
101 | /* Sanity check. */ | |
102 | if (str == NULL) | |
103 | return 0; | |
104 | ||
105 | if (strncmp(str, "1", 1) == 0) | |
106 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
107 | else if (strncmp(str, "2", 1) == 0) | |
108 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
109 | else | |
110 | return 0; | |
111 | ||
112 | return 1; | |
113 | } | |
114 | ||
115 | int ospf_oi_count(struct interface *ifp) | |
116 | { | |
117 | struct route_node *rn; | |
118 | int i = 0; | |
119 | ||
120 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
121 | if (rn->info) | |
122 | i++; | |
123 | ||
124 | return i; | |
125 | } | |
126 | ||
127 | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ | |
128 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ | |
129 | vrf_name = argv[idx_vrf + 1]->arg; \ | |
130 | all_vrf = strmatch(vrf_name, "all"); \ | |
131 | } | |
132 | ||
133 | static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, | |
134 | struct cmd_token *argv[], | |
135 | const int argc, uint32_t enable, | |
136 | unsigned short *instance) | |
137 | { | |
138 | struct ospf *ospf = NULL; | |
139 | int idx_vrf = 0, idx_inst = 0; | |
140 | const char *vrf_name = NULL; | |
141 | ||
142 | *instance = 0; | |
143 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) | |
144 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); | |
145 | ||
146 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { | |
147 | vrf_name = argv[idx_vrf + 1]->arg; | |
148 | if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
149 | vrf_name = NULL; | |
150 | if (enable) { | |
151 | /* Allocate VRF aware instance */ | |
152 | ospf = ospf_get(*instance, vrf_name); | |
153 | } else { | |
154 | ospf = ospf_lookup_by_inst_name(*instance, vrf_name); | |
155 | } | |
156 | } else { | |
157 | if (enable) { | |
158 | ospf = ospf_get(*instance, NULL); | |
159 | } else { | |
160 | ospf = ospf_lookup_instance(*instance); | |
161 | } | |
162 | } | |
163 | ||
164 | return ospf; | |
165 | } | |
166 | ||
167 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, | |
168 | json_object *json, uint8_t use_vrf) | |
169 | { | |
170 | if (use_vrf) { | |
171 | if (json) { | |
172 | if (ospf->vrf_id == VRF_DEFAULT) | |
173 | json_object_string_add(json, "vrfName", | |
174 | "default"); | |
175 | else | |
176 | json_object_string_add(json, "vrfName", | |
177 | ospf->name); | |
178 | json_object_int_add(json, "vrfId", ospf->vrf_id); | |
179 | } else { | |
180 | if (ospf->vrf_id == VRF_DEFAULT) | |
181 | vty_out(vty, "VRF Name: %s\n", "default"); | |
182 | else if (ospf->name) | |
183 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
184 | } | |
185 | } | |
186 | } | |
187 | ||
188 | #ifndef VTYSH_EXTRACT_PL | |
189 | #include "ospfd/ospf_vty_clippy.c" | |
190 | #endif | |
191 | ||
192 | DEFUN_NOSH (router_ospf, | |
193 | router_ospf_cmd, | |
194 | "router ospf [{(1-65535)|vrf NAME}]", | |
195 | "Enable a routing process\n" | |
196 | "Start OSPF configuration\n" | |
197 | "Instance ID\n" | |
198 | VRF_CMD_HELP_STR) | |
199 | { | |
200 | struct ospf *ospf = NULL; | |
201 | int ret = CMD_SUCCESS; | |
202 | unsigned short instance = 0; | |
203 | struct vrf *vrf = NULL; | |
204 | struct route_node *rn; | |
205 | struct interface *ifp; | |
206 | ||
207 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance); | |
208 | if (!ospf) | |
209 | return CMD_WARNING_CONFIG_FAILED; | |
210 | ||
211 | /* The following logic to set the vty qobj index is in place to be able | |
212 | to ignore the commands which dont belong to this instance. */ | |
213 | if (ospf->instance != instance) { | |
214 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); | |
215 | ret = CMD_NOT_MY_INSTANCE; | |
216 | } else { | |
217 | if (ospf->vrf_id != VRF_UNKNOWN) | |
218 | ospf->oi_running = 1; | |
219 | if (IS_DEBUG_OSPF_EVENT) | |
220 | zlog_debug( | |
221 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
222 | instance, ospf->name ? ospf->name : "NIL", | |
223 | ospf->vrf_id, ospf->oi_running); | |
224 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); | |
225 | ||
226 | /* Activate 'ip ospf area x' configured interfaces for given | |
227 | * vrf. Activate area on vrf x aware interfaces. | |
228 | * vrf_enable callback calls router_id_update which | |
229 | * internally will call ospf_if_update to trigger | |
230 | * network_run_state | |
231 | */ | |
232 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
233 | ||
234 | FOR_ALL_INTERFACES (vrf, ifp) { | |
235 | struct ospf_if_params *params; | |
236 | ||
237 | params = IF_DEF_PARAMS(ifp); | |
238 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
239 | for (rn = route_top(ospf->networks); rn; | |
240 | rn = route_next(rn)) { | |
241 | if (rn->info != NULL) { | |
242 | vty_out(vty, | |
243 | "Interface %s has area config but please remove all network commands first.\n", | |
244 | ifp->name); | |
245 | return ret; | |
246 | } | |
247 | } | |
248 | if (!ospf_interface_area_is_already_set(ospf, | |
249 | ifp)) { | |
250 | ospf_interface_area_set(ospf, ifp); | |
251 | ospf->if_ospf_cli_count++; | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | ospf_router_id_update(ospf); | |
257 | } | |
258 | ||
259 | return ret; | |
260 | } | |
261 | ||
262 | DEFUN (no_router_ospf, | |
263 | no_router_ospf_cmd, | |
264 | "no router ospf [{(1-65535)|vrf NAME}]", | |
265 | NO_STR | |
266 | "Enable a routing process\n" | |
267 | "Start OSPF configuration\n" | |
268 | "Instance ID\n" | |
269 | VRF_CMD_HELP_STR) | |
270 | { | |
271 | struct ospf *ospf; | |
272 | unsigned short instance = 0; | |
273 | ||
274 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); | |
275 | if (ospf == NULL) { | |
276 | if (instance) | |
277 | return CMD_NOT_MY_INSTANCE; | |
278 | else | |
279 | return CMD_WARNING; | |
280 | } | |
281 | ospf_finish(ospf); | |
282 | ||
283 | return CMD_SUCCESS; | |
284 | } | |
285 | ||
286 | ||
287 | DEFPY (ospf_router_id, | |
288 | ospf_router_id_cmd, | |
289 | "ospf router-id A.B.C.D", | |
290 | "OSPF specific commands\n" | |
291 | "router-id for the OSPF process\n" | |
292 | "OSPF router-id in IP address format\n") | |
293 | { | |
294 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
295 | ||
296 | struct listnode *node; | |
297 | struct ospf_area *area; | |
298 | ||
299 | ospf->router_id_static = router_id; | |
300 | ||
301 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
302 | if (area->full_nbrs) { | |
303 | vty_out(vty, | |
304 | "For this router-id change to take effect," | |
305 | " save config and restart ospfd\n"); | |
306 | return CMD_SUCCESS; | |
307 | } | |
308 | ||
309 | ospf_router_id_update(ospf); | |
310 | ||
311 | return CMD_SUCCESS; | |
312 | } | |
313 | ||
314 | DEFUN_HIDDEN (ospf_router_id_old, | |
315 | ospf_router_id_old_cmd, | |
316 | "router-id A.B.C.D", | |
317 | "router-id for the OSPF process\n" | |
318 | "OSPF router-id in IP address format\n") | |
319 | { | |
320 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
321 | int idx_ipv4 = 1; | |
322 | struct listnode *node; | |
323 | struct ospf_area *area; | |
324 | struct in_addr router_id; | |
325 | int ret; | |
326 | ||
327 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
328 | if (!ret) { | |
329 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
330 | return CMD_WARNING_CONFIG_FAILED; | |
331 | } | |
332 | ||
333 | ospf->router_id_static = router_id; | |
334 | ||
335 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
336 | if (area->full_nbrs) { | |
337 | vty_out(vty, | |
338 | "For this router-id change to take effect," | |
339 | " save config and restart ospfd\n"); | |
340 | return CMD_SUCCESS; | |
341 | } | |
342 | ||
343 | ospf_router_id_update(ospf); | |
344 | ||
345 | return CMD_SUCCESS; | |
346 | } | |
347 | ||
348 | DEFPY (no_ospf_router_id, | |
349 | no_ospf_router_id_cmd, | |
350 | "no ospf router-id [A.B.C.D]", | |
351 | NO_STR | |
352 | "OSPF specific commands\n" | |
353 | "router-id for the OSPF process\n" | |
354 | "OSPF router-id in IP address format\n") | |
355 | { | |
356 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
357 | struct listnode *node; | |
358 | struct ospf_area *area; | |
359 | ||
360 | if (router_id_str) { | |
361 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
362 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
363 | return CMD_WARNING_CONFIG_FAILED; | |
364 | } | |
365 | } | |
366 | ||
367 | ospf->router_id_static.s_addr = 0; | |
368 | ||
369 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
370 | if (area->full_nbrs) { | |
371 | vty_out(vty, | |
372 | "For this router-id change to take effect," | |
373 | " save config and restart ospfd\n"); | |
374 | return CMD_SUCCESS; | |
375 | } | |
376 | ||
377 | ospf_router_id_update(ospf); | |
378 | ||
379 | return CMD_SUCCESS; | |
380 | } | |
381 | ||
382 | ||
383 | static void ospf_passive_interface_default(struct ospf *ospf, uint8_t newval) | |
384 | { | |
385 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); | |
386 | struct listnode *ln; | |
387 | struct interface *ifp; | |
388 | struct ospf_interface *oi; | |
389 | ||
390 | ospf->passive_interface_default = newval; | |
391 | ||
392 | FOR_ALL_INTERFACES (vrf, ifp) { | |
393 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
394 | passive_interface)) | |
395 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); | |
396 | } | |
397 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
398 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
399 | UNSET_IF_PARAM(oi->params, passive_interface); | |
400 | /* update multicast memberships */ | |
401 | ospf_if_set_multicast(oi); | |
402 | } | |
403 | } | |
404 | ||
405 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
406 | struct interface *ifp, | |
407 | struct ospf_if_params *params, | |
408 | uint8_t value, | |
409 | struct in_addr addr) | |
410 | { | |
411 | uint8_t dflt; | |
412 | ||
413 | params->passive_interface = value; | |
414 | if (params != IF_DEF_PARAMS(ifp)) { | |
415 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
416 | passive_interface)) | |
417 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
418 | else | |
419 | dflt = ospf->passive_interface_default; | |
420 | ||
421 | if (value != dflt) | |
422 | SET_IF_PARAM(params, passive_interface); | |
423 | else | |
424 | UNSET_IF_PARAM(params, passive_interface); | |
425 | ||
426 | ospf_free_if_params(ifp, addr); | |
427 | ospf_if_update_params(ifp, addr); | |
428 | } | |
429 | } | |
430 | ||
431 | static void ospf_passive_interface_update(struct ospf *ospf, | |
432 | struct interface *ifp, | |
433 | struct ospf_if_params *params, | |
434 | uint8_t value) | |
435 | { | |
436 | params->passive_interface = value; | |
437 | if (params == IF_DEF_PARAMS(ifp)) { | |
438 | if (value != ospf->passive_interface_default) | |
439 | SET_IF_PARAM(params, passive_interface); | |
440 | else | |
441 | UNSET_IF_PARAM(params, passive_interface); | |
442 | } | |
443 | } | |
444 | ||
445 | DEFUN (ospf_passive_interface, | |
446 | ospf_passive_interface_addr_cmd, | |
447 | "passive-interface <IFNAME [A.B.C.D]|default>", | |
448 | "Suppress routing updates on an interface\n" | |
449 | "Interface's name\n" | |
450 | "IPv4 address\n" | |
451 | "Suppress routing updates on interfaces by default\n") | |
452 | { | |
453 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
454 | int idx_ipv4 = 2; | |
455 | struct interface *ifp = NULL; | |
456 | struct in_addr addr = {.s_addr = INADDR_ANY}; | |
457 | int ret; | |
458 | struct ospf_if_params *params; | |
459 | struct route_node *rn; | |
460 | ||
461 | if (strmatch(argv[1]->text, "default")) { | |
462 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
463 | return CMD_SUCCESS; | |
464 | } | |
465 | if (ospf->vrf_id != VRF_UNKNOWN) | |
466 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); | |
467 | ||
468 | if (ifp == NULL) { | |
469 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); | |
470 | return CMD_WARNING_CONFIG_FAILED; | |
471 | } | |
472 | ||
473 | params = IF_DEF_PARAMS(ifp); | |
474 | ||
475 | if (argc == 3) { | |
476 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
477 | if (!ret) { | |
478 | vty_out(vty, | |
479 | "Please specify interface address by A.B.C.D\n"); | |
480 | return CMD_WARNING_CONFIG_FAILED; | |
481 | } | |
482 | ||
483 | params = ospf_get_if_params(ifp, addr); | |
484 | ospf_if_update_params(ifp, addr); | |
485 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
486 | OSPF_IF_PASSIVE, addr); | |
487 | } | |
488 | ||
489 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
490 | ||
491 | /* XXX We should call ospf_if_set_multicast on exactly those | |
492 | * interfaces for which the passive property changed. It is too much | |
493 | * work to determine this set, so we do this for every interface. | |
494 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
495 | * record of joined groups to avoid systems calls if the desired | |
496 | * memberships match the current memership. | |
497 | */ | |
498 | ||
499 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
500 | struct ospf_interface *oi = rn->info; | |
501 | ||
502 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) | |
503 | == OSPF_IF_PASSIVE)) | |
504 | ospf_if_set_multicast(oi); | |
505 | } | |
506 | /* | |
507 | * XXX It is not clear what state transitions the interface needs to | |
508 | * undergo when going from active to passive. Fixing this will | |
509 | * require precise identification of interfaces having such a | |
510 | * transition. | |
511 | */ | |
512 | ||
513 | return CMD_SUCCESS; | |
514 | } | |
515 | ||
516 | DEFUN (no_ospf_passive_interface, | |
517 | no_ospf_passive_interface_addr_cmd, | |
518 | "no passive-interface <IFNAME [A.B.C.D]|default>", | |
519 | NO_STR | |
520 | "Allow routing updates on an interface\n" | |
521 | "Interface's name\n" | |
522 | "IPv4 address\n" | |
523 | "Allow routing updates on interfaces by default\n") | |
524 | { | |
525 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
526 | int idx_ipv4 = 3; | |
527 | struct interface *ifp = NULL; | |
528 | struct in_addr addr = {.s_addr = INADDR_ANY}; | |
529 | struct ospf_if_params *params; | |
530 | int ret; | |
531 | struct route_node *rn; | |
532 | ||
533 | if (strmatch(argv[2]->text, "default")) { | |
534 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
535 | return CMD_SUCCESS; | |
536 | } | |
537 | ||
538 | if (ospf->vrf_id != VRF_UNKNOWN) | |
539 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); | |
540 | ||
541 | if (ifp == NULL) { | |
542 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); | |
543 | return CMD_WARNING_CONFIG_FAILED; | |
544 | } | |
545 | ||
546 | params = IF_DEF_PARAMS(ifp); | |
547 | ||
548 | if (argc == 4) { | |
549 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
550 | if (!ret) { | |
551 | vty_out(vty, | |
552 | "Please specify interface address by A.B.C.D\n"); | |
553 | return CMD_WARNING_CONFIG_FAILED; | |
554 | } | |
555 | ||
556 | params = ospf_lookup_if_params(ifp, addr); | |
557 | if (params == NULL) | |
558 | return CMD_SUCCESS; | |
559 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
560 | OSPF_IF_ACTIVE, addr); | |
561 | } | |
562 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
563 | ||
564 | /* XXX We should call ospf_if_set_multicast on exactly those | |
565 | * interfaces for which the passive property changed. It is too much | |
566 | * work to determine this set, so we do this for every interface. | |
567 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
568 | * record of joined groups to avoid systems calls if the desired | |
569 | * memberships match the current memership. | |
570 | */ | |
571 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
572 | struct ospf_interface *oi = rn->info; | |
573 | ||
574 | if (oi | |
575 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
576 | ospf_if_set_multicast(oi); | |
577 | } | |
578 | ||
579 | return CMD_SUCCESS; | |
580 | } | |
581 | ||
582 | ||
583 | DEFUN (ospf_network_area, | |
584 | ospf_network_area_cmd, | |
585 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", | |
586 | "Enable routing on an IP network\n" | |
587 | "OSPF network prefix\n" | |
588 | "Set the OSPF area ID\n" | |
589 | "OSPF area ID in IP address format\n" | |
590 | "OSPF area ID as a decimal value\n") | |
591 | { | |
592 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
593 | int idx_ipv4_prefixlen = 1; | |
594 | int idx_ipv4_number = 3; | |
595 | struct prefix_ipv4 p; | |
596 | struct in_addr area_id; | |
597 | int ret, format; | |
598 | ||
599 | if (ospf->instance) { | |
600 | vty_out(vty, | |
601 | "The network command is not supported in multi-instance ospf\n"); | |
602 | return CMD_WARNING_CONFIG_FAILED; | |
603 | } | |
604 | ||
605 | if (ospf->if_ospf_cli_count > 0) { | |
606 | vty_out(vty, | |
607 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
608 | if (IS_DEBUG_OSPF_EVENT) | |
609 | zlog_debug( | |
610 | "%s ospf vrf %s num of %u ip osp area x config", | |
611 | __PRETTY_FUNCTION__, | |
612 | ospf->name ? ospf->name : "NIL", | |
613 | ospf->if_ospf_cli_count); | |
614 | return CMD_WARNING_CONFIG_FAILED; | |
615 | } | |
616 | ||
617 | /* Get network prefix and Area ID. */ | |
618 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
619 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
620 | ||
621 | ret = ospf_network_set(ospf, &p, area_id, format); | |
622 | if (ret == 0) { | |
623 | vty_out(vty, "There is already same network statement.\n"); | |
624 | return CMD_WARNING_CONFIG_FAILED; | |
625 | } | |
626 | ||
627 | return CMD_SUCCESS; | |
628 | } | |
629 | ||
630 | DEFUN (no_ospf_network_area, | |
631 | no_ospf_network_area_cmd, | |
632 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", | |
633 | NO_STR | |
634 | "Enable routing on an IP network\n" | |
635 | "OSPF network prefix\n" | |
636 | "Set the OSPF area ID\n" | |
637 | "OSPF area ID in IP address format\n" | |
638 | "OSPF area ID as a decimal value\n") | |
639 | { | |
640 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
641 | int idx_ipv4_prefixlen = 2; | |
642 | int idx_ipv4_number = 4; | |
643 | struct prefix_ipv4 p; | |
644 | struct in_addr area_id; | |
645 | int ret, format; | |
646 | ||
647 | if (ospf->instance) { | |
648 | vty_out(vty, | |
649 | "The network command is not supported in multi-instance ospf\n"); | |
650 | return CMD_WARNING_CONFIG_FAILED; | |
651 | } | |
652 | ||
653 | /* Get network prefix and Area ID. */ | |
654 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
655 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
656 | ||
657 | ret = ospf_network_unset(ospf, &p, area_id); | |
658 | if (ret == 0) { | |
659 | vty_out(vty, | |
660 | "Can't find specified network area configuration.\n"); | |
661 | return CMD_WARNING_CONFIG_FAILED; | |
662 | } | |
663 | ||
664 | return CMD_SUCCESS; | |
665 | } | |
666 | ||
667 | DEFUN (ospf_area_range, | |
668 | ospf_area_range_cmd, | |
669 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", | |
670 | "OSPF area parameters\n" | |
671 | "OSPF area ID in IP address format\n" | |
672 | "OSPF area ID as a decimal value\n" | |
673 | "Summarize routes matching address/mask (border routers only)\n" | |
674 | "Area range prefix\n" | |
675 | "Advertise this range (default)\n" | |
676 | "User specified metric for this range\n" | |
677 | "Advertised metric for this range\n") | |
678 | { | |
679 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
680 | int idx_ipv4_number = 1; | |
681 | int idx_ipv4_prefixlen = 3; | |
682 | int idx_cost = 6; | |
683 | struct prefix_ipv4 p; | |
684 | struct in_addr area_id; | |
685 | int format; | |
686 | uint32_t cost; | |
687 | ||
688 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
689 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
690 | ||
691 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
692 | if (argc > 5) { | |
693 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
694 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
695 | } | |
696 | ||
697 | return CMD_SUCCESS; | |
698 | } | |
699 | ||
700 | DEFUN (ospf_area_range_cost, | |
701 | ospf_area_range_cost_cmd, | |
702 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
703 | "OSPF area parameters\n" | |
704 | "OSPF area ID in IP address format\n" | |
705 | "OSPF area ID as a decimal value\n" | |
706 | "Summarize routes matching address/mask (border routers only)\n" | |
707 | "Area range prefix\n" | |
708 | "User specified metric for this range\n" | |
709 | "Advertised metric for this range\n") | |
710 | { | |
711 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
712 | int idx_ipv4_number = 1; | |
713 | int idx_ipv4_prefixlen = 3; | |
714 | int idx_cost = 5; | |
715 | struct prefix_ipv4 p; | |
716 | struct in_addr area_id; | |
717 | int format; | |
718 | uint32_t cost; | |
719 | ||
720 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
721 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
722 | ||
723 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
724 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
725 | format); | |
726 | ||
727 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
728 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
729 | ||
730 | return CMD_SUCCESS; | |
731 | } | |
732 | ||
733 | DEFUN (ospf_area_range_not_advertise, | |
734 | ospf_area_range_not_advertise_cmd, | |
735 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", | |
736 | "OSPF area parameters\n" | |
737 | "OSPF area ID in IP address format\n" | |
738 | "OSPF area ID as a decimal value\n" | |
739 | "Summarize routes matching address/mask (border routers only)\n" | |
740 | "Area range prefix\n" | |
741 | "DoNotAdvertise this range\n") | |
742 | { | |
743 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
744 | int idx_ipv4_number = 1; | |
745 | int idx_ipv4_prefixlen = 3; | |
746 | struct prefix_ipv4 p; | |
747 | struct in_addr area_id; | |
748 | int format; | |
749 | ||
750 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
751 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
752 | ||
753 | ospf_area_range_set(ospf, area_id, &p, 0); | |
754 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
755 | format); | |
756 | ospf_area_range_substitute_unset(ospf, area_id, &p); | |
757 | ||
758 | return CMD_SUCCESS; | |
759 | } | |
760 | ||
761 | DEFUN (no_ospf_area_range, | |
762 | no_ospf_area_range_cmd, | |
763 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", | |
764 | NO_STR | |
765 | "OSPF area parameters\n" | |
766 | "OSPF area ID in IP address format\n" | |
767 | "OSPF area ID as a decimal value\n" | |
768 | "Summarize routes matching address/mask (border routers only)\n" | |
769 | "Area range prefix\n" | |
770 | "User specified metric for this range\n" | |
771 | "Advertised metric for this range\n" | |
772 | "Advertise this range (default)\n" | |
773 | "User specified metric for this range\n" | |
774 | "Advertised metric for this range\n" | |
775 | "DoNotAdvertise this range\n") | |
776 | { | |
777 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
778 | int idx_ipv4_number = 2; | |
779 | int idx_ipv4_prefixlen = 4; | |
780 | struct prefix_ipv4 p; | |
781 | struct in_addr area_id; | |
782 | int format; | |
783 | ||
784 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
785 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
786 | ||
787 | ospf_area_range_unset(ospf, area_id, &p); | |
788 | ||
789 | return CMD_SUCCESS; | |
790 | } | |
791 | ||
792 | DEFUN (ospf_area_range_substitute, | |
793 | ospf_area_range_substitute_cmd, | |
794 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", | |
795 | "OSPF area parameters\n" | |
796 | "OSPF area ID in IP address format\n" | |
797 | "OSPF area ID as a decimal value\n" | |
798 | "Summarize routes matching address/mask (border routers only)\n" | |
799 | "Area range prefix\n" | |
800 | "Announce area range as another prefix\n" | |
801 | "Network prefix to be announced instead of range\n") | |
802 | { | |
803 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
804 | int idx_ipv4_number = 1; | |
805 | int idx_ipv4_prefixlen = 3; | |
806 | int idx_ipv4_prefixlen_2 = 5; | |
807 | struct prefix_ipv4 p, s; | |
808 | struct in_addr area_id; | |
809 | int format; | |
810 | ||
811 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
812 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
813 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
814 | ||
815 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); | |
816 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
817 | format); | |
818 | ||
819 | return CMD_SUCCESS; | |
820 | } | |
821 | ||
822 | DEFUN (no_ospf_area_range_substitute, | |
823 | no_ospf_area_range_substitute_cmd, | |
824 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", | |
825 | NO_STR | |
826 | "OSPF area parameters\n" | |
827 | "OSPF area ID in IP address format\n" | |
828 | "OSPF area ID as a decimal value\n" | |
829 | "Summarize routes matching address/mask (border routers only)\n" | |
830 | "Area range prefix\n" | |
831 | "Announce area range as another prefix\n" | |
832 | "Network prefix to be announced instead of range\n") | |
833 | { | |
834 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
835 | int idx_ipv4_number = 2; | |
836 | int idx_ipv4_prefixlen = 4; | |
837 | int idx_ipv4_prefixlen_2 = 6; | |
838 | struct prefix_ipv4 p, s; | |
839 | struct in_addr area_id; | |
840 | int format; | |
841 | ||
842 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
843 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
844 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
845 | ||
846 | ospf_area_range_substitute_unset(ospf, area_id, &p); | |
847 | ||
848 | return CMD_SUCCESS; | |
849 | } | |
850 | ||
851 | ||
852 | /* Command Handler Logic in VLink stuff is delicate!! | |
853 | ||
854 | ALTER AT YOUR OWN RISK!!!! | |
855 | ||
856 | Various dummy values are used to represent 'NoChange' state for | |
857 | VLink configuration NOT being changed by a VLink command, and | |
858 | special syntax is used within the command strings so that the | |
859 | typed in command verbs can be seen in the configuration command | |
860 | bacckend handler. This is to drastically reduce the verbeage | |
861 | required to coe up with a reasonably compatible Cisco VLink command | |
862 | ||
863 | - Matthew Grant <grantma@anathoth.gen.nz> | |
864 | Wed, 21 Feb 2001 15:13:52 +1300 | |
865 | */ | |
866 | ||
867 | /* Configuration data for virtual links | |
868 | */ | |
869 | struct ospf_vl_config_data { | |
870 | struct vty *vty; /* vty stuff */ | |
871 | struct in_addr area_id; /* area ID from command line */ | |
872 | int area_id_fmt; /* command line area ID format */ | |
873 | struct in_addr vl_peer; /* command line vl_peer */ | |
874 | int auth_type; /* Authehntication type, if given */ | |
875 | char *auth_key; /* simple password if present */ | |
876 | int crypto_key_id; /* Cryptographic key ID */ | |
877 | char *md5_key; /* MD5 authentication key */ | |
878 | int hello_interval; /* Obvious what these are... */ | |
879 | int retransmit_interval; | |
880 | int transmit_delay; | |
881 | int dead_interval; | |
882 | }; | |
883 | ||
884 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, | |
885 | struct vty *vty) | |
886 | { | |
887 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); | |
888 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
889 | vl_config->vty = vty; | |
890 | } | |
891 | ||
892 | static struct ospf_vl_data * | |
893 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) | |
894 | { | |
895 | struct ospf_area *area; | |
896 | struct ospf_vl_data *vl_data; | |
897 | struct vty *vty; | |
898 | struct in_addr area_id; | |
899 | ||
900 | vty = vl_config->vty; | |
901 | area_id = vl_config->area_id; | |
902 | ||
903 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
904 | vty_out(vty, | |
905 | "Configuring VLs over the backbone is not allowed\n"); | |
906 | return NULL; | |
907 | } | |
908 | area = ospf_area_get(ospf, area_id); | |
909 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
910 | ||
911 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
912 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
913 | vty_out(vty, "Area %s is %s\n", inet_ntoa(area_id), | |
914 | area->external_routing == OSPF_AREA_NSSA | |
915 | ? "nssa" | |
916 | : "stub"); | |
917 | else | |
918 | vty_out(vty, "Area %ld is %s\n", | |
919 | (unsigned long)ntohl(area_id.s_addr), | |
920 | area->external_routing == OSPF_AREA_NSSA | |
921 | ? "nssa" | |
922 | : "stub"); | |
923 | return NULL; | |
924 | } | |
925 | ||
926 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
927 | == NULL) { | |
928 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
929 | if (vl_data->vl_oi == NULL) { | |
930 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
931 | ospf_vl_add(ospf, vl_data); | |
932 | ospf_spf_calculate_schedule(ospf, | |
933 | SPF_FLAG_CONFIG_CHANGE); | |
934 | } | |
935 | } | |
936 | return vl_data; | |
937 | } | |
938 | ||
939 | ||
940 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, | |
941 | struct ospf_vl_config_data *vl_config) | |
942 | { | |
943 | struct crypt_key *ck; | |
944 | struct vty *vty; | |
945 | struct interface *ifp = vl_data->vl_oi->ifp; | |
946 | ||
947 | vty = vl_config->vty; | |
948 | ||
949 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
950 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
951 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
952 | } | |
953 | ||
954 | if (vl_config->auth_key) { | |
955 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
956 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
957 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, | |
958 | vl_config->auth_key, | |
959 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
960 | } else if (vl_config->md5_key) { | |
961 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
962 | vl_config->crypto_key_id) | |
963 | != NULL) { | |
964 | vty_out(vty, "OSPF: Key %d already exists\n", | |
965 | vl_config->crypto_key_id); | |
966 | return CMD_WARNING; | |
967 | } | |
968 | ck = ospf_crypt_key_new(); | |
969 | ck->key_id = vl_config->crypto_key_id; | |
970 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
971 | strlcpy((char *)ck->auth_key, vl_config->md5_key, | |
972 | sizeof(ck->auth_key)); | |
973 | ||
974 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
975 | } else if (vl_config->crypto_key_id != 0) { | |
976 | /* Delete a key */ | |
977 | ||
978 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
979 | vl_config->crypto_key_id) | |
980 | == NULL) { | |
981 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
982 | vl_config->crypto_key_id); | |
983 | return CMD_WARNING_CONFIG_FAILED; | |
984 | } | |
985 | ||
986 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
987 | vl_config->crypto_key_id); | |
988 | } | |
989 | ||
990 | return CMD_SUCCESS; | |
991 | } | |
992 | ||
993 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, | |
994 | struct ospf_vl_config_data *vl_config) | |
995 | { | |
996 | struct interface *ifp = vl_data->vl_oi->ifp; | |
997 | /* Virtual Link data initialised to defaults, so only set | |
998 | if a value given */ | |
999 | if (vl_config->hello_interval) { | |
1000 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
1001 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
1002 | } | |
1003 | ||
1004 | if (vl_config->dead_interval) { | |
1005 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
1006 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
1007 | } | |
1008 | ||
1009 | if (vl_config->retransmit_interval) { | |
1010 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
1011 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
1012 | vl_config->retransmit_interval; | |
1013 | } | |
1014 | ||
1015 | if (vl_config->transmit_delay) { | |
1016 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
1017 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
1018 | } | |
1019 | ||
1020 | return CMD_SUCCESS; | |
1021 | } | |
1022 | ||
1023 | ||
1024 | /* The business end of all of the above */ | |
1025 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) | |
1026 | { | |
1027 | struct ospf_vl_data *vl_data; | |
1028 | int ret; | |
1029 | ||
1030 | vl_data = ospf_find_vl_data(ospf, vl_config); | |
1031 | if (!vl_data) | |
1032 | return CMD_WARNING_CONFIG_FAILED; | |
1033 | ||
1034 | /* Process this one first as it can have a fatal result, which can | |
1035 | only logically occur if the virtual link exists already | |
1036 | Thus a command error does not result in a change to the | |
1037 | running configuration such as unexpectedly altered timer | |
1038 | values etc.*/ | |
1039 | ret = ospf_vl_set_security(vl_data, vl_config); | |
1040 | if (ret != CMD_SUCCESS) | |
1041 | return ret; | |
1042 | ||
1043 | /* Set any time based parameters, these area already range checked */ | |
1044 | ||
1045 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1046 | if (ret != CMD_SUCCESS) | |
1047 | return ret; | |
1048 | ||
1049 | return CMD_SUCCESS; | |
1050 | } | |
1051 | ||
1052 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1053 | */ | |
1054 | #define VLINK_HELPSTR_IPADDR \ | |
1055 | "OSPF area parameters\n" \ | |
1056 | "OSPF area ID in IP address format\n" \ | |
1057 | "OSPF area ID as a decimal value\n" \ | |
1058 | "Configure a virtual link\n" \ | |
1059 | "Router ID of the remote ABR\n" | |
1060 | ||
1061 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1062 | "Enable authentication on this virtual link\n" \ | |
1063 | "dummy string \n" | |
1064 | ||
1065 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1066 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1067 | "Use null authentication\n" \ | |
1068 | "Use message-digest authentication\n" | |
1069 | ||
1070 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1071 | "Time between HELLO packets\n" \ | |
1072 | "Seconds\n" \ | |
1073 | "Time between retransmitting lost link state advertisements\n" \ | |
1074 | "Seconds\n" \ | |
1075 | "Link state transmit delay\n" \ | |
1076 | "Seconds\n" \ | |
1077 | "Interval time after which a neighbor is declared down\n" \ | |
1078 | "Seconds\n" | |
1079 | ||
1080 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1081 | "Authentication password (key)\n" \ | |
1082 | "The OSPF password (key)\n" | |
1083 | ||
1084 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1085 | "Message digest authentication password (key)\n" \ | |
1086 | "Key ID\n" \ | |
1087 | "Use MD5 algorithm\n" \ | |
1088 | "The OSPF password (key)\n" | |
1089 | ||
1090 | DEFUN (ospf_area_vlink, | |
1091 | ospf_area_vlink_cmd, | |
1092 | "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>]", | |
1093 | VLINK_HELPSTR_IPADDR | |
1094 | "Enable authentication on this virtual link\n" | |
1095 | "Use message-digest authentication\n" | |
1096 | "Use null authentication\n" | |
1097 | VLINK_HELPSTR_AUTH_MD5 | |
1098 | VLINK_HELPSTR_AUTH_SIMPLE) | |
1099 | { | |
1100 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1101 | int idx_ipv4_number = 1; | |
1102 | int idx_ipv4 = 3; | |
1103 | struct ospf_vl_config_data vl_config; | |
1104 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1105 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
1106 | int ret; | |
1107 | int idx = 0; | |
1108 | ||
1109 | ospf_vl_config_data_init(&vl_config, vty); | |
1110 | ||
1111 | /* Read off first 2 parameters and check them */ | |
1112 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1113 | &vl_config.area_id_fmt); | |
1114 | if (ret < 0) { | |
1115 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1116 | return CMD_WARNING_CONFIG_FAILED; | |
1117 | } | |
1118 | ||
1119 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1120 | if (!ret) { | |
1121 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1122 | return CMD_WARNING_CONFIG_FAILED; | |
1123 | } | |
1124 | ||
1125 | if (argc <= 4) { | |
1126 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
1127 | ||
1128 | return ospf_vl_set(ospf, &vl_config); | |
1129 | } | |
1130 | ||
1131 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1132 | /* authentication - this option can only occur | |
1133 | at start of command line */ | |
1134 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1135 | } | |
1136 | ||
1137 | if (argv_find(argv, argc, "message-digest", &idx)) { | |
1138 | /* authentication message-digest */ | |
1139 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
1140 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1141 | /* "authentication null" */ | |
1142 | vl_config.auth_type = OSPF_AUTH_NULL; | |
1143 | } | |
1144 | ||
1145 | if (argv_find(argv, argc, "message-digest-key", &idx)) { | |
1146 | vl_config.md5_key = NULL; | |
1147 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); | |
1148 | if (vl_config.crypto_key_id < 0) | |
1149 | return CMD_WARNING_CONFIG_FAILED; | |
1150 | ||
1151 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); | |
1152 | vl_config.md5_key = md5_key; | |
1153 | } | |
1154 | ||
1155 | if (argv_find(argv, argc, "authentication-key", &idx)) { | |
1156 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); | |
1157 | vl_config.auth_key = auth_key; | |
1158 | } | |
1159 | ||
1160 | /* Action configuration */ | |
1161 | ||
1162 | return ospf_vl_set(ospf, &vl_config); | |
1163 | } | |
1164 | ||
1165 | DEFUN (no_ospf_area_vlink, | |
1166 | no_ospf_area_vlink_cmd, | |
1167 | "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>]", | |
1168 | NO_STR | |
1169 | VLINK_HELPSTR_IPADDR | |
1170 | "Enable authentication on this virtual link\n" \ | |
1171 | "Use message-digest authentication\n" \ | |
1172 | "Use null authentication\n" \ | |
1173 | VLINK_HELPSTR_AUTH_MD5 | |
1174 | VLINK_HELPSTR_AUTH_SIMPLE) | |
1175 | { | |
1176 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1177 | int idx_ipv4_number = 2; | |
1178 | int idx_ipv4 = 4; | |
1179 | struct ospf_area *area; | |
1180 | struct ospf_vl_config_data vl_config; | |
1181 | struct ospf_vl_data *vl_data = NULL; | |
1182 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1183 | int idx = 0; | |
1184 | int ret, format; | |
1185 | ||
1186 | ospf_vl_config_data_init(&vl_config, vty); | |
1187 | ||
1188 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1189 | &format); | |
1190 | if (ret < 0) { | |
1191 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1192 | return CMD_WARNING_CONFIG_FAILED; | |
1193 | } | |
1194 | ||
1195 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1196 | if (!area) { | |
1197 | vty_out(vty, "Area does not exist\n"); | |
1198 | return CMD_WARNING_CONFIG_FAILED; | |
1199 | } | |
1200 | ||
1201 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1202 | if (!ret) { | |
1203 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1204 | return CMD_WARNING_CONFIG_FAILED; | |
1205 | } | |
1206 | ||
1207 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); | |
1208 | if (!vl_data) { | |
1209 | vty_out(vty, "Virtual link does not exist\n"); | |
1210 | return CMD_WARNING_CONFIG_FAILED; | |
1211 | } | |
1212 | ||
1213 | if (argc <= 5) { | |
1214 | /* Basic VLink no command */ | |
1215 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
1216 | ospf_vl_delete(ospf, vl_data); | |
1217 | ospf_area_check_free(ospf, vl_config.area_id); | |
1218 | return CMD_SUCCESS; | |
1219 | } | |
1220 | ||
1221 | /* If we are down here, we are reseting parameters */ | |
1222 | /* Deal with other parameters */ | |
1223 | ||
1224 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1225 | /* authentication - this option can only occur | |
1226 | at start of command line */ | |
1227 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1228 | } | |
1229 | ||
1230 | if (argv_find(argv, argc, "message-digest-key", &idx)) { | |
1231 | vl_config.md5_key = NULL; | |
1232 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); | |
1233 | if (vl_config.crypto_key_id < 0) | |
1234 | return CMD_WARNING_CONFIG_FAILED; | |
1235 | } | |
1236 | ||
1237 | if (argv_find(argv, argc, "authentication-key", &idx)) { | |
1238 | /* Reset authentication-key to 0 */ | |
1239 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); | |
1240 | vl_config.auth_key = auth_key; | |
1241 | } | |
1242 | ||
1243 | /* Action configuration */ | |
1244 | ||
1245 | return ospf_vl_set(ospf, &vl_config); | |
1246 | } | |
1247 | ||
1248 | DEFUN (ospf_area_vlink_intervals, | |
1249 | ospf_area_vlink_intervals_cmd, | |
1250 | "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)}", | |
1251 | VLINK_HELPSTR_IPADDR | |
1252 | VLINK_HELPSTR_TIME_PARAM) | |
1253 | { | |
1254 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1255 | struct ospf_vl_config_data vl_config; | |
1256 | int ret = 0; | |
1257 | ||
1258 | ospf_vl_config_data_init(&vl_config, vty); | |
1259 | ||
1260 | char *area_id = argv[1]->arg; | |
1261 | char *router_id = argv[3]->arg; | |
1262 | ||
1263 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1264 | if (ret < 0) { | |
1265 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1266 | return CMD_WARNING_CONFIG_FAILED; | |
1267 | } | |
1268 | ||
1269 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1270 | if (!ret) { | |
1271 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1272 | return CMD_WARNING_CONFIG_FAILED; | |
1273 | } | |
1274 | ||
1275 | for (int idx = 4; idx < argc; idx++) { | |
1276 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1277 | vl_config.hello_interval = | |
1278 | strtol(argv[++idx]->arg, NULL, 10); | |
1279 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1280 | vl_config.retransmit_interval = | |
1281 | strtol(argv[++idx]->arg, NULL, 10); | |
1282 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1283 | vl_config.transmit_delay = | |
1284 | strtol(argv[++idx]->arg, NULL, 10); | |
1285 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1286 | vl_config.dead_interval = | |
1287 | strtol(argv[++idx]->arg, NULL, 10); | |
1288 | } | |
1289 | ||
1290 | /* Action configuration */ | |
1291 | return ospf_vl_set(ospf, &vl_config); | |
1292 | } | |
1293 | ||
1294 | DEFUN (no_ospf_area_vlink_intervals, | |
1295 | no_ospf_area_vlink_intervals_cmd, | |
1296 | "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)}", | |
1297 | NO_STR | |
1298 | VLINK_HELPSTR_IPADDR | |
1299 | VLINK_HELPSTR_TIME_PARAM) | |
1300 | { | |
1301 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1302 | struct ospf_vl_config_data vl_config; | |
1303 | int ret = 0; | |
1304 | ||
1305 | ospf_vl_config_data_init(&vl_config, vty); | |
1306 | ||
1307 | char *area_id = argv[2]->arg; | |
1308 | char *router_id = argv[4]->arg; | |
1309 | ||
1310 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1311 | if (ret < 0) { | |
1312 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1313 | return CMD_WARNING_CONFIG_FAILED; | |
1314 | } | |
1315 | ||
1316 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1317 | if (!ret) { | |
1318 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1319 | return CMD_WARNING_CONFIG_FAILED; | |
1320 | } | |
1321 | ||
1322 | for (int idx = 5; idx < argc; idx++) { | |
1323 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1324 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1325 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1326 | vl_config.retransmit_interval = | |
1327 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1328 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1329 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1330 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1331 | vl_config.dead_interval = | |
1332 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1333 | } | |
1334 | ||
1335 | /* Action configuration */ | |
1336 | return ospf_vl_set(ospf, &vl_config); | |
1337 | } | |
1338 | ||
1339 | DEFUN (ospf_area_shortcut, | |
1340 | ospf_area_shortcut_cmd, | |
1341 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", | |
1342 | "OSPF area parameters\n" | |
1343 | "OSPF area ID in IP address format\n" | |
1344 | "OSPF area ID as a decimal value\n" | |
1345 | "Configure the area's shortcutting mode\n" | |
1346 | "Set default shortcutting behavior\n" | |
1347 | "Enable shortcutting through the area\n" | |
1348 | "Disable shortcutting through the area\n") | |
1349 | { | |
1350 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1351 | int idx_ipv4_number = 1; | |
1352 | int idx_enable_disable = 3; | |
1353 | struct ospf_area *area; | |
1354 | struct in_addr area_id; | |
1355 | int mode; | |
1356 | int format; | |
1357 | ||
1358 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1359 | argv[idx_ipv4_number]->arg); | |
1360 | ||
1361 | area = ospf_area_get(ospf, area_id); | |
1362 | ospf_area_display_format_set(ospf, area, format); | |
1363 | ||
1364 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1365 | mode = OSPF_SHORTCUT_DEFAULT; | |
1366 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1367 | mode = OSPF_SHORTCUT_DISABLE; | |
1368 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1369 | mode = OSPF_SHORTCUT_ENABLE; | |
1370 | else | |
1371 | return CMD_WARNING_CONFIG_FAILED; | |
1372 | ||
1373 | ospf_area_shortcut_set(ospf, area, mode); | |
1374 | ||
1375 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) | |
1376 | vty_out(vty, | |
1377 | "Shortcut area setting will take effect " | |
1378 | "only when the router is configured as Shortcut ABR\n"); | |
1379 | ||
1380 | return CMD_SUCCESS; | |
1381 | } | |
1382 | ||
1383 | DEFUN (no_ospf_area_shortcut, | |
1384 | no_ospf_area_shortcut_cmd, | |
1385 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", | |
1386 | NO_STR | |
1387 | "OSPF area parameters\n" | |
1388 | "OSPF area ID in IP address format\n" | |
1389 | "OSPF area ID as a decimal value\n" | |
1390 | "Deconfigure the area's shortcutting mode\n" | |
1391 | "Deconfigure enabled shortcutting through the area\n" | |
1392 | "Deconfigure disabled shortcutting through the area\n") | |
1393 | { | |
1394 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1395 | int idx_ipv4_number = 2; | |
1396 | struct ospf_area *area; | |
1397 | struct in_addr area_id; | |
1398 | int format; | |
1399 | ||
1400 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1401 | argv[idx_ipv4_number]->arg); | |
1402 | ||
1403 | area = ospf_area_lookup_by_area_id(ospf, area_id); | |
1404 | if (!area) | |
1405 | return CMD_SUCCESS; | |
1406 | ||
1407 | ospf_area_shortcut_unset(ospf, area); | |
1408 | ||
1409 | return CMD_SUCCESS; | |
1410 | } | |
1411 | ||
1412 | ||
1413 | DEFUN (ospf_area_stub, | |
1414 | ospf_area_stub_cmd, | |
1415 | "area <A.B.C.D|(0-4294967295)> stub", | |
1416 | "OSPF area parameters\n" | |
1417 | "OSPF area ID in IP address format\n" | |
1418 | "OSPF area ID as a decimal value\n" | |
1419 | "Configure OSPF area as stub\n") | |
1420 | { | |
1421 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1422 | int idx_ipv4_number = 1; | |
1423 | struct in_addr area_id; | |
1424 | int ret, format; | |
1425 | ||
1426 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1427 | argv[idx_ipv4_number]->arg); | |
1428 | ||
1429 | ret = ospf_area_stub_set(ospf, area_id); | |
1430 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1431 | format); | |
1432 | if (ret == 0) { | |
1433 | vty_out(vty, | |
1434 | "First deconfigure all virtual link through this area\n"); | |
1435 | return CMD_WARNING_CONFIG_FAILED; | |
1436 | } | |
1437 | ||
1438 | ospf_area_no_summary_unset(ospf, area_id); | |
1439 | ||
1440 | return CMD_SUCCESS; | |
1441 | } | |
1442 | ||
1443 | DEFUN (ospf_area_stub_no_summary, | |
1444 | ospf_area_stub_no_summary_cmd, | |
1445 | "area <A.B.C.D|(0-4294967295)> stub no-summary", | |
1446 | "OSPF stub parameters\n" | |
1447 | "OSPF area ID in IP address format\n" | |
1448 | "OSPF area ID as a decimal value\n" | |
1449 | "Configure OSPF area as stub\n" | |
1450 | "Do not inject inter-area routes into stub\n") | |
1451 | { | |
1452 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1453 | int idx_ipv4_number = 1; | |
1454 | struct in_addr area_id; | |
1455 | int ret, format; | |
1456 | ||
1457 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1458 | argv[idx_ipv4_number]->arg); | |
1459 | ||
1460 | ret = ospf_area_stub_set(ospf, area_id); | |
1461 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1462 | format); | |
1463 | if (ret == 0) { | |
1464 | vty_out(vty, | |
1465 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1466 | return CMD_WARNING_CONFIG_FAILED; | |
1467 | } | |
1468 | ||
1469 | ospf_area_no_summary_set(ospf, area_id); | |
1470 | ||
1471 | return CMD_SUCCESS; | |
1472 | } | |
1473 | ||
1474 | DEFUN (no_ospf_area_stub, | |
1475 | no_ospf_area_stub_cmd, | |
1476 | "no area <A.B.C.D|(0-4294967295)> stub", | |
1477 | NO_STR | |
1478 | "OSPF area parameters\n" | |
1479 | "OSPF area ID in IP address format\n" | |
1480 | "OSPF area ID as a decimal value\n" | |
1481 | "Configure OSPF area as stub\n") | |
1482 | { | |
1483 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1484 | int idx_ipv4_number = 2; | |
1485 | struct in_addr area_id; | |
1486 | int format; | |
1487 | ||
1488 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1489 | argv[idx_ipv4_number]->arg); | |
1490 | ||
1491 | ospf_area_stub_unset(ospf, area_id); | |
1492 | ospf_area_no_summary_unset(ospf, area_id); | |
1493 | ||
1494 | return CMD_SUCCESS; | |
1495 | } | |
1496 | ||
1497 | DEFUN (no_ospf_area_stub_no_summary, | |
1498 | no_ospf_area_stub_no_summary_cmd, | |
1499 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", | |
1500 | NO_STR | |
1501 | "OSPF area parameters\n" | |
1502 | "OSPF area ID in IP address format\n" | |
1503 | "OSPF area ID as a decimal value\n" | |
1504 | "Configure OSPF area as stub\n" | |
1505 | "Do not inject inter-area routes into area\n") | |
1506 | { | |
1507 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1508 | int idx_ipv4_number = 2; | |
1509 | struct in_addr area_id; | |
1510 | int format; | |
1511 | ||
1512 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1513 | argv[idx_ipv4_number]->arg); | |
1514 | ospf_area_no_summary_unset(ospf, area_id); | |
1515 | ||
1516 | return CMD_SUCCESS; | |
1517 | } | |
1518 | ||
1519 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, | |
1520 | struct cmd_token **argv, int cfg_nosum, | |
1521 | int nosum) | |
1522 | { | |
1523 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1524 | struct in_addr area_id; | |
1525 | int ret, format; | |
1526 | ||
1527 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1528 | ||
1529 | ret = ospf_area_nssa_set(ospf, area_id); | |
1530 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1531 | format); | |
1532 | if (ret == 0) { | |
1533 | vty_out(vty, | |
1534 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1535 | return CMD_WARNING_CONFIG_FAILED; | |
1536 | } | |
1537 | ||
1538 | if (argc > 3) { | |
1539 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1540 | ospf_area_nssa_translator_role_set( | |
1541 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1542 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1543 | ospf_area_nssa_translator_role_set( | |
1544 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1545 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1546 | ospf_area_nssa_translator_role_set( | |
1547 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1548 | } else { | |
1549 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1550 | OSPF_NSSA_ROLE_CANDIDATE); | |
1551 | } | |
1552 | ||
1553 | if (cfg_nosum) { | |
1554 | if (nosum) | |
1555 | ospf_area_no_summary_set(ospf, area_id); | |
1556 | else | |
1557 | ospf_area_no_summary_unset(ospf, area_id); | |
1558 | } | |
1559 | ||
1560 | ospf_schedule_abr_task(ospf); | |
1561 | ||
1562 | return CMD_SUCCESS; | |
1563 | } | |
1564 | ||
1565 | ||
1566 | DEFUN (ospf_area_nssa_translate, | |
1567 | ospf_area_nssa_translate_cmd, | |
1568 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", | |
1569 | "OSPF area parameters\n" | |
1570 | "OSPF area ID in IP address format\n" | |
1571 | "OSPF area ID as a decimal value\n" | |
1572 | "Configure OSPF area as nssa\n" | |
1573 | "Configure NSSA-ABR for translate election (default)\n" | |
1574 | "Configure NSSA-ABR to never translate\n" | |
1575 | "Configure NSSA-ABR to always translate\n") | |
1576 | { | |
1577 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); | |
1578 | } | |
1579 | ||
1580 | DEFUN (ospf_area_nssa, | |
1581 | ospf_area_nssa_cmd, | |
1582 | "area <A.B.C.D|(0-4294967295)> nssa", | |
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 | { | |
1588 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); | |
1589 | } | |
1590 | ||
1591 | DEFUN (ospf_area_nssa_no_summary, | |
1592 | ospf_area_nssa_no_summary_cmd, | |
1593 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1594 | "OSPF area parameters\n" | |
1595 | "OSPF area ID in IP address format\n" | |
1596 | "OSPF area ID as a decimal value\n" | |
1597 | "Configure OSPF area as nssa\n" | |
1598 | "Do not inject inter-area routes into nssa\n") | |
1599 | { | |
1600 | int idx_ipv4_number = 1; | |
1601 | struct in_addr area_id; | |
1602 | int format; | |
1603 | ||
1604 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1605 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1606 | argv[idx_ipv4_number]->arg); | |
1607 | ||
1608 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1609 | format); | |
1610 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1611 | ||
1612 | ospf_schedule_abr_task(ospf); | |
1613 | ||
1614 | return CMD_SUCCESS; | |
1615 | } | |
1616 | ||
1617 | DEFUN (no_ospf_area_nssa_no_summary, | |
1618 | no_ospf_area_nssa_no_summary_cmd, | |
1619 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1620 | NO_STR | |
1621 | "OSPF area parameters\n" | |
1622 | "OSPF area ID in IP address format\n" | |
1623 | "OSPF area ID as a decimal value\n" | |
1624 | "Configure OSPF area as nssa\n" | |
1625 | "Do not inject inter-area routes into nssa\n") | |
1626 | { | |
1627 | int idx_ipv4_number = 2; | |
1628 | struct in_addr area_id; | |
1629 | int format; | |
1630 | ||
1631 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1632 | ||
1633 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1634 | argv[idx_ipv4_number]->arg); | |
1635 | ||
1636 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1637 | format); | |
1638 | ospf_area_no_summary_unset(ospf, area_id); | |
1639 | ||
1640 | ospf_schedule_abr_task(ospf); | |
1641 | ||
1642 | return CMD_SUCCESS; | |
1643 | } | |
1644 | ||
1645 | DEFUN (no_ospf_area_nssa, | |
1646 | no_ospf_area_nssa_cmd, | |
1647 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", | |
1648 | NO_STR | |
1649 | "OSPF area parameters\n" | |
1650 | "OSPF area ID in IP address format\n" | |
1651 | "OSPF area ID as a decimal value\n" | |
1652 | "Configure OSPF area as nssa\n" | |
1653 | "Configure NSSA-ABR for translate election (default)\n" | |
1654 | "Configure NSSA-ABR to never translate\n" | |
1655 | "Configure NSSA-ABR to always translate\n") | |
1656 | { | |
1657 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1658 | int idx_ipv4_number = 2; | |
1659 | struct in_addr area_id; | |
1660 | int format; | |
1661 | ||
1662 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1663 | argv[idx_ipv4_number]->arg); | |
1664 | ||
1665 | ospf_area_nssa_unset(ospf, area_id, argc); | |
1666 | ||
1667 | ospf_schedule_abr_task(ospf); | |
1668 | ||
1669 | return CMD_SUCCESS; | |
1670 | } | |
1671 | ||
1672 | ||
1673 | DEFUN (ospf_area_default_cost, | |
1674 | ospf_area_default_cost_cmd, | |
1675 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", | |
1676 | "OSPF area parameters\n" | |
1677 | "OSPF area ID in IP address format\n" | |
1678 | "OSPF area ID as a decimal value\n" | |
1679 | "Set the summary-default cost of a NSSA or stub area\n" | |
1680 | "Stub's advertised default summary cost\n") | |
1681 | { | |
1682 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1683 | int idx_ipv4_number = 1; | |
1684 | int idx_number = 3; | |
1685 | struct ospf_area *area; | |
1686 | struct in_addr area_id; | |
1687 | uint32_t cost; | |
1688 | int format; | |
1689 | struct prefix_ipv4 p; | |
1690 | ||
1691 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1692 | argv[idx_ipv4_number]->arg); | |
1693 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1694 | ||
1695 | area = ospf_area_get(ospf, area_id); | |
1696 | ospf_area_display_format_set(ospf, area, format); | |
1697 | ||
1698 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1699 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1700 | return CMD_WARNING_CONFIG_FAILED; | |
1701 | } | |
1702 | ||
1703 | area->default_cost = cost; | |
1704 | ||
1705 | p.family = AF_INET; | |
1706 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1707 | p.prefixlen = 0; | |
1708 | if (IS_DEBUG_OSPF_EVENT) | |
1709 | zlog_debug( | |
1710 | "ospf_abr_announce_stub_defaults(): " | |
1711 | "announcing 0.0.0.0/0 to area %s", | |
1712 | inet_ntoa(area->area_id)); | |
1713 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
1714 | ||
1715 | return CMD_SUCCESS; | |
1716 | } | |
1717 | ||
1718 | DEFUN (no_ospf_area_default_cost, | |
1719 | no_ospf_area_default_cost_cmd, | |
1720 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", | |
1721 | NO_STR | |
1722 | "OSPF area parameters\n" | |
1723 | "OSPF area ID in IP address format\n" | |
1724 | "OSPF area ID as a decimal value\n" | |
1725 | "Set the summary-default cost of a NSSA or stub area\n" | |
1726 | "Stub's advertised default summary cost\n") | |
1727 | { | |
1728 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1729 | int idx_ipv4_number = 2; | |
1730 | struct ospf_area *area; | |
1731 | struct in_addr area_id; | |
1732 | int format; | |
1733 | struct prefix_ipv4 p; | |
1734 | ||
1735 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1736 | argv[idx_ipv4_number]->arg); | |
1737 | ||
1738 | area = ospf_area_lookup_by_area_id(ospf, area_id); | |
1739 | if (area == NULL) | |
1740 | return CMD_SUCCESS; | |
1741 | ||
1742 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1743 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1744 | return CMD_WARNING_CONFIG_FAILED; | |
1745 | } | |
1746 | ||
1747 | area->default_cost = 1; | |
1748 | ||
1749 | p.family = AF_INET; | |
1750 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1751 | p.prefixlen = 0; | |
1752 | if (IS_DEBUG_OSPF_EVENT) | |
1753 | zlog_debug( | |
1754 | "ospf_abr_announce_stub_defaults(): " | |
1755 | "announcing 0.0.0.0/0 to area %s", | |
1756 | inet_ntoa(area->area_id)); | |
1757 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
1758 | ||
1759 | ||
1760 | ospf_area_check_free(ospf, area_id); | |
1761 | ||
1762 | return CMD_SUCCESS; | |
1763 | } | |
1764 | ||
1765 | DEFUN (ospf_area_export_list, | |
1766 | ospf_area_export_list_cmd, | |
1767 | "area <A.B.C.D|(0-4294967295)> export-list NAME", | |
1768 | "OSPF area parameters\n" | |
1769 | "OSPF area ID in IP address format\n" | |
1770 | "OSPF area ID as a decimal value\n" | |
1771 | "Set the filter for networks announced to other areas\n" | |
1772 | "Name of the access-list\n") | |
1773 | { | |
1774 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1775 | int idx_ipv4_number = 1; | |
1776 | struct ospf_area *area; | |
1777 | struct in_addr area_id; | |
1778 | int format; | |
1779 | ||
1780 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1781 | ||
1782 | area = ospf_area_get(ospf, area_id); | |
1783 | ospf_area_display_format_set(ospf, area, format); | |
1784 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
1785 | ||
1786 | return CMD_SUCCESS; | |
1787 | } | |
1788 | ||
1789 | DEFUN (no_ospf_area_export_list, | |
1790 | no_ospf_area_export_list_cmd, | |
1791 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", | |
1792 | NO_STR | |
1793 | "OSPF area parameters\n" | |
1794 | "OSPF area ID in IP address format\n" | |
1795 | "OSPF area ID as a decimal value\n" | |
1796 | "Unset the filter for networks announced to other areas\n" | |
1797 | "Name of the access-list\n") | |
1798 | { | |
1799 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1800 | int idx_ipv4_number = 2; | |
1801 | struct ospf_area *area; | |
1802 | struct in_addr area_id; | |
1803 | int format; | |
1804 | ||
1805 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1806 | ||
1807 | area = ospf_area_lookup_by_area_id(ospf, area_id); | |
1808 | if (area == NULL) | |
1809 | return CMD_SUCCESS; | |
1810 | ||
1811 | ospf_area_export_list_unset(ospf, area); | |
1812 | ||
1813 | return CMD_SUCCESS; | |
1814 | } | |
1815 | ||
1816 | ||
1817 | DEFUN (ospf_area_import_list, | |
1818 | ospf_area_import_list_cmd, | |
1819 | "area <A.B.C.D|(0-4294967295)> import-list NAME", | |
1820 | "OSPF area parameters\n" | |
1821 | "OSPF area ID in IP address format\n" | |
1822 | "OSPF area ID as a decimal value\n" | |
1823 | "Set the filter for networks from other areas announced to the specified one\n" | |
1824 | "Name of the access-list\n") | |
1825 | { | |
1826 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1827 | int idx_ipv4_number = 1; | |
1828 | struct ospf_area *area; | |
1829 | struct in_addr area_id; | |
1830 | int format; | |
1831 | ||
1832 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1833 | ||
1834 | area = ospf_area_get(ospf, area_id); | |
1835 | ospf_area_display_format_set(ospf, area, format); | |
1836 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
1837 | ||
1838 | return CMD_SUCCESS; | |
1839 | } | |
1840 | ||
1841 | DEFUN (no_ospf_area_import_list, | |
1842 | no_ospf_area_import_list_cmd, | |
1843 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", | |
1844 | NO_STR | |
1845 | "OSPF area parameters\n" | |
1846 | "OSPF area ID in IP address format\n" | |
1847 | "OSPF area ID as a decimal value\n" | |
1848 | "Unset the filter for networks announced to other areas\n" | |
1849 | "Name of the access-list\n") | |
1850 | { | |
1851 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1852 | int idx_ipv4_number = 2; | |
1853 | struct ospf_area *area; | |
1854 | struct in_addr area_id; | |
1855 | int format; | |
1856 | ||
1857 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1858 | ||
1859 | area = ospf_area_lookup_by_area_id(ospf, area_id); | |
1860 | if (area == NULL) | |
1861 | return CMD_SUCCESS; | |
1862 | ||
1863 | ospf_area_import_list_unset(ospf, area); | |
1864 | ||
1865 | return CMD_SUCCESS; | |
1866 | } | |
1867 | ||
1868 | DEFUN (ospf_area_filter_list, | |
1869 | ospf_area_filter_list_cmd, | |
1870 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", | |
1871 | "OSPF area parameters\n" | |
1872 | "OSPF area ID in IP address format\n" | |
1873 | "OSPF area ID as a decimal value\n" | |
1874 | "Filter networks between OSPF areas\n" | |
1875 | "Filter prefixes between OSPF areas\n" | |
1876 | "Name of an IP prefix-list\n" | |
1877 | "Filter networks sent to this area\n" | |
1878 | "Filter networks sent from this area\n") | |
1879 | { | |
1880 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1881 | int idx_ipv4_number = 1; | |
1882 | int idx_word = 4; | |
1883 | int idx_in_out = 5; | |
1884 | struct ospf_area *area; | |
1885 | struct in_addr area_id; | |
1886 | struct prefix_list *plist; | |
1887 | int format; | |
1888 | ||
1889 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1890 | ||
1891 | area = ospf_area_get(ospf, area_id); | |
1892 | ospf_area_display_format_set(ospf, area, format); | |
1893 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1894 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1895 | PREFIX_LIST_IN(area) = plist; | |
1896 | if (PREFIX_NAME_IN(area)) | |
1897 | free(PREFIX_NAME_IN(area)); | |
1898 | ||
1899 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1900 | ospf_schedule_abr_task(ospf); | |
1901 | } else { | |
1902 | PREFIX_LIST_OUT(area) = plist; | |
1903 | if (PREFIX_NAME_OUT(area)) | |
1904 | free(PREFIX_NAME_OUT(area)); | |
1905 | ||
1906 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1907 | ospf_schedule_abr_task(ospf); | |
1908 | } | |
1909 | ||
1910 | return CMD_SUCCESS; | |
1911 | } | |
1912 | ||
1913 | DEFUN (no_ospf_area_filter_list, | |
1914 | no_ospf_area_filter_list_cmd, | |
1915 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", | |
1916 | NO_STR | |
1917 | "OSPF area parameters\n" | |
1918 | "OSPF area ID in IP address format\n" | |
1919 | "OSPF area ID as a decimal value\n" | |
1920 | "Filter networks between OSPF areas\n" | |
1921 | "Filter prefixes between OSPF areas\n" | |
1922 | "Name of an IP prefix-list\n" | |
1923 | "Filter networks sent to this area\n" | |
1924 | "Filter networks sent from this area\n") | |
1925 | { | |
1926 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1927 | int idx_ipv4_number = 2; | |
1928 | int idx_word = 5; | |
1929 | int idx_in_out = 6; | |
1930 | struct ospf_area *area; | |
1931 | struct in_addr area_id; | |
1932 | int format; | |
1933 | ||
1934 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1935 | ||
1936 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) | |
1937 | return CMD_SUCCESS; | |
1938 | ||
1939 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1940 | if (PREFIX_NAME_IN(area)) | |
1941 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1942 | != 0) | |
1943 | return CMD_SUCCESS; | |
1944 | ||
1945 | PREFIX_LIST_IN(area) = NULL; | |
1946 | if (PREFIX_NAME_IN(area)) | |
1947 | free(PREFIX_NAME_IN(area)); | |
1948 | ||
1949 | PREFIX_NAME_IN(area) = NULL; | |
1950 | ||
1951 | ospf_schedule_abr_task(ospf); | |
1952 | } else { | |
1953 | if (PREFIX_NAME_OUT(area)) | |
1954 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1955 | != 0) | |
1956 | return CMD_SUCCESS; | |
1957 | ||
1958 | PREFIX_LIST_OUT(area) = NULL; | |
1959 | if (PREFIX_NAME_OUT(area)) | |
1960 | free(PREFIX_NAME_OUT(area)); | |
1961 | ||
1962 | PREFIX_NAME_OUT(area) = NULL; | |
1963 | ||
1964 | ospf_schedule_abr_task(ospf); | |
1965 | } | |
1966 | ||
1967 | return CMD_SUCCESS; | |
1968 | } | |
1969 | ||
1970 | ||
1971 | DEFUN (ospf_area_authentication_message_digest, | |
1972 | ospf_area_authentication_message_digest_cmd, | |
1973 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", | |
1974 | NO_STR | |
1975 | "OSPF area parameters\n" | |
1976 | "OSPF area ID in IP address format\n" | |
1977 | "OSPF area ID as a decimal value\n" | |
1978 | "Enable authentication\n" | |
1979 | "Use message-digest authentication\n") | |
1980 | { | |
1981 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1982 | int idx = 0; | |
1983 | struct ospf_area *area; | |
1984 | struct in_addr area_id; | |
1985 | int format; | |
1986 | ||
1987 | argv_find(argv, argc, "area", &idx); | |
1988 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
1989 | ||
1990 | area = ospf_area_get(ospf, area_id); | |
1991 | ospf_area_display_format_set(ospf, area, format); | |
1992 | area->auth_type = strmatch(argv[0]->text, "no") | |
1993 | ? OSPF_AUTH_NULL | |
1994 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
1995 | ||
1996 | return CMD_SUCCESS; | |
1997 | } | |
1998 | ||
1999 | DEFUN (ospf_area_authentication, | |
2000 | ospf_area_authentication_cmd, | |
2001 | "area <A.B.C.D|(0-4294967295)> authentication", | |
2002 | "OSPF area parameters\n" | |
2003 | "OSPF area ID in IP address format\n" | |
2004 | "OSPF area ID as a decimal value\n" | |
2005 | "Enable authentication\n") | |
2006 | { | |
2007 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2008 | int idx_ipv4_number = 1; | |
2009 | struct ospf_area *area; | |
2010 | struct in_addr area_id; | |
2011 | int format; | |
2012 | ||
2013 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
2014 | ||
2015 | area = ospf_area_get(ospf, area_id); | |
2016 | ospf_area_display_format_set(ospf, area, format); | |
2017 | area->auth_type = OSPF_AUTH_SIMPLE; | |
2018 | ||
2019 | return CMD_SUCCESS; | |
2020 | } | |
2021 | ||
2022 | DEFUN (no_ospf_area_authentication, | |
2023 | no_ospf_area_authentication_cmd, | |
2024 | "no area <A.B.C.D|(0-4294967295)> authentication", | |
2025 | NO_STR | |
2026 | "OSPF area parameters\n" | |
2027 | "OSPF area ID in IP address format\n" | |
2028 | "OSPF area ID as a decimal value\n" | |
2029 | "Enable authentication\n") | |
2030 | { | |
2031 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2032 | int idx_ipv4_number = 2; | |
2033 | struct ospf_area *area; | |
2034 | struct in_addr area_id; | |
2035 | int format; | |
2036 | ||
2037 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
2038 | ||
2039 | area = ospf_area_lookup_by_area_id(ospf, area_id); | |
2040 | if (area == NULL) | |
2041 | return CMD_SUCCESS; | |
2042 | ||
2043 | area->auth_type = OSPF_AUTH_NULL; | |
2044 | ||
2045 | ospf_area_check_free(ospf, area_id); | |
2046 | ||
2047 | return CMD_SUCCESS; | |
2048 | } | |
2049 | ||
2050 | ||
2051 | DEFUN (ospf_abr_type, | |
2052 | ospf_abr_type_cmd, | |
2053 | "ospf abr-type <cisco|ibm|shortcut|standard>", | |
2054 | "OSPF specific commands\n" | |
2055 | "Set OSPF ABR type\n" | |
2056 | "Alternative ABR, cisco implementation\n" | |
2057 | "Alternative ABR, IBM implementation\n" | |
2058 | "Shortcut ABR\n" | |
2059 | "Standard behavior (RFC2328)\n") | |
2060 | { | |
2061 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2062 | int idx_vendor = 2; | |
2063 | uint8_t abr_type = OSPF_ABR_UNKNOWN; | |
2064 | ||
2065 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2066 | abr_type = OSPF_ABR_CISCO; | |
2067 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2068 | abr_type = OSPF_ABR_IBM; | |
2069 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2070 | abr_type = OSPF_ABR_SHORTCUT; | |
2071 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2072 | abr_type = OSPF_ABR_STAND; | |
2073 | else | |
2074 | return CMD_WARNING_CONFIG_FAILED; | |
2075 | ||
2076 | /* If ABR type value is changed, schedule ABR task. */ | |
2077 | if (ospf->abr_type != abr_type) { | |
2078 | ospf->abr_type = abr_type; | |
2079 | ospf_schedule_abr_task(ospf); | |
2080 | } | |
2081 | ||
2082 | return CMD_SUCCESS; | |
2083 | } | |
2084 | ||
2085 | DEFUN (no_ospf_abr_type, | |
2086 | no_ospf_abr_type_cmd, | |
2087 | "no ospf abr-type <cisco|ibm|shortcut|standard>", | |
2088 | NO_STR | |
2089 | "OSPF specific commands\n" | |
2090 | "Set OSPF ABR type\n" | |
2091 | "Alternative ABR, cisco implementation\n" | |
2092 | "Alternative ABR, IBM implementation\n" | |
2093 | "Shortcut ABR\n" | |
2094 | "Standard ABR\n") | |
2095 | { | |
2096 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2097 | int idx_vendor = 3; | |
2098 | uint8_t abr_type = OSPF_ABR_UNKNOWN; | |
2099 | ||
2100 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2101 | abr_type = OSPF_ABR_CISCO; | |
2102 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2103 | abr_type = OSPF_ABR_IBM; | |
2104 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2105 | abr_type = OSPF_ABR_SHORTCUT; | |
2106 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2107 | abr_type = OSPF_ABR_STAND; | |
2108 | else | |
2109 | return CMD_WARNING_CONFIG_FAILED; | |
2110 | ||
2111 | /* If ABR type value is changed, schedule ABR task. */ | |
2112 | if (ospf->abr_type == abr_type) { | |
2113 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2114 | ospf_schedule_abr_task(ospf); | |
2115 | } | |
2116 | ||
2117 | return CMD_SUCCESS; | |
2118 | } | |
2119 | ||
2120 | DEFUN (ospf_log_adjacency_changes, | |
2121 | ospf_log_adjacency_changes_cmd, | |
2122 | "log-adjacency-changes", | |
2123 | "Log changes in adjacency state\n") | |
2124 | { | |
2125 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2126 | ||
2127 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2128 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2129 | return CMD_SUCCESS; | |
2130 | } | |
2131 | ||
2132 | DEFUN (ospf_log_adjacency_changes_detail, | |
2133 | ospf_log_adjacency_changes_detail_cmd, | |
2134 | "log-adjacency-changes detail", | |
2135 | "Log changes in adjacency state\n" | |
2136 | "Log all state changes\n") | |
2137 | { | |
2138 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2139 | ||
2140 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2141 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2142 | return CMD_SUCCESS; | |
2143 | } | |
2144 | ||
2145 | DEFUN (no_ospf_log_adjacency_changes, | |
2146 | no_ospf_log_adjacency_changes_cmd, | |
2147 | "no log-adjacency-changes", | |
2148 | NO_STR | |
2149 | "Log changes in adjacency state\n") | |
2150 | { | |
2151 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2152 | ||
2153 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2154 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2155 | return CMD_SUCCESS; | |
2156 | } | |
2157 | ||
2158 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2159 | no_ospf_log_adjacency_changes_detail_cmd, | |
2160 | "no log-adjacency-changes detail", | |
2161 | NO_STR | |
2162 | "Log changes in adjacency state\n" | |
2163 | "Log all state changes\n") | |
2164 | { | |
2165 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2166 | ||
2167 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2168 | return CMD_SUCCESS; | |
2169 | } | |
2170 | ||
2171 | DEFUN (ospf_compatible_rfc1583, | |
2172 | ospf_compatible_rfc1583_cmd, | |
2173 | "compatible rfc1583", | |
2174 | "OSPF compatibility list\n" | |
2175 | "compatible with RFC 1583\n") | |
2176 | { | |
2177 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2178 | ||
2179 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { | |
2180 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2181 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2182 | } | |
2183 | return CMD_SUCCESS; | |
2184 | } | |
2185 | ||
2186 | DEFUN (no_ospf_compatible_rfc1583, | |
2187 | no_ospf_compatible_rfc1583_cmd, | |
2188 | "no compatible rfc1583", | |
2189 | NO_STR | |
2190 | "OSPF compatibility list\n" | |
2191 | "compatible with RFC 1583\n") | |
2192 | { | |
2193 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2194 | ||
2195 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { | |
2196 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2197 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2198 | } | |
2199 | return CMD_SUCCESS; | |
2200 | } | |
2201 | ||
2202 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, | |
2203 | "ospf rfc1583compatibility", | |
2204 | "OSPF specific commands\n" | |
2205 | "Enable the RFC1583Compatibility flag\n") | |
2206 | ||
2207 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, | |
2208 | "no ospf rfc1583compatibility", NO_STR | |
2209 | "OSPF specific commands\n" | |
2210 | "Disable the RFC1583Compatibility flag\n") | |
2211 | ||
2212 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, | |
2213 | unsigned int hold, unsigned int max) | |
2214 | { | |
2215 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2216 | ||
2217 | ospf->spf_delay = delay; | |
2218 | ospf->spf_holdtime = hold; | |
2219 | ospf->spf_max_holdtime = max; | |
2220 | ||
2221 | return CMD_SUCCESS; | |
2222 | } | |
2223 | ||
2224 | DEFUN (ospf_timers_min_ls_interval, | |
2225 | ospf_timers_min_ls_interval_cmd, | |
2226 | "timers throttle lsa all (0-5000)", | |
2227 | "Adjust routing timers\n" | |
2228 | "Throttling adaptive timer\n" | |
2229 | "LSA delay between transmissions\n" | |
2230 | "All LSA types\n" | |
2231 | "Delay (msec) between sending LSAs\n") | |
2232 | { | |
2233 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2234 | int idx_number = 4; | |
2235 | unsigned int interval; | |
2236 | ||
2237 | if (argc < 5) { | |
2238 | vty_out(vty, "Insufficient arguments\n"); | |
2239 | return CMD_WARNING_CONFIG_FAILED; | |
2240 | } | |
2241 | ||
2242 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
2243 | ||
2244 | ospf->min_ls_interval = interval; | |
2245 | ||
2246 | return CMD_SUCCESS; | |
2247 | } | |
2248 | ||
2249 | DEFUN (no_ospf_timers_min_ls_interval, | |
2250 | no_ospf_timers_min_ls_interval_cmd, | |
2251 | "no timers throttle lsa all [(0-5000)]", | |
2252 | NO_STR | |
2253 | "Adjust routing timers\n" | |
2254 | "Throttling adaptive timer\n" | |
2255 | "LSA delay between transmissions\n" | |
2256 | "All LSA types\n" | |
2257 | "Delay (msec) between sending LSAs\n") | |
2258 | { | |
2259 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2260 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; | |
2261 | ||
2262 | return CMD_SUCCESS; | |
2263 | } | |
2264 | ||
2265 | DEFUN (ospf_timers_throttle_spf, | |
2266 | ospf_timers_throttle_spf_cmd, | |
2267 | "timers throttle spf (0-600000) (0-600000) (0-600000)", | |
2268 | "Adjust routing timers\n" | |
2269 | "Throttling adaptive timer\n" | |
2270 | "OSPF SPF timers\n" | |
2271 | "Delay (msec) from first change received till SPF calculation\n" | |
2272 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2273 | "Maximum hold time (msec)\n") | |
2274 | { | |
2275 | int idx_number = 3; | |
2276 | int idx_number_2 = 4; | |
2277 | int idx_number_3 = 5; | |
2278 | unsigned int delay, hold, max; | |
2279 | ||
2280 | if (argc < 6) { | |
2281 | vty_out(vty, "Insufficient arguments\n"); | |
2282 | return CMD_WARNING_CONFIG_FAILED; | |
2283 | } | |
2284 | ||
2285 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2286 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2287 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2288 | ||
2289 | return ospf_timers_spf_set(vty, delay, hold, max); | |
2290 | } | |
2291 | ||
2292 | DEFUN (no_ospf_timers_throttle_spf, | |
2293 | no_ospf_timers_throttle_spf_cmd, | |
2294 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", | |
2295 | NO_STR | |
2296 | "Adjust routing timers\n" | |
2297 | "Throttling adaptive timer\n" | |
2298 | "OSPF SPF timers\n" | |
2299 | "Delay (msec) from first change received till SPF calculation\n" | |
2300 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2301 | "Maximum hold time (msec)\n") | |
2302 | { | |
2303 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, | |
2304 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2305 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
2306 | } | |
2307 | ||
2308 | ||
2309 | DEFUN (ospf_timers_lsa_min_arrival, | |
2310 | ospf_timers_lsa_min_arrival_cmd, | |
2311 | "timers lsa min-arrival (0-600000)", | |
2312 | "Adjust routing timers\n" | |
2313 | "OSPF LSA timers\n" | |
2314 | "Minimum delay in receiving new version of a LSA\n" | |
2315 | "Delay in milliseconds\n") | |
2316 | { | |
2317 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2318 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); | |
2319 | return CMD_SUCCESS; | |
2320 | } | |
2321 | ||
2322 | DEFUN (no_ospf_timers_lsa_min_arrival, | |
2323 | no_ospf_timers_lsa_min_arrival_cmd, | |
2324 | "no timers lsa min-arrival [(0-600000)]", | |
2325 | NO_STR | |
2326 | "Adjust routing timers\n" | |
2327 | "OSPF LSA timers\n" | |
2328 | "Minimum delay in receiving new version of a LSA\n" | |
2329 | "Delay in milliseconds\n") | |
2330 | { | |
2331 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2332 | unsigned int minarrival; | |
2333 | ||
2334 | if (argc > 4) { | |
2335 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); | |
2336 | ||
2337 | if (ospf->min_ls_arrival != minarrival | |
2338 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2339 | return CMD_SUCCESS; | |
2340 | } | |
2341 | ||
2342 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; | |
2343 | ||
2344 | return CMD_SUCCESS; | |
2345 | } | |
2346 | ||
2347 | DEFUN (ospf_neighbor, | |
2348 | ospf_neighbor_cmd, | |
2349 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", | |
2350 | NEIGHBOR_STR | |
2351 | "Neighbor IP address\n" | |
2352 | "Neighbor Priority\n" | |
2353 | "Priority\n" | |
2354 | "Dead Neighbor Polling interval\n" | |
2355 | "Seconds\n") | |
2356 | { | |
2357 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2358 | int idx_ipv4 = 1; | |
2359 | int idx_pri = 3; | |
2360 | int idx_poll = 5; | |
2361 | struct in_addr nbr_addr; | |
2362 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2363 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
2364 | ||
2365 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { | |
2366 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2367 | return CMD_WARNING_CONFIG_FAILED; | |
2368 | } | |
2369 | ||
2370 | if (argc > 2) | |
2371 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
2372 | ||
2373 | if (argc > 4) | |
2374 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
2375 | ||
2376 | ospf_nbr_nbma_set(ospf, nbr_addr); | |
2377 | ||
2378 | if (argc > 2) | |
2379 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
2380 | ||
2381 | if (argc > 4) | |
2382 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
2383 | ||
2384 | return CMD_SUCCESS; | |
2385 | } | |
2386 | ||
2387 | DEFUN (ospf_neighbor_poll_interval, | |
2388 | ospf_neighbor_poll_interval_cmd, | |
2389 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2390 | NEIGHBOR_STR | |
2391 | "Neighbor IP address\n" | |
2392 | "Dead Neighbor Polling interval\n" | |
2393 | "Seconds\n" | |
2394 | "OSPF priority of non-broadcast neighbor\n" | |
2395 | "Priority\n") | |
2396 | { | |
2397 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2398 | int idx_ipv4 = 1; | |
2399 | int idx_poll = 3; | |
2400 | int idx_pri = 5; | |
2401 | struct in_addr nbr_addr; | |
2402 | unsigned int priority; | |
2403 | unsigned int interval; | |
2404 | ||
2405 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { | |
2406 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2407 | return CMD_WARNING_CONFIG_FAILED; | |
2408 | } | |
2409 | ||
2410 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
2411 | ||
2412 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) | |
2413 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2414 | ||
2415 | ospf_nbr_nbma_set(ospf, nbr_addr); | |
2416 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
2417 | ||
2418 | if (argc > 4) | |
2419 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
2420 | ||
2421 | return CMD_SUCCESS; | |
2422 | } | |
2423 | ||
2424 | DEFUN (no_ospf_neighbor, | |
2425 | no_ospf_neighbor_cmd, | |
2426 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", | |
2427 | NO_STR | |
2428 | NEIGHBOR_STR | |
2429 | "Neighbor IP address\n" | |
2430 | "Neighbor Priority\n" | |
2431 | "Priority\n" | |
2432 | "Dead Neighbor Polling interval\n" | |
2433 | "Seconds\n") | |
2434 | { | |
2435 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2436 | int idx_ipv4 = 2; | |
2437 | struct in_addr nbr_addr; | |
2438 | ||
2439 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { | |
2440 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2441 | return CMD_WARNING_CONFIG_FAILED; | |
2442 | } | |
2443 | ||
2444 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); | |
2445 | ||
2446 | return CMD_SUCCESS; | |
2447 | } | |
2448 | ||
2449 | DEFUN (no_ospf_neighbor_poll, | |
2450 | no_ospf_neighbor_poll_cmd, | |
2451 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2452 | NO_STR | |
2453 | NEIGHBOR_STR | |
2454 | "Neighbor IP address\n" | |
2455 | "Dead Neighbor Polling interval\n" | |
2456 | "Seconds\n" | |
2457 | "Neighbor Priority\n" | |
2458 | "Priority\n") | |
2459 | { | |
2460 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2461 | int idx_ipv4 = 2; | |
2462 | struct in_addr nbr_addr; | |
2463 | ||
2464 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { | |
2465 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2466 | return CMD_WARNING_CONFIG_FAILED; | |
2467 | } | |
2468 | ||
2469 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); | |
2470 | ||
2471 | return CMD_SUCCESS; | |
2472 | } | |
2473 | ||
2474 | DEFUN (ospf_refresh_timer, | |
2475 | ospf_refresh_timer_cmd, | |
2476 | "refresh timer (10-1800)", | |
2477 | "Adjust refresh parameters\n" | |
2478 | "Set refresh timer\n" | |
2479 | "Timer value in seconds\n") | |
2480 | { | |
2481 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2482 | int idx_number = 2; | |
2483 | unsigned int interval; | |
2484 | ||
2485 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
2486 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2487 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
2488 | ||
2489 | ospf_timers_refresh_set(ospf, interval); | |
2490 | ||
2491 | return CMD_SUCCESS; | |
2492 | } | |
2493 | ||
2494 | DEFUN (no_ospf_refresh_timer, | |
2495 | no_ospf_refresh_timer_val_cmd, | |
2496 | "no refresh timer [(10-1800)]", | |
2497 | NO_STR | |
2498 | "Adjust refresh parameters\n" | |
2499 | "Unset refresh timer\n" | |
2500 | "Timer value in seconds\n") | |
2501 | { | |
2502 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2503 | int idx_number = 3; | |
2504 | unsigned int interval; | |
2505 | ||
2506 | if (argc == 1) { | |
2507 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
2508 | ||
2509 | if (ospf->lsa_refresh_interval != interval | |
2510 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2511 | return CMD_SUCCESS; | |
2512 | } | |
2513 | ||
2514 | ospf_timers_refresh_unset(ospf); | |
2515 | ||
2516 | return CMD_SUCCESS; | |
2517 | } | |
2518 | ||
2519 | ||
2520 | DEFUN (ospf_auto_cost_reference_bandwidth, | |
2521 | ospf_auto_cost_reference_bandwidth_cmd, | |
2522 | "auto-cost reference-bandwidth (1-4294967)", | |
2523 | "Calculate OSPF interface cost according to bandwidth\n" | |
2524 | "Use reference bandwidth method to assign OSPF cost\n" | |
2525 | "The reference bandwidth in terms of Mbits per second\n") | |
2526 | { | |
2527 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2528 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); | |
2529 | int idx_number = 2; | |
2530 | uint32_t refbw; | |
2531 | struct interface *ifp; | |
2532 | ||
2533 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2534 | if (refbw < 1 || refbw > 4294967) { | |
2535 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2536 | return CMD_WARNING_CONFIG_FAILED; | |
2537 | } | |
2538 | ||
2539 | /* If reference bandwidth is changed. */ | |
2540 | if ((refbw) == ospf->ref_bandwidth) | |
2541 | return CMD_SUCCESS; | |
2542 | ||
2543 | ospf->ref_bandwidth = refbw; | |
2544 | FOR_ALL_INTERFACES (vrf, ifp) | |
2545 | ospf_if_recalculate_output_cost(ifp); | |
2546 | ||
2547 | return CMD_SUCCESS; | |
2548 | } | |
2549 | ||
2550 | DEFUN (no_ospf_auto_cost_reference_bandwidth, | |
2551 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
2552 | "no auto-cost reference-bandwidth [(1-4294967)]", | |
2553 | NO_STR | |
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 | { | |
2558 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2559 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); | |
2560 | struct interface *ifp; | |
2561 | ||
2562 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) | |
2563 | return CMD_SUCCESS; | |
2564 | ||
2565 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2566 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2567 | vty_out(vty, | |
2568 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2569 | ||
2570 | FOR_ALL_INTERFACES (vrf, ifp) | |
2571 | ospf_if_recalculate_output_cost(ifp); | |
2572 | ||
2573 | return CMD_SUCCESS; | |
2574 | } | |
2575 | ||
2576 | DEFUN (ospf_write_multiplier, | |
2577 | ospf_write_multiplier_cmd, | |
2578 | "ospf write-multiplier (1-100)", | |
2579 | "OSPF specific commands\n" | |
2580 | "Write multiplier\n" | |
2581 | "Maximum number of interface serviced per write\n") | |
2582 | { | |
2583 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2584 | int idx_number; | |
2585 | uint32_t write_oi_count; | |
2586 | ||
2587 | if (argc == 3) | |
2588 | idx_number = 2; | |
2589 | else | |
2590 | idx_number = 1; | |
2591 | ||
2592 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2593 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2594 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2595 | return CMD_WARNING_CONFIG_FAILED; | |
2596 | } | |
2597 | ||
2598 | ospf->write_oi_count = write_oi_count; | |
2599 | return CMD_SUCCESS; | |
2600 | } | |
2601 | ||
2602 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", | |
2603 | "Write multiplier\n" | |
2604 | "Maximum number of interface serviced per write\n") | |
2605 | ||
2606 | DEFUN (no_ospf_write_multiplier, | |
2607 | no_ospf_write_multiplier_cmd, | |
2608 | "no ospf write-multiplier (1-100)", | |
2609 | NO_STR | |
2610 | "OSPF specific commands\n" | |
2611 | "Write multiplier\n" | |
2612 | "Maximum number of interface serviced per write\n") | |
2613 | { | |
2614 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2615 | ||
2616 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; | |
2617 | return CMD_SUCCESS; | |
2618 | } | |
2619 | ||
2620 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, | |
2621 | "no write-multiplier (1-100)", NO_STR | |
2622 | "Write multiplier\n" | |
2623 | "Maximum number of interface serviced per write\n") | |
2624 | ||
2625 | static const char *const ospf_abr_type_descr_str[] = { | |
2626 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2627 | "Alternative Cisco", "Alternative Shortcut" | |
2628 | }; | |
2629 | ||
2630 | static const char *const ospf_shortcut_mode_descr_str[] = { | |
2631 | "Default", "Enabled", "Disabled" | |
2632 | }; | |
2633 | ||
2634 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
2635 | json_object *json_areas, bool use_json) | |
2636 | { | |
2637 | json_object *json_area = NULL; | |
2638 | ||
2639 | if (use_json) | |
2640 | json_area = json_object_new_object(); | |
2641 | ||
2642 | /* Show Area ID. */ | |
2643 | if (!use_json) | |
2644 | vty_out(vty, " Area ID: %s", inet_ntoa(area->area_id)); | |
2645 | ||
2646 | /* Show Area type/mode. */ | |
2647 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2648 | if (use_json) | |
2649 | json_object_boolean_true_add(json_area, "backbone"); | |
2650 | else | |
2651 | vty_out(vty, " (Backbone)\n"); | |
2652 | } else { | |
2653 | if (use_json) { | |
2654 | if (area->external_routing == OSPF_AREA_STUB) { | |
2655 | if (area->no_summary) | |
2656 | json_object_boolean_true_add( | |
2657 | json_area, "stubNoSummary"); | |
2658 | if (area->shortcut_configured) | |
2659 | json_object_boolean_true_add( | |
2660 | json_area, "stubShortcut"); | |
2661 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2662 | if (area->no_summary) | |
2663 | json_object_boolean_true_add( | |
2664 | json_area, "nssaNoSummary"); | |
2665 | if (area->shortcut_configured) | |
2666 | json_object_boolean_true_add( | |
2667 | json_area, "nssaShortcut"); | |
2668 | } | |
2669 | ||
2670 | json_object_string_add( | |
2671 | json_area, "shortcuttingMode", | |
2672 | ospf_shortcut_mode_descr_str | |
2673 | [area->shortcut_configured]); | |
2674 | if (area->shortcut_capability) | |
2675 | json_object_boolean_true_add(json_area, | |
2676 | "sBitConcensus"); | |
2677 | } else { | |
2678 | if (area->external_routing == OSPF_AREA_STUB) | |
2679 | vty_out(vty, " (Stub%s%s)", | |
2680 | area->no_summary ? ", no summary" : "", | |
2681 | area->shortcut_configured ? "; " : ""); | |
2682 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2683 | vty_out(vty, " (NSSA%s%s)", | |
2684 | area->no_summary ? ", no summary" : "", | |
2685 | area->shortcut_configured ? "; " : ""); | |
2686 | ||
2687 | vty_out(vty, "\n"); | |
2688 | vty_out(vty, " Shortcutting mode: %s", | |
2689 | ospf_shortcut_mode_descr_str | |
2690 | [area->shortcut_configured]); | |
2691 | vty_out(vty, ", S-bit consensus: %s\n", | |
2692 | area->shortcut_capability ? "ok" : "no"); | |
2693 | } | |
2694 | } | |
2695 | ||
2696 | /* Show number of interfaces */ | |
2697 | if (use_json) { | |
2698 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2699 | listcount(area->oiflist)); | |
2700 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2701 | area->act_ints); | |
2702 | } else | |
2703 | vty_out(vty, | |
2704 | " Number of interfaces in this area: Total: %d, " | |
2705 | "Active: %d\n", | |
2706 | listcount(area->oiflist), area->act_ints); | |
2707 | ||
2708 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2709 | if (use_json) { | |
2710 | json_object_boolean_true_add(json_area, "nssa"); | |
2711 | if (!IS_OSPF_ABR(area->ospf)) | |
2712 | json_object_boolean_false_add(json_area, "abr"); | |
2713 | else if (area->NSSATranslatorState) { | |
2714 | json_object_boolean_true_add(json_area, "abr"); | |
2715 | if (area->NSSATranslatorRole | |
2716 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2717 | json_object_boolean_true_add( | |
2718 | json_area, | |
2719 | "nssaTranslatorElected"); | |
2720 | else if (area->NSSATranslatorRole | |
2721 | == OSPF_NSSA_ROLE_ALWAYS) | |
2722 | json_object_boolean_true_add( | |
2723 | json_area, | |
2724 | "nssaTranslatorAlways"); | |
2725 | } else { | |
2726 | json_object_boolean_true_add(json_area, "abr"); | |
2727 | if (area->NSSATranslatorRole | |
2728 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2729 | json_object_boolean_false_add( | |
2730 | json_area, | |
2731 | "nssaTranslatorElected"); | |
2732 | else | |
2733 | json_object_boolean_true_add( | |
2734 | json_area, | |
2735 | "nssaTranslatorNever"); | |
2736 | } | |
2737 | } else { | |
2738 | vty_out(vty, | |
2739 | " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n"); | |
2740 | if (!IS_OSPF_ABR(area->ospf)) | |
2741 | vty_out(vty, | |
2742 | " It is not ABR, therefore not Translator. \n"); | |
2743 | else if (area->NSSATranslatorState) { | |
2744 | vty_out(vty, " We are an ABR and "); | |
2745 | if (area->NSSATranslatorRole | |
2746 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2747 | vty_out(vty, | |
2748 | "the NSSA Elected Translator. \n"); | |
2749 | else if (area->NSSATranslatorRole | |
2750 | == OSPF_NSSA_ROLE_ALWAYS) | |
2751 | vty_out(vty, | |
2752 | "always an NSSA Translator. \n"); | |
2753 | } else { | |
2754 | vty_out(vty, " We are an ABR, but "); | |
2755 | if (area->NSSATranslatorRole | |
2756 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2757 | vty_out(vty, | |
2758 | "not the NSSA Elected Translator. \n"); | |
2759 | else | |
2760 | vty_out(vty, | |
2761 | "never an NSSA Translator. \n"); | |
2762 | } | |
2763 | } | |
2764 | } | |
2765 | ||
2766 | /* Stub-router state for this area */ | |
2767 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2768 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2769 | ||
2770 | if (use_json) { | |
2771 | json_object_boolean_true_add( | |
2772 | json_area, "originStubMaxDistRouterLsa"); | |
2773 | if (CHECK_FLAG(area->stub_router_state, | |
2774 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2775 | json_object_boolean_true_add( | |
2776 | json_area, "indefiniteActiveAdmin"); | |
2777 | if (area->t_stub_router) { | |
2778 | long time_store; | |
2779 | time_store = | |
2780 | monotime_until( | |
2781 | &area->t_stub_router->u.sands, | |
2782 | NULL) | |
2783 | / 1000LL; | |
2784 | json_object_int_add( | |
2785 | json_area, | |
2786 | "activeStartupRemainderMsecs", | |
2787 | time_store); | |
2788 | } | |
2789 | } else { | |
2790 | vty_out(vty, | |
2791 | " Originating stub / maximum-distance Router-LSA\n"); | |
2792 | if (CHECK_FLAG(area->stub_router_state, | |
2793 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2794 | vty_out(vty, | |
2795 | " Administratively activated (indefinitely)\n"); | |
2796 | if (area->t_stub_router) | |
2797 | vty_out(vty, | |
2798 | " Active from startup, %s remaining\n", | |
2799 | ospf_timer_dump(area->t_stub_router, | |
2800 | timebuf, | |
2801 | sizeof(timebuf))); | |
2802 | } | |
2803 | } | |
2804 | ||
2805 | if (use_json) { | |
2806 | /* Show number of fully adjacent neighbors. */ | |
2807 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2808 | area->full_nbrs); | |
2809 | ||
2810 | /* Show authentication type. */ | |
2811 | if (area->auth_type == OSPF_AUTH_NULL) | |
2812 | json_object_string_add(json_area, "authentication", | |
2813 | "authenticationNone"); | |
2814 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2815 | json_object_string_add(json_area, "authentication", | |
2816 | "authenticationSimplePassword"); | |
2817 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2818 | json_object_string_add(json_area, "authentication", | |
2819 | "authenticationMessageDigest"); | |
2820 | ||
2821 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2822 | json_object_int_add(json_area, | |
2823 | "virtualAdjacenciesPassingCounter", | |
2824 | area->full_vls); | |
2825 | ||
2826 | /* Show SPF calculation times. */ | |
2827 | json_object_int_add(json_area, "spfExecutedCounter", | |
2828 | area->spf_calculation); | |
2829 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2830 | json_object_int_add( | |
2831 | json_area, "lsaRouterNumber", | |
2832 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2833 | json_object_int_add( | |
2834 | json_area, "lsaRouterChecksum", | |
2835 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2836 | json_object_int_add( | |
2837 | json_area, "lsaNetworkNumber", | |
2838 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2839 | json_object_int_add( | |
2840 | json_area, "lsaNetworkChecksum", | |
2841 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2842 | json_object_int_add( | |
2843 | json_area, "lsaSummaryNumber", | |
2844 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2845 | json_object_int_add( | |
2846 | json_area, "lsaSummaryChecksum", | |
2847 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2848 | json_object_int_add( | |
2849 | json_area, "lsaAsbrNumber", | |
2850 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2851 | json_object_int_add( | |
2852 | json_area, "lsaAsbrChecksum", | |
2853 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2854 | json_object_int_add( | |
2855 | json_area, "lsaNssaNumber", | |
2856 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2857 | json_object_int_add( | |
2858 | json_area, "lsaNssaChecksum", | |
2859 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2860 | } else { | |
2861 | /* Show number of fully adjacent neighbors. */ | |
2862 | vty_out(vty, | |
2863 | " Number of fully adjacent neighbors in this area:" | |
2864 | " %d\n", | |
2865 | area->full_nbrs); | |
2866 | ||
2867 | /* Show authentication type. */ | |
2868 | vty_out(vty, " Area has "); | |
2869 | if (area->auth_type == OSPF_AUTH_NULL) | |
2870 | vty_out(vty, "no authentication\n"); | |
2871 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2872 | vty_out(vty, "simple password authentication\n"); | |
2873 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2874 | vty_out(vty, "message digest authentication\n"); | |
2875 | ||
2876 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2877 | vty_out(vty, | |
2878 | " Number of full virtual adjacencies going through" | |
2879 | " this area: %d\n", | |
2880 | area->full_vls); | |
2881 | ||
2882 | /* Show SPF calculation times. */ | |
2883 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2884 | area->spf_calculation); | |
2885 | ||
2886 | /* Show number of LSA. */ | |
2887 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2888 | vty_out(vty, | |
2889 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2890 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2891 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2892 | vty_out(vty, | |
2893 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2894 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2895 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2896 | vty_out(vty, | |
2897 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2898 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2899 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2900 | vty_out(vty, | |
2901 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2902 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
2903 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2904 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
2905 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
2906 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2907 | } | |
2908 | ||
2909 | if (use_json) { | |
2910 | json_object_int_add( | |
2911 | json_area, "lsaOpaqueLinkNumber", | |
2912 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2913 | json_object_int_add( | |
2914 | json_area, "lsaOpaqueLinkChecksum", | |
2915 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2916 | json_object_int_add( | |
2917 | json_area, "lsaOpaqueAreaNumber", | |
2918 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2919 | json_object_int_add( | |
2920 | json_area, "lsaOpaqueAreaChecksum", | |
2921 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2922 | } else { | |
2923 | vty_out(vty, | |
2924 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
2925 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
2926 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2927 | vty_out(vty, | |
2928 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
2929 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
2930 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2931 | } | |
2932 | ||
2933 | if (use_json) | |
2934 | json_object_object_add(json_areas, inet_ntoa(area->area_id), | |
2935 | json_area); | |
2936 | else | |
2937 | vty_out(vty, "\n"); | |
2938 | } | |
2939 | ||
2940 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, | |
2941 | json_object *json, uint8_t use_vrf) | |
2942 | { | |
2943 | struct listnode *node, *nnode; | |
2944 | struct ospf_area *area; | |
2945 | struct timeval result; | |
2946 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2947 | json_object *json_vrf = NULL; | |
2948 | json_object *json_areas = NULL; | |
2949 | ||
2950 | if (json) { | |
2951 | if (use_vrf) | |
2952 | json_vrf = json_object_new_object(); | |
2953 | else | |
2954 | json_vrf = json; | |
2955 | json_areas = json_object_new_object(); | |
2956 | } | |
2957 | ||
2958 | if (ospf->instance) { | |
2959 | if (json) { | |
2960 | json_object_int_add(json, "ospfInstance", | |
2961 | ospf->instance); | |
2962 | } else { | |
2963 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
2964 | } | |
2965 | } | |
2966 | ||
2967 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
2968 | ||
2969 | /* Show Router ID. */ | |
2970 | if (json) { | |
2971 | json_object_string_add(json_vrf, "routerId", | |
2972 | inet_ntoa(ospf->router_id)); | |
2973 | } else { | |
2974 | vty_out(vty, " OSPF Routing Process, Router ID: %s\n", | |
2975 | inet_ntoa(ospf->router_id)); | |
2976 | } | |
2977 | ||
2978 | /* Graceful shutdown */ | |
2979 | if (ospf->t_deferred_shutdown) { | |
2980 | if (json) { | |
2981 | long time_store; | |
2982 | time_store = | |
2983 | monotime_until( | |
2984 | &ospf->t_deferred_shutdown->u.sands, | |
2985 | NULL) | |
2986 | / 1000LL; | |
2987 | json_object_int_add(json_vrf, "deferredShutdownMsecs", | |
2988 | time_store); | |
2989 | } else { | |
2990 | vty_out(vty, | |
2991 | " Deferred shutdown in progress, %s remaining\n", | |
2992 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
2993 | timebuf, sizeof(timebuf))); | |
2994 | } | |
2995 | } | |
2996 | ||
2997 | /* Show capability. */ | |
2998 | if (json) { | |
2999 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
3000 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
3001 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { | |
3002 | json_object_boolean_true_add(json_vrf, | |
3003 | "rfc1583Compatibility"); | |
3004 | } | |
3005 | } else { | |
3006 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3007 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3008 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3009 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3010 | ? "enabled" | |
3011 | : "disabled"); | |
3012 | } | |
3013 | ||
3014 | if (json) { | |
3015 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { | |
3016 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); | |
3017 | } | |
3018 | } else { | |
3019 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3020 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3021 | ? "enabled" | |
3022 | : "disabled"); | |
3023 | } | |
3024 | ||
3025 | /* Show stub-router configuration */ | |
3026 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3027 | || ospf->stub_router_shutdown_time | |
3028 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
3029 | if (json) { | |
3030 | json_object_boolean_true_add(json_vrf, | |
3031 | "stubAdvertisement"); | |
3032 | if (ospf->stub_router_startup_time | |
3033 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3034 | json_object_int_add( | |
3035 | json_vrf, "postStartEnabledSecs", | |
3036 | ospf->stub_router_startup_time); | |
3037 | if (ospf->stub_router_shutdown_time | |
3038 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3039 | json_object_int_add( | |
3040 | json_vrf, "preShutdownEnabledSecs", | |
3041 | ospf->stub_router_shutdown_time); | |
3042 | } else { | |
3043 | vty_out(vty, | |
3044 | " Stub router advertisement is configured\n"); | |
3045 | if (ospf->stub_router_startup_time | |
3046 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3047 | vty_out(vty, | |
3048 | " Enabled for %us after start-up\n", | |
3049 | ospf->stub_router_startup_time); | |
3050 | if (ospf->stub_router_shutdown_time | |
3051 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3052 | vty_out(vty, | |
3053 | " Enabled for %us prior to full shutdown\n", | |
3054 | ospf->stub_router_shutdown_time); | |
3055 | } | |
3056 | } | |
3057 | ||
3058 | /* Show SPF timers. */ | |
3059 | if (json) { | |
3060 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
3061 | ospf->spf_delay); | |
3062 | json_object_int_add(json_vrf, "holdtimeMinMsecs", | |
3063 | ospf->spf_holdtime); | |
3064 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", | |
3065 | ospf->spf_max_holdtime); | |
3066 | json_object_int_add(json_vrf, "holdtimeMultplier", | |
3067 | ospf->spf_hold_multiplier); | |
3068 | } else { | |
3069 | vty_out(vty, | |
3070 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3071 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3072 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3073 | " Hold time multiplier is currently %d\n", | |
3074 | ospf->spf_delay, ospf->spf_holdtime, | |
3075 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3076 | } | |
3077 | ||
3078 | if (json) { | |
3079 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3080 | long time_store = 0; | |
3081 | ||
3082 | time_store = | |
3083 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
3084 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", | |
3085 | time_store); | |
3086 | ||
3087 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3088 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
3089 | json_object_int_add(json_vrf, "spfLastDurationMsecs", | |
3090 | time_store); | |
3091 | } else | |
3092 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); | |
3093 | } else { | |
3094 | vty_out(vty, " SPF algorithm "); | |
3095 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3096 | monotime_since(&ospf->ts_spf, &result); | |
3097 | vty_out(vty, "last executed %s ago\n", | |
3098 | ospf_timeval_dump(&result, timebuf, | |
3099 | sizeof(timebuf))); | |
3100 | vty_out(vty, " Last SPF duration %s\n", | |
3101 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3102 | timebuf, sizeof(timebuf))); | |
3103 | } else | |
3104 | vty_out(vty, "has not been run\n"); | |
3105 | } | |
3106 | ||
3107 | if (json) { | |
3108 | if (ospf->t_spf_calc) { | |
3109 | long time_store; | |
3110 | time_store = | |
3111 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3112 | / 1000LL; | |
3113 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", | |
3114 | time_store); | |
3115 | } | |
3116 | ||
3117 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", | |
3118 | ospf->min_ls_interval); | |
3119 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", | |
3120 | ospf->min_ls_arrival); | |
3121 | /* Show write multiplier values */ | |
3122 | json_object_int_add(json_vrf, "writeMultiplier", | |
3123 | ospf->write_oi_count); | |
3124 | /* Show refresh parameters. */ | |
3125 | json_object_int_add(json_vrf, "refreshTimerMsecs", | |
3126 | ospf->lsa_refresh_interval * 1000); | |
3127 | } else { | |
3128 | vty_out(vty, " SPF timer %s%s\n", | |
3129 | (ospf->t_spf_calc ? "due in " : "is "), | |
3130 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3131 | sizeof(timebuf))); | |
3132 | ||
3133 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3134 | ospf->min_ls_interval); | |
3135 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3136 | ospf->min_ls_arrival); | |
3137 | ||
3138 | /* Show write multiplier values */ | |
3139 | vty_out(vty, " Write Multiplier set to %d \n", | |
3140 | ospf->write_oi_count); | |
3141 | ||
3142 | /* Show refresh parameters. */ | |
3143 | vty_out(vty, " Refresh timer %d secs\n", | |
3144 | ospf->lsa_refresh_interval); | |
3145 | } | |
3146 | ||
3147 | /* Show ABR/ASBR flags. */ | |
3148 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
3149 | if (json) | |
3150 | json_object_string_add( | |
3151 | json_vrf, "abrType", | |
3152 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3153 | else | |
3154 | vty_out(vty, | |
3155 | " This router is an ABR, ABR type is: %s\n", | |
3156 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3157 | } | |
3158 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
3159 | if (json) | |
3160 | json_object_string_add( | |
3161 | json_vrf, "asbrRouter", | |
3162 | "injectingExternalRoutingInformation"); | |
3163 | else | |
3164 | vty_out(vty, | |
3165 | " This router is an ASBR " | |
3166 | "(injecting external routing information)\n"); | |
3167 | } | |
3168 | ||
3169 | /* Show Number of AS-external-LSAs. */ | |
3170 | if (json) { | |
3171 | json_object_int_add( | |
3172 | json_vrf, "lsaExternalCounter", | |
3173 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3174 | json_object_int_add( | |
3175 | json_vrf, "lsaExternalChecksum", | |
3176 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3177 | } else { | |
3178 | vty_out(vty, | |
3179 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3180 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3181 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3182 | } | |
3183 | ||
3184 | if (json) { | |
3185 | json_object_int_add( | |
3186 | json_vrf, "lsaAsopaqueCounter", | |
3187 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3188 | json_object_int_add( | |
3189 | json_vrf, "lsaAsOpaqueChecksum", | |
3190 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3191 | } else { | |
3192 | vty_out(vty, | |
3193 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3194 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3195 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3196 | } | |
3197 | ||
3198 | /* Show number of areas attached. */ | |
3199 | if (json) | |
3200 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
3201 | listcount(ospf->areas)); | |
3202 | else | |
3203 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3204 | listcount(ospf->areas)); | |
3205 | ||
3206 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3207 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
3208 | if (json) | |
3209 | json_object_boolean_true_add( | |
3210 | json_vrf, "adjacencyChangesLoggedAll"); | |
3211 | else | |
3212 | vty_out(vty, | |
3213 | " All adjacency changes are logged\n"); | |
3214 | } else { | |
3215 | if (json) | |
3216 | json_object_boolean_true_add( | |
3217 | json_vrf, "adjacencyChangesLogged"); | |
3218 | else | |
3219 | vty_out(vty, " Adjacency changes are logged\n"); | |
3220 | } | |
3221 | } | |
3222 | /* Show each area status. */ | |
3223 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
3224 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); | |
3225 | ||
3226 | if (json) { | |
3227 | if (use_vrf) { | |
3228 | json_object_object_add(json_vrf, "areas", json_areas); | |
3229 | if (ospf->vrf_id == VRF_DEFAULT) | |
3230 | json_object_object_add(json, "default", | |
3231 | json_vrf); | |
3232 | else | |
3233 | json_object_object_add(json, ospf->name, | |
3234 | json_vrf); | |
3235 | } else { | |
3236 | json_object_object_add(json, "areas", json_areas); | |
3237 | } | |
3238 | } else | |
3239 | vty_out(vty, "\n"); | |
3240 | ||
3241 | return CMD_SUCCESS; | |
3242 | } | |
3243 | ||
3244 | DEFUN (show_ip_ospf, | |
3245 | show_ip_ospf_cmd, | |
3246 | "show ip ospf [vrf <NAME|all>] [json]", | |
3247 | SHOW_STR | |
3248 | IP_STR | |
3249 | "OSPF information\n" | |
3250 | VRF_CMD_HELP_STR | |
3251 | "All VRFs\n" | |
3252 | JSON_STR) | |
3253 | { | |
3254 | struct ospf *ospf; | |
3255 | bool uj = use_json(argc, argv); | |
3256 | struct listnode *node = NULL; | |
3257 | char *vrf_name = NULL; | |
3258 | bool all_vrf = false; | |
3259 | int ret = CMD_SUCCESS; | |
3260 | int inst = 0; | |
3261 | int idx_vrf = 0; | |
3262 | json_object *json = NULL; | |
3263 | uint8_t use_vrf = 0; | |
3264 | ||
3265 | if (listcount(om->ospf) == 0) | |
3266 | return CMD_SUCCESS; | |
3267 | ||
3268 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
3269 | ||
3270 | if (uj) | |
3271 | json = json_object_new_object(); | |
3272 | ||
3273 | /* vrf input is provided could be all or specific vrf*/ | |
3274 | if (vrf_name) { | |
3275 | bool ospf_output = false; | |
3276 | ||
3277 | use_vrf = 1; | |
3278 | ||
3279 | if (all_vrf) { | |
3280 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3281 | if (!ospf->oi_running) | |
3282 | continue; | |
3283 | ospf_output = true; | |
3284 | ret = show_ip_ospf_common(vty, ospf, json, | |
3285 | use_vrf); | |
3286 | } | |
3287 | if (uj) { | |
3288 | vty_out(vty, "%s\n", | |
3289 | json_object_to_json_string_ext( | |
3290 | json, JSON_C_TO_STRING_PRETTY)); | |
3291 | json_object_free(json); | |
3292 | } else if (!ospf_output) | |
3293 | vty_out(vty, "%% OSPF instance not found\n"); | |
3294 | return ret; | |
3295 | } | |
3296 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
3297 | if ((ospf == NULL) || !ospf->oi_running) { | |
3298 | if (uj) { | |
3299 | vty_out(vty, "%s\n", | |
3300 | json_object_to_json_string_ext( | |
3301 | json, JSON_C_TO_STRING_PRETTY)); | |
3302 | json_object_free(json); | |
3303 | } else | |
3304 | vty_out(vty, "%% OSPF instance not found\n"); | |
3305 | ||
3306 | return CMD_SUCCESS; | |
3307 | } | |
3308 | } else { | |
3309 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3310 | /* Display default ospf (instance 0) info */ | |
3311 | if (ospf == NULL || !ospf->oi_running) { | |
3312 | if (uj) { | |
3313 | vty_out(vty, "%s\n", | |
3314 | json_object_to_json_string_ext( | |
3315 | json, JSON_C_TO_STRING_PRETTY)); | |
3316 | json_object_free(json); | |
3317 | } else | |
3318 | vty_out(vty, "%% OSPF instance not found\n"); | |
3319 | ||
3320 | return CMD_SUCCESS; | |
3321 | } | |
3322 | } | |
3323 | ||
3324 | if (ospf) { | |
3325 | show_ip_ospf_common(vty, ospf, json, use_vrf); | |
3326 | if (uj) | |
3327 | vty_out(vty, "%s\n", | |
3328 | json_object_to_json_string_ext( | |
3329 | json, JSON_C_TO_STRING_PRETTY)); | |
3330 | } | |
3331 | ||
3332 | if (uj) | |
3333 | json_object_free(json); | |
3334 | ||
3335 | return ret; | |
3336 | } | |
3337 | ||
3338 | DEFUN (show_ip_ospf_instance, | |
3339 | show_ip_ospf_instance_cmd, | |
3340 | "show ip ospf (1-65535) [json]", | |
3341 | SHOW_STR | |
3342 | IP_STR | |
3343 | "OSPF information\n" | |
3344 | "Instance ID\n" | |
3345 | JSON_STR) | |
3346 | { | |
3347 | int idx_number = 3; | |
3348 | struct ospf *ospf; | |
3349 | unsigned short instance = 0; | |
3350 | bool uj = use_json(argc, argv); | |
3351 | int ret = CMD_SUCCESS; | |
3352 | json_object *json = NULL; | |
3353 | ||
3354 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
3355 | ospf = ospf_lookup_instance(instance); | |
3356 | if (ospf == NULL) | |
3357 | return CMD_NOT_MY_INSTANCE; | |
3358 | ||
3359 | if (!ospf->oi_running) | |
3360 | return CMD_SUCCESS; | |
3361 | ||
3362 | if (uj) | |
3363 | json = json_object_new_object(); | |
3364 | ||
3365 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3366 | ||
3367 | if (uj) { | |
3368 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3369 | json, JSON_C_TO_STRING_PRETTY)); | |
3370 | json_object_free(json); | |
3371 | } | |
3372 | ||
3373 | return ret; | |
3374 | } | |
3375 | ||
3376 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, | |
3377 | struct interface *ifp, | |
3378 | json_object *json_interface_sub, | |
3379 | bool use_json) | |
3380 | { | |
3381 | int is_up; | |
3382 | struct ospf_neighbor *nbr; | |
3383 | struct route_node *rn; | |
3384 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; | |
3385 | ||
3386 | /* Is interface up? */ | |
3387 | if (use_json) { | |
3388 | is_up = if_is_operative(ifp); | |
3389 | if (is_up) | |
3390 | json_object_boolean_true_add(json_interface_sub, | |
3391 | "ifUp"); | |
3392 | else | |
3393 | json_object_boolean_false_add(json_interface_sub, | |
3394 | "ifDown"); | |
3395 | ||
3396 | json_object_int_add(json_interface_sub, "ifIndex", | |
3397 | ifp->ifindex); | |
3398 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3399 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3400 | bandwidth); | |
3401 | json_object_string_add(json_interface_sub, "ifFlags", | |
3402 | if_flag_dump(ifp->flags)); | |
3403 | } else { | |
3404 | vty_out(vty, "%s is %s\n", ifp->name, | |
3405 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3406 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3407 | ifp->ifindex, ifp->mtu, bandwidth, | |
3408 | if_flag_dump(ifp->flags)); | |
3409 | } | |
3410 | ||
3411 | /* Is interface OSPF enabled? */ | |
3412 | if (use_json) { | |
3413 | if (ospf_oi_count(ifp) == 0) { | |
3414 | json_object_boolean_false_add(json_interface_sub, | |
3415 | "ospfEnabled"); | |
3416 | return; | |
3417 | } else if (!is_up) { | |
3418 | json_object_boolean_false_add(json_interface_sub, | |
3419 | "ospfRunning"); | |
3420 | return; | |
3421 | } else | |
3422 | json_object_boolean_true_add(json_interface_sub, | |
3423 | "ospfEnabled"); | |
3424 | } else { | |
3425 | if (ospf_oi_count(ifp) == 0) { | |
3426 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3427 | return; | |
3428 | } else if (!is_up) { | |
3429 | vty_out(vty, | |
3430 | " OSPF is enabled, but not running on this interface\n"); | |
3431 | return; | |
3432 | } | |
3433 | } | |
3434 | ||
3435 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3436 | struct ospf_interface *oi = rn->info; | |
3437 | ||
3438 | if (oi == NULL) | |
3439 | continue; | |
3440 | ||
3441 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3442 | if (use_json) | |
3443 | json_object_boolean_true_add(json_interface_sub, | |
3444 | "ifUnnumbered"); | |
3445 | else | |
3446 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3447 | } else { | |
3448 | struct in_addr dest; | |
3449 | const char *dstr; | |
3450 | ||
3451 | /* Show OSPF interface information. */ | |
3452 | if (use_json) { | |
3453 | json_object_string_add( | |
3454 | json_interface_sub, "ipAddress", | |
3455 | inet_ntoa(oi->address->u.prefix4)); | |
3456 | json_object_int_add(json_interface_sub, | |
3457 | "ipAddressPrefixlen", | |
3458 | oi->address->prefixlen); | |
3459 | } else | |
3460 | vty_out(vty, " Internet Address %s/%d,", | |
3461 | inet_ntoa(oi->address->u.prefix4), | |
3462 | oi->address->prefixlen); | |
3463 | ||
3464 | /* For Vlinks, showing the peer address is | |
3465 | * probably more informative than the local | |
3466 | * interface that is being used */ | |
3467 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3468 | dstr = "Peer"; | |
3469 | dest = oi->vl_data->peer_addr; | |
3470 | } else if (CONNECTED_PEER(oi->connected) | |
3471 | && oi->connected->destination) { | |
3472 | dstr = "Peer"; | |
3473 | dest = oi->connected->destination->u.prefix4; | |
3474 | } else { | |
3475 | dstr = "Broadcast"; | |
3476 | dest.s_addr = ipv4_broadcast_addr( | |
3477 | oi->connected->address->u.prefix4.s_addr, | |
3478 | oi->connected->address->prefixlen); | |
3479 | } | |
3480 | ||
3481 | if (use_json) { | |
3482 | json_object_string_add( | |
3483 | json_interface_sub, | |
3484 | "ospfIfType", dstr); | |
3485 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3486 | json_object_string_add( | |
3487 | json_interface_sub, | |
3488 | "vlinkPeer", | |
3489 | inet_ntoa(dest)); | |
3490 | else | |
3491 | json_object_string_add( | |
3492 | json_interface_sub, | |
3493 | "localIfUsed", | |
3494 | inet_ntoa(dest)); | |
3495 | } else | |
3496 | vty_out(vty, " %s %s,", dstr, | |
3497 | inet_ntoa(dest)); | |
3498 | } | |
3499 | if (use_json) { | |
3500 | json_object_string_add(json_interface_sub, "area", | |
3501 | ospf_area_desc_string(oi->area)); | |
3502 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3503 | json_object_boolean_true_add( | |
3504 | json_interface_sub, | |
3505 | "mtuMismatchDetect"); | |
3506 | json_object_string_add(json_interface_sub, "routerId", | |
3507 | inet_ntoa(ospf->router_id)); | |
3508 | json_object_string_add(json_interface_sub, | |
3509 | "networkType", | |
3510 | ospf_network_type_str[oi->type]); | |
3511 | json_object_int_add(json_interface_sub, "cost", | |
3512 | oi->output_cost); | |
3513 | json_object_int_add( | |
3514 | json_interface_sub, "transmitDelaySecs", | |
3515 | OSPF_IF_PARAM(oi, transmit_delay)); | |
3516 | json_object_string_add(json_interface_sub, "state", | |
3517 | lookup_msg(ospf_ism_state_msg, | |
3518 | oi->state, NULL)); | |
3519 | json_object_int_add(json_interface_sub, "priority", | |
3520 | PRIORITY(oi)); | |
3521 | } else { | |
3522 | vty_out(vty, " Area %s\n", | |
3523 | ospf_area_desc_string(oi->area)); | |
3524 | ||
3525 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3526 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3527 | : "enabled"); | |
3528 | ||
3529 | vty_out(vty, | |
3530 | " Router ID %s, Network Type %s, Cost: %d\n", | |
3531 | inet_ntoa(ospf->router_id), | |
3532 | ospf_network_type_str[oi->type], | |
3533 | oi->output_cost); | |
3534 | ||
3535 | vty_out(vty, | |
3536 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3537 | OSPF_IF_PARAM(oi, transmit_delay), | |
3538 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3539 | PRIORITY(oi)); | |
3540 | } | |
3541 | ||
3542 | /* Show DR information. */ | |
3543 | if (DR(oi).s_addr == 0) { | |
3544 | if (!use_json) | |
3545 | vty_out(vty, | |
3546 | " No backup designated router on this network\n"); | |
3547 | } else { | |
3548 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3549 | if (nbr == NULL) { | |
3550 | if (!use_json) | |
3551 | vty_out(vty, | |
3552 | " No backup designated router on this network\n"); | |
3553 | } else { | |
3554 | if (use_json) { | |
3555 | json_object_string_add( | |
3556 | json_interface_sub, "bdrId", | |
3557 | inet_ntoa(nbr->router_id)); | |
3558 | json_object_string_add( | |
3559 | json_interface_sub, | |
3560 | "bdrAddress", | |
3561 | inet_ntoa(nbr->address.u | |
3562 | .prefix4)); | |
3563 | } else { | |
3564 | vty_out(vty, | |
3565 | " Backup Designated Router (ID) %s,", | |
3566 | inet_ntoa(nbr->router_id)); | |
3567 | vty_out(vty, " Interface Address %s\n", | |
3568 | inet_ntoa(nbr->address.u | |
3569 | .prefix4)); | |
3570 | } | |
3571 | } | |
3572 | } | |
3573 | ||
3574 | /* Next network-LSA sequence number we'll use, if we're elected | |
3575 | * DR */ | |
3576 | if (oi->params | |
3577 | && ntohl(oi->params->network_lsa_seqnum) | |
3578 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3579 | if (use_json) | |
3580 | json_object_int_add( | |
3581 | json_interface_sub, | |
3582 | "networkLsaSequence", | |
3583 | ntohl(oi->params->network_lsa_seqnum)); | |
3584 | else | |
3585 | vty_out(vty, | |
3586 | " Saved Network-LSA sequence number 0x%x\n", | |
3587 | ntohl(oi->params->network_lsa_seqnum)); | |
3588 | } | |
3589 | ||
3590 | if (use_json) { | |
3591 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3592 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3593 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3594 | json_object_boolean_true_add( | |
3595 | json_interface_sub, | |
3596 | "mcastMemberOspfAllRouters"); | |
3597 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3598 | json_object_boolean_true_add( | |
3599 | json_interface_sub, | |
3600 | "mcastMemberOspfDesignatedRouters"); | |
3601 | } | |
3602 | } else { | |
3603 | vty_out(vty, " Multicast group memberships:"); | |
3604 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3605 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3606 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3607 | vty_out(vty, " OSPFAllRouters"); | |
3608 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3609 | vty_out(vty, " OSPFDesignatedRouters"); | |
3610 | } else | |
3611 | vty_out(vty, " <None>"); | |
3612 | vty_out(vty, "\n"); | |
3613 | } | |
3614 | ||
3615 | if (use_json) { | |
3616 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3617 | json_object_int_add( | |
3618 | json_interface_sub, "timerMsecs", | |
3619 | OSPF_IF_PARAM(oi, v_hello) * 1000); | |
3620 | else | |
3621 | json_object_int_add( | |
3622 | json_interface_sub, "timerMsecs", | |
3623 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3624 | json_object_int_add(json_interface_sub, | |
3625 | "timerDeadSecs", | |
3626 | OSPF_IF_PARAM(oi, v_wait)); | |
3627 | json_object_int_add(json_interface_sub, | |
3628 | "timerWaitSecs", | |
3629 | OSPF_IF_PARAM(oi, v_wait)); | |
3630 | json_object_int_add( | |
3631 | json_interface_sub, "timerRetransmitSecs", | |
3632 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3633 | } else { | |
3634 | vty_out(vty, " Timer intervals configured,"); | |
3635 | vty_out(vty, " Hello "); | |
3636 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3637 | vty_out(vty, "%ds,", | |
3638 | OSPF_IF_PARAM(oi, v_hello)); | |
3639 | else | |
3640 | vty_out(vty, "%dms,", | |
3641 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3642 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3643 | OSPF_IF_PARAM(oi, v_wait), | |
3644 | OSPF_IF_PARAM(oi, v_wait), | |
3645 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3646 | } | |
3647 | ||
3648 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3649 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3650 | if (use_json) { | |
3651 | long time_store = 0; | |
3652 | if (oi->t_hello) | |
3653 | time_store = | |
3654 | monotime_until( | |
3655 | &oi->t_hello->u.sands, | |
3656 | NULL) | |
3657 | / 1000LL; | |
3658 | json_object_int_add(json_interface_sub, | |
3659 | "timerHelloInMsecs", | |
3660 | time_store); | |
3661 | } else | |
3662 | vty_out(vty, " Hello due in %s\n", | |
3663 | ospf_timer_dump(oi->t_hello, timebuf, | |
3664 | sizeof(timebuf))); | |
3665 | } else /* passive-interface is set */ | |
3666 | { | |
3667 | if (use_json) | |
3668 | json_object_boolean_true_add( | |
3669 | json_interface_sub, | |
3670 | "timerPassiveIface"); | |
3671 | else | |
3672 | vty_out(vty, | |
3673 | " No Hellos (Passive interface)\n"); | |
3674 | } | |
3675 | ||
3676 | if (use_json) { | |
3677 | json_object_int_add(json_interface_sub, "nbrCount", | |
3678 | ospf_nbr_count(oi, 0)); | |
3679 | json_object_int_add(json_interface_sub, | |
3680 | "nbrAdjacentCount", | |
3681 | ospf_nbr_count(oi, NSM_Full)); | |
3682 | } else | |
3683 | vty_out(vty, | |
3684 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3685 | ospf_nbr_count(oi, 0), | |
3686 | ospf_nbr_count(oi, NSM_Full)); | |
3687 | ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json); | |
3688 | } | |
3689 | } | |
3690 | ||
3691 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, | |
3692 | char *intf_name, uint8_t use_vrf, | |
3693 | json_object *json, bool use_json) | |
3694 | { | |
3695 | struct interface *ifp; | |
3696 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); | |
3697 | json_object *json_vrf = NULL; | |
3698 | json_object *json_interface_sub = NULL, *json_interface = NULL; | |
3699 | ||
3700 | if (use_json) { | |
3701 | if (use_vrf) | |
3702 | json_vrf = json_object_new_object(); | |
3703 | else | |
3704 | json_vrf = json; | |
3705 | json_interface = json_object_new_object(); | |
3706 | } | |
3707 | ||
3708 | if (ospf->instance) { | |
3709 | if (use_json) | |
3710 | json_object_int_add(json, "ospfInstance", | |
3711 | ospf->instance); | |
3712 | else | |
3713 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3714 | } | |
3715 | ||
3716 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
3717 | ||
3718 | if (intf_name == NULL) { | |
3719 | /* Show All Interfaces.*/ | |
3720 | FOR_ALL_INTERFACES (vrf, ifp) { | |
3721 | if (ospf_oi_count(ifp)) { | |
3722 | if (use_json) { | |
3723 | json_interface_sub = | |
3724 | json_object_new_object(); | |
3725 | } | |
3726 | show_ip_ospf_interface_sub(vty, ospf, ifp, | |
3727 | json_interface_sub, | |
3728 | use_json); | |
3729 | ||
3730 | if (use_json) { | |
3731 | json_object_object_add( | |
3732 | json_interface, ifp->name, | |
3733 | json_interface_sub); | |
3734 | } | |
3735 | } | |
3736 | } | |
3737 | if (use_json) | |
3738 | json_object_object_add(json_vrf, "interfaces", | |
3739 | json_interface); | |
3740 | } else { | |
3741 | /* Interface name is specified. */ | |
3742 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); | |
3743 | if (ifp == NULL) { | |
3744 | if (use_json) | |
3745 | json_object_boolean_true_add(json_vrf, | |
3746 | "noSuchIface"); | |
3747 | else | |
3748 | vty_out(vty, "No such interface name\n"); | |
3749 | } else { | |
3750 | if (use_json) { | |
3751 | json_interface_sub = json_object_new_object(); | |
3752 | json_interface = json_object_new_object(); | |
3753 | } | |
3754 | ||
3755 | show_ip_ospf_interface_sub( | |
3756 | vty, ospf, ifp, json_interface_sub, use_json); | |
3757 | ||
3758 | if (use_json) { | |
3759 | json_object_object_add(json_interface, | |
3760 | ifp->name, | |
3761 | json_interface_sub); | |
3762 | json_object_object_add(json_vrf, "interfaces", | |
3763 | json_interface); | |
3764 | } | |
3765 | } | |
3766 | } | |
3767 | ||
3768 | if (use_json) { | |
3769 | if (use_vrf) { | |
3770 | if (ospf->vrf_id == VRF_DEFAULT) | |
3771 | json_object_object_add(json, "default", | |
3772 | json_vrf); | |
3773 | else | |
3774 | json_object_object_add(json, ospf->name, | |
3775 | json_vrf); | |
3776 | } | |
3777 | } else | |
3778 | vty_out(vty, "\n"); | |
3779 | ||
3780 | return CMD_SUCCESS; | |
3781 | } | |
3782 | ||
3783 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, | |
3784 | struct ospf_interface *oi, | |
3785 | json_object *json_interface_sub, | |
3786 | bool use_json) | |
3787 | { | |
3788 | if (use_json) { | |
3789 | json_object_int_add(json_interface_sub, "ifIndex", | |
3790 | oi->ifp->ifindex); | |
3791 | json_object_int_add(json_interface_sub, "helloIn", | |
3792 | oi->hello_in); | |
3793 | json_object_int_add(json_interface_sub, "helloOut", | |
3794 | oi->hello_out); | |
3795 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3796 | oi->db_desc_in); | |
3797 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3798 | oi->db_desc_out); | |
3799 | json_object_int_add(json_interface_sub, "lsReqIn", | |
3800 | oi->ls_req_in); | |
3801 | json_object_int_add(json_interface_sub, "lsReqOut", | |
3802 | oi->ls_req_out); | |
3803 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
3804 | oi->ls_upd_in); | |
3805 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
3806 | oi->ls_upd_out); | |
3807 | json_object_int_add(json_interface_sub, "lsAckIn", | |
3808 | oi->ls_ack_in); | |
3809 | json_object_int_add(json_interface_sub, "lsAckOut", | |
3810 | oi->ls_ack_out); | |
3811 | } else { | |
3812 | vty_out(vty, | |
3813 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
3814 | oi->ifp->name, oi->hello_in, oi->hello_out, | |
3815 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
3816 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
3817 | oi->ls_ack_in, oi->ls_ack_out); | |
3818 | } | |
3819 | } | |
3820 | ||
3821 | /* OSPFv2 Packet Counters */ | |
3822 | static int show_ip_ospf_interface_traffic_common( | |
3823 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
3824 | int display_once, uint8_t use_vrf, bool use_json) | |
3825 | { | |
3826 | struct vrf *vrf = NULL; | |
3827 | struct interface *ifp = NULL; | |
3828 | json_object *json_vrf = NULL; | |
3829 | json_object *json_interface_sub = NULL; | |
3830 | ||
3831 | if (!use_json && !display_once) { | |
3832 | vty_out(vty, "\n"); | |
3833 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", | |
3834 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
3835 | " LS-Ack"); | |
3836 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", | |
3837 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", | |
3838 | " Rx/Tx"); | |
3839 | vty_out(vty, | |
3840 | "--------------------------------------------------------------------------------------------\n"); | |
3841 | } else if (use_json) { | |
3842 | if (use_vrf) | |
3843 | json_vrf = json_object_new_object(); | |
3844 | else | |
3845 | json_vrf = json; | |
3846 | } | |
3847 | ||
3848 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
3849 | ||
3850 | if (intf_name == NULL) { | |
3851 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
3852 | FOR_ALL_INTERFACES (vrf, ifp) { | |
3853 | struct route_node *rn; | |
3854 | struct ospf_interface *oi; | |
3855 | ||
3856 | if (ospf_oi_count(ifp) == 0) | |
3857 | continue; | |
3858 | ||
3859 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3860 | rn = route_next(rn)) { | |
3861 | oi = rn->info; | |
3862 | ||
3863 | if (oi == NULL) | |
3864 | continue; | |
3865 | ||
3866 | if (use_json) { | |
3867 | json_interface_sub = | |
3868 | json_object_new_object(); | |
3869 | } | |
3870 | ||
3871 | show_ip_ospf_interface_traffic_sub( | |
3872 | vty, oi, json_interface_sub, use_json); | |
3873 | if (use_json) { | |
3874 | json_object_object_add( | |
3875 | json_vrf, ifp->name, | |
3876 | json_interface_sub); | |
3877 | } | |
3878 | } | |
3879 | } | |
3880 | } else { | |
3881 | /* Interface name is specified. */ | |
3882 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); | |
3883 | if (ifp != NULL) { | |
3884 | struct route_node *rn; | |
3885 | struct ospf_interface *oi; | |
3886 | ||
3887 | if (ospf_oi_count(ifp) == 0) { | |
3888 | vty_out(vty, | |
3889 | " OSPF not enabled on this interface %s\n", | |
3890 | ifp->name); | |
3891 | return CMD_SUCCESS; | |
3892 | } | |
3893 | ||
3894 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3895 | rn = route_next(rn)) { | |
3896 | oi = rn->info; | |
3897 | ||
3898 | if (use_json) { | |
3899 | json_interface_sub = | |
3900 | json_object_new_object(); | |
3901 | } | |
3902 | ||
3903 | show_ip_ospf_interface_traffic_sub( | |
3904 | vty, oi, json_interface_sub, use_json); | |
3905 | if (use_json) { | |
3906 | json_object_object_add( | |
3907 | json_vrf, ifp->name, | |
3908 | json_interface_sub); | |
3909 | } | |
3910 | } | |
3911 | } | |
3912 | } | |
3913 | ||
3914 | if (use_json) { | |
3915 | if (use_vrf) { | |
3916 | if (ospf->vrf_id == VRF_DEFAULT) | |
3917 | json_object_object_add(json, "default", | |
3918 | json_vrf); | |
3919 | else | |
3920 | json_object_object_add(json, ospf->name, | |
3921 | json_vrf); | |
3922 | } | |
3923 | } else | |
3924 | vty_out(vty, "\n"); | |
3925 | ||
3926 | return CMD_SUCCESS; | |
3927 | } | |
3928 | ||
3929 | DEFUN (show_ip_ospf_interface, | |
3930 | show_ip_ospf_interface_cmd, | |
3931 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", | |
3932 | SHOW_STR | |
3933 | IP_STR | |
3934 | "OSPF information\n" | |
3935 | VRF_CMD_HELP_STR | |
3936 | "All VRFs\n" | |
3937 | "Interface information\n" | |
3938 | "Interface name\n" | |
3939 | JSON_STR) | |
3940 | { | |
3941 | struct ospf *ospf; | |
3942 | bool uj = use_json(argc, argv); | |
3943 | struct listnode *node = NULL; | |
3944 | char *vrf_name = NULL, *intf_name = NULL; | |
3945 | bool all_vrf = false; | |
3946 | int ret = CMD_SUCCESS; | |
3947 | int inst = 0; | |
3948 | int idx_vrf = 0, idx_intf = 0; | |
3949 | uint8_t use_vrf = 0; | |
3950 | json_object *json = NULL; | |
3951 | ||
3952 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
3953 | ||
3954 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
3955 | intf_name = argv[idx_intf]->arg; | |
3956 | ||
3957 | if (uj) | |
3958 | json = json_object_new_object(); | |
3959 | ||
3960 | /* vrf input is provided could be all or specific vrf*/ | |
3961 | if (vrf_name) { | |
3962 | use_vrf = 1; | |
3963 | if (all_vrf) { | |
3964 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3965 | if (!ospf->oi_running) | |
3966 | continue; | |
3967 | ret = show_ip_ospf_interface_common( | |
3968 | vty, ospf, intf_name, use_vrf, json, | |
3969 | uj); | |
3970 | } | |
3971 | ||
3972 | if (uj) { | |
3973 | vty_out(vty, "%s\n", | |
3974 | json_object_to_json_string_ext( | |
3975 | json, JSON_C_TO_STRING_PRETTY)); | |
3976 | json_object_free(json); | |
3977 | } else if (!ospf) | |
3978 | vty_out(vty, "%% OSPF instance not found\n"); | |
3979 | ||
3980 | return ret; | |
3981 | } | |
3982 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
3983 | if (ospf == NULL || !ospf->oi_running) { | |
3984 | if (uj) { | |
3985 | vty_out(vty, "%s\n", | |
3986 | json_object_to_json_string_ext( | |
3987 | json, JSON_C_TO_STRING_PRETTY)); | |
3988 | json_object_free(json); | |
3989 | } else | |
3990 | vty_out(vty, "%% OSPF instance not found\n"); | |
3991 | ||
3992 | return CMD_SUCCESS; | |
3993 | } | |
3994 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
3995 | use_vrf, json, uj); | |
3996 | ||
3997 | } else { | |
3998 | /* Display default ospf (instance 0) info */ | |
3999 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4000 | if (ospf == NULL || !ospf->oi_running) { | |
4001 | if (uj) { | |
4002 | vty_out(vty, "%s\n", | |
4003 | json_object_to_json_string_ext( | |
4004 | json, JSON_C_TO_STRING_PRETTY)); | |
4005 | json_object_free(json); | |
4006 | } else | |
4007 | vty_out(vty, "%% OSPF instance not found\n"); | |
4008 | ||
4009 | return CMD_SUCCESS; | |
4010 | } | |
4011 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4012 | use_vrf, json, uj); | |
4013 | } | |
4014 | ||
4015 | if (uj) { | |
4016 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4017 | json, JSON_C_TO_STRING_PRETTY)); | |
4018 | json_object_free(json); | |
4019 | } | |
4020 | ||
4021 | return ret; | |
4022 | } | |
4023 | ||
4024 | DEFUN (show_ip_ospf_instance_interface, | |
4025 | show_ip_ospf_instance_interface_cmd, | |
4026 | "show ip ospf (1-65535) interface [INTERFACE] [json]", | |
4027 | SHOW_STR | |
4028 | IP_STR | |
4029 | "OSPF information\n" | |
4030 | "Instance ID\n" | |
4031 | "Interface information\n" | |
4032 | "Interface name\n" | |
4033 | JSON_STR) | |
4034 | { | |
4035 | int idx_number = 3; | |
4036 | int idx_intf = 0; | |
4037 | struct ospf *ospf; | |
4038 | unsigned short instance = 0; | |
4039 | bool uj = use_json(argc, argv); | |
4040 | char *intf_name = NULL; | |
4041 | int ret = CMD_SUCCESS; | |
4042 | json_object *json = NULL; | |
4043 | ||
4044 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
4045 | ospf = ospf_lookup_instance(instance); | |
4046 | if (ospf == NULL) | |
4047 | return CMD_NOT_MY_INSTANCE; | |
4048 | ||
4049 | if (!ospf->oi_running) | |
4050 | return CMD_SUCCESS; | |
4051 | ||
4052 | if (uj) | |
4053 | json = json_object_new_object(); | |
4054 | ||
4055 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4056 | intf_name = argv[idx_intf]->arg; | |
4057 | ||
4058 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4059 | ||
4060 | if (uj) { | |
4061 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4062 | json, JSON_C_TO_STRING_PRETTY)); | |
4063 | json_object_free(json); | |
4064 | } | |
4065 | ||
4066 | return ret; | |
4067 | } | |
4068 | ||
4069 | DEFUN (show_ip_ospf_interface_traffic, | |
4070 | show_ip_ospf_interface_traffic_cmd, | |
4071 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4072 | SHOW_STR | |
4073 | IP_STR | |
4074 | "OSPF information\n" | |
4075 | VRF_CMD_HELP_STR | |
4076 | "All VRFs\n" | |
4077 | "Interface information\n" | |
4078 | "Protocol Packet counters\n" | |
4079 | "Interface name\n" | |
4080 | JSON_STR) | |
4081 | { | |
4082 | struct ospf *ospf = NULL; | |
4083 | struct listnode *node = NULL; | |
4084 | char *vrf_name = NULL, *intf_name = NULL; | |
4085 | bool all_vrf = false; | |
4086 | int inst = 0; | |
4087 | int idx_vrf = 0, idx_intf = 0; | |
4088 | bool uj = use_json(argc, argv); | |
4089 | json_object *json = NULL; | |
4090 | int ret = CMD_SUCCESS; | |
4091 | int display_once = 0; | |
4092 | uint8_t use_vrf = 0; | |
4093 | ||
4094 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4095 | ||
4096 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4097 | intf_name = argv[idx_intf]->arg; | |
4098 | ||
4099 | if (uj) | |
4100 | json = json_object_new_object(); | |
4101 | ||
4102 | if (vrf_name) { | |
4103 | use_vrf = 1; | |
4104 | if (all_vrf) { | |
4105 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4106 | if (!ospf->oi_running) | |
4107 | continue; | |
4108 | ||
4109 | ret = show_ip_ospf_interface_traffic_common( | |
4110 | vty, ospf, intf_name, json, | |
4111 | display_once, use_vrf, uj); | |
4112 | display_once = 1; | |
4113 | } | |
4114 | ||
4115 | if (uj) { | |
4116 | vty_out(vty, "%s\n", | |
4117 | json_object_to_json_string_ext( | |
4118 | json, JSON_C_TO_STRING_PRETTY)); | |
4119 | json_object_free(json); | |
4120 | } | |
4121 | ||
4122 | return ret; | |
4123 | } | |
4124 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4125 | if (ospf == NULL || !ospf->oi_running) { | |
4126 | if (uj) | |
4127 | json_object_free(json); | |
4128 | return CMD_SUCCESS; | |
4129 | } | |
4130 | ||
4131 | ret = show_ip_ospf_interface_traffic_common( | |
4132 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
4133 | } else { | |
4134 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4135 | if (ospf == NULL || !ospf->oi_running) { | |
4136 | if (uj) | |
4137 | json_object_free(json); | |
4138 | return CMD_SUCCESS; | |
4139 | } | |
4140 | ||
4141 | ret = show_ip_ospf_interface_traffic_common( | |
4142 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
4143 | } | |
4144 | ||
4145 | if (uj) { | |
4146 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4147 | json, JSON_C_TO_STRING_PRETTY)); | |
4148 | json_object_free(json); | |
4149 | } | |
4150 | ||
4151 | return ret; | |
4152 | } | |
4153 | ||
4154 | ||
4155 | static void show_ip_ospf_neighbour_header(struct vty *vty) | |
4156 | { | |
4157 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n", | |
4158 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", | |
4159 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4160 | } | |
4161 | ||
4162 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4163 | struct ospf_interface *oi, | |
4164 | json_object *json, bool use_json) | |
4165 | { | |
4166 | struct route_node *rn; | |
4167 | struct ospf_neighbor *nbr, *prev_nbr = NULL; | |
4168 | char msgbuf[16]; | |
4169 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4170 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; | |
4171 | ||
4172 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4173 | if ((nbr = rn->info)) { | |
4174 | /* Do not show myself. */ | |
4175 | if (nbr == oi->nbr_self) | |
4176 | continue; | |
4177 | /* Down state is not shown. */ | |
4178 | if (nbr->state == NSM_Down) | |
4179 | continue; | |
4180 | if (use_json) { | |
4181 | char neigh_str[INET_ADDRSTRLEN]; | |
4182 | ||
4183 | if (prev_nbr | |
4184 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4185 | &nbr->src)) { | |
4186 | /* Start new neigh list */ | |
4187 | json_neigh_array = NULL; | |
4188 | } | |
4189 | ||
4190 | if (nbr->state == NSM_Attempt | |
4191 | && nbr->router_id.s_addr == 0) | |
4192 | strlcpy(neigh_str, "neighbor", | |
4193 | sizeof(neigh_str)); | |
4194 | else | |
4195 | strlcpy(neigh_str, | |
4196 | inet_ntoa(nbr->router_id), | |
4197 | sizeof(neigh_str)); | |
4198 | ||
4199 | json_object_object_get_ex(json, neigh_str, | |
4200 | &json_neigh_array); | |
4201 | ||
4202 | if (!json_neigh_array) { | |
4203 | json_neigh_array = | |
4204 | json_object_new_array(); | |
4205 | json_object_object_add( | |
4206 | json, neigh_str, | |
4207 | json_neigh_array); | |
4208 | } | |
4209 | ||
4210 | json_neighbor = json_object_new_object(); | |
4211 | ||
4212 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4213 | ||
4214 | long time_store; | |
4215 | ||
4216 | time_store = | |
4217 | monotime_until( | |
4218 | &nbr->t_inactivity->u.sands, | |
4219 | NULL) | |
4220 | / 1000LL; | |
4221 | ||
4222 | json_object_int_add(json_neighbor, "priority", | |
4223 | nbr->priority); | |
4224 | json_object_string_add(json_neighbor, "state", | |
4225 | msgbuf); | |
4226 | json_object_int_add(json_neighbor, | |
4227 | "deadTimeMsecs", | |
4228 | time_store); | |
4229 | json_object_string_add(json_neighbor, "address", | |
4230 | inet_ntoa(nbr->src)); | |
4231 | json_object_string_add(json_neighbor, | |
4232 | "ifaceName", | |
4233 | IF_NAME(oi)); | |
4234 | json_object_int_add( | |
4235 | json_neighbor, "retransmitCounter", | |
4236 | ospf_ls_retransmit_count(nbr)); | |
4237 | json_object_int_add(json_neighbor, | |
4238 | "requestCounter", | |
4239 | ospf_ls_request_count(nbr)); | |
4240 | json_object_int_add(json_neighbor, | |
4241 | "dbSummaryCounter", | |
4242 | ospf_db_summary_count(nbr)); | |
4243 | ||
4244 | json_object_array_add(json_neigh_array, | |
4245 | json_neighbor); | |
4246 | } else { | |
4247 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4248 | ||
4249 | if (nbr->state == NSM_Attempt | |
4250 | && nbr->router_id.s_addr == 0) | |
4251 | vty_out(vty, "%-15s %3d %-15s ", "-", | |
4252 | nbr->priority, msgbuf); | |
4253 | else | |
4254 | vty_out(vty, "%-15s %3d %-15s ", | |
4255 | inet_ntoa(nbr->router_id), | |
4256 | nbr->priority, msgbuf); | |
4257 | ||
4258 | vty_out(vty, "%9s ", | |
4259 | ospf_timer_dump(nbr->t_inactivity, | |
4260 | timebuf, | |
4261 | sizeof(timebuf))); | |
4262 | vty_out(vty, "%-15s ", inet_ntoa(nbr->src)); | |
4263 | vty_out(vty, "%-20s %5ld %5ld %5d\n", | |
4264 | IF_NAME(oi), | |
4265 | ospf_ls_retransmit_count(nbr), | |
4266 | ospf_ls_request_count(nbr), | |
4267 | ospf_db_summary_count(nbr)); | |
4268 | } | |
4269 | prev_nbr = nbr; | |
4270 | } | |
4271 | } | |
4272 | } | |
4273 | ||
4274 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
4275 | json_object *json, bool use_json, | |
4276 | uint8_t use_vrf) | |
4277 | { | |
4278 | struct ospf_interface *oi; | |
4279 | struct listnode *node; | |
4280 | json_object *json_vrf = NULL; | |
4281 | json_object *json_nbr_sub = NULL; | |
4282 | ||
4283 | if (use_json) { | |
4284 | if (use_vrf) | |
4285 | json_vrf = json_object_new_object(); | |
4286 | else | |
4287 | json_vrf = json; | |
4288 | json_nbr_sub = json_object_new_object(); | |
4289 | } | |
4290 | ||
4291 | if (ospf->instance) { | |
4292 | if (use_json) | |
4293 | json_object_int_add(json, "ospfInstance", | |
4294 | ospf->instance); | |
4295 | else | |
4296 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4297 | } | |
4298 | ||
4299 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
4300 | if (!use_json) | |
4301 | show_ip_ospf_neighbour_header(vty); | |
4302 | ||
4303 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4304 | if (ospf_interface_neighbor_count(oi) == 0) | |
4305 | continue; | |
4306 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); | |
4307 | } | |
4308 | ||
4309 | if (use_json) { | |
4310 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); | |
4311 | if (use_vrf) { | |
4312 | if (ospf->vrf_id == VRF_DEFAULT) | |
4313 | json_object_object_add(json, "default", | |
4314 | json_vrf); | |
4315 | else | |
4316 | json_object_object_add(json, ospf->name, | |
4317 | json_vrf); | |
4318 | } | |
4319 | } else | |
4320 | vty_out(vty, "\n"); | |
4321 | ||
4322 | return CMD_SUCCESS; | |
4323 | } | |
4324 | ||
4325 | DEFUN (show_ip_ospf_neighbor, | |
4326 | show_ip_ospf_neighbor_cmd, | |
4327 | "show ip ospf [vrf <NAME|all>] neighbor [json]", | |
4328 | SHOW_STR | |
4329 | IP_STR | |
4330 | "OSPF information\n" | |
4331 | VRF_CMD_HELP_STR | |
4332 | "All VRFs\n" | |
4333 | "Neighbor list\n" | |
4334 | JSON_STR) | |
4335 | { | |
4336 | struct ospf *ospf; | |
4337 | bool uj = use_json(argc, argv); | |
4338 | struct listnode *node = NULL; | |
4339 | char *vrf_name = NULL; | |
4340 | bool all_vrf = false; | |
4341 | int ret = CMD_SUCCESS; | |
4342 | int inst = 0; | |
4343 | int idx_vrf = 0; | |
4344 | uint8_t use_vrf = 0; | |
4345 | json_object *json = NULL; | |
4346 | ||
4347 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4348 | ||
4349 | if (uj) | |
4350 | json = json_object_new_object(); | |
4351 | ||
4352 | /* vrf input is provided could be all or specific vrf*/ | |
4353 | if (vrf_name) { | |
4354 | use_vrf = 1; | |
4355 | if (all_vrf) { | |
4356 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4357 | if (!ospf->oi_running) | |
4358 | continue; | |
4359 | ret = show_ip_ospf_neighbor_common( | |
4360 | vty, ospf, json, uj, use_vrf); | |
4361 | } | |
4362 | ||
4363 | if (uj) { | |
4364 | vty_out(vty, "%s\n", | |
4365 | json_object_to_json_string_ext( | |
4366 | json, JSON_C_TO_STRING_PRETTY)); | |
4367 | json_object_free(json); | |
4368 | } else if (!ospf) | |
4369 | vty_out(vty, "OSPF instance not found\n"); | |
4370 | ||
4371 | return ret; | |
4372 | } | |
4373 | ||
4374 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4375 | if (ospf == NULL || !ospf->oi_running) { | |
4376 | if (uj) { | |
4377 | vty_out(vty, "%s\n", | |
4378 | json_object_to_json_string_ext( | |
4379 | json, JSON_C_TO_STRING_PRETTY)); | |
4380 | json_object_free(json); | |
4381 | } else | |
4382 | vty_out(vty, "%% OSPF instance not found\n"); | |
4383 | ||
4384 | return CMD_SUCCESS; | |
4385 | } | |
4386 | } else { | |
4387 | /* Display default ospf (instance 0) info */ | |
4388 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4389 | if (ospf == NULL || !ospf->oi_running) { | |
4390 | if (uj) { | |
4391 | vty_out(vty, "%s\n", | |
4392 | json_object_to_json_string_ext( | |
4393 | json, JSON_C_TO_STRING_PRETTY)); | |
4394 | json_object_free(json); | |
4395 | } else | |
4396 | vty_out(vty, "%% OSPF instance not found\n"); | |
4397 | ||
4398 | return CMD_SUCCESS; | |
4399 | } | |
4400 | } | |
4401 | ||
4402 | if (ospf) { | |
4403 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4404 | use_vrf); | |
4405 | ||
4406 | if (uj) { | |
4407 | vty_out(vty, "%s\n", | |
4408 | json_object_to_json_string_ext( | |
4409 | json, JSON_C_TO_STRING_PRETTY)); | |
4410 | } | |
4411 | } | |
4412 | ||
4413 | if (uj) | |
4414 | json_object_free(json); | |
4415 | ||
4416 | return ret; | |
4417 | } | |
4418 | ||
4419 | ||
4420 | DEFUN (show_ip_ospf_instance_neighbor, | |
4421 | show_ip_ospf_instance_neighbor_cmd, | |
4422 | "show ip ospf (1-65535) neighbor [json]", | |
4423 | SHOW_STR | |
4424 | IP_STR | |
4425 | "OSPF information\n" | |
4426 | "Instance ID\n" | |
4427 | "Neighbor list\n" | |
4428 | JSON_STR) | |
4429 | { | |
4430 | int idx_number = 3; | |
4431 | struct ospf *ospf; | |
4432 | unsigned short instance = 0; | |
4433 | bool uj = use_json(argc, argv); | |
4434 | json_object *json = NULL; | |
4435 | int ret = CMD_SUCCESS; | |
4436 | ||
4437 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
4438 | ospf = ospf_lookup_instance(instance); | |
4439 | if (ospf == NULL) | |
4440 | return CMD_NOT_MY_INSTANCE; | |
4441 | ||
4442 | if (!ospf->oi_running) | |
4443 | return CMD_SUCCESS; | |
4444 | ||
4445 | if (uj) | |
4446 | json = json_object_new_object(); | |
4447 | ||
4448 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); | |
4449 | ||
4450 | if (uj) { | |
4451 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4452 | json, JSON_C_TO_STRING_PRETTY)); | |
4453 | json_object_free(json); | |
4454 | } | |
4455 | ||
4456 | return ret; | |
4457 | } | |
4458 | ||
4459 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, | |
4460 | json_object *json, bool use_json, | |
4461 | uint8_t use_vrf) | |
4462 | { | |
4463 | struct listnode *node; | |
4464 | struct ospf_interface *oi; | |
4465 | json_object *json_vrf = NULL; | |
4466 | json_object *json_neighbor_sub = NULL; | |
4467 | ||
4468 | if (use_json) { | |
4469 | if (use_vrf) | |
4470 | json_vrf = json_object_new_object(); | |
4471 | else | |
4472 | json_vrf = json; | |
4473 | json_neighbor_sub = json_object_new_object(); | |
4474 | } | |
4475 | ||
4476 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
4477 | if (!use_json) | |
4478 | show_ip_ospf_neighbour_header(vty); | |
4479 | ||
4480 | if (ospf->instance) { | |
4481 | if (use_json) | |
4482 | json_object_int_add(json_vrf, "ospfInstance", | |
4483 | ospf->instance); | |
4484 | else | |
4485 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4486 | } | |
4487 | ||
4488 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4489 | struct listnode *nbr_node; | |
4490 | struct ospf_nbr_nbma *nbr_nbma; | |
4491 | ||
4492 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); | |
4493 | ||
4494 | /* print Down neighbor status */ | |
4495 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4496 | if (nbr_nbma->nbr == NULL | |
4497 | || nbr_nbma->nbr->state == NSM_Down) { | |
4498 | if (use_json) { | |
4499 | json_object_int_add(json_neighbor_sub, | |
4500 | "nbrNbmaPriority", | |
4501 | nbr_nbma->priority); | |
4502 | json_object_boolean_true_add( | |
4503 | json_neighbor_sub, | |
4504 | "nbrNbmaDown"); | |
4505 | json_object_string_add( | |
4506 | json_neighbor_sub, | |
4507 | "nbrNbmaIfaceName", | |
4508 | IF_NAME(oi)); | |
4509 | json_object_int_add( | |
4510 | json_neighbor_sub, | |
4511 | "nbrNbmaRetransmitCounter", 0); | |
4512 | json_object_int_add( | |
4513 | json_neighbor_sub, | |
4514 | "nbrNbmaRequestCounter", 0); | |
4515 | json_object_int_add( | |
4516 | json_neighbor_sub, | |
4517 | "nbrNbmaDbSummaryCounter", 0); | |
4518 | json_object_object_add( | |
4519 | json_vrf, | |
4520 | inet_ntoa(nbr_nbma->addr), | |
4521 | json_neighbor_sub); | |
4522 | } else { | |
4523 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4524 | "-", nbr_nbma->priority, "Down", | |
4525 | "-"); | |
4526 | vty_out(vty, | |
4527 | "%-15s %-20s %5d %5d %5d\n", | |
4528 | inet_ntoa(nbr_nbma->addr), | |
4529 | IF_NAME(oi), 0, 0, 0); | |
4530 | } | |
4531 | } | |
4532 | } | |
4533 | } | |
4534 | ||
4535 | if (use_json) { | |
4536 | if (use_vrf) { | |
4537 | if (ospf->vrf_id == VRF_DEFAULT) | |
4538 | json_object_object_add(json, "default", | |
4539 | json_vrf); | |
4540 | else | |
4541 | json_object_object_add(json, ospf->name, | |
4542 | json_vrf); | |
4543 | } | |
4544 | } else | |
4545 | vty_out(vty, "\n"); | |
4546 | ||
4547 | return CMD_SUCCESS; | |
4548 | } | |
4549 | ||
4550 | DEFUN (show_ip_ospf_neighbor_all, | |
4551 | show_ip_ospf_neighbor_all_cmd, | |
4552 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", | |
4553 | SHOW_STR | |
4554 | IP_STR | |
4555 | "OSPF information\n" | |
4556 | VRF_CMD_HELP_STR | |
4557 | "All VRFs\n" | |
4558 | "Neighbor list\n" | |
4559 | "include down status neighbor\n" | |
4560 | JSON_STR) | |
4561 | { | |
4562 | struct ospf *ospf; | |
4563 | bool uj = use_json(argc, argv); | |
4564 | struct listnode *node = NULL; | |
4565 | char *vrf_name = NULL; | |
4566 | bool all_vrf = false; | |
4567 | int ret = CMD_SUCCESS; | |
4568 | int inst = 0; | |
4569 | int idx_vrf = 0; | |
4570 | uint8_t use_vrf = 0; | |
4571 | json_object *json = NULL; | |
4572 | ||
4573 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4574 | ||
4575 | if (uj) | |
4576 | json = json_object_new_object(); | |
4577 | ||
4578 | /* vrf input is provided could be all or specific vrf*/ | |
4579 | if (vrf_name) { | |
4580 | use_vrf = 1; | |
4581 | if (all_vrf) { | |
4582 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4583 | if (!ospf->oi_running) | |
4584 | continue; | |
4585 | ret = show_ip_ospf_neighbor_all_common( | |
4586 | vty, ospf, json, uj, use_vrf); | |
4587 | } | |
4588 | ||
4589 | if (uj) { | |
4590 | vty_out(vty, "%s\n", | |
4591 | json_object_to_json_string_ext( | |
4592 | json, JSON_C_TO_STRING_PRETTY)); | |
4593 | json_object_free(json); | |
4594 | } | |
4595 | ||
4596 | return ret; | |
4597 | } | |
4598 | ||
4599 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4600 | if (ospf == NULL || !ospf->oi_running) { | |
4601 | if (uj) | |
4602 | json_object_free(json); | |
4603 | return CMD_SUCCESS; | |
4604 | } | |
4605 | } else { | |
4606 | /* Display default ospf (instance 0) info */ | |
4607 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4608 | if (ospf == NULL || !ospf->oi_running) { | |
4609 | if (uj) | |
4610 | json_object_free(json); | |
4611 | return CMD_SUCCESS; | |
4612 | } | |
4613 | } | |
4614 | ||
4615 | if (ospf) { | |
4616 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4617 | use_vrf); | |
4618 | if (uj) { | |
4619 | vty_out(vty, "%s\n", | |
4620 | json_object_to_json_string_ext( | |
4621 | json, JSON_C_TO_STRING_PRETTY)); | |
4622 | } | |
4623 | } | |
4624 | ||
4625 | if (uj) | |
4626 | json_object_free(json); | |
4627 | ||
4628 | return ret; | |
4629 | } | |
4630 | ||
4631 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4632 | show_ip_ospf_instance_neighbor_all_cmd, | |
4633 | "show ip ospf (1-65535) neighbor all [json]", | |
4634 | SHOW_STR | |
4635 | IP_STR | |
4636 | "OSPF information\n" | |
4637 | "Instance ID\n" | |
4638 | "Neighbor list\n" | |
4639 | "include down status neighbor\n" | |
4640 | JSON_STR) | |
4641 | { | |
4642 | int idx_number = 3; | |
4643 | struct ospf *ospf; | |
4644 | unsigned short instance = 0; | |
4645 | bool uj = use_json(argc, argv); | |
4646 | json_object *json = NULL; | |
4647 | int ret = CMD_SUCCESS; | |
4648 | ||
4649 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
4650 | ospf = ospf_lookup_instance(instance); | |
4651 | if (ospf == NULL) | |
4652 | return CMD_NOT_MY_INSTANCE; | |
4653 | ||
4654 | if (!ospf->oi_running) | |
4655 | return CMD_SUCCESS; | |
4656 | if (uj) | |
4657 | json = json_object_new_object(); | |
4658 | ||
4659 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4660 | ||
4661 | if (uj) { | |
4662 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4663 | json, JSON_C_TO_STRING_PRETTY)); | |
4664 | json_object_free(json); | |
4665 | } | |
4666 | ||
4667 | return ret; | |
4668 | } | |
4669 | ||
4670 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, | |
4671 | int arg_base, | |
4672 | struct cmd_token **argv, | |
4673 | bool use_json, uint8_t use_vrf) | |
4674 | { | |
4675 | struct interface *ifp; | |
4676 | struct route_node *rn; | |
4677 | json_object *json = NULL; | |
4678 | ||
4679 | if (use_json) | |
4680 | json = json_object_new_object(); | |
4681 | ||
4682 | if (ospf->instance) { | |
4683 | if (use_json) | |
4684 | json_object_int_add(json, "ospfInstance", | |
4685 | ospf->instance); | |
4686 | else | |
4687 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4688 | } | |
4689 | ||
4690 | ospf_show_vrf_name(ospf, vty, json, use_vrf); | |
4691 | ||
4692 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); | |
4693 | if (!ifp) { | |
4694 | if (use_json) | |
4695 | json_object_boolean_true_add(json, "noSuchIface"); | |
4696 | else | |
4697 | vty_out(vty, "No such interface.\n"); | |
4698 | return CMD_WARNING; | |
4699 | } | |
4700 | ||
4701 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4702 | struct ospf_interface *oi = rn->info; | |
4703 | ||
4704 | if (oi == NULL) | |
4705 | continue; | |
4706 | ||
4707 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4708 | } | |
4709 | ||
4710 | if (use_json) { | |
4711 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4712 | json, JSON_C_TO_STRING_PRETTY)); | |
4713 | json_object_free(json); | |
4714 | } else | |
4715 | vty_out(vty, "\n"); | |
4716 | ||
4717 | return CMD_SUCCESS; | |
4718 | } | |
4719 | ||
4720 | DEFUN (show_ip_ospf_neighbor_int, | |
4721 | show_ip_ospf_neighbor_int_cmd, | |
4722 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", | |
4723 | SHOW_STR | |
4724 | IP_STR | |
4725 | "OSPF information\n" | |
4726 | VRF_CMD_HELP_STR | |
4727 | "Neighbor list\n" | |
4728 | "Interface name\n" | |
4729 | JSON_STR) | |
4730 | { | |
4731 | struct ospf *ospf; | |
4732 | int idx_ifname = 0; | |
4733 | int idx_vrf = 0; | |
4734 | bool uj = use_json(argc, argv); | |
4735 | int ret = CMD_SUCCESS; | |
4736 | struct interface *ifp = NULL; | |
4737 | char *vrf_name = NULL; | |
4738 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4739 | struct vrf *vrf = NULL; | |
4740 | ||
4741 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4742 | vrf_name = argv[idx_vrf + 1]->arg; | |
4743 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4744 | vrf_name = NULL; | |
4745 | if (vrf_name) { | |
4746 | vrf = vrf_lookup_by_name(vrf_name); | |
4747 | if (vrf) | |
4748 | vrf_id = vrf->vrf_id; | |
4749 | } | |
4750 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4751 | ||
4752 | if (!ospf || !ospf->oi_running) | |
4753 | return ret; | |
4754 | ||
4755 | if (!uj) | |
4756 | show_ip_ospf_neighbour_header(vty); | |
4757 | ||
4758 | argv_find(argv, argc, "IFNAME", &idx_ifname); | |
4759 | ||
4760 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); | |
4761 | if (!ifp) | |
4762 | return ret; | |
4763 | ||
4764 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4765 | argv, uj, 0); | |
4766 | return ret; | |
4767 | } | |
4768 | ||
4769 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4770 | show_ip_ospf_instance_neighbor_int_cmd, | |
4771 | "show ip ospf (1-65535) neighbor IFNAME [json]", | |
4772 | SHOW_STR | |
4773 | IP_STR | |
4774 | "OSPF information\n" | |
4775 | "Instance ID\n" | |
4776 | "Neighbor list\n" | |
4777 | "Interface name\n" | |
4778 | JSON_STR) | |
4779 | { | |
4780 | int idx_number = 3; | |
4781 | int idx_ifname = 5; | |
4782 | struct ospf *ospf; | |
4783 | unsigned short instance = 0; | |
4784 | bool uj = use_json(argc, argv); | |
4785 | ||
4786 | if (!uj) | |
4787 | show_ip_ospf_neighbour_header(vty); | |
4788 | ||
4789 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
4790 | ospf = ospf_lookup_instance(instance); | |
4791 | if (ospf == NULL) | |
4792 | return CMD_NOT_MY_INSTANCE; | |
4793 | ||
4794 | if (!ospf->oi_running) | |
4795 | return CMD_SUCCESS; | |
4796 | ||
4797 | if (!uj) | |
4798 | show_ip_ospf_neighbour_header(vty); | |
4799 | ||
4800 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, | |
4801 | 0); | |
4802 | } | |
4803 | ||
4804 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, | |
4805 | struct ospf_interface *oi, | |
4806 | struct ospf_nbr_nbma *nbr_nbma, | |
4807 | bool use_json, json_object *json) | |
4808 | { | |
4809 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4810 | json_object *json_sub = NULL; | |
4811 | ||
4812 | if (use_json) | |
4813 | json_sub = json_object_new_object(); | |
4814 | else /* Show neighbor ID. */ | |
4815 | vty_out(vty, " Neighbor %s,", "-"); | |
4816 | ||
4817 | /* Show interface address. */ | |
4818 | if (use_json) | |
4819 | json_object_string_add(json_sub, "ifaceAddress", | |
4820 | inet_ntoa(nbr_nbma->addr)); | |
4821 | else | |
4822 | vty_out(vty, " interface address %s\n", | |
4823 | inet_ntoa(nbr_nbma->addr)); | |
4824 | ||
4825 | /* Show Area ID. */ | |
4826 | if (use_json) { | |
4827 | json_object_string_add(json_sub, "areaId", | |
4828 | ospf_area_desc_string(oi->area)); | |
4829 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
4830 | } else | |
4831 | vty_out(vty, " In the area %s via interface %s\n", | |
4832 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
4833 | ||
4834 | /* Show neighbor priority and state. */ | |
4835 | if (use_json) { | |
4836 | json_object_int_add(json_sub, "nbrPriority", | |
4837 | nbr_nbma->priority); | |
4838 | json_object_string_add(json_sub, "nbrState", "down"); | |
4839 | } else | |
4840 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4841 | nbr_nbma->priority, "Down"); | |
4842 | ||
4843 | /* Show state changes. */ | |
4844 | if (use_json) | |
4845 | json_object_int_add(json_sub, "stateChangeCounter", | |
4846 | nbr_nbma->state_change); | |
4847 | else | |
4848 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
4849 | ||
4850 | /* Show PollInterval */ | |
4851 | if (use_json) | |
4852 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
4853 | else | |
4854 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
4855 | ||
4856 | /* Show poll-interval timer. */ | |
4857 | if (nbr_nbma->t_poll) { | |
4858 | if (use_json) { | |
4859 | long time_store; | |
4860 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
4861 | NULL) / 1000LL; | |
4862 | json_object_int_add(json_sub, | |
4863 | "pollIntervalTimerDueMsec", | |
4864 | time_store); | |
4865 | } else | |
4866 | vty_out(vty, " Poll timer due in %s\n", | |
4867 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
4868 | sizeof(timebuf))); | |
4869 | } | |
4870 | ||
4871 | /* Show poll-interval timer thread. */ | |
4872 | if (use_json) { | |
4873 | if (nbr_nbma->t_poll != NULL) | |
4874 | json_object_string_add(json_sub, | |
4875 | "pollIntervalTimerThread", "on"); | |
4876 | } else | |
4877 | vty_out(vty, " Thread Poll Timer %s\n", | |
4878 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
4879 | ||
4880 | if (use_json) | |
4881 | json_object_object_add(json, "noNbrId", json_sub); | |
4882 | } | |
4883 | ||
4884 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
4885 | struct ospf_interface *oi, | |
4886 | struct ospf_neighbor *nbr, | |
4887 | struct ospf_neighbor *prev_nbr, | |
4888 | json_object *json, bool use_json) | |
4889 | { | |
4890 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4891 | json_object *json_neigh = NULL, *json_neigh_array = NULL; | |
4892 | char neigh_str[INET_ADDRSTRLEN] = {0}; | |
4893 | ||
4894 | if (use_json) { | |
4895 | if (prev_nbr && | |
4896 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
4897 | json_neigh_array = NULL; | |
4898 | } | |
4899 | ||
4900 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
4901 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); | |
4902 | else | |
4903 | strlcpy(neigh_str, inet_ntoa(nbr->router_id), | |
4904 | sizeof(neigh_str)); | |
4905 | ||
4906 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
4907 | ||
4908 | if (!json_neigh_array) { | |
4909 | json_neigh_array = json_object_new_array(); | |
4910 | json_object_object_add(json, neigh_str, | |
4911 | json_neigh_array); | |
4912 | } | |
4913 | ||
4914 | json_neigh = json_object_new_object(); | |
4915 | ||
4916 | } else { | |
4917 | /* Show neighbor ID. */ | |
4918 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
4919 | vty_out(vty, " Neighbor %s,", "-"); | |
4920 | else | |
4921 | vty_out(vty, " Neighbor %s,", | |
4922 | inet_ntoa(nbr->router_id)); | |
4923 | } | |
4924 | ||
4925 | /* Show interface address. */ | |
4926 | if (use_json) | |
4927 | json_object_string_add(json_neigh, "ifaceAddress", | |
4928 | inet_ntoa(nbr->address.u.prefix4)); | |
4929 | else | |
4930 | vty_out(vty, " interface address %s\n", | |
4931 | inet_ntoa(nbr->address.u.prefix4)); | |
4932 | ||
4933 | /* Show Area ID. */ | |
4934 | if (use_json) { | |
4935 | json_object_string_add(json_neigh, "areaId", | |
4936 | ospf_area_desc_string(oi->area)); | |
4937 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); | |
4938 | } else | |
4939 | vty_out(vty, " In the area %s via interface %s\n", | |
4940 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
4941 | ||
4942 | /* Show neighbor priority and state. */ | |
4943 | if (use_json) { | |
4944 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); | |
4945 | json_object_string_add( | |
4946 | json_neigh, "nbrState", | |
4947 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4948 | } else | |
4949 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4950 | nbr->priority, | |
4951 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4952 | ||
4953 | /* Show state changes. */ | |
4954 | if (use_json) | |
4955 | json_object_int_add(json_neigh, "stateChangeCounter", | |
4956 | nbr->state_change); | |
4957 | else | |
4958 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
4959 | ||
4960 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
4961 | struct timeval res; | |
4962 | long time_store; | |
4963 | ||
4964 | time_store = | |
4965 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
4966 | if (use_json) { | |
4967 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", | |
4968 | time_store); | |
4969 | } else { | |
4970 | vty_out(vty, | |
4971 | " Most recent state change statistics:\n"); | |
4972 | vty_out(vty, " Progressive change %s ago\n", | |
4973 | ospf_timeval_dump(&res, timebuf, | |
4974 | sizeof(timebuf))); | |
4975 | } | |
4976 | } | |
4977 | ||
4978 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
4979 | struct timeval res; | |
4980 | long time_store; | |
4981 | ||
4982 | time_store = | |
4983 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
4984 | if (use_json) { | |
4985 | json_object_int_add(json_neigh, | |
4986 | "lastRegressiveChangeMsec", | |
4987 | time_store); | |
4988 | if (nbr->last_regress_str) | |
4989 | json_object_string_add( | |
4990 | json_neigh, | |
4991 | "lastRegressiveChangeReason", | |
4992 | nbr->last_regress_str); | |
4993 | } else { | |
4994 | vty_out(vty, | |
4995 | " Regressive change %s ago, due to %s\n", | |
4996 | ospf_timeval_dump(&res, timebuf, | |
4997 | sizeof(timebuf)), | |
4998 | (nbr->last_regress_str ? nbr->last_regress_str | |
4999 | : "??")); | |
5000 | } | |
5001 | } | |
5002 | ||
5003 | /* Show Designated Rotuer ID. */ | |
5004 | if (use_json) | |
5005 | json_object_string_add(json_neigh, "routerDesignatedId", | |
5006 | inet_ntoa(nbr->d_router)); | |
5007 | else | |
5008 | vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router)); | |
5009 | ||
5010 | /* Show Backup Designated Rotuer ID. */ | |
5011 | if (use_json) | |
5012 | json_object_string_add(json_neigh, "routerDesignatedBackupId", | |
5013 | inet_ntoa(nbr->bd_router)); | |
5014 | else | |
5015 | vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router)); | |
5016 | ||
5017 | /* Show options. */ | |
5018 | if (use_json) { | |
5019 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); | |
5020 | json_object_string_add(json_neigh, "optionsList", | |
5021 | ospf_options_dump(nbr->options)); | |
5022 | } else | |
5023 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5024 | ospf_options_dump(nbr->options)); | |
5025 | ||
5026 | /* Show Router Dead interval timer. */ | |
5027 | if (use_json) { | |
5028 | if (nbr->t_inactivity) { | |
5029 | long time_store; | |
5030 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5031 | NULL) | |
5032 | / 1000LL; | |
5033 | json_object_int_add(json_neigh, | |
5034 | "routerDeadIntervalTimerDueMsec", | |
5035 | time_store); | |
5036 | } else | |
5037 | json_object_int_add( | |
5038 | json_neigh, | |
5039 | "routerDeadIntervalTimerDueMsec", -1); | |
5040 | } else | |
5041 | vty_out(vty, " Dead timer due in %s\n", | |
5042 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5043 | sizeof(timebuf))); | |
5044 | ||
5045 | /* Show Database Summary list. */ | |
5046 | if (use_json) | |
5047 | json_object_int_add(json_neigh, "databaseSummaryListCounter", | |
5048 | ospf_db_summary_count(nbr)); | |
5049 | else | |
5050 | vty_out(vty, " Database Summary List %d\n", | |
5051 | ospf_db_summary_count(nbr)); | |
5052 | ||
5053 | /* Show Link State Request list. */ | |
5054 | if (use_json) | |
5055 | json_object_int_add(json_neigh, "linkStateRequestListCounter", | |
5056 | ospf_ls_request_count(nbr)); | |
5057 | else | |
5058 | vty_out(vty, " Link State Request List %ld\n", | |
5059 | ospf_ls_request_count(nbr)); | |
5060 | ||
5061 | /* Show Link State Retransmission list. */ | |
5062 | if (use_json) | |
5063 | json_object_int_add(json_neigh, | |
5064 | "linkStateRetransmissionListCounter", | |
5065 | ospf_ls_retransmit_count(nbr)); | |
5066 | else | |
5067 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5068 | ospf_ls_retransmit_count(nbr)); | |
5069 | ||
5070 | /* Show inactivity timer thread. */ | |
5071 | if (use_json) { | |
5072 | if (nbr->t_inactivity != NULL) | |
5073 | json_object_string_add(json_neigh, | |
5074 | "threadInactivityTimer", "on"); | |
5075 | } else | |
5076 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5077 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5078 | ||
5079 | /* Show Database Description retransmission thread. */ | |
5080 | if (use_json) { | |
5081 | if (nbr->t_db_desc != NULL) | |
5082 | json_object_string_add( | |
5083 | json_neigh, | |
5084 | "threadDatabaseDescriptionRetransmission", | |
5085 | "on"); | |
5086 | } else | |
5087 | vty_out(vty, | |
5088 | " Thread Database Description Retransmision %s\n", | |
5089 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5090 | ||
5091 | /* Show Link State Request Retransmission thread. */ | |
5092 | if (use_json) { | |
5093 | if (nbr->t_ls_req != NULL) | |
5094 | json_object_string_add( | |
5095 | json_neigh, | |
5096 | "threadLinkStateRequestRetransmission", "on"); | |
5097 | } else | |
5098 | vty_out(vty, | |
5099 | " Thread Link State Request Retransmission %s\n", | |
5100 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5101 | ||
5102 | /* Show Link State Update Retransmission thread. */ | |
5103 | if (use_json) { | |
5104 | if (nbr->t_ls_upd != NULL) | |
5105 | json_object_string_add( | |
5106 | json_neigh, | |
5107 | "threadLinkStateUpdateRetransmission", | |
5108 | "on"); | |
5109 | } else | |
5110 | vty_out(vty, | |
5111 | " Thread Link State Update Retransmission %s\n\n", | |
5112 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5113 | ||
5114 | ospf_bfd_show_info(vty, nbr->bfd_info, json_neigh, use_json, 0); | |
5115 | ||
5116 | if (use_json) | |
5117 | json_object_array_add(json_neigh_array, json_neigh); | |
5118 | ||
5119 | } | |
5120 | ||
5121 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
5122 | struct in_addr *router_id, | |
5123 | bool use_json, uint8_t use_vrf) | |
5124 | { | |
5125 | struct listnode *node; | |
5126 | struct ospf_neighbor *nbr; | |
5127 | struct ospf_interface *oi; | |
5128 | json_object *json = NULL; | |
5129 | ||
5130 | if (use_json) | |
5131 | json = json_object_new_object(); | |
5132 | ||
5133 | if (ospf->instance) { | |
5134 | if (use_json) | |
5135 | json_object_int_add(json, "ospfInstance", | |
5136 | ospf->instance); | |
5137 | else | |
5138 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5139 | } | |
5140 | ||
5141 | ospf_show_vrf_name(ospf, vty, json, use_vrf); | |
5142 | ||
5143 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
5144 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { | |
5145 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, | |
5146 | json, use_json); | |
5147 | } | |
5148 | } | |
5149 | ||
5150 | if (use_json) { | |
5151 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5152 | json, JSON_C_TO_STRING_PRETTY)); | |
5153 | json_object_free(json); | |
5154 | } else | |
5155 | vty_out(vty, "\n"); | |
5156 | ||
5157 | return CMD_SUCCESS; | |
5158 | } | |
5159 | ||
5160 | DEFPY (show_ip_ospf_neighbor_id, | |
5161 | show_ip_ospf_neighbor_id_cmd, | |
5162 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", | |
5163 | SHOW_STR | |
5164 | IP_STR | |
5165 | "OSPF information\n" | |
5166 | "Neighbor list\n" | |
5167 | "Neighbor ID\n" | |
5168 | JSON_STR) | |
5169 | { | |
5170 | struct ospf *ospf; | |
5171 | struct listnode *node; | |
5172 | int ret = CMD_SUCCESS; | |
5173 | ||
5174 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5175 | if (!ospf->oi_running) | |
5176 | continue; | |
5177 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, | |
5178 | !!json, 0); | |
5179 | } | |
5180 | ||
5181 | return ret; | |
5182 | } | |
5183 | ||
5184 | DEFPY (show_ip_ospf_instance_neighbor_id, | |
5185 | show_ip_ospf_instance_neighbor_id_cmd, | |
5186 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", | |
5187 | SHOW_STR | |
5188 | IP_STR | |
5189 | "OSPF information\n" | |
5190 | "Instance ID\n" | |
5191 | "Neighbor list\n" | |
5192 | "Neighbor ID\n" | |
5193 | JSON_STR) | |
5194 | { | |
5195 | struct ospf *ospf; | |
5196 | ||
5197 | ospf = ospf_lookup_instance(instance); | |
5198 | if (ospf == NULL) | |
5199 | return CMD_NOT_MY_INSTANCE; | |
5200 | ||
5201 | if (!ospf->oi_running) | |
5202 | return CMD_SUCCESS; | |
5203 | ||
5204 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, | |
5205 | 0); | |
5206 | } | |
5207 | ||
5208 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, | |
5209 | struct ospf *ospf, | |
5210 | json_object *json, bool use_json, | |
5211 | uint8_t use_vrf) | |
5212 | { | |
5213 | struct ospf_interface *oi; | |
5214 | struct listnode *node; | |
5215 | json_object *json_vrf = NULL; | |
5216 | json_object *json_nbr_sub = NULL; | |
5217 | ||
5218 | if (use_json) { | |
5219 | if (use_vrf) | |
5220 | json_vrf = json_object_new_object(); | |
5221 | else | |
5222 | json_vrf = json; | |
5223 | ||
5224 | json_nbr_sub = json_object_new_object(); | |
5225 | } | |
5226 | ||
5227 | if (ospf->instance) { | |
5228 | if (use_json) | |
5229 | json_object_int_add(json, "ospfInstance", | |
5230 | ospf->instance); | |
5231 | else | |
5232 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5233 | } | |
5234 | ||
5235 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
5236 | ||
5237 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
5238 | struct route_node *rn; | |
5239 | struct ospf_neighbor *nbr, *prev_nbr = NULL; | |
5240 | ||
5241 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5242 | if ((nbr = rn->info)) { | |
5243 | if (nbr != oi->nbr_self) { | |
5244 | if (nbr->state != NSM_Down) { | |
5245 | show_ip_ospf_neighbor_detail_sub( | |
5246 | vty, oi, nbr, prev_nbr, | |
5247 | json_nbr_sub, use_json); | |
5248 | } | |
5249 | } | |
5250 | prev_nbr = nbr; | |
5251 | } | |
5252 | } | |
5253 | } | |
5254 | ||
5255 | if (use_json) { | |
5256 | json_object_object_add(json_vrf, "neighbors", | |
5257 | json_nbr_sub); | |
5258 | if (use_vrf) { | |
5259 | if (ospf->vrf_id == VRF_DEFAULT) | |
5260 | json_object_object_add(json, "default", | |
5261 | json_vrf); | |
5262 | else | |
5263 | json_object_object_add(json, ospf->name, | |
5264 | json_vrf); | |
5265 | } | |
5266 | } else | |
5267 | vty_out(vty, "\n"); | |
5268 | ||
5269 | return CMD_SUCCESS; | |
5270 | } | |
5271 | ||
5272 | DEFUN (show_ip_ospf_neighbor_detail, | |
5273 | show_ip_ospf_neighbor_detail_cmd, | |
5274 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", | |
5275 | SHOW_STR | |
5276 | IP_STR | |
5277 | "OSPF information\n" | |
5278 | VRF_CMD_HELP_STR | |
5279 | "All VRFs\n" | |
5280 | "Neighbor list\n" | |
5281 | "detail of all neighbors\n" | |
5282 | JSON_STR) | |
5283 | { | |
5284 | struct ospf *ospf; | |
5285 | bool uj = use_json(argc, argv); | |
5286 | struct listnode *node = NULL; | |
5287 | char *vrf_name = NULL; | |
5288 | bool all_vrf = false; | |
5289 | int ret = CMD_SUCCESS; | |
5290 | int inst = 0; | |
5291 | int idx_vrf = 0; | |
5292 | uint8_t use_vrf = 0; | |
5293 | json_object *json = NULL; | |
5294 | ||
5295 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
5296 | ||
5297 | if (uj) | |
5298 | json = json_object_new_object(); | |
5299 | ||
5300 | /* vrf input is provided could be all or specific vrf*/ | |
5301 | if (vrf_name) { | |
5302 | use_vrf = 1; | |
5303 | if (all_vrf) { | |
5304 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5305 | if (!ospf->oi_running) | |
5306 | continue; | |
5307 | ret = show_ip_ospf_neighbor_detail_common( | |
5308 | vty, ospf, json, uj, use_vrf); | |
5309 | } | |
5310 | if (uj) { | |
5311 | vty_out(vty, "%s\n", | |
5312 | json_object_to_json_string_ext( | |
5313 | json, JSON_C_TO_STRING_PRETTY)); | |
5314 | json_object_free(json); | |
5315 | } | |
5316 | ||
5317 | return ret; | |
5318 | } | |
5319 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
5320 | if (ospf == NULL || !ospf->oi_running) { | |
5321 | if (uj) | |
5322 | json_object_free(json); | |
5323 | return CMD_SUCCESS; | |
5324 | } | |
5325 | } else { | |
5326 | /* Display default ospf (instance 0) info */ | |
5327 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
5328 | if (ospf == NULL || !ospf->oi_running) { | |
5329 | if (uj) | |
5330 | json_object_free(json); | |
5331 | return CMD_SUCCESS; | |
5332 | } | |
5333 | } | |
5334 | ||
5335 | if (ospf) { | |
5336 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5337 | use_vrf); | |
5338 | if (uj) { | |
5339 | vty_out(vty, "%s\n", | |
5340 | json_object_to_json_string_ext( | |
5341 | json, JSON_C_TO_STRING_PRETTY)); | |
5342 | } | |
5343 | } | |
5344 | ||
5345 | if (uj) | |
5346 | json_object_free(json); | |
5347 | ||
5348 | return ret; | |
5349 | } | |
5350 | ||
5351 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5352 | show_ip_ospf_instance_neighbor_detail_cmd, | |
5353 | "show ip ospf (1-65535) neighbor detail [json]", | |
5354 | SHOW_STR | |
5355 | IP_STR | |
5356 | "OSPF information\n" | |
5357 | "Instance ID\n" | |
5358 | "Neighbor list\n" | |
5359 | "detail of all neighbors\n" | |
5360 | JSON_STR) | |
5361 | { | |
5362 | int idx_number = 3; | |
5363 | struct ospf *ospf; | |
5364 | unsigned short instance = 0; | |
5365 | bool uj = use_json(argc, argv); | |
5366 | json_object *json = NULL; | |
5367 | int ret = CMD_SUCCESS; | |
5368 | ||
5369 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
5370 | ospf = ospf_lookup_instance(instance); | |
5371 | if (ospf == NULL) | |
5372 | return CMD_NOT_MY_INSTANCE; | |
5373 | ||
5374 | if (!ospf->oi_running) | |
5375 | return CMD_SUCCESS; | |
5376 | ||
5377 | if (uj) | |
5378 | json = json_object_new_object(); | |
5379 | ||
5380 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5381 | ||
5382 | if (uj) { | |
5383 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5384 | json, JSON_C_TO_STRING_PRETTY)); | |
5385 | json_object_free(json); | |
5386 | } | |
5387 | ||
5388 | return ret; | |
5389 | } | |
5390 | ||
5391 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, | |
5392 | struct ospf *ospf, | |
5393 | json_object *json, | |
5394 | bool use_json, | |
5395 | uint8_t use_vrf) | |
5396 | { | |
5397 | struct listnode *node; | |
5398 | struct ospf_interface *oi; | |
5399 | json_object *json_vrf = NULL; | |
5400 | ||
5401 | if (use_json) { | |
5402 | if (use_vrf) | |
5403 | json_vrf = json_object_new_object(); | |
5404 | else | |
5405 | json_vrf = json; | |
5406 | } | |
5407 | ||
5408 | if (ospf->instance) { | |
5409 | if (use_json) | |
5410 | json_object_int_add(json, "ospfInstance", | |
5411 | ospf->instance); | |
5412 | else | |
5413 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5414 | } | |
5415 | ||
5416 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
5417 | ||
5418 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
5419 | struct route_node *rn; | |
5420 | struct ospf_neighbor *nbr, *prev_nbr = NULL; | |
5421 | struct ospf_nbr_nbma *nbr_nbma; | |
5422 | ||
5423 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5424 | if ((nbr = rn->info)) { | |
5425 | if (nbr != oi->nbr_self) | |
5426 | if (nbr->state != NSM_Down) | |
5427 | show_ip_ospf_neighbor_detail_sub( | |
5428 | vty, oi, rn->info, | |
5429 | prev_nbr, | |
5430 | json_vrf, use_json); | |
5431 | prev_nbr = nbr; | |
5432 | } | |
5433 | } | |
5434 | ||
5435 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5436 | struct listnode *nd; | |
5437 | ||
5438 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5439 | if (nbr_nbma->nbr == NULL | |
5440 | || nbr_nbma->nbr->state == NSM_Down) | |
5441 | show_ip_ospf_nbr_nbma_detail_sub( | |
5442 | vty, oi, nbr_nbma, use_json, | |
5443 | json_vrf); | |
5444 | } | |
5445 | } | |
5446 | } | |
5447 | ||
5448 | if (use_json) { | |
5449 | if (use_vrf) { | |
5450 | if (ospf->vrf_id == VRF_DEFAULT) | |
5451 | json_object_object_add(json, "default", | |
5452 | json_vrf); | |
5453 | else | |
5454 | json_object_object_add(json, ospf->name, | |
5455 | json_vrf); | |
5456 | } | |
5457 | } else { | |
5458 | vty_out(vty, "\n"); | |
5459 | } | |
5460 | ||
5461 | return CMD_SUCCESS; | |
5462 | } | |
5463 | ||
5464 | DEFUN (show_ip_ospf_neighbor_detail_all, | |
5465 | show_ip_ospf_neighbor_detail_all_cmd, | |
5466 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", | |
5467 | SHOW_STR | |
5468 | IP_STR | |
5469 | "OSPF information\n" | |
5470 | VRF_CMD_HELP_STR | |
5471 | "All VRFs\n" | |
5472 | "Neighbor list\n" | |
5473 | "detail of all neighbors\n" | |
5474 | "include down status neighbor\n" | |
5475 | JSON_STR) | |
5476 | { | |
5477 | struct ospf *ospf; | |
5478 | bool uj = use_json(argc, argv); | |
5479 | struct listnode *node = NULL; | |
5480 | char *vrf_name = NULL; | |
5481 | bool all_vrf = false; | |
5482 | int ret = CMD_SUCCESS; | |
5483 | int inst = 0; | |
5484 | int idx_vrf = 0; | |
5485 | uint8_t use_vrf = 0; | |
5486 | json_object *json = NULL; | |
5487 | ||
5488 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
5489 | ||
5490 | if (uj) | |
5491 | json = json_object_new_object(); | |
5492 | ||
5493 | /* vrf input is provided could be all or specific vrf*/ | |
5494 | if (vrf_name) { | |
5495 | use_vrf = 1; | |
5496 | if (all_vrf) { | |
5497 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5498 | if (!ospf->oi_running) | |
5499 | continue; | |
5500 | ret = show_ip_ospf_neighbor_detail_all_common( | |
5501 | vty, ospf, json, uj, use_vrf); | |
5502 | } | |
5503 | ||
5504 | if (uj) { | |
5505 | vty_out(vty, "%s\n", | |
5506 | json_object_to_json_string_ext( | |
5507 | json, JSON_C_TO_STRING_PRETTY)); | |
5508 | json_object_free(json); | |
5509 | } | |
5510 | ||
5511 | return ret; | |
5512 | } | |
5513 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
5514 | if (ospf == NULL || !ospf->oi_running) { | |
5515 | if (uj) | |
5516 | json_object_free(json); | |
5517 | return CMD_SUCCESS; | |
5518 | } | |
5519 | } else { | |
5520 | /* Display default ospf (instance 0) info */ | |
5521 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
5522 | if (ospf == NULL || !ospf->oi_running) { | |
5523 | if (uj) | |
5524 | json_object_free(json); | |
5525 | return CMD_SUCCESS; | |
5526 | } | |
5527 | } | |
5528 | ||
5529 | if (ospf) { | |
5530 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5531 | uj, use_vrf); | |
5532 | if (uj) { | |
5533 | vty_out(vty, "%s\n", | |
5534 | json_object_to_json_string_ext( | |
5535 | json, JSON_C_TO_STRING_PRETTY)); | |
5536 | } | |
5537 | } | |
5538 | ||
5539 | if (uj) | |
5540 | json_object_free(json); | |
5541 | ||
5542 | return ret; | |
5543 | } | |
5544 | ||
5545 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5546 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
5547 | "show ip ospf (1-65535) neighbor detail all [json]", | |
5548 | SHOW_STR | |
5549 | IP_STR | |
5550 | "OSPF information\n" | |
5551 | "Instance ID\n" | |
5552 | "Neighbor list\n" | |
5553 | "detail of all neighbors\n" | |
5554 | "include down status neighbor\n" | |
5555 | JSON_STR) | |
5556 | { | |
5557 | int idx_number = 3; | |
5558 | struct ospf *ospf; | |
5559 | unsigned short instance = 0; | |
5560 | bool uj = use_json(argc, argv); | |
5561 | json_object *json = NULL; | |
5562 | int ret = CMD_SUCCESS; | |
5563 | ||
5564 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
5565 | ospf = ospf_lookup_instance(instance); | |
5566 | if (ospf == NULL) | |
5567 | return CMD_NOT_MY_INSTANCE; | |
5568 | ||
5569 | if (!ospf->oi_running) | |
5570 | return CMD_SUCCESS; | |
5571 | ||
5572 | if (uj) | |
5573 | json = json_object_new_object(); | |
5574 | ||
5575 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5576 | ||
5577 | if (uj) { | |
5578 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5579 | json, JSON_C_TO_STRING_PRETTY)); | |
5580 | json_object_free(json); | |
5581 | } | |
5582 | ||
5583 | return ret; | |
5584 | } | |
5585 | ||
5586 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, | |
5587 | struct ospf *ospf, | |
5588 | int arg_base, | |
5589 | struct cmd_token **argv, | |
5590 | bool use_json) | |
5591 | { | |
5592 | struct ospf_interface *oi; | |
5593 | struct interface *ifp; | |
5594 | struct route_node *rn, *nrn; | |
5595 | struct ospf_neighbor *nbr; | |
5596 | json_object *json = NULL; | |
5597 | ||
5598 | if (use_json) | |
5599 | json = json_object_new_object(); | |
5600 | ||
5601 | if (ospf->instance) { | |
5602 | if (use_json) | |
5603 | json_object_int_add(json, "ospfInstance", | |
5604 | ospf->instance); | |
5605 | else | |
5606 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5607 | } | |
5608 | ||
5609 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); | |
5610 | if (!ifp) { | |
5611 | if (!use_json) | |
5612 | vty_out(vty, "No such interface.\n"); | |
5613 | else { | |
5614 | vty_out(vty, "{}\n"); | |
5615 | json_object_free(json); | |
5616 | } | |
5617 | return CMD_WARNING; | |
5618 | } | |
5619 | ||
5620 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5621 | if ((oi = rn->info)) { | |
5622 | for (nrn = route_top(oi->nbrs); nrn; | |
5623 | nrn = route_next(nrn)) { | |
5624 | if ((nbr = nrn->info)) { | |
5625 | if (nbr != oi->nbr_self) { | |
5626 | if (nbr->state != NSM_Down) | |
5627 | show_ip_ospf_neighbor_detail_sub( | |
5628 | vty, oi, nbr, | |
5629 | NULL, | |
5630 | json, use_json); | |
5631 | } | |
5632 | } | |
5633 | } | |
5634 | } | |
5635 | } | |
5636 | ||
5637 | if (use_json) { | |
5638 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5639 | json, JSON_C_TO_STRING_PRETTY)); | |
5640 | json_object_free(json); | |
5641 | } else | |
5642 | vty_out(vty, "\n"); | |
5643 | ||
5644 | return CMD_SUCCESS; | |
5645 | } | |
5646 | ||
5647 | DEFUN (show_ip_ospf_neighbor_int_detail, | |
5648 | show_ip_ospf_neighbor_int_detail_cmd, | |
5649 | "show ip ospf neighbor IFNAME detail [json]", | |
5650 | SHOW_STR | |
5651 | IP_STR | |
5652 | "OSPF information\n" | |
5653 | "Neighbor list\n" | |
5654 | "Interface name\n" | |
5655 | "detail of all neighbors\n" | |
5656 | JSON_STR) | |
5657 | { | |
5658 | struct ospf *ospf; | |
5659 | bool uj = use_json(argc, argv); | |
5660 | struct listnode *node = NULL; | |
5661 | int ret = CMD_SUCCESS; | |
5662 | bool ospf_output = false; | |
5663 | ||
5664 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5665 | if (!ospf->oi_running) | |
5666 | continue; | |
5667 | ospf_output = true; | |
5668 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, | |
5669 | argv, uj); | |
5670 | } | |
5671 | ||
5672 | if (!ospf_output) | |
5673 | vty_out(vty, "%% OSPF instance not found\n"); | |
5674 | ||
5675 | return ret; | |
5676 | } | |
5677 | ||
5678 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5679 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
5680 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", | |
5681 | SHOW_STR | |
5682 | IP_STR | |
5683 | "OSPF information\n" | |
5684 | "Instance ID\n" | |
5685 | "Neighbor list\n" | |
5686 | "Interface name\n" | |
5687 | "detail of all neighbors\n" | |
5688 | JSON_STR) | |
5689 | { | |
5690 | int idx_number = 3; | |
5691 | int idx_ifname = 5; | |
5692 | struct ospf *ospf; | |
5693 | unsigned short instance = 0; | |
5694 | bool uj = use_json(argc, argv); | |
5695 | ||
5696 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
5697 | ospf = ospf_lookup_instance(instance); | |
5698 | if (ospf == NULL) | |
5699 | return CMD_NOT_MY_INSTANCE; | |
5700 | ||
5701 | if (!ospf->oi_running) | |
5702 | return CMD_SUCCESS; | |
5703 | ||
5704 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, | |
5705 | argv, uj); | |
5706 | } | |
5707 | ||
5708 | /* Show functions */ | |
5709 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) | |
5710 | { | |
5711 | struct router_lsa *rl; | |
5712 | struct summary_lsa *sl; | |
5713 | struct as_external_lsa *asel; | |
5714 | struct prefix_ipv4 p; | |
5715 | ||
5716 | if (lsa != NULL) | |
5717 | /* If self option is set, check LSA self flag. */ | |
5718 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
5719 | /* LSA common part show. */ | |
5720 | vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id)); | |
5721 | vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", | |
5722 | inet_ntoa(lsa->data->adv_router), LS_AGE(lsa), | |
5723 | (unsigned long)ntohl(lsa->data->ls_seqnum), | |
5724 | ntohs(lsa->data->checksum)); | |
5725 | /* LSA specific part show. */ | |
5726 | switch (lsa->data->type) { | |
5727 | case OSPF_ROUTER_LSA: | |
5728 | rl = (struct router_lsa *)lsa->data; | |
5729 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5730 | break; | |
5731 | case OSPF_SUMMARY_LSA: | |
5732 | sl = (struct summary_lsa *)lsa->data; | |
5733 | ||
5734 | p.family = AF_INET; | |
5735 | p.prefix = sl->header.id; | |
5736 | p.prefixlen = ip_masklen(sl->mask); | |
5737 | apply_mask_ipv4(&p); | |
5738 | ||
5739 | vty_out(vty, " %s/%d", inet_ntoa(p.prefix), | |
5740 | p.prefixlen); | |
5741 | break; | |
5742 | case OSPF_AS_EXTERNAL_LSA: | |
5743 | case OSPF_AS_NSSA_LSA: | |
5744 | asel = (struct as_external_lsa *)lsa->data; | |
5745 | ||
5746 | p.family = AF_INET; | |
5747 | p.prefix = asel->header.id; | |
5748 | p.prefixlen = ip_masklen(asel->mask); | |
5749 | apply_mask_ipv4(&p); | |
5750 | ||
5751 | vty_out(vty, " %s %s/%d [0x%lx]", | |
5752 | IS_EXTERNAL_METRIC(asel->e[0].tos) | |
5753 | ? "E2" | |
5754 | : "E1", | |
5755 | inet_ntoa(p.prefix), p.prefixlen, | |
5756 | (unsigned long)ntohl( | |
5757 | asel->e[0].route_tag)); | |
5758 | break; | |
5759 | case OSPF_NETWORK_LSA: | |
5760 | case OSPF_ASBR_SUMMARY_LSA: | |
5761 | case OSPF_OPAQUE_LINK_LSA: | |
5762 | case OSPF_OPAQUE_AREA_LSA: | |
5763 | case OSPF_OPAQUE_AS_LSA: | |
5764 | default: | |
5765 | break; | |
5766 | } | |
5767 | vty_out(vty, "\n"); | |
5768 | } | |
5769 | ||
5770 | return 0; | |
5771 | } | |
5772 | ||
5773 | static const char *const show_database_desc[] = { | |
5774 | "unknown", | |
5775 | "Router Link States", | |
5776 | "Net Link States", | |
5777 | "Summary Link States", | |
5778 | "ASBR-Summary Link States", | |
5779 | "AS External Link States", | |
5780 | "Group Membership LSA", | |
5781 | "NSSA-external Link States", | |
5782 | "Type-8 LSA", | |
5783 | "Link-Local Opaque-LSA", | |
5784 | "Area-Local Opaque-LSA", | |
5785 | "AS-external Opaque-LSA", | |
5786 | }; | |
5787 | ||
5788 | static const char *const show_database_header[] = { | |
5789 | "", | |
5790 | "Link ID ADV Router Age Seq# CkSum Link count", | |
5791 | "Link ID ADV Router Age Seq# CkSum", | |
5792 | "Link ID ADV Router Age Seq# CkSum Route", | |
5793 | "Link ID ADV Router Age Seq# CkSum", | |
5794 | "Link ID ADV Router Age Seq# CkSum Route", | |
5795 | " --- header for Group Member ----", | |
5796 | "Link ID ADV Router Age Seq# CkSum Route", | |
5797 | " --- type-8 ---", | |
5798 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5799 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5800 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5801 | }; | |
5802 | ||
5803 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa) | |
5804 | { | |
5805 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
5806 | ||
5807 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
5808 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
5809 | ospf_options_dump(lsa->data->options)); | |
5810 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
5811 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" | |
5812 | : "")); | |
5813 | ||
5814 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
5815 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
5816 | ||
5817 | if (rlsa->flags) | |
5818 | vty_out(vty, " :%s%s%s%s", | |
5819 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "", | |
5820 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "", | |
5821 | IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint" | |
5822 | : "", | |
5823 | IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut" | |
5824 | : ""); | |
5825 | ||
5826 | vty_out(vty, "\n"); | |
5827 | } | |
5828 | vty_out(vty, " LS Type: %s\n", | |
5829 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
5830 | vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id), | |
5831 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL)); | |
5832 | vty_out(vty, " Advertising Router: %s\n", | |
5833 | inet_ntoa(lsa->data->adv_router)); | |
5834 | vty_out(vty, " LS Seq Number: %08lx\n", | |
5835 | (unsigned long)ntohl(lsa->data->ls_seqnum)); | |
5836 | vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum)); | |
5837 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
5838 | } | |
5839 | ||
5840 | static const char *const link_type_desc[] = { | |
5841 | "(null)", | |
5842 | "another Router (point-to-point)", | |
5843 | "a Transit Network", | |
5844 | "Stub Network", | |
5845 | "a Virtual Link", | |
5846 | }; | |
5847 | ||
5848 | static const char *const link_id_desc[] = { | |
5849 | "(null)", "Neighboring Router ID", "Designated Router address", | |
5850 | "Net", "Neighboring Router ID", | |
5851 | }; | |
5852 | ||
5853 | static const char *const link_data_desc[] = { | |
5854 | "(null)", "Router Interface address", "Router Interface address", | |
5855 | "Network Mask", "Router Interface address", | |
5856 | }; | |
5857 | ||
5858 | /* Show router-LSA each Link information. */ | |
5859 | static void show_ip_ospf_database_router_links(struct vty *vty, | |
5860 | struct router_lsa *rl) | |
5861 | { | |
5862 | int len, type; | |
5863 | unsigned int i; | |
5864 | ||
5865 | len = ntohs(rl->header.length) - 4; | |
5866 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
5867 | type = rl->link[i].type; | |
5868 | ||
5869 | vty_out(vty, " Link connected to: %s\n", | |
5870 | link_type_desc[type]); | |
5871 | vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type], | |
5872 | inet_ntoa(rl->link[i].link_id)); | |
5873 | vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type], | |
5874 | inet_ntoa(rl->link[i].link_data)); | |
5875 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
5876 | vty_out(vty, " TOS 0 Metric: %d\n", | |
5877 | ntohs(rl->link[i].metric)); | |
5878 | vty_out(vty, "\n"); | |
5879 | } | |
5880 | } | |
5881 | ||
5882 | /* Show router-LSA detail information. */ | |
5883 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) | |
5884 | { | |
5885 | if (lsa != NULL) { | |
5886 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
5887 | ||
5888 | show_ip_ospf_database_header(vty, lsa); | |
5889 | ||
5890 | vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links)); | |
5891 | ||
5892 | show_ip_ospf_database_router_links(vty, rl); | |
5893 | vty_out(vty, "\n"); | |
5894 | } | |
5895 | ||
5896 | return 0; | |
5897 | } | |
5898 | ||
5899 | /* Show network-LSA detail information. */ | |
5900 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) | |
5901 | { | |
5902 | int length, i; | |
5903 | ||
5904 | if (lsa != NULL) { | |
5905 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
5906 | ||
5907 | show_ip_ospf_database_header(vty, lsa); | |
5908 | ||
5909 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask)); | |
5910 | ||
5911 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; | |
5912 | ||
5913 | for (i = 0; length > 0; i++, length -= 4) | |
5914 | vty_out(vty, " Attached Router: %s\n", | |
5915 | inet_ntoa(nl->routers[i])); | |
5916 | ||
5917 | vty_out(vty, "\n"); | |
5918 | } | |
5919 | ||
5920 | return 0; | |
5921 | } | |
5922 | ||
5923 | /* Show summary-LSA detail information. */ | |
5924 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) | |
5925 | { | |
5926 | if (lsa != NULL) { | |
5927 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
5928 | ||
5929 | show_ip_ospf_database_header(vty, lsa); | |
5930 | ||
5931 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); | |
5932 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5933 | GET_METRIC(sl->metric)); | |
5934 | vty_out(vty, "\n"); | |
5935 | } | |
5936 | ||
5937 | return 0; | |
5938 | } | |
5939 | ||
5940 | /* Show summary-ASBR-LSA detail information. */ | |
5941 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) | |
5942 | { | |
5943 | if (lsa != NULL) { | |
5944 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
5945 | ||
5946 | show_ip_ospf_database_header(vty, lsa); | |
5947 | ||
5948 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); | |
5949 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5950 | GET_METRIC(sl->metric)); | |
5951 | vty_out(vty, "\n"); | |
5952 | } | |
5953 | ||
5954 | return 0; | |
5955 | } | |
5956 | ||
5957 | /* Show AS-external-LSA detail information. */ | |
5958 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) | |
5959 | { | |
5960 | if (lsa != NULL) { | |
5961 | struct as_external_lsa *al = | |
5962 | (struct as_external_lsa *)lsa->data; | |
5963 | ||
5964 | show_ip_ospf_database_header(vty, lsa); | |
5965 | ||
5966 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5967 | vty_out(vty, " Metric Type: %s\n", | |
5968 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5969 | ? "2 (Larger than any link state path)" | |
5970 | : "1"); | |
5971 | vty_out(vty, " TOS: 0\n"); | |
5972 | vty_out(vty, " Metric: %d\n", | |
5973 | GET_METRIC(al->e[0].metric)); | |
5974 | vty_out(vty, " Forward Address: %s\n", | |
5975 | inet_ntoa(al->e[0].fwd_addr)); | |
5976 | ||
5977 | vty_out(vty, | |
5978 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5979 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5980 | } | |
5981 | ||
5982 | return 0; | |
5983 | } | |
5984 | #if 0 | |
5985 | static int | |
5986 | show_as_external_lsa_stdvty (struct ospf_lsa *lsa) | |
5987 | { | |
5988 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; | |
5989 | ||
5990 | /* show_ip_ospf_database_header (vty, lsa); */ | |
5991 | ||
5992 | zlog_debug( " Network Mask: /%d%s", | |
5993 | ip_masklen (al->mask), "\n"); | |
5994 | zlog_debug( " Metric Type: %s%s", | |
5995 | IS_EXTERNAL_METRIC (al->e[0].tos) ? | |
5996 | "2 (Larger than any link state path)" : "1", "\n"); | |
5997 | zlog_debug( " TOS: 0%s", "\n"); | |
5998 | zlog_debug( " Metric: %d%s", | |
5999 | GET_METRIC (al->e[0].metric), "\n"); | |
6000 | zlog_debug( " Forward Address: %s%s", | |
6001 | inet_ntoa (al->e[0].fwd_addr), "\n"); | |
6002 | ||
6003 | zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s", | |
6004 | (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n"); | |
6005 | ||
6006 | return 0; | |
6007 | } | |
6008 | #endif | |
6009 | /* Show AS-NSSA-LSA detail information. */ | |
6010 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) | |
6011 | { | |
6012 | if (lsa != NULL) { | |
6013 | struct as_external_lsa *al = | |
6014 | (struct as_external_lsa *)lsa->data; | |
6015 | ||
6016 | show_ip_ospf_database_header(vty, lsa); | |
6017 | ||
6018 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
6019 | vty_out(vty, " Metric Type: %s\n", | |
6020 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6021 | ? "2 (Larger than any link state path)" | |
6022 | : "1"); | |
6023 | vty_out(vty, " TOS: 0\n"); | |
6024 | vty_out(vty, " Metric: %d\n", | |
6025 | GET_METRIC(al->e[0].metric)); | |
6026 | vty_out(vty, " NSSA: Forward Address: %s\n", | |
6027 | inet_ntoa(al->e[0].fwd_addr)); | |
6028 | ||
6029 | vty_out(vty, | |
6030 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6031 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6032 | } | |
6033 | ||
6034 | return 0; | |
6035 | } | |
6036 | ||
6037 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa) | |
6038 | { | |
6039 | return 0; | |
6040 | } | |
6041 | ||
6042 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) | |
6043 | { | |
6044 | if (lsa != NULL) { | |
6045 | show_ip_ospf_database_header(vty, lsa); | |
6046 | show_opaque_info_detail(vty, lsa); | |
6047 | ||
6048 | vty_out(vty, "\n"); | |
6049 | } | |
6050 | return 0; | |
6051 | } | |
6052 | ||
6053 | int (*const show_function[])(struct vty *, struct ospf_lsa *) = { | |
6054 | NULL, | |
6055 | show_router_lsa_detail, | |
6056 | show_network_lsa_detail, | |
6057 | show_summary_lsa_detail, | |
6058 | show_summary_asbr_lsa_detail, | |
6059 | show_as_external_lsa_detail, | |
6060 | show_func_dummy, | |
6061 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6062 | NULL, /* type-8 */ | |
6063 | show_opaque_lsa_detail, | |
6064 | show_opaque_lsa_detail, | |
6065 | show_opaque_lsa_detail, | |
6066 | }; | |
6067 | ||
6068 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6069 | struct in_addr *id, struct in_addr *adv_router) | |
6070 | { | |
6071 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6072 | lp->family = 0; | |
6073 | if (id == NULL) | |
6074 | lp->prefixlen = 0; | |
6075 | else if (adv_router == NULL) { | |
6076 | lp->prefixlen = 32; | |
6077 | lp->id = *id; | |
6078 | } else { | |
6079 | lp->prefixlen = 64; | |
6080 | lp->id = *id; | |
6081 | lp->adv_router = *adv_router; | |
6082 | } | |
6083 | } | |
6084 | ||
6085 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, | |
6086 | struct in_addr *id, struct in_addr *adv_router) | |
6087 | { | |
6088 | struct prefix_ls lp; | |
6089 | struct route_node *rn, *start; | |
6090 | struct ospf_lsa *lsa; | |
6091 | ||
6092 | show_lsa_prefix_set(vty, &lp, id, adv_router); | |
6093 | start = route_node_get(rt, (struct prefix *)&lp); | |
6094 | if (start) { | |
6095 | route_lock_node(start); | |
6096 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6097 | if ((lsa = rn->info)) { | |
6098 | if (show_function[lsa->data->type] != NULL) | |
6099 | show_function[lsa->data->type](vty, | |
6100 | lsa); | |
6101 | } | |
6102 | route_unlock_node(start); | |
6103 | } | |
6104 | } | |
6105 | ||
6106 | /* Show detail LSA information | |
6107 | -- if id is NULL then show all LSAs. */ | |
6108 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, | |
6109 | struct in_addr *id, struct in_addr *adv_router) | |
6110 | { | |
6111 | struct listnode *node; | |
6112 | struct ospf_area *area; | |
6113 | ||
6114 | switch (type) { | |
6115 | case OSPF_AS_EXTERNAL_LSA: | |
6116 | case OSPF_OPAQUE_AS_LSA: | |
6117 | vty_out(vty, " %s \n\n", | |
6118 | show_database_desc[type]); | |
6119 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router); | |
6120 | break; | |
6121 | default: | |
6122 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6123 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6124 | show_database_desc[type], | |
6125 | ospf_area_desc_string(area)); | |
6126 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, | |
6127 | adv_router); | |
6128 | } | |
6129 | break; | |
6130 | } | |
6131 | } | |
6132 | ||
6133 | static void show_lsa_detail_adv_router_proc(struct vty *vty, | |
6134 | struct route_table *rt, | |
6135 | struct in_addr *adv_router) | |
6136 | { | |
6137 | struct route_node *rn; | |
6138 | struct ospf_lsa *lsa; | |
6139 | ||
6140 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
6141 | if ((lsa = rn->info)) | |
6142 | if (IPV4_ADDR_SAME(adv_router, | |
6143 | &lsa->data->adv_router)) { | |
6144 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6145 | continue; | |
6146 | if (show_function[lsa->data->type] != NULL) | |
6147 | show_function[lsa->data->type](vty, | |
6148 | lsa); | |
6149 | } | |
6150 | } | |
6151 | ||
6152 | /* Show detail LSA information. */ | |
6153 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, | |
6154 | int type, struct in_addr *adv_router) | |
6155 | { | |
6156 | struct listnode *node; | |
6157 | struct ospf_area *area; | |
6158 | ||
6159 | switch (type) { | |
6160 | case OSPF_AS_EXTERNAL_LSA: | |
6161 | case OSPF_OPAQUE_AS_LSA: | |
6162 | vty_out(vty, " %s \n\n", | |
6163 | show_database_desc[type]); | |
6164 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), | |
6165 | adv_router); | |
6166 | break; | |
6167 | default: | |
6168 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6169 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6170 | show_database_desc[type], | |
6171 | ospf_area_desc_string(area)); | |
6172 | show_lsa_detail_adv_router_proc( | |
6173 | vty, AREA_LSDB(area, type), adv_router); | |
6174 | } | |
6175 | break; | |
6176 | } | |
6177 | } | |
6178 | ||
6179 | static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, | |
6180 | int self) | |
6181 | { | |
6182 | struct ospf_lsa *lsa; | |
6183 | struct route_node *rn; | |
6184 | struct ospf_area *area; | |
6185 | struct listnode *node; | |
6186 | int type; | |
6187 | ||
6188 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6189 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6190 | switch (type) { | |
6191 | case OSPF_AS_EXTERNAL_LSA: | |
6192 | case OSPF_OPAQUE_AS_LSA: | |
6193 | continue; | |
6194 | default: | |
6195 | break; | |
6196 | } | |
6197 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6198 | || (!self | |
6199 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
6200 | vty_out(vty, " %s (Area %s)\n\n", | |
6201 | show_database_desc[type], | |
6202 | ospf_area_desc_string(area)); | |
6203 | vty_out(vty, "%s\n", | |
6204 | show_database_header[type]); | |
6205 | ||
6206 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) | |
6207 | show_lsa_summary(vty, lsa, self); | |
6208 | ||
6209 | vty_out(vty, "\n"); | |
6210 | } | |
6211 | } | |
6212 | } | |
6213 | ||
6214 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6215 | switch (type) { | |
6216 | case OSPF_AS_EXTERNAL_LSA: | |
6217 | case OSPF_OPAQUE_AS_LSA: | |
6218 | break; | |
6219 | default: | |
6220 | continue; | |
6221 | } | |
6222 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6223 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
6224 | vty_out(vty, " %s\n\n", | |
6225 | show_database_desc[type]); | |
6226 | vty_out(vty, "%s\n", show_database_header[type]); | |
6227 | ||
6228 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) | |
6229 | show_lsa_summary(vty, lsa, self); | |
6230 | ||
6231 | vty_out(vty, "\n"); | |
6232 | } | |
6233 | } | |
6234 | ||
6235 | vty_out(vty, "\n"); | |
6236 | } | |
6237 | ||
6238 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) | |
6239 | { | |
6240 | struct route_node *rn; | |
6241 | ||
6242 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6243 | ||
6244 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6245 | struct ospf_lsa *lsa; | |
6246 | ||
6247 | if ((lsa = rn->info) != NULL) { | |
6248 | vty_out(vty, "Link type: %d\n", lsa->data->type); | |
6249 | vty_out(vty, "Link State ID: %s\n", | |
6250 | inet_ntoa(lsa->data->id)); | |
6251 | vty_out(vty, "Advertising Router: %s\n", | |
6252 | inet_ntoa(lsa->data->adv_router)); | |
6253 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6254 | vty_out(vty, "\n"); | |
6255 | } | |
6256 | } | |
6257 | } | |
6258 | ||
6259 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" | |
6260 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
6261 | ||
6262 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" | |
6263 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6264 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6265 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
6266 | ||
6267 | #define OSPF_LSA_TYPES_DESC \ | |
6268 | "ASBR summary link states\n" \ | |
6269 | "External link states\n" \ | |
6270 | "Network link states\n" \ | |
6271 | "Router link states\n" \ | |
6272 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6273 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6274 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6275 | ||
6276 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6277 | int arg_base, int argc, | |
6278 | struct cmd_token **argv, | |
6279 | uint8_t use_vrf) | |
6280 | { | |
6281 | int idx_type = 4; | |
6282 | int type, ret; | |
6283 | struct in_addr id, adv_router; | |
6284 | ||
6285 | if (ospf->instance) | |
6286 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6287 | ||
6288 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); | |
6289 | ||
6290 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", | |
6291 | inet_ntoa(ospf->router_id)); | |
6292 | ||
6293 | /* Show all LSA. */ | |
6294 | if (argc == arg_base + 4) { | |
6295 | show_ip_ospf_database_summary(vty, ospf, 0); | |
6296 | return CMD_SUCCESS; | |
6297 | } | |
6298 | ||
6299 | /* Set database type to show. */ | |
6300 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6301 | type = OSPF_ROUTER_LSA; | |
6302 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6303 | type = OSPF_NETWORK_LSA; | |
6304 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6305 | type = OSPF_AS_NSSA_LSA; | |
6306 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
6307 | type = OSPF_SUMMARY_LSA; | |
6308 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6309 | type = OSPF_ASBR_SUMMARY_LSA; | |
6310 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6311 | type = OSPF_AS_EXTERNAL_LSA; | |
6312 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
6313 | show_ip_ospf_database_summary(vty, ospf, 1); | |
6314 | return CMD_SUCCESS; | |
6315 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
6316 | show_ip_ospf_database_maxage(vty, ospf); | |
6317 | return CMD_SUCCESS; | |
6318 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6319 | type = OSPF_OPAQUE_LINK_LSA; | |
6320 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6321 | type = OSPF_OPAQUE_AREA_LSA; | |
6322 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6323 | type = OSPF_OPAQUE_AS_LSA; | |
6324 | else | |
6325 | return CMD_WARNING; | |
6326 | ||
6327 | /* `show ip ospf database LSA'. */ | |
6328 | if (argc == arg_base + 5) | |
6329 | show_lsa_detail(vty, ospf, type, NULL, NULL); | |
6330 | else if (argc >= arg_base + 6) { | |
6331 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
6332 | if (!ret) | |
6333 | return CMD_WARNING; | |
6334 | ||
6335 | /* `show ip ospf database LSA ID'. */ | |
6336 | if (argc == arg_base + 6) | |
6337 | show_lsa_detail(vty, ospf, type, &id, NULL); | |
6338 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ | |
6339 | else if (argc == arg_base + 7) { | |
6340 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) | |
6341 | adv_router = ospf->router_id; | |
6342 | else { | |
6343 | ret = inet_aton(argv[arg_base + 7]->arg, | |
6344 | &adv_router); | |
6345 | if (!ret) | |
6346 | return CMD_WARNING; | |
6347 | } | |
6348 | show_lsa_detail(vty, ospf, type, &id, &adv_router); | |
6349 | } | |
6350 | } | |
6351 | ||
6352 | return CMD_SUCCESS; | |
6353 | } | |
6354 | ||
6355 | DEFUN (show_ip_ospf_database_max, | |
6356 | show_ip_ospf_database_max_cmd, | |
6357 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>", | |
6358 | SHOW_STR | |
6359 | IP_STR | |
6360 | "OSPF information\n" | |
6361 | VRF_CMD_HELP_STR | |
6362 | "All VRFs\n" | |
6363 | "Database summary\n" | |
6364 | "LSAs in MaxAge list\n" | |
6365 | "Self-originated link states\n") | |
6366 | { | |
6367 | struct ospf *ospf = NULL; | |
6368 | struct listnode *node = NULL; | |
6369 | char *vrf_name = NULL; | |
6370 | bool all_vrf = false; | |
6371 | int ret = CMD_SUCCESS; | |
6372 | int inst = 0; | |
6373 | int idx_vrf = 0; | |
6374 | uint8_t use_vrf = 0; | |
6375 | ||
6376 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
6377 | ||
6378 | if (vrf_name) { | |
6379 | bool ospf_output = false; | |
6380 | ||
6381 | use_vrf = 1; | |
6382 | ||
6383 | if (all_vrf) { | |
6384 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6385 | if (!ospf->oi_running) | |
6386 | continue; | |
6387 | ospf_output = true; | |
6388 | ret = show_ip_ospf_database_common( | |
6389 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
6390 | use_vrf); | |
6391 | } | |
6392 | ||
6393 | if (!ospf_output) | |
6394 | vty_out(vty, "%% OSPF instance not found\n"); | |
6395 | } else { | |
6396 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
6397 | if (ospf == NULL || !ospf->oi_running) { | |
6398 | vty_out(vty, "%% OSPF instance not found\n"); | |
6399 | return CMD_SUCCESS; | |
6400 | } | |
6401 | ret = (show_ip_ospf_database_common( | |
6402 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
6403 | use_vrf)); | |
6404 | } | |
6405 | } else { | |
6406 | /* Display default ospf (instance 0) info */ | |
6407 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
6408 | if (ospf == NULL || !ospf->oi_running) { | |
6409 | vty_out(vty, "%% OSPF instance not found\n"); | |
6410 | return CMD_SUCCESS; | |
6411 | } | |
6412 | ||
6413 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, | |
6414 | use_vrf); | |
6415 | } | |
6416 | ||
6417 | return ret; | |
6418 | } | |
6419 | ||
6420 | DEFUN (show_ip_ospf_instance_database, | |
6421 | show_ip_ospf_instance_database_cmd, | |
6422 | "show ip ospf [{(1-65535)|vrf NAME}] database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]]", | |
6423 | SHOW_STR | |
6424 | IP_STR | |
6425 | "OSPF information\n" | |
6426 | "Instance ID\n" | |
6427 | VRF_CMD_HELP_STR | |
6428 | "Database summary\n" | |
6429 | OSPF_LSA_TYPES_DESC | |
6430 | "Link State ID (as an IP address)\n" | |
6431 | "Self-originated link states\n" | |
6432 | "Advertising Router link states\n" | |
6433 | "Advertising Router (as an IP address)\n") | |
6434 | { | |
6435 | struct ospf *ospf; | |
6436 | unsigned short instance = 0; | |
6437 | struct listnode *node = NULL; | |
6438 | char *vrf_name = NULL; | |
6439 | bool all_vrf = false; | |
6440 | int ret = CMD_SUCCESS; | |
6441 | int inst = 0; | |
6442 | int idx = 0; | |
6443 | uint8_t use_vrf = 0; | |
6444 | ||
6445 | if (argv_find(argv, argc, "(1-65535)", &idx)) { | |
6446 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6447 | ospf = ospf_lookup_instance(instance); | |
6448 | if (ospf == NULL) | |
6449 | return CMD_NOT_MY_INSTANCE; | |
6450 | if (!ospf->oi_running) | |
6451 | return CMD_SUCCESS; | |
6452 | ||
6453 | return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, | |
6454 | argc, argv, use_vrf)); | |
6455 | } else if (argv_find(argv, argc, "vrf", &idx)) { | |
6456 | vrf_name = argv[++idx]->arg; | |
6457 | all_vrf = strmatch(vrf_name, "all"); | |
6458 | } | |
6459 | ||
6460 | if (vrf_name) { | |
6461 | use_vrf = 1; | |
6462 | if (all_vrf) { | |
6463 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6464 | if (!ospf->oi_running) | |
6465 | continue; | |
6466 | ret = (show_ip_ospf_database_common( | |
6467 | vty, ospf, idx ? 2 : 0, argc, argv, | |
6468 | use_vrf)); | |
6469 | } | |
6470 | } else { | |
6471 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
6472 | if ((ospf == NULL) || !ospf->oi_running) { | |
6473 | vty_out(vty, "%% OSPF instance not found\n"); | |
6474 | return CMD_SUCCESS; | |
6475 | } | |
6476 | ||
6477 | ret = (show_ip_ospf_database_common( | |
6478 | vty, ospf, idx ? 2 : 0, argc, argv, use_vrf)); | |
6479 | } | |
6480 | } else { | |
6481 | /* Display default ospf (instance 0) info */ | |
6482 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
6483 | if (ospf == NULL || !ospf->oi_running) { | |
6484 | vty_out(vty, "%% OSPF instance not found\n"); | |
6485 | return CMD_SUCCESS; | |
6486 | } | |
6487 | ||
6488 | ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv, | |
6489 | use_vrf)); | |
6490 | } | |
6491 | ||
6492 | return ret; | |
6493 | } | |
6494 | ||
6495 | DEFUN (show_ip_ospf_instance_database_max, | |
6496 | show_ip_ospf_instance_database_max_cmd, | |
6497 | "show ip ospf (1-65535) database <max-age|self-originate>", | |
6498 | SHOW_STR | |
6499 | IP_STR | |
6500 | "OSPF information\n" | |
6501 | "Instance ID\n" | |
6502 | "Database summary\n" | |
6503 | "LSAs in MaxAge list\n" | |
6504 | "Self-originated link states\n") | |
6505 | { | |
6506 | int idx_number = 3; | |
6507 | struct ospf *ospf; | |
6508 | unsigned short instance = 0; | |
6509 | ||
6510 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
6511 | ||
6512 | ospf = ospf_lookup_instance(instance); | |
6513 | if (ospf == NULL) | |
6514 | return CMD_NOT_MY_INSTANCE; | |
6515 | ||
6516 | if (!ospf->oi_running) { | |
6517 | vty_out(vty, "%% OSPF instance not found\n"); | |
6518 | return CMD_SUCCESS; | |
6519 | } | |
6520 | ||
6521 | return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0); | |
6522 | } | |
6523 | ||
6524 | ||
6525 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
6526 | struct ospf *ospf, | |
6527 | int arg_base, int argc, | |
6528 | struct cmd_token **argv, | |
6529 | uint8_t use_vrf) | |
6530 | { | |
6531 | int idx_type = 4; | |
6532 | int type, ret; | |
6533 | struct in_addr adv_router; | |
6534 | ||
6535 | if (ospf->instance) | |
6536 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6537 | ||
6538 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); | |
6539 | ||
6540 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", | |
6541 | inet_ntoa(ospf->router_id)); | |
6542 | ||
6543 | /* Set database type to show. */ | |
6544 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6545 | type = OSPF_ROUTER_LSA; | |
6546 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6547 | type = OSPF_NETWORK_LSA; | |
6548 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6549 | type = OSPF_AS_NSSA_LSA; | |
6550 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
6551 | type = OSPF_SUMMARY_LSA; | |
6552 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6553 | type = OSPF_ASBR_SUMMARY_LSA; | |
6554 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6555 | type = OSPF_AS_EXTERNAL_LSA; | |
6556 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6557 | type = OSPF_OPAQUE_LINK_LSA; | |
6558 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6559 | type = OSPF_OPAQUE_AREA_LSA; | |
6560 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6561 | type = OSPF_OPAQUE_AS_LSA; | |
6562 | else | |
6563 | return CMD_WARNING; | |
6564 | ||
6565 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ | |
6566 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
6567 | adv_router = ospf->router_id; | |
6568 | else { | |
6569 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
6570 | if (!ret) | |
6571 | return CMD_WARNING; | |
6572 | } | |
6573 | ||
6574 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router); | |
6575 | ||
6576 | return CMD_SUCCESS; | |
6577 | } | |
6578 | ||
6579 | DEFUN (show_ip_ospf_instance_database_type_adv_router, | |
6580 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
6581 | "show ip ospf [{(1-65535)|vrf NAME}] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate>", | |
6582 | SHOW_STR | |
6583 | IP_STR | |
6584 | "OSPF information\n" | |
6585 | "Instance ID\n" | |
6586 | VRF_CMD_HELP_STR | |
6587 | "Database summary\n" | |
6588 | OSPF_LSA_TYPES_DESC | |
6589 | "Advertising Router link states\n" | |
6590 | "Advertising Router (as an IP address)\n" | |
6591 | "Self-originated link states\n") | |
6592 | { | |
6593 | struct ospf *ospf = NULL; | |
6594 | unsigned short instance = 0; | |
6595 | struct listnode *node = NULL; | |
6596 | char *vrf_name = NULL; | |
6597 | bool all_vrf = false; | |
6598 | int ret = CMD_SUCCESS; | |
6599 | int inst = 0; | |
6600 | int idx = 0, idx_vrf = 0; | |
6601 | uint8_t use_vrf = 0; | |
6602 | ||
6603 | if (argv_find(argv, argc, "(1-65535)", &idx)) { | |
6604 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6605 | ospf = ospf_lookup_instance(instance); | |
6606 | if (ospf == NULL) | |
6607 | return CMD_NOT_MY_INSTANCE; | |
6608 | if (!ospf->oi_running) { | |
6609 | vty_out(vty, "%% OSPF instance not found\n"); | |
6610 | return CMD_SUCCESS; | |
6611 | } | |
6612 | ||
6613 | return (show_ip_ospf_database_type_adv_router_common( | |
6614 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf)); | |
6615 | } | |
6616 | ||
6617 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
6618 | ||
6619 | if (vrf_name) { | |
6620 | bool ospf_output = false; | |
6621 | ||
6622 | use_vrf = 1; | |
6623 | ||
6624 | if (all_vrf) { | |
6625 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6626 | if (!ospf->oi_running) | |
6627 | continue; | |
6628 | ospf_output = true; | |
6629 | ret = show_ip_ospf_database_type_adv_router_common( | |
6630 | vty, ospf, idx ? 1 : 0, argc, argv, | |
6631 | use_vrf); | |
6632 | } | |
6633 | if (!ospf_output) | |
6634 | vty_out(vty, "%% OSPF instance not found\n"); | |
6635 | } else { | |
6636 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
6637 | if ((ospf == NULL) || !ospf->oi_running) { | |
6638 | vty_out(vty, "%% OSPF instance not found\n"); | |
6639 | return CMD_SUCCESS; | |
6640 | } | |
6641 | ||
6642 | ret = show_ip_ospf_database_type_adv_router_common( | |
6643 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf); | |
6644 | } | |
6645 | } else { | |
6646 | /* Display default ospf (instance 0) info */ | |
6647 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
6648 | if (ospf == NULL || !ospf->oi_running) { | |
6649 | vty_out(vty, "%% OSPF instance not found\n"); | |
6650 | return CMD_SUCCESS; | |
6651 | } | |
6652 | ||
6653 | ret = show_ip_ospf_database_type_adv_router_common( | |
6654 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf); | |
6655 | } | |
6656 | return ret; | |
6657 | /*return (show_ip_ospf_database_type_adv_router_common( | |
6658 | vty, ospf, idx ? 1 : 0, argc, argv));*/ | |
6659 | } | |
6660 | ||
6661 | DEFUN (ip_ospf_authentication_args, | |
6662 | ip_ospf_authentication_args_addr_cmd, | |
6663 | "ip ospf authentication <null|message-digest> [A.B.C.D]", | |
6664 | "IP Information\n" | |
6665 | "OSPF interface commands\n" | |
6666 | "Enable authentication on this interface\n" | |
6667 | "Use null authentication\n" | |
6668 | "Use message-digest authentication\n" | |
6669 | "Address of interface\n") | |
6670 | { | |
6671 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6672 | int idx_encryption = 3; | |
6673 | int idx_ipv4 = 4; | |
6674 | struct in_addr addr; | |
6675 | int ret; | |
6676 | struct ospf_if_params *params; | |
6677 | ||
6678 | params = IF_DEF_PARAMS(ifp); | |
6679 | ||
6680 | if (argc == 5) { | |
6681 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6682 | if (!ret) { | |
6683 | vty_out(vty, | |
6684 | "Please specify interface address by A.B.C.D\n"); | |
6685 | return CMD_WARNING_CONFIG_FAILED; | |
6686 | } | |
6687 | ||
6688 | params = ospf_get_if_params(ifp, addr); | |
6689 | ospf_if_update_params(ifp, addr); | |
6690 | } | |
6691 | ||
6692 | /* Handle null authentication */ | |
6693 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6694 | SET_IF_PARAM(params, auth_type); | |
6695 | params->auth_type = OSPF_AUTH_NULL; | |
6696 | return CMD_SUCCESS; | |
6697 | } | |
6698 | ||
6699 | /* Handle message-digest authentication */ | |
6700 | if (argv[idx_encryption]->arg[0] == 'm') { | |
6701 | SET_IF_PARAM(params, auth_type); | |
6702 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6703 | return CMD_SUCCESS; | |
6704 | } | |
6705 | ||
6706 | vty_out(vty, "You shouldn't get here!\n"); | |
6707 | return CMD_WARNING_CONFIG_FAILED; | |
6708 | } | |
6709 | ||
6710 | DEFUN (ip_ospf_authentication, | |
6711 | ip_ospf_authentication_addr_cmd, | |
6712 | "ip ospf authentication [A.B.C.D]", | |
6713 | "IP Information\n" | |
6714 | "OSPF interface commands\n" | |
6715 | "Enable authentication on this interface\n" | |
6716 | "Address of interface\n") | |
6717 | { | |
6718 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6719 | int idx_ipv4 = 3; | |
6720 | struct in_addr addr; | |
6721 | int ret; | |
6722 | struct ospf_if_params *params; | |
6723 | ||
6724 | params = IF_DEF_PARAMS(ifp); | |
6725 | ||
6726 | if (argc == 4) { | |
6727 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6728 | if (!ret) { | |
6729 | vty_out(vty, | |
6730 | "Please specify interface address by A.B.C.D\n"); | |
6731 | return CMD_WARNING_CONFIG_FAILED; | |
6732 | } | |
6733 | ||
6734 | params = ospf_get_if_params(ifp, addr); | |
6735 | ospf_if_update_params(ifp, addr); | |
6736 | } | |
6737 | ||
6738 | SET_IF_PARAM(params, auth_type); | |
6739 | params->auth_type = OSPF_AUTH_SIMPLE; | |
6740 | ||
6741 | return CMD_SUCCESS; | |
6742 | } | |
6743 | ||
6744 | DEFUN (no_ip_ospf_authentication_args, | |
6745 | no_ip_ospf_authentication_args_addr_cmd, | |
6746 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", | |
6747 | NO_STR | |
6748 | "IP Information\n" | |
6749 | "OSPF interface commands\n" | |
6750 | "Enable authentication on this interface\n" | |
6751 | "Use null authentication\n" | |
6752 | "Use message-digest authentication\n" | |
6753 | "Address of interface\n") | |
6754 | { | |
6755 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6756 | int idx_encryption = 4; | |
6757 | int idx_ipv4 = 5; | |
6758 | struct in_addr addr; | |
6759 | int ret; | |
6760 | struct ospf_if_params *params; | |
6761 | struct route_node *rn; | |
6762 | int auth_type; | |
6763 | ||
6764 | params = IF_DEF_PARAMS(ifp); | |
6765 | ||
6766 | if (argc == 6) { | |
6767 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6768 | if (!ret) { | |
6769 | vty_out(vty, | |
6770 | "Please specify interface address by A.B.C.D\n"); | |
6771 | return CMD_WARNING_CONFIG_FAILED; | |
6772 | } | |
6773 | ||
6774 | params = ospf_lookup_if_params(ifp, addr); | |
6775 | if (params == NULL) { | |
6776 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6777 | return CMD_WARNING_CONFIG_FAILED; | |
6778 | } | |
6779 | params->auth_type = OSPF_AUTH_NOTSET; | |
6780 | UNSET_IF_PARAM(params, auth_type); | |
6781 | if (params != IF_DEF_PARAMS(ifp)) { | |
6782 | ospf_free_if_params(ifp, addr); | |
6783 | ospf_if_update_params(ifp, addr); | |
6784 | } | |
6785 | } else { | |
6786 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6787 | auth_type = OSPF_AUTH_NULL; | |
6788 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
6789 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6790 | } else { | |
6791 | vty_out(vty, "Unexpected input encountered\n"); | |
6792 | return CMD_WARNING_CONFIG_FAILED; | |
6793 | } | |
6794 | /* | |
6795 | * Here we have a case where the user has entered | |
6796 | * 'no ip ospf authentication (null | message_digest )' | |
6797 | * we need to find if we have any ip addresses underneath it | |
6798 | * that | |
6799 | * correspond to the associated type. | |
6800 | */ | |
6801 | if (params->auth_type == auth_type) { | |
6802 | params->auth_type = OSPF_AUTH_NOTSET; | |
6803 | UNSET_IF_PARAM(params, auth_type); | |
6804 | } | |
6805 | ||
6806 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
6807 | rn = route_next(rn)) { | |
6808 | if ((params = rn->info)) { | |
6809 | if (params->auth_type == auth_type) { | |
6810 | params->auth_type = OSPF_AUTH_NOTSET; | |
6811 | UNSET_IF_PARAM(params, auth_type); | |
6812 | if (params != IF_DEF_PARAMS(ifp)) { | |
6813 | ospf_free_if_params( | |
6814 | ifp, rn->p.u.prefix4); | |
6815 | ospf_if_update_params( | |
6816 | ifp, rn->p.u.prefix4); | |
6817 | } | |
6818 | } | |
6819 | } | |
6820 | } | |
6821 | } | |
6822 | ||
6823 | return CMD_SUCCESS; | |
6824 | } | |
6825 | ||
6826 | DEFUN (no_ip_ospf_authentication, | |
6827 | no_ip_ospf_authentication_addr_cmd, | |
6828 | "no ip ospf authentication [A.B.C.D]", | |
6829 | NO_STR | |
6830 | "IP Information\n" | |
6831 | "OSPF interface commands\n" | |
6832 | "Enable authentication on this interface\n" | |
6833 | "Address of interface\n") | |
6834 | { | |
6835 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6836 | int idx_ipv4 = 4; | |
6837 | struct in_addr addr; | |
6838 | int ret; | |
6839 | struct ospf_if_params *params; | |
6840 | struct route_node *rn; | |
6841 | ||
6842 | params = IF_DEF_PARAMS(ifp); | |
6843 | ||
6844 | if (argc == 5) { | |
6845 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6846 | if (!ret) { | |
6847 | vty_out(vty, | |
6848 | "Please specify interface address by A.B.C.D\n"); | |
6849 | return CMD_WARNING_CONFIG_FAILED; | |
6850 | } | |
6851 | ||
6852 | params = ospf_lookup_if_params(ifp, addr); | |
6853 | if (params == NULL) { | |
6854 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6855 | return CMD_WARNING_CONFIG_FAILED; | |
6856 | } | |
6857 | ||
6858 | params->auth_type = OSPF_AUTH_NOTSET; | |
6859 | UNSET_IF_PARAM(params, auth_type); | |
6860 | if (params != IF_DEF_PARAMS(ifp)) { | |
6861 | ospf_free_if_params(ifp, addr); | |
6862 | ospf_if_update_params(ifp, addr); | |
6863 | } | |
6864 | } else { | |
6865 | /* | |
6866 | * When a user enters 'no ip ospf authentication' | |
6867 | * We should remove all authentication types from | |
6868 | * the interface. | |
6869 | */ | |
6870 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6871 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
6872 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
6873 | params->auth_type = OSPF_AUTH_NOTSET; | |
6874 | UNSET_IF_PARAM(params, auth_type); | |
6875 | } | |
6876 | ||
6877 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
6878 | rn = route_next(rn)) { | |
6879 | if ((params = rn->info)) { | |
6880 | ||
6881 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6882 | || (params->auth_type | |
6883 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
6884 | || (params->auth_type | |
6885 | == OSPF_AUTH_SIMPLE)) { | |
6886 | params->auth_type = OSPF_AUTH_NOTSET; | |
6887 | UNSET_IF_PARAM(params, auth_type); | |
6888 | if (params != IF_DEF_PARAMS(ifp)) { | |
6889 | ospf_free_if_params( | |
6890 | ifp, rn->p.u.prefix4); | |
6891 | ospf_if_update_params( | |
6892 | ifp, rn->p.u.prefix4); | |
6893 | } | |
6894 | } | |
6895 | } | |
6896 | } | |
6897 | } | |
6898 | ||
6899 | return CMD_SUCCESS; | |
6900 | } | |
6901 | ||
6902 | ||
6903 | DEFUN (ip_ospf_authentication_key, | |
6904 | ip_ospf_authentication_key_addr_cmd, | |
6905 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", | |
6906 | "IP Information\n" | |
6907 | "OSPF interface commands\n" | |
6908 | "Authentication password (key)\n" | |
6909 | "The OSPF password (key)\n" | |
6910 | "Address of interface\n") | |
6911 | { | |
6912 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6913 | int idx = 0; | |
6914 | struct in_addr addr; | |
6915 | struct ospf_if_params *params; | |
6916 | ||
6917 | params = IF_DEF_PARAMS(ifp); | |
6918 | ||
6919 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6920 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6921 | vty_out(vty, | |
6922 | "Please specify interface address by A.B.C.D\n"); | |
6923 | return CMD_WARNING_CONFIG_FAILED; | |
6924 | } | |
6925 | ||
6926 | params = ospf_get_if_params(ifp, addr); | |
6927 | ospf_if_update_params(ifp, addr); | |
6928 | } | |
6929 | ||
6930 | strlcpy((char *)params->auth_simple, argv[3]->arg, | |
6931 | sizeof(params->auth_simple)); | |
6932 | SET_IF_PARAM(params, auth_simple); | |
6933 | ||
6934 | return CMD_SUCCESS; | |
6935 | } | |
6936 | ||
6937 | DEFUN_HIDDEN (ospf_authentication_key, | |
6938 | ospf_authentication_key_cmd, | |
6939 | "ospf authentication-key AUTH_KEY [A.B.C.D]", | |
6940 | "OSPF interface commands\n" | |
6941 | VLINK_HELPSTR_AUTH_SIMPLE | |
6942 | "Address of interface\n") | |
6943 | { | |
6944 | return ip_ospf_authentication_key(self, vty, argc, argv); | |
6945 | } | |
6946 | ||
6947 | DEFUN (no_ip_ospf_authentication_key, | |
6948 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
6949 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6950 | NO_STR | |
6951 | "IP Information\n" | |
6952 | "OSPF interface commands\n" | |
6953 | VLINK_HELPSTR_AUTH_SIMPLE | |
6954 | "Address of interface\n") | |
6955 | { | |
6956 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6957 | int idx = 0; | |
6958 | struct in_addr addr; | |
6959 | struct ospf_if_params *params; | |
6960 | params = IF_DEF_PARAMS(ifp); | |
6961 | ||
6962 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6963 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6964 | vty_out(vty, | |
6965 | "Please specify interface address by A.B.C.D\n"); | |
6966 | return CMD_WARNING_CONFIG_FAILED; | |
6967 | } | |
6968 | ||
6969 | params = ospf_lookup_if_params(ifp, addr); | |
6970 | if (params == NULL) | |
6971 | return CMD_SUCCESS; | |
6972 | } | |
6973 | ||
6974 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); | |
6975 | UNSET_IF_PARAM(params, auth_simple); | |
6976 | ||
6977 | if (params != IF_DEF_PARAMS(ifp)) { | |
6978 | ospf_free_if_params(ifp, addr); | |
6979 | ospf_if_update_params(ifp, addr); | |
6980 | } | |
6981 | ||
6982 | return CMD_SUCCESS; | |
6983 | } | |
6984 | ||
6985 | DEFUN_HIDDEN (no_ospf_authentication_key, | |
6986 | no_ospf_authentication_key_authkey_addr_cmd, | |
6987 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6988 | NO_STR | |
6989 | "OSPF interface commands\n" | |
6990 | VLINK_HELPSTR_AUTH_SIMPLE | |
6991 | "Address of interface\n") | |
6992 | { | |
6993 | return no_ip_ospf_authentication_key(self, vty, argc, argv); | |
6994 | } | |
6995 | ||
6996 | DEFUN (ip_ospf_message_digest_key, | |
6997 | ip_ospf_message_digest_key_cmd, | |
6998 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", | |
6999 | "IP Information\n" | |
7000 | "OSPF interface commands\n" | |
7001 | "Message digest authentication password (key)\n" | |
7002 | "Key ID\n" | |
7003 | "Use MD5 algorithm\n" | |
7004 | "The OSPF password (key)\n" | |
7005 | "Address of interface\n") | |
7006 | { | |
7007 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7008 | struct crypt_key *ck; | |
7009 | uint8_t key_id; | |
7010 | struct in_addr addr; | |
7011 | struct ospf_if_params *params; | |
7012 | ||
7013 | params = IF_DEF_PARAMS(ifp); | |
7014 | int idx = 0; | |
7015 | ||
7016 | argv_find(argv, argc, "(1-255)", &idx); | |
7017 | char *keyid = argv[idx]->arg; | |
7018 | argv_find(argv, argc, "KEY", &idx); | |
7019 | char *cryptkey = argv[idx]->arg; | |
7020 | ||
7021 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7022 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7023 | vty_out(vty, | |
7024 | "Please specify interface address by A.B.C.D\n"); | |
7025 | return CMD_WARNING_CONFIG_FAILED; | |
7026 | } | |
7027 | ||
7028 | params = ospf_get_if_params(ifp, addr); | |
7029 | ospf_if_update_params(ifp, addr); | |
7030 | } | |
7031 | ||
7032 | key_id = strtol(keyid, NULL, 10); | |
7033 | if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) { | |
7034 | vty_out(vty, "OSPF: Key %d already exists\n", key_id); | |
7035 | return CMD_WARNING; | |
7036 | } | |
7037 | ||
7038 | ck = ospf_crypt_key_new(); | |
7039 | ck->key_id = (uint8_t)key_id; | |
7040 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); | |
7041 | ||
7042 | ospf_crypt_key_add(params->auth_crypt, ck); | |
7043 | SET_IF_PARAM(params, auth_crypt); | |
7044 | ||
7045 | return CMD_SUCCESS; | |
7046 | } | |
7047 | ||
7048 | DEFUN_HIDDEN (ospf_message_digest_key, | |
7049 | ospf_message_digest_key_cmd, | |
7050 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", | |
7051 | "OSPF interface commands\n" | |
7052 | "Message digest authentication password (key)\n" | |
7053 | "Key ID\n" | |
7054 | "Use MD5 algorithm\n" | |
7055 | "The OSPF password (key)\n" | |
7056 | "Address of interface\n") | |
7057 | { | |
7058 | return ip_ospf_message_digest_key(self, vty, argc, argv); | |
7059 | } | |
7060 | ||
7061 | DEFUN (no_ip_ospf_message_digest_key, | |
7062 | no_ip_ospf_message_digest_key_cmd, | |
7063 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", | |
7064 | NO_STR | |
7065 | "IP Information\n" | |
7066 | "OSPF interface commands\n" | |
7067 | "Message digest authentication password (key)\n" | |
7068 | "Key ID\n" | |
7069 | "Use MD5 algorithm\n" | |
7070 | "The OSPF password (key)\n" | |
7071 | "Address of interface\n") | |
7072 | { | |
7073 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7074 | int idx = 0; | |
7075 | struct crypt_key *ck; | |
7076 | int key_id; | |
7077 | struct in_addr addr; | |
7078 | struct ospf_if_params *params; | |
7079 | params = IF_DEF_PARAMS(ifp); | |
7080 | ||
7081 | argv_find(argv, argc, "(1-255)", &idx); | |
7082 | char *keyid = argv[idx]->arg; | |
7083 | ||
7084 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7085 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7086 | vty_out(vty, | |
7087 | "Please specify interface address by A.B.C.D\n"); | |
7088 | return CMD_WARNING_CONFIG_FAILED; | |
7089 | } | |
7090 | ||
7091 | params = ospf_lookup_if_params(ifp, addr); | |
7092 | if (params == NULL) | |
7093 | return CMD_SUCCESS; | |
7094 | } | |
7095 | ||
7096 | key_id = strtol(keyid, NULL, 10); | |
7097 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7098 | if (ck == NULL) { | |
7099 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7100 | return CMD_WARNING_CONFIG_FAILED; | |
7101 | } | |
7102 | ||
7103 | ospf_crypt_key_delete(params->auth_crypt, key_id); | |
7104 | ||
7105 | if (params != IF_DEF_PARAMS(ifp)) { | |
7106 | ospf_free_if_params(ifp, addr); | |
7107 | ospf_if_update_params(ifp, addr); | |
7108 | } | |
7109 | ||
7110 | return CMD_SUCCESS; | |
7111 | } | |
7112 | ||
7113 | DEFUN_HIDDEN (no_ospf_message_digest_key, | |
7114 | no_ospf_message_digest_key_cmd, | |
7115 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", | |
7116 | NO_STR | |
7117 | "OSPF interface commands\n" | |
7118 | "Message digest authentication password (key)\n" | |
7119 | "Key ID\n" | |
7120 | "Use MD5 algorithm\n" | |
7121 | "The OSPF password (key)\n" | |
7122 | "Address of interface\n") | |
7123 | { | |
7124 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); | |
7125 | } | |
7126 | ||
7127 | DEFUN (ip_ospf_cost, | |
7128 | ip_ospf_cost_cmd, | |
7129 | "ip ospf cost (1-65535) [A.B.C.D]", | |
7130 | "IP Information\n" | |
7131 | "OSPF interface commands\n" | |
7132 | "Interface cost\n" | |
7133 | "Cost\n" | |
7134 | "Address of interface\n") | |
7135 | { | |
7136 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7137 | int idx = 0; | |
7138 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; | |
7139 | struct in_addr addr; | |
7140 | struct ospf_if_params *params; | |
7141 | params = IF_DEF_PARAMS(ifp); | |
7142 | ||
7143 | // get arguments | |
7144 | char *coststr = NULL, *ifaddr = NULL; | |
7145 | ||
7146 | argv_find(argv, argc, "(1-65535)", &idx); | |
7147 | coststr = argv[idx]->arg; | |
7148 | cost = strtol(coststr, NULL, 10); | |
7149 | ||
7150 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
7151 | if (ifaddr) { | |
7152 | if (!inet_aton(ifaddr, &addr)) { | |
7153 | vty_out(vty, | |
7154 | "Please specify interface address by A.B.C.D\n"); | |
7155 | return CMD_WARNING_CONFIG_FAILED; | |
7156 | } | |
7157 | ||
7158 | params = ospf_get_if_params(ifp, addr); | |
7159 | ospf_if_update_params(ifp, addr); | |
7160 | } | |
7161 | ||
7162 | SET_IF_PARAM(params, output_cost_cmd); | |
7163 | params->output_cost_cmd = cost; | |
7164 | ||
7165 | ospf_if_recalculate_output_cost(ifp); | |
7166 | ||
7167 | return CMD_SUCCESS; | |
7168 | } | |
7169 | ||
7170 | DEFUN_HIDDEN (ospf_cost, | |
7171 | ospf_cost_cmd, | |
7172 | "ospf cost (1-65535) [A.B.C.D]", | |
7173 | "OSPF interface commands\n" | |
7174 | "Interface cost\n" | |
7175 | "Cost\n" | |
7176 | "Address of interface\n") | |
7177 | { | |
7178 | return ip_ospf_cost(self, vty, argc, argv); | |
7179 | } | |
7180 | ||
7181 | DEFUN (no_ip_ospf_cost, | |
7182 | no_ip_ospf_cost_cmd, | |
7183 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
7184 | NO_STR | |
7185 | "IP Information\n" | |
7186 | "OSPF interface commands\n" | |
7187 | "Interface cost\n" | |
7188 | "Cost\n" | |
7189 | "Address of interface\n") | |
7190 | { | |
7191 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7192 | int idx = 0; | |
7193 | struct in_addr addr; | |
7194 | struct ospf_if_params *params; | |
7195 | ||
7196 | params = IF_DEF_PARAMS(ifp); | |
7197 | ||
7198 | // get arguments | |
7199 | char *ifaddr = NULL; | |
7200 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
7201 | ||
7202 | /* According to the semantics we are mimicking "no ip ospf cost N" is | |
7203 | * always treated as "no ip ospf cost" regardless of the actual value | |
7204 | * of N already configured for the interface. Thus ignore cost. */ | |
7205 | ||
7206 | if (ifaddr) { | |
7207 | if (!inet_aton(ifaddr, &addr)) { | |
7208 | vty_out(vty, | |
7209 | "Please specify interface address by A.B.C.D\n"); | |
7210 | return CMD_WARNING_CONFIG_FAILED; | |
7211 | } | |
7212 | ||
7213 | params = ospf_lookup_if_params(ifp, addr); | |
7214 | if (params == NULL) | |
7215 | return CMD_SUCCESS; | |
7216 | } | |
7217 | ||
7218 | UNSET_IF_PARAM(params, output_cost_cmd); | |
7219 | ||
7220 | if (params != IF_DEF_PARAMS(ifp)) { | |
7221 | ospf_free_if_params(ifp, addr); | |
7222 | ospf_if_update_params(ifp, addr); | |
7223 | } | |
7224 | ||
7225 | ospf_if_recalculate_output_cost(ifp); | |
7226 | ||
7227 | return CMD_SUCCESS; | |
7228 | } | |
7229 | ||
7230 | DEFUN_HIDDEN (no_ospf_cost, | |
7231 | no_ospf_cost_cmd, | |
7232 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
7233 | NO_STR | |
7234 | "OSPF interface commands\n" | |
7235 | "Interface cost\n" | |
7236 | "Cost\n" | |
7237 | "Address of interface\n") | |
7238 | { | |
7239 | return no_ip_ospf_cost(self, vty, argc, argv); | |
7240 | } | |
7241 | ||
7242 | static void ospf_nbr_timer_update(struct ospf_interface *oi) | |
7243 | { | |
7244 | struct route_node *rn; | |
7245 | struct ospf_neighbor *nbr; | |
7246 | ||
7247 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) | |
7248 | if ((nbr = rn->info)) { | |
7249 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
7250 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
7251 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
7252 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
7253 | } | |
7254 | } | |
7255 | ||
7256 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, | |
7257 | const char *nbr_str, | |
7258 | const char *fast_hello_str) | |
7259 | { | |
7260 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7261 | uint32_t seconds; | |
7262 | uint8_t hellomult; | |
7263 | struct in_addr addr; | |
7264 | int ret; | |
7265 | struct ospf_if_params *params; | |
7266 | struct ospf_interface *oi; | |
7267 | struct route_node *rn; | |
7268 | ||
7269 | params = IF_DEF_PARAMS(ifp); | |
7270 | ||
7271 | if (nbr_str) { | |
7272 | ret = inet_aton(nbr_str, &addr); | |
7273 | if (!ret) { | |
7274 | vty_out(vty, | |
7275 | "Please specify interface address by A.B.C.D\n"); | |
7276 | return CMD_WARNING_CONFIG_FAILED; | |
7277 | } | |
7278 | ||
7279 | params = ospf_get_if_params(ifp, addr); | |
7280 | ospf_if_update_params(ifp, addr); | |
7281 | } | |
7282 | ||
7283 | if (interval_str) { | |
7284 | seconds = strtoul(interval_str, NULL, 10); | |
7285 | ||
7286 | /* reset fast_hello too, just to be sure */ | |
7287 | UNSET_IF_PARAM(params, fast_hello); | |
7288 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7289 | } else if (fast_hello_str) { | |
7290 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
7291 | /* 1s dead-interval with sub-second hellos desired */ | |
7292 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
7293 | SET_IF_PARAM(params, fast_hello); | |
7294 | params->fast_hello = hellomult; | |
7295 | } else { | |
7296 | vty_out(vty, | |
7297 | "Please specify dead-interval or hello-multiplier\n"); | |
7298 | return CMD_WARNING_CONFIG_FAILED; | |
7299 | } | |
7300 | ||
7301 | SET_IF_PARAM(params, v_wait); | |
7302 | params->v_wait = seconds; | |
7303 | ||
7304 | /* Update timer values in neighbor structure. */ | |
7305 | if (nbr_str) { | |
7306 | struct ospf *ospf = NULL; | |
7307 | ||
7308 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7309 | if (ospf) { | |
7310 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); | |
7311 | if (oi) | |
7312 | ospf_nbr_timer_update(oi); | |
7313 | } | |
7314 | } else { | |
7315 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7316 | if ((oi = rn->info)) | |
7317 | ospf_nbr_timer_update(oi); | |
7318 | } | |
7319 | ||
7320 | return CMD_SUCCESS; | |
7321 | } | |
7322 | ||
7323 | DEFUN (ip_ospf_dead_interval, | |
7324 | ip_ospf_dead_interval_cmd, | |
7325 | "ip ospf dead-interval (1-65535) [A.B.C.D]", | |
7326 | "IP Information\n" | |
7327 | "OSPF interface commands\n" | |
7328 | "Interval time after which a neighbor is declared down\n" | |
7329 | "Seconds\n" | |
7330 | "Address of interface\n") | |
7331 | { | |
7332 | int idx = 0; | |
7333 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
7334 | ? argv[idx]->arg | |
7335 | : NULL; | |
7336 | char *ifaddr = | |
7337 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
7338 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
7339 | } | |
7340 | ||
7341 | ||
7342 | DEFUN_HIDDEN (ospf_dead_interval, | |
7343 | ospf_dead_interval_cmd, | |
7344 | "ospf dead-interval (1-65535) [A.B.C.D]", | |
7345 | "OSPF interface commands\n" | |
7346 | "Interval time after which a neighbor is declared down\n" | |
7347 | "Seconds\n" | |
7348 | "Address of interface\n") | |
7349 | { | |
7350 | return ip_ospf_dead_interval(self, vty, argc, argv); | |
7351 | } | |
7352 | ||
7353 | DEFUN (ip_ospf_dead_interval_minimal, | |
7354 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7355 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", | |
7356 | "IP Information\n" | |
7357 | "OSPF interface commands\n" | |
7358 | "Interval time after which a neighbor is declared down\n" | |
7359 | "Minimal 1s dead-interval with fast sub-second hellos\n" | |
7360 | "Hello multiplier factor\n" | |
7361 | "Number of Hellos to send each second\n" | |
7362 | "Address of interface\n") | |
7363 | { | |
7364 | int idx_number = 5; | |
7365 | int idx_ipv4 = 6; | |
7366 | if (argc == 7) | |
7367 | return ospf_vty_dead_interval_set( | |
7368 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
7369 | else | |
7370 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
7371 | argv[idx_number]->arg); | |
7372 | } | |
7373 | ||
7374 | DEFUN (no_ip_ospf_dead_interval, | |
7375 | no_ip_ospf_dead_interval_cmd, | |
7376 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
7377 | NO_STR | |
7378 | "IP Information\n" | |
7379 | "OSPF interface commands\n" | |
7380 | "Interval time after which a neighbor is declared down\n" | |
7381 | "Seconds\n" | |
7382 | "Minimal 1s dead-interval with fast sub-second hellos\n" | |
7383 | "Hello multiplier factor\n" | |
7384 | "Number of Hellos to send each second\n" | |
7385 | "Address of interface\n") | |
7386 | { | |
7387 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7388 | int idx_ipv4 = argc - 1; | |
7389 | struct in_addr addr = {.s_addr = 0L}; | |
7390 | int ret; | |
7391 | struct ospf_if_params *params; | |
7392 | struct ospf_interface *oi; | |
7393 | struct route_node *rn; | |
7394 | ||
7395 | params = IF_DEF_PARAMS(ifp); | |
7396 | ||
7397 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
7398 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7399 | if (!ret) { | |
7400 | vty_out(vty, | |
7401 | "Please specify interface address by A.B.C.D\n"); | |
7402 | return CMD_WARNING_CONFIG_FAILED; | |
7403 | } | |
7404 | ||
7405 | params = ospf_lookup_if_params(ifp, addr); | |
7406 | if (params == NULL) | |
7407 | return CMD_SUCCESS; | |
7408 | } | |
7409 | ||
7410 | UNSET_IF_PARAM(params, v_wait); | |
7411 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
7412 | ||
7413 | UNSET_IF_PARAM(params, fast_hello); | |
7414 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7415 | ||
7416 | if (params != IF_DEF_PARAMS(ifp)) { | |
7417 | ospf_free_if_params(ifp, addr); | |
7418 | ospf_if_update_params(ifp, addr); | |
7419 | } | |
7420 | ||
7421 | /* Update timer values in neighbor structure. */ | |
7422 | if (argc == 1) { | |
7423 | struct ospf *ospf = NULL; | |
7424 | ||
7425 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7426 | if (ospf) { | |
7427 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); | |
7428 | if (oi) | |
7429 | ospf_nbr_timer_update(oi); | |
7430 | } | |
7431 | } else { | |
7432 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7433 | if ((oi = rn->info)) | |
7434 | ospf_nbr_timer_update(oi); | |
7435 | } | |
7436 | ||
7437 | return CMD_SUCCESS; | |
7438 | } | |
7439 | ||
7440 | DEFUN_HIDDEN (no_ospf_dead_interval, | |
7441 | no_ospf_dead_interval_cmd, | |
7442 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
7443 | NO_STR | |
7444 | "OSPF interface commands\n" | |
7445 | "Interval time after which a neighbor is declared down\n" | |
7446 | "Seconds\n" | |
7447 | "Minimal 1s dead-interval with fast sub-second hellos\n" | |
7448 | "Hello multiplier factor\n" | |
7449 | "Number of Hellos to send each second\n" | |
7450 | "Address of interface\n") | |
7451 | { | |
7452 | return no_ip_ospf_dead_interval(self, vty, argc, argv); | |
7453 | } | |
7454 | ||
7455 | DEFUN (ip_ospf_hello_interval, | |
7456 | ip_ospf_hello_interval_cmd, | |
7457 | "ip ospf hello-interval (1-65535) [A.B.C.D]", | |
7458 | "IP Information\n" | |
7459 | "OSPF interface commands\n" | |
7460 | "Time between HELLO packets\n" | |
7461 | "Seconds\n" | |
7462 | "Address of interface\n") | |
7463 | { | |
7464 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7465 | int idx = 0; | |
7466 | struct in_addr addr; | |
7467 | struct ospf_if_params *params; | |
7468 | params = IF_DEF_PARAMS(ifp); | |
7469 | uint32_t seconds = 0; | |
7470 | ||
7471 | argv_find(argv, argc, "(1-65535)", &idx); | |
7472 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7473 | ||
7474 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7475 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7476 | vty_out(vty, | |
7477 | "Please specify interface address by A.B.C.D\n"); | |
7478 | return CMD_WARNING_CONFIG_FAILED; | |
7479 | } | |
7480 | ||
7481 | params = ospf_get_if_params(ifp, addr); | |
7482 | ospf_if_update_params(ifp, addr); | |
7483 | } | |
7484 | ||
7485 | SET_IF_PARAM(params, v_hello); | |
7486 | params->v_hello = seconds; | |
7487 | ||
7488 | return CMD_SUCCESS; | |
7489 | } | |
7490 | ||
7491 | DEFUN_HIDDEN (ospf_hello_interval, | |
7492 | ospf_hello_interval_cmd, | |
7493 | "ospf hello-interval (1-65535) [A.B.C.D]", | |
7494 | "OSPF interface commands\n" | |
7495 | "Time between HELLO packets\n" | |
7496 | "Seconds\n" | |
7497 | "Address of interface\n") | |
7498 | { | |
7499 | return ip_ospf_hello_interval(self, vty, argc, argv); | |
7500 | } | |
7501 | ||
7502 | DEFUN (no_ip_ospf_hello_interval, | |
7503 | no_ip_ospf_hello_interval_cmd, | |
7504 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
7505 | NO_STR | |
7506 | "IP Information\n" | |
7507 | "OSPF interface commands\n" | |
7508 | "Time between HELLO packets\n" // ignored | |
7509 | "Seconds\n" | |
7510 | "Address of interface\n") | |
7511 | { | |
7512 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7513 | int idx = 0; | |
7514 | struct in_addr addr; | |
7515 | struct ospf_if_params *params; | |
7516 | ||
7517 | params = IF_DEF_PARAMS(ifp); | |
7518 | ||
7519 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7520 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7521 | vty_out(vty, | |
7522 | "Please specify interface address by A.B.C.D\n"); | |
7523 | return CMD_WARNING_CONFIG_FAILED; | |
7524 | } | |
7525 | ||
7526 | params = ospf_lookup_if_params(ifp, addr); | |
7527 | if (params == NULL) | |
7528 | return CMD_SUCCESS; | |
7529 | } | |
7530 | ||
7531 | UNSET_IF_PARAM(params, v_hello); | |
7532 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
7533 | ||
7534 | if (params != IF_DEF_PARAMS(ifp)) { | |
7535 | ospf_free_if_params(ifp, addr); | |
7536 | ospf_if_update_params(ifp, addr); | |
7537 | } | |
7538 | ||
7539 | return CMD_SUCCESS; | |
7540 | } | |
7541 | ||
7542 | DEFUN_HIDDEN (no_ospf_hello_interval, | |
7543 | no_ospf_hello_interval_cmd, | |
7544 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
7545 | NO_STR | |
7546 | "OSPF interface commands\n" | |
7547 | "Time between HELLO packets\n" // ignored | |
7548 | "Seconds\n" | |
7549 | "Address of interface\n") | |
7550 | { | |
7551 | return no_ip_ospf_hello_interval(self, vty, argc, argv); | |
7552 | } | |
7553 | ||
7554 | DEFUN (ip_ospf_network, | |
7555 | ip_ospf_network_cmd, | |
7556 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", | |
7557 | "IP Information\n" | |
7558 | "OSPF interface commands\n" | |
7559 | "Network type\n" | |
7560 | "Specify OSPF broadcast multi-access network\n" | |
7561 | "Specify OSPF NBMA network\n" | |
7562 | "Specify OSPF point-to-multipoint network\n" | |
7563 | "Specify OSPF point-to-point network\n") | |
7564 | { | |
7565 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7566 | int idx = 0; | |
7567 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7568 | struct route_node *rn; | |
7569 | ||
7570 | if (old_type == OSPF_IFTYPE_LOOPBACK) { | |
7571 | vty_out(vty, | |
7572 | "This is a loopback interface. Can't set network type.\n"); | |
7573 | return CMD_WARNING_CONFIG_FAILED; | |
7574 | } | |
7575 | ||
7576 | if (argv_find(argv, argc, "broadcast", &idx)) | |
7577 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
7578 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
7579 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
7580 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
7581 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
7582 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
7583 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
7584 | ||
7585 | if (IF_DEF_PARAMS(ifp)->type == old_type) | |
7586 | return CMD_SUCCESS; | |
7587 | ||
7588 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
7589 | ||
7590 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7591 | struct ospf_interface *oi = rn->info; | |
7592 | ||
7593 | if (!oi) | |
7594 | continue; | |
7595 | ||
7596 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
7597 | ||
7598 | if (oi->state > ISM_Down) { | |
7599 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7600 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7601 | } | |
7602 | } | |
7603 | ||
7604 | return CMD_SUCCESS; | |
7605 | } | |
7606 | ||
7607 | DEFUN_HIDDEN (ospf_network, | |
7608 | ospf_network_cmd, | |
7609 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", | |
7610 | "OSPF interface commands\n" | |
7611 | "Network type\n" | |
7612 | "Specify OSPF broadcast multi-access network\n" | |
7613 | "Specify OSPF NBMA network\n" | |
7614 | "Specify OSPF point-to-multipoint network\n" | |
7615 | "Specify OSPF point-to-point network\n") | |
7616 | { | |
7617 | return ip_ospf_network(self, vty, argc, argv); | |
7618 | } | |
7619 | ||
7620 | DEFUN (no_ip_ospf_network, | |
7621 | no_ip_ospf_network_cmd, | |
7622 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7623 | NO_STR | |
7624 | "IP Information\n" | |
7625 | "OSPF interface commands\n" | |
7626 | "Network type\n" | |
7627 | "Specify OSPF broadcast multi-access network\n" | |
7628 | "Specify OSPF NBMA network\n" | |
7629 | "Specify OSPF point-to-multipoint network\n" | |
7630 | "Specify OSPF point-to-point network\n") | |
7631 | { | |
7632 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7633 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7634 | struct route_node *rn; | |
7635 | ||
7636 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); | |
7637 | ||
7638 | if (IF_DEF_PARAMS(ifp)->type == old_type) | |
7639 | return CMD_SUCCESS; | |
7640 | ||
7641 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7642 | struct ospf_interface *oi = rn->info; | |
7643 | ||
7644 | if (!oi) | |
7645 | continue; | |
7646 | ||
7647 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
7648 | ||
7649 | if (oi->state > ISM_Down) { | |
7650 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7651 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7652 | } | |
7653 | } | |
7654 | ||
7655 | return CMD_SUCCESS; | |
7656 | } | |
7657 | ||
7658 | DEFUN_HIDDEN (no_ospf_network, | |
7659 | no_ospf_network_cmd, | |
7660 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7661 | NO_STR | |
7662 | "OSPF interface commands\n" | |
7663 | "Network type\n" | |
7664 | "Specify OSPF broadcast multi-access network\n" | |
7665 | "Specify OSPF NBMA network\n" | |
7666 | "Specify OSPF point-to-multipoint network\n" | |
7667 | "Specify OSPF point-to-point network\n") | |
7668 | { | |
7669 | return no_ip_ospf_network(self, vty, argc, argv); | |
7670 | } | |
7671 | ||
7672 | DEFUN (ip_ospf_priority, | |
7673 | ip_ospf_priority_cmd, | |
7674 | "ip ospf priority (0-255) [A.B.C.D]", | |
7675 | "IP Information\n" | |
7676 | "OSPF interface commands\n" | |
7677 | "Router priority\n" | |
7678 | "Priority\n" | |
7679 | "Address of interface\n") | |
7680 | { | |
7681 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7682 | int idx = 0; | |
7683 | long priority; | |
7684 | struct route_node *rn; | |
7685 | struct in_addr addr; | |
7686 | struct ospf_if_params *params; | |
7687 | params = IF_DEF_PARAMS(ifp); | |
7688 | ||
7689 | argv_find(argv, argc, "(0-255)", &idx); | |
7690 | priority = strtol(argv[idx]->arg, NULL, 10); | |
7691 | ||
7692 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7693 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7694 | vty_out(vty, | |
7695 | "Please specify interface address by A.B.C.D\n"); | |
7696 | return CMD_WARNING_CONFIG_FAILED; | |
7697 | } | |
7698 | ||
7699 | params = ospf_get_if_params(ifp, addr); | |
7700 | ospf_if_update_params(ifp, addr); | |
7701 | } | |
7702 | ||
7703 | SET_IF_PARAM(params, priority); | |
7704 | params->priority = priority; | |
7705 | ||
7706 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7707 | struct ospf_interface *oi = rn->info; | |
7708 | ||
7709 | if (!oi) | |
7710 | continue; | |
7711 | ||
7712 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7713 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7714 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7715 | } | |
7716 | } | |
7717 | ||
7718 | return CMD_SUCCESS; | |
7719 | } | |
7720 | ||
7721 | DEFUN_HIDDEN (ospf_priority, | |
7722 | ospf_priority_cmd, | |
7723 | "ospf priority (0-255) [A.B.C.D]", | |
7724 | "OSPF interface commands\n" | |
7725 | "Router priority\n" | |
7726 | "Priority\n" | |
7727 | "Address of interface\n") | |
7728 | { | |
7729 | return ip_ospf_priority(self, vty, argc, argv); | |
7730 | } | |
7731 | ||
7732 | DEFUN (no_ip_ospf_priority, | |
7733 | no_ip_ospf_priority_cmd, | |
7734 | "no ip ospf priority [(0-255) [A.B.C.D]]", | |
7735 | NO_STR | |
7736 | "IP Information\n" | |
7737 | "OSPF interface commands\n" | |
7738 | "Router priority\n" // ignored | |
7739 | "Priority\n" | |
7740 | "Address of interface\n") | |
7741 | { | |
7742 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7743 | int idx = 0; | |
7744 | struct route_node *rn; | |
7745 | struct in_addr addr; | |
7746 | struct ospf_if_params *params; | |
7747 | ||
7748 | params = IF_DEF_PARAMS(ifp); | |
7749 | ||
7750 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7751 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7752 | vty_out(vty, | |
7753 | "Please specify interface address by A.B.C.D\n"); | |
7754 | return CMD_WARNING_CONFIG_FAILED; | |
7755 | } | |
7756 | ||
7757 | params = ospf_lookup_if_params(ifp, addr); | |
7758 | if (params == NULL) | |
7759 | return CMD_SUCCESS; | |
7760 | } | |
7761 | ||
7762 | UNSET_IF_PARAM(params, priority); | |
7763 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
7764 | ||
7765 | if (params != IF_DEF_PARAMS(ifp)) { | |
7766 | ospf_free_if_params(ifp, addr); | |
7767 | ospf_if_update_params(ifp, addr); | |
7768 | } | |
7769 | ||
7770 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7771 | struct ospf_interface *oi = rn->info; | |
7772 | ||
7773 | if (!oi) | |
7774 | continue; | |
7775 | ||
7776 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7777 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7778 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7779 | } | |
7780 | } | |
7781 | ||
7782 | return CMD_SUCCESS; | |
7783 | } | |
7784 | ||
7785 | DEFUN_HIDDEN (no_ospf_priority, | |
7786 | no_ospf_priority_cmd, | |
7787 | "no ospf priority [(0-255) [A.B.C.D]]", | |
7788 | NO_STR | |
7789 | "OSPF interface commands\n" | |
7790 | "Router priority\n" | |
7791 | "Priority\n" | |
7792 | "Address of interface\n") | |
7793 | { | |
7794 | return no_ip_ospf_priority(self, vty, argc, argv); | |
7795 | } | |
7796 | ||
7797 | DEFUN (ip_ospf_retransmit_interval, | |
7798 | ip_ospf_retransmit_interval_addr_cmd, | |
7799 | "ip ospf retransmit-interval (3-65535) [A.B.C.D]", | |
7800 | "IP Information\n" | |
7801 | "OSPF interface commands\n" | |
7802 | "Time between retransmitting lost link state advertisements\n" | |
7803 | "Seconds\n" | |
7804 | "Address of interface\n") | |
7805 | { | |
7806 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7807 | int idx = 0; | |
7808 | uint32_t seconds; | |
7809 | struct in_addr addr; | |
7810 | struct ospf_if_params *params; | |
7811 | params = IF_DEF_PARAMS(ifp); | |
7812 | ||
7813 | argv_find(argv, argc, "(3-65535)", &idx); | |
7814 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7815 | ||
7816 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7817 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7818 | vty_out(vty, | |
7819 | "Please specify interface address by A.B.C.D\n"); | |
7820 | return CMD_WARNING_CONFIG_FAILED; | |
7821 | } | |
7822 | ||
7823 | params = ospf_get_if_params(ifp, addr); | |
7824 | ospf_if_update_params(ifp, addr); | |
7825 | } | |
7826 | ||
7827 | SET_IF_PARAM(params, retransmit_interval); | |
7828 | params->retransmit_interval = seconds; | |
7829 | ||
7830 | return CMD_SUCCESS; | |
7831 | } | |
7832 | ||
7833 | DEFUN_HIDDEN (ospf_retransmit_interval, | |
7834 | ospf_retransmit_interval_cmd, | |
7835 | "ospf retransmit-interval (3-65535) [A.B.C.D]", | |
7836 | "OSPF interface commands\n" | |
7837 | "Time between retransmitting lost link state advertisements\n" | |
7838 | "Seconds\n" | |
7839 | "Address of interface\n") | |
7840 | { | |
7841 | return ip_ospf_retransmit_interval(self, vty, argc, argv); | |
7842 | } | |
7843 | ||
7844 | DEFUN (no_ip_ospf_retransmit_interval, | |
7845 | no_ip_ospf_retransmit_interval_addr_cmd, | |
7846 | "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]", | |
7847 | NO_STR | |
7848 | "IP Information\n" | |
7849 | "OSPF interface commands\n" | |
7850 | "Time between retransmitting lost link state advertisements\n" | |
7851 | "Seconds\n" | |
7852 | "Address of interface\n") | |
7853 | { | |
7854 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7855 | int idx = 0; | |
7856 | struct in_addr addr; | |
7857 | struct ospf_if_params *params; | |
7858 | ||
7859 | params = IF_DEF_PARAMS(ifp); | |
7860 | ||
7861 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7862 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7863 | vty_out(vty, | |
7864 | "Please specify interface address by A.B.C.D\n"); | |
7865 | return CMD_WARNING_CONFIG_FAILED; | |
7866 | } | |
7867 | ||
7868 | params = ospf_lookup_if_params(ifp, addr); | |
7869 | if (params == NULL) | |
7870 | return CMD_SUCCESS; | |
7871 | } | |
7872 | ||
7873 | UNSET_IF_PARAM(params, retransmit_interval); | |
7874 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
7875 | ||
7876 | if (params != IF_DEF_PARAMS(ifp)) { | |
7877 | ospf_free_if_params(ifp, addr); | |
7878 | ospf_if_update_params(ifp, addr); | |
7879 | } | |
7880 | ||
7881 | return CMD_SUCCESS; | |
7882 | } | |
7883 | ||
7884 | DEFUN_HIDDEN (no_ospf_retransmit_interval, | |
7885 | no_ospf_retransmit_interval_cmd, | |
7886 | "no ospf retransmit-interval [(3-65535)] [A.B.C.D]", | |
7887 | NO_STR | |
7888 | "OSPF interface commands\n" | |
7889 | "Time between retransmitting lost link state advertisements\n" | |
7890 | "Seconds\n" | |
7891 | "Address of interface\n") | |
7892 | { | |
7893 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); | |
7894 | } | |
7895 | ||
7896 | DEFUN (ip_ospf_transmit_delay, | |
7897 | ip_ospf_transmit_delay_addr_cmd, | |
7898 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", | |
7899 | "IP Information\n" | |
7900 | "OSPF interface commands\n" | |
7901 | "Link state transmit delay\n" | |
7902 | "Seconds\n" | |
7903 | "Address of interface\n") | |
7904 | { | |
7905 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7906 | int idx = 0; | |
7907 | uint32_t seconds; | |
7908 | struct in_addr addr; | |
7909 | struct ospf_if_params *params; | |
7910 | ||
7911 | params = IF_DEF_PARAMS(ifp); | |
7912 | argv_find(argv, argc, "(1-65535)", &idx); | |
7913 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7914 | ||
7915 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7916 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7917 | vty_out(vty, | |
7918 | "Please specify interface address by A.B.C.D\n"); | |
7919 | return CMD_WARNING_CONFIG_FAILED; | |
7920 | } | |
7921 | ||
7922 | params = ospf_get_if_params(ifp, addr); | |
7923 | ospf_if_update_params(ifp, addr); | |
7924 | } | |
7925 | ||
7926 | SET_IF_PARAM(params, transmit_delay); | |
7927 | params->transmit_delay = seconds; | |
7928 | ||
7929 | return CMD_SUCCESS; | |
7930 | } | |
7931 | ||
7932 | DEFUN_HIDDEN (ospf_transmit_delay, | |
7933 | ospf_transmit_delay_cmd, | |
7934 | "ospf transmit-delay (1-65535) [A.B.C.D]", | |
7935 | "OSPF interface commands\n" | |
7936 | "Link state transmit delay\n" | |
7937 | "Seconds\n" | |
7938 | "Address of interface\n") | |
7939 | { | |
7940 | return ip_ospf_transmit_delay(self, vty, argc, argv); | |
7941 | } | |
7942 | ||
7943 | DEFUN (no_ip_ospf_transmit_delay, | |
7944 | no_ip_ospf_transmit_delay_addr_cmd, | |
7945 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", | |
7946 | NO_STR | |
7947 | "IP Information\n" | |
7948 | "OSPF interface commands\n" | |
7949 | "Link state transmit delay\n" | |
7950 | "Seconds\n" | |
7951 | "Address of interface\n") | |
7952 | { | |
7953 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
7954 | int idx = 0; | |
7955 | struct in_addr addr; | |
7956 | struct ospf_if_params *params; | |
7957 | ||
7958 | params = IF_DEF_PARAMS(ifp); | |
7959 | ||
7960 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7961 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7962 | vty_out(vty, | |
7963 | "Please specify interface address by A.B.C.D\n"); | |
7964 | return CMD_WARNING_CONFIG_FAILED; | |
7965 | } | |
7966 | ||
7967 | params = ospf_lookup_if_params(ifp, addr); | |
7968 | if (params == NULL) | |
7969 | return CMD_SUCCESS; | |
7970 | } | |
7971 | ||
7972 | UNSET_IF_PARAM(params, transmit_delay); | |
7973 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
7974 | ||
7975 | if (params != IF_DEF_PARAMS(ifp)) { | |
7976 | ospf_free_if_params(ifp, addr); | |
7977 | ospf_if_update_params(ifp, addr); | |
7978 | } | |
7979 | ||
7980 | return CMD_SUCCESS; | |
7981 | } | |
7982 | ||
7983 | ||
7984 | DEFUN_HIDDEN (no_ospf_transmit_delay, | |
7985 | no_ospf_transmit_delay_cmd, | |
7986 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", | |
7987 | NO_STR | |
7988 | "OSPF interface commands\n" | |
7989 | "Link state transmit delay\n" | |
7990 | "Seconds\n" | |
7991 | "Address of interface\n") | |
7992 | { | |
7993 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); | |
7994 | } | |
7995 | ||
7996 | DEFUN (ip_ospf_area, | |
7997 | ip_ospf_area_cmd, | |
7998 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", | |
7999 | "IP Information\n" | |
8000 | "OSPF interface commands\n" | |
8001 | "Instance ID\n" | |
8002 | "Enable OSPF on this interface\n" | |
8003 | "OSPF area ID in IP address format\n" | |
8004 | "OSPF area ID as a decimal value\n" | |
8005 | "Address of interface\n") | |
8006 | { | |
8007 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
8008 | int idx = 0; | |
8009 | int format, ret; | |
8010 | struct in_addr area_id; | |
8011 | struct in_addr addr; | |
8012 | struct ospf_if_params *params = NULL; | |
8013 | struct route_node *rn; | |
8014 | struct ospf *ospf = NULL; | |
8015 | unsigned short instance = 0; | |
8016 | char *areaid; | |
8017 | ||
8018 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8019 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8020 | ||
8021 | argv_find(argv, argc, "area", &idx); | |
8022 | areaid = argv[idx + 1]->arg; | |
8023 | ||
8024 | if (ifp->vrf_id && !instance) | |
8025 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
8026 | else | |
8027 | ospf = ospf_lookup_instance(instance); | |
8028 | ||
8029 | if (instance && ospf == NULL) { | |
8030 | params = IF_DEF_PARAMS(ifp); | |
8031 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8032 | UNSET_IF_PARAM(params, if_area); | |
8033 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
8034 | ospf_interface_area_unset(ospf, ifp); | |
8035 | ospf->if_ospf_cli_count--; | |
8036 | } | |
8037 | return CMD_NOT_MY_INSTANCE; | |
8038 | } | |
8039 | ||
8040 | ret = str2area_id(areaid, &area_id, &format); | |
8041 | if (ret < 0) { | |
8042 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8043 | return CMD_WARNING_CONFIG_FAILED; | |
8044 | } | |
8045 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8046 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8047 | return CMD_WARNING_CONFIG_FAILED; | |
8048 | } | |
8049 | ||
8050 | params = IF_DEF_PARAMS(ifp); | |
8051 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8052 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8053 | vty_out(vty, | |
8054 | "Must remove previous area config before changing ospf area \n"); | |
8055 | return CMD_WARNING_CONFIG_FAILED; | |
8056 | } | |
8057 | ||
8058 | // Check if we have an address arg and proccess it | |
8059 | if (argc == idx + 3) { | |
8060 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { | |
8061 | vty_out(vty, | |
8062 | "Please specify Intf Address by A.B.C.D\n"); | |
8063 | return CMD_WARNING_CONFIG_FAILED; | |
8064 | } | |
8065 | // update/create address-level params | |
8066 | params = ospf_get_if_params((ifp), (addr)); | |
8067 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8068 | vty_out(vty, | |
8069 | "Must remove previous area/address config before changing ospf area"); | |
8070 | return CMD_WARNING_CONFIG_FAILED; | |
8071 | } | |
8072 | ospf_if_update_params((ifp), (addr)); | |
8073 | } | |
8074 | ||
8075 | if (ospf) { | |
8076 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8077 | if (rn->info != NULL) { | |
8078 | vty_out(vty, | |
8079 | "Please remove all network commands first.\n"); | |
8080 | return CMD_WARNING_CONFIG_FAILED; | |
8081 | } | |
8082 | } | |
8083 | } | |
8084 | ||
8085 | /* enable ospf on this interface with area_id */ | |
8086 | if (params) { | |
8087 | SET_IF_PARAM(params, if_area); | |
8088 | params->if_area = area_id; | |
8089 | params->if_area_id_fmt = format; | |
8090 | } | |
8091 | ||
8092 | if (ospf) { | |
8093 | ospf_interface_area_set(ospf, ifp); | |
8094 | ospf->if_ospf_cli_count++; | |
8095 | } | |
8096 | ||
8097 | return CMD_SUCCESS; | |
8098 | } | |
8099 | ||
8100 | DEFUN (no_ip_ospf_area, | |
8101 | no_ip_ospf_area_cmd, | |
8102 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", | |
8103 | NO_STR | |
8104 | "IP Information\n" | |
8105 | "OSPF interface commands\n" | |
8106 | "Instance ID\n" | |
8107 | "Disable OSPF on this interface\n" | |
8108 | "OSPF area ID in IP address format\n" | |
8109 | "OSPF area ID as a decimal value\n" | |
8110 | "Address of interface\n") | |
8111 | { | |
8112 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
8113 | int idx = 0; | |
8114 | struct ospf *ospf; | |
8115 | struct ospf_if_params *params; | |
8116 | unsigned short instance = 0; | |
8117 | struct in_addr addr; | |
8118 | ||
8119 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8120 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8121 | ||
8122 | if (ifp->vrf_id && !instance) | |
8123 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
8124 | else | |
8125 | ospf = ospf_lookup_instance(instance); | |
8126 | ||
8127 | if (ospf == NULL) | |
8128 | return CMD_NOT_MY_INSTANCE; | |
8129 | ||
8130 | argv_find(argv, argc, "area", &idx); | |
8131 | ||
8132 | // Check if we have an address arg and proccess it | |
8133 | if (argc == idx + 3) { | |
8134 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { | |
8135 | vty_out(vty, | |
8136 | "Please specify Intf Address by A.B.C.D\n"); | |
8137 | return CMD_WARNING_CONFIG_FAILED; | |
8138 | } | |
8139 | params = ospf_lookup_if_params(ifp, addr); | |
8140 | if ((params) == NULL) | |
8141 | return CMD_SUCCESS; | |
8142 | } else | |
8143 | params = IF_DEF_PARAMS(ifp); | |
8144 | ||
8145 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8146 | vty_out(vty, | |
8147 | "Can't find specified interface area configuration.\n"); | |
8148 | return CMD_WARNING_CONFIG_FAILED; | |
8149 | } | |
8150 | ||
8151 | UNSET_IF_PARAM(params, if_area); | |
8152 | if (params != IF_DEF_PARAMS((ifp))) { | |
8153 | ospf_free_if_params((ifp), (addr)); | |
8154 | ospf_if_update_params((ifp), (addr)); | |
8155 | } | |
8156 | ||
8157 | ospf_interface_area_unset(ospf, ifp); | |
8158 | ospf->if_ospf_cli_count--; | |
8159 | return CMD_SUCCESS; | |
8160 | } | |
8161 | ||
8162 | DEFUN (ospf_redistribute_source, | |
8163 | ospf_redistribute_source_cmd, | |
8164 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", | |
8165 | REDIST_STR | |
8166 | FRR_REDIST_HELP_STR_OSPFD | |
8167 | "Metric for redistributed routes\n" | |
8168 | "OSPF default metric\n" | |
8169 | "OSPF exterior metric type for redistributed routes\n" | |
8170 | "Set OSPF External Type 1/2 metrics\n" | |
8171 | "Route map reference\n" | |
8172 | "Pointer to route-map entries\n") | |
8173 | { | |
8174 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8175 | int idx_protocol = 1; | |
8176 | int source; | |
8177 | int type = -1; | |
8178 | int metric = -1; | |
8179 | struct ospf_redist *red; | |
8180 | int idx = 0; | |
8181 | ||
8182 | /* Get distribute source. */ | |
8183 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
8184 | if (source < 0) | |
8185 | return CMD_WARNING_CONFIG_FAILED; | |
8186 | ||
8187 | red = ospf_redist_add(ospf, source, 0); | |
8188 | ||
8189 | /* Get metric value. */ | |
8190 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
8191 | if (!str2metric(argv[idx]->arg, &metric)) | |
8192 | return CMD_WARNING_CONFIG_FAILED; | |
8193 | } | |
8194 | idx = 1; | |
8195 | /* Get metric type. */ | |
8196 | if (argv_find(argv, argc, "(1-2)", &idx)) { | |
8197 | if (!str2metric_type(argv[idx]->arg, &type)) | |
8198 | return CMD_WARNING_CONFIG_FAILED; | |
8199 | } | |
8200 | idx = 1; | |
8201 | /* Get route-map */ | |
8202 | if (argv_find(argv, argc, "WORD", &idx)) { | |
8203 | ospf_routemap_set(red, argv[idx]->arg); | |
8204 | } else | |
8205 | ospf_routemap_unset(red); | |
8206 | ||
8207 | return ospf_redistribute_set(ospf, source, 0, type, metric); | |
8208 | } | |
8209 | ||
8210 | DEFUN (no_ospf_redistribute_source, | |
8211 | no_ospf_redistribute_source_cmd, | |
8212 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", | |
8213 | NO_STR | |
8214 | REDIST_STR | |
8215 | FRR_REDIST_HELP_STR_OSPFD | |
8216 | "Metric for redistributed routes\n" | |
8217 | "OSPF default metric\n" | |
8218 | "OSPF exterior metric type for redistributed routes\n" | |
8219 | "Set OSPF External Type 1/2 metrics\n" | |
8220 | "Route map reference\n" | |
8221 | "Pointer to route-map entries\n") | |
8222 | { | |
8223 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8224 | int idx_protocol = 2; | |
8225 | int source; | |
8226 | struct ospf_redist *red; | |
8227 | ||
8228 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
8229 | if (source < 0) | |
8230 | return CMD_WARNING_CONFIG_FAILED; | |
8231 | ||
8232 | red = ospf_redist_lookup(ospf, source, 0); | |
8233 | if (!red) | |
8234 | return CMD_SUCCESS; | |
8235 | ||
8236 | ospf_routemap_unset(red); | |
8237 | ospf_redist_del(ospf, source, 0); | |
8238 | ||
8239 | return ospf_redistribute_unset(ospf, source, 0); | |
8240 | } | |
8241 | ||
8242 | DEFUN (ospf_redistribute_instance_source, | |
8243 | ospf_redistribute_instance_source_cmd, | |
8244 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", | |
8245 | REDIST_STR | |
8246 | "Open Shortest Path First\n" | |
8247 | "Non-main Kernel Routing Table\n" | |
8248 | "Instance ID/Table ID\n" | |
8249 | "Metric for redistributed routes\n" | |
8250 | "OSPF default metric\n" | |
8251 | "OSPF exterior metric type for redistributed routes\n" | |
8252 | "Set OSPF External Type 1/2 metrics\n" | |
8253 | "Route map reference\n" | |
8254 | "Pointer to route-map entries\n") | |
8255 | { | |
8256 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8257 | int idx_ospf_table = 1; | |
8258 | int idx_number = 2; | |
8259 | int idx = 3; | |
8260 | int source; | |
8261 | int type = -1; | |
8262 | int metric = -1; | |
8263 | unsigned short instance; | |
8264 | struct ospf_redist *red; | |
8265 | ||
8266 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); | |
8267 | ||
8268 | if (source < 0) { | |
8269 | vty_out(vty, "Unknown instance redistribution\n"); | |
8270 | return CMD_WARNING_CONFIG_FAILED; | |
8271 | } | |
8272 | ||
8273 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
8274 | ||
8275 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { | |
8276 | vty_out(vty, | |
8277 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8278 | return CMD_WARNING_CONFIG_FAILED; | |
8279 | } | |
8280 | ||
8281 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
8282 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8283 | return CMD_WARNING_CONFIG_FAILED; | |
8284 | } | |
8285 | ||
8286 | /* Get metric value. */ | |
8287 | if (argv_find(argv, argc, "metric", &idx)) | |
8288 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
8289 | return CMD_WARNING_CONFIG_FAILED; | |
8290 | ||
8291 | idx = 3; | |
8292 | /* Get metric type. */ | |
8293 | if (argv_find(argv, argc, "metric-type", &idx)) | |
8294 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
8295 | return CMD_WARNING_CONFIG_FAILED; | |
8296 | ||
8297 | red = ospf_redist_add(ospf, source, instance); | |
8298 | ||
8299 | idx = 3; | |
8300 | if (argv_find(argv, argc, "route-map", &idx)) | |
8301 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
8302 | else | |
8303 | ospf_routemap_unset(red); | |
8304 | ||
8305 | return ospf_redistribute_set(ospf, source, instance, type, metric); | |
8306 | } | |
8307 | ||
8308 | DEFUN (no_ospf_redistribute_instance_source, | |
8309 | no_ospf_redistribute_instance_source_cmd, | |
8310 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", | |
8311 | NO_STR | |
8312 | REDIST_STR | |
8313 | "Open Shortest Path First\n" | |
8314 | "Non-main Kernel Routing Table\n" | |
8315 | "Instance ID/Table Id\n" | |
8316 | "Metric for redistributed routes\n" | |
8317 | "OSPF default metric\n" | |
8318 | "OSPF exterior metric type for redistributed routes\n" | |
8319 | "Set OSPF External Type 1/2 metrics\n" | |
8320 | "Route map reference\n" | |
8321 | "Pointer to route-map entries\n") | |
8322 | { | |
8323 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8324 | int idx_ospf_table = 2; | |
8325 | int idx_number = 3; | |
8326 | unsigned int instance; | |
8327 | struct ospf_redist *red; | |
8328 | int source; | |
8329 | ||
8330 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
8331 | source = ZEBRA_ROUTE_OSPF; | |
8332 | else | |
8333 | source = ZEBRA_ROUTE_TABLE; | |
8334 | ||
8335 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
8336 | ||
8337 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { | |
8338 | vty_out(vty, | |
8339 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8340 | return CMD_WARNING_CONFIG_FAILED; | |
8341 | } | |
8342 | ||
8343 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
8344 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8345 | return CMD_WARNING_CONFIG_FAILED; | |
8346 | } | |
8347 | ||
8348 | red = ospf_redist_lookup(ospf, source, instance); | |
8349 | if (!red) | |
8350 | return CMD_SUCCESS; | |
8351 | ||
8352 | ospf_routemap_unset(red); | |
8353 | ospf_redist_del(ospf, source, instance); | |
8354 | ||
8355 | return ospf_redistribute_unset(ospf, source, instance); | |
8356 | } | |
8357 | ||
8358 | DEFUN (ospf_distribute_list_out, | |
8359 | ospf_distribute_list_out_cmd, | |
8360 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, | |
8361 | "Filter networks in routing updates\n" | |
8362 | "Access-list name\n" | |
8363 | OUT_STR | |
8364 | FRR_REDIST_HELP_STR_OSPFD) | |
8365 | { | |
8366 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8367 | int idx_word = 1; | |
8368 | int source; | |
8369 | ||
8370 | char *proto = argv[argc - 1]->text; | |
8371 | ||
8372 | /* Get distribute source. */ | |
8373 | source = proto_redistnum(AFI_IP, proto); | |
8374 | if (source < 0) | |
8375 | return CMD_WARNING_CONFIG_FAILED; | |
8376 | ||
8377 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); | |
8378 | } | |
8379 | ||
8380 | DEFUN (no_ospf_distribute_list_out, | |
8381 | no_ospf_distribute_list_out_cmd, | |
8382 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, | |
8383 | NO_STR | |
8384 | "Filter networks in routing updates\n" | |
8385 | "Access-list name\n" | |
8386 | OUT_STR | |
8387 | FRR_REDIST_HELP_STR_OSPFD) | |
8388 | { | |
8389 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8390 | int idx_word = 2; | |
8391 | int source; | |
8392 | ||
8393 | char *proto = argv[argc - 1]->text; | |
8394 | source = proto_redistnum(AFI_IP, proto); | |
8395 | if (source < 0) | |
8396 | return CMD_WARNING_CONFIG_FAILED; | |
8397 | ||
8398 | return ospf_distribute_list_out_unset(ospf, source, | |
8399 | argv[idx_word]->arg); | |
8400 | } | |
8401 | ||
8402 | /* Default information originate. */ | |
8403 | DEFUN (ospf_default_information_originate, | |
8404 | ospf_default_information_originate_cmd, | |
8405 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", | |
8406 | "Control distribution of default information\n" | |
8407 | "Distribute a default route\n" | |
8408 | "Always advertise default route\n" | |
8409 | "OSPF default metric\n" | |
8410 | "OSPF metric\n" | |
8411 | "OSPF metric type for default routes\n" | |
8412 | "Set OSPF External Type 1/2 metrics\n" | |
8413 | "Route map reference\n" | |
8414 | "Pointer to route-map entries\n") | |
8415 | { | |
8416 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8417 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; | |
8418 | int type = -1; | |
8419 | int metric = -1; | |
8420 | struct ospf_redist *red; | |
8421 | int idx = 0; | |
8422 | int cur_originate = ospf->default_originate; | |
8423 | int sameRtmap = 0; | |
8424 | char *rtmap = NULL; | |
8425 | ||
8426 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
8427 | ||
8428 | /* Check whether "always" was specified */ | |
8429 | if (argv_find(argv, argc, "always", &idx)) | |
8430 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
8431 | idx = 1; | |
8432 | /* Get metric value */ | |
8433 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
8434 | if (!str2metric(argv[idx]->arg, &metric)) | |
8435 | return CMD_WARNING_CONFIG_FAILED; | |
8436 | } | |
8437 | idx = 1; | |
8438 | /* Get metric type. */ | |
8439 | if (argv_find(argv, argc, "(1-2)", &idx)) { | |
8440 | if (!str2metric_type(argv[idx]->arg, &type)) | |
8441 | return CMD_WARNING_CONFIG_FAILED; | |
8442 | } | |
8443 | idx = 1; | |
8444 | /* Get route-map */ | |
8445 | if (argv_find(argv, argc, "WORD", &idx)) | |
8446 | rtmap = argv[idx]->arg; | |
8447 | ||
8448 | /* To check ,if user is providing same route map */ | |
8449 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
8450 | (rtmap && ROUTEMAP_NAME(red) | |
8451 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
8452 | sameRtmap = 1; | |
8453 | ||
8454 | /* Don't allow if the same lsa is aleardy originated. */ | |
8455 | if ((sameRtmap) | |
8456 | && (red->dmetric.type == type) | |
8457 | && (red->dmetric.value == metric) | |
8458 | && (cur_originate == default_originate)) | |
8459 | return CMD_SUCCESS; | |
8460 | ||
8461 | /* Updating Metric details */ | |
8462 | red->dmetric.type = type; | |
8463 | red->dmetric.value = metric; | |
8464 | ||
8465 | /* updating route map details */ | |
8466 | if (rtmap) | |
8467 | ospf_routemap_set(red, rtmap); | |
8468 | else | |
8469 | ospf_routemap_unset(red); | |
8470 | ||
8471 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
8472 | metric); | |
8473 | } | |
8474 | ||
8475 | DEFUN (no_ospf_default_information_originate, | |
8476 | no_ospf_default_information_originate_cmd, | |
8477 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", | |
8478 | NO_STR | |
8479 | "Control distribution of default information\n" | |
8480 | "Distribute a default route\n" | |
8481 | "Always advertise default route\n" | |
8482 | "OSPF default metric\n" | |
8483 | "OSPF metric\n" | |
8484 | "OSPF metric type for default routes\n" | |
8485 | "Set OSPF External Type 1/2 metrics\n" | |
8486 | "Route map reference\n" | |
8487 | "Pointer to route-map entries\n") | |
8488 | { | |
8489 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8490 | struct ospf_redist *red; | |
8491 | ||
8492 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); | |
8493 | if (!red) | |
8494 | return CMD_SUCCESS; | |
8495 | ||
8496 | ospf_routemap_unset(red); | |
8497 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); | |
8498 | ||
8499 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, | |
8500 | 0, 0); | |
8501 | } | |
8502 | ||
8503 | DEFUN (ospf_default_metric, | |
8504 | ospf_default_metric_cmd, | |
8505 | "default-metric (0-16777214)", | |
8506 | "Set metric of redistributed routes\n" | |
8507 | "Default metric\n") | |
8508 | { | |
8509 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8510 | int idx_number = 1; | |
8511 | int metric = -1; | |
8512 | ||
8513 | if (!str2metric(argv[idx_number]->arg, &metric)) | |
8514 | return CMD_WARNING_CONFIG_FAILED; | |
8515 | ||
8516 | ospf->default_metric = metric; | |
8517 | ||
8518 | return CMD_SUCCESS; | |
8519 | } | |
8520 | ||
8521 | DEFUN (no_ospf_default_metric, | |
8522 | no_ospf_default_metric_cmd, | |
8523 | "no default-metric [(0-16777214)]", | |
8524 | NO_STR | |
8525 | "Set metric of redistributed routes\n" | |
8526 | "Default metric\n") | |
8527 | { | |
8528 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8529 | ||
8530 | ospf->default_metric = -1; | |
8531 | ||
8532 | return CMD_SUCCESS; | |
8533 | } | |
8534 | ||
8535 | ||
8536 | DEFUN (ospf_distance, | |
8537 | ospf_distance_cmd, | |
8538 | "distance (1-255)", | |
8539 | "Administrative distance\n" | |
8540 | "OSPF Administrative distance\n") | |
8541 | { | |
8542 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8543 | int idx_number = 1; | |
8544 | ||
8545 | ospf->distance_all = atoi(argv[idx_number]->arg); | |
8546 | ||
8547 | return CMD_SUCCESS; | |
8548 | } | |
8549 | ||
8550 | DEFUN (no_ospf_distance, | |
8551 | no_ospf_distance_cmd, | |
8552 | "no distance (1-255)", | |
8553 | NO_STR | |
8554 | "Administrative distance\n" | |
8555 | "OSPF Administrative distance\n") | |
8556 | { | |
8557 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8558 | ||
8559 | ospf->distance_all = 0; | |
8560 | ||
8561 | return CMD_SUCCESS; | |
8562 | } | |
8563 | ||
8564 | DEFUN (no_ospf_distance_ospf, | |
8565 | no_ospf_distance_ospf_cmd, | |
8566 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", | |
8567 | NO_STR | |
8568 | "Administrative distance\n" | |
8569 | "OSPF administrative distance\n" | |
8570 | "Intra-area routes\n" | |
8571 | "Distance for intra-area routes\n" | |
8572 | "Inter-area routes\n" | |
8573 | "Distance for inter-area routes\n" | |
8574 | "External routes\n" | |
8575 | "Distance for external routes\n") | |
8576 | { | |
8577 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8578 | int idx = 0; | |
8579 | ||
8580 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) | |
8581 | idx = ospf->distance_intra = 0; | |
8582 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
8583 | idx = ospf->distance_inter = 0; | |
8584 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
8585 | ospf->distance_external = 0; | |
8586 | ||
8587 | return CMD_SUCCESS; | |
8588 | } | |
8589 | ||
8590 | DEFUN (ospf_distance_ospf, | |
8591 | ospf_distance_ospf_cmd, | |
8592 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", | |
8593 | "Administrative distance\n" | |
8594 | "OSPF administrative distance\n" | |
8595 | "Intra-area routes\n" | |
8596 | "Distance for intra-area routes\n" | |
8597 | "Inter-area routes\n" | |
8598 | "Distance for inter-area routes\n" | |
8599 | "External routes\n" | |
8600 | "Distance for external routes\n") | |
8601 | { | |
8602 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8603 | int idx = 0; | |
8604 | ||
8605 | ospf->distance_intra = 0; | |
8606 | ospf->distance_inter = 0; | |
8607 | ospf->distance_external = 0; | |
8608 | ||
8609 | if (argv_find(argv, argc, "intra-area", &idx)) | |
8610 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
8611 | idx = 0; | |
8612 | if (argv_find(argv, argc, "inter-area", &idx)) | |
8613 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
8614 | idx = 0; | |
8615 | if (argv_find(argv, argc, "external", &idx)) | |
8616 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
8617 | ||
8618 | return CMD_SUCCESS; | |
8619 | } | |
8620 | ||
8621 | #if 0 | |
8622 | DEFUN (ospf_distance_source, | |
8623 | ospf_distance_source_cmd, | |
8624 | "distance (1-255) A.B.C.D/M", | |
8625 | "Administrative distance\n" | |
8626 | "Distance value\n" | |
8627 | "IP source prefix\n") | |
8628 | { | |
8629 | VTY_DECLVAR_CONTEXT(ospf, ospf); | |
8630 | int idx_number = 1; | |
8631 | int idx_ipv4_prefixlen = 2; | |
8632 | ||
8633 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); | |
8634 | ||
8635 | return CMD_SUCCESS; | |
8636 | } | |
8637 | ||
8638 | DEFUN (no_ospf_distance_source, | |
8639 | no_ospf_distance_source_cmd, | |
8640 | "no distance (1-255) A.B.C.D/M", | |
8641 | NO_STR | |
8642 | "Administrative distance\n" | |
8643 | "Distance value\n" | |
8644 | "IP source prefix\n") | |
8645 | { | |
8646 | VTY_DECLVAR_CONTEXT(ospf, ospf); | |
8647 | int idx_number = 2; | |
8648 | int idx_ipv4_prefixlen = 3; | |
8649 | ||
8650 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); | |
8651 | ||
8652 | return CMD_SUCCESS; | |
8653 | } | |
8654 | ||
8655 | DEFUN (ospf_distance_source_access_list, | |
8656 | ospf_distance_source_access_list_cmd, | |
8657 | "distance (1-255) A.B.C.D/M WORD", | |
8658 | "Administrative distance\n" | |
8659 | "Distance value\n" | |
8660 | "IP source prefix\n" | |
8661 | "Access list name\n") | |
8662 | { | |
8663 | VTY_DECLVAR_CONTEXT(ospf, ospf); | |
8664 | int idx_number = 1; | |
8665 | int idx_ipv4_prefixlen = 2; | |
8666 | int idx_word = 3; | |
8667 | ||
8668 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); | |
8669 | ||
8670 | return CMD_SUCCESS; | |
8671 | } | |
8672 | ||
8673 | DEFUN (no_ospf_distance_source_access_list, | |
8674 | no_ospf_distance_source_access_list_cmd, | |
8675 | "no distance (1-255) A.B.C.D/M WORD", | |
8676 | NO_STR | |
8677 | "Administrative distance\n" | |
8678 | "Distance value\n" | |
8679 | "IP source prefix\n" | |
8680 | "Access list name\n") | |
8681 | { | |
8682 | VTY_DECLVAR_CONTEXT(ospf, ospf); | |
8683 | int idx_number = 2; | |
8684 | int idx_ipv4_prefixlen = 3; | |
8685 | int idx_word = 4; | |
8686 | ||
8687 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); | |
8688 | ||
8689 | return CMD_SUCCESS; | |
8690 | } | |
8691 | #endif | |
8692 | ||
8693 | DEFUN (ip_ospf_mtu_ignore, | |
8694 | ip_ospf_mtu_ignore_addr_cmd, | |
8695 | "ip ospf mtu-ignore [A.B.C.D]", | |
8696 | "IP Information\n" | |
8697 | "OSPF interface commands\n" | |
8698 | "Disable MTU mismatch detection on this interface\n" | |
8699 | "Address of interface\n") | |
8700 | { | |
8701 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
8702 | int idx_ipv4 = 3; | |
8703 | struct in_addr addr; | |
8704 | int ret; | |
8705 | ||
8706 | struct ospf_if_params *params; | |
8707 | params = IF_DEF_PARAMS(ifp); | |
8708 | ||
8709 | if (argc == 4) { | |
8710 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8711 | if (!ret) { | |
8712 | vty_out(vty, | |
8713 | "Please specify interface address by A.B.C.D\n"); | |
8714 | return CMD_WARNING_CONFIG_FAILED; | |
8715 | } | |
8716 | params = ospf_get_if_params(ifp, addr); | |
8717 | ospf_if_update_params(ifp, addr); | |
8718 | } | |
8719 | params->mtu_ignore = 1; | |
8720 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8721 | SET_IF_PARAM(params, mtu_ignore); | |
8722 | else { | |
8723 | UNSET_IF_PARAM(params, mtu_ignore); | |
8724 | if (params != IF_DEF_PARAMS(ifp)) { | |
8725 | ospf_free_if_params(ifp, addr); | |
8726 | ospf_if_update_params(ifp, addr); | |
8727 | } | |
8728 | } | |
8729 | return CMD_SUCCESS; | |
8730 | } | |
8731 | ||
8732 | DEFUN (no_ip_ospf_mtu_ignore, | |
8733 | no_ip_ospf_mtu_ignore_addr_cmd, | |
8734 | "no ip ospf mtu-ignore [A.B.C.D]", | |
8735 | NO_STR | |
8736 | "IP Information\n" | |
8737 | "OSPF interface commands\n" | |
8738 | "Disable MTU mismatch detection on this interface\n" | |
8739 | "Address of interface\n") | |
8740 | { | |
8741 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
8742 | int idx_ipv4 = 4; | |
8743 | struct in_addr addr; | |
8744 | int ret; | |
8745 | ||
8746 | struct ospf_if_params *params; | |
8747 | params = IF_DEF_PARAMS(ifp); | |
8748 | ||
8749 | if (argc == 5) { | |
8750 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8751 | if (!ret) { | |
8752 | vty_out(vty, | |
8753 | "Please specify interface address by A.B.C.D\n"); | |
8754 | return CMD_WARNING_CONFIG_FAILED; | |
8755 | } | |
8756 | params = ospf_get_if_params(ifp, addr); | |
8757 | ospf_if_update_params(ifp, addr); | |
8758 | } | |
8759 | params->mtu_ignore = 0; | |
8760 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8761 | SET_IF_PARAM(params, mtu_ignore); | |
8762 | else { | |
8763 | UNSET_IF_PARAM(params, mtu_ignore); | |
8764 | if (params != IF_DEF_PARAMS(ifp)) { | |
8765 | ospf_free_if_params(ifp, addr); | |
8766 | ospf_if_update_params(ifp, addr); | |
8767 | } | |
8768 | } | |
8769 | return CMD_SUCCESS; | |
8770 | } | |
8771 | ||
8772 | ||
8773 | DEFUN (ospf_max_metric_router_lsa_admin, | |
8774 | ospf_max_metric_router_lsa_admin_cmd, | |
8775 | "max-metric router-lsa administrative", | |
8776 | "OSPF maximum / infinite-distance metric\n" | |
8777 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8778 | "Administratively applied, for an indefinite period\n") | |
8779 | { | |
8780 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8781 | struct listnode *ln; | |
8782 | struct ospf_area *area; | |
8783 | ||
8784 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8785 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
8786 | ||
8787 | if (!CHECK_FLAG(area->stub_router_state, | |
8788 | OSPF_AREA_IS_STUB_ROUTED)) | |
8789 | ospf_router_lsa_update_area(area); | |
8790 | } | |
8791 | ||
8792 | /* Allows for areas configured later to get the property */ | |
8793 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
8794 | ||
8795 | return CMD_SUCCESS; | |
8796 | } | |
8797 | ||
8798 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
8799 | no_ospf_max_metric_router_lsa_admin_cmd, | |
8800 | "no max-metric router-lsa administrative", | |
8801 | NO_STR | |
8802 | "OSPF maximum / infinite-distance metric\n" | |
8803 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8804 | "Administratively applied, for an indefinite period\n") | |
8805 | { | |
8806 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8807 | struct listnode *ln; | |
8808 | struct ospf_area *area; | |
8809 | ||
8810 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8811 | UNSET_FLAG(area->stub_router_state, | |
8812 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
8813 | ||
8814 | /* Don't trample on the start-up stub timer */ | |
8815 | if (CHECK_FLAG(area->stub_router_state, | |
8816 | OSPF_AREA_IS_STUB_ROUTED) | |
8817 | && !area->t_stub_router) { | |
8818 | UNSET_FLAG(area->stub_router_state, | |
8819 | OSPF_AREA_IS_STUB_ROUTED); | |
8820 | ospf_router_lsa_update_area(area); | |
8821 | } | |
8822 | } | |
8823 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
8824 | return CMD_SUCCESS; | |
8825 | } | |
8826 | ||
8827 | DEFUN (ospf_max_metric_router_lsa_startup, | |
8828 | ospf_max_metric_router_lsa_startup_cmd, | |
8829 | "max-metric router-lsa on-startup (5-86400)", | |
8830 | "OSPF maximum / infinite-distance metric\n" | |
8831 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8832 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8833 | "Time (seconds) to advertise self as stub-router\n") | |
8834 | { | |
8835 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8836 | int idx_number = 3; | |
8837 | unsigned int seconds; | |
8838 | ||
8839 | if (argc < 4) { | |
8840 | vty_out(vty, "%% Must supply stub-router period"); | |
8841 | return CMD_WARNING_CONFIG_FAILED; | |
8842 | } | |
8843 | ||
8844 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8845 | ||
8846 | ospf->stub_router_startup_time = seconds; | |
8847 | ||
8848 | return CMD_SUCCESS; | |
8849 | } | |
8850 | ||
8851 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
8852 | no_ospf_max_metric_router_lsa_startup_cmd, | |
8853 | "no max-metric router-lsa on-startup [(5-86400)]", | |
8854 | NO_STR | |
8855 | "OSPF maximum / infinite-distance metric\n" | |
8856 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8857 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8858 | "Time (seconds) to advertise self as stub-router\n") | |
8859 | { | |
8860 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8861 | struct listnode *ln; | |
8862 | struct ospf_area *area; | |
8863 | ||
8864 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8865 | ||
8866 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8867 | SET_FLAG(area->stub_router_state, | |
8868 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
8869 | OSPF_TIMER_OFF(area->t_stub_router); | |
8870 | ||
8871 | /* Don't trample on admin stub routed */ | |
8872 | if (!CHECK_FLAG(area->stub_router_state, | |
8873 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8874 | UNSET_FLAG(area->stub_router_state, | |
8875 | OSPF_AREA_IS_STUB_ROUTED); | |
8876 | ospf_router_lsa_update_area(area); | |
8877 | } | |
8878 | } | |
8879 | return CMD_SUCCESS; | |
8880 | } | |
8881 | ||
8882 | ||
8883 | DEFUN (ospf_max_metric_router_lsa_shutdown, | |
8884 | ospf_max_metric_router_lsa_shutdown_cmd, | |
8885 | "max-metric router-lsa on-shutdown (5-100)", | |
8886 | "OSPF maximum / infinite-distance metric\n" | |
8887 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8888 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8889 | "Time (seconds) to wait till full shutdown\n") | |
8890 | { | |
8891 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8892 | int idx_number = 3; | |
8893 | unsigned int seconds; | |
8894 | ||
8895 | if (argc < 4) { | |
8896 | vty_out(vty, "%% Must supply stub-router shutdown period"); | |
8897 | return CMD_WARNING_CONFIG_FAILED; | |
8898 | } | |
8899 | ||
8900 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8901 | ||
8902 | ospf->stub_router_shutdown_time = seconds; | |
8903 | ||
8904 | return CMD_SUCCESS; | |
8905 | } | |
8906 | ||
8907 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
8908 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
8909 | "no max-metric router-lsa on-shutdown [(5-100)]", | |
8910 | NO_STR | |
8911 | "OSPF maximum / infinite-distance metric\n" | |
8912 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8913 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8914 | "Time (seconds) to wait till full shutdown\n") | |
8915 | { | |
8916 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
8917 | ||
8918 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8919 | ||
8920 | return CMD_SUCCESS; | |
8921 | } | |
8922 | ||
8923 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) | |
8924 | { | |
8925 | struct listnode *ln; | |
8926 | struct ospf_area *area; | |
8927 | ||
8928 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8929 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
8930 | ospf->stub_router_startup_time); | |
8931 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8932 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
8933 | ospf->stub_router_shutdown_time); | |
8934 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8935 | if (CHECK_FLAG(area->stub_router_state, | |
8936 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8937 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
8938 | break; | |
8939 | } | |
8940 | } | |
8941 | return; | |
8942 | } | |
8943 | ||
8944 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, | |
8945 | struct route_table *rt, | |
8946 | json_object *json) | |
8947 | { | |
8948 | struct route_node *rn; | |
8949 | struct ospf_route * or ; | |
8950 | struct listnode *pnode, *pnnode; | |
8951 | struct ospf_path *path; | |
8952 | json_object *json_route = NULL, *json_nexthop_array = NULL, | |
8953 | *json_nexthop = NULL; | |
8954 | ||
8955 | if (!json) | |
8956 | vty_out(vty, | |
8957 | "============ OSPF network routing table ============\n"); | |
8958 | ||
8959 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
8960 | if ((or = rn->info) == NULL) | |
8961 | continue; | |
8962 | char buf1[PREFIX2STR_BUFFER]; | |
8963 | ||
8964 | memset(buf1, 0, sizeof(buf1)); | |
8965 | prefix2str(&rn->p, buf1, sizeof(buf1)); | |
8966 | ||
8967 | json_route = json_object_new_object(); | |
8968 | if (json) { | |
8969 | json_object_object_add(json, buf1, json_route); | |
8970 | json_object_to_json_string_ext( | |
8971 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
8972 | } | |
8973 | ||
8974 | switch (or->path_type) { | |
8975 | case OSPF_PATH_INTER_AREA: | |
8976 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
8977 | if (json) { | |
8978 | json_object_string_add(json_route, | |
8979 | "routeType", | |
8980 | "N IA"); | |
8981 | json_object_int_add(json_route, "cost", | |
8982 | or->cost); | |
8983 | json_object_string_add( | |
8984 | json_route, "area", | |
8985 | inet_ntoa(or->u.std.area_id)); | |
8986 | } else { | |
8987 | vty_out(vty, | |
8988 | "N IA %-18s [%d] area: %s\n", | |
8989 | buf1, or->cost, | |
8990 | inet_ntoa(or->u.std.area_id)); | |
8991 | } | |
8992 | } else if (or->type == OSPF_DESTINATION_DISCARD) { | |
8993 | if (json) { | |
8994 | json_object_string_add(json_route, | |
8995 | "routeType", | |
8996 | "D IA"); | |
8997 | } else { | |
8998 | vty_out(vty, | |
8999 | "D IA %-18s Discard entry\n", | |
9000 | buf1); | |
9001 | } | |
9002 | } | |
9003 | break; | |
9004 | case OSPF_PATH_INTRA_AREA: | |
9005 | if (json) { | |
9006 | json_object_string_add(json_route, "routeType", | |
9007 | "N"); | |
9008 | json_object_int_add(json_route, "cost", | |
9009 | or->cost); | |
9010 | json_object_string_add( | |
9011 | json_route, "area", | |
9012 | inet_ntoa(or->u.std.area_id)); | |
9013 | } else { | |
9014 | vty_out(vty, "N %-18s [%d] area: %s\n", | |
9015 | buf1, or->cost, | |
9016 | inet_ntoa(or->u.std.area_id)); | |
9017 | } | |
9018 | break; | |
9019 | default: | |
9020 | break; | |
9021 | } | |
9022 | ||
9023 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
9024 | if (json) { | |
9025 | json_nexthop_array = json_object_new_array(); | |
9026 | json_object_object_add(json_route, "nexthops", | |
9027 | json_nexthop_array); | |
9028 | } | |
9029 | ||
9030 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, | |
9031 | path)) { | |
9032 | if (json) { | |
9033 | json_nexthop = json_object_new_object(); | |
9034 | json_object_array_add( | |
9035 | json_nexthop_array, | |
9036 | json_nexthop); | |
9037 | } | |
9038 | if (if_lookup_by_index(path->ifindex, | |
9039 | ospf->vrf_id)) { | |
9040 | ||
9041 | if (path->nexthop.s_addr == 0) { | |
9042 | if (json) { | |
9043 | json_object_string_add( | |
9044 | json_nexthop, | |
9045 | "ip", " "); | |
9046 | json_object_string_add( | |
9047 | json_nexthop, | |
9048 | "directly attached to", | |
9049 | ifindex2ifname( | |
9050 | path->ifindex, | |
9051 | ospf->vrf_id)); | |
9052 | } else { | |
9053 | vty_out(vty, | |
9054 | "%24s directly attached to %s\n", | |
9055 | "", | |
9056 | ifindex2ifname( | |
9057 | path->ifindex, | |
9058 | ospf->vrf_id)); | |
9059 | } | |
9060 | } else { | |
9061 | if (json) { | |
9062 | json_object_string_add( | |
9063 | json_nexthop, | |
9064 | "ip", | |
9065 | inet_ntoa( | |
9066 | path->nexthop)); | |
9067 | json_object_string_add( | |
9068 | json_nexthop, | |
9069 | "via", | |
9070 | ifindex2ifname( | |
9071 | path->ifindex, | |
9072 | ospf->vrf_id)); | |
9073 | } else { | |
9074 | vty_out(vty, | |
9075 | "%24s via %s, %s\n", | |
9076 | "", | |
9077 | inet_ntoa( | |
9078 | path->nexthop), | |
9079 | ifindex2ifname( | |
9080 | path->ifindex, | |
9081 | ospf->vrf_id)); | |
9082 | } | |
9083 | } | |
9084 | } | |
9085 | } | |
9086 | } | |
9087 | if (!json) | |
9088 | json_object_free(json_route); | |
9089 | } | |
9090 | if (!json) | |
9091 | vty_out(vty, "\n"); | |
9092 | } | |
9093 | ||
9094 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, | |
9095 | struct route_table *rtrs, | |
9096 | json_object *json) | |
9097 | { | |
9098 | struct route_node *rn; | |
9099 | struct ospf_route * or ; | |
9100 | struct listnode *pnode; | |
9101 | struct listnode *node; | |
9102 | struct ospf_path *path; | |
9103 | json_object *json_route = NULL, *json_nexthop_array = NULL, | |
9104 | *json_nexthop = NULL; | |
9105 | ||
9106 | if (!json) | |
9107 | vty_out(vty, | |
9108 | "============ OSPF router routing table =============\n"); | |
9109 | ||
9110 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { | |
9111 | if (rn->info == NULL) | |
9112 | continue; | |
9113 | int flag = 0; | |
9114 | ||
9115 | json_route = json_object_new_object(); | |
9116 | if (json) { | |
9117 | json_object_object_add(json, inet_ntoa(rn->p.u.prefix4), | |
9118 | json_route); | |
9119 | json_object_string_add(json_route, "routeType", "R "); | |
9120 | } else { | |
9121 | vty_out(vty, "R %-15s ", | |
9122 | inet_ntoa(rn->p.u.prefix4)); | |
9123 | } | |
9124 | ||
9125 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { | |
9126 | if (flag++) { | |
9127 | if (!json) | |
9128 | vty_out(vty, "%24s", ""); | |
9129 | } | |
9130 | ||
9131 | /* Show path. */ | |
9132 | if (json) { | |
9133 | json_object_int_add(json_route, "cost", | |
9134 | or->cost); | |
9135 | json_object_string_add( | |
9136 | json_route, "area", | |
9137 | inet_ntoa(or->u.std.area_id)); | |
9138 | if (or->path_type == OSPF_PATH_INTER_AREA) | |
9139 | json_object_boolean_true_add(json_route, | |
9140 | "IA"); | |
9141 | if (or->u.std.flags & ROUTER_LSA_BORDER) | |
9142 | json_object_string_add(json_route, | |
9143 | "routerType", | |
9144 | "abr"); | |
9145 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
9146 | json_object_string_add(json_route, | |
9147 | "routerType", | |
9148 | "asbr"); | |
9149 | } else { | |
9150 | vty_out(vty, "%s [%d] area: %s", | |
9151 | (or->path_type == OSPF_PATH_INTER_AREA | |
9152 | ? "IA" | |
9153 | : " "), | |
9154 | or->cost, inet_ntoa(or->u.std.area_id)); | |
9155 | /* Show flags. */ | |
9156 | vty_out(vty, "%s%s\n", | |
9157 | (or->u.std.flags & ROUTER_LSA_BORDER | |
9158 | ? ", ABR" | |
9159 | : ""), | |
9160 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
9161 | ? ", ASBR" | |
9162 | : "")); | |
9163 | } | |
9164 | ||
9165 | if (json) { | |
9166 | json_nexthop_array = json_object_new_array(); | |
9167 | json_object_object_add(json_route, "nexthops", | |
9168 | json_nexthop_array); | |
9169 | } | |
9170 | ||
9171 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { | |
9172 | if (json) { | |
9173 | json_nexthop = json_object_new_object(); | |
9174 | json_object_array_add( | |
9175 | json_nexthop_array, | |
9176 | json_nexthop); | |
9177 | } | |
9178 | if (if_lookup_by_index(path->ifindex, | |
9179 | ospf->vrf_id)) { | |
9180 | if (path->nexthop.s_addr == 0) { | |
9181 | if (json) { | |
9182 | json_object_string_add( | |
9183 | json_nexthop, | |
9184 | "ip", " "); | |
9185 | json_object_string_add( | |
9186 | json_nexthop, | |
9187 | "directly attached to", | |
9188 | ifindex2ifname( | |
9189 | path->ifindex, | |
9190 | ospf->vrf_id)); | |
9191 | } else { | |
9192 | vty_out(vty, | |
9193 | "%24s directly attached to %s\n", | |
9194 | "", | |
9195 | ifindex2ifname( | |
9196 | path->ifindex, | |
9197 | ospf->vrf_id)); | |
9198 | } | |
9199 | } else { | |
9200 | if (json) { | |
9201 | json_object_string_add( | |
9202 | json_nexthop, | |
9203 | "ip", | |
9204 | inet_ntoa( | |
9205 | path->nexthop)); | |
9206 | json_object_string_add( | |
9207 | json_nexthop, | |
9208 | "via", | |
9209 | ifindex2ifname( | |
9210 | path->ifindex, | |
9211 | ospf->vrf_id)); | |
9212 | } else { | |
9213 | vty_out(vty, | |
9214 | "%24s via %s, %s\n", | |
9215 | "", | |
9216 | inet_ntoa( | |
9217 | path->nexthop), | |
9218 | ifindex2ifname( | |
9219 | path->ifindex, | |
9220 | ospf->vrf_id)); | |
9221 | } | |
9222 | } | |
9223 | } | |
9224 | } | |
9225 | } | |
9226 | if (!json) | |
9227 | json_object_free(json_route); | |
9228 | } | |
9229 | if (!json) | |
9230 | vty_out(vty, "\n"); | |
9231 | } | |
9232 | ||
9233 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, | |
9234 | struct route_table *rt, | |
9235 | json_object *json) | |
9236 | { | |
9237 | struct route_node *rn; | |
9238 | struct ospf_route *er; | |
9239 | struct listnode *pnode, *pnnode; | |
9240 | struct ospf_path *path; | |
9241 | json_object *json_route = NULL, *json_nexthop_array = NULL, | |
9242 | *json_nexthop = NULL; | |
9243 | ||
9244 | if (!json) | |
9245 | vty_out(vty, | |
9246 | "============ OSPF external routing table ===========\n"); | |
9247 | ||
9248 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
9249 | if ((er = rn->info) == NULL) | |
9250 | continue; | |
9251 | ||
9252 | char buf1[19]; | |
9253 | ||
9254 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
9255 | rn->p.prefixlen); | |
9256 | json_route = json_object_new_object(); | |
9257 | if (json) { | |
9258 | json_object_object_add(json, buf1, json_route); | |
9259 | json_object_to_json_string_ext( | |
9260 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
9261 | } | |
9262 | ||
9263 | switch (er->path_type) { | |
9264 | case OSPF_PATH_TYPE1_EXTERNAL: | |
9265 | if (json) { | |
9266 | json_object_string_add(json_route, "routeType", | |
9267 | "N E1"); | |
9268 | json_object_int_add(json_route, "cost", | |
9269 | er->cost); | |
9270 | } else { | |
9271 | vty_out(vty, | |
9272 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI | |
9273 | "\n", | |
9274 | buf1, er->cost, er->u.ext.tag); | |
9275 | } | |
9276 | break; | |
9277 | case OSPF_PATH_TYPE2_EXTERNAL: | |
9278 | if (json) { | |
9279 | json_object_string_add(json_route, "routeType", | |
9280 | "N E2"); | |
9281 | json_object_int_add(json_route, "cost", | |
9282 | er->cost); | |
9283 | } else { | |
9284 | vty_out(vty, | |
9285 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI | |
9286 | "\n", | |
9287 | buf1, er->cost, er->u.ext.type2_cost, | |
9288 | er->u.ext.tag); | |
9289 | } | |
9290 | break; | |
9291 | } | |
9292 | ||
9293 | if (json) { | |
9294 | json_nexthop_array = json_object_new_array(); | |
9295 | json_object_object_add(json_route, "nexthops", | |
9296 | json_nexthop_array); | |
9297 | } | |
9298 | ||
9299 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { | |
9300 | if (json) { | |
9301 | json_nexthop = json_object_new_object(); | |
9302 | json_object_array_add(json_nexthop_array, | |
9303 | json_nexthop); | |
9304 | } | |
9305 | ||
9306 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { | |
9307 | if (path->nexthop.s_addr == 0) { | |
9308 | if (json) { | |
9309 | json_object_string_add( | |
9310 | json_nexthop, "ip", | |
9311 | " "); | |
9312 | json_object_string_add( | |
9313 | json_nexthop, | |
9314 | "directly attached to", | |
9315 | ifindex2ifname( | |
9316 | path->ifindex, | |
9317 | ospf->vrf_id)); | |
9318 | } else { | |
9319 | vty_out(vty, | |
9320 | "%24s directly attached to %s\n", | |
9321 | "", | |
9322 | ifindex2ifname( | |
9323 | path->ifindex, | |
9324 | ospf->vrf_id)); | |
9325 | } | |
9326 | } else { | |
9327 | if (json) { | |
9328 | json_object_string_add( | |
9329 | json_nexthop, "ip", | |
9330 | inet_ntoa( | |
9331 | path->nexthop)); | |
9332 | json_object_string_add( | |
9333 | json_nexthop, "via", | |
9334 | ifindex2ifname( | |
9335 | path->ifindex, | |
9336 | ospf->vrf_id)); | |
9337 | } else { | |
9338 | vty_out(vty, | |
9339 | "%24s via %s, %s\n", | |
9340 | "", | |
9341 | inet_ntoa( | |
9342 | path->nexthop), | |
9343 | ifindex2ifname( | |
9344 | path->ifindex, | |
9345 | ospf->vrf_id)); | |
9346 | } | |
9347 | } | |
9348 | } | |
9349 | } | |
9350 | if (!json) | |
9351 | json_object_free(json_route); | |
9352 | } | |
9353 | if (!json) | |
9354 | vty_out(vty, "\n"); | |
9355 | } | |
9356 | ||
9357 | static int show_ip_ospf_border_routers_common(struct vty *vty, | |
9358 | struct ospf *ospf, | |
9359 | uint8_t use_vrf) | |
9360 | { | |
9361 | if (ospf->instance) | |
9362 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
9363 | ||
9364 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); | |
9365 | ||
9366 | if (ospf->new_table == NULL) { | |
9367 | vty_out(vty, "No OSPF routing information exist\n"); | |
9368 | return CMD_SUCCESS; | |
9369 | } | |
9370 | ||
9371 | /* Show Network routes. | |
9372 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
9373 | ||
9374 | /* Show Router routes. */ | |
9375 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); | |
9376 | ||
9377 | vty_out(vty, "\n"); | |
9378 | ||
9379 | return CMD_SUCCESS; | |
9380 | } | |
9381 | ||
9382 | DEFUN (show_ip_ospf_border_routers, | |
9383 | show_ip_ospf_border_routers_cmd, | |
9384 | "show ip ospf [vrf <NAME|all>] border-routers", | |
9385 | SHOW_STR | |
9386 | IP_STR | |
9387 | "OSPF information\n" | |
9388 | VRF_CMD_HELP_STR | |
9389 | "All VRFs\n" | |
9390 | "Show all the ABR's and ASBR's\n") | |
9391 | { | |
9392 | struct ospf *ospf = NULL; | |
9393 | struct listnode *node = NULL; | |
9394 | char *vrf_name = NULL; | |
9395 | bool all_vrf = false; | |
9396 | int ret = CMD_SUCCESS; | |
9397 | int inst = 0; | |
9398 | int idx_vrf = 0; | |
9399 | uint8_t use_vrf = 0; | |
9400 | ||
9401 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
9402 | ||
9403 | if (vrf_name) { | |
9404 | bool ospf_output = false; | |
9405 | ||
9406 | use_vrf = 1; | |
9407 | ||
9408 | if (all_vrf) { | |
9409 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9410 | if (!ospf->oi_running) | |
9411 | continue; | |
9412 | ||
9413 | ospf_output = true; | |
9414 | ret = show_ip_ospf_border_routers_common( | |
9415 | vty, ospf, use_vrf); | |
9416 | } | |
9417 | ||
9418 | if (!ospf_output) | |
9419 | vty_out(vty, "%% OSPF instance not found\n"); | |
9420 | } else { | |
9421 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9422 | if (ospf == NULL || !ospf->oi_running) { | |
9423 | vty_out(vty, "%% OSPF instance not found\n"); | |
9424 | return CMD_SUCCESS; | |
9425 | } | |
9426 | ||
9427 | ret = show_ip_ospf_border_routers_common(vty, ospf, | |
9428 | use_vrf); | |
9429 | } | |
9430 | } else { | |
9431 | /* Display default ospf (instance 0) info */ | |
9432 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9433 | if (ospf == NULL || !ospf->oi_running) { | |
9434 | vty_out(vty, "%% OSPF instance not found\n"); | |
9435 | return CMD_SUCCESS; | |
9436 | } | |
9437 | ||
9438 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); | |
9439 | } | |
9440 | ||
9441 | return ret; | |
9442 | } | |
9443 | ||
9444 | DEFUN (show_ip_ospf_instance_border_routers, | |
9445 | show_ip_ospf_instance_border_routers_cmd, | |
9446 | "show ip ospf (1-65535) border-routers", | |
9447 | SHOW_STR | |
9448 | IP_STR | |
9449 | "OSPF information\n" | |
9450 | "Instance ID\n" | |
9451 | "Show all the ABR's and ASBR's\n") | |
9452 | { | |
9453 | int idx_number = 3; | |
9454 | struct ospf *ospf; | |
9455 | unsigned short instance = 0; | |
9456 | ||
9457 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
9458 | ospf = ospf_lookup_instance(instance); | |
9459 | if (ospf == NULL) | |
9460 | return CMD_NOT_MY_INSTANCE; | |
9461 | ||
9462 | if (!ospf->oi_running) | |
9463 | return CMD_SUCCESS; | |
9464 | ||
9465 | return show_ip_ospf_border_routers_common(vty, ospf, 0); | |
9466 | } | |
9467 | ||
9468 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, | |
9469 | json_object *json, uint8_t use_vrf) | |
9470 | { | |
9471 | json_object *json_vrf = NULL; | |
9472 | ||
9473 | if (ospf->instance) | |
9474 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
9475 | ||
9476 | ||
9477 | if (json) { | |
9478 | if (use_vrf) | |
9479 | json_vrf = json_object_new_object(); | |
9480 | else | |
9481 | json_vrf = json; | |
9482 | } | |
9483 | ||
9484 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
9485 | ||
9486 | if (ospf->new_table == NULL) { | |
9487 | vty_out(vty, "No OSPF routing information exist\n"); | |
9488 | return CMD_SUCCESS; | |
9489 | } | |
9490 | ||
9491 | /* Show Network routes. */ | |
9492 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); | |
9493 | ||
9494 | /* Show Router routes. */ | |
9495 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); | |
9496 | ||
9497 | /* Show AS External routes. */ | |
9498 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, | |
9499 | json_vrf); | |
9500 | ||
9501 | if (json) { | |
9502 | if (use_vrf) { | |
9503 | // json_object_object_add(json_vrf, "areas", | |
9504 | // json_areas); | |
9505 | if (ospf->vrf_id == VRF_DEFAULT) | |
9506 | json_object_object_add(json, "default", | |
9507 | json_vrf); | |
9508 | else | |
9509 | json_object_object_add(json, ospf->name, | |
9510 | json_vrf); | |
9511 | } | |
9512 | } else { | |
9513 | vty_out(vty, "\n"); | |
9514 | } | |
9515 | ||
9516 | return CMD_SUCCESS; | |
9517 | } | |
9518 | ||
9519 | DEFUN (show_ip_ospf_route, | |
9520 | show_ip_ospf_route_cmd, | |
9521 | "show ip ospf [vrf <NAME|all>] route [json]", | |
9522 | SHOW_STR | |
9523 | IP_STR | |
9524 | "OSPF information\n" | |
9525 | VRF_CMD_HELP_STR | |
9526 | "All VRFs\n" | |
9527 | "OSPF routing table\n" | |
9528 | JSON_STR) | |
9529 | { | |
9530 | struct ospf *ospf = NULL; | |
9531 | struct listnode *node = NULL; | |
9532 | char *vrf_name = NULL; | |
9533 | bool all_vrf = false; | |
9534 | int ret = CMD_SUCCESS; | |
9535 | int inst = 0; | |
9536 | int idx_vrf = 0; | |
9537 | uint8_t use_vrf = 0; | |
9538 | bool uj = use_json(argc, argv); | |
9539 | json_object *json = NULL; | |
9540 | ||
9541 | if (uj) | |
9542 | json = json_object_new_object(); | |
9543 | ||
9544 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
9545 | ||
9546 | /* vrf input is provided could be all or specific vrf*/ | |
9547 | if (vrf_name) { | |
9548 | bool ospf_output = false; | |
9549 | ||
9550 | use_vrf = 1; | |
9551 | ||
9552 | if (all_vrf) { | |
9553 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9554 | if (!ospf->oi_running) | |
9555 | continue; | |
9556 | ospf_output = true; | |
9557 | ret = show_ip_ospf_route_common(vty, ospf, json, | |
9558 | use_vrf); | |
9559 | } | |
9560 | ||
9561 | if (uj) { | |
9562 | /* Keep Non-pretty format */ | |
9563 | vty_out(vty, "%s\n", | |
9564 | json_object_to_json_string(json)); | |
9565 | json_object_free(json); | |
9566 | } else if (!ospf_output) | |
9567 | vty_out(vty, "%% OSPF instance not found\n"); | |
9568 | ||
9569 | return ret; | |
9570 | } | |
9571 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9572 | if (ospf == NULL || !ospf->oi_running) { | |
9573 | if (uj) { | |
9574 | vty_out(vty, "%s\n", | |
9575 | json_object_to_json_string_ext( | |
9576 | json, JSON_C_TO_STRING_PRETTY)); | |
9577 | json_object_free(json); | |
9578 | } else | |
9579 | vty_out(vty, "%% OSPF instance not found\n"); | |
9580 | ||
9581 | return CMD_SUCCESS; | |
9582 | } | |
9583 | } else { | |
9584 | /* Display default ospf (instance 0) info */ | |
9585 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9586 | if (ospf == NULL || !ospf->oi_running) { | |
9587 | if (uj) { | |
9588 | vty_out(vty, "%s\n", | |
9589 | json_object_to_json_string_ext( | |
9590 | json, JSON_C_TO_STRING_PRETTY)); | |
9591 | json_object_free(json); | |
9592 | } else | |
9593 | vty_out(vty, "%% OSPF instance not found\n"); | |
9594 | ||
9595 | return CMD_SUCCESS; | |
9596 | } | |
9597 | } | |
9598 | ||
9599 | if (ospf) { | |
9600 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
9601 | /* Keep Non-pretty format */ | |
9602 | if (uj) | |
9603 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
9604 | } | |
9605 | ||
9606 | if (uj) | |
9607 | json_object_free(json); | |
9608 | ||
9609 | return ret; | |
9610 | } | |
9611 | ||
9612 | DEFUN (show_ip_ospf_instance_route, | |
9613 | show_ip_ospf_instance_route_cmd, | |
9614 | "show ip ospf (1-65535) route", | |
9615 | SHOW_STR | |
9616 | IP_STR | |
9617 | "OSPF information\n" | |
9618 | "Instance ID\n" | |
9619 | "OSPF routing table\n") | |
9620 | { | |
9621 | int idx_number = 3; | |
9622 | struct ospf *ospf; | |
9623 | unsigned short instance = 0; | |
9624 | ||
9625 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
9626 | ospf = ospf_lookup_instance(instance); | |
9627 | if (ospf == NULL) | |
9628 | return CMD_NOT_MY_INSTANCE; | |
9629 | ||
9630 | if (!ospf->oi_running) | |
9631 | return CMD_SUCCESS; | |
9632 | ||
9633 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); | |
9634 | } | |
9635 | ||
9636 | ||
9637 | DEFUN (show_ip_ospf_vrfs, | |
9638 | show_ip_ospf_vrfs_cmd, | |
9639 | "show ip ospf vrfs [json]", | |
9640 | SHOW_STR | |
9641 | IP_STR | |
9642 | "OSPF information\n" | |
9643 | "Show OSPF VRFs \n" | |
9644 | JSON_STR) | |
9645 | { | |
9646 | bool uj = use_json(argc, argv); | |
9647 | json_object *json = NULL; | |
9648 | json_object *json_vrfs = NULL; | |
9649 | struct ospf *ospf = NULL; | |
9650 | struct listnode *node = NULL; | |
9651 | int count = 0; | |
9652 | static const char header[] = "Name Id RouterId "; | |
9653 | ||
9654 | if (uj) { | |
9655 | json = json_object_new_object(); | |
9656 | json_vrfs = json_object_new_object(); | |
9657 | } | |
9658 | ||
9659 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9660 | json_object *json_vrf = NULL; | |
9661 | const char *name = NULL; | |
9662 | int64_t vrf_id_ui = 0; | |
9663 | ||
9664 | count++; | |
9665 | ||
9666 | if (!uj && count == 1) | |
9667 | vty_out(vty, "%s\n", header); | |
9668 | if (uj) | |
9669 | json_vrf = json_object_new_object(); | |
9670 | ||
9671 | if (ospf->vrf_id == 0) | |
9672 | name = VRF_DEFAULT_NAME; | |
9673 | else | |
9674 | name = ospf->name; | |
9675 | ||
9676 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) | |
9677 | ? -1 | |
9678 | : (int64_t)ospf->vrf_id; | |
9679 | ||
9680 | if (uj) { | |
9681 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
9682 | json_object_string_add(json_vrf, "routerId", | |
9683 | inet_ntoa(ospf->router_id)); | |
9684 | ||
9685 | json_object_object_add(json_vrfs, name, json_vrf); | |
9686 | ||
9687 | } else { | |
9688 | vty_out(vty, "%-25s %-5d %-16s \n", name, | |
9689 | ospf->vrf_id, inet_ntoa(ospf->router_id)); | |
9690 | } | |
9691 | } | |
9692 | ||
9693 | if (uj) { | |
9694 | json_object_object_add(json, "vrfs", json_vrfs); | |
9695 | json_object_int_add(json, "totalVrfs", count); | |
9696 | ||
9697 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
9698 | json, JSON_C_TO_STRING_PRETTY)); | |
9699 | json_object_free(json); | |
9700 | } else { | |
9701 | if (count) | |
9702 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", | |
9703 | count); | |
9704 | } | |
9705 | ||
9706 | return CMD_SUCCESS; | |
9707 | } | |
9708 | ||
9709 | static const char *const ospf_abr_type_str[] = { | |
9710 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
9711 | }; | |
9712 | ||
9713 | static const char *const ospf_shortcut_mode_str[] = { | |
9714 | "default", "enable", "disable" | |
9715 | }; | |
9716 | ||
9717 | static const char *const ospf_int_type_str[] = { | |
9718 | "unknown", /* should never be used. */ | |
9719 | "point-to-point", | |
9720 | "broadcast", | |
9721 | "non-broadcast", | |
9722 | "point-to-multipoint", | |
9723 | "virtual-link", /* should never be used. */ | |
9724 | "loopback" | |
9725 | }; | |
9726 | ||
9727 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) | |
9728 | { | |
9729 | struct listnode *node; | |
9730 | struct interface *ifp; | |
9731 | struct crypt_key *ck; | |
9732 | struct route_node *rn = NULL; | |
9733 | struct ospf_if_params *params; | |
9734 | int write = 0; | |
9735 | struct ospf *ospf = vrf->info; | |
9736 | ||
9737 | FOR_ALL_INTERFACES (vrf, ifp) { | |
9738 | ||
9739 | if (memcmp(ifp->name, "VLINK", 5) == 0) | |
9740 | continue; | |
9741 | ||
9742 | vty_frame(vty, "!\n"); | |
9743 | if (ifp->vrf_id == VRF_DEFAULT) | |
9744 | vty_frame(vty, "interface %s\n", ifp->name); | |
9745 | else | |
9746 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, | |
9747 | vrf->name); | |
9748 | if (ifp->desc) | |
9749 | vty_out(vty, " description %s\n", ifp->desc); | |
9750 | ||
9751 | write++; | |
9752 | ||
9753 | params = IF_DEF_PARAMS(ifp); | |
9754 | ||
9755 | do { | |
9756 | /* Interface Network print. */ | |
9757 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
9758 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
9759 | if (params->type != ospf_default_iftype(ifp)) { | |
9760 | vty_out(vty, " ip ospf network %s", | |
9761 | ospf_int_type_str | |
9762 | [params->type]); | |
9763 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9764 | vty_out(vty, " %s", | |
9765 | inet_ntoa( | |
9766 | rn->p.u.prefix4)); | |
9767 | vty_out(vty, "\n"); | |
9768 | } | |
9769 | } | |
9770 | ||
9771 | /* OSPF interface authentication print */ | |
9772 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
9773 | && params->auth_type != OSPF_AUTH_NOTSET) { | |
9774 | const char *auth_str; | |
9775 | ||
9776 | /* Translation tables are not that much help | |
9777 | * here due to syntax | |
9778 | * of the simple option */ | |
9779 | switch (params->auth_type) { | |
9780 | ||
9781 | case OSPF_AUTH_NULL: | |
9782 | auth_str = " null"; | |
9783 | break; | |
9784 | ||
9785 | case OSPF_AUTH_SIMPLE: | |
9786 | auth_str = ""; | |
9787 | break; | |
9788 | ||
9789 | case OSPF_AUTH_CRYPTOGRAPHIC: | |
9790 | auth_str = " message-digest"; | |
9791 | break; | |
9792 | ||
9793 | default: | |
9794 | auth_str = ""; | |
9795 | break; | |
9796 | } | |
9797 | ||
9798 | vty_out(vty, " ip ospf authentication%s", | |
9799 | auth_str); | |
9800 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9801 | vty_out(vty, " %s", | |
9802 | inet_ntoa(rn->p.u.prefix4)); | |
9803 | vty_out(vty, "\n"); | |
9804 | } | |
9805 | ||
9806 | /* Simple Authentication Password print. */ | |
9807 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
9808 | && params->auth_simple[0] != '\0') { | |
9809 | vty_out(vty, " ip ospf authentication-key %s", | |
9810 | params->auth_simple); | |
9811 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9812 | vty_out(vty, " %s", | |
9813 | inet_ntoa(rn->p.u.prefix4)); | |
9814 | vty_out(vty, "\n"); | |
9815 | } | |
9816 | ||
9817 | /* Cryptographic Authentication Key print. */ | |
9818 | if (params && params->auth_crypt) { | |
9819 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, | |
9820 | node, ck)) { | |
9821 | vty_out(vty, | |
9822 | " ip ospf message-digest-key %d md5 %s", | |
9823 | ck->key_id, ck->auth_key); | |
9824 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9825 | vty_out(vty, " %s", | |
9826 | inet_ntoa( | |
9827 | rn->p.u.prefix4)); | |
9828 | vty_out(vty, "\n"); | |
9829 | } | |
9830 | } | |
9831 | ||
9832 | /* Interface Output Cost print. */ | |
9833 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { | |
9834 | vty_out(vty, " ip ospf cost %u", | |
9835 | params->output_cost_cmd); | |
9836 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9837 | vty_out(vty, " %s", | |
9838 | inet_ntoa(rn->p.u.prefix4)); | |
9839 | vty_out(vty, "\n"); | |
9840 | } | |
9841 | ||
9842 | /* Hello Interval print. */ | |
9843 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
9844 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { | |
9845 | vty_out(vty, " ip ospf hello-interval %u", | |
9846 | params->v_hello); | |
9847 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9848 | vty_out(vty, " %s", | |
9849 | inet_ntoa(rn->p.u.prefix4)); | |
9850 | vty_out(vty, "\n"); | |
9851 | } | |
9852 | ||
9853 | ||
9854 | /* Router Dead Interval print. */ | |
9855 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
9856 | && params->v_wait | |
9857 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
9858 | vty_out(vty, " ip ospf dead-interval "); | |
9859 | ||
9860 | /* fast hello ? */ | |
9861 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
9862 | fast_hello)) | |
9863 | vty_out(vty, | |
9864 | "minimal hello-multiplier %d", | |
9865 | params->fast_hello); | |
9866 | else | |
9867 | vty_out(vty, "%u", params->v_wait); | |
9868 | ||
9869 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9870 | vty_out(vty, " %s", | |
9871 | inet_ntoa(rn->p.u.prefix4)); | |
9872 | vty_out(vty, "\n"); | |
9873 | } | |
9874 | ||
9875 | /* Router Priority print. */ | |
9876 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
9877 | && params->priority | |
9878 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
9879 | vty_out(vty, " ip ospf priority %u", | |
9880 | params->priority); | |
9881 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9882 | vty_out(vty, " %s", | |
9883 | inet_ntoa(rn->p.u.prefix4)); | |
9884 | vty_out(vty, "\n"); | |
9885 | } | |
9886 | ||
9887 | /* Retransmit Interval print. */ | |
9888 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
9889 | retransmit_interval) | |
9890 | && params->retransmit_interval | |
9891 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
9892 | vty_out(vty, " ip ospf retransmit-interval %u", | |
9893 | params->retransmit_interval); | |
9894 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9895 | vty_out(vty, " %s", | |
9896 | inet_ntoa(rn->p.u.prefix4)); | |
9897 | vty_out(vty, "\n"); | |
9898 | } | |
9899 | ||
9900 | /* Transmit Delay print. */ | |
9901 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) | |
9902 | && params->transmit_delay | |
9903 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
9904 | vty_out(vty, " ip ospf transmit-delay %u", | |
9905 | params->transmit_delay); | |
9906 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9907 | vty_out(vty, " %s", | |
9908 | inet_ntoa(rn->p.u.prefix4)); | |
9909 | vty_out(vty, "\n"); | |
9910 | } | |
9911 | ||
9912 | /* Area print. */ | |
9913 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
9914 | if (ospf && ospf->instance) | |
9915 | vty_out(vty, " ip ospf %d", | |
9916 | ospf->instance); | |
9917 | else | |
9918 | vty_out(vty, " ip ospf"); | |
9919 | ||
9920 | char buf[INET_ADDRSTRLEN]; | |
9921 | ||
9922 | area_id2str(buf, sizeof(buf), ¶ms->if_area, | |
9923 | params->if_area_id_fmt); | |
9924 | vty_out(vty, " area %s", buf); | |
9925 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9926 | vty_out(vty, " %s", | |
9927 | inet_ntoa(rn->p.u.prefix4)); | |
9928 | vty_out(vty, "\n"); | |
9929 | } | |
9930 | ||
9931 | /* bfd print. */ | |
9932 | if (params && params->bfd_info) | |
9933 | ospf_bfd_write_config(vty, params); | |
9934 | ||
9935 | /* MTU ignore print. */ | |
9936 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
9937 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { | |
9938 | if (params->mtu_ignore == 0) | |
9939 | vty_out(vty, " no ip ospf mtu-ignore"); | |
9940 | else | |
9941 | vty_out(vty, " ip ospf mtu-ignore"); | |
9942 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
9943 | vty_out(vty, " %s", | |
9944 | inet_ntoa(rn->p.u.prefix4)); | |
9945 | vty_out(vty, "\n"); | |
9946 | } | |
9947 | ||
9948 | ||
9949 | while (1) { | |
9950 | if (rn == NULL) | |
9951 | rn = route_top(IF_OIFS_PARAMS(ifp)); | |
9952 | else | |
9953 | rn = route_next(rn); | |
9954 | ||
9955 | if (rn == NULL) | |
9956 | break; | |
9957 | params = rn->info; | |
9958 | if (params != NULL) | |
9959 | break; | |
9960 | } | |
9961 | } while (rn); | |
9962 | ||
9963 | ospf_opaque_config_write_if(vty, ifp); | |
9964 | ||
9965 | vty_endframe(vty, NULL); | |
9966 | } | |
9967 | ||
9968 | return write; | |
9969 | } | |
9970 | ||
9971 | /* Configuration write function for ospfd. */ | |
9972 | static int config_write_interface(struct vty *vty) | |
9973 | { | |
9974 | int write = 0; | |
9975 | struct vrf *vrf = NULL; | |
9976 | ||
9977 | /* Display all VRF aware OSPF interface configuration */ | |
9978 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
9979 | write += config_write_interface_one(vty, vrf); | |
9980 | } | |
9981 | ||
9982 | return write; | |
9983 | } | |
9984 | ||
9985 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) | |
9986 | { | |
9987 | struct route_node *rn; | |
9988 | uint8_t buf[INET_ADDRSTRLEN]; | |
9989 | ||
9990 | /* `network area' print. */ | |
9991 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
9992 | if (rn->info) { | |
9993 | struct ospf_network *n = rn->info; | |
9994 | ||
9995 | /* Create Area ID string by specified Area ID format. */ | |
9996 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
9997 | inet_ntop(AF_INET, &n->area_id, (char *)buf, | |
9998 | sizeof(buf)); | |
9999 | else | |
10000 | sprintf((char *)buf, "%lu", | |
10001 | (unsigned long int)ntohl( | |
10002 | n->area_id.s_addr)); | |
10003 | ||
10004 | /* Network print. */ | |
10005 | vty_out(vty, " network %s/%d area %s\n", | |
10006 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen, | |
10007 | buf); | |
10008 | } | |
10009 | ||
10010 | return 0; | |
10011 | } | |
10012 | ||
10013 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) | |
10014 | { | |
10015 | struct listnode *node; | |
10016 | struct ospf_area *area; | |
10017 | uint8_t buf[INET_ADDRSTRLEN]; | |
10018 | ||
10019 | /* Area configuration print. */ | |
10020 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
10021 | struct route_node *rn1; | |
10022 | ||
10023 | area_id2str((char *)buf, sizeof(buf), &area->area_id, | |
10024 | area->area_id_fmt); | |
10025 | ||
10026 | if (area->auth_type != OSPF_AUTH_NULL) { | |
10027 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
10028 | vty_out(vty, " area %s authentication\n", buf); | |
10029 | else | |
10030 | vty_out(vty, | |
10031 | " area %s authentication message-digest\n", | |
10032 | buf); | |
10033 | } | |
10034 | ||
10035 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) | |
10036 | vty_out(vty, " area %s shortcut %s\n", buf, | |
10037 | ospf_shortcut_mode_str | |
10038 | [area->shortcut_configured]); | |
10039 | ||
10040 | if ((area->external_routing == OSPF_AREA_STUB) | |
10041 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
10042 | if (area->external_routing == OSPF_AREA_STUB) { | |
10043 | vty_out(vty, " area %s stub", buf); | |
10044 | if (area->no_summary) | |
10045 | vty_out(vty, " no-summary\n"); | |
10046 | vty_out(vty, "\n"); | |
10047 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
10048 | switch (area->NSSATranslatorRole) { | |
10049 | case OSPF_NSSA_ROLE_NEVER: | |
10050 | vty_out(vty, | |
10051 | " area %s nssa translate-never\n", | |
10052 | buf); | |
10053 | break; | |
10054 | case OSPF_NSSA_ROLE_ALWAYS: | |
10055 | vty_out(vty, | |
10056 | " area %s nssa translate-always\n", | |
10057 | buf); | |
10058 | break; | |
10059 | case OSPF_NSSA_ROLE_CANDIDATE: | |
10060 | vty_out(vty, " area %s nssa \n", buf); | |
10061 | break; | |
10062 | } | |
10063 | if (area->no_summary) | |
10064 | vty_out(vty, | |
10065 | " area %s nssa no-summary\n", | |
10066 | buf); | |
10067 | } | |
10068 | ||
10069 | if (area->default_cost != 1) | |
10070 | vty_out(vty, " area %s default-cost %d\n", buf, | |
10071 | area->default_cost); | |
10072 | } | |
10073 | ||
10074 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) | |
10075 | if (rn1->info) { | |
10076 | struct ospf_area_range *range = rn1->info; | |
10077 | ||
10078 | vty_out(vty, " area %s range %s/%d", buf, | |
10079 | inet_ntoa(rn1->p.u.prefix4), | |
10080 | rn1->p.prefixlen); | |
10081 | ||
10082 | if (range->cost_config | |
10083 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
10084 | vty_out(vty, " cost %d", | |
10085 | range->cost_config); | |
10086 | ||
10087 | if (!CHECK_FLAG(range->flags, | |
10088 | OSPF_AREA_RANGE_ADVERTISE)) | |
10089 | vty_out(vty, " not-advertise"); | |
10090 | ||
10091 | if (CHECK_FLAG(range->flags, | |
10092 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
10093 | vty_out(vty, " substitute %s/%d", | |
10094 | inet_ntoa(range->subst_addr), | |
10095 | range->subst_masklen); | |
10096 | ||
10097 | vty_out(vty, "\n"); | |
10098 | } | |
10099 | ||
10100 | if (EXPORT_NAME(area)) | |
10101 | vty_out(vty, " area %s export-list %s\n", buf, | |
10102 | EXPORT_NAME(area)); | |
10103 | ||
10104 | if (IMPORT_NAME(area)) | |
10105 | vty_out(vty, " area %s import-list %s\n", buf, | |
10106 | IMPORT_NAME(area)); | |
10107 | ||
10108 | if (PREFIX_NAME_IN(area)) | |
10109 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
10110 | PREFIX_NAME_IN(area)); | |
10111 | ||
10112 | if (PREFIX_NAME_OUT(area)) | |
10113 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
10114 | buf, PREFIX_NAME_OUT(area)); | |
10115 | } | |
10116 | ||
10117 | return 0; | |
10118 | } | |
10119 | ||
10120 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) | |
10121 | { | |
10122 | struct ospf_nbr_nbma *nbr_nbma; | |
10123 | struct route_node *rn; | |
10124 | ||
10125 | /* Static Neighbor configuration print. */ | |
10126 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
10127 | if ((nbr_nbma = rn->info)) { | |
10128 | vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr)); | |
10129 | ||
10130 | if (nbr_nbma->priority | |
10131 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
10132 | vty_out(vty, " priority %d", | |
10133 | nbr_nbma->priority); | |
10134 | ||
10135 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) | |
10136 | vty_out(vty, " poll-interval %d", | |
10137 | nbr_nbma->v_poll); | |
10138 | ||
10139 | vty_out(vty, "\n"); | |
10140 | } | |
10141 | ||
10142 | return 0; | |
10143 | } | |
10144 | ||
10145 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
10146 | { | |
10147 | struct listnode *node; | |
10148 | struct ospf_vl_data *vl_data; | |
10149 | char buf[INET_ADDRSTRLEN]; | |
10150 | ||
10151 | /* Virtual-Link print */ | |
10152 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
10153 | struct listnode *n2; | |
10154 | struct crypt_key *ck; | |
10155 | struct ospf_interface *oi; | |
10156 | ||
10157 | if (vl_data != NULL) { | |
10158 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, | |
10159 | vl_data->vl_area_id_fmt); | |
10160 | oi = vl_data->vl_oi; | |
10161 | ||
10162 | /* timers */ | |
10163 | if (OSPF_IF_PARAM(oi, v_hello) | |
10164 | != OSPF_HELLO_INTERVAL_DEFAULT | |
10165 | || OSPF_IF_PARAM(oi, v_wait) | |
10166 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
10167 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
10168 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
10169 | || OSPF_IF_PARAM(oi, transmit_delay) | |
10170 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
10171 | vty_out(vty, | |
10172 | " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", | |
10173 | buf, inet_ntoa(vl_data->vl_peer), | |
10174 | OSPF_IF_PARAM(oi, v_hello), | |
10175 | OSPF_IF_PARAM(oi, retransmit_interval), | |
10176 | OSPF_IF_PARAM(oi, transmit_delay), | |
10177 | OSPF_IF_PARAM(oi, v_wait)); | |
10178 | else | |
10179 | vty_out(vty, " area %s virtual-link %s\n", buf, | |
10180 | inet_ntoa(vl_data->vl_peer)); | |
10181 | /* Auth key */ | |
10182 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
10183 | != '\0') | |
10184 | vty_out(vty, | |
10185 | " area %s virtual-link %s authentication-key %s\n", | |
10186 | buf, inet_ntoa(vl_data->vl_peer), | |
10187 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
10188 | ->auth_simple); | |
10189 | /* md5 keys */ | |
10190 | for (ALL_LIST_ELEMENTS_RO( | |
10191 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
10192 | ->auth_crypt, | |
10193 | n2, ck)) | |
10194 | vty_out(vty, | |
10195 | " area %s virtual-link %s" | |
10196 | " message-digest-key %d md5 %s\n", | |
10197 | buf, inet_ntoa(vl_data->vl_peer), | |
10198 | ck->key_id, ck->auth_key); | |
10199 | } | |
10200 | } | |
10201 | ||
10202 | return 0; | |
10203 | } | |
10204 | ||
10205 | ||
10206 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) | |
10207 | { | |
10208 | int type; | |
10209 | ||
10210 | /* redistribute print. */ | |
10211 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
10212 | struct list *red_list; | |
10213 | struct listnode *node; | |
10214 | struct ospf_redist *red; | |
10215 | ||
10216 | red_list = ospf->redist[type]; | |
10217 | if (!red_list) | |
10218 | continue; | |
10219 | ||
10220 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { | |
10221 | vty_out(vty, " redistribute %s", | |
10222 | zebra_route_string(type)); | |
10223 | if (red->instance) | |
10224 | vty_out(vty, " %d", red->instance); | |
10225 | ||
10226 | if (red->dmetric.value >= 0) | |
10227 | vty_out(vty, " metric %d", red->dmetric.value); | |
10228 | ||
10229 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) | |
10230 | vty_out(vty, " metric-type 1"); | |
10231 | ||
10232 | if (ROUTEMAP_NAME(red)) | |
10233 | vty_out(vty, " route-map %s", | |
10234 | ROUTEMAP_NAME(red)); | |
10235 | ||
10236 | vty_out(vty, "\n"); | |
10237 | } | |
10238 | } | |
10239 | ||
10240 | return 0; | |
10241 | } | |
10242 | ||
10243 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) | |
10244 | { | |
10245 | if (ospf->default_metric != -1) | |
10246 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
10247 | return 0; | |
10248 | } | |
10249 | ||
10250 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) | |
10251 | { | |
10252 | int type; | |
10253 | struct ospf_redist *red; | |
10254 | ||
10255 | if (ospf) { | |
10256 | /* distribute-list print. */ | |
10257 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
10258 | if (DISTRIBUTE_NAME(ospf, type)) | |
10259 | vty_out(vty, " distribute-list %s out %s\n", | |
10260 | DISTRIBUTE_NAME(ospf, type), | |
10261 | zebra_route_string(type)); | |
10262 | ||
10263 | /* default-information print. */ | |
10264 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
10265 | vty_out(vty, " default-information originate"); | |
10266 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
10267 | vty_out(vty, " always"); | |
10268 | ||
10269 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); | |
10270 | if (red) { | |
10271 | if (red->dmetric.value >= 0) | |
10272 | vty_out(vty, " metric %d", | |
10273 | red->dmetric.value); | |
10274 | ||
10275 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) | |
10276 | vty_out(vty, " metric-type 1"); | |
10277 | ||
10278 | if (ROUTEMAP_NAME(red)) | |
10279 | vty_out(vty, " route-map %s", | |
10280 | ROUTEMAP_NAME(red)); | |
10281 | } | |
10282 | ||
10283 | vty_out(vty, "\n"); | |
10284 | } | |
10285 | } | |
10286 | ||
10287 | return 0; | |
10288 | } | |
10289 | ||
10290 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) | |
10291 | { | |
10292 | struct route_node *rn; | |
10293 | struct ospf_distance *odistance; | |
10294 | ||
10295 | if (ospf->distance_all) | |
10296 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
10297 | ||
10298 | if (ospf->distance_intra || ospf->distance_inter | |
10299 | || ospf->distance_external) { | |
10300 | vty_out(vty, " distance ospf"); | |
10301 | ||
10302 | if (ospf->distance_intra) | |
10303 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
10304 | if (ospf->distance_inter) | |
10305 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
10306 | if (ospf->distance_external) | |
10307 | vty_out(vty, " external %d", ospf->distance_external); | |
10308 | ||
10309 | vty_out(vty, "\n"); | |
10310 | } | |
10311 | ||
10312 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
10313 | if ((odistance = rn->info) != NULL) { | |
10314 | vty_out(vty, " distance %d %s/%d %s\n", | |
10315 | odistance->distance, inet_ntoa(rn->p.u.prefix4), | |
10316 | rn->p.prefixlen, | |
10317 | odistance->access_list ? odistance->access_list | |
10318 | : ""); | |
10319 | } | |
10320 | return 0; | |
10321 | } | |
10322 | ||
10323 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) | |
10324 | { | |
10325 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); | |
10326 | struct interface *ifp; | |
10327 | struct ospf_interface *oi; | |
10328 | struct listnode *node = NULL; | |
10329 | int write = 0; | |
10330 | ||
10331 | /* `router ospf' print. */ | |
10332 | if (ospf->instance && ospf->name) { | |
10333 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, | |
10334 | ospf->name); | |
10335 | } else if (ospf->instance) { | |
10336 | vty_out(vty, "router ospf %d\n", ospf->instance); | |
10337 | } else if (ospf->name) { | |
10338 | vty_out(vty, "router ospf vrf %s\n", ospf->name); | |
10339 | } else | |
10340 | vty_out(vty, "router ospf\n"); | |
10341 | ||
10342 | if (!ospf->networks) { | |
10343 | write++; | |
10344 | return write; | |
10345 | } | |
10346 | ||
10347 | /* Router ID print. */ | |
10348 | if (ospf->router_id_static.s_addr != 0) | |
10349 | vty_out(vty, " ospf router-id %s\n", | |
10350 | inet_ntoa(ospf->router_id_static)); | |
10351 | ||
10352 | /* ABR type print. */ | |
10353 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
10354 | vty_out(vty, " ospf abr-type %s\n", | |
10355 | ospf_abr_type_str[ospf->abr_type]); | |
10356 | ||
10357 | /* log-adjacency-changes flag print. */ | |
10358 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
10359 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
10360 | vty_out(vty, " log-adjacency-changes detail\n"); | |
10361 | else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
10362 | vty_out(vty, " log-adjacency-changes\n"); | |
10363 | } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { | |
10364 | vty_out(vty, " no log-adjacency-changes\n"); | |
10365 | } | |
10366 | ||
10367 | /* RFC1583 compatibility flag print -- Compatible with CISCO | |
10368 | * 12.1. */ | |
10369 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
10370 | vty_out(vty, " compatible rfc1583\n"); | |
10371 | ||
10372 | /* auto-cost reference-bandwidth configuration. */ | |
10373 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
10374 | vty_out(vty, | |
10375 | "! Important: ensure reference bandwidth " | |
10376 | "is consistent across all routers\n"); | |
10377 | vty_out(vty, " auto-cost reference-bandwidth %d\n", | |
10378 | ospf->ref_bandwidth); | |
10379 | } | |
10380 | ||
10381 | /* SPF timers print. */ | |
10382 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
10383 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
10384 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
10385 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, | |
10386 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
10387 | ||
10388 | /* LSA timers print. */ | |
10389 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
10390 | vty_out(vty, " timers throttle lsa all %d\n", | |
10391 | ospf->min_ls_interval); | |
10392 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
10393 | vty_out(vty, " timers lsa min-arrival %d\n", | |
10394 | ospf->min_ls_arrival); | |
10395 | ||
10396 | /* Write multiplier print. */ | |
10397 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
10398 | vty_out(vty, " ospf write-multiplier %d\n", | |
10399 | ospf->write_oi_count); | |
10400 | ||
10401 | /* Max-metric router-lsa print */ | |
10402 | config_write_stub_router(vty, ospf); | |
10403 | ||
10404 | /* SPF refresh parameters print. */ | |
10405 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
10406 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
10407 | ||
10408 | /* Redistribute information print. */ | |
10409 | config_write_ospf_redistribute(vty, ospf); | |
10410 | ||
10411 | /* passive-interface print. */ | |
10412 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
10413 | vty_out(vty, " passive-interface default\n"); | |
10414 | ||
10415 | FOR_ALL_INTERFACES (vrf, ifp) | |
10416 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
10417 | passive_interface) | |
10418 | && IF_DEF_PARAMS(ifp)->passive_interface | |
10419 | != ospf->passive_interface_default) { | |
10420 | vty_out(vty, " %spassive-interface %s\n", | |
10421 | IF_DEF_PARAMS(ifp)->passive_interface ? "" | |
10422 | : "no ", | |
10423 | ifp->name); | |
10424 | } | |
10425 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
10426 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
10427 | continue; | |
10428 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
10429 | passive_interface)) { | |
10430 | if (oi->params->passive_interface | |
10431 | == IF_DEF_PARAMS(oi->ifp)->passive_interface) | |
10432 | continue; | |
10433 | } else if (oi->params->passive_interface | |
10434 | == ospf->passive_interface_default) | |
10435 | continue; | |
10436 | ||
10437 | vty_out(vty, " %spassive-interface %s %s\n", | |
10438 | oi->params->passive_interface ? "" : "no ", | |
10439 | oi->ifp->name, inet_ntoa(oi->address->u.prefix4)); | |
10440 | } | |
10441 | ||
10442 | /* Network area print. */ | |
10443 | config_write_network_area(vty, ospf); | |
10444 | ||
10445 | /* Area config print. */ | |
10446 | config_write_ospf_area(vty, ospf); | |
10447 | ||
10448 | /* static neighbor print. */ | |
10449 | config_write_ospf_nbr_nbma(vty, ospf); | |
10450 | ||
10451 | /* Virtual-Link print. */ | |
10452 | config_write_virtual_link(vty, ospf); | |
10453 | ||
10454 | /* Default metric configuration. */ | |
10455 | config_write_ospf_default_metric(vty, ospf); | |
10456 | ||
10457 | /* Distribute-list and default-information print. */ | |
10458 | config_write_ospf_distribute(vty, ospf); | |
10459 | ||
10460 | /* Distance configuration. */ | |
10461 | config_write_ospf_distance(vty, ospf); | |
10462 | ||
10463 | ospf_opaque_config_write_router(vty, ospf); | |
10464 | ||
10465 | write++; | |
10466 | return write; | |
10467 | } | |
10468 | ||
10469 | /* OSPF configuration write function. */ | |
10470 | static int ospf_config_write(struct vty *vty) | |
10471 | { | |
10472 | struct ospf *ospf; | |
10473 | struct listnode *ospf_node = NULL; | |
10474 | int write = 0; | |
10475 | ||
10476 | if (listcount(om->ospf) == 0) | |
10477 | return write; | |
10478 | ||
10479 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
10480 | /* VRF Default check if it is running. | |
10481 | * Upon daemon start, there could be default instance | |
10482 | * in absence of 'router ospf'/oi_running is disabled. */ | |
10483 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
10484 | write += ospf_config_write_one(vty, ospf); | |
10485 | /* For Non-Default VRF simply display the configuration, | |
10486 | * even if it is not oi_running. */ | |
10487 | else if (ospf->vrf_id != VRF_DEFAULT) | |
10488 | write += ospf_config_write_one(vty, ospf); | |
10489 | } | |
10490 | return write; | |
10491 | } | |
10492 | ||
10493 | void ospf_vty_show_init(void) | |
10494 | { | |
10495 | /* "show ip ospf" commands. */ | |
10496 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
10497 | ||
10498 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
10499 | ||
10500 | /* "show ip ospf database" commands. */ | |
10501 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
10502 | ||
10503 | install_element(VIEW_NODE, | |
10504 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
10505 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
10506 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
10507 | ||
10508 | /* "show ip ospf interface" commands. */ | |
10509 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
10510 | ||
10511 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
10512 | /* "show ip ospf interface traffic */ | |
10513 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
10514 | ||
10515 | /* "show ip ospf neighbor" commands. */ | |
10516 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
10517 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
10518 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
10519 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
10520 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
10521 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
10522 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
10523 | ||
10524 | install_element(VIEW_NODE, | |
10525 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
10526 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
10527 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
10528 | install_element(VIEW_NODE, | |
10529 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
10530 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
10531 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
10532 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
10533 | ||
10534 | /* "show ip ospf route" commands. */ | |
10535 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
10536 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
10537 | ||
10538 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
10539 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
10540 | ||
10541 | /* "show ip ospf vrfs" commands. */ | |
10542 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
10543 | } | |
10544 | ||
10545 | ||
10546 | /* ospfd's interface node. */ | |
10547 | static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1}; | |
10548 | ||
10549 | /* Initialization of OSPF interface. */ | |
10550 | static void ospf_vty_if_init(void) | |
10551 | { | |
10552 | /* Install interface node. */ | |
10553 | install_node(&interface_node, config_write_interface); | |
10554 | if_cmd_init(); | |
10555 | ||
10556 | /* "ip ospf authentication" commands. */ | |
10557 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
10558 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
10559 | install_element(INTERFACE_NODE, | |
10560 | &no_ip_ospf_authentication_args_addr_cmd); | |
10561 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
10562 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
10563 | install_element(INTERFACE_NODE, | |
10564 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
10565 | install_element(INTERFACE_NODE, | |
10566 | &no_ospf_authentication_key_authkey_addr_cmd); | |
10567 | ||
10568 | /* "ip ospf message-digest-key" commands. */ | |
10569 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
10570 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
10571 | ||
10572 | /* "ip ospf cost" commands. */ | |
10573 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
10574 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
10575 | ||
10576 | /* "ip ospf mtu-ignore" commands. */ | |
10577 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
10578 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
10579 | ||
10580 | /* "ip ospf dead-interval" commands. */ | |
10581 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
10582 | install_element(INTERFACE_NODE, | |
10583 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
10584 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
10585 | ||
10586 | /* "ip ospf hello-interval" commands. */ | |
10587 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
10588 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
10589 | ||
10590 | /* "ip ospf network" commands. */ | |
10591 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
10592 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
10593 | ||
10594 | /* "ip ospf priority" commands. */ | |
10595 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
10596 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
10597 | ||
10598 | /* "ip ospf retransmit-interval" commands. */ | |
10599 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
10600 | install_element(INTERFACE_NODE, | |
10601 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
10602 | ||
10603 | /* "ip ospf transmit-delay" commands. */ | |
10604 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
10605 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
10606 | ||
10607 | /* "ip ospf area" commands. */ | |
10608 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
10609 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
10610 | ||
10611 | /* These commands are compatibitliy for previous version. */ | |
10612 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
10613 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
10614 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
10615 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
10616 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
10617 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
10618 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
10619 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
10620 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
10621 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
10622 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
10623 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
10624 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
10625 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
10626 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
10627 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
10628 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
10629 | } | |
10630 | ||
10631 | static void ospf_vty_zebra_init(void) | |
10632 | { | |
10633 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
10634 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
10635 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
10636 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
10637 | ||
10638 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
10639 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
10640 | ||
10641 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
10642 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
10643 | ||
10644 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
10645 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
10646 | ||
10647 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
10648 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
10649 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
10650 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
10651 | #if 0 | |
10652 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
10653 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
10654 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
10655 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
10656 | #endif /* 0 */ | |
10657 | } | |
10658 | ||
10659 | static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1}; | |
10660 | ||
10661 | static void ospf_interface_clear(struct interface *ifp) | |
10662 | { | |
10663 | if (!if_is_operative(ifp)) | |
10664 | return; | |
10665 | ||
10666 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) | |
10667 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
10668 | ||
10669 | ospf_if_reset(ifp); | |
10670 | } | |
10671 | ||
10672 | DEFUN (clear_ip_ospf_interface, | |
10673 | clear_ip_ospf_interface_cmd, | |
10674 | "clear ip ospf [vrf NAME] interface [IFNAME]", | |
10675 | CLEAR_STR | |
10676 | IP_STR | |
10677 | "OSPF information\n" | |
10678 | VRF_CMD_HELP_STR | |
10679 | "Interface information\n" | |
10680 | "Interface name\n") | |
10681 | { | |
10682 | int idx_ifname = 0; | |
10683 | int idx_vrf = 0; | |
10684 | struct interface *ifp; | |
10685 | struct listnode *node; | |
10686 | struct ospf *ospf = NULL; | |
10687 | char *vrf_name = NULL; | |
10688 | vrf_id_t vrf_id = VRF_DEFAULT; | |
10689 | struct vrf *vrf = NULL; | |
10690 | ||
10691 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
10692 | vrf_name = argv[idx_vrf + 1]->arg; | |
10693 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
10694 | vrf_name = NULL; | |
10695 | if (vrf_name) { | |
10696 | vrf = vrf_lookup_by_name(vrf_name); | |
10697 | if (vrf) | |
10698 | vrf_id = vrf->vrf_id; | |
10699 | } | |
10700 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
10701 | /* Clear all the ospfv2 interfaces. */ | |
10702 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10703 | if (vrf_id != ospf->vrf_id) | |
10704 | continue; | |
10705 | if (!vrf) | |
10706 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
10707 | FOR_ALL_INTERFACES (vrf, ifp) | |
10708 | ospf_interface_clear(ifp); | |
10709 | } | |
10710 | } else { | |
10711 | /* Interface name is specified. */ | |
10712 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); | |
10713 | if (ifp == NULL) | |
10714 | vty_out(vty, "No such interface name\n"); | |
10715 | else | |
10716 | ospf_interface_clear(ifp); | |
10717 | } | |
10718 | ||
10719 | return CMD_SUCCESS; | |
10720 | } | |
10721 | ||
10722 | void ospf_vty_clear_init(void) | |
10723 | { | |
10724 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); | |
10725 | } | |
10726 | ||
10727 | ||
10728 | /* Install OSPF related vty commands. */ | |
10729 | void ospf_vty_init(void) | |
10730 | { | |
10731 | /* Install ospf top node. */ | |
10732 | install_node(&ospf_node, ospf_config_write); | |
10733 | ||
10734 | /* "router ospf" commands. */ | |
10735 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
10736 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
10737 | ||
10738 | ||
10739 | install_default(OSPF_NODE); | |
10740 | ||
10741 | /* "ospf router-id" commands. */ | |
10742 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
10743 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
10744 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
10745 | ||
10746 | /* "passive-interface" commands. */ | |
10747 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
10748 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
10749 | ||
10750 | /* "ospf abr-type" commands. */ | |
10751 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
10752 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
10753 | ||
10754 | /* "ospf log-adjacency-changes" commands. */ | |
10755 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
10756 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
10757 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
10758 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
10759 | ||
10760 | /* "ospf rfc1583-compatible" commands. */ | |
10761 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
10762 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
10763 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
10764 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
10765 | ||
10766 | /* "network area" commands. */ | |
10767 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
10768 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
10769 | ||
10770 | /* "area authentication" commands. */ | |
10771 | install_element(OSPF_NODE, | |
10772 | &ospf_area_authentication_message_digest_cmd); | |
10773 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
10774 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
10775 | ||
10776 | /* "area range" commands. */ | |
10777 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
10778 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
10779 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
10780 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
10781 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
10782 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
10783 | ||
10784 | /* "area virtual-link" commands. */ | |
10785 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
10786 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
10787 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
10788 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
10789 | ||
10790 | ||
10791 | /* "area stub" commands. */ | |
10792 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
10793 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
10794 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
10795 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
10796 | ||
10797 | /* "area nssa" commands. */ | |
10798 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
10799 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); | |
10800 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
10801 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); | |
10802 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); | |
10803 | ||
10804 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
10805 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
10806 | ||
10807 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
10808 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
10809 | ||
10810 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
10811 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
10812 | ||
10813 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
10814 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
10815 | ||
10816 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
10817 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
10818 | ||
10819 | /* SPF timer commands */ | |
10820 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
10821 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
10822 | ||
10823 | /* LSA timers commands */ | |
10824 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
10825 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
10826 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); | |
10827 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
10828 | ||
10829 | /* refresh timer commands */ | |
10830 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
10831 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
10832 | ||
10833 | /* max-metric commands */ | |
10834 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
10835 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
10836 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
10837 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
10838 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
10839 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
10840 | ||
10841 | /* reference bandwidth commands */ | |
10842 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
10843 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
10844 | ||
10845 | /* "neighbor" commands. */ | |
10846 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
10847 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
10848 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
10849 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
10850 | ||
10851 | /* write multiplier commands */ | |
10852 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
10853 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
10854 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
10855 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
10856 | ||
10857 | /* Init interface related vty commands. */ | |
10858 | ospf_vty_if_init(); | |
10859 | ||
10860 | /* Init zebra related vty commands. */ | |
10861 | ospf_vty_zebra_init(); | |
10862 | } |