blob: 52fa59033aeb464773d62e85b5d09728af99aa80 [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{
hasso52dc7ee2004-09-23 19:18:23 +000055 struct listnode *node;
hasso6452df02004-08-15 05:52:07 +000056 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;
hasso52dc7ee2004-09-23 19:18:23 +000076 struct listnode *node;
hasso3b687352004-08-19 06:56:53 +000077
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))
hasso4846ef62004-09-03 06:04:00 +000090 {
91 if (CHECK_FLAG (ro->flag, OSPF6_ROUTE_ACTIVE_SUMMARY))
92 ospf6_abr_originate_summary_to_area (ro, area);
93 }
hasso3b687352004-08-19 06:56:53 +000094 }
95 }
96
97 /* install calculated routes to border routers */
98 for (ro = ospf6_route_head (area->ospf6->brouter_table); ro;
99 ro = ospf6_route_next (ro))
100 ospf6_abr_originate_summary_to_area (ro, area);
101
102 /* install calculated routes to network (may be rejected by ranges) */
103 for (ro = ospf6_route_head (area->ospf6->route_table); ro;
104 ro = ospf6_route_next (ro))
105 ospf6_abr_originate_summary_to_area (ro, area);
106}
107
108void
109ospf6_abr_disable_area (struct ospf6_area *area)
110{
111 struct ospf6_area *oa;
112 struct ospf6_route *ro;
113 struct ospf6_lsa *old;
hasso52dc7ee2004-09-23 19:18:23 +0000114 struct listnode *node;
hasso3b687352004-08-19 06:56:53 +0000115
116 /* Withdraw all summary prefixes previously originated */
117 for (ro = ospf6_route_head (area->summary_prefix); ro;
118 ro = ospf6_route_next (ro))
119 {
120 old = ospf6_lsdb_lookup (ro->path.origin.type, ro->path.origin.id,
121 area->ospf6->router_id, area->lsdb);
122 if (old)
123 ospf6_lsa_purge (old);
124 ospf6_route_remove (ro, area->summary_prefix);
125 }
126
127 /* Withdraw all summary router-routes previously originated */
128 for (ro = ospf6_route_head (area->summary_router); ro;
129 ro = ospf6_route_next (ro))
130 {
131 old = ospf6_lsdb_lookup (ro->path.origin.type, ro->path.origin.id,
132 area->ospf6->router_id, area->lsdb);
133 if (old)
134 ospf6_lsa_purge (old);
135 ospf6_route_remove (ro, area->summary_router);
136 }
137
138 /* Schedule Router-LSA for each area (ABR status may change) */
139 for (node = listhead (area->ospf6->area_list); node; nextnode (node))
140 {
141 oa = OSPF6_AREA (getdata (node));
142
143 /* update B bit for each area */
144 OSPF6_ROUTER_LSA_SCHEDULE (oa);
145 }
146}
147
hasso049207c2004-08-04 20:02:13 +0000148/* RFC 2328 12.4.3. Summary-LSAs */
149void
hasso6452df02004-08-15 05:52:07 +0000150ospf6_abr_originate_summary_to_area (struct ospf6_route *route,
151 struct ospf6_area *area)
hasso049207c2004-08-04 20:02:13 +0000152{
153 struct ospf6_lsa *lsa, *old = NULL;
154 struct ospf6_interface *oi;
155 struct ospf6_route *summary, *range = NULL;
156 struct ospf6_area *route_area;
157 char buffer[OSPF6_MAX_LSASIZE];
158 struct ospf6_lsa_header *lsa_header;
159 caddr_t p;
160 struct ospf6_inter_prefix_lsa *prefix_lsa;
hasso6452df02004-08-15 05:52:07 +0000161 struct ospf6_inter_router_lsa *router_lsa;
162 struct ospf6_route_table *summary_table = NULL;
163 u_int16_t type;
hasso1e058382004-09-01 21:36:14 +0000164 char buf[64];
165 int is_debug = 0;
hasso049207c2004-08-04 20:02:13 +0000166
hasso1e058382004-09-01 21:36:14 +0000167 if (route->type == OSPF6_DEST_TYPE_ROUTER)
hasso6452df02004-08-15 05:52:07 +0000168 {
hasso1e058382004-09-01 21:36:14 +0000169 if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_ORIGINATE (INTER_ROUTER))
hasso6452df02004-08-15 05:52:07 +0000170 {
hasso1e058382004-09-01 21:36:14 +0000171 is_debug++;
hasso3b687352004-08-19 06:56:53 +0000172 inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
hasso6452df02004-08-15 05:52:07 +0000173 buf, sizeof (buf));
174 zlog_info ("Originating summary in area %s for ASBR %s",
175 area->name, buf);
176 }
hasso1e058382004-09-01 21:36:14 +0000177 summary_table = area->summary_router;
178 }
179 else
180 {
181 if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_ORIGINATE (INTER_PREFIX))
hasso6452df02004-08-15 05:52:07 +0000182 {
hasso1e058382004-09-01 21:36:14 +0000183 is_debug++;
hasso6452df02004-08-15 05:52:07 +0000184 prefix2str (&route->prefix, buf, sizeof (buf));
185 zlog_info ("Originating summary in area %s for %s",
186 area->name, buf);
187 }
hasso1e058382004-09-01 21:36:14 +0000188 summary_table = area->summary_prefix;
hasso6452df02004-08-15 05:52:07 +0000189 }
190
hasso6452df02004-08-15 05:52:07 +0000191 summary = ospf6_route_lookup (&route->prefix, summary_table);
hasso049207c2004-08-04 20:02:13 +0000192 if (summary)
hasso6452df02004-08-15 05:52:07 +0000193 old = ospf6_lsdb_lookup (summary->path.origin.type,
hasso049207c2004-08-04 20:02:13 +0000194 summary->path.origin.id,
195 area->ospf6->router_id, area->lsdb);
196
197 /* if this route has just removed, remove corresponding LSA */
198 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
199 {
hasso1e058382004-09-01 21:36:14 +0000200 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000201 zlog_info ("The route has just removed, purge previous LSA");
202 if (summary)
203 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000204 if (old)
hasso6452df02004-08-15 05:52:07 +0000205 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000206 return;
207 }
208
hasso6452df02004-08-15 05:52:07 +0000209 /* Only destination type network, range or ASBR are considered */
210 if (route->type != OSPF6_DEST_TYPE_NETWORK &&
211 route->type != OSPF6_DEST_TYPE_RANGE &&
212 (route->type != OSPF6_DEST_TYPE_ROUTER ||
213 ! CHECK_FLAG (route->path.router_bits, OSPF6_ROUTER_BIT_E)))
hasso049207c2004-08-04 20:02:13 +0000214 {
hasso1e058382004-09-01 21:36:14 +0000215 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000216 zlog_info ("Route type is none of network, range nor ASBR, withdraw");
217 if (summary)
218 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000219 if (old)
hasso6452df02004-08-15 05:52:07 +0000220 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000221 return;
222 }
223
224 /* AS External routes are never considered */
225 if (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
226 route->path.type == OSPF6_PATH_TYPE_EXTERNAL2)
227 {
hasso1e058382004-09-01 21:36:14 +0000228 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000229 zlog_info ("Path type is external, withdraw");
230 if (summary)
231 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000232 if (old)
hasso6452df02004-08-15 05:52:07 +0000233 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000234 return;
235 }
236
237 /* do not generate if the path's area is the same as target area */
238 if (route->path.area_id == area->area_id)
239 {
hasso1e058382004-09-01 21:36:14 +0000240 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000241 zlog_info ("The route is in the area itself, ignore");
242 if (summary)
243 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000244 if (old)
hasso6452df02004-08-15 05:52:07 +0000245 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000246 return;
247 }
248
249 /* do not generate if the nexthops belongs to the target area */
250 oi = ospf6_interface_lookup_by_ifindex (route->nexthop[0].ifindex);
hasso6452df02004-08-15 05:52:07 +0000251 if (oi && oi->area && oi->area == area)
hasso049207c2004-08-04 20:02:13 +0000252 {
hasso1e058382004-09-01 21:36:14 +0000253 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000254 zlog_info ("The route's nexthop is in the same area, ignore");
255 if (summary)
256 ospf6_route_remove (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000257 if (old)
hasso6452df02004-08-15 05:52:07 +0000258 ospf6_lsa_purge (old);
hasso049207c2004-08-04 20:02:13 +0000259 return;
260 }
261
hasso6452df02004-08-15 05:52:07 +0000262 /* do not generate if the route cost is greater or equal to LSInfinity */
263 if (route->path.cost >= LS_INFINITY)
264 {
hasso1e058382004-09-01 21:36:14 +0000265 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000266 zlog_info ("The cost exceeds LSInfinity, withdraw");
267 if (summary)
268 ospf6_route_remove (summary, summary_table);
269 if (old)
270 ospf6_lsa_purge (old);
271 return;
272 }
273
274 /* if this is a route to ASBR */
275 if (route->type == OSPF6_DEST_TYPE_ROUTER)
276 {
277 /* Only the prefered best path is considered */
278 if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_BEST))
279 {
hasso1e058382004-09-01 21:36:14 +0000280 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000281 zlog_info ("This is the secondary path to the ASBR, ignore");
282 if (summary)
283 ospf6_route_remove (summary, summary_table);
284 if (old)
285 ospf6_lsa_purge (old);
286 return;
287 }
288
289 /* Do not generate if the area is stub */
290 /* XXX */
291 }
292
293 /* if this is an intra-area route, this may be suppressed by aggregation */
294 if (route->type == OSPF6_DEST_TYPE_NETWORK &&
295 route->path.type == OSPF6_PATH_TYPE_INTRA)
296 {
297 /* search for configured address range for the route's area */
298 route_area = ospf6_area_lookup (route->path.area_id, area->ospf6);
299 assert (route_area);
300 range = ospf6_route_lookup_bestmatch (&route->prefix,
301 route_area->range_table);
302
303 /* ranges are ignored when originate backbone routes to transit area.
304 Otherwise, if ranges are configured, the route is suppressed. */
305 if (range && ! CHECK_FLAG (range->flag, OSPF6_ROUTE_REMOVE) &&
306 (route->path.area_id != BACKBONE_AREA_ID ||
307 ! IS_AREA_TRANSIT (area)))
308 {
hasso1e058382004-09-01 21:36:14 +0000309 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000310 {
hasso6452df02004-08-15 05:52:07 +0000311 prefix2str (&range->prefix, buf, sizeof (buf));
312 zlog_info ("Suppressed by range %s of area %s",
313 buf, route_area->name);
314 }
315
316 if (summary)
317 ospf6_route_remove (summary, summary_table);
318 if (old)
319 ospf6_lsa_purge (old);
320 return;
321 }
322 }
323
324 /* If this is a configured address range */
325 if (route->type == OSPF6_DEST_TYPE_RANGE)
326 {
327 /* If DoNotAdvertise is set */
328 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE))
329 {
hasso1e058382004-09-01 21:36:14 +0000330 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000331 zlog_info ("This is the range with DoNotAdvertise set. ignore");
332 if (summary)
333 ospf6_route_remove (summary, summary_table);
334 if (old)
335 ospf6_lsa_purge (old);
336 return;
337 }
338
339 /* Whether the route have active longer prefix */
340 if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_ACTIVE_SUMMARY))
341 {
hasso1e058382004-09-01 21:36:14 +0000342 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000343 zlog_info ("The range is not active. withdraw");
344 if (summary)
345 ospf6_route_remove (summary, summary_table);
346 if (old)
347 ospf6_lsa_purge (old);
348 return;
349 }
350 }
351
hasso049207c2004-08-04 20:02:13 +0000352 /* the route is going to be originated. store it in area's summary_table */
353 if (summary == NULL)
354 {
355 summary = ospf6_route_copy (route);
hasso6452df02004-08-15 05:52:07 +0000356 if (route->type == OSPF6_DEST_TYPE_NETWORK ||
357 route->type == OSPF6_DEST_TYPE_RANGE)
358 summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_PREFIX);
359 else
360 summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_ROUTER);
hasso049207c2004-08-04 20:02:13 +0000361 summary->path.origin.adv_router = area->ospf6->router_id;
362 summary->path.origin.id =
363 ospf6_new_ls_id (summary->path.origin.type,
364 summary->path.origin.adv_router, area->lsdb);
hasso9428f2d2004-09-13 14:01:12 +0000365 summary = ospf6_route_add (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000366 }
hasso6452df02004-08-15 05:52:07 +0000367 else
368 {
369 summary->type = route->type;
370 gettimeofday (&summary->changed, NULL);
371 }
372
373 summary->path.router_bits = route->path.router_bits;
374 summary->path.options[0] = route->path.options[0];
375 summary->path.options[1] = route->path.options[1];
376 summary->path.options[2] = route->path.options[2];
377 summary->path.prefix_options = route->path.prefix_options;
378 summary->path.area_id = area->area_id;
379 summary->path.type = OSPF6_PATH_TYPE_INTER;
380 summary->path.cost = route->path.cost;
381 summary->nexthop[0] = route->nexthop[0];
hasso049207c2004-08-04 20:02:13 +0000382
383 /* prepare buffer */
384 memset (buffer, 0, sizeof (buffer));
385 lsa_header = (struct ospf6_lsa_header *) buffer;
hasso049207c2004-08-04 20:02:13 +0000386
hasso6452df02004-08-15 05:52:07 +0000387 if (route->type == OSPF6_DEST_TYPE_ROUTER)
388 {
389 router_lsa = (struct ospf6_inter_router_lsa *)
390 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
391 p = (caddr_t) router_lsa + sizeof (struct ospf6_inter_router_lsa);
hasso049207c2004-08-04 20:02:13 +0000392
hasso6452df02004-08-15 05:52:07 +0000393 /* Fill Inter-Area-Router-LSA */
394 router_lsa->options[0] = route->path.options[0];
395 router_lsa->options[1] = route->path.options[1];
396 router_lsa->options[2] = route->path.options[2];
397 OSPF6_ABR_SUMMARY_METRIC_SET (router_lsa, route->path.cost);
hasso3b687352004-08-19 06:56:53 +0000398 router_lsa->router_id = ADV_ROUTER_IN_PREFIX (&route->prefix);
hasso6452df02004-08-15 05:52:07 +0000399 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
400 }
401 else
402 {
403 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
404 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
405 p = (caddr_t) prefix_lsa + sizeof (struct ospf6_inter_prefix_lsa);
hasso049207c2004-08-04 20:02:13 +0000406
hasso6452df02004-08-15 05:52:07 +0000407 /* Fill Inter-Area-Prefix-LSA */
408 OSPF6_ABR_SUMMARY_METRIC_SET (prefix_lsa, route->path.cost);
409 prefix_lsa->prefix.prefix_length = route->prefix.prefixlen;
410 prefix_lsa->prefix.prefix_options = route->path.prefix_options;
hasso049207c2004-08-04 20:02:13 +0000411
hasso6452df02004-08-15 05:52:07 +0000412 /* set Prefix */
413 memcpy (p, &route->prefix.u.prefix6,
414 OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
415 ospf6_prefix_apply_mask (&prefix_lsa->prefix);
416 p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
417 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
418 }
hasso049207c2004-08-04 20:02:13 +0000419
420 /* Fill LSA Header */
421 lsa_header->age = 0;
hasso6452df02004-08-15 05:52:07 +0000422 lsa_header->type = type;
hasso049207c2004-08-04 20:02:13 +0000423 lsa_header->id = summary->path.origin.id;
424 lsa_header->adv_router = area->ospf6->router_id;
425 lsa_header->seqnum =
426 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
427 lsa_header->adv_router, area->lsdb);
428 lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
429
430 /* LSA checksum */
431 ospf6_lsa_checksum (lsa_header);
432
433 /* create LSA */
434 lsa = ospf6_lsa_create (lsa_header);
hasso6452df02004-08-15 05:52:07 +0000435
hasso049207c2004-08-04 20:02:13 +0000436 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000437 ospf6_lsa_originate_area (lsa, area);
hasso049207c2004-08-04 20:02:13 +0000438}
439
440void
hasso6452df02004-08-15 05:52:07 +0000441ospf6_abr_range_update (struct ospf6_route *range)
442{
443 u_int32_t cost = 0;
444 struct ospf6_route *ro;
445
446 assert (range->type == OSPF6_DEST_TYPE_RANGE);
447
448 /* update range's cost and active flag */
449 for (ro = ospf6_route_match_head (&range->prefix, ospf6->route_table);
450 ro; ro = ospf6_route_match_next (&range->prefix, ro))
451 {
452 if (ro->path.area_id == range->path.area_id &&
453 ! CHECK_FLAG (ro->flag, OSPF6_ROUTE_REMOVE))
454 cost = MAX (cost, ro->path.cost);
455 }
456
457 if (range->path.cost != cost)
458 {
459 range->path.cost = cost;
460
461 if (range->path.cost)
462 SET_FLAG (range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY);
463 else
464 UNSET_FLAG (range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY);
465
466 ospf6_abr_originate_summary (range);
467 }
468}
469
470void
471ospf6_abr_originate_summary (struct ospf6_route *route)
hasso049207c2004-08-04 20:02:13 +0000472{
hasso52dc7ee2004-09-23 19:18:23 +0000473 struct listnode *node;
hasso049207c2004-08-04 20:02:13 +0000474 struct ospf6_area *oa;
hasso6452df02004-08-15 05:52:07 +0000475 struct ospf6_route *range = NULL;
hasso049207c2004-08-04 20:02:13 +0000476
hasso6452df02004-08-15 05:52:07 +0000477 if (route->type == OSPF6_DEST_TYPE_NETWORK)
478 {
479 oa = ospf6_area_lookup (route->path.area_id, ospf6);
480 range = ospf6_route_lookup_bestmatch (&route->prefix, oa->range_table);
481 if (range)
482 ospf6_abr_range_update (range);
483 }
484
485 for (node = listhead (ospf6->area_list); node; nextnode (node))
hasso049207c2004-08-04 20:02:13 +0000486 {
487 oa = (struct ospf6_area *) getdata (node);
hasso6452df02004-08-15 05:52:07 +0000488 ospf6_abr_originate_summary_to_area (route, oa);
hasso049207c2004-08-04 20:02:13 +0000489 }
490}
491
492/* RFC 2328 16.2. Calculating the inter-area routes */
493void
494ospf6_abr_examin_summary (struct ospf6_lsa *lsa, struct ospf6_area *oa)
495{
496 struct prefix prefix, abr_prefix;
497 struct ospf6_route_table *table = NULL;
498 struct ospf6_route *range, *route, *old = NULL;
499 struct ospf6_route *abr_entry;
hasso6452df02004-08-15 05:52:07 +0000500 u_char type = 0;
hasso049207c2004-08-04 20:02:13 +0000501 char options[3] = {0, 0, 0};
502 u_int8_t prefix_options = 0;
503 u_int32_t cost = 0;
hasso63069ad2004-09-02 13:01:01 +0000504 u_char router_bits = 0;
hasso049207c2004-08-04 20:02:13 +0000505 int i;
hassoccb59b12004-08-25 09:10:37 +0000506 char buf[64];
hasso1e058382004-09-01 21:36:14 +0000507 int is_debug = 0;
hasso3b687352004-08-19 06:56:53 +0000508
hasso049207c2004-08-04 20:02:13 +0000509 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
510 {
511 struct ospf6_inter_prefix_lsa *prefix_lsa;
hasso1e058382004-09-01 21:36:14 +0000512
513 if (IS_OSPF6_DEBUG_EXAMIN (INTER_PREFIX))
514 {
515 is_debug++;
516 zlog_info ("Examin %s in area %s", lsa->name, oa->name);
517 }
518
hasso049207c2004-08-04 20:02:13 +0000519 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
520 OSPF6_LSA_HEADER_END (lsa->header);
521 prefix.family = AF_INET6;
522 prefix.prefixlen = prefix_lsa->prefix.prefix_length;
523 ospf6_prefix_in6_addr (&prefix.u.prefix6, &prefix_lsa->prefix);
hassoccb59b12004-08-25 09:10:37 +0000524 prefix2str (&prefix, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000525 table = oa->ospf6->route_table;
526 type = OSPF6_DEST_TYPE_NETWORK;
527 prefix_options = prefix_lsa->prefix.prefix_options;
528 cost = OSPF6_ABR_SUMMARY_METRIC (prefix_lsa);
529 }
530 else if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_ROUTER))
531 {
532 struct ospf6_inter_router_lsa *router_lsa;
hasso1e058382004-09-01 21:36:14 +0000533
534 if (IS_OSPF6_DEBUG_EXAMIN (INTER_ROUTER))
535 {
536 is_debug++;
537 zlog_info ("Examin %s in area %s", lsa->name, oa->name);
538 }
539
hasso049207c2004-08-04 20:02:13 +0000540 router_lsa = (struct ospf6_inter_router_lsa *)
541 OSPF6_LSA_HEADER_END (lsa->header);
542 ospf6_linkstate_prefix (router_lsa->router_id, htonl (0), &prefix);
hassoccb59b12004-08-25 09:10:37 +0000543 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000544 table = oa->ospf6->brouter_table;
545 type = OSPF6_DEST_TYPE_ROUTER;
546 options[0] = router_lsa->options[0];
547 options[1] = router_lsa->options[1];
548 options[2] = router_lsa->options[2];
549 cost = OSPF6_ABR_SUMMARY_METRIC (router_lsa);
hasso63069ad2004-09-02 13:01:01 +0000550 SET_FLAG (router_bits, OSPF6_ROUTER_BIT_E);
hasso049207c2004-08-04 20:02:13 +0000551 }
552 else
553 assert (0);
554
hassoccb59b12004-08-25 09:10:37 +0000555 /* Find existing route */
556 route = ospf6_route_lookup (&prefix, table);
557 if (route)
558 ospf6_route_lock (route);
559 while (route && ospf6_route_is_prefix (&prefix, route))
hasso049207c2004-08-04 20:02:13 +0000560 {
561 if (route->path.area_id == oa->area_id &&
562 route->path.origin.type == lsa->header->type &&
563 route->path.origin.id == lsa->header->id &&
564 route->path.origin.adv_router == lsa->header->adv_router)
565 old = route;
hassoccb59b12004-08-25 09:10:37 +0000566 route = ospf6_route_next (route);
hasso049207c2004-08-04 20:02:13 +0000567 }
568
569 /* (1) if cost == LSInfinity or if the LSA is MaxAge */
hasso3b687352004-08-19 06:56:53 +0000570 if (cost == LS_INFINITY)
hasso049207c2004-08-04 20:02:13 +0000571 {
hasso1e058382004-09-01 21:36:14 +0000572 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000573 zlog_info ("cost is LS_INFINITY, ignore");
574 if (old)
hasso63069ad2004-09-02 13:01:01 +0000575 ospf6_route_remove (old, table);
hasso3b687352004-08-19 06:56:53 +0000576 return;
577 }
578 if (OSPF6_LSA_IS_MAXAGE (lsa))
579 {
hasso1e058382004-09-01 21:36:14 +0000580 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000581 zlog_info ("LSA is MaxAge, ignore");
hasso049207c2004-08-04 20:02:13 +0000582 if (old)
hasso63069ad2004-09-02 13:01:01 +0000583 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000584 return;
585 }
586
587 /* (2) if the LSA is self-originated, ignore */
588 if (lsa->header->adv_router == oa->ospf6->router_id)
589 {
hasso1e058382004-09-01 21:36:14 +0000590 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000591 zlog_info ("LSA is self-originated, ignore");
hasso049207c2004-08-04 20:02:13 +0000592 if (old)
hasso63069ad2004-09-02 13:01:01 +0000593 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000594 return;
595 }
596
597 /* (3) if the prefix is equal to an active configured address range */
hasso6452df02004-08-15 05:52:07 +0000598 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
hasso049207c2004-08-04 20:02:13 +0000599 {
hasso6452df02004-08-15 05:52:07 +0000600 range = ospf6_route_lookup (&prefix, oa->range_table);
601 if (range)
602 {
hasso1e058382004-09-01 21:36:14 +0000603 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000604 zlog_info ("Prefix is equal to address range, ignore");
hasso6452df02004-08-15 05:52:07 +0000605 if (old)
hasso63069ad2004-09-02 13:01:01 +0000606 ospf6_route_remove (old, table);
hasso6452df02004-08-15 05:52:07 +0000607 return;
608 }
hasso049207c2004-08-04 20:02:13 +0000609 }
610
611 /* (4) if the routing table entry for the ABR does not exist */
612 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &abr_prefix);
613 abr_entry = ospf6_route_lookup (&abr_prefix, oa->ospf6->brouter_table);
hasso6452df02004-08-15 05:52:07 +0000614 if (abr_entry == NULL || abr_entry->path.area_id != oa->area_id ||
hassoccb59b12004-08-25 09:10:37 +0000615 CHECK_FLAG (abr_entry->flag, OSPF6_ROUTE_REMOVE) ||
hasso6452df02004-08-15 05:52:07 +0000616 ! CHECK_FLAG (abr_entry->path.router_bits, OSPF6_ROUTER_BIT_B))
hasso049207c2004-08-04 20:02:13 +0000617 {
hasso1e058382004-09-01 21:36:14 +0000618 if (is_debug)
hasso3b687352004-08-19 06:56:53 +0000619 zlog_info ("ABR router entry does not exist, ignore");
hasso049207c2004-08-04 20:02:13 +0000620 if (old)
hasso63069ad2004-09-02 13:01:01 +0000621 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000622 return;
623 }
624
625 /* (5),(6),(7) the path preference is handled by the sorting
626 in the routing table. Always install the path by substituting
627 old route (if any). */
628 if (old)
hassoccb59b12004-08-25 09:10:37 +0000629 route = ospf6_route_copy (old);
hasso049207c2004-08-04 20:02:13 +0000630 else
631 route = ospf6_route_create ();
632
633 route->type = type;
634 route->prefix = prefix;
635 route->path.origin.type = lsa->header->type;
636 route->path.origin.id = lsa->header->id;
637 route->path.origin.adv_router = lsa->header->adv_router;
hasso63069ad2004-09-02 13:01:01 +0000638 route->path.router_bits = router_bits;
hasso049207c2004-08-04 20:02:13 +0000639 route->path.options[0] = options[0];
640 route->path.options[1] = options[1];
641 route->path.options[2] = options[2];
642 route->path.prefix_options = prefix_options;
643 route->path.area_id = oa->area_id;
644 route->path.type = OSPF6_PATH_TYPE_INTER;
645 route->path.cost = abr_entry->path.cost + cost;
646 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
647 route->nexthop[i] = abr_entry->nexthop[i];
648
hasso1e058382004-09-01 21:36:14 +0000649 if (is_debug)
hassoccb59b12004-08-25 09:10:37 +0000650 zlog_info ("Install route: %s", buf);
hasso049207c2004-08-04 20:02:13 +0000651 ospf6_route_add (route, table);
652}
653
hassoccb59b12004-08-25 09:10:37 +0000654void
655ospf6_abr_examin_brouter (u_int32_t router_id)
656{
657 struct ospf6_lsa *lsa;
658 struct ospf6_area *oa;
hasso52dc7ee2004-09-23 19:18:23 +0000659 struct listnode *node;
hassoccb59b12004-08-25 09:10:37 +0000660 u_int16_t type;
661
hassoccb59b12004-08-25 09:10:37 +0000662 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
663 for (node = listhead (ospf6->area_list); node; nextnode (node))
664 {
665 oa = OSPF6_AREA (getdata (node));
666 for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;
667 lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))
668 ospf6_abr_examin_summary (lsa, oa);
669 }
670
671 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
672 for (node = listhead (ospf6->area_list); node; nextnode (node))
673 {
674 oa = OSPF6_AREA (getdata (node));
675 for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;
676 lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))
677 ospf6_abr_examin_summary (lsa, oa);
678 }
679}
680
hasso049207c2004-08-04 20:02:13 +0000681
682/* Display functions */
683int
684ospf6_inter_area_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
685{
686 struct ospf6_inter_prefix_lsa *prefix_lsa;
687 struct in6_addr in6;
688 char buf[64];
689
690 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
691 OSPF6_LSA_HEADER_END (lsa->header);
692
693 vty_out (vty, " Metric: %lu%s",
694 (u_long) OSPF6_ABR_SUMMARY_METRIC (prefix_lsa), VNL);
695
696 ospf6_prefix_options_printbuf (prefix_lsa->prefix.prefix_options,
697 buf, sizeof (buf));
698 vty_out (vty, " Prefix Options: %s%s", buf, VNL);
699
700 ospf6_prefix_in6_addr (&in6, &prefix_lsa->prefix);
701 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
702 vty_out (vty, " Prefix: %s/%d%s", buf,
703 prefix_lsa->prefix.prefix_length, VNL);
704
705 return 0;
706}
707
708int
709ospf6_inter_area_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
710{
711 struct ospf6_inter_router_lsa *router_lsa;
712 char buf[64];
713
714 router_lsa = (struct ospf6_inter_router_lsa *)
715 OSPF6_LSA_HEADER_END (lsa->header);
716
717 ospf6_options_printbuf (router_lsa->options, buf, sizeof (buf));
718 vty_out (vty, " Options: %s%s", buf, VNL);
719 vty_out (vty, " Metric: %lu%s",
720 (u_long) OSPF6_ABR_SUMMARY_METRIC (router_lsa), VNL);
721 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
722 vty_out (vty, " Destination Router ID: %s%s", buf, VNL);
723
724 return 0;
725}
726
727/* Debug commands */
728DEFUN (debug_ospf6_abr,
729 debug_ospf6_abr_cmd,
730 "debug ospf6 abr",
731 DEBUG_STR
732 OSPF6_STR
733 "Debug OSPFv3 ABR function\n"
734 )
735{
736 OSPF6_DEBUG_ABR_ON ();
737 return CMD_SUCCESS;
738}
739
740DEFUN (no_debug_ospf6_abr,
741 no_debug_ospf6_abr_cmd,
742 "no debug ospf6 abr",
743 NO_STR
744 DEBUG_STR
745 OSPF6_STR
746 "Debug OSPFv3 ABR function\n"
747 )
748{
749 OSPF6_DEBUG_ABR_OFF ();
750 return CMD_SUCCESS;
751}
752
753int
754config_write_ospf6_debug_abr (struct vty *vty)
755{
756 if (IS_OSPF6_DEBUG_ABR)
757 vty_out (vty, "debug ospf6 abr%s", VNL);
758 return 0;
759}
760
761void
762install_element_ospf6_debug_abr ()
763{
764 install_element (ENABLE_NODE, &debug_ospf6_abr_cmd);
765 install_element (ENABLE_NODE, &no_debug_ospf6_abr_cmd);
766 install_element (CONFIG_NODE, &debug_ospf6_abr_cmd);
767 install_element (CONFIG_NODE, &no_debug_ospf6_abr_cmd);
768}
769
hasso6452df02004-08-15 05:52:07 +0000770struct ospf6_lsa_handler inter_prefix_handler =
771{
772 OSPF6_LSTYPE_INTER_PREFIX,
773 "Inter-Prefix",
774 ospf6_inter_area_prefix_lsa_show
775};
776
777struct ospf6_lsa_handler inter_router_handler =
778{
779 OSPF6_LSTYPE_INTER_ROUTER,
780 "Inter-Router",
781 ospf6_inter_area_router_lsa_show
782};
783
hasso049207c2004-08-04 20:02:13 +0000784void
785ospf6_abr_init ()
786{
hasso6452df02004-08-15 05:52:07 +0000787 ospf6_install_lsa_handler (&inter_prefix_handler);
788 ospf6_install_lsa_handler (&inter_router_handler);
hasso049207c2004-08-04 20:02:13 +0000789}
790
791