blob: 2d4b10f9798e00ca759761b2088525802d5a09f4 [file] [log] [blame]
hasso049207c2004-08-04 20:02:13 +00001/*
2 * Area Border Router function.
3 * Copyright (C) 2004 Yasuhiro Ohara
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "log.h"
26#include "prefix.h"
27#include "table.h"
28#include "vty.h"
29#include "linklist.h"
30#include "command.h"
hasso3b687352004-08-19 06:56:53 +000031#include "thread.h"
hasso049207c2004-08-04 20:02:13 +000032
33#include "ospf6_proto.h"
34#include "ospf6_route.h"
35#include "ospf6_lsa.h"
36#include "ospf6_route.h"
37#include "ospf6_lsdb.h"
hasso6452df02004-08-15 05:52:07 +000038#include "ospf6_message.h"
39
hasso049207c2004-08-04 20:02:13 +000040#include "ospf6_top.h"
41#include "ospf6_area.h"
42#include "ospf6_interface.h"
hasso6452df02004-08-15 05:52:07 +000043#include "ospf6_neighbor.h"
44
hasso6452df02004-08-15 05:52:07 +000045#include "ospf6_flood.h"
hasso3b687352004-08-19 06:56:53 +000046#include "ospf6_intra.h"
47#include "ospf6_abr.h"
hasso049207c2004-08-04 20:02:13 +000048#include "ospf6d.h"
49
50unsigned char conf_debug_ospf6_abr;
51
hasso6452df02004-08-15 05:52:07 +000052int
53ospf6_is_router_abr (struct ospf6 *o)
54{
55 listnode node;
56 struct ospf6_area *oa;
57 int area_count = 0;
58
59 for (node = listhead (o->area_list); node; nextnode (node))
60 {
61 oa = OSPF6_AREA (getdata (node));
62 if (IS_AREA_ENABLED (oa))
63 area_count++;
64 }
65
66 if (area_count > 1)
67 return 1;
68 return 0;
69}
70
hasso3b687352004-08-19 06:56:53 +000071void
72ospf6_abr_enable_area (struct ospf6_area *area)
73{
74 struct ospf6_area *oa;
75 struct ospf6_route *ro;
76 listnode node;
77
78 for (node = listhead (area->ospf6->area_list); node; nextnode (node))
79 {
80 oa = OSPF6_AREA (getdata (node));
81
82 /* update B bit for each area */
83 OSPF6_ROUTER_LSA_SCHEDULE (oa);
84
85 /* install other area's configured address range */
86 if (oa != area)
87 {
88 for (ro = ospf6_route_head (oa->range_table); ro;
89 ro = ospf6_route_next (ro))
90 ospf6_abr_originate_summary_to_area (ro, area);
91 }
92 }
93
94 /* install calculated routes to border routers */
95 for (ro = ospf6_route_head (area->ospf6->brouter_table); ro;
96 ro = ospf6_route_next (ro))
97 ospf6_abr_originate_summary_to_area (ro, area);
98
99 /* install calculated routes to network (may be rejected by ranges) */
100 for (ro = ospf6_route_head (area->ospf6->route_table); ro;
101 ro = ospf6_route_next (ro))
102 ospf6_abr_originate_summary_to_area (ro, area);
103}
104
105void
106ospf6_abr_disable_area (struct ospf6_area *area)
107{
108 struct ospf6_area *oa;
109 struct ospf6_route *ro;
110 struct ospf6_lsa *old;
111 listnode node;
112
113 /* Withdraw all summary prefixes previously originated */
114 for (ro = ospf6_route_head (area->summary_prefix); ro;
115 ro = ospf6_route_next (ro))
116 {
117 old = ospf6_lsdb_lookup (ro->path.origin.type, ro->path.origin.id,
118 area->ospf6->router_id, area->lsdb);
119 if (old)
120 ospf6_lsa_purge (old);
121 ospf6_route_remove (ro, area->summary_prefix);
122 }
123
124 /* Withdraw all summary router-routes previously originated */
125 for (ro = ospf6_route_head (area->summary_router); ro;
126 ro = ospf6_route_next (ro))
127 {
128 old = ospf6_lsdb_lookup (ro->path.origin.type, ro->path.origin.id,
129 area->ospf6->router_id, area->lsdb);
130 if (old)
131 ospf6_lsa_purge (old);
132 ospf6_route_remove (ro, area->summary_router);
133 }
134
135 /* Schedule Router-LSA for each area (ABR status may change) */
136 for (node = listhead (area->ospf6->area_list); node; nextnode (node))
137 {
138 oa = OSPF6_AREA (getdata (node));
139
140 /* update B bit for each area */
141 OSPF6_ROUTER_LSA_SCHEDULE (oa);
142 }
143}
144
hasso049207c2004-08-04 20:02:13 +0000145/* RFC 2328 12.4.3. Summary-LSAs */
146void
hasso6452df02004-08-15 05:52:07 +0000147ospf6_abr_originate_summary_to_area (struct ospf6_route *route,
148 struct ospf6_area *area)
hasso049207c2004-08-04 20:02:13 +0000149{
150 struct ospf6_lsa *lsa, *old = NULL;
151 struct ospf6_interface *oi;
152 struct ospf6_route *summary, *range = NULL;
153 struct ospf6_area *route_area;
154 char buffer[OSPF6_MAX_LSASIZE];
155 struct ospf6_lsa_header *lsa_header;
156 caddr_t p;
157 struct ospf6_inter_prefix_lsa *prefix_lsa;
hasso6452df02004-08-15 05:52:07 +0000158 struct ospf6_inter_router_lsa *router_lsa;
159 struct ospf6_route_table *summary_table = NULL;
160 u_int16_t type;
hasso049207c2004-08-04 20:02:13 +0000161
hasso6452df02004-08-15 05:52:07 +0000162 if (IS_OSPF6_DEBUG_ABR)
163 {
164 char buf[64];
165 if (route->type == OSPF6_DEST_TYPE_ROUTER)
166 {
hasso3b687352004-08-19 06:56:53 +0000167 inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
hasso6452df02004-08-15 05:52:07 +0000168 buf, sizeof (buf));
169 zlog_info ("Originating summary in area %s for ASBR %s",
170 area->name, buf);
171 }
172 else
173 {
174 prefix2str (&route->prefix, buf, sizeof (buf));
175 zlog_info ("Originating summary in area %s for %s",
176 area->name, buf);
177 }
178 }
179
180 if (route->type == OSPF6_DEST_TYPE_ROUTER)
181 summary_table = area->summary_router;
182 else
183 summary_table = area->summary_prefix;
184 summary = ospf6_route_lookup (&route->prefix, summary_table);
hasso049207c2004-08-04 20:02:13 +0000185 if (summary)
hasso6452df02004-08-15 05:52:07 +0000186 old = ospf6_lsdb_lookup (summary->path.origin.type,
hasso049207c2004-08-04 20:02:13 +0000187 summary->path.origin.id,
188 area->ospf6->router_id, area->lsdb);
189
190 /* if this route has just removed, remove corresponding LSA */
191 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
192 {
hasso6452df02004-08-15 05:52:07 +0000193 if (IS_OSPF6_DEBUG_ABR)
194 zlog_info ("The route has just removed, purge previous LSA");
195 if (summary)
196 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000197 if (old)
hasso6452df02004-08-15 05:52:07 +0000198 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000199 return;
200 }
201
hasso6452df02004-08-15 05:52:07 +0000202 /* Only destination type network, range or ASBR are considered */
203 if (route->type != OSPF6_DEST_TYPE_NETWORK &&
204 route->type != OSPF6_DEST_TYPE_RANGE &&
205 (route->type != OSPF6_DEST_TYPE_ROUTER ||
206 ! CHECK_FLAG (route->path.router_bits, OSPF6_ROUTER_BIT_E)))
hasso049207c2004-08-04 20:02:13 +0000207 {
hasso6452df02004-08-15 05:52:07 +0000208 if (IS_OSPF6_DEBUG_ABR)
209 zlog_info ("Route type is none of network, range nor ASBR, withdraw");
210 if (summary)
211 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000212 if (old)
hasso6452df02004-08-15 05:52:07 +0000213 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000214 return;
215 }
216
217 /* AS External routes are never considered */
218 if (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
219 route->path.type == OSPF6_PATH_TYPE_EXTERNAL2)
220 {
hasso6452df02004-08-15 05:52:07 +0000221 if (IS_OSPF6_DEBUG_ABR)
222 zlog_info ("Path type is external, withdraw");
223 if (summary)
224 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000225 if (old)
hasso6452df02004-08-15 05:52:07 +0000226 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000227 return;
228 }
229
230 /* do not generate if the path's area is the same as target area */
231 if (route->path.area_id == area->area_id)
232 {
hasso6452df02004-08-15 05:52:07 +0000233 if (IS_OSPF6_DEBUG_ABR)
234 zlog_info ("The route is in the area itself, ignore");
235 if (summary)
236 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000237 if (old)
hasso6452df02004-08-15 05:52:07 +0000238 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000239 return;
240 }
241
242 /* do not generate if the nexthops belongs to the target area */
243 oi = ospf6_interface_lookup_by_ifindex (route->nexthop[0].ifindex);
hasso6452df02004-08-15 05:52:07 +0000244 if (oi && oi->area && oi->area == area)
hasso049207c2004-08-04 20:02:13 +0000245 {
hasso6452df02004-08-15 05:52:07 +0000246 if (IS_OSPF6_DEBUG_ABR)
247 zlog_info ("The route's nexthop is in the same area, ignore");
248 if (summary)
249 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000250 if (old)
hasso6452df02004-08-15 05:52:07 +0000251 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000252 return;
253 }
254
hasso6452df02004-08-15 05:52:07 +0000255 /* do not generate if the route cost is greater or equal to LSInfinity */
256 if (route->path.cost >= LS_INFINITY)
257 {
258 if (IS_OSPF6_DEBUG_ABR)
259 zlog_info ("The cost exceeds LSInfinity, withdraw");
260 if (summary)
261 ospf6_route_remove (summary, summary_table);
262 if (old)
263 ospf6_lsa_purge (old);
264 return;
265 }
266
267 /* if this is a route to ASBR */
268 if (route->type == OSPF6_DEST_TYPE_ROUTER)
269 {
270 /* Only the prefered best path is considered */
271 if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_BEST))
272 {
273 if (IS_OSPF6_DEBUG_ABR)
274 zlog_info ("This is the secondary path to the ASBR, ignore");
275 if (summary)
276 ospf6_route_remove (summary, summary_table);
277 if (old)
278 ospf6_lsa_purge (old);
279 return;
280 }
281
282 /* Do not generate if the area is stub */
283 /* XXX */
284 }
285
286 /* if this is an intra-area route, this may be suppressed by aggregation */
287 if (route->type == OSPF6_DEST_TYPE_NETWORK &&
288 route->path.type == OSPF6_PATH_TYPE_INTRA)
289 {
290 /* search for configured address range for the route's area */
291 route_area = ospf6_area_lookup (route->path.area_id, area->ospf6);
292 assert (route_area);
293 range = ospf6_route_lookup_bestmatch (&route->prefix,
294 route_area->range_table);
295
296 /* ranges are ignored when originate backbone routes to transit area.
297 Otherwise, if ranges are configured, the route is suppressed. */
298 if (range && ! CHECK_FLAG (range->flag, OSPF6_ROUTE_REMOVE) &&
299 (route->path.area_id != BACKBONE_AREA_ID ||
300 ! IS_AREA_TRANSIT (area)))
301 {
302 if (IS_OSPF6_DEBUG_ABR)
303 {
304 char buf[64];
305 prefix2str (&range->prefix, buf, sizeof (buf));
306 zlog_info ("Suppressed by range %s of area %s",
307 buf, route_area->name);
308 }
309
310 if (summary)
311 ospf6_route_remove (summary, summary_table);
312 if (old)
313 ospf6_lsa_purge (old);
314 return;
315 }
316 }
317
318 /* If this is a configured address range */
319 if (route->type == OSPF6_DEST_TYPE_RANGE)
320 {
321 /* If DoNotAdvertise is set */
322 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE))
323 {
324 if (IS_OSPF6_DEBUG_ABR)
325 zlog_info ("This is the range with DoNotAdvertise set. ignore");
326 if (summary)
327 ospf6_route_remove (summary, summary_table);
328 if (old)
329 ospf6_lsa_purge (old);
330 return;
331 }
332
333 /* Whether the route have active longer prefix */
334 if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_ACTIVE_SUMMARY))
335 {
336 if (IS_OSPF6_DEBUG_ABR)
337 zlog_info ("The range is not active. withdraw");
338 if (summary)
339 ospf6_route_remove (summary, summary_table);
340 if (old)
341 ospf6_lsa_purge (old);
342 return;
343 }
344 }
345
hasso049207c2004-08-04 20:02:13 +0000346 /* the route is going to be originated. store it in area's summary_table */
347 if (summary == NULL)
348 {
349 summary = ospf6_route_copy (route);
hasso6452df02004-08-15 05:52:07 +0000350 if (route->type == OSPF6_DEST_TYPE_NETWORK ||
351 route->type == OSPF6_DEST_TYPE_RANGE)
352 summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_PREFIX);
353 else
354 summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_ROUTER);
hasso049207c2004-08-04 20:02:13 +0000355 summary->path.origin.adv_router = area->ospf6->router_id;
356 summary->path.origin.id =
357 ospf6_new_ls_id (summary->path.origin.type,
358 summary->path.origin.adv_router, area->lsdb);
hasso6452df02004-08-15 05:52:07 +0000359 ospf6_route_add (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000360 }
hasso6452df02004-08-15 05:52:07 +0000361 else
362 {
363 summary->type = route->type;
364 gettimeofday (&summary->changed, NULL);
365 }
366
367 summary->path.router_bits = route->path.router_bits;
368 summary->path.options[0] = route->path.options[0];
369 summary->path.options[1] = route->path.options[1];
370 summary->path.options[2] = route->path.options[2];
371 summary->path.prefix_options = route->path.prefix_options;
372 summary->path.area_id = area->area_id;
373 summary->path.type = OSPF6_PATH_TYPE_INTER;
374 summary->path.cost = route->path.cost;
375 summary->nexthop[0] = route->nexthop[0];
hasso049207c2004-08-04 20:02:13 +0000376
377 /* prepare buffer */
378 memset (buffer, 0, sizeof (buffer));
379 lsa_header = (struct ospf6_lsa_header *) buffer;
hasso049207c2004-08-04 20:02:13 +0000380
hasso6452df02004-08-15 05:52:07 +0000381 if (route->type == OSPF6_DEST_TYPE_ROUTER)
382 {
383 router_lsa = (struct ospf6_inter_router_lsa *)
384 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
385 p = (caddr_t) router_lsa + sizeof (struct ospf6_inter_router_lsa);
hasso049207c2004-08-04 20:02:13 +0000386
hasso6452df02004-08-15 05:52:07 +0000387 /* Fill Inter-Area-Router-LSA */
388 router_lsa->options[0] = route->path.options[0];
389 router_lsa->options[1] = route->path.options[1];
390 router_lsa->options[2] = route->path.options[2];
391 OSPF6_ABR_SUMMARY_METRIC_SET (router_lsa, route->path.cost);
hasso3b687352004-08-19 06:56:53 +0000392 router_lsa->router_id = ADV_ROUTER_IN_PREFIX (&route->prefix);
hasso6452df02004-08-15 05:52:07 +0000393 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
394 }
395 else
396 {
397 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
398 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
399 p = (caddr_t) prefix_lsa + sizeof (struct ospf6_inter_prefix_lsa);
hasso049207c2004-08-04 20:02:13 +0000400
hasso6452df02004-08-15 05:52:07 +0000401 /* Fill Inter-Area-Prefix-LSA */
402 OSPF6_ABR_SUMMARY_METRIC_SET (prefix_lsa, route->path.cost);
403 prefix_lsa->prefix.prefix_length = route->prefix.prefixlen;
404 prefix_lsa->prefix.prefix_options = route->path.prefix_options;
hasso049207c2004-08-04 20:02:13 +0000405
hasso6452df02004-08-15 05:52:07 +0000406 /* set Prefix */
407 memcpy (p, &route->prefix.u.prefix6,
408 OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
409 ospf6_prefix_apply_mask (&prefix_lsa->prefix);
410 p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
411 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
412 }
hasso049207c2004-08-04 20:02:13 +0000413
414 /* Fill LSA Header */
415 lsa_header->age = 0;
hasso6452df02004-08-15 05:52:07 +0000416 lsa_header->type = type;
hasso049207c2004-08-04 20:02:13 +0000417 lsa_header->id = summary->path.origin.id;
418 lsa_header->adv_router = area->ospf6->router_id;
419 lsa_header->seqnum =
420 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
421 lsa_header->adv_router, area->lsdb);
422 lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
423
424 /* LSA checksum */
425 ospf6_lsa_checksum (lsa_header);
426
427 /* create LSA */
428 lsa = ospf6_lsa_create (lsa_header);
hasso6452df02004-08-15 05:52:07 +0000429
430 if (IS_OSPF6_DEBUG_ABR)
431 zlog_info ("Originate as %s", lsa->name);
hasso049207c2004-08-04 20:02:13 +0000432
433 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000434 ospf6_lsa_originate_area (lsa, area);
hasso049207c2004-08-04 20:02:13 +0000435}
436
437void
hasso6452df02004-08-15 05:52:07 +0000438ospf6_abr_range_update (struct ospf6_route *range)
439{
440 u_int32_t cost = 0;
441 struct ospf6_route *ro;
442
443 assert (range->type == OSPF6_DEST_TYPE_RANGE);
444
445 /* update range's cost and active flag */
446 for (ro = ospf6_route_match_head (&range->prefix, ospf6->route_table);
447 ro; ro = ospf6_route_match_next (&range->prefix, ro))
448 {
449 if (ro->path.area_id == range->path.area_id &&
450 ! CHECK_FLAG (ro->flag, OSPF6_ROUTE_REMOVE))
451 cost = MAX (cost, ro->path.cost);
452 }
453
454 if (range->path.cost != cost)
455 {
456 range->path.cost = cost;
457
458 if (range->path.cost)
459 SET_FLAG (range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY);
460 else
461 UNSET_FLAG (range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY);
462
463 ospf6_abr_originate_summary (range);
464 }
465}
466
467void
468ospf6_abr_originate_summary (struct ospf6_route *route)
hasso049207c2004-08-04 20:02:13 +0000469{
470 listnode node;
471 struct ospf6_area *oa;
hasso6452df02004-08-15 05:52:07 +0000472 struct ospf6_route *range = NULL;
hasso049207c2004-08-04 20:02:13 +0000473
hasso6452df02004-08-15 05:52:07 +0000474 if (route->type == OSPF6_DEST_TYPE_NETWORK)
475 {
476 oa = ospf6_area_lookup (route->path.area_id, ospf6);
477 range = ospf6_route_lookup_bestmatch (&route->prefix, oa->range_table);
478 if (range)
479 ospf6_abr_range_update (range);
480 }
481
482 for (node = listhead (ospf6->area_list); node; nextnode (node))
hasso049207c2004-08-04 20:02:13 +0000483 {
484 oa = (struct ospf6_area *) getdata (node);
hasso6452df02004-08-15 05:52:07 +0000485 ospf6_abr_originate_summary_to_area (route, oa);
hasso049207c2004-08-04 20:02:13 +0000486 }
487}
488
489/* RFC 2328 16.2. Calculating the inter-area routes */
490void
491ospf6_abr_examin_summary (struct ospf6_lsa *lsa, struct ospf6_area *oa)
492{
493 struct prefix prefix, abr_prefix;
494 struct ospf6_route_table *table = NULL;
495 struct ospf6_route *range, *route, *old = NULL;
496 struct ospf6_route *abr_entry;
hasso6452df02004-08-15 05:52:07 +0000497 u_char type = 0;
hasso049207c2004-08-04 20:02:13 +0000498 char options[3] = {0, 0, 0};
499 u_int8_t prefix_options = 0;
500 u_int32_t cost = 0;
501 int i;
hassoccb59b12004-08-25 09:10:37 +0000502 char buf[64];
hasso049207c2004-08-04 20:02:13 +0000503
hasso3b687352004-08-19 06:56:53 +0000504 if (IS_OSPF6_DEBUG_ABR)
505 zlog_info ("Examin %s in area %s", lsa->name, oa->name);
506
hasso049207c2004-08-04 20:02:13 +0000507 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
508 {
509 struct ospf6_inter_prefix_lsa *prefix_lsa;
510 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
511 OSPF6_LSA_HEADER_END (lsa->header);
512 prefix.family = AF_INET6;
513 prefix.prefixlen = prefix_lsa->prefix.prefix_length;
514 ospf6_prefix_in6_addr (&prefix.u.prefix6, &prefix_lsa->prefix);
hassoccb59b12004-08-25 09:10:37 +0000515 prefix2str (&prefix, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000516 table = oa->ospf6->route_table;
517 type = OSPF6_DEST_TYPE_NETWORK;
518 prefix_options = prefix_lsa->prefix.prefix_options;
519 cost = OSPF6_ABR_SUMMARY_METRIC (prefix_lsa);
520 }
521 else if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_ROUTER))
522 {
523 struct ospf6_inter_router_lsa *router_lsa;
524 router_lsa = (struct ospf6_inter_router_lsa *)
525 OSPF6_LSA_HEADER_END (lsa->header);
526 ospf6_linkstate_prefix (router_lsa->router_id, htonl (0), &prefix);
hassoccb59b12004-08-25 09:10:37 +0000527 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000528 table = oa->ospf6->brouter_table;
529 type = OSPF6_DEST_TYPE_ROUTER;
530 options[0] = router_lsa->options[0];
531 options[1] = router_lsa->options[1];
532 options[2] = router_lsa->options[2];
533 cost = OSPF6_ABR_SUMMARY_METRIC (router_lsa);
534 }
535 else
536 assert (0);
537
hassoccb59b12004-08-25 09:10:37 +0000538 /* Find existing route */
539 route = ospf6_route_lookup (&prefix, table);
540 if (route)
541 ospf6_route_lock (route);
542 while (route && ospf6_route_is_prefix (&prefix, route))
hasso049207c2004-08-04 20:02:13 +0000543 {
544 if (route->path.area_id == oa->area_id &&
545 route->path.origin.type == lsa->header->type &&
546 route->path.origin.id == lsa->header->id &&
547 route->path.origin.adv_router == lsa->header->adv_router)
548 old = route;
hassoccb59b12004-08-25 09:10:37 +0000549 route = ospf6_route_next (route);
hasso049207c2004-08-04 20:02:13 +0000550 }
551
552 /* (1) if cost == LSInfinity or if the LSA is MaxAge */
hasso3b687352004-08-19 06:56:53 +0000553 if (cost == LS_INFINITY)
hasso049207c2004-08-04 20:02:13 +0000554 {
hasso3b687352004-08-19 06:56:53 +0000555 if (IS_OSPF6_DEBUG_ABR)
556 zlog_info ("cost is LS_INFINITY, ignore");
557 if (old)
558 ospf6_route_remove (old, oa->ospf6->route_table);
559 return;
560 }
561 if (OSPF6_LSA_IS_MAXAGE (lsa))
562 {
563 if (IS_OSPF6_DEBUG_ABR)
564 zlog_info ("LSA is MaxAge, ignore");
hasso049207c2004-08-04 20:02:13 +0000565 if (old)
566 ospf6_route_remove (old, oa->ospf6->route_table);
567 return;
568 }
569
570 /* (2) if the LSA is self-originated, ignore */
571 if (lsa->header->adv_router == oa->ospf6->router_id)
572 {
hasso3b687352004-08-19 06:56:53 +0000573 if (IS_OSPF6_DEBUG_ABR)
574 zlog_info ("LSA is self-originated, ignore");
hasso049207c2004-08-04 20:02:13 +0000575 if (old)
576 ospf6_route_remove (old, oa->ospf6->route_table);
577 return;
578 }
579
580 /* (3) if the prefix is equal to an active configured address range */
hasso6452df02004-08-15 05:52:07 +0000581 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
hasso049207c2004-08-04 20:02:13 +0000582 {
hasso6452df02004-08-15 05:52:07 +0000583 range = ospf6_route_lookup (&prefix, oa->range_table);
584 if (range)
585 {
hasso3b687352004-08-19 06:56:53 +0000586 if (IS_OSPF6_DEBUG_ABR)
587 zlog_info ("Prefix is equal to address range, ignore");
hasso6452df02004-08-15 05:52:07 +0000588 if (old)
589 ospf6_route_remove (old, oa->ospf6->route_table);
590 return;
591 }
hasso049207c2004-08-04 20:02:13 +0000592 }
593
594 /* (4) if the routing table entry for the ABR does not exist */
595 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &abr_prefix);
596 abr_entry = ospf6_route_lookup (&abr_prefix, oa->ospf6->brouter_table);
hasso6452df02004-08-15 05:52:07 +0000597 if (abr_entry == NULL || abr_entry->path.area_id != oa->area_id ||
hassoccb59b12004-08-25 09:10:37 +0000598 CHECK_FLAG (abr_entry->flag, OSPF6_ROUTE_REMOVE) ||
hasso6452df02004-08-15 05:52:07 +0000599 ! CHECK_FLAG (abr_entry->path.router_bits, OSPF6_ROUTER_BIT_B))
hasso049207c2004-08-04 20:02:13 +0000600 {
hasso3b687352004-08-19 06:56:53 +0000601 if (IS_OSPF6_DEBUG_ABR)
602 zlog_info ("ABR router entry does not exist, ignore");
hasso049207c2004-08-04 20:02:13 +0000603 if (old)
604 ospf6_route_remove (old, oa->ospf6->route_table);
605 return;
606 }
607
608 /* (5),(6),(7) the path preference is handled by the sorting
609 in the routing table. Always install the path by substituting
610 old route (if any). */
611 if (old)
hassoccb59b12004-08-25 09:10:37 +0000612 route = ospf6_route_copy (old);
hasso049207c2004-08-04 20:02:13 +0000613 else
614 route = ospf6_route_create ();
615
616 route->type = type;
617 route->prefix = prefix;
618 route->path.origin.type = lsa->header->type;
619 route->path.origin.id = lsa->header->id;
620 route->path.origin.adv_router = lsa->header->adv_router;
621 route->path.options[0] = options[0];
622 route->path.options[1] = options[1];
623 route->path.options[2] = options[2];
624 route->path.prefix_options = prefix_options;
625 route->path.area_id = oa->area_id;
626 route->path.type = OSPF6_PATH_TYPE_INTER;
627 route->path.cost = abr_entry->path.cost + cost;
628 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
629 route->nexthop[i] = abr_entry->nexthop[i];
630
hasso3b687352004-08-19 06:56:53 +0000631 if (IS_OSPF6_DEBUG_ABR)
hassoccb59b12004-08-25 09:10:37 +0000632 zlog_info ("Install route: %s", buf);
hasso049207c2004-08-04 20:02:13 +0000633 ospf6_route_add (route, table);
634}
635
hassoccb59b12004-08-25 09:10:37 +0000636void
637ospf6_abr_examin_brouter (u_int32_t router_id)
638{
639 struct ospf6_lsa *lsa;
640 struct ospf6_area *oa;
641 listnode node;
642 u_int16_t type;
643
644 if (IS_OSPF6_DEBUG_ABR)
645 {
646 char buf[16];
647 inet_ntop (AF_INET, &router_id, buf, sizeof (buf));
648 zlog_info ("Router entry of %s changed", buf);
649 zlog_info ("Examin summary LSAs originated by the router");
650 }
651
652 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
653 for (node = listhead (ospf6->area_list); node; nextnode (node))
654 {
655 oa = OSPF6_AREA (getdata (node));
656 for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;
657 lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))
658 ospf6_abr_examin_summary (lsa, oa);
659 }
660
661 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
662 for (node = listhead (ospf6->area_list); node; nextnode (node))
663 {
664 oa = OSPF6_AREA (getdata (node));
665 for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;
666 lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))
667 ospf6_abr_examin_summary (lsa, oa);
668 }
669}
670
hasso049207c2004-08-04 20:02:13 +0000671
672/* Display functions */
673int
674ospf6_inter_area_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
675{
676 struct ospf6_inter_prefix_lsa *prefix_lsa;
677 struct in6_addr in6;
678 char buf[64];
679
680 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
681 OSPF6_LSA_HEADER_END (lsa->header);
682
683 vty_out (vty, " Metric: %lu%s",
684 (u_long) OSPF6_ABR_SUMMARY_METRIC (prefix_lsa), VNL);
685
686 ospf6_prefix_options_printbuf (prefix_lsa->prefix.prefix_options,
687 buf, sizeof (buf));
688 vty_out (vty, " Prefix Options: %s%s", buf, VNL);
689
690 ospf6_prefix_in6_addr (&in6, &prefix_lsa->prefix);
691 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
692 vty_out (vty, " Prefix: %s/%d%s", buf,
693 prefix_lsa->prefix.prefix_length, VNL);
694
695 return 0;
696}
697
698int
699ospf6_inter_area_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
700{
701 struct ospf6_inter_router_lsa *router_lsa;
702 char buf[64];
703
704 router_lsa = (struct ospf6_inter_router_lsa *)
705 OSPF6_LSA_HEADER_END (lsa->header);
706
707 ospf6_options_printbuf (router_lsa->options, buf, sizeof (buf));
708 vty_out (vty, " Options: %s%s", buf, VNL);
709 vty_out (vty, " Metric: %lu%s",
710 (u_long) OSPF6_ABR_SUMMARY_METRIC (router_lsa), VNL);
711 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
712 vty_out (vty, " Destination Router ID: %s%s", buf, VNL);
713
714 return 0;
715}
716
717/* Debug commands */
718DEFUN (debug_ospf6_abr,
719 debug_ospf6_abr_cmd,
720 "debug ospf6 abr",
721 DEBUG_STR
722 OSPF6_STR
723 "Debug OSPFv3 ABR function\n"
724 )
725{
726 OSPF6_DEBUG_ABR_ON ();
727 return CMD_SUCCESS;
728}
729
730DEFUN (no_debug_ospf6_abr,
731 no_debug_ospf6_abr_cmd,
732 "no debug ospf6 abr",
733 NO_STR
734 DEBUG_STR
735 OSPF6_STR
736 "Debug OSPFv3 ABR function\n"
737 )
738{
739 OSPF6_DEBUG_ABR_OFF ();
740 return CMD_SUCCESS;
741}
742
743int
744config_write_ospf6_debug_abr (struct vty *vty)
745{
746 if (IS_OSPF6_DEBUG_ABR)
747 vty_out (vty, "debug ospf6 abr%s", VNL);
748 return 0;
749}
750
751void
752install_element_ospf6_debug_abr ()
753{
754 install_element (ENABLE_NODE, &debug_ospf6_abr_cmd);
755 install_element (ENABLE_NODE, &no_debug_ospf6_abr_cmd);
756 install_element (CONFIG_NODE, &debug_ospf6_abr_cmd);
757 install_element (CONFIG_NODE, &no_debug_ospf6_abr_cmd);
758}
759
hasso6452df02004-08-15 05:52:07 +0000760struct ospf6_lsa_handler inter_prefix_handler =
761{
762 OSPF6_LSTYPE_INTER_PREFIX,
763 "Inter-Prefix",
764 ospf6_inter_area_prefix_lsa_show
765};
766
767struct ospf6_lsa_handler inter_router_handler =
768{
769 OSPF6_LSTYPE_INTER_ROUTER,
770 "Inter-Router",
771 ospf6_inter_area_router_lsa_show
772};
773
hasso049207c2004-08-04 20:02:13 +0000774void
775ospf6_abr_init ()
776{
hasso6452df02004-08-15 05:52:07 +0000777 ospf6_install_lsa_handler (&inter_prefix_handler);
778 ospf6_install_lsa_handler (&inter_router_handler);
hasso049207c2004-08-04 20:02:13 +0000779}
780
781