]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
508e53e2 | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
718e3744 | 3 | * |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 19 | */ |
20 | ||
508e53e2 | 21 | #include <zebra.h> |
22 | ||
23 | #include "log.h" | |
24 | #include "memory.h" | |
25 | #include "prefix.h" | |
26 | #include "table.h" | |
27 | #include "vty.h" | |
28 | #include "command.h" | |
cf1ce250 | 29 | #include "linklist.h" |
508e53e2 | 30 | |
508e53e2 | 31 | #include "ospf6_proto.h" |
32 | #include "ospf6_lsa.h" | |
049207c3 | 33 | #include "ospf6_lsdb.h" |
508e53e2 | 34 | #include "ospf6_route.h" |
cf1ce250 PJ |
35 | #include "ospf6_top.h" |
36 | #include "ospf6_area.h" | |
37 | #include "ospf6_interface.h" | |
049207c3 | 38 | #include "ospf6d.h" |
c3c0ac83 | 39 | #include "ospf6_zebra.h" |
718e3744 | 40 | |
508e53e2 | 41 | unsigned char conf_debug_ospf6_route = 0; |
718e3744 | 42 | |
cf1ce250 PJ |
43 | static char * |
44 | ospf6_route_table_name (struct ospf6_route_table *table) | |
45 | { | |
46 | static char name[32]; | |
47 | switch (table->scope_type) | |
48 | { | |
49 | case OSPF6_SCOPE_TYPE_GLOBAL: | |
50 | { | |
51 | switch (table->table_type) | |
52 | { | |
53 | case OSPF6_TABLE_TYPE_ROUTES: | |
54 | snprintf (name, sizeof (name), "global route table"); | |
55 | break; | |
56 | case OSPF6_TABLE_TYPE_BORDER_ROUTERS: | |
57 | snprintf (name, sizeof (name), "global brouter table"); | |
58 | break; | |
59 | case OSPF6_TABLE_TYPE_EXTERNAL_ROUTES: | |
60 | snprintf (name, sizeof (name), "global external table"); | |
61 | break; | |
62 | default: | |
63 | snprintf (name, sizeof (name), "global unknown table"); | |
64 | break; | |
65 | } | |
66 | } | |
67 | break; | |
68 | ||
69 | case OSPF6_SCOPE_TYPE_AREA: | |
70 | { | |
71 | struct ospf6_area *oa = (struct ospf6_area *) table->scope; | |
72 | switch (table->table_type) | |
73 | { | |
74 | case OSPF6_TABLE_TYPE_SPF_RESULTS: | |
75 | snprintf (name, sizeof (name), | |
76 | "area %s spf table", oa->name); | |
77 | break; | |
78 | case OSPF6_TABLE_TYPE_ROUTES: | |
79 | snprintf (name, sizeof (name), | |
80 | "area %s route table", oa->name); | |
81 | break; | |
82 | case OSPF6_TABLE_TYPE_PREFIX_RANGES: | |
83 | snprintf (name, sizeof (name), | |
84 | "area %s range table", oa->name); | |
85 | break; | |
86 | case OSPF6_TABLE_TYPE_SUMMARY_PREFIXES: | |
87 | snprintf (name, sizeof (name), | |
88 | "area %s summary prefix table", oa->name); | |
89 | break; | |
90 | case OSPF6_TABLE_TYPE_SUMMARY_ROUTERS: | |
91 | snprintf (name, sizeof (name), | |
92 | "area %s summary router table", oa->name); | |
93 | break; | |
94 | default: | |
95 | snprintf (name, sizeof (name), | |
96 | "area %s unknown table", oa->name); | |
97 | break; | |
98 | } | |
99 | } | |
100 | break; | |
101 | ||
102 | case OSPF6_SCOPE_TYPE_INTERFACE: | |
103 | { | |
104 | struct ospf6_interface *oi = (struct ospf6_interface *) table->scope; | |
105 | switch (table->table_type) | |
106 | { | |
107 | case OSPF6_TABLE_TYPE_CONNECTED_ROUTES: | |
108 | snprintf (name, sizeof (name), "interface %s connected table", | |
109 | oi->interface->name); | |
110 | break; | |
111 | default: | |
112 | snprintf (name, sizeof (name), "interface %s unknown table", | |
113 | oi->interface->name); | |
114 | break; | |
115 | } | |
116 | } | |
117 | break; | |
118 | ||
119 | default: | |
120 | { | |
121 | switch (table->table_type) | |
122 | { | |
123 | case OSPF6_TABLE_TYPE_SPF_RESULTS: | |
124 | snprintf (name, sizeof (name), "temporary spf table"); | |
125 | break; | |
126 | default: | |
127 | snprintf (name, sizeof (name), "temporary unknown table"); | |
128 | break; | |
129 | } | |
130 | } | |
131 | break; | |
132 | } | |
133 | return name; | |
134 | } | |
135 | ||
508e53e2 | 136 | void |
137 | ospf6_linkstate_prefix (u_int32_t adv_router, u_int32_t id, | |
138 | struct prefix *prefix) | |
139 | { | |
140 | memset (prefix, 0, sizeof (struct prefix)); | |
141 | prefix->family = AF_INET6; | |
142 | prefix->prefixlen = 64; | |
143 | memcpy (&prefix->u.prefix6.s6_addr[0], &adv_router, 4); | |
144 | memcpy (&prefix->u.prefix6.s6_addr[4], &id, 4); | |
145 | } | |
718e3744 | 146 | |
508e53e2 | 147 | void |
148 | ospf6_linkstate_prefix2str (struct prefix *prefix, char *buf, int size) | |
718e3744 | 149 | { |
508e53e2 | 150 | u_int32_t adv_router, id; |
4846ef64 | 151 | char adv_router_str[16], id_str[16]; |
508e53e2 | 152 | memcpy (&adv_router, &prefix->u.prefix6.s6_addr[0], 4); |
153 | memcpy (&id, &prefix->u.prefix6.s6_addr[4], 4); | |
154 | inet_ntop (AF_INET, &adv_router, adv_router_str, sizeof (adv_router_str)); | |
4846ef64 | 155 | inet_ntop (AF_INET, &id, id_str, sizeof (id_str)); |
156 | if (ntohl (id)) | |
157 | snprintf (buf, size, "%s Net-ID: %s", adv_router_str, id_str); | |
158 | else | |
159 | snprintf (buf, size, "%s", adv_router_str); | |
508e53e2 | 160 | } |
718e3744 | 161 | |
508e53e2 | 162 | /* Global strings for logging */ |
0c083ee9 | 163 | const char *ospf6_dest_type_str[OSPF6_DEST_TYPE_MAX] = |
4846ef64 | 164 | { "Unknown", "Router", "Network", "Discard", "Linkstate", "AddressRange", }; |
718e3744 | 165 | |
0c083ee9 | 166 | const char *ospf6_dest_type_substr[OSPF6_DEST_TYPE_MAX] = |
4846ef64 | 167 | { "?", "R", "N", "D", "L", "A", }; |
718e3744 | 168 | |
0c083ee9 | 169 | const char *ospf6_path_type_str[OSPF6_PATH_TYPE_MAX] = |
508e53e2 | 170 | { "Unknown", "Intra-Area", "Inter-Area", "External-1", "External-2", }; |
718e3744 | 171 | |
0c083ee9 | 172 | const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX] = |
4846ef64 | 173 | { "??", "IA", "IE", "E1", "E2", }; |
718e3744 | 174 | |
718e3744 | 175 | |
c3c0ac83 DS |
176 | struct ospf6_nexthop * |
177 | ospf6_nexthop_create (void) | |
178 | { | |
179 | struct ospf6_nexthop *nh; | |
180 | ||
181 | nh = XCALLOC (MTYPE_OSPF6_NEXTHOP, sizeof (struct ospf6_nexthop)); | |
182 | return nh; | |
183 | } | |
184 | ||
185 | void | |
186 | ospf6_nexthop_delete (struct ospf6_nexthop *nh) | |
187 | { | |
188 | if (nh) | |
189 | XFREE (MTYPE_OSPF6_NEXTHOP, nh); | |
190 | } | |
191 | ||
192 | void | |
193 | ospf6_free_nexthops (struct list *nh_list) | |
194 | { | |
195 | struct ospf6_nexthop *nh; | |
196 | struct listnode *node, *nnode; | |
197 | ||
198 | if (nh_list) | |
199 | { | |
200 | for (ALL_LIST_ELEMENTS (nh_list, node, nnode, nh)) | |
201 | ospf6_nexthop_delete (nh); | |
202 | } | |
203 | } | |
204 | ||
205 | void | |
206 | ospf6_clear_nexthops (struct list *nh_list) | |
207 | { | |
208 | struct listnode *node; | |
209 | struct ospf6_nexthop *nh; | |
210 | ||
211 | if (nh_list) | |
212 | { | |
213 | for (ALL_LIST_ELEMENTS_RO (nh_list, node, nh)) | |
214 | ospf6_nexthop_clear (nh); | |
215 | } | |
216 | } | |
217 | ||
218 | static struct ospf6_nexthop * | |
219 | ospf6_route_find_nexthop (struct list *nh_list, struct ospf6_nexthop *nh_match) | |
220 | { | |
221 | struct listnode *node; | |
222 | struct ospf6_nexthop *nh; | |
223 | ||
224 | if (nh_list && nh_match) | |
225 | { | |
226 | for (ALL_LIST_ELEMENTS_RO (nh_list, node, nh)) | |
227 | { | |
228 | if (ospf6_nexthop_is_same (nh, nh_match)) | |
229 | return (nh); | |
230 | } | |
231 | } | |
232 | ||
233 | return (NULL); | |
234 | } | |
235 | ||
236 | void | |
237 | ospf6_copy_nexthops (struct list *dst, struct list *src) | |
238 | { | |
239 | struct ospf6_nexthop *nh_new, *nh; | |
240 | struct listnode *node; | |
241 | ||
242 | if (dst && src) | |
243 | { | |
244 | for (ALL_LIST_ELEMENTS_RO (src, node, nh)) | |
245 | { | |
246 | if (ospf6_nexthop_is_set (nh)) | |
247 | { | |
248 | nh_new = ospf6_nexthop_create (); | |
249 | ospf6_nexthop_copy (nh_new, nh); | |
250 | listnode_add (dst, nh_new); | |
251 | } | |
252 | } | |
253 | } | |
254 | } | |
255 | ||
256 | void | |
257 | ospf6_merge_nexthops (struct list *dst, struct list *src) | |
258 | { | |
259 | struct listnode *node; | |
260 | struct ospf6_nexthop *nh, *nh_new; | |
261 | ||
262 | if (src && dst) | |
263 | { | |
264 | for (ALL_LIST_ELEMENTS_RO (src, node, nh)) | |
265 | { | |
266 | if (!ospf6_route_find_nexthop (dst, nh)) | |
267 | { | |
268 | nh_new = ospf6_nexthop_create (); | |
269 | ospf6_nexthop_copy (nh_new, nh); | |
270 | listnode_add (dst, nh_new); | |
271 | } | |
272 | } | |
273 | } | |
274 | } | |
275 | ||
276 | int | |
277 | ospf6_route_cmp_nexthops (struct ospf6_route *a, struct ospf6_route *b) | |
278 | { | |
279 | struct listnode *anode, *bnode; | |
280 | struct ospf6_nexthop *anh, *bnh; | |
281 | ||
282 | if (a && b) | |
283 | { | |
284 | if (listcount(a->nh_list) == listcount(b->nh_list)) | |
285 | { | |
286 | for (ALL_LIST_ELEMENTS_RO (a->nh_list, anode, anh)) | |
287 | { | |
288 | for (ALL_LIST_ELEMENTS_RO (b->nh_list, bnode, bnh)) | |
289 | if (!ospf6_nexthop_is_same (anh, bnh)) | |
290 | return (1); | |
291 | } | |
292 | return (0); | |
293 | } | |
294 | else | |
295 | return (1); | |
296 | } | |
297 | /* One of the routes doesn't exist ? */ | |
298 | return (1); | |
299 | } | |
300 | ||
301 | int | |
302 | ospf6_num_nexthops (struct list *nh_list) | |
303 | { | |
304 | return (listcount(nh_list)); | |
305 | } | |
306 | ||
307 | void | |
308 | ospf6_add_nexthop (struct list *nh_list, int ifindex, | |
309 | struct in6_addr *addr) | |
310 | { | |
311 | struct ospf6_nexthop *nh; | |
312 | struct ospf6_nexthop nh_match; | |
313 | ||
314 | if (nh_list) | |
315 | { | |
316 | nh_match.ifindex = ifindex; | |
317 | if (addr != NULL) | |
318 | memcpy (&nh_match.address, addr, sizeof (struct in6_addr)); | |
319 | else | |
320 | memset (&nh_match.address, 0, sizeof (struct in6_addr)); | |
321 | ||
322 | if (!ospf6_route_find_nexthop (nh_list, &nh_match)) | |
323 | { | |
324 | nh = ospf6_nexthop_create(); | |
325 | ospf6_nexthop_copy (nh, &nh_match); | |
326 | listnode_add (nh_list, nh); | |
327 | } | |
328 | } | |
329 | } | |
330 | ||
331 | void | |
332 | ospf6_route_zebra_copy_nexthops (struct ospf6_route *route, | |
b892f1dd | 333 | ifindex_t *ifindexes, |
c3c0ac83 DS |
334 | struct in6_addr **nexthop_addr, |
335 | int entries) | |
336 | { | |
337 | struct ospf6_nexthop *nh; | |
338 | struct listnode *node; | |
339 | char buf[64]; | |
340 | int i; | |
341 | ||
342 | if (route) | |
343 | { | |
344 | i = 0; | |
345 | for (ALL_LIST_ELEMENTS_RO (route->nh_list, node, nh)) | |
346 | { | |
347 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) | |
348 | { | |
322e5964 | 349 | const char *ifname; |
c3c0ac83 | 350 | inet_ntop (AF_INET6, &nh->address, buf, sizeof (buf)); |
baaea325 | 351 | ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT); |
c3c0ac83 DS |
352 | zlog_debug (" nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname, |
353 | nh->ifindex); | |
354 | } | |
355 | if (i < entries) | |
356 | { | |
357 | nexthop_addr[i] = &nh->address; | |
358 | ifindexes[i] = nh->ifindex; | |
359 | i++; | |
360 | } | |
361 | else | |
362 | { | |
363 | return; | |
364 | } | |
365 | } | |
366 | } | |
367 | } | |
368 | ||
369 | int | |
370 | ospf6_route_get_first_nh_index (struct ospf6_route *route) | |
371 | { | |
372 | struct ospf6_nexthop *nh; | |
373 | ||
374 | if (route) | |
375 | { | |
ed2eb093 | 376 | if ((nh = (struct ospf6_nexthop *)listhead (route->nh_list))) |
c3c0ac83 DS |
377 | return (nh->ifindex); |
378 | } | |
379 | ||
380 | return (-1); | |
381 | } | |
382 | ||
508e53e2 | 383 | struct ospf6_route * |
6ac29a51 | 384 | ospf6_route_create (void) |
718e3744 | 385 | { |
508e53e2 | 386 | struct ospf6_route *route; |
387 | route = XCALLOC (MTYPE_OSPF6_ROUTE, sizeof (struct ospf6_route)); | |
c3c0ac83 | 388 | route->nh_list = list_new(); |
508e53e2 | 389 | return route; |
390 | } | |
718e3744 | 391 | |
508e53e2 | 392 | void |
393 | ospf6_route_delete (struct ospf6_route *route) | |
394 | { | |
c3c0ac83 DS |
395 | if (route) |
396 | { | |
397 | ospf6_free_nexthops (route->nh_list); | |
398 | list_free (route->nh_list); | |
399 | XFREE (MTYPE_OSPF6_ROUTE, route); | |
400 | } | |
718e3744 | 401 | } |
402 | ||
508e53e2 | 403 | struct ospf6_route * |
404 | ospf6_route_copy (struct ospf6_route *route) | |
718e3744 | 405 | { |
508e53e2 | 406 | struct ospf6_route *new; |
407 | ||
408 | new = ospf6_route_create (); | |
c3c0ac83 DS |
409 | new->type = route->type; |
410 | memcpy (&new->prefix, &route->prefix, sizeof (struct prefix)); | |
411 | new->installed = route->installed; | |
412 | new->changed = route->changed; | |
413 | new->flag = route->flag; | |
414 | new->route_option = route->route_option; | |
415 | new->linkstate_id = route->linkstate_id; | |
416 | new->path = route->path; | |
417 | ospf6_copy_nexthops (new->nh_list, route->nh_list); | |
508e53e2 | 418 | new->rnode = NULL; |
419 | new->prev = NULL; | |
420 | new->next = NULL; | |
cf1ce250 | 421 | new->table = NULL; |
508e53e2 | 422 | new->lock = 0; |
423 | return new; | |
424 | } | |
718e3744 | 425 | |
508e53e2 | 426 | void |
427 | ospf6_route_lock (struct ospf6_route *route) | |
428 | { | |
429 | route->lock++; | |
430 | } | |
718e3744 | 431 | |
508e53e2 | 432 | void |
433 | ospf6_route_unlock (struct ospf6_route *route) | |
434 | { | |
435 | assert (route->lock > 0); | |
436 | route->lock--; | |
437 | if (route->lock == 0) | |
cf1ce250 PJ |
438 | { |
439 | /* Can't detach from the table until here | |
440 | because ospf6_route_next () will use | |
441 | the 'route->table' pointer for logging */ | |
442 | route->table = NULL; | |
443 | ospf6_route_delete (route); | |
444 | } | |
508e53e2 | 445 | } |
718e3744 | 446 | |
508e53e2 | 447 | /* Route compare function. If ra is more preferred, it returns |
448 | less than 0. If rb is more preferred returns greater than 0. | |
449 | Otherwise (neither one is preferred), returns 0 */ | |
c3c0ac83 | 450 | int |
508e53e2 | 451 | ospf6_route_cmp (struct ospf6_route *ra, struct ospf6_route *rb) |
452 | { | |
453 | assert (ospf6_route_is_same (ra, rb)); | |
454 | assert (OSPF6_PATH_TYPE_NONE < ra->path.type && | |
455 | ra->path.type < OSPF6_PATH_TYPE_MAX); | |
456 | assert (OSPF6_PATH_TYPE_NONE < rb->path.type && | |
457 | rb->path.type < OSPF6_PATH_TYPE_MAX); | |
718e3744 | 458 | |
508e53e2 | 459 | if (ra->type != rb->type) |
460 | return (ra->type - rb->type); | |
718e3744 | 461 | |
508e53e2 | 462 | if (ra->path.area_id != rb->path.area_id) |
463 | return (ntohl (ra->path.area_id) - ntohl (rb->path.area_id)); | |
718e3744 | 464 | |
508e53e2 | 465 | if (ra->path.type != rb->path.type) |
466 | return (ra->path.type - rb->path.type); | |
718e3744 | 467 | |
508e53e2 | 468 | if (ra->path.type == OSPF6_PATH_TYPE_EXTERNAL2) |
469 | { | |
c3c0ac83 DS |
470 | if (ra->path.u.cost_e2 != rb->path.u.cost_e2) |
471 | return (ra->path.u.cost_e2 - rb->path.u.cost_e2); | |
718e3744 | 472 | } |
508e53e2 | 473 | else |
718e3744 | 474 | { |
508e53e2 | 475 | if (ra->path.cost != rb->path.cost) |
476 | return (ra->path.cost - rb->path.cost); | |
718e3744 | 477 | } |
718e3744 | 478 | |
508e53e2 | 479 | return 0; |
718e3744 | 480 | } |
481 | ||
508e53e2 | 482 | struct ospf6_route * |
483 | ospf6_route_lookup (struct prefix *prefix, | |
718e3744 | 484 | struct ospf6_route_table *table) |
485 | { | |
486 | struct route_node *node; | |
508e53e2 | 487 | struct ospf6_route *route; |
718e3744 | 488 | |
489 | node = route_node_lookup (table->table, prefix); | |
508e53e2 | 490 | if (node == NULL) |
491 | return NULL; | |
492 | ||
493 | route = (struct ospf6_route *) node->info; | |
494 | return route; | |
495 | } | |
718e3744 | 496 | |
508e53e2 | 497 | struct ospf6_route * |
498 | ospf6_route_lookup_identical (struct ospf6_route *route, | |
499 | struct ospf6_route_table *table) | |
500 | { | |
501 | struct ospf6_route *target; | |
718e3744 | 502 | |
508e53e2 | 503 | for (target = ospf6_route_lookup (&route->prefix, table); |
504 | target; target = target->next) | |
718e3744 | 505 | { |
508e53e2 | 506 | if (ospf6_route_is_identical (target, route)) |
507 | return target; | |
718e3744 | 508 | } |
508e53e2 | 509 | return NULL; |
718e3744 | 510 | } |
511 | ||
508e53e2 | 512 | struct ospf6_route * |
513 | ospf6_route_lookup_bestmatch (struct prefix *prefix, | |
514 | struct ospf6_route_table *table) | |
718e3744 | 515 | { |
516 | struct route_node *node; | |
508e53e2 | 517 | struct ospf6_route *route; |
718e3744 | 518 | |
508e53e2 | 519 | node = route_node_match (table->table, prefix); |
520 | if (node == NULL) | |
521 | return NULL; | |
522 | route_unlock_node (node); | |
718e3744 | 523 | |
508e53e2 | 524 | route = (struct ospf6_route *) node->info; |
525 | return route; | |
718e3744 | 526 | } |
527 | ||
e39d0538 | 528 | #ifdef DEBUG |
508e53e2 | 529 | static void |
cf1ce250 | 530 | route_table_assert (struct ospf6_route_table *table) |
718e3744 | 531 | { |
cf1ce250 | 532 | struct ospf6_route *prev, *r, *next; |
4690c7d7 | 533 | char buf[PREFIX2STR_BUFFER]; |
cf1ce250 PJ |
534 | unsigned int link_error = 0, num = 0; |
535 | ||
536 | r = ospf6_route_head (table); | |
537 | prev = NULL; | |
538 | while (r) | |
539 | { | |
540 | if (r->prev != prev) | |
541 | link_error++; | |
542 | ||
543 | next = ospf6_route_next (r); | |
544 | ||
545 | if (r->next != next) | |
546 | link_error++; | |
547 | ||
548 | prev = r; | |
549 | r = next; | |
550 | } | |
551 | ||
552 | for (r = ospf6_route_head (table); r; r = ospf6_route_next (r)) | |
508e53e2 | 553 | num++; |
cf1ce250 PJ |
554 | |
555 | if (link_error == 0 && num == table->count) | |
ccb59b11 | 556 | return; |
557 | ||
cf1ce250 PJ |
558 | zlog_err ("PANIC !!"); |
559 | zlog_err ("Something has gone wrong with ospf6_route_table[%p]", table); | |
560 | zlog_debug ("table count = %d, real number = %d", table->count, num); | |
561 | zlog_debug ("DUMP START"); | |
562 | for (r = ospf6_route_head (table); r; r = ospf6_route_next (r)) | |
ccb59b11 | 563 | { |
cf1ce250 PJ |
564 | prefix2str (&r->prefix, buf, sizeof (buf)); |
565 | zlog_info ("%p<-[%p]->%p : %s", r->prev, r, r->next, buf); | |
ccb59b11 | 566 | } |
c6487d61 | 567 | zlog_debug ("DUMP END"); |
ccb59b11 | 568 | |
cf1ce250 | 569 | assert (link_error == 0 && num == table->count); |
718e3744 | 570 | } |
cf1ce250 | 571 | #define ospf6_route_table_assert(t) (route_table_assert (t)) |
508e53e2 | 572 | #else |
cf1ce250 | 573 | #define ospf6_route_table_assert(t) ((void) 0) |
e39d0538 | 574 | #endif /*DEBUG*/ |
718e3744 | 575 | |
508e53e2 | 576 | struct ospf6_route * |
577 | ospf6_route_add (struct ospf6_route *route, | |
578 | struct ospf6_route_table *table) | |
718e3744 | 579 | { |
508e53e2 | 580 | struct route_node *node, *nextnode, *prevnode; |
581 | struct ospf6_route *current = NULL; | |
582 | struct ospf6_route *prev = NULL, *old = NULL, *next = NULL; | |
4690c7d7 | 583 | char buf[PREFIX2STR_BUFFER]; |
508e53e2 | 584 | struct timeval now; |
585 | ||
586 | assert (route->rnode == NULL); | |
587 | assert (route->lock == 0); | |
588 | assert (route->next == NULL); | |
589 | assert (route->prev == NULL); | |
590 | ||
591 | if (route->type == OSPF6_DEST_TYPE_LINKSTATE) | |
592 | ospf6_linkstate_prefix2str (&route->prefix, buf, sizeof (buf)); | |
593 | else | |
594 | prefix2str (&route->prefix, buf, sizeof (buf)); | |
718e3744 | 595 | |
cf1ce250 PJ |
596 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) |
597 | zlog_debug ("%s %p: route add %p: %s", ospf6_route_table_name (table), | |
6c4f4e6e | 598 | (void *)table, (void *)route, buf); |
cf1ce250 PJ |
599 | else if (IS_OSPF6_DEBUG_ROUTE (TABLE)) |
600 | zlog_debug ("%s: route add: %s", ospf6_route_table_name (table), buf); | |
718e3744 | 601 | |
cf672a86 | 602 | monotime(&now); |
718e3744 | 603 | |
508e53e2 | 604 | node = route_node_get (table->table, &route->prefix); |
605 | route->rnode = node; | |
718e3744 | 606 | |
508e53e2 | 607 | /* find place to insert */ |
608 | for (current = node->info; current; current = current->next) | |
718e3744 | 609 | { |
508e53e2 | 610 | if (! ospf6_route_is_same (current, route)) |
611 | next = current; | |
612 | else if (current->type != route->type) | |
613 | prev = current; | |
614 | else if (ospf6_route_is_same_origin (current, route)) | |
615 | old = current; | |
616 | else if (ospf6_route_cmp (current, route) > 0) | |
617 | next = current; | |
618 | else | |
619 | prev = current; | |
718e3744 | 620 | |
508e53e2 | 621 | if (old || next) |
622 | break; | |
718e3744 | 623 | } |
508e53e2 | 624 | |
625 | if (old) | |
718e3744 | 626 | { |
508e53e2 | 627 | /* if route does not actually change, return unchanged */ |
628 | if (ospf6_route_is_identical (old, route)) | |
629 | { | |
cf1ce250 PJ |
630 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) |
631 | zlog_debug ("%s %p: route add %p: needless update of %p", | |
6c4f4e6e DL |
632 | ospf6_route_table_name (table), |
633 | (void *)table, (void *)route, (void *)old); | |
cf1ce250 PJ |
634 | else if (IS_OSPF6_DEBUG_ROUTE (TABLE)) |
635 | zlog_debug ("%s: route add: needless update", | |
636 | ospf6_route_table_name (table)); | |
718e3744 | 637 | |
508e53e2 | 638 | ospf6_route_delete (route); |
639 | SET_FLAG (old->flag, OSPF6_ROUTE_ADD); | |
cf1ce250 | 640 | ospf6_route_table_assert (table); |
9428f2dc | 641 | |
508e53e2 | 642 | return old; |
643 | } | |
718e3744 | 644 | |
cf1ce250 PJ |
645 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) |
646 | zlog_debug ("%s %p: route add %p: update of %p", | |
6c4f4e6e DL |
647 | ospf6_route_table_name (table), |
648 | (void *)table, (void *)route, (void *)old); | |
cf1ce250 PJ |
649 | else if (IS_OSPF6_DEBUG_ROUTE (TABLE)) |
650 | zlog_debug ("%s: route add: update", | |
651 | ospf6_route_table_name (table)); | |
718e3744 | 652 | |
508e53e2 | 653 | /* replace old one if exists */ |
654 | if (node->info == old) | |
655 | { | |
656 | node->info = route; | |
657 | SET_FLAG (route->flag, OSPF6_ROUTE_BEST); | |
658 | } | |
718e3744 | 659 | |
508e53e2 | 660 | if (old->prev) |
661 | old->prev->next = route; | |
662 | route->prev = old->prev; | |
663 | if (old->next) | |
664 | old->next->prev = route; | |
665 | route->next = old->next; | |
718e3744 | 666 | |
508e53e2 | 667 | route->installed = old->installed; |
668 | route->changed = now; | |
cf1ce250 PJ |
669 | assert (route->table == NULL); |
670 | route->table = table; | |
718e3744 | 671 | |
508e53e2 | 672 | ospf6_route_unlock (old); /* will be deleted later */ |
673 | ospf6_route_lock (route); | |
718e3744 | 674 | |
508e53e2 | 675 | SET_FLAG (route->flag, OSPF6_ROUTE_CHANGE); |
cf1ce250 | 676 | ospf6_route_table_assert (table); |
9428f2dc | 677 | |
508e53e2 | 678 | if (table->hook_add) |
679 | (*table->hook_add) (route); | |
718e3744 | 680 | |
508e53e2 | 681 | return route; |
682 | } | |
718e3744 | 683 | |
508e53e2 | 684 | /* insert if previous or next node found */ |
685 | if (prev || next) | |
686 | { | |
cf1ce250 PJ |
687 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) |
688 | zlog_debug ("%s %p: route add %p: another path: prev %p, next %p", | |
6c4f4e6e DL |
689 | ospf6_route_table_name (table), |
690 | (void *)table, (void *)route, (void *)prev, (void *)next); | |
cf1ce250 PJ |
691 | else if (IS_OSPF6_DEBUG_ROUTE (TABLE)) |
692 | zlog_debug ("%s: route add: another path found", | |
693 | ospf6_route_table_name (table)); | |
508e53e2 | 694 | |
695 | if (prev == NULL) | |
696 | prev = next->prev; | |
697 | if (next == NULL) | |
698 | next = prev->next; | |
699 | ||
700 | if (prev) | |
701 | prev->next = route; | |
702 | route->prev = prev; | |
703 | if (next) | |
704 | next->prev = route; | |
705 | route->next = next; | |
706 | ||
707 | if (node->info == next) | |
708 | { | |
709 | assert (next->rnode == node); | |
710 | node->info = route; | |
711 | UNSET_FLAG (next->flag, OSPF6_ROUTE_BEST); | |
712 | SET_FLAG (route->flag, OSPF6_ROUTE_BEST); | |
cf1ce250 PJ |
713 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) |
714 | zlog_info ("%s %p: route add %p: replacing previous best: %p", | |
6c4f4e6e DL |
715 | ospf6_route_table_name (table), |
716 | (void *)table, (void *)route, (void *)next); | |
508e53e2 | 717 | } |
718e3744 | 718 | |
508e53e2 | 719 | route->installed = now; |
720 | route->changed = now; | |
cf1ce250 PJ |
721 | assert (route->table == NULL); |
722 | route->table = table; | |
718e3744 | 723 | |
508e53e2 | 724 | ospf6_route_lock (route); |
725 | table->count++; | |
cf1ce250 | 726 | ospf6_route_table_assert (table); |
508e53e2 | 727 | |
728 | SET_FLAG (route->flag, OSPF6_ROUTE_ADD); | |
729 | if (table->hook_add) | |
730 | (*table->hook_add) (route); | |
718e3744 | 731 | |
508e53e2 | 732 | return route; |
718e3744 | 733 | } |
734 | ||
508e53e2 | 735 | /* Else, this is the brand new route regarding to the prefix */ |
cf1ce250 PJ |
736 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) |
737 | zlog_debug ("%s %p: route add %p: brand new route", | |
6c4f4e6e | 738 | ospf6_route_table_name (table), (void *)table, (void *)route); |
cf1ce250 PJ |
739 | else if (IS_OSPF6_DEBUG_ROUTE (TABLE)) |
740 | zlog_debug ("%s: route add: brand new route", | |
741 | ospf6_route_table_name (table)); | |
508e53e2 | 742 | |
743 | assert (node->info == NULL); | |
744 | node->info = route; | |
745 | SET_FLAG (route->flag, OSPF6_ROUTE_BEST); | |
746 | ospf6_route_lock (route); | |
747 | route->installed = now; | |
748 | route->changed = now; | |
cf1ce250 PJ |
749 | assert (route->table == NULL); |
750 | route->table = table; | |
508e53e2 | 751 | |
752 | /* lookup real existing next route */ | |
753 | nextnode = node; | |
754 | route_lock_node (nextnode); | |
755 | do { | |
756 | nextnode = route_next (nextnode); | |
757 | } while (nextnode && nextnode->info == NULL); | |
758 | ||
759 | /* set next link */ | |
760 | if (nextnode == NULL) | |
761 | route->next = NULL; | |
762 | else | |
718e3744 | 763 | { |
508e53e2 | 764 | route_unlock_node (nextnode); |
765 | ||
766 | next = nextnode->info; | |
767 | route->next = next; | |
768 | next->prev = route; | |
718e3744 | 769 | } |
718e3744 | 770 | |
508e53e2 | 771 | /* lookup real existing prev route */ |
772 | prevnode = node; | |
773 | route_lock_node (prevnode); | |
774 | do { | |
775 | prevnode = route_prev (prevnode); | |
776 | } while (prevnode && prevnode->info == NULL); | |
718e3744 | 777 | |
508e53e2 | 778 | /* set prev link */ |
779 | if (prevnode == NULL) | |
780 | route->prev = NULL; | |
781 | else | |
718e3744 | 782 | { |
508e53e2 | 783 | route_unlock_node (prevnode); |
718e3744 | 784 | |
508e53e2 | 785 | prev = prevnode->info; |
786 | while (prev->next && ospf6_route_is_same (prev, prev->next)) | |
787 | prev = prev->next; | |
788 | route->prev = prev; | |
789 | prev->next = route; | |
718e3744 | 790 | } |
508e53e2 | 791 | |
792 | table->count++; | |
cf1ce250 | 793 | ospf6_route_table_assert (table); |
508e53e2 | 794 | |
795 | SET_FLAG (route->flag, OSPF6_ROUTE_ADD); | |
796 | if (table->hook_add) | |
797 | (*table->hook_add) (route); | |
798 | ||
508e53e2 | 799 | return route; |
718e3744 | 800 | } |
801 | ||
802 | void | |
508e53e2 | 803 | ospf6_route_remove (struct ospf6_route *route, |
804 | struct ospf6_route_table *table) | |
718e3744 | 805 | { |
508e53e2 | 806 | struct route_node *node; |
807 | struct ospf6_route *current; | |
4690c7d7 | 808 | char buf[PREFIX2STR_BUFFER]; |
718e3744 | 809 | |
508e53e2 | 810 | if (route->type == OSPF6_DEST_TYPE_LINKSTATE) |
811 | ospf6_linkstate_prefix2str (&route->prefix, buf, sizeof (buf)); | |
812 | else | |
813 | prefix2str (&route->prefix, buf, sizeof (buf)); | |
718e3744 | 814 | |
cf1ce250 PJ |
815 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) |
816 | zlog_debug ("%s %p: route remove %p: %s", | |
6c4f4e6e DL |
817 | ospf6_route_table_name (table), |
818 | (void *)table, (void *)route, buf); | |
cf1ce250 PJ |
819 | else if (IS_OSPF6_DEBUG_ROUTE (TABLE)) |
820 | zlog_debug ("%s: route remove: %s", ospf6_route_table_name (table), buf); | |
718e3744 | 821 | |
508e53e2 | 822 | node = route_node_lookup (table->table, &route->prefix); |
823 | assert (node); | |
718e3744 | 824 | |
508e53e2 | 825 | /* find the route to remove, making sure that the route pointer |
826 | is from the route table. */ | |
827 | current = node->info; | |
828 | while (current && ospf6_route_is_same (current, route)) | |
718e3744 | 829 | { |
508e53e2 | 830 | if (current == route) |
831 | break; | |
832 | current = current->next; | |
718e3744 | 833 | } |
508e53e2 | 834 | assert (current == route); |
718e3744 | 835 | |
508e53e2 | 836 | /* adjust doubly linked list */ |
837 | if (route->prev) | |
838 | route->prev->next = route->next; | |
839 | if (route->next) | |
840 | route->next->prev = route->prev; | |
718e3744 | 841 | |
508e53e2 | 842 | if (node->info == route) |
718e3744 | 843 | { |
0f23bb67 | 844 | if (route->next && route->next->rnode == node) |
718e3744 | 845 | { |
508e53e2 | 846 | node->info = route->next; |
847 | SET_FLAG (route->next->flag, OSPF6_ROUTE_BEST); | |
718e3744 | 848 | } |
508e53e2 | 849 | else |
850 | node->info = NULL; /* should unlock route_node here ? */ | |
718e3744 | 851 | } |
852 | ||
9428f2dc | 853 | table->count--; |
cf1ce250 | 854 | ospf6_route_table_assert (table); |
9428f2dc | 855 | |
856 | SET_FLAG (route->flag, OSPF6_ROUTE_WAS_REMOVED); | |
857 | ||
508e53e2 | 858 | if (table->hook_remove) |
859 | (*table->hook_remove) (route); | |
718e3744 | 860 | |
508e53e2 | 861 | ospf6_route_unlock (route); |
508e53e2 | 862 | } |
718e3744 | 863 | |
508e53e2 | 864 | struct ospf6_route * |
865 | ospf6_route_head (struct ospf6_route_table *table) | |
866 | { | |
867 | struct route_node *node; | |
868 | struct ospf6_route *route; | |
718e3744 | 869 | |
508e53e2 | 870 | node = route_top (table->table); |
871 | if (node == NULL) | |
872 | return NULL; | |
873 | ||
874 | /* skip to the real existing entry */ | |
875 | while (node && node->info == NULL) | |
876 | node = route_next (node); | |
877 | if (node == NULL) | |
878 | return NULL; | |
718e3744 | 879 | |
508e53e2 | 880 | route_unlock_node (node); |
881 | assert (node->info); | |
882 | ||
883 | route = (struct ospf6_route *) node->info; | |
884 | assert (route->prev == NULL); | |
cf1ce250 | 885 | assert (route->table == table); |
508e53e2 | 886 | ospf6_route_lock (route); |
cf1ce250 PJ |
887 | |
888 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) | |
889 | zlog_info ("%s %p: route head: %p<-[%p]->%p", | |
6c4f4e6e DL |
890 | ospf6_route_table_name (table), (void *)table, |
891 | (void *)route->prev, (void *)route, (void *)route->next); | |
cf1ce250 | 892 | |
508e53e2 | 893 | return route; |
718e3744 | 894 | } |
895 | ||
508e53e2 | 896 | struct ospf6_route * |
897 | ospf6_route_next (struct ospf6_route *route) | |
718e3744 | 898 | { |
508e53e2 | 899 | struct ospf6_route *next = route->next; |
718e3744 | 900 | |
cf1ce250 PJ |
901 | if (IS_OSPF6_DEBUG_ROUTE (MEMORY)) |
902 | zlog_info ("%s %p: route next: %p<-[%p]->%p", | |
6c4f4e6e DL |
903 | ospf6_route_table_name (route->table), (void *)route->table, |
904 | (void *)route->prev, (void *)route, (void *)route->next); | |
cf1ce250 | 905 | |
508e53e2 | 906 | ospf6_route_unlock (route); |
907 | if (next) | |
908 | ospf6_route_lock (next); | |
718e3744 | 909 | |
508e53e2 | 910 | return next; |
911 | } | |
718e3744 | 912 | |
508e53e2 | 913 | struct ospf6_route * |
914 | ospf6_route_best_next (struct ospf6_route *route) | |
915 | { | |
916 | struct route_node *rnode; | |
917 | struct ospf6_route *next; | |
918 | ||
e7a6d80d TG |
919 | ospf6_route_unlock (route); |
920 | ||
508e53e2 | 921 | rnode = route->rnode; |
922 | route_lock_node (rnode); | |
923 | rnode = route_next (rnode); | |
924 | while (rnode && rnode->info == NULL) | |
925 | rnode = route_next (rnode); | |
926 | if (rnode == NULL) | |
927 | return NULL; | |
928 | route_unlock_node (rnode); | |
929 | ||
930 | assert (rnode->info); | |
931 | next = (struct ospf6_route *) rnode->info; | |
508e53e2 | 932 | ospf6_route_lock (next); |
933 | return next; | |
934 | } | |
718e3744 | 935 | |
508e53e2 | 936 | struct ospf6_route * |
937 | ospf6_route_match_head (struct prefix *prefix, | |
938 | struct ospf6_route_table *table) | |
939 | { | |
940 | struct route_node *node; | |
941 | struct ospf6_route *route; | |
718e3744 | 942 | |
508e53e2 | 943 | /* Walk down tree. */ |
944 | node = table->table->top; | |
945 | while (node && node->p.prefixlen < prefix->prefixlen && | |
946 | prefix_match (&node->p, prefix)) | |
1352ef32 | 947 | node = node->link[prefix_bit(&prefix->u.prefix, node->p.prefixlen)]; |
718e3744 | 948 | |
508e53e2 | 949 | if (node) |
950 | route_lock_node (node); | |
951 | while (node && node->info == NULL) | |
952 | node = route_next (node); | |
953 | if (node == NULL) | |
954 | return NULL; | |
955 | route_unlock_node (node); | |
718e3744 | 956 | |
508e53e2 | 957 | if (! prefix_match (prefix, &node->p)) |
958 | return NULL; | |
718e3744 | 959 | |
508e53e2 | 960 | route = node->info; |
961 | ospf6_route_lock (route); | |
962 | return route; | |
963 | } | |
718e3744 | 964 | |
508e53e2 | 965 | struct ospf6_route * |
966 | ospf6_route_match_next (struct prefix *prefix, | |
967 | struct ospf6_route *route) | |
968 | { | |
969 | struct ospf6_route *next; | |
970 | ||
971 | next = ospf6_route_next (route); | |
972 | if (next && ! prefix_match (prefix, &next->prefix)) | |
973 | { | |
974 | ospf6_route_unlock (next); | |
975 | next = NULL; | |
976 | } | |
977 | ||
978 | return next; | |
718e3744 | 979 | } |
980 | ||
981 | void | |
982 | ospf6_route_remove_all (struct ospf6_route_table *table) | |
983 | { | |
508e53e2 | 984 | struct ospf6_route *route; |
985 | for (route = ospf6_route_head (table); route; | |
986 | route = ospf6_route_next (route)) | |
987 | ospf6_route_remove (route, table); | |
718e3744 | 988 | } |
989 | ||
718e3744 | 990 | struct ospf6_route_table * |
cf1ce250 | 991 | ospf6_route_table_create (int s, int t) |
718e3744 | 992 | { |
718e3744 | 993 | struct ospf6_route_table *new; |
718e3744 | 994 | new = XCALLOC (MTYPE_OSPF6_ROUTE, sizeof (struct ospf6_route_table)); |
718e3744 | 995 | new->table = route_table_init (); |
cf1ce250 PJ |
996 | new->scope_type = s; |
997 | new->table_type = t; | |
718e3744 | 998 | return new; |
999 | } | |
1000 | ||
1001 | void | |
1002 | ospf6_route_table_delete (struct ospf6_route_table *table) | |
1003 | { | |
718e3744 | 1004 | ospf6_route_remove_all (table); |
1005 | route_table_finish (table->table); | |
718e3744 | 1006 | XFREE (MTYPE_OSPF6_ROUTE, table); |
1007 | } | |
1008 | ||
6b0655a2 | 1009 | |
508e53e2 | 1010 | /* VTY commands */ |
718e3744 | 1011 | void |
508e53e2 | 1012 | ospf6_route_show (struct vty *vty, struct ospf6_route *route) |
718e3744 | 1013 | { |
508e53e2 | 1014 | int i; |
4690c7d7 | 1015 | char destination[PREFIX2STR_BUFFER], nexthop[64]; |
322e5964 FL |
1016 | char duration[16]; |
1017 | const char *ifname; | |
508e53e2 | 1018 | struct timeval now, res; |
c3c0ac83 DS |
1019 | struct listnode *node; |
1020 | struct ospf6_nexthop *nh; | |
718e3744 | 1021 | |
cf672a86 | 1022 | monotime(&now); |
508e53e2 | 1023 | timersub (&now, &route->changed, &res); |
1024 | timerstring (&res, duration, sizeof (duration)); | |
718e3744 | 1025 | |
508e53e2 | 1026 | /* destination */ |
1027 | if (route->type == OSPF6_DEST_TYPE_LINKSTATE) | |
1028 | ospf6_linkstate_prefix2str (&route->prefix, destination, | |
1029 | sizeof (destination)); | |
1030 | else if (route->type == OSPF6_DEST_TYPE_ROUTER) | |
1031 | inet_ntop (route->prefix.family, &route->prefix.u.prefix, | |
1032 | destination, sizeof (destination)); | |
1033 | else | |
1034 | prefix2str (&route->prefix, destination, sizeof (destination)); | |
1035 | ||
c3c0ac83 DS |
1036 | i = 0; |
1037 | for (ALL_LIST_ELEMENTS_RO (route->nh_list, node, nh)) | |
718e3744 | 1038 | { |
508e53e2 | 1039 | /* nexthop */ |
c3c0ac83 | 1040 | inet_ntop (AF_INET6, &nh->address, nexthop, |
508e53e2 | 1041 | sizeof (nexthop)); |
baaea325 | 1042 | ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT); |
c3c0ac83 DS |
1043 | |
1044 | if (!i) | |
1045 | { | |
55f70b67 | 1046 | vty_out (vty, "%c%1s %2s %-30s %-25s %6.*s %s\n", |
c3c0ac83 DS |
1047 | (ospf6_route_is_best (route) ? '*' : ' '), |
1048 | OSPF6_DEST_TYPE_SUBSTR (route->type), | |
1049 | OSPF6_PATH_TYPE_SUBSTR (route->path.type), | |
55f70b67 | 1050 | destination, nexthop, IFNAMSIZ, ifname, duration); |
c3c0ac83 DS |
1051 | i++; |
1052 | } | |
1053 | else | |
55f70b67 DL |
1054 | vty_out (vty, "%c%1s %2s %-30s %-25s %6.*s %s\n", |
1055 | ' ', "", "", "", nexthop, IFNAMSIZ, ifname, ""); | |
718e3744 | 1056 | } |
1057 | } | |
1058 | ||
718e3744 | 1059 | void |
508e53e2 | 1060 | ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route) |
718e3744 | 1061 | { |
322e5964 FL |
1062 | const char *ifname; |
1063 | char destination[PREFIX2STR_BUFFER], nexthop[64]; | |
508e53e2 | 1064 | char area_id[16], id[16], adv_router[16], capa[16], options[16]; |
718e3744 | 1065 | struct timeval now, res; |
1066 | char duration[16]; | |
c3c0ac83 DS |
1067 | struct listnode *node; |
1068 | struct ospf6_nexthop *nh; | |
718e3744 | 1069 | |
cf672a86 | 1070 | monotime(&now); |
718e3744 | 1071 | |
1072 | /* destination */ | |
508e53e2 | 1073 | if (route->type == OSPF6_DEST_TYPE_LINKSTATE) |
1074 | ospf6_linkstate_prefix2str (&route->prefix, destination, | |
1075 | sizeof (destination)); | |
1076 | else if (route->type == OSPF6_DEST_TYPE_ROUTER) | |
1077 | inet_ntop (route->prefix.family, &route->prefix.u.prefix, | |
1078 | destination, sizeof (destination)); | |
718e3744 | 1079 | else |
508e53e2 | 1080 | prefix2str (&route->prefix, destination, sizeof (destination)); |
55f70b67 | 1081 | vty_out (vty, "Destination: %s\n", destination); |
508e53e2 | 1082 | |
1083 | /* destination type */ | |
55f70b67 DL |
1084 | vty_out (vty, "Destination type: %s\n", |
1085 | OSPF6_DEST_TYPE_NAME (route->type)); | |
508e53e2 | 1086 | |
1087 | /* Time */ | |
1088 | timersub (&now, &route->installed, &res); | |
1089 | timerstring (&res, duration, sizeof (duration)); | |
55f70b67 | 1090 | vty_out (vty, "Installed Time: %s ago\n", duration); |
508e53e2 | 1091 | |
1092 | timersub (&now, &route->changed, &res); | |
1093 | timerstring (&res, duration, sizeof (duration)); | |
55f70b67 | 1094 | vty_out (vty, " Changed Time: %s ago\n", duration); |
508e53e2 | 1095 | |
1096 | /* Debugging info */ | |
55f70b67 | 1097 | vty_out (vty, "Lock: %d Flags: %s%s%s%s\n", route->lock, |
508e53e2 | 1098 | (CHECK_FLAG (route->flag, OSPF6_ROUTE_BEST) ? "B" : "-"), |
1099 | (CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD) ? "A" : "-"), | |
1100 | (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE) ? "R" : "-"), | |
55f70b67 DL |
1101 | (CHECK_FLAG (route->flag, OSPF6_ROUTE_CHANGE) ? "C" : "-")); |
1102 | vty_out (vty, "Memory: prev: %p this: %p next: %p\n", | |
1103 | (void *)route->prev, (void *)route, (void *)route->next); | |
508e53e2 | 1104 | |
1105 | /* Path section */ | |
1106 | ||
1107 | /* Area-ID */ | |
1108 | inet_ntop (AF_INET, &route->path.area_id, area_id, sizeof (area_id)); | |
55f70b67 | 1109 | vty_out (vty, "Associated Area: %s\n", area_id); |
508e53e2 | 1110 | |
1111 | /* Path type */ | |
55f70b67 DL |
1112 | vty_out (vty, "Path Type: %s\n", |
1113 | OSPF6_PATH_TYPE_NAME (route->path.type)); | |
508e53e2 | 1114 | |
1115 | /* LS Origin */ | |
1116 | inet_ntop (AF_INET, &route->path.origin.id, id, sizeof (id)); | |
1117 | inet_ntop (AF_INET, &route->path.origin.adv_router, adv_router, | |
1118 | sizeof (adv_router)); | |
55f70b67 | 1119 | vty_out (vty, "LS Origin: %s Id: %s Adv: %s\n", |
1e05838a | 1120 | ospf6_lstype_name (route->path.origin.type), |
55f70b67 | 1121 | id, adv_router); |
508e53e2 | 1122 | |
1123 | /* Options */ | |
1124 | ospf6_options_printbuf (route->path.options, options, sizeof (options)); | |
55f70b67 | 1125 | vty_out (vty, "Options: %s\n", options); |
508e53e2 | 1126 | |
1127 | /* Router Bits */ | |
1128 | ospf6_capability_printbuf (route->path.router_bits, capa, sizeof (capa)); | |
55f70b67 | 1129 | vty_out (vty, "Router Bits: %s\n", capa); |
508e53e2 | 1130 | |
1131 | /* Prefix Options */ | |
26a429fe | 1132 | vty_out (vty, "Prefix Options: xxx\n"); |
508e53e2 | 1133 | |
1134 | /* Metrics */ | |
55f70b67 DL |
1135 | vty_out (vty, "Metric Type: %d\n", route->path.metric_type); |
1136 | vty_out (vty, "Metric: %d (%d)\n", | |
1137 | route->path.cost, route->path.u.cost_e2); | |
508e53e2 | 1138 | |
1139 | /* Nexthops */ | |
26a429fe | 1140 | vty_out (vty, "Nexthop:\n"); |
c3c0ac83 | 1141 | for (ALL_LIST_ELEMENTS_RO (route->nh_list, node, nh)) |
508e53e2 | 1142 | { |
1143 | /* nexthop */ | |
c3c0ac83 | 1144 | inet_ntop (AF_INET6, &nh->address, nexthop, sizeof (nexthop)); |
baaea325 | 1145 | ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT); |
55f70b67 | 1146 | vty_out (vty, " %s %.*s\n", nexthop, IFNAMSIZ, ifname); |
508e53e2 | 1147 | } |
26a429fe | 1148 | vty_out (vty, "\n"); |
508e53e2 | 1149 | } |
718e3744 | 1150 | |
6ac29a51 | 1151 | static void |
508e53e2 | 1152 | ospf6_route_show_table_summary (struct vty *vty, |
1153 | struct ospf6_route_table *table) | |
1154 | { | |
1155 | struct ospf6_route *route, *prev = NULL; | |
1156 | int i, pathtype[OSPF6_PATH_TYPE_MAX]; | |
0c083ee9 | 1157 | unsigned int number = 0; |
c3c0ac83 | 1158 | int nh_count =0 , nhinval = 0, ecmp = 0; |
4846ef64 | 1159 | int alternative = 0, destination = 0; |
508e53e2 | 1160 | |
1161 | for (i = 0; i < OSPF6_PATH_TYPE_MAX; i++) | |
1162 | pathtype[i] = 0; | |
1163 | ||
1164 | for (route = ospf6_route_head (table); route; | |
1165 | route = ospf6_route_next (route)) | |
718e3744 | 1166 | { |
508e53e2 | 1167 | if (prev == NULL || ! ospf6_route_is_same (prev, route)) |
1168 | destination++; | |
1169 | else | |
4846ef64 | 1170 | alternative++; |
c3c0ac83 DS |
1171 | nh_count = ospf6_num_nexthops (route->nh_list); |
1172 | if (!nh_count) | |
508e53e2 | 1173 | nhinval++; |
c3c0ac83 | 1174 | else if (nh_count > 1) |
508e53e2 | 1175 | ecmp++; |
4846ef64 | 1176 | pathtype[route->path.type]++; |
508e53e2 | 1177 | number++; |
4846ef64 | 1178 | |
508e53e2 | 1179 | prev = route; |
1180 | } | |
718e3744 | 1181 | |
508e53e2 | 1182 | assert (number == table->count); |
508e53e2 | 1183 | |
55f70b67 DL |
1184 | vty_out (vty, "Number of OSPFv3 routes: %d\n", number); |
1185 | vty_out (vty, "Number of Destination: %d\n", destination); | |
1186 | vty_out (vty, "Number of Alternative routes: %d\n", alternative); | |
1187 | vty_out (vty, "Number of Equal Cost Multi Path: %d\n", ecmp); | |
4846ef64 | 1188 | for (i = OSPF6_PATH_TYPE_INTRA; i <= OSPF6_PATH_TYPE_EXTERNAL2; i++) |
1189 | { | |
55f70b67 DL |
1190 | vty_out (vty, "Number of %s routes: %d\n", |
1191 | OSPF6_PATH_TYPE_NAME (i), pathtype[i]); | |
4846ef64 | 1192 | } |
1193 | } | |
1194 | ||
6ac29a51 | 1195 | static void |
4846ef64 | 1196 | ospf6_route_show_table_prefix (struct vty *vty, |
1197 | struct prefix *prefix, | |
1198 | struct ospf6_route_table *table) | |
1199 | { | |
1200 | struct ospf6_route *route; | |
1201 | ||
1202 | route = ospf6_route_lookup (prefix, table); | |
1203 | if (route == NULL) | |
1204 | return; | |
1205 | ||
1206 | ospf6_route_lock (route); | |
1207 | while (route && ospf6_route_is_prefix (prefix, route)) | |
1208 | { | |
1209 | /* Specifying a prefix will always display details */ | |
1210 | ospf6_route_show_detail (vty, route); | |
1211 | route = ospf6_route_next (route); | |
1212 | } | |
1213 | if (route) | |
1214 | ospf6_route_unlock (route); | |
1215 | } | |
1216 | ||
6ac29a51 | 1217 | static void |
4846ef64 | 1218 | ospf6_route_show_table_address (struct vty *vty, |
1219 | struct prefix *prefix, | |
1220 | struct ospf6_route_table *table) | |
1221 | { | |
1222 | struct ospf6_route *route; | |
1223 | ||
1224 | route = ospf6_route_lookup_bestmatch (prefix, table); | |
1225 | if (route == NULL) | |
1226 | return; | |
1227 | ||
1228 | prefix = &route->prefix; | |
1229 | ospf6_route_lock (route); | |
1230 | while (route && ospf6_route_is_prefix (prefix, route)) | |
1231 | { | |
1232 | /* Specifying a prefix will always display details */ | |
1233 | ospf6_route_show_detail (vty, route); | |
1234 | route = ospf6_route_next (route); | |
1235 | } | |
1236 | if (route) | |
1237 | ospf6_route_unlock (route); | |
1238 | } | |
1239 | ||
6ac29a51 | 1240 | static void |
4846ef64 | 1241 | ospf6_route_show_table_match (struct vty *vty, int detail, |
1242 | struct prefix *prefix, | |
1243 | struct ospf6_route_table *table) | |
1244 | { | |
1245 | struct ospf6_route *route; | |
1246 | assert (prefix->family); | |
1247 | ||
1248 | route = ospf6_route_match_head (prefix, table); | |
1249 | while (route) | |
1250 | { | |
1251 | if (detail) | |
1252 | ospf6_route_show_detail (vty, route); | |
1253 | else | |
1254 | ospf6_route_show (vty, route); | |
1255 | route = ospf6_route_match_next (prefix, route); | |
1256 | } | |
1257 | } | |
1258 | ||
6ac29a51 | 1259 | static void |
4846ef64 | 1260 | ospf6_route_show_table_type (struct vty *vty, int detail, u_char type, |
1261 | struct ospf6_route_table *table) | |
1262 | { | |
1263 | struct ospf6_route *route; | |
1264 | ||
1265 | route = ospf6_route_head (table); | |
1266 | while (route) | |
1267 | { | |
1268 | if (route->path.type == type) | |
1269 | { | |
1270 | if (detail) | |
1271 | ospf6_route_show_detail (vty, route); | |
1272 | else | |
1273 | ospf6_route_show (vty, route); | |
1274 | } | |
1275 | route = ospf6_route_next (route); | |
1276 | } | |
1277 | } | |
1278 | ||
6ac29a51 | 1279 | static void |
4846ef64 | 1280 | ospf6_route_show_table (struct vty *vty, int detail, |
1281 | struct ospf6_route_table *table) | |
1282 | { | |
1283 | struct ospf6_route *route; | |
1284 | ||
1285 | route = ospf6_route_head (table); | |
1286 | while (route) | |
508e53e2 | 1287 | { |
4846ef64 | 1288 | if (detail) |
1289 | ospf6_route_show_detail (vty, route); | |
1290 | else | |
1291 | ospf6_route_show (vty, route); | |
1292 | route = ospf6_route_next (route); | |
718e3744 | 1293 | } |
1294 | } | |
1295 | ||
508e53e2 | 1296 | int |
1d68dbfe | 1297 | ospf6_route_table_show (struct vty *vty, int argc_start, int argc, struct cmd_token **argv, |
508e53e2 | 1298 | struct ospf6_route_table *table) |
718e3744 | 1299 | { |
4846ef64 | 1300 | int summary = 0; |
1301 | int match = 0; | |
1302 | int detail = 0; | |
1303 | int slash = 0; | |
1304 | int isprefix = 0; | |
508e53e2 | 1305 | int i, ret; |
4846ef64 | 1306 | struct prefix prefix; |
1307 | u_char type = 0; | |
718e3744 | 1308 | |
508e53e2 | 1309 | memset (&prefix, 0, sizeof (struct prefix)); |
718e3744 | 1310 | |
1d68dbfe | 1311 | for (i = argc_start; i < argc; i++) |
508e53e2 | 1312 | { |
7e045c3d | 1313 | if (strmatch(argv[i]->text, "summary")) |
508e53e2 | 1314 | { |
4846ef64 | 1315 | summary++; |
508e53e2 | 1316 | continue; |
1317 | } | |
718e3744 | 1318 | |
7e045c3d | 1319 | if (strmatch(argv[i]->text, "intra-area")) |
508e53e2 | 1320 | { |
4846ef64 | 1321 | type = OSPF6_PATH_TYPE_INTRA; |
508e53e2 | 1322 | continue; |
1323 | } | |
1324 | ||
7e045c3d | 1325 | if (strmatch(argv[i]->text, "inter-area")) |
508e53e2 | 1326 | { |
4846ef64 | 1327 | type = OSPF6_PATH_TYPE_INTER; |
508e53e2 | 1328 | continue; |
1329 | } | |
718e3744 | 1330 | |
7e045c3d | 1331 | if (strmatch(argv[i]->text, "external-1")) |
508e53e2 | 1332 | { |
4846ef64 | 1333 | type = OSPF6_PATH_TYPE_EXTERNAL1; |
1334 | continue; | |
1335 | } | |
1336 | ||
7e045c3d | 1337 | if (strmatch(argv[i]->text, "external-2")) |
4846ef64 | 1338 | { |
1339 | type = OSPF6_PATH_TYPE_EXTERNAL2; | |
1340 | continue; | |
1341 | } | |
1342 | ||
7e045c3d | 1343 | if (strmatch(argv[i]->text, "detail")) |
4846ef64 | 1344 | { |
1345 | detail++; | |
1346 | continue; | |
1347 | } | |
1348 | ||
7e045c3d | 1349 | if (strmatch(argv[i]->text, "match")) |
4846ef64 | 1350 | { |
1351 | match++; | |
1352 | continue; | |
508e53e2 | 1353 | } |
718e3744 | 1354 | |
cc9de1ba | 1355 | ret = str2prefix (argv[i]->arg, &prefix); |
4846ef64 | 1356 | if (ret == 1 && prefix.family == AF_INET6) |
718e3744 | 1357 | { |
4846ef64 | 1358 | isprefix++; |
cc9de1ba | 1359 | if (strchr (argv[i]->arg, '/')) |
4846ef64 | 1360 | slash++; |
1361 | continue; | |
508e53e2 | 1362 | } |
718e3744 | 1363 | |
55f70b67 | 1364 | vty_out (vty, "Malformed argument: %s\n", argv[i]->arg); |
4846ef64 | 1365 | return CMD_SUCCESS; |
508e53e2 | 1366 | } |
718e3744 | 1367 | |
508e53e2 | 1368 | /* Give summary of this route table */ |
4846ef64 | 1369 | if (summary) |
508e53e2 | 1370 | { |
1371 | ospf6_route_show_table_summary (vty, table); | |
1372 | return CMD_SUCCESS; | |
1373 | } | |
718e3744 | 1374 | |
508e53e2 | 1375 | /* Give exact prefix-match route */ |
4846ef64 | 1376 | if (isprefix && ! match) |
508e53e2 | 1377 | { |
1378 | /* If exact address, give best matching route */ | |
4846ef64 | 1379 | if (! slash) |
1380 | ospf6_route_show_table_address (vty, &prefix, table); | |
508e53e2 | 1381 | else |
4846ef64 | 1382 | ospf6_route_show_table_prefix (vty, &prefix, table); |
508e53e2 | 1383 | |
4846ef64 | 1384 | return CMD_SUCCESS; |
1385 | } | |
508e53e2 | 1386 | |
4846ef64 | 1387 | if (match) |
1388 | ospf6_route_show_table_match (vty, detail, &prefix, table); | |
1389 | else if (type) | |
1390 | ospf6_route_show_table_type (vty, detail, type, table); | |
1391 | else | |
1392 | ospf6_route_show_table (vty, detail, table); | |
508e53e2 | 1393 | |
4846ef64 | 1394 | return CMD_SUCCESS; |
1395 | } | |
508e53e2 | 1396 | |
6ac29a51 | 1397 | static void |
4846ef64 | 1398 | ospf6_linkstate_show_header (struct vty *vty) |
1399 | { | |
55f70b67 DL |
1400 | vty_out (vty, "%-7s %-15s %-15s %-8s %-14s %s\n", |
1401 | "Type", "Router-ID", "Net-ID", "Rtr-Bits", "Options", "Cost"); | |
4846ef64 | 1402 | } |
1403 | ||
6ac29a51 | 1404 | static void |
4846ef64 | 1405 | ospf6_linkstate_show (struct vty *vty, struct ospf6_route *route) |
1406 | { | |
1407 | u_int32_t router, id; | |
1408 | char routername[16], idname[16], rbits[16], options[16]; | |
1409 | ||
1410 | router = ospf6_linkstate_prefix_adv_router (&route->prefix); | |
1411 | inet_ntop (AF_INET, &router, routername, sizeof (routername)); | |
1412 | id = ospf6_linkstate_prefix_id (&route->prefix); | |
1413 | inet_ntop (AF_INET, &id, idname, sizeof (idname)); | |
1414 | ||
1415 | ospf6_capability_printbuf (route->path.router_bits, rbits, sizeof (rbits)); | |
1416 | ospf6_options_printbuf (route->path.options, options, sizeof (options)); | |
508e53e2 | 1417 | |
4846ef64 | 1418 | if (ntohl (id)) |
55f70b67 | 1419 | vty_out (vty, "%-7s %-15s %-15s %-8s %-14s %lu\n", |
4846ef64 | 1420 | "Network", routername, idname, rbits, options, |
55f70b67 | 1421 | (unsigned long) route->path.cost); |
508e53e2 | 1422 | else |
55f70b67 | 1423 | vty_out (vty, "%-7s %-15s %-15s %-8s %-14s %lu\n", |
4846ef64 | 1424 | "Router", routername, idname, rbits, options, |
55f70b67 | 1425 | (unsigned long) route->path.cost); |
4846ef64 | 1426 | } |
1427 | ||
1428 | ||
6ac29a51 | 1429 | static void |
4846ef64 | 1430 | ospf6_linkstate_show_table_exact (struct vty *vty, |
1431 | struct prefix *prefix, | |
1432 | struct ospf6_route_table *table) | |
1433 | { | |
1434 | struct ospf6_route *route; | |
1435 | ||
1436 | route = ospf6_route_lookup (prefix, table); | |
1437 | if (route == NULL) | |
1438 | return; | |
1439 | ||
1440 | ospf6_route_lock (route); | |
1441 | while (route && ospf6_route_is_prefix (prefix, route)) | |
1442 | { | |
1443 | /* Specifying a prefix will always display details */ | |
1444 | ospf6_route_show_detail (vty, route); | |
1445 | route = ospf6_route_next (route); | |
1446 | } | |
1447 | if (route) | |
1448 | ospf6_route_unlock (route); | |
1449 | } | |
1450 | ||
6ac29a51 | 1451 | static void |
4846ef64 | 1452 | ospf6_linkstate_show_table (struct vty *vty, int detail, |
1453 | struct ospf6_route_table *table) | |
1454 | { | |
1455 | struct ospf6_route *route; | |
1456 | ||
1457 | if (! detail) | |
1458 | ospf6_linkstate_show_header (vty); | |
508e53e2 | 1459 | |
4846ef64 | 1460 | route = ospf6_route_head (table); |
508e53e2 | 1461 | while (route) |
1462 | { | |
4846ef64 | 1463 | if (detail) |
508e53e2 | 1464 | ospf6_route_show_detail (vty, route); |
1465 | else | |
4846ef64 | 1466 | ospf6_linkstate_show (vty, route); |
1467 | route = ospf6_route_next (route); | |
508e53e2 | 1468 | } |
718e3744 | 1469 | } |
1470 | ||
1471 | int | |
093d7a3a DW |
1472 | ospf6_linkstate_table_show (struct vty *vty, int idx_ipv4, int argc, |
1473 | struct cmd_token **argv, | |
4846ef64 | 1474 | struct ospf6_route_table *table) |
718e3744 | 1475 | { |
4846ef64 | 1476 | int detail = 0; |
1477 | int is_id = 0; | |
1478 | int is_router = 0; | |
718e3744 | 1479 | int i, ret; |
4846ef64 | 1480 | struct prefix router, id, prefix; |
718e3744 | 1481 | |
4846ef64 | 1482 | memset (&router, 0, sizeof (struct prefix)); |
508e53e2 | 1483 | memset (&id, 0, sizeof (struct prefix)); |
4846ef64 | 1484 | memset (&prefix, 0, sizeof (struct prefix)); |
718e3744 | 1485 | |
093d7a3a | 1486 | for (i = idx_ipv4; i < argc; i++) |
718e3744 | 1487 | { |
7e045c3d | 1488 | if (strmatch(argv[i]->text, "detail")) |
718e3744 | 1489 | { |
4846ef64 | 1490 | detail++; |
508e53e2 | 1491 | continue; |
718e3744 | 1492 | } |
1493 | ||
4846ef64 | 1494 | if (! is_router) |
718e3744 | 1495 | { |
cc9de1ba | 1496 | ret = str2prefix (argv[i]->arg, &router); |
4846ef64 | 1497 | if (ret == 1 && router.family == AF_INET) |
718e3744 | 1498 | { |
4846ef64 | 1499 | is_router++; |
1500 | continue; | |
718e3744 | 1501 | } |
55f70b67 | 1502 | vty_out (vty, "Malformed argument: %s\n", argv[i]->arg); |
4846ef64 | 1503 | return CMD_SUCCESS; |
508e53e2 | 1504 | } |
508e53e2 | 1505 | |
4846ef64 | 1506 | if (! is_id) |
1507 | { | |
cc9de1ba | 1508 | ret = str2prefix (argv[i]->arg, &id); |
4846ef64 | 1509 | if (ret == 1 && id.family == AF_INET) |
718e3744 | 1510 | { |
4846ef64 | 1511 | is_id++; |
1512 | continue; | |
718e3744 | 1513 | } |
55f70b67 | 1514 | vty_out (vty, "Malformed argument: %s\n", argv[i]->arg); |
508e53e2 | 1515 | return CMD_SUCCESS; |
1516 | } | |
1517 | ||
55f70b67 | 1518 | vty_out (vty, "Malformed argument: %s\n", argv[i]->arg); |
508e53e2 | 1519 | return CMD_SUCCESS; |
718e3744 | 1520 | } |
1521 | ||
4846ef64 | 1522 | if (is_router) |
1523 | ospf6_linkstate_prefix (router.u.prefix4.s_addr, | |
1524 | id.u.prefix4.s_addr, &prefix); | |
718e3744 | 1525 | |
4846ef64 | 1526 | if (prefix.family) |
1527 | ospf6_linkstate_show_table_exact (vty, &prefix, table); | |
1528 | else | |
1529 | ospf6_linkstate_show_table (vty, detail, table); | |
718e3744 | 1530 | |
508e53e2 | 1531 | return CMD_SUCCESS; |
1532 | } | |
718e3744 | 1533 | |
4846ef64 | 1534 | |
6452df09 | 1535 | void |
1536 | ospf6_brouter_show_header (struct vty *vty) | |
1537 | { | |
55f70b67 DL |
1538 | vty_out (vty, "%-15s %-8s %-14s %-10s %-15s\n", |
1539 | "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area"); | |
6452df09 | 1540 | } |
1541 | ||
1542 | void | |
1543 | ospf6_brouter_show (struct vty *vty, struct ospf6_route *route) | |
1544 | { | |
1545 | u_int32_t adv_router; | |
1546 | char adv[16], rbits[16], options[16], area[16]; | |
1547 | ||
1548 | adv_router = ospf6_linkstate_prefix_adv_router (&route->prefix); | |
1549 | inet_ntop (AF_INET, &adv_router, adv, sizeof (adv)); | |
1550 | ospf6_capability_printbuf (route->path.router_bits, rbits, sizeof (rbits)); | |
1551 | ospf6_options_printbuf (route->path.options, options, sizeof (options)); | |
1552 | inet_ntop (AF_INET, &route->path.area_id, area, sizeof (area)); | |
1553 | ||
55f70b67 DL |
1554 | /* vty_out (vty, "%-15s %-8s %-14s %-10s %-15s\n", |
1555 | "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area"); */ | |
1556 | vty_out (vty, "%-15s %-8s %-14s %-10s %-15s\n", | |
6452df09 | 1557 | adv, rbits, options, OSPF6_PATH_TYPE_NAME (route->path.type), |
55f70b67 | 1558 | area); |
6452df09 | 1559 | } |
1560 | ||
508e53e2 | 1561 | DEFUN (debug_ospf6_route, |
1562 | debug_ospf6_route_cmd, | |
6147e2c6 | 1563 | "debug ospf6 route <table|intra-area|inter-area|memory>", |
508e53e2 | 1564 | DEBUG_STR |
1565 | OSPF6_STR | |
16cedbb0 | 1566 | "Debug routes\n" |
508e53e2 | 1567 | "Debug route table calculation\n" |
508e53e2 | 1568 | "Debug intra-area route calculation\n" |
1569 | "Debug inter-area route calculation\n" | |
8f228de7 | 1570 | "Debug route memory use\n" |
508e53e2 | 1571 | ) |
1572 | { | |
51c26414 | 1573 | int idx_type = 3; |
508e53e2 | 1574 | unsigned char level = 0; |
1575 | ||
51c26414 | 1576 | if (! strncmp (argv[idx_type]->arg, "table", 5)) |
508e53e2 | 1577 | level = OSPF6_DEBUG_ROUTE_TABLE; |
51c26414 | 1578 | else if (! strncmp (argv[idx_type]->arg, "intra", 5)) |
508e53e2 | 1579 | level = OSPF6_DEBUG_ROUTE_INTRA; |
51c26414 | 1580 | else if (! strncmp (argv[idx_type]->arg, "inter", 5)) |
508e53e2 | 1581 | level = OSPF6_DEBUG_ROUTE_INTER; |
51c26414 | 1582 | else if (! strncmp (argv[idx_type]->arg, "memor", 5)) |
8f228de7 | 1583 | level = OSPF6_DEBUG_ROUTE_MEMORY; |
508e53e2 | 1584 | OSPF6_DEBUG_ROUTE_ON (level); |
1585 | return CMD_SUCCESS; | |
1586 | } | |
1587 | ||
1588 | DEFUN (no_debug_ospf6_route, | |
1589 | no_debug_ospf6_route_cmd, | |
6147e2c6 | 1590 | "no debug ospf6 route <table|intra-area|inter-area|memory>", |
508e53e2 | 1591 | NO_STR |
1592 | DEBUG_STR | |
1593 | OSPF6_STR | |
16cedbb0 | 1594 | "Debug routes\n" |
508e53e2 | 1595 | "Debug route table calculation\n" |
8f228de7 | 1596 | "Debug intra-area route calculation\n" |
16cedbb0 | 1597 | "Debug inter-area route calculation\n" |
8f228de7 | 1598 | "Debug route memory use\n") |
508e53e2 | 1599 | { |
51c26414 | 1600 | int idx_type = 4; |
508e53e2 | 1601 | unsigned char level = 0; |
1602 | ||
51c26414 | 1603 | if (! strncmp (argv[idx_type]->arg, "table", 5)) |
508e53e2 | 1604 | level = OSPF6_DEBUG_ROUTE_TABLE; |
51c26414 | 1605 | else if (! strncmp (argv[idx_type]->arg, "intra", 5)) |
508e53e2 | 1606 | level = OSPF6_DEBUG_ROUTE_INTRA; |
51c26414 | 1607 | else if (! strncmp (argv[idx_type]->arg, "inter", 5)) |
508e53e2 | 1608 | level = OSPF6_DEBUG_ROUTE_INTER; |
51c26414 | 1609 | else if (! strncmp (argv[idx_type]->arg, "memor", 5)) |
8f228de7 | 1610 | level = OSPF6_DEBUG_ROUTE_MEMORY; |
508e53e2 | 1611 | OSPF6_DEBUG_ROUTE_OFF (level); |
718e3744 | 1612 | return CMD_SUCCESS; |
1613 | } | |
1614 | ||
508e53e2 | 1615 | int |
1616 | config_write_ospf6_debug_route (struct vty *vty) | |
1617 | { | |
1618 | if (IS_OSPF6_DEBUG_ROUTE (TABLE)) | |
26a429fe | 1619 | vty_out (vty, "debug ospf6 route table\n"); |
508e53e2 | 1620 | if (IS_OSPF6_DEBUG_ROUTE (INTRA)) |
26a429fe | 1621 | vty_out (vty, "debug ospf6 route intra-area\n"); |
508e53e2 | 1622 | if (IS_OSPF6_DEBUG_ROUTE (INTER)) |
26a429fe | 1623 | vty_out (vty, "debug ospf6 route inter-area\n"); |
508e53e2 | 1624 | return 0; |
1625 | } | |
1626 | ||
1627 | void | |
6ac29a51 | 1628 | install_element_ospf6_debug_route (void) |
508e53e2 | 1629 | { |
1630 | install_element (ENABLE_NODE, &debug_ospf6_route_cmd); | |
1631 | install_element (ENABLE_NODE, &no_debug_ospf6_route_cmd); | |
1632 | install_element (CONFIG_NODE, &debug_ospf6_route_cmd); | |
1633 | install_element (CONFIG_NODE, &no_debug_ospf6_route_cmd); | |
1634 | } | |
1635 | ||
1636 | ||
1637 |