]>
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 | { | |
1046 | vty_out (vty, "%c%1s %2s %-30s %-25s %6.*s %s%s", | |
1047 | (ospf6_route_is_best (route) ? '*' : ' '), | |
1048 | OSPF6_DEST_TYPE_SUBSTR (route->type), | |
1049 | OSPF6_PATH_TYPE_SUBSTR (route->path.type), | |
1050 | destination, nexthop, IFNAMSIZ, ifname, duration, VNL); | |
1051 | i++; | |
1052 | } | |
1053 | else | |
1054 | vty_out (vty, "%c%1s %2s %-30s %-25s %6.*s %s%s", | |
1055 | ' ', "", "", "", nexthop, IFNAMSIZ, ifname, "", VNL); | |
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)); |
049207c3 | 1081 | vty_out (vty, "Destination: %s%s", destination, VNL); |
508e53e2 | 1082 | |
1083 | /* destination type */ | |
1084 | vty_out (vty, "Destination type: %s%s", | |
1085 | OSPF6_DEST_TYPE_NAME (route->type), | |
049207c3 | 1086 | VNL); |
508e53e2 | 1087 | |
1088 | /* Time */ | |
1089 | timersub (&now, &route->installed, &res); | |
1090 | timerstring (&res, duration, sizeof (duration)); | |
049207c3 | 1091 | vty_out (vty, "Installed Time: %s ago%s", duration, VNL); |
508e53e2 | 1092 | |
1093 | timersub (&now, &route->changed, &res); | |
1094 | timerstring (&res, duration, sizeof (duration)); | |
049207c3 | 1095 | vty_out (vty, " Changed Time: %s ago%s", duration, VNL); |
508e53e2 | 1096 | |
1097 | /* Debugging info */ | |
1098 | vty_out (vty, "Lock: %d Flags: %s%s%s%s%s", route->lock, | |
1099 | (CHECK_FLAG (route->flag, OSPF6_ROUTE_BEST) ? "B" : "-"), | |
1100 | (CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD) ? "A" : "-"), | |
1101 | (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE) ? "R" : "-"), | |
1102 | (CHECK_FLAG (route->flag, OSPF6_ROUTE_CHANGE) ? "C" : "-"), | |
049207c3 | 1103 | VNL); |
508e53e2 | 1104 | vty_out (vty, "Memory: prev: %p this: %p next: %p%s", |
6c4f4e6e | 1105 | (void *)route->prev, (void *)route, (void *)route->next, VNL); |
508e53e2 | 1106 | |
1107 | /* Path section */ | |
1108 | ||
1109 | /* Area-ID */ | |
1110 | inet_ntop (AF_INET, &route->path.area_id, area_id, sizeof (area_id)); | |
049207c3 | 1111 | vty_out (vty, "Associated Area: %s%s", area_id, VNL); |
508e53e2 | 1112 | |
1113 | /* Path type */ | |
1114 | vty_out (vty, "Path Type: %s%s", | |
049207c3 | 1115 | OSPF6_PATH_TYPE_NAME (route->path.type), VNL); |
508e53e2 | 1116 | |
1117 | /* LS Origin */ | |
1118 | inet_ntop (AF_INET, &route->path.origin.id, id, sizeof (id)); | |
1119 | inet_ntop (AF_INET, &route->path.origin.adv_router, adv_router, | |
1120 | sizeof (adv_router)); | |
1121 | vty_out (vty, "LS Origin: %s Id: %s Adv: %s%s", | |
1e05838a | 1122 | ospf6_lstype_name (route->path.origin.type), |
049207c3 | 1123 | id, adv_router, VNL); |
508e53e2 | 1124 | |
1125 | /* Options */ | |
1126 | ospf6_options_printbuf (route->path.options, options, sizeof (options)); | |
049207c3 | 1127 | vty_out (vty, "Options: %s%s", options, VNL); |
508e53e2 | 1128 | |
1129 | /* Router Bits */ | |
1130 | ospf6_capability_printbuf (route->path.router_bits, capa, sizeof (capa)); | |
049207c3 | 1131 | vty_out (vty, "Router Bits: %s%s", capa, VNL); |
508e53e2 | 1132 | |
1133 | /* Prefix Options */ | |
049207c3 | 1134 | vty_out (vty, "Prefix Options: xxx%s", VNL); |
508e53e2 | 1135 | |
1136 | /* Metrics */ | |
1137 | vty_out (vty, "Metric Type: %d%s", route->path.metric_type, | |
049207c3 | 1138 | VNL); |
508e53e2 | 1139 | vty_out (vty, "Metric: %d (%d)%s", |
c3c0ac83 | 1140 | route->path.cost, route->path.u.cost_e2, VNL); |
508e53e2 | 1141 | |
1142 | /* Nexthops */ | |
049207c3 | 1143 | vty_out (vty, "Nexthop:%s", VNL); |
c3c0ac83 | 1144 | for (ALL_LIST_ELEMENTS_RO (route->nh_list, node, nh)) |
508e53e2 | 1145 | { |
1146 | /* nexthop */ | |
c3c0ac83 | 1147 | inet_ntop (AF_INET6, &nh->address, nexthop, sizeof (nexthop)); |
baaea325 | 1148 | ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT); |
3b7b814c | 1149 | vty_out (vty, " %s %.*s%s", nexthop, IFNAMSIZ, ifname, VNL); |
508e53e2 | 1150 | } |
049207c3 | 1151 | vty_out (vty, "%s", VNL); |
508e53e2 | 1152 | } |
718e3744 | 1153 | |
6ac29a51 | 1154 | static void |
508e53e2 | 1155 | ospf6_route_show_table_summary (struct vty *vty, |
1156 | struct ospf6_route_table *table) | |
1157 | { | |
1158 | struct ospf6_route *route, *prev = NULL; | |
1159 | int i, pathtype[OSPF6_PATH_TYPE_MAX]; | |
0c083ee9 | 1160 | unsigned int number = 0; |
c3c0ac83 | 1161 | int nh_count =0 , nhinval = 0, ecmp = 0; |
4846ef64 | 1162 | int alternative = 0, destination = 0; |
508e53e2 | 1163 | |
1164 | for (i = 0; i < OSPF6_PATH_TYPE_MAX; i++) | |
1165 | pathtype[i] = 0; | |
1166 | ||
1167 | for (route = ospf6_route_head (table); route; | |
1168 | route = ospf6_route_next (route)) | |
718e3744 | 1169 | { |
508e53e2 | 1170 | if (prev == NULL || ! ospf6_route_is_same (prev, route)) |
1171 | destination++; | |
1172 | else | |
4846ef64 | 1173 | alternative++; |
c3c0ac83 DS |
1174 | nh_count = ospf6_num_nexthops (route->nh_list); |
1175 | if (!nh_count) | |
508e53e2 | 1176 | nhinval++; |
c3c0ac83 | 1177 | else if (nh_count > 1) |
508e53e2 | 1178 | ecmp++; |
4846ef64 | 1179 | pathtype[route->path.type]++; |
508e53e2 | 1180 | number++; |
4846ef64 | 1181 | |
508e53e2 | 1182 | prev = route; |
1183 | } | |
718e3744 | 1184 | |
508e53e2 | 1185 | assert (number == table->count); |
508e53e2 | 1186 | |
4846ef64 | 1187 | vty_out (vty, "Number of OSPFv3 routes: %d%s", number, VNL); |
1188 | vty_out (vty, "Number of Destination: %d%s", destination, VNL); | |
1189 | vty_out (vty, "Number of Alternative routes: %d%s", alternative, VNL); | |
1190 | vty_out (vty, "Number of Equal Cost Multi Path: %d%s", ecmp, VNL); | |
1191 | for (i = OSPF6_PATH_TYPE_INTRA; i <= OSPF6_PATH_TYPE_EXTERNAL2; i++) | |
1192 | { | |
1193 | vty_out (vty, "Number of %s routes: %d%s", | |
1194 | OSPF6_PATH_TYPE_NAME (i), pathtype[i], VNL); | |
1195 | } | |
1196 | } | |
1197 | ||
6ac29a51 | 1198 | static void |
4846ef64 | 1199 | ospf6_route_show_table_prefix (struct vty *vty, |
1200 | struct prefix *prefix, | |
1201 | struct ospf6_route_table *table) | |
1202 | { | |
1203 | struct ospf6_route *route; | |
1204 | ||
1205 | route = ospf6_route_lookup (prefix, table); | |
1206 | if (route == NULL) | |
1207 | return; | |
1208 | ||
1209 | ospf6_route_lock (route); | |
1210 | while (route && ospf6_route_is_prefix (prefix, route)) | |
1211 | { | |
1212 | /* Specifying a prefix will always display details */ | |
1213 | ospf6_route_show_detail (vty, route); | |
1214 | route = ospf6_route_next (route); | |
1215 | } | |
1216 | if (route) | |
1217 | ospf6_route_unlock (route); | |
1218 | } | |
1219 | ||
6ac29a51 | 1220 | static void |
4846ef64 | 1221 | ospf6_route_show_table_address (struct vty *vty, |
1222 | struct prefix *prefix, | |
1223 | struct ospf6_route_table *table) | |
1224 | { | |
1225 | struct ospf6_route *route; | |
1226 | ||
1227 | route = ospf6_route_lookup_bestmatch (prefix, table); | |
1228 | if (route == NULL) | |
1229 | return; | |
1230 | ||
1231 | prefix = &route->prefix; | |
1232 | ospf6_route_lock (route); | |
1233 | while (route && ospf6_route_is_prefix (prefix, route)) | |
1234 | { | |
1235 | /* Specifying a prefix will always display details */ | |
1236 | ospf6_route_show_detail (vty, route); | |
1237 | route = ospf6_route_next (route); | |
1238 | } | |
1239 | if (route) | |
1240 | ospf6_route_unlock (route); | |
1241 | } | |
1242 | ||
6ac29a51 | 1243 | static void |
4846ef64 | 1244 | ospf6_route_show_table_match (struct vty *vty, int detail, |
1245 | struct prefix *prefix, | |
1246 | struct ospf6_route_table *table) | |
1247 | { | |
1248 | struct ospf6_route *route; | |
1249 | assert (prefix->family); | |
1250 | ||
1251 | route = ospf6_route_match_head (prefix, table); | |
1252 | while (route) | |
1253 | { | |
1254 | if (detail) | |
1255 | ospf6_route_show_detail (vty, route); | |
1256 | else | |
1257 | ospf6_route_show (vty, route); | |
1258 | route = ospf6_route_match_next (prefix, route); | |
1259 | } | |
1260 | } | |
1261 | ||
6ac29a51 | 1262 | static void |
4846ef64 | 1263 | ospf6_route_show_table_type (struct vty *vty, int detail, u_char type, |
1264 | struct ospf6_route_table *table) | |
1265 | { | |
1266 | struct ospf6_route *route; | |
1267 | ||
1268 | route = ospf6_route_head (table); | |
1269 | while (route) | |
1270 | { | |
1271 | if (route->path.type == type) | |
1272 | { | |
1273 | if (detail) | |
1274 | ospf6_route_show_detail (vty, route); | |
1275 | else | |
1276 | ospf6_route_show (vty, route); | |
1277 | } | |
1278 | route = ospf6_route_next (route); | |
1279 | } | |
1280 | } | |
1281 | ||
6ac29a51 | 1282 | static void |
4846ef64 | 1283 | ospf6_route_show_table (struct vty *vty, int detail, |
1284 | struct ospf6_route_table *table) | |
1285 | { | |
1286 | struct ospf6_route *route; | |
1287 | ||
1288 | route = ospf6_route_head (table); | |
1289 | while (route) | |
508e53e2 | 1290 | { |
4846ef64 | 1291 | if (detail) |
1292 | ospf6_route_show_detail (vty, route); | |
1293 | else | |
1294 | ospf6_route_show (vty, route); | |
1295 | route = ospf6_route_next (route); | |
718e3744 | 1296 | } |
1297 | } | |
1298 | ||
508e53e2 | 1299 | int |
1d68dbfe | 1300 | ospf6_route_table_show (struct vty *vty, int argc_start, int argc, struct cmd_token **argv, |
508e53e2 | 1301 | struct ospf6_route_table *table) |
718e3744 | 1302 | { |
4846ef64 | 1303 | int summary = 0; |
1304 | int match = 0; | |
1305 | int detail = 0; | |
1306 | int slash = 0; | |
1307 | int isprefix = 0; | |
508e53e2 | 1308 | int i, ret; |
4846ef64 | 1309 | struct prefix prefix; |
1310 | u_char type = 0; | |
718e3744 | 1311 | |
508e53e2 | 1312 | memset (&prefix, 0, sizeof (struct prefix)); |
718e3744 | 1313 | |
1d68dbfe | 1314 | for (i = argc_start; i < argc; i++) |
508e53e2 | 1315 | { |
cc9de1ba | 1316 | if (! strcmp (argv[i]->arg, "summary")) |
508e53e2 | 1317 | { |
4846ef64 | 1318 | summary++; |
508e53e2 | 1319 | continue; |
1320 | } | |
718e3744 | 1321 | |
cc9de1ba | 1322 | if (! strcmp (argv[i]->arg, "intra-area")) |
508e53e2 | 1323 | { |
4846ef64 | 1324 | type = OSPF6_PATH_TYPE_INTRA; |
508e53e2 | 1325 | continue; |
1326 | } | |
1327 | ||
cc9de1ba | 1328 | if (! strcmp (argv[i]->arg, "inter-area")) |
508e53e2 | 1329 | { |
4846ef64 | 1330 | type = OSPF6_PATH_TYPE_INTER; |
508e53e2 | 1331 | continue; |
1332 | } | |
718e3744 | 1333 | |
cc9de1ba | 1334 | if (! strcmp (argv[i]->arg, "external-1")) |
508e53e2 | 1335 | { |
4846ef64 | 1336 | type = OSPF6_PATH_TYPE_EXTERNAL1; |
1337 | continue; | |
1338 | } | |
1339 | ||
cc9de1ba | 1340 | if (! strcmp (argv[i]->arg, "external-2")) |
4846ef64 | 1341 | { |
1342 | type = OSPF6_PATH_TYPE_EXTERNAL2; | |
1343 | continue; | |
1344 | } | |
1345 | ||
cc9de1ba | 1346 | if (! strcmp (argv[i]->arg, "detail")) |
4846ef64 | 1347 | { |
1348 | detail++; | |
1349 | continue; | |
1350 | } | |
1351 | ||
cc9de1ba | 1352 | if (! strcmp (argv[i]->arg, "match")) |
4846ef64 | 1353 | { |
1354 | match++; | |
1355 | continue; | |
508e53e2 | 1356 | } |
718e3744 | 1357 | |
cc9de1ba | 1358 | ret = str2prefix (argv[i]->arg, &prefix); |
4846ef64 | 1359 | if (ret == 1 && prefix.family == AF_INET6) |
718e3744 | 1360 | { |
4846ef64 | 1361 | isprefix++; |
cc9de1ba | 1362 | if (strchr (argv[i]->arg, '/')) |
4846ef64 | 1363 | slash++; |
1364 | continue; | |
508e53e2 | 1365 | } |
718e3744 | 1366 | |
cc9de1ba | 1367 | vty_out (vty, "Malformed argument: %s%s", argv[i]->arg, VNL); |
4846ef64 | 1368 | return CMD_SUCCESS; |
508e53e2 | 1369 | } |
718e3744 | 1370 | |
508e53e2 | 1371 | /* Give summary of this route table */ |
4846ef64 | 1372 | if (summary) |
508e53e2 | 1373 | { |
1374 | ospf6_route_show_table_summary (vty, table); | |
1375 | return CMD_SUCCESS; | |
1376 | } | |
718e3744 | 1377 | |
508e53e2 | 1378 | /* Give exact prefix-match route */ |
4846ef64 | 1379 | if (isprefix && ! match) |
508e53e2 | 1380 | { |
1381 | /* If exact address, give best matching route */ | |
4846ef64 | 1382 | if (! slash) |
1383 | ospf6_route_show_table_address (vty, &prefix, table); | |
508e53e2 | 1384 | else |
4846ef64 | 1385 | ospf6_route_show_table_prefix (vty, &prefix, table); |
508e53e2 | 1386 | |
4846ef64 | 1387 | return CMD_SUCCESS; |
1388 | } | |
508e53e2 | 1389 | |
4846ef64 | 1390 | if (match) |
1391 | ospf6_route_show_table_match (vty, detail, &prefix, table); | |
1392 | else if (type) | |
1393 | ospf6_route_show_table_type (vty, detail, type, table); | |
1394 | else | |
1395 | ospf6_route_show_table (vty, detail, table); | |
508e53e2 | 1396 | |
4846ef64 | 1397 | return CMD_SUCCESS; |
1398 | } | |
508e53e2 | 1399 | |
6ac29a51 | 1400 | static void |
4846ef64 | 1401 | ospf6_linkstate_show_header (struct vty *vty) |
1402 | { | |
1403 | vty_out (vty, "%-7s %-15s %-15s %-8s %-14s %s%s", | |
1404 | "Type", "Router-ID", "Net-ID", "Rtr-Bits", "Options", "Cost", VNL); | |
1405 | } | |
1406 | ||
6ac29a51 | 1407 | static void |
4846ef64 | 1408 | ospf6_linkstate_show (struct vty *vty, struct ospf6_route *route) |
1409 | { | |
1410 | u_int32_t router, id; | |
1411 | char routername[16], idname[16], rbits[16], options[16]; | |
1412 | ||
1413 | router = ospf6_linkstate_prefix_adv_router (&route->prefix); | |
1414 | inet_ntop (AF_INET, &router, routername, sizeof (routername)); | |
1415 | id = ospf6_linkstate_prefix_id (&route->prefix); | |
1416 | inet_ntop (AF_INET, &id, idname, sizeof (idname)); | |
1417 | ||
1418 | ospf6_capability_printbuf (route->path.router_bits, rbits, sizeof (rbits)); | |
1419 | ospf6_options_printbuf (route->path.options, options, sizeof (options)); | |
508e53e2 | 1420 | |
4846ef64 | 1421 | if (ntohl (id)) |
1422 | vty_out (vty, "%-7s %-15s %-15s %-8s %-14s %lu%s", | |
1423 | "Network", routername, idname, rbits, options, | |
1424 | (unsigned long) route->path.cost, VNL); | |
508e53e2 | 1425 | else |
4846ef64 | 1426 | vty_out (vty, "%-7s %-15s %-15s %-8s %-14s %lu%s", |
1427 | "Router", routername, idname, rbits, options, | |
1428 | (unsigned long) route->path.cost, VNL); | |
1429 | } | |
1430 | ||
1431 | ||
6ac29a51 | 1432 | static void |
4846ef64 | 1433 | ospf6_linkstate_show_table_exact (struct vty *vty, |
1434 | struct prefix *prefix, | |
1435 | struct ospf6_route_table *table) | |
1436 | { | |
1437 | struct ospf6_route *route; | |
1438 | ||
1439 | route = ospf6_route_lookup (prefix, table); | |
1440 | if (route == NULL) | |
1441 | return; | |
1442 | ||
1443 | ospf6_route_lock (route); | |
1444 | while (route && ospf6_route_is_prefix (prefix, route)) | |
1445 | { | |
1446 | /* Specifying a prefix will always display details */ | |
1447 | ospf6_route_show_detail (vty, route); | |
1448 | route = ospf6_route_next (route); | |
1449 | } | |
1450 | if (route) | |
1451 | ospf6_route_unlock (route); | |
1452 | } | |
1453 | ||
6ac29a51 | 1454 | static void |
4846ef64 | 1455 | ospf6_linkstate_show_table (struct vty *vty, int detail, |
1456 | struct ospf6_route_table *table) | |
1457 | { | |
1458 | struct ospf6_route *route; | |
1459 | ||
1460 | if (! detail) | |
1461 | ospf6_linkstate_show_header (vty); | |
508e53e2 | 1462 | |
4846ef64 | 1463 | route = ospf6_route_head (table); |
508e53e2 | 1464 | while (route) |
1465 | { | |
4846ef64 | 1466 | if (detail) |
508e53e2 | 1467 | ospf6_route_show_detail (vty, route); |
1468 | else | |
4846ef64 | 1469 | ospf6_linkstate_show (vty, route); |
1470 | route = ospf6_route_next (route); | |
508e53e2 | 1471 | } |
718e3744 | 1472 | } |
1473 | ||
1474 | int | |
093d7a3a DW |
1475 | ospf6_linkstate_table_show (struct vty *vty, int idx_ipv4, int argc, |
1476 | struct cmd_token **argv, | |
4846ef64 | 1477 | struct ospf6_route_table *table) |
718e3744 | 1478 | { |
4846ef64 | 1479 | int detail = 0; |
1480 | int is_id = 0; | |
1481 | int is_router = 0; | |
718e3744 | 1482 | int i, ret; |
4846ef64 | 1483 | struct prefix router, id, prefix; |
718e3744 | 1484 | |
4846ef64 | 1485 | memset (&router, 0, sizeof (struct prefix)); |
508e53e2 | 1486 | memset (&id, 0, sizeof (struct prefix)); |
4846ef64 | 1487 | memset (&prefix, 0, sizeof (struct prefix)); |
718e3744 | 1488 | |
093d7a3a | 1489 | for (i = idx_ipv4; i < argc; i++) |
718e3744 | 1490 | { |
cc9de1ba | 1491 | if (! strcmp (argv[i]->arg, "detail")) |
718e3744 | 1492 | { |
4846ef64 | 1493 | detail++; |
508e53e2 | 1494 | continue; |
718e3744 | 1495 | } |
1496 | ||
4846ef64 | 1497 | if (! is_router) |
718e3744 | 1498 | { |
cc9de1ba | 1499 | ret = str2prefix (argv[i]->arg, &router); |
4846ef64 | 1500 | if (ret == 1 && router.family == AF_INET) |
718e3744 | 1501 | { |
4846ef64 | 1502 | is_router++; |
1503 | continue; | |
718e3744 | 1504 | } |
cc9de1ba | 1505 | vty_out (vty, "Malformed argument: %s%s", argv[i]->arg, VNL); |
4846ef64 | 1506 | return CMD_SUCCESS; |
508e53e2 | 1507 | } |
508e53e2 | 1508 | |
4846ef64 | 1509 | if (! is_id) |
1510 | { | |
cc9de1ba | 1511 | ret = str2prefix (argv[i]->arg, &id); |
4846ef64 | 1512 | if (ret == 1 && id.family == AF_INET) |
718e3744 | 1513 | { |
4846ef64 | 1514 | is_id++; |
1515 | continue; | |
718e3744 | 1516 | } |
cc9de1ba | 1517 | vty_out (vty, "Malformed argument: %s%s", argv[i]->arg, VNL); |
508e53e2 | 1518 | return CMD_SUCCESS; |
1519 | } | |
1520 | ||
cc9de1ba | 1521 | vty_out (vty, "Malformed argument: %s%s", argv[i]->arg, VNL); |
508e53e2 | 1522 | return CMD_SUCCESS; |
718e3744 | 1523 | } |
1524 | ||
4846ef64 | 1525 | if (is_router) |
1526 | ospf6_linkstate_prefix (router.u.prefix4.s_addr, | |
1527 | id.u.prefix4.s_addr, &prefix); | |
718e3744 | 1528 | |
4846ef64 | 1529 | if (prefix.family) |
1530 | ospf6_linkstate_show_table_exact (vty, &prefix, table); | |
1531 | else | |
1532 | ospf6_linkstate_show_table (vty, detail, table); | |
718e3744 | 1533 | |
508e53e2 | 1534 | return CMD_SUCCESS; |
1535 | } | |
718e3744 | 1536 | |
4846ef64 | 1537 | |
6452df09 | 1538 | void |
1539 | ospf6_brouter_show_header (struct vty *vty) | |
1540 | { | |
1541 | vty_out (vty, "%-15s %-8s %-14s %-10s %-15s%s", | |
1542 | "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area", VNL); | |
1543 | } | |
1544 | ||
1545 | void | |
1546 | ospf6_brouter_show (struct vty *vty, struct ospf6_route *route) | |
1547 | { | |
1548 | u_int32_t adv_router; | |
1549 | char adv[16], rbits[16], options[16], area[16]; | |
1550 | ||
1551 | adv_router = ospf6_linkstate_prefix_adv_router (&route->prefix); | |
1552 | inet_ntop (AF_INET, &adv_router, adv, sizeof (adv)); | |
1553 | ospf6_capability_printbuf (route->path.router_bits, rbits, sizeof (rbits)); | |
1554 | ospf6_options_printbuf (route->path.options, options, sizeof (options)); | |
1555 | inet_ntop (AF_INET, &route->path.area_id, area, sizeof (area)); | |
1556 | ||
1557 | /* vty_out (vty, "%-15s %-8s %-14s %-10s %-15s%s", | |
1558 | "Router-ID", "Rtr-Bits", "Options", "Path-Type", "Area", VNL); */ | |
1559 | vty_out (vty, "%-15s %-8s %-14s %-10s %-15s%s", | |
1560 | adv, rbits, options, OSPF6_PATH_TYPE_NAME (route->path.type), | |
1561 | area, VNL); | |
1562 | } | |
1563 | ||
508e53e2 | 1564 | DEFUN (debug_ospf6_route, |
1565 | debug_ospf6_route_cmd, | |
6147e2c6 | 1566 | "debug ospf6 route <table|intra-area|inter-area|memory>", |
508e53e2 | 1567 | DEBUG_STR |
1568 | OSPF6_STR | |
16cedbb0 | 1569 | "Debug routes\n" |
508e53e2 | 1570 | "Debug route table calculation\n" |
508e53e2 | 1571 | "Debug intra-area route calculation\n" |
1572 | "Debug inter-area route calculation\n" | |
8f228de7 | 1573 | "Debug route memory use\n" |
508e53e2 | 1574 | ) |
1575 | { | |
51c26414 | 1576 | int idx_type = 3; |
508e53e2 | 1577 | unsigned char level = 0; |
1578 | ||
51c26414 | 1579 | if (! strncmp (argv[idx_type]->arg, "table", 5)) |
508e53e2 | 1580 | level = OSPF6_DEBUG_ROUTE_TABLE; |
51c26414 | 1581 | else if (! strncmp (argv[idx_type]->arg, "intra", 5)) |
508e53e2 | 1582 | level = OSPF6_DEBUG_ROUTE_INTRA; |
51c26414 | 1583 | else if (! strncmp (argv[idx_type]->arg, "inter", 5)) |
508e53e2 | 1584 | level = OSPF6_DEBUG_ROUTE_INTER; |
51c26414 | 1585 | else if (! strncmp (argv[idx_type]->arg, "memor", 5)) |
8f228de7 | 1586 | level = OSPF6_DEBUG_ROUTE_MEMORY; |
508e53e2 | 1587 | OSPF6_DEBUG_ROUTE_ON (level); |
1588 | return CMD_SUCCESS; | |
1589 | } | |
1590 | ||
1591 | DEFUN (no_debug_ospf6_route, | |
1592 | no_debug_ospf6_route_cmd, | |
6147e2c6 | 1593 | "no debug ospf6 route <table|intra-area|inter-area|memory>", |
508e53e2 | 1594 | NO_STR |
1595 | DEBUG_STR | |
1596 | OSPF6_STR | |
16cedbb0 | 1597 | "Debug routes\n" |
508e53e2 | 1598 | "Debug route table calculation\n" |
8f228de7 | 1599 | "Debug intra-area route calculation\n" |
16cedbb0 | 1600 | "Debug inter-area route calculation\n" |
8f228de7 | 1601 | "Debug route memory use\n") |
508e53e2 | 1602 | { |
51c26414 | 1603 | int idx_type = 4; |
508e53e2 | 1604 | unsigned char level = 0; |
1605 | ||
51c26414 | 1606 | if (! strncmp (argv[idx_type]->arg, "table", 5)) |
508e53e2 | 1607 | level = OSPF6_DEBUG_ROUTE_TABLE; |
51c26414 | 1608 | else if (! strncmp (argv[idx_type]->arg, "intra", 5)) |
508e53e2 | 1609 | level = OSPF6_DEBUG_ROUTE_INTRA; |
51c26414 | 1610 | else if (! strncmp (argv[idx_type]->arg, "inter", 5)) |
508e53e2 | 1611 | level = OSPF6_DEBUG_ROUTE_INTER; |
51c26414 | 1612 | else if (! strncmp (argv[idx_type]->arg, "memor", 5)) |
8f228de7 | 1613 | level = OSPF6_DEBUG_ROUTE_MEMORY; |
508e53e2 | 1614 | OSPF6_DEBUG_ROUTE_OFF (level); |
718e3744 | 1615 | return CMD_SUCCESS; |
1616 | } | |
1617 | ||
508e53e2 | 1618 | int |
1619 | config_write_ospf6_debug_route (struct vty *vty) | |
1620 | { | |
1621 | if (IS_OSPF6_DEBUG_ROUTE (TABLE)) | |
049207c3 | 1622 | vty_out (vty, "debug ospf6 route table%s", VNL); |
508e53e2 | 1623 | if (IS_OSPF6_DEBUG_ROUTE (INTRA)) |
049207c3 | 1624 | vty_out (vty, "debug ospf6 route intra-area%s", VNL); |
508e53e2 | 1625 | if (IS_OSPF6_DEBUG_ROUTE (INTER)) |
049207c3 | 1626 | vty_out (vty, "debug ospf6 route inter-area%s", VNL); |
508e53e2 | 1627 | return 0; |
1628 | } | |
1629 | ||
1630 | void | |
6ac29a51 | 1631 | install_element_ospf6_debug_route (void) |
508e53e2 | 1632 | { |
1633 | install_element (ENABLE_NODE, &debug_ospf6_route_cmd); | |
1634 | install_element (ENABLE_NODE, &no_debug_ospf6_route_cmd); | |
1635 | install_element (CONFIG_NODE, &debug_ospf6_route_cmd); | |
1636 | install_element (CONFIG_NODE, &no_debug_ospf6_route_cmd); | |
1637 | } | |
1638 | ||
1639 | ||
1640 |