blob: e9dc238ac55f01b94250bcce5836528057c8b6fd [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;
502
hasso3b687352004-08-19 06:56:53 +0000503 if (IS_OSPF6_DEBUG_ABR)
504 zlog_info ("Examin %s in area %s", lsa->name, oa->name);
505
hasso049207c2004-08-04 20:02:13 +0000506 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
507 {
508 struct ospf6_inter_prefix_lsa *prefix_lsa;
509 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
510 OSPF6_LSA_HEADER_END (lsa->header);
511 prefix.family = AF_INET6;
512 prefix.prefixlen = prefix_lsa->prefix.prefix_length;
513 ospf6_prefix_in6_addr (&prefix.u.prefix6, &prefix_lsa->prefix);
514 table = oa->ospf6->route_table;
515 type = OSPF6_DEST_TYPE_NETWORK;
516 prefix_options = prefix_lsa->prefix.prefix_options;
517 cost = OSPF6_ABR_SUMMARY_METRIC (prefix_lsa);
518 }
519 else if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_ROUTER))
520 {
521 struct ospf6_inter_router_lsa *router_lsa;
522 router_lsa = (struct ospf6_inter_router_lsa *)
523 OSPF6_LSA_HEADER_END (lsa->header);
524 ospf6_linkstate_prefix (router_lsa->router_id, htonl (0), &prefix);
525 table = oa->ospf6->brouter_table;
526 type = OSPF6_DEST_TYPE_ROUTER;
527 options[0] = router_lsa->options[0];
528 options[1] = router_lsa->options[1];
529 options[2] = router_lsa->options[2];
530 cost = OSPF6_ABR_SUMMARY_METRIC (router_lsa);
531 }
532 else
533 assert (0);
534
535 for (route = ospf6_route_lookup (&prefix, table);
536 route && ospf6_route_is_prefix (&prefix, route);
537 route = ospf6_route_next (route))
538 {
539 if (route->path.area_id == oa->area_id &&
540 route->path.origin.type == lsa->header->type &&
541 route->path.origin.id == lsa->header->id &&
542 route->path.origin.adv_router == lsa->header->adv_router)
543 old = route;
544 }
545
546 /* (1) if cost == LSInfinity or if the LSA is MaxAge */
hasso3b687352004-08-19 06:56:53 +0000547 if (cost == LS_INFINITY)
hasso049207c2004-08-04 20:02:13 +0000548 {
hasso3b687352004-08-19 06:56:53 +0000549 if (IS_OSPF6_DEBUG_ABR)
550 zlog_info ("cost is LS_INFINITY, ignore");
551 if (old)
552 ospf6_route_remove (old, oa->ospf6->route_table);
553 return;
554 }
555 if (OSPF6_LSA_IS_MAXAGE (lsa))
556 {
557 if (IS_OSPF6_DEBUG_ABR)
558 zlog_info ("LSA is MaxAge, ignore");
hasso049207c2004-08-04 20:02:13 +0000559 if (old)
560 ospf6_route_remove (old, oa->ospf6->route_table);
561 return;
562 }
563
564 /* (2) if the LSA is self-originated, ignore */
565 if (lsa->header->adv_router == oa->ospf6->router_id)
566 {
hasso3b687352004-08-19 06:56:53 +0000567 if (IS_OSPF6_DEBUG_ABR)
568 zlog_info ("LSA is self-originated, ignore");
hasso049207c2004-08-04 20:02:13 +0000569 if (old)
570 ospf6_route_remove (old, oa->ospf6->route_table);
571 return;
572 }
573
574 /* (3) if the prefix is equal to an active configured address range */
hasso6452df02004-08-15 05:52:07 +0000575 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
hasso049207c2004-08-04 20:02:13 +0000576 {
hasso6452df02004-08-15 05:52:07 +0000577 range = ospf6_route_lookup (&prefix, oa->range_table);
578 if (range)
579 {
hasso3b687352004-08-19 06:56:53 +0000580 if (IS_OSPF6_DEBUG_ABR)
581 zlog_info ("Prefix is equal to address range, ignore");
hasso6452df02004-08-15 05:52:07 +0000582 if (old)
583 ospf6_route_remove (old, oa->ospf6->route_table);
584 return;
585 }
hasso049207c2004-08-04 20:02:13 +0000586 }
587
588 /* (4) if the routing table entry for the ABR does not exist */
589 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &abr_prefix);
590 abr_entry = ospf6_route_lookup (&abr_prefix, oa->ospf6->brouter_table);
hasso6452df02004-08-15 05:52:07 +0000591 if (abr_entry == NULL || abr_entry->path.area_id != oa->area_id ||
592 ! CHECK_FLAG (abr_entry->path.router_bits, OSPF6_ROUTER_BIT_B))
hasso049207c2004-08-04 20:02:13 +0000593 {
hasso3b687352004-08-19 06:56:53 +0000594 if (IS_OSPF6_DEBUG_ABR)
595 zlog_info ("ABR router entry does not exist, ignore");
hasso049207c2004-08-04 20:02:13 +0000596 if (old)
597 ospf6_route_remove (old, oa->ospf6->route_table);
598 return;
599 }
600
601 /* (5),(6),(7) the path preference is handled by the sorting
602 in the routing table. Always install the path by substituting
603 old route (if any). */
604 if (old)
605 route = old;
606 else
607 route = ospf6_route_create ();
608
609 route->type = type;
610 route->prefix = prefix;
611 route->path.origin.type = lsa->header->type;
612 route->path.origin.id = lsa->header->id;
613 route->path.origin.adv_router = lsa->header->adv_router;
614 route->path.options[0] = options[0];
615 route->path.options[1] = options[1];
616 route->path.options[2] = options[2];
617 route->path.prefix_options = prefix_options;
618 route->path.area_id = oa->area_id;
619 route->path.type = OSPF6_PATH_TYPE_INTER;
620 route->path.cost = abr_entry->path.cost + cost;
621 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
622 route->nexthop[i] = abr_entry->nexthop[i];
623
hasso3b687352004-08-19 06:56:53 +0000624 if (IS_OSPF6_DEBUG_ABR)
625 zlog_info ("Install route");
hasso049207c2004-08-04 20:02:13 +0000626 ospf6_route_add (route, table);
627}
628
hasso049207c2004-08-04 20:02:13 +0000629
630/* Display functions */
631int
632ospf6_inter_area_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
633{
634 struct ospf6_inter_prefix_lsa *prefix_lsa;
635 struct in6_addr in6;
636 char buf[64];
637
638 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
639 OSPF6_LSA_HEADER_END (lsa->header);
640
641 vty_out (vty, " Metric: %lu%s",
642 (u_long) OSPF6_ABR_SUMMARY_METRIC (prefix_lsa), VNL);
643
644 ospf6_prefix_options_printbuf (prefix_lsa->prefix.prefix_options,
645 buf, sizeof (buf));
646 vty_out (vty, " Prefix Options: %s%s", buf, VNL);
647
648 ospf6_prefix_in6_addr (&in6, &prefix_lsa->prefix);
649 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
650 vty_out (vty, " Prefix: %s/%d%s", buf,
651 prefix_lsa->prefix.prefix_length, VNL);
652
653 return 0;
654}
655
656int
657ospf6_inter_area_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
658{
659 struct ospf6_inter_router_lsa *router_lsa;
660 char buf[64];
661
662 router_lsa = (struct ospf6_inter_router_lsa *)
663 OSPF6_LSA_HEADER_END (lsa->header);
664
665 ospf6_options_printbuf (router_lsa->options, buf, sizeof (buf));
666 vty_out (vty, " Options: %s%s", buf, VNL);
667 vty_out (vty, " Metric: %lu%s",
668 (u_long) OSPF6_ABR_SUMMARY_METRIC (router_lsa), VNL);
669 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
670 vty_out (vty, " Destination Router ID: %s%s", buf, VNL);
671
672 return 0;
673}
674
675/* Debug commands */
676DEFUN (debug_ospf6_abr,
677 debug_ospf6_abr_cmd,
678 "debug ospf6 abr",
679 DEBUG_STR
680 OSPF6_STR
681 "Debug OSPFv3 ABR function\n"
682 )
683{
684 OSPF6_DEBUG_ABR_ON ();
685 return CMD_SUCCESS;
686}
687
688DEFUN (no_debug_ospf6_abr,
689 no_debug_ospf6_abr_cmd,
690 "no debug ospf6 abr",
691 NO_STR
692 DEBUG_STR
693 OSPF6_STR
694 "Debug OSPFv3 ABR function\n"
695 )
696{
697 OSPF6_DEBUG_ABR_OFF ();
698 return CMD_SUCCESS;
699}
700
701int
702config_write_ospf6_debug_abr (struct vty *vty)
703{
704 if (IS_OSPF6_DEBUG_ABR)
705 vty_out (vty, "debug ospf6 abr%s", VNL);
706 return 0;
707}
708
709void
710install_element_ospf6_debug_abr ()
711{
712 install_element (ENABLE_NODE, &debug_ospf6_abr_cmd);
713 install_element (ENABLE_NODE, &no_debug_ospf6_abr_cmd);
714 install_element (CONFIG_NODE, &debug_ospf6_abr_cmd);
715 install_element (CONFIG_NODE, &no_debug_ospf6_abr_cmd);
716}
717
hasso6452df02004-08-15 05:52:07 +0000718struct ospf6_lsa_handler inter_prefix_handler =
719{
720 OSPF6_LSTYPE_INTER_PREFIX,
721 "Inter-Prefix",
722 ospf6_inter_area_prefix_lsa_show
723};
724
725struct ospf6_lsa_handler inter_router_handler =
726{
727 OSPF6_LSTYPE_INTER_ROUTER,
728 "Inter-Router",
729 ospf6_inter_area_router_lsa_show
730};
731
hasso049207c2004-08-04 20:02:13 +0000732void
733ospf6_abr_init ()
734{
hasso6452df02004-08-15 05:52:07 +0000735 ospf6_install_lsa_handler (&inter_prefix_handler);
736 ospf6_install_lsa_handler (&inter_router_handler);
hasso049207c2004-08-04 20:02:13 +0000737}
738
739