blob: c3a63fe60e55c1444a8dec7f06393795a6beb386 [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"
hasso34956b32005-06-24 08:44:02 +000032#include "plist.h"
33#include "filter.h"
hasso049207c2004-08-04 20:02:13 +000034
35#include "ospf6_proto.h"
36#include "ospf6_route.h"
37#include "ospf6_lsa.h"
38#include "ospf6_route.h"
39#include "ospf6_lsdb.h"
hasso6452df02004-08-15 05:52:07 +000040#include "ospf6_message.h"
41
hasso049207c2004-08-04 20:02:13 +000042#include "ospf6_top.h"
43#include "ospf6_area.h"
44#include "ospf6_interface.h"
hasso6452df02004-08-15 05:52:07 +000045#include "ospf6_neighbor.h"
46
hasso6452df02004-08-15 05:52:07 +000047#include "ospf6_flood.h"
hasso3b687352004-08-19 06:56:53 +000048#include "ospf6_intra.h"
49#include "ospf6_abr.h"
hasso049207c2004-08-04 20:02:13 +000050#include "ospf6d.h"
51
52unsigned char conf_debug_ospf6_abr;
53
hasso6452df02004-08-15 05:52:07 +000054int
55ospf6_is_router_abr (struct ospf6 *o)
56{
hasso52dc7ee2004-09-23 19:18:23 +000057 struct listnode *node;
hasso6452df02004-08-15 05:52:07 +000058 struct ospf6_area *oa;
59 int area_count = 0;
60
paul1eb8ef22005-04-07 07:30:20 +000061 for (ALL_LIST_ELEMENTS_RO (o->area_list, node, oa))
62 if (IS_AREA_ENABLED (oa))
63 area_count++;
hasso6452df02004-08-15 05:52:07 +000064
65 if (area_count > 1)
66 return 1;
67 return 0;
68}
69
hasso3b687352004-08-19 06:56:53 +000070void
71ospf6_abr_enable_area (struct ospf6_area *area)
72{
73 struct ospf6_area *oa;
74 struct ospf6_route *ro;
paul1eb8ef22005-04-07 07:30:20 +000075 struct listnode *node, *nnode;
hasso3b687352004-08-19 06:56:53 +000076
paul1eb8ef22005-04-07 07:30:20 +000077 for (ALL_LIST_ELEMENTS (area->ospf6->area_list, node, nnode, oa))
hasso3b687352004-08-19 06:56:53 +000078 {
hasso3b687352004-08-19 06:56:53 +000079 /* update B bit for each area */
80 OSPF6_ROUTER_LSA_SCHEDULE (oa);
81
82 /* install other area's configured address range */
83 if (oa != area)
84 {
85 for (ro = ospf6_route_head (oa->range_table); ro;
86 ro = ospf6_route_next (ro))
hasso4846ef62004-09-03 06:04:00 +000087 {
88 if (CHECK_FLAG (ro->flag, OSPF6_ROUTE_ACTIVE_SUMMARY))
89 ospf6_abr_originate_summary_to_area (ro, area);
90 }
hasso3b687352004-08-19 06:56:53 +000091 }
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;
paul1eb8ef22005-04-07 07:30:20 +0000111 struct listnode *node, *nnode;
hasso3b687352004-08-19 06:56:53 +0000112
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) */
paul1eb8ef22005-04-07 07:30:20 +0000136 for (ALL_LIST_ELEMENTS (area->ospf6->area_list, node, nnode, oa))
137 /* update B bit for each area */
138 OSPF6_ROUTER_LSA_SCHEDULE (oa);
hasso3b687352004-08-19 06:56:53 +0000139}
140
hasso049207c2004-08-04 20:02:13 +0000141/* RFC 2328 12.4.3. Summary-LSAs */
142void
hasso6452df02004-08-15 05:52:07 +0000143ospf6_abr_originate_summary_to_area (struct ospf6_route *route,
144 struct ospf6_area *area)
hasso049207c2004-08-04 20:02:13 +0000145{
146 struct ospf6_lsa *lsa, *old = NULL;
147 struct ospf6_interface *oi;
148 struct ospf6_route *summary, *range = NULL;
149 struct ospf6_area *route_area;
150 char buffer[OSPF6_MAX_LSASIZE];
151 struct ospf6_lsa_header *lsa_header;
152 caddr_t p;
153 struct ospf6_inter_prefix_lsa *prefix_lsa;
hasso6452df02004-08-15 05:52:07 +0000154 struct ospf6_inter_router_lsa *router_lsa;
155 struct ospf6_route_table *summary_table = NULL;
156 u_int16_t type;
hasso1e058382004-09-01 21:36:14 +0000157 char buf[64];
158 int is_debug = 0;
hasso049207c2004-08-04 20:02:13 +0000159
hasso1e058382004-09-01 21:36:14 +0000160 if (route->type == OSPF6_DEST_TYPE_ROUTER)
hasso6452df02004-08-15 05:52:07 +0000161 {
hasso1e058382004-09-01 21:36:14 +0000162 if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_ORIGINATE (INTER_ROUTER))
hasso6452df02004-08-15 05:52:07 +0000163 {
hasso1e058382004-09-01 21:36:14 +0000164 is_debug++;
hasso3b687352004-08-19 06:56:53 +0000165 inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
hasso6452df02004-08-15 05:52:07 +0000166 buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000167 zlog_debug ("Originating summary in area %s for ASBR %s",
168 area->name, buf);
hasso6452df02004-08-15 05:52:07 +0000169 }
hasso1e058382004-09-01 21:36:14 +0000170 summary_table = area->summary_router;
171 }
172 else
173 {
174 if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_ORIGINATE (INTER_PREFIX))
hasso6452df02004-08-15 05:52:07 +0000175 {
hasso1e058382004-09-01 21:36:14 +0000176 is_debug++;
hasso6452df02004-08-15 05:52:07 +0000177 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000178 zlog_debug ("Originating summary in area %s for %s",
179 area->name, buf);
hasso6452df02004-08-15 05:52:07 +0000180 }
hasso1e058382004-09-01 21:36:14 +0000181 summary_table = area->summary_prefix;
hasso6452df02004-08-15 05:52:07 +0000182 }
183
hasso6452df02004-08-15 05:52:07 +0000184 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 {
hasso1e058382004-09-01 21:36:14 +0000193 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000194 zlog_debug ("The route has just removed, purge previous LSA");
hasso6452df02004-08-15 05:52:07 +0000195 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 {
hasso1e058382004-09-01 21:36:14 +0000208 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000209 zlog_debug ("Route type is none of network, range nor ASBR, withdraw");
hasso6452df02004-08-15 05:52:07 +0000210 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 {
hasso1e058382004-09-01 21:36:14 +0000221 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000222 zlog_debug ("Path type is external, withdraw");
hasso6452df02004-08-15 05:52:07 +0000223 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 {
hasso1e058382004-09-01 21:36:14 +0000233 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000234 zlog_debug ("The route is in the area itself, ignore");
hasso6452df02004-08-15 05:52:07 +0000235 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 {
hasso1e058382004-09-01 21:36:14 +0000246 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000247 zlog_debug ("The route's nexthop is in the same area, ignore");
hasso6452df02004-08-15 05:52:07 +0000248 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 {
hasso1e058382004-09-01 21:36:14 +0000258 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000259 zlog_debug ("The cost exceeds LSInfinity, withdraw");
hasso6452df02004-08-15 05:52:07 +0000260 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 {
hasso1e058382004-09-01 21:36:14 +0000273 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000274 zlog_debug ("This is the secondary path to the ASBR, ignore");
hasso6452df02004-08-15 05:52:07 +0000275 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 {
hasso1e058382004-09-01 21:36:14 +0000302 if (is_debug)
hasso6452df02004-08-15 05:52:07 +0000303 {
hasso6452df02004-08-15 05:52:07 +0000304 prefix2str (&range->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000305 zlog_debug ("Suppressed by range %s of area %s",
hasso6452df02004-08-15 05:52:07 +0000306 buf, route_area->name);
307 }
308
309 if (summary)
310 ospf6_route_remove (summary, summary_table);
311 if (old)
312 ospf6_lsa_purge (old);
313 return;
314 }
315 }
316
317 /* If this is a configured address range */
318 if (route->type == OSPF6_DEST_TYPE_RANGE)
319 {
320 /* If DoNotAdvertise is set */
321 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE))
322 {
hasso1e058382004-09-01 21:36:14 +0000323 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000324 zlog_debug ("This is the range with DoNotAdvertise set. ignore");
hasso6452df02004-08-15 05:52:07 +0000325 if (summary)
326 ospf6_route_remove (summary, summary_table);
327 if (old)
328 ospf6_lsa_purge (old);
329 return;
330 }
331
332 /* Whether the route have active longer prefix */
333 if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_ACTIVE_SUMMARY))
334 {
hasso1e058382004-09-01 21:36:14 +0000335 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000336 zlog_debug ("The range is not active. withdraw");
hasso6452df02004-08-15 05:52:07 +0000337 if (summary)
338 ospf6_route_remove (summary, summary_table);
339 if (old)
340 ospf6_lsa_purge (old);
341 return;
342 }
343 }
344
hasso34956b32005-06-24 08:44:02 +0000345 /* Check export list */
346 if (EXPORT_NAME (area))
347 {
348 if (EXPORT_LIST (area) == NULL)
349 EXPORT_LIST (area) =
350 access_list_lookup (AFI_IP6, EXPORT_NAME (area));
351
352 if (EXPORT_LIST (area))
353 if (access_list_apply (EXPORT_LIST (area),
354 &route->prefix) == FILTER_DENY)
355 {
356 if (is_debug)
357 {
358 inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
359 buf, sizeof(buf));
360 zlog_debug ("prefix %s was denied by export list", buf);
361 }
362 return;
363 }
364 }
365
366 /* Check filter-list */
367 if (PREFIX_NAME_OUT (area))
368 {
369 if (PREFIX_LIST_OUT (area) == NULL)
370 PREFIX_LIST_OUT (area) =
371 prefix_list_lookup(AFI_IP6, PREFIX_NAME_OUT (area));
372
373 if (PREFIX_LIST_OUT (area))
374 if (prefix_list_apply (PREFIX_LIST_OUT (area),
375 &route->prefix) != PREFIX_PERMIT)
376 {
377 if (is_debug)
378 {
379 inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
380 buf, sizeof (buf));
381 zlog_debug ("prefix %s was denied by filter-list out", buf);
382 }
383 return;
384 }
385 }
386
hasso049207c2004-08-04 20:02:13 +0000387 /* the route is going to be originated. store it in area's summary_table */
388 if (summary == NULL)
389 {
390 summary = ospf6_route_copy (route);
hasso6452df02004-08-15 05:52:07 +0000391 if (route->type == OSPF6_DEST_TYPE_NETWORK ||
392 route->type == OSPF6_DEST_TYPE_RANGE)
393 summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_PREFIX);
394 else
395 summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_ROUTER);
hasso049207c2004-08-04 20:02:13 +0000396 summary->path.origin.adv_router = area->ospf6->router_id;
397 summary->path.origin.id =
398 ospf6_new_ls_id (summary->path.origin.type,
399 summary->path.origin.adv_router, area->lsdb);
hasso9428f2d2004-09-13 14:01:12 +0000400 summary = ospf6_route_add (summary, summary_table);
hasso049207c2004-08-04 20:02:13 +0000401 }
hasso6452df02004-08-15 05:52:07 +0000402 else
403 {
404 summary->type = route->type;
Takashi Sogabe86f72dc2009-06-22 13:07:02 +0900405 quagga_gettime (QUAGGA_CLK_MONOTONIC, &summary->changed);
hasso6452df02004-08-15 05:52:07 +0000406 }
407
408 summary->path.router_bits = route->path.router_bits;
409 summary->path.options[0] = route->path.options[0];
410 summary->path.options[1] = route->path.options[1];
411 summary->path.options[2] = route->path.options[2];
412 summary->path.prefix_options = route->path.prefix_options;
413 summary->path.area_id = area->area_id;
414 summary->path.type = OSPF6_PATH_TYPE_INTER;
415 summary->path.cost = route->path.cost;
416 summary->nexthop[0] = route->nexthop[0];
hasso049207c2004-08-04 20:02:13 +0000417
418 /* prepare buffer */
419 memset (buffer, 0, sizeof (buffer));
420 lsa_header = (struct ospf6_lsa_header *) buffer;
hasso049207c2004-08-04 20:02:13 +0000421
hasso6452df02004-08-15 05:52:07 +0000422 if (route->type == OSPF6_DEST_TYPE_ROUTER)
423 {
424 router_lsa = (struct ospf6_inter_router_lsa *)
425 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
426 p = (caddr_t) router_lsa + sizeof (struct ospf6_inter_router_lsa);
hasso049207c2004-08-04 20:02:13 +0000427
hasso6452df02004-08-15 05:52:07 +0000428 /* Fill Inter-Area-Router-LSA */
429 router_lsa->options[0] = route->path.options[0];
430 router_lsa->options[1] = route->path.options[1];
431 router_lsa->options[2] = route->path.options[2];
432 OSPF6_ABR_SUMMARY_METRIC_SET (router_lsa, route->path.cost);
hasso3b687352004-08-19 06:56:53 +0000433 router_lsa->router_id = ADV_ROUTER_IN_PREFIX (&route->prefix);
hasso6452df02004-08-15 05:52:07 +0000434 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
435 }
436 else
437 {
438 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
439 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
440 p = (caddr_t) prefix_lsa + sizeof (struct ospf6_inter_prefix_lsa);
hasso049207c2004-08-04 20:02:13 +0000441
hasso6452df02004-08-15 05:52:07 +0000442 /* Fill Inter-Area-Prefix-LSA */
443 OSPF6_ABR_SUMMARY_METRIC_SET (prefix_lsa, route->path.cost);
444 prefix_lsa->prefix.prefix_length = route->prefix.prefixlen;
445 prefix_lsa->prefix.prefix_options = route->path.prefix_options;
hasso049207c2004-08-04 20:02:13 +0000446
hasso6452df02004-08-15 05:52:07 +0000447 /* set Prefix */
448 memcpy (p, &route->prefix.u.prefix6,
449 OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
450 ospf6_prefix_apply_mask (&prefix_lsa->prefix);
451 p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
452 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
453 }
hasso049207c2004-08-04 20:02:13 +0000454
455 /* Fill LSA Header */
456 lsa_header->age = 0;
hasso6452df02004-08-15 05:52:07 +0000457 lsa_header->type = type;
hasso049207c2004-08-04 20:02:13 +0000458 lsa_header->id = summary->path.origin.id;
459 lsa_header->adv_router = area->ospf6->router_id;
460 lsa_header->seqnum =
461 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
462 lsa_header->adv_router, area->lsdb);
463 lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
464
465 /* LSA checksum */
466 ospf6_lsa_checksum (lsa_header);
467
468 /* create LSA */
469 lsa = ospf6_lsa_create (lsa_header);
hasso6452df02004-08-15 05:52:07 +0000470
hasso049207c2004-08-04 20:02:13 +0000471 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000472 ospf6_lsa_originate_area (lsa, area);
hasso049207c2004-08-04 20:02:13 +0000473}
474
Paul Jakma6ac29a52008-08-15 13:45:30 +0100475static void
hasso6452df02004-08-15 05:52:07 +0000476ospf6_abr_range_update (struct ospf6_route *range)
477{
478 u_int32_t cost = 0;
479 struct ospf6_route *ro;
480
481 assert (range->type == OSPF6_DEST_TYPE_RANGE);
482
483 /* update range's cost and active flag */
484 for (ro = ospf6_route_match_head (&range->prefix, ospf6->route_table);
485 ro; ro = ospf6_route_match_next (&range->prefix, ro))
486 {
487 if (ro->path.area_id == range->path.area_id &&
488 ! CHECK_FLAG (ro->flag, OSPF6_ROUTE_REMOVE))
489 cost = MAX (cost, ro->path.cost);
490 }
491
492 if (range->path.cost != cost)
493 {
494 range->path.cost = cost;
495
496 if (range->path.cost)
497 SET_FLAG (range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY);
498 else
499 UNSET_FLAG (range->flag, OSPF6_ROUTE_ACTIVE_SUMMARY);
500
501 ospf6_abr_originate_summary (range);
502 }
503}
504
505void
506ospf6_abr_originate_summary (struct ospf6_route *route)
hasso049207c2004-08-04 20:02:13 +0000507{
paul1eb8ef22005-04-07 07:30:20 +0000508 struct listnode *node, *nnode;
hasso049207c2004-08-04 20:02:13 +0000509 struct ospf6_area *oa;
hasso6452df02004-08-15 05:52:07 +0000510 struct ospf6_route *range = NULL;
hasso049207c2004-08-04 20:02:13 +0000511
hasso6452df02004-08-15 05:52:07 +0000512 if (route->type == OSPF6_DEST_TYPE_NETWORK)
513 {
514 oa = ospf6_area_lookup (route->path.area_id, ospf6);
515 range = ospf6_route_lookup_bestmatch (&route->prefix, oa->range_table);
516 if (range)
517 ospf6_abr_range_update (range);
518 }
519
paul1eb8ef22005-04-07 07:30:20 +0000520 for (ALL_LIST_ELEMENTS (ospf6->area_list, node, nnode, oa))
521 ospf6_abr_originate_summary_to_area (route, oa);
hasso049207c2004-08-04 20:02:13 +0000522}
523
524/* RFC 2328 16.2. Calculating the inter-area routes */
525void
526ospf6_abr_examin_summary (struct ospf6_lsa *lsa, struct ospf6_area *oa)
527{
528 struct prefix prefix, abr_prefix;
529 struct ospf6_route_table *table = NULL;
530 struct ospf6_route *range, *route, *old = NULL;
531 struct ospf6_route *abr_entry;
hasso6452df02004-08-15 05:52:07 +0000532 u_char type = 0;
hasso049207c2004-08-04 20:02:13 +0000533 char options[3] = {0, 0, 0};
534 u_int8_t prefix_options = 0;
535 u_int32_t cost = 0;
hasso63069ad2004-09-02 13:01:01 +0000536 u_char router_bits = 0;
hasso049207c2004-08-04 20:02:13 +0000537 int i;
hassoccb59b12004-08-25 09:10:37 +0000538 char buf[64];
hasso1e058382004-09-01 21:36:14 +0000539 int is_debug = 0;
hasso3b687352004-08-19 06:56:53 +0000540
Paul Jakmacf1ce252006-05-15 10:46:07 +0000541 memset (&prefix, 0, sizeof (prefix));
542
hasso049207c2004-08-04 20:02:13 +0000543 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
544 {
545 struct ospf6_inter_prefix_lsa *prefix_lsa;
hasso1e058382004-09-01 21:36:14 +0000546
547 if (IS_OSPF6_DEBUG_EXAMIN (INTER_PREFIX))
548 {
549 is_debug++;
hassoc6487d62004-12-24 06:00:11 +0000550 zlog_debug ("Examin %s in area %s", lsa->name, oa->name);
hasso1e058382004-09-01 21:36:14 +0000551 }
552
hasso049207c2004-08-04 20:02:13 +0000553 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
554 OSPF6_LSA_HEADER_END (lsa->header);
555 prefix.family = AF_INET6;
556 prefix.prefixlen = prefix_lsa->prefix.prefix_length;
557 ospf6_prefix_in6_addr (&prefix.u.prefix6, &prefix_lsa->prefix);
Denis Ovsienkod91f35b2011-08-19 22:24:27 +0400558 if (is_debug)
559 prefix2str (&prefix, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000560 table = oa->ospf6->route_table;
561 type = OSPF6_DEST_TYPE_NETWORK;
562 prefix_options = prefix_lsa->prefix.prefix_options;
563 cost = OSPF6_ABR_SUMMARY_METRIC (prefix_lsa);
564 }
565 else if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_ROUTER))
566 {
567 struct ospf6_inter_router_lsa *router_lsa;
hasso1e058382004-09-01 21:36:14 +0000568
569 if (IS_OSPF6_DEBUG_EXAMIN (INTER_ROUTER))
570 {
571 is_debug++;
hassoc6487d62004-12-24 06:00:11 +0000572 zlog_debug ("Examin %s in area %s", lsa->name, oa->name);
hasso1e058382004-09-01 21:36:14 +0000573 }
574
hasso049207c2004-08-04 20:02:13 +0000575 router_lsa = (struct ospf6_inter_router_lsa *)
576 OSPF6_LSA_HEADER_END (lsa->header);
577 ospf6_linkstate_prefix (router_lsa->router_id, htonl (0), &prefix);
Denis Ovsienkod91f35b2011-08-19 22:24:27 +0400578 if (is_debug)
579 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000580 table = oa->ospf6->brouter_table;
581 type = OSPF6_DEST_TYPE_ROUTER;
582 options[0] = router_lsa->options[0];
583 options[1] = router_lsa->options[1];
584 options[2] = router_lsa->options[2];
585 cost = OSPF6_ABR_SUMMARY_METRIC (router_lsa);
hasso63069ad2004-09-02 13:01:01 +0000586 SET_FLAG (router_bits, OSPF6_ROUTER_BIT_E);
hasso049207c2004-08-04 20:02:13 +0000587 }
588 else
589 assert (0);
590
hassoccb59b12004-08-25 09:10:37 +0000591 /* Find existing route */
592 route = ospf6_route_lookup (&prefix, table);
593 if (route)
594 ospf6_route_lock (route);
595 while (route && ospf6_route_is_prefix (&prefix, route))
hasso049207c2004-08-04 20:02:13 +0000596 {
597 if (route->path.area_id == oa->area_id &&
598 route->path.origin.type == lsa->header->type &&
599 route->path.origin.id == lsa->header->id &&
Paul Jakmacf1ce252006-05-15 10:46:07 +0000600 route->path.origin.adv_router == lsa->header->adv_router &&
601 ! CHECK_FLAG (route->flag, OSPF6_ROUTE_WAS_REMOVED))
hasso049207c2004-08-04 20:02:13 +0000602 old = route;
hassoccb59b12004-08-25 09:10:37 +0000603 route = ospf6_route_next (route);
hasso049207c2004-08-04 20:02:13 +0000604 }
605
606 /* (1) if cost == LSInfinity or if the LSA is MaxAge */
hasso3b687352004-08-19 06:56:53 +0000607 if (cost == LS_INFINITY)
hasso049207c2004-08-04 20:02:13 +0000608 {
hasso1e058382004-09-01 21:36:14 +0000609 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000610 zlog_debug ("cost is LS_INFINITY, ignore");
hasso3b687352004-08-19 06:56:53 +0000611 if (old)
hasso63069ad2004-09-02 13:01:01 +0000612 ospf6_route_remove (old, table);
hasso3b687352004-08-19 06:56:53 +0000613 return;
614 }
615 if (OSPF6_LSA_IS_MAXAGE (lsa))
616 {
hasso1e058382004-09-01 21:36:14 +0000617 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000618 zlog_debug ("LSA is MaxAge, ignore");
hasso049207c2004-08-04 20:02:13 +0000619 if (old)
hasso63069ad2004-09-02 13:01:01 +0000620 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000621 return;
622 }
623
624 /* (2) if the LSA is self-originated, ignore */
625 if (lsa->header->adv_router == oa->ospf6->router_id)
626 {
hasso1e058382004-09-01 21:36:14 +0000627 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000628 zlog_debug ("LSA is self-originated, ignore");
hasso049207c2004-08-04 20:02:13 +0000629 if (old)
hasso63069ad2004-09-02 13:01:01 +0000630 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000631 return;
632 }
633
634 /* (3) if the prefix is equal to an active configured address range */
hasso6452df02004-08-15 05:52:07 +0000635 if (lsa->header->type == htons (OSPF6_LSTYPE_INTER_PREFIX))
hasso049207c2004-08-04 20:02:13 +0000636 {
hasso6452df02004-08-15 05:52:07 +0000637 range = ospf6_route_lookup (&prefix, oa->range_table);
638 if (range)
639 {
hasso1e058382004-09-01 21:36:14 +0000640 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000641 zlog_debug ("Prefix is equal to address range, ignore");
hasso6452df02004-08-15 05:52:07 +0000642 if (old)
hasso63069ad2004-09-02 13:01:01 +0000643 ospf6_route_remove (old, table);
hasso6452df02004-08-15 05:52:07 +0000644 return;
645 }
hasso049207c2004-08-04 20:02:13 +0000646 }
647
648 /* (4) if the routing table entry for the ABR does not exist */
649 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &abr_prefix);
650 abr_entry = ospf6_route_lookup (&abr_prefix, oa->ospf6->brouter_table);
hasso6452df02004-08-15 05:52:07 +0000651 if (abr_entry == NULL || abr_entry->path.area_id != oa->area_id ||
hassoccb59b12004-08-25 09:10:37 +0000652 CHECK_FLAG (abr_entry->flag, OSPF6_ROUTE_REMOVE) ||
hasso6452df02004-08-15 05:52:07 +0000653 ! CHECK_FLAG (abr_entry->path.router_bits, OSPF6_ROUTER_BIT_B))
hasso049207c2004-08-04 20:02:13 +0000654 {
hasso1e058382004-09-01 21:36:14 +0000655 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000656 zlog_debug ("ABR router entry does not exist, ignore");
hasso049207c2004-08-04 20:02:13 +0000657 if (old)
hasso63069ad2004-09-02 13:01:01 +0000658 ospf6_route_remove (old, table);
hasso049207c2004-08-04 20:02:13 +0000659 return;
660 }
661
hasso34956b32005-06-24 08:44:02 +0000662 /* Check import list */
663 if (IMPORT_NAME (oa))
664 {
665 if (IMPORT_LIST (oa) == NULL)
666 IMPORT_LIST (oa) = access_list_lookup (AFI_IP6, IMPORT_NAME (oa));
667
668 if (IMPORT_LIST (oa))
669 if (access_list_apply (IMPORT_LIST (oa), &prefix) == FILTER_DENY)
670 {
671 if (is_debug)
672 zlog_debug ("Prefix was denied by import-list");
673 if (old)
674 ospf6_route_remove (old, table);
675 return;
676 }
677 }
678
679 /* Check input prefix-list */
680 if (PREFIX_NAME_IN (oa))
681 {
682 if (PREFIX_LIST_IN (oa) == NULL)
683 PREFIX_LIST_IN (oa) = prefix_list_lookup (AFI_IP6, PREFIX_NAME_IN (oa));
684
685 if (PREFIX_LIST_IN (oa))
686 if (prefix_list_apply (PREFIX_LIST_IN (oa), &prefix) != PREFIX_PERMIT)
687 {
688 if (is_debug)
689 zlog_debug ("Prefix was denied by prefix-list");
690 if (old)
691 ospf6_route_remove (old, table);
692 return;
693 }
694 }
695
hasso049207c2004-08-04 20:02:13 +0000696 /* (5),(6),(7) the path preference is handled by the sorting
697 in the routing table. Always install the path by substituting
698 old route (if any). */
699 if (old)
hassoccb59b12004-08-25 09:10:37 +0000700 route = ospf6_route_copy (old);
hasso049207c2004-08-04 20:02:13 +0000701 else
702 route = ospf6_route_create ();
703
704 route->type = type;
705 route->prefix = prefix;
706 route->path.origin.type = lsa->header->type;
707 route->path.origin.id = lsa->header->id;
708 route->path.origin.adv_router = lsa->header->adv_router;
hasso63069ad2004-09-02 13:01:01 +0000709 route->path.router_bits = router_bits;
hasso049207c2004-08-04 20:02:13 +0000710 route->path.options[0] = options[0];
711 route->path.options[1] = options[1];
712 route->path.options[2] = options[2];
713 route->path.prefix_options = prefix_options;
714 route->path.area_id = oa->area_id;
715 route->path.type = OSPF6_PATH_TYPE_INTER;
716 route->path.cost = abr_entry->path.cost + cost;
717 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
718 route->nexthop[i] = abr_entry->nexthop[i];
719
hasso1e058382004-09-01 21:36:14 +0000720 if (is_debug)
hassoc6487d62004-12-24 06:00:11 +0000721 zlog_debug ("Install route: %s", buf);
hasso049207c2004-08-04 20:02:13 +0000722 ospf6_route_add (route, table);
723}
724
hassoccb59b12004-08-25 09:10:37 +0000725void
726ospf6_abr_examin_brouter (u_int32_t router_id)
727{
728 struct ospf6_lsa *lsa;
729 struct ospf6_area *oa;
paul1eb8ef22005-04-07 07:30:20 +0000730 struct listnode *node, *nnode;
hassoccb59b12004-08-25 09:10:37 +0000731 u_int16_t type;
732
paul1eb8ef22005-04-07 07:30:20 +0000733 for (ALL_LIST_ELEMENTS (ospf6->area_list, node, nnode, oa))
hassoccb59b12004-08-25 09:10:37 +0000734 {
paul1eb8ef22005-04-07 07:30:20 +0000735 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
hassoccb59b12004-08-25 09:10:37 +0000736 for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;
737 lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))
738 ospf6_abr_examin_summary (lsa, oa);
hassoccb59b12004-08-25 09:10:37 +0000739
paul1eb8ef22005-04-07 07:30:20 +0000740 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
hassoccb59b12004-08-25 09:10:37 +0000741 for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa;
742 lsa = ospf6_lsdb_type_router_next (type, router_id, lsa))
743 ospf6_abr_examin_summary (lsa, oa);
744 }
745}
746
hasso34956b32005-06-24 08:44:02 +0000747void
748ospf6_abr_reimport (struct ospf6_area *oa)
749{
750 struct ospf6_lsa *lsa;
751 u_int16_t type;
752
753 type = htons (OSPF6_LSTYPE_INTER_ROUTER);
754 for (lsa = ospf6_lsdb_type_head (type, oa->lsdb); lsa;
755 lsa = ospf6_lsdb_type_next (type, lsa))
756 ospf6_abr_examin_summary (lsa, oa);
757
758 type = htons (OSPF6_LSTYPE_INTER_PREFIX);
759 for (lsa = ospf6_lsdb_type_head (type, oa->lsdb); lsa;
760 lsa = ospf6_lsdb_type_next (type, lsa))
761 ospf6_abr_examin_summary (lsa, oa);
762}
763
764
hasso049207c2004-08-04 20:02:13 +0000765
766/* Display functions */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100767static int
hasso049207c2004-08-04 20:02:13 +0000768ospf6_inter_area_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
769{
770 struct ospf6_inter_prefix_lsa *prefix_lsa;
771 struct in6_addr in6;
772 char buf[64];
773
774 prefix_lsa = (struct ospf6_inter_prefix_lsa *)
775 OSPF6_LSA_HEADER_END (lsa->header);
776
777 vty_out (vty, " Metric: %lu%s",
778 (u_long) OSPF6_ABR_SUMMARY_METRIC (prefix_lsa), VNL);
779
780 ospf6_prefix_options_printbuf (prefix_lsa->prefix.prefix_options,
781 buf, sizeof (buf));
782 vty_out (vty, " Prefix Options: %s%s", buf, VNL);
783
784 ospf6_prefix_in6_addr (&in6, &prefix_lsa->prefix);
785 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
786 vty_out (vty, " Prefix: %s/%d%s", buf,
787 prefix_lsa->prefix.prefix_length, VNL);
788
789 return 0;
790}
791
Paul Jakma6ac29a52008-08-15 13:45:30 +0100792static int
hasso049207c2004-08-04 20:02:13 +0000793ospf6_inter_area_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
794{
795 struct ospf6_inter_router_lsa *router_lsa;
796 char buf[64];
797
798 router_lsa = (struct ospf6_inter_router_lsa *)
799 OSPF6_LSA_HEADER_END (lsa->header);
800
801 ospf6_options_printbuf (router_lsa->options, buf, sizeof (buf));
802 vty_out (vty, " Options: %s%s", buf, VNL);
803 vty_out (vty, " Metric: %lu%s",
804 (u_long) OSPF6_ABR_SUMMARY_METRIC (router_lsa), VNL);
805 inet_ntop (AF_INET, &router_lsa->router_id, buf, sizeof (buf));
806 vty_out (vty, " Destination Router ID: %s%s", buf, VNL);
807
808 return 0;
809}
810
811/* Debug commands */
812DEFUN (debug_ospf6_abr,
813 debug_ospf6_abr_cmd,
814 "debug ospf6 abr",
815 DEBUG_STR
816 OSPF6_STR
817 "Debug OSPFv3 ABR function\n"
818 )
819{
820 OSPF6_DEBUG_ABR_ON ();
821 return CMD_SUCCESS;
822}
823
824DEFUN (no_debug_ospf6_abr,
825 no_debug_ospf6_abr_cmd,
826 "no debug ospf6 abr",
827 NO_STR
828 DEBUG_STR
829 OSPF6_STR
830 "Debug OSPFv3 ABR function\n"
831 )
832{
833 OSPF6_DEBUG_ABR_OFF ();
834 return CMD_SUCCESS;
835}
836
837int
838config_write_ospf6_debug_abr (struct vty *vty)
839{
840 if (IS_OSPF6_DEBUG_ABR)
841 vty_out (vty, "debug ospf6 abr%s", VNL);
842 return 0;
843}
844
845void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100846install_element_ospf6_debug_abr (void)
hasso049207c2004-08-04 20:02:13 +0000847{
848 install_element (ENABLE_NODE, &debug_ospf6_abr_cmd);
849 install_element (ENABLE_NODE, &no_debug_ospf6_abr_cmd);
850 install_element (CONFIG_NODE, &debug_ospf6_abr_cmd);
851 install_element (CONFIG_NODE, &no_debug_ospf6_abr_cmd);
852}
853
hasso6452df02004-08-15 05:52:07 +0000854struct ospf6_lsa_handler inter_prefix_handler =
855{
856 OSPF6_LSTYPE_INTER_PREFIX,
857 "Inter-Prefix",
858 ospf6_inter_area_prefix_lsa_show
859};
860
861struct ospf6_lsa_handler inter_router_handler =
862{
863 OSPF6_LSTYPE_INTER_ROUTER,
864 "Inter-Router",
865 ospf6_inter_area_router_lsa_show
866};
867
hasso049207c2004-08-04 20:02:13 +0000868void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100869ospf6_abr_init (void)
hasso049207c2004-08-04 20:02:13 +0000870{
hasso6452df02004-08-15 05:52:07 +0000871 ospf6_install_lsa_handler (&inter_prefix_handler);
872 ospf6_install_lsa_handler (&inter_router_handler);
hasso049207c2004-08-04 20:02:13 +0000873}
874
875