blob: 58015ff3e12998a2a065f9f832bbd97798c24ac6 [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;
hasso1e058382004-09-01 21:36:14 +0000161 char buf[64];
162 int is_debug = 0;
hasso049207c2004-08-04 20:02:13 +0000163
hasso1e058382004-09-01 21:36:14 +0000164 if (route->type == OSPF6_DEST_TYPE_ROUTER)
hasso6452df02004-08-15 05:52:07 +0000165 {
hasso1e058382004-09-01 21:36:14 +0000166 if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_ORIGINATE (INTER_ROUTER))
hasso6452df02004-08-15 05:52:07 +0000167 {
hasso1e058382004-09-01 21:36:14 +0000168 is_debug++;
hasso3b687352004-08-19 06:56:53 +0000169 inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
hasso6452df02004-08-15 05:52:07 +0000170 buf, sizeof (buf));
171 zlog_info ("Originating summary in area %s for ASBR %s",
172 area->name, buf);
173 }
hasso1e058382004-09-01 21:36:14 +0000174 summary_table = area->summary_router;
175 }
176 else
177 {
178 if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_ORIGINATE (INTER_PREFIX))
hasso6452df02004-08-15 05:52:07 +0000179 {
hasso1e058382004-09-01 21:36:14 +0000180 is_debug++;
hasso6452df02004-08-15 05:52:07 +0000181 prefix2str (&route->prefix, buf, sizeof (buf));
182 zlog_info ("Originating summary in area %s for %s",
183 area->name, buf);
184 }
hasso1e058382004-09-01 21:36:14 +0000185 summary_table = area->summary_prefix;
hasso6452df02004-08-15 05:52:07 +0000186 }
187
hasso6452df02004-08-15 05:52:07 +0000188 summary = ospf6_route_lookup (&route->prefix, summary_table);
hasso049207c2004-08-04 20:02:13 +0000189 if (summary)
hasso6452df02004-08-15 05:52:07 +0000190 old = ospf6_lsdb_lookup (summary->path.origin.type,
hasso049207c2004-08-04 20:02:13 +0000191 summary->path.origin.id,
192 area->ospf6->router_id, area->lsdb);
193
194 /* if this route has just removed, remove corresponding LSA */
195 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
196 {
hasso1e058382004-09-01 21:36:14 +0000197 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000198 zlog_info ("The route has just removed, purge previous LSA");
199 if (summary)
200 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000201 if (old)
hasso6452df02004-08-15 05:52:07 +0000202 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000203 return;
204 }
205
hasso6452df02004-08-15 05:52:07 +0000206 /* Only destination type network, range or ASBR are considered */
207 if (route->type != OSPF6_DEST_TYPE_NETWORK &&
208 route->type != OSPF6_DEST_TYPE_RANGE &&
209 (route->type != OSPF6_DEST_TYPE_ROUTER ||
210 ! CHECK_FLAG (route->path.router_bits, OSPF6_ROUTER_BIT_E)))
hasso049207c2004-08-04 20:02:13 +0000211 {
hasso1e058382004-09-01 21:36:14 +0000212 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000213 zlog_info ("Route type is none of network, range nor ASBR, withdraw");
214 if (summary)
215 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000216 if (old)
hasso6452df02004-08-15 05:52:07 +0000217 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000218 return;
219 }
220
221 /* AS External routes are never considered */
222 if (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
223 route->path.type == OSPF6_PATH_TYPE_EXTERNAL2)
224 {
hasso1e058382004-09-01 21:36:14 +0000225 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000226 zlog_info ("Path type is external, withdraw");
227 if (summary)
228 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000229 if (old)
hasso6452df02004-08-15 05:52:07 +0000230 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000231 return;
232 }
233
234 /* do not generate if the path's area is the same as target area */
235 if (route->path.area_id == area->area_id)
236 {
hasso1e058382004-09-01 21:36:14 +0000237 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000238 zlog_info ("The route is in the area itself, ignore");
239 if (summary)
240 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000241 if (old)
hasso6452df02004-08-15 05:52:07 +0000242 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000243 return;
244 }
245
246 /* do not generate if the nexthops belongs to the target area */
247 oi = ospf6_interface_lookup_by_ifindex (route->nexthop[0].ifindex);
hasso6452df02004-08-15 05:52:07 +0000248 if (oi && oi->area && oi->area == area)
hasso049207c2004-08-04 20:02:13 +0000249 {
hasso1e058382004-09-01 21:36:14 +0000250 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000251 zlog_info ("The route's nexthop is in the same area, ignore");
252 if (summary)
253 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000254 if (old)
hasso6452df02004-08-15 05:52:07 +0000255 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000256 return;
257 }
258
hasso6452df02004-08-15 05:52:07 +0000259 /* do not generate if the route cost is greater or equal to LSInfinity */
260 if (route->path.cost >= LS_INFINITY)
261 {
hasso1e058382004-09-01 21:36:14 +0000262 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000263 zlog_info ("The cost exceeds LSInfinity, withdraw");
264 if (summary)
265 ospf6_route_remove (summary, summary_table);
266 if (old)
267 ospf6_lsa_purge (old);
268 return;
269 }
270
271 /* if this is a route to ASBR */
272 if (route->type == OSPF6_DEST_TYPE_ROUTER)
273 {
274 /* Only the prefered best path is considered */
275 if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_BEST))
276 {
hasso1e058382004-09-01 21:36:14 +0000277 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000278 zlog_info ("This is the secondary path to the ASBR, ignore");
279 if (summary)
280 ospf6_route_remove (summary, summary_table);
281 if (old)
282 ospf6_lsa_purge (old);
283 return;
284 }
285
286 /* Do not generate if the area is stub */
287 /* XXX */
288 }
289
290 /* if this is an intra-area route, this may be suppressed by aggregation */
291 if (route->type == OSPF6_DEST_TYPE_NETWORK &&
292 route->path.type == OSPF6_PATH_TYPE_INTRA)
293 {
294 /* search for configured address range for the route's area */
295 route_area = ospf6_area_lookup (route->path.area_id, area->ospf6);
296 assert (route_area);
297 range = ospf6_route_lookup_bestmatch (&route->prefix,
298 route_area->range_table);
299
300 /* ranges are ignored when originate backbone routes to transit area.
301 Otherwise, if ranges are configured, the route is suppressed. */
302 if (range && ! CHECK_FLAG (range->flag, OSPF6_ROUTE_REMOVE) &&
303 (route->path.area_id != BACKBONE_AREA_ID ||
304 ! IS_AREA_TRANSIT (area)))
305 {
hasso1e058382004-09-01 21:36:14 +0000306 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000307 {
hasso6452df02004-08-15 05:52:07 +0000308 prefix2str (&range->prefix, buf, sizeof (buf));
309 zlog_info ("Suppressed by range %s of area %s",
310 buf, route_area->name);
311 }
312
313 if (summary)
314 ospf6_route_remove (summary, summary_table);
315 if (old)
316 ospf6_lsa_purge (old);
317 return;
318 }
319 }
320
321 /* If this is a configured address range */
322 if (route->type == OSPF6_DEST_TYPE_RANGE)
323 {
324 /* If DoNotAdvertise is set */
325 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE))
326 {
hasso1e058382004-09-01 21:36:14 +0000327 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000328 zlog_info ("This is the range with DoNotAdvertise set. ignore");
329 if (summary)
330 ospf6_route_remove (summary, summary_table);
331 if (old)
332 ospf6_lsa_purge (old);
333 return;
334 }
335
336 /* Whether the route have active longer prefix */
337 if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_ACTIVE_SUMMARY))
338 {
hasso1e058382004-09-01 21:36:14 +0000339 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000340 zlog_info ("The range is not active. withdraw");
341 if (summary)
342 ospf6_route_remove (summary, summary_table);
343 if (old)
344 ospf6_lsa_purge (old);
345 return;
346 }
347 }
348
hasso049207c2004-08-04 20:02:13 +0000349 /* the route is going to be originated. store it in area's summary_table */
350 if (summary == NULL)
351 {
352 summary = ospf6_route_copy (route);
hasso6452df02004-08-15 05:52:07 +0000353 if (route->type == OSPF6_DEST_TYPE_NETWORK ||
354 route->type == OSPF6_DEST_TYPE_RANGE)
355 summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_PREFIX);
356 else
357 summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_ROUTER);
hasso049207c2004-08-04 20:02:13 +0000358 summary->path.origin.adv_router = area->ospf6->router_id;
359 summary->path.origin.id =
360 ospf6_new_ls_id (summary->path.origin.type,
361 summary->path.origin.adv_router, area->lsdb);
hasso6452df02004-08-15 05:52:07 +0000362 ospf6_route_add (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000363 }
hasso6452df02004-08-15 05:52:07 +0000364 else
365 {
366 summary->type = route->type;
367 gettimeofday (&summary->changed, NULL);
368 }
369
370 summary->path.router_bits = route->path.router_bits;
371 summary->path.options[0] = route->path.options[0];
372 summary->path.options[1] = route->path.options[1];
373 summary->path.options[2] = route->path.options[2];
374 summary->path.prefix_options = route->path.prefix_options;
375 summary->path.area_id = area->area_id;
376 summary->path.type = OSPF6_PATH_TYPE_INTER;
377 summary->path.cost = route->path.cost;
378 summary->nexthop[0] = route->nexthop[0];
hasso049207c2004-08-04 20:02:13 +0000379
380 /* prepare buffer */
381 memset (buffer, 0, sizeof (buffer));
382 lsa_header = (struct ospf6_lsa_header *) buffer;
hasso049207c2004-08-04 20:02:13 +0000383
hasso6452df02004-08-15 05:52:07 +0000384 if (route->type == OSPF6_DEST_TYPE_ROUTER)
385 {
386 router_lsa = (struct ospf6_inter_router_lsa *)
387 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
388 p = (caddr_t) router_lsa + sizeof (struct ospf6_inter_router_lsa);
hasso049207c2004-08-04 20:02:13 +0000389
hasso6452df02004-08-15 05:52:07 +0000390 /* Fill Inter-Area-Router-LSA */
391 router_lsa->options[0] = route->path.options[0];
392 router_lsa->options[1] = route->path.options[1];
393 router_lsa->options[2] = route->path.options[2];
394 OSPF6_ABR_SUMMARY_METRIC_SET (router_lsa, route->path.cost);
hasso3b687352004-08-19 06:56:53 +0000395 router_lsa->router_id = ADV_ROUTER_IN_PREFIX (&route->prefix);
hasso6452df02004-08-15 05:52:07 +0000396 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
397 }
398 else
399 {
400 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
401 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
402 p = (caddr_t) prefix_lsa + sizeof (struct ospf6_inter_prefix_lsa);
hasso049207c2004-08-04 20:02:13 +0000403
hasso6452df02004-08-15 05:52:07 +0000404 /* Fill Inter-Area-Prefix-LSA */
405 OSPF6_ABR_SUMMARY_METRIC_SET (prefix_lsa, route->path.cost);
406 prefix_lsa->prefix.prefix_length = route->prefix.prefixlen;
407 prefix_lsa->prefix.prefix_options = route->path.prefix_options;
hasso049207c2004-08-04 20:02:13 +0000408
hasso6452df02004-08-15 05:52:07 +0000409 /* set Prefix */
410 memcpy (p, &route->prefix.u.prefix6,
411 OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
412 ospf6_prefix_apply_mask (&prefix_lsa->prefix);
413 p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
414 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
415 }
hasso049207c2004-08-04 20:02:13 +0000416
417 /* Fill LSA Header */
418 lsa_header->age = 0;
hasso6452df02004-08-15 05:52:07 +0000419 lsa_header->type = type;
hasso049207c2004-08-04 20:02:13 +0000420 lsa_header->id = summary->path.origin.id;
421 lsa_header->adv_router = area->ospf6->router_id;
422 lsa_header->seqnum =
423 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
424 lsa_header->adv_router, area->lsdb);
425 lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
426
427 /* LSA checksum */
428 ospf6_lsa_checksum (lsa_header);
429
430 /* create LSA */
431 lsa = ospf6_lsa_create (lsa_header);
hasso6452df02004-08-15 05:52:07 +0000432
hasso049207c2004-08-04 20:02:13 +0000433 /* 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;
hasso63069ad2004-09-02 13:01:01 +0000501 u_char router_bits = 0;
hasso049207c2004-08-04 20:02:13 +0000502 int i;
hassoccb59b12004-08-25 09:10:37 +0000503 char buf[64];
hasso1e058382004-09-01 21:36:14 +0000504 int is_debug = 0;
hasso3b687352004-08-19 06:56:53 +0000505
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;
hasso1e058382004-09-01 21:36:14 +0000509
510 if (IS_OSPF6_DEBUG_EXAMIN (INTER_PREFIX))
511 {
512 is_debug++;
513 zlog_info ("Examin %s in area %s", lsa->name, oa->name);
514 }
515
hasso049207c2004-08-04 20:02:13 +0000516 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
517 OSPF6_LSA_HEADER_END (lsa->header);
518 prefix.family = AF_INET6;
519 prefix.prefixlen = prefix_lsa->prefix.prefix_length;
520 ospf6_prefix_in6_addr (&prefix.u.prefix6, &prefix_lsa->prefix);
hassoccb59b12004-08-25 09:10:37 +0000521 prefix2str (&prefix, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000522 table = oa->ospf6->route_table;
523 type = OSPF6_DEST_TYPE_NETWORK;
524 prefix_options = prefix_lsa->prefix.prefix_options;
525 cost = OSPF6_ABR_SUMMARY_METRIC (prefix_lsa);
526 }
527 else if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_ROUTER))
528 {
529 struct ospf6_inter_router_lsa *router_lsa;
hasso1e058382004-09-01 21:36:14 +0000530
531 if (IS_OSPF6_DEBUG_EXAMIN (INTER_ROUTER))
532 {
533 is_debug++;
534 zlog_info ("Examin %s in area %s", lsa->name, oa->name);
535 }
536
hasso049207c2004-08-04 20:02:13 +0000537 router_lsa = (struct ospf6_inter_router_lsa *)
538 OSPF6_LSA_HEADER_END (lsa->header);
539 ospf6_linkstate_prefix (router_lsa->router_id, htonl (0), &prefix);
hassoccb59b12004-08-25 09:10:37 +0000540 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000541 table = oa->ospf6->brouter_table;
542 type = OSPF6_DEST_TYPE_ROUTER;
543 options[0] = router_lsa->options[0];
544 options[1] = router_lsa->options[1];
545 options[2] = router_lsa->options[2];
546 cost = OSPF6_ABR_SUMMARY_METRIC (router_lsa);
hasso63069ad2004-09-02 13:01:01 +0000547 SET_FLAG (router_bits, OSPF6_ROUTER_BIT_E);
hasso049207c2004-08-04 20:02:13 +0000548 }
549 else
550 assert (0);
551
hassoccb59b12004-08-25 09:10:37 +0000552 /* Find existing route */
553 route = ospf6_route_lookup (&prefix, table);
554 if (route)
555 ospf6_route_lock (route);
556 while (route && ospf6_route_is_prefix (&prefix, route))
hasso049207c2004-08-04 20:02:13 +0000557 {
558 if (route->path.area_id == oa->area_id &&
559 route->path.origin.type == lsa->header->type &&
560 route->path.origin.id == lsa->header->id &&
561 route->path.origin.adv_router == lsa->header->adv_router)
562 old = route;
hassoccb59b12004-08-25 09:10:37 +0000563 route = ospf6_route_next (route);
hasso049207c2004-08-04 20:02:13 +0000564 }
565
566 /* (1) if cost == LSInfinity or if the LSA is MaxAge */
hasso3b687352004-08-19 06:56:53 +0000567 if (cost == LS_INFINITY)
hasso049207c2004-08-04 20:02:13 +0000568 {
hasso1e058382004-09-01 21:36:14 +0000569 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000570 zlog_info ("cost is LS_INFINITY, ignore");
571 if (old)
hasso63069ad2004-09-02 13:01:01 +0000572 ospf6_route_remove (old, table);
hasso3b687352004-08-19 06:56:53 +0000573 return;
574 }
575 if (OSPF6_LSA_IS_MAXAGE (lsa))
576 {
hasso1e058382004-09-01 21:36:14 +0000577 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000578 zlog_info ("LSA is MaxAge, ignore");
hasso049207c2004-08-04 20:02:13 +0000579 if (old)
hasso63069ad2004-09-02 13:01:01 +0000580 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000581 return;
582 }
583
584 /* (2) if the LSA is self-originated, ignore */
585 if (lsa->header->adv_router == oa->ospf6->router_id)
586 {
hasso1e058382004-09-01 21:36:14 +0000587 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000588 zlog_info ("LSA is self-originated, ignore");
hasso049207c2004-08-04 20:02:13 +0000589 if (old)
hasso63069ad2004-09-02 13:01:01 +0000590 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000591 return;
592 }
593
594 /* (3) if the prefix is equal to an active configured address range */
hasso6452df02004-08-15 05:52:07 +0000595 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
hasso049207c2004-08-04 20:02:13 +0000596 {
hasso6452df02004-08-15 05:52:07 +0000597 range = ospf6_route_lookup (&prefix, oa->range_table);
598 if (range)
599 {
hasso1e058382004-09-01 21:36:14 +0000600 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000601 zlog_info ("Prefix is equal to address range, ignore");
hasso6452df02004-08-15 05:52:07 +0000602 if (old)
hasso63069ad2004-09-02 13:01:01 +0000603 ospf6_route_remove (old, table);
hasso6452df02004-08-15 05:52:07 +0000604 return;
605 }
hasso049207c2004-08-04 20:02:13 +0000606 }
607
608 /* (4) if the routing table entry for the ABR does not exist */
609 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &abr_prefix);
610 abr_entry = ospf6_route_lookup (&abr_prefix, oa->ospf6->brouter_table);
hasso6452df02004-08-15 05:52:07 +0000611 if (abr_entry == NULL || abr_entry->path.area_id != oa->area_id ||
hassoccb59b12004-08-25 09:10:37 +0000612 CHECK_FLAG (abr_entry->flag, OSPF6_ROUTE_REMOVE) ||
hasso6452df02004-08-15 05:52:07 +0000613 ! CHECK_FLAG (abr_entry->path.router_bits, OSPF6_ROUTER_BIT_B))
hasso049207c2004-08-04 20:02:13 +0000614 {
hasso1e058382004-09-01 21:36:14 +0000615 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000616 zlog_info ("ABR router entry does not exist, ignore");
hasso049207c2004-08-04 20:02:13 +0000617 if (old)
hasso63069ad2004-09-02 13:01:01 +0000618 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000619 return;
620 }
621
622 /* (5),(6),(7) the path preference is handled by the sorting
623 in the routing table. Always install the path by substituting
624 old route (if any). */
625 if (old)
hassoccb59b12004-08-25 09:10:37 +0000626 route = ospf6_route_copy (old);
hasso049207c2004-08-04 20:02:13 +0000627 else
628 route = ospf6_route_create ();
629
630 route->type = type;
631 route->prefix = prefix;
632 route->path.origin.type = lsa->header->type;
633 route->path.origin.id = lsa->header->id;
634 route->path.origin.adv_router = lsa->header->adv_router;
hasso63069ad2004-09-02 13:01:01 +0000635 route->path.router_bits = router_bits;
hasso049207c2004-08-04 20:02:13 +0000636 route->path.options[0] = options[0];
637 route->path.options[1] = options[1];
638 route->path.options[2] = options[2];
639 route->path.prefix_options = prefix_options;
640 route->path.area_id = oa->area_id;
641 route->path.type = OSPF6_PATH_TYPE_INTER;
642 route->path.cost = abr_entry->path.cost + cost;
643 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
644 route->nexthop[i] = abr_entry->nexthop[i];
645
hasso1e058382004-09-01 21:36:14 +0000646 if (is_debug)
hassoccb59b12004-08-25 09:10:37 +0000647 zlog_info ("Install route: %s", buf);
hasso049207c2004-08-04 20:02:13 +0000648 ospf6_route_add (route, table);
649}
650
hassoccb59b12004-08-25 09:10:37 +0000651void
652ospf6_abr_examin_brouter (u_int32_t router_id)
653{
654 struct ospf6_lsa *lsa;
655 struct ospf6_area *oa;
656 listnode node;
657 u_int16_t type;
658
hassoccb59b12004-08-25 09:10:37 +0000659 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
660 for (node = listhead (ospf6->area_list); node; nextnode (node))
661 {
662 oa = OSPF6_AREA (getdata (node));
663 for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;
664 lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))
665 ospf6_abr_examin_summary (lsa, oa);
666 }
667
668 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
669 for (node = listhead (ospf6->area_list); node; nextnode (node))
670 {
671 oa = OSPF6_AREA (getdata (node));
672 for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;
673 lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))
674 ospf6_abr_examin_summary (lsa, oa);
675 }
676}
677
hasso049207c2004-08-04 20:02:13 +0000678
679/* Display functions */
680int
681ospf6_inter_area_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
682{
683 struct ospf6_inter_prefix_lsa *prefix_lsa;
684 struct in6_addr in6;
685 char buf[64];
686
687 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
688 OSPF6_LSA_HEADER_END (lsa->header);
689
690 vty_out (vty, " Metric: %lu%s",
691 (u_long) OSPF6_ABR_SUMMARY_METRIC (prefix_lsa), VNL);
692
693 ospf6_prefix_options_printbuf (prefix_lsa->prefix.prefix_options,
694 buf, sizeof (buf));
695 vty_out (vty, " Prefix Options: %s%s", buf, VNL);
696
697 ospf6_prefix_in6_addr (&in6, &prefix_lsa->prefix);
698 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
699 vty_out (vty, " Prefix: %s/%d%s", buf,
700 prefix_lsa->prefix.prefix_length, VNL);
701
702 return 0;
703}
704
705int
706ospf6_inter_area_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
707{
708 struct ospf6_inter_router_lsa *router_lsa;
709 char buf[64];
710
711 router_lsa = (struct ospf6_inter_router_lsa *)
712 OSPF6_LSA_HEADER_END (lsa->header);
713
714 ospf6_options_printbuf (router_lsa->options, buf, sizeof (buf));
715 vty_out (vty, " Options: %s%s", buf, VNL);
716 vty_out (vty, " Metric: %lu%s",
717 (u_long) OSPF6_ABR_SUMMARY_METRIC (router_lsa), VNL);
718 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
719 vty_out (vty, " Destination Router ID: %s%s", buf, VNL);
720
721 return 0;
722}
723
724/* Debug commands */
725DEFUN (debug_ospf6_abr,
726 debug_ospf6_abr_cmd,
727 "debug ospf6 abr",
728 DEBUG_STR
729 OSPF6_STR
730 "Debug OSPFv3 ABR function\n"
731 )
732{
733 OSPF6_DEBUG_ABR_ON ();
734 return CMD_SUCCESS;
735}
736
737DEFUN (no_debug_ospf6_abr,
738 no_debug_ospf6_abr_cmd,
739 "no debug ospf6 abr",
740 NO_STR
741 DEBUG_STR
742 OSPF6_STR
743 "Debug OSPFv3 ABR function\n"
744 )
745{
746 OSPF6_DEBUG_ABR_OFF ();
747 return CMD_SUCCESS;
748}
749
750int
751config_write_ospf6_debug_abr (struct vty *vty)
752{
753 if (IS_OSPF6_DEBUG_ABR)
754 vty_out (vty, "debug ospf6 abr%s", VNL);
755 return 0;
756}
757
758void
759install_element_ospf6_debug_abr ()
760{
761 install_element (ENABLE_NODE, &debug_ospf6_abr_cmd);
762 install_element (ENABLE_NODE, &no_debug_ospf6_abr_cmd);
763 install_element (CONFIG_NODE, &debug_ospf6_abr_cmd);
764 install_element (CONFIG_NODE, &no_debug_ospf6_abr_cmd);
765}
766
hasso6452df02004-08-15 05:52:07 +0000767struct ospf6_lsa_handler inter_prefix_handler =
768{
769 OSPF6_LSTYPE_INTER_PREFIX,
770 "Inter-Prefix",
771 ospf6_inter_area_prefix_lsa_show
772};
773
774struct ospf6_lsa_handler inter_router_handler =
775{
776 OSPF6_LSTYPE_INTER_ROUTER,
777 "Inter-Router",
778 ospf6_inter_area_router_lsa_show
779};
780
hasso049207c2004-08-04 20:02:13 +0000781void
782ospf6_abr_init ()
783{
hasso6452df02004-08-15 05:52:07 +0000784 ospf6_install_lsa_handler (&inter_prefix_handler);
785 ospf6_install_lsa_handler (&inter_router_handler);
hasso049207c2004-08-04 20:02:13 +0000786}
787
788