blob: 21693dbceae17dec40ca1b82172dc30e10e30e7c [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
hasso508e53e2004-05-18 18:57:06 +000022#include <zebra.h>
23
24#include "log.h"
25#include "linklist.h"
26#include "thread.h"
27#include "memory.h"
28#include "if.h"
29#include "prefix.h"
30#include "table.h"
31#include "vty.h"
32#include "command.h"
33
hasso508e53e2004-05-18 18:57:06 +000034#include "ospf6_proto.h"
35#include "ospf6_message.h"
36#include "ospf6_route.h"
37#include "ospf6_lsa.h"
38#include "ospf6_lsdb.h"
paul718e3742002-12-13 20:15:29 +000039
hasso508e53e2004-05-18 18:57:06 +000040#include "ospf6_top.h"
41#include "ospf6_area.h"
42#include "ospf6_interface.h"
43#include "ospf6_neighbor.h"
44#include "ospf6_intra.h"
45#include "ospf6_asbr.h"
hasso6452df02004-08-15 05:52:07 +000046#include "ospf6_abr.h"
47#include "ospf6_flood.h"
hasso049207c2004-08-04 20:02:13 +000048#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000049
hasso508e53e2004-05-18 18:57:06 +000050/******************************/
51/* RFC2740 3.4.3.1 Router-LSA */
52/******************************/
paul718e3742002-12-13 20:15:29 +000053
hasso508e53e2004-05-18 18:57:06 +000054int
55ospf6_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +000056{
hasso508e53e2004-05-18 18:57:06 +000057 char *start, *end, *current;
58 char buf[32], name[32], bits[16], options[32];
59 struct ospf6_router_lsa *router_lsa;
60 struct ospf6_router_lsdesc *lsdesc;
paul718e3742002-12-13 20:15:29 +000061
hasso508e53e2004-05-18 18:57:06 +000062 router_lsa = (struct ospf6_router_lsa *)
63 ((char *) lsa->header + sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +000064
hasso508e53e2004-05-18 18:57:06 +000065 ospf6_capability_printbuf (router_lsa->bits, bits, sizeof (bits));
66 ospf6_options_printbuf (router_lsa->options, options, sizeof (options));
hasso049207c2004-08-04 20:02:13 +000067 vty_out (vty, " Bits: %s Options: %s%s", bits, options, VNL);
paul718e3742002-12-13 20:15:29 +000068
hasso508e53e2004-05-18 18:57:06 +000069 start = (char *) router_lsa + sizeof (struct ospf6_router_lsa);
paul718e3742002-12-13 20:15:29 +000070 end = (char *) lsa->header + ntohs (lsa->header->length);
hasso508e53e2004-05-18 18:57:06 +000071 for (current = start; current + sizeof (struct ospf6_router_lsdesc) <= end;
72 current += sizeof (struct ospf6_router_lsdesc))
paul718e3742002-12-13 20:15:29 +000073 {
hasso508e53e2004-05-18 18:57:06 +000074 lsdesc = (struct ospf6_router_lsdesc *) current;
paul718e3742002-12-13 20:15:29 +000075
hasso508e53e2004-05-18 18:57:06 +000076 if (lsdesc->type == OSPF6_ROUTER_LSDESC_POINTTOPOINT)
77 snprintf (name, sizeof (name), "Point-To-Point");
78 else if (lsdesc->type == OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK)
79 snprintf (name, sizeof (name), "Transit-Network");
80 else if (lsdesc->type == OSPF6_ROUTER_LSDESC_STUB_NETWORK)
81 snprintf (name, sizeof (name), "Stub-Network");
82 else if (lsdesc->type == OSPF6_ROUTER_LSDESC_VIRTUAL_LINK)
83 snprintf (name, sizeof (name), "Virtual-Link");
paul718e3742002-12-13 20:15:29 +000084 else
hasso508e53e2004-05-18 18:57:06 +000085 snprintf (name, sizeof (name), "Unknown (%#x)", lsdesc->type);
paul718e3742002-12-13 20:15:29 +000086
hasso508e53e2004-05-18 18:57:06 +000087 vty_out (vty, " Type: %s Metric: %d%s",
hasso049207c2004-08-04 20:02:13 +000088 name, ntohs (lsdesc->metric), VNL);
hasso508e53e2004-05-18 18:57:06 +000089 vty_out (vty, " Interface ID: %s%s",
90 inet_ntop (AF_INET, &lsdesc->interface_id,
hasso049207c2004-08-04 20:02:13 +000091 buf, sizeof (buf)), VNL);
hasso508e53e2004-05-18 18:57:06 +000092 vty_out (vty, " Neighbor Interface ID: %s%s",
93 inet_ntop (AF_INET, &lsdesc->neighbor_interface_id,
hasso049207c2004-08-04 20:02:13 +000094 buf, sizeof (buf)), VNL);
hasso508e53e2004-05-18 18:57:06 +000095 vty_out (vty, " Neighbor Router ID: %s%s",
96 inet_ntop (AF_INET, &lsdesc->neighbor_router_id,
hasso049207c2004-08-04 20:02:13 +000097 buf, sizeof (buf)), VNL);
paul718e3742002-12-13 20:15:29 +000098 }
99 return 0;
100}
101
hasso6452df02004-08-15 05:52:07 +0000102int
103ospf6_router_lsa_originate (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000104{
hasso6452df02004-08-15 05:52:07 +0000105 struct ospf6_area *oa;
106
hasso508e53e2004-05-18 18:57:06 +0000107 char buffer [OSPF6_MAX_LSASIZE];
108 struct ospf6_lsa_header *lsa_header;
109 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000110
hasso508e53e2004-05-18 18:57:06 +0000111 u_int32_t link_state_id = 0;
paul1eb8ef22005-04-07 07:30:20 +0000112 struct listnode *node, *nnode;
113 struct listnode *j;
hasso508e53e2004-05-18 18:57:06 +0000114 struct ospf6_interface *oi;
115 struct ospf6_neighbor *on, *drouter = NULL;
116 struct ospf6_router_lsa *router_lsa;
117 struct ospf6_router_lsdesc *lsdesc;
118 u_int16_t type;
119 u_int32_t router;
120 int count;
paul718e3742002-12-13 20:15:29 +0000121
hasso6452df02004-08-15 05:52:07 +0000122 oa = (struct ospf6_area *) THREAD_ARG (thread);
123 oa->thread_router_lsa = NULL;
124
hasso1e058382004-09-01 21:36:14 +0000125 if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER))
hassoc6487d62004-12-24 06:00:11 +0000126 zlog_debug ("Originate Router-LSA for Area %s", oa->name);
paul718e3742002-12-13 20:15:29 +0000127
hasso508e53e2004-05-18 18:57:06 +0000128 memset (buffer, 0, sizeof (buffer));
129 lsa_header = (struct ospf6_lsa_header *) buffer;
130 router_lsa = (struct ospf6_router_lsa *)
131 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
132
133 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_V6);
134 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_E);
135 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_MC);
136 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_N);
137 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_R);
138 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_DC);
139
hasso6452df02004-08-15 05:52:07 +0000140 if (ospf6_is_router_abr (ospf6))
141 SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B);
142 else
143 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B);
hasso508e53e2004-05-18 18:57:06 +0000144 if (ospf6_asbr_is_asbr (ospf6))
145 SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E);
146 else
147 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E);
148 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_V);
149 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_W);
150
151 /* describe links for each interfaces */
152 lsdesc = (struct ospf6_router_lsdesc *)
153 ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa));
154
paul1eb8ef22005-04-07 07:30:20 +0000155 for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
paul718e3742002-12-13 20:15:29 +0000156 {
hasso508e53e2004-05-18 18:57:06 +0000157 /* Interfaces in state Down or Loopback are not described */
158 if (oi->state == OSPF6_INTERFACE_DOWN ||
159 oi->state == OSPF6_INTERFACE_LOOPBACK)
paul718e3742002-12-13 20:15:29 +0000160 continue;
161
hasso508e53e2004-05-18 18:57:06 +0000162 /* Nor are interfaces without any full adjacencies described */
163 count = 0;
paul1eb8ef22005-04-07 07:30:20 +0000164 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
165 if (on->state == OSPF6_NEIGHBOR_FULL)
166 count++;
167
hasso508e53e2004-05-18 18:57:06 +0000168 if (count == 0)
169 continue;
170
171 /* Multiple Router-LSA instance according to size limit setting */
paul0c083ee2004-10-10 12:54:58 +0000172 if ( (oa->router_lsa_size_limit != 0)
173 && ((caddr_t) lsdesc + sizeof (struct ospf6_router_lsdesc) -
gdt1686f932004-12-09 14:47:09 +0000174 /* XXX warning: comparison between signed and unsigned */
paul0c083ee2004-10-10 12:54:58 +0000175 (caddr_t) buffer > oa->router_lsa_size_limit))
hasso508e53e2004-05-18 18:57:06 +0000176 {
177 if ((caddr_t) lsdesc == (caddr_t) router_lsa +
178 sizeof (struct ospf6_router_lsa))
179 {
hasso1e058382004-09-01 21:36:14 +0000180 if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER))
hassoc6487d62004-12-24 06:00:11 +0000181 zlog_debug ("Size limit setting for Router-LSA too short");
hasso6452df02004-08-15 05:52:07 +0000182 return 0;
hasso508e53e2004-05-18 18:57:06 +0000183 }
184
185 /* Fill LSA Header */
186 lsa_header->age = 0;
187 lsa_header->type = htons (OSPF6_LSTYPE_ROUTER);
188 lsa_header->id = htonl (link_state_id);
189 lsa_header->adv_router = oa->ospf6->router_id;
190 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000191 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
192 lsa_header->adv_router, oa->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000193 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
194
195 /* LSA checksum */
196 ospf6_lsa_checksum (lsa_header);
197
198 /* create LSA */
199 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000200
201 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000202 ospf6_lsa_originate_area (lsa, oa);
hasso508e53e2004-05-18 18:57:06 +0000203
204 /* Reset setting for consecutive origination */
205 memset ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa),
206 0, (caddr_t) lsdesc - (caddr_t) router_lsa);
207 lsdesc = (struct ospf6_router_lsdesc *)
208 ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa));
209 link_state_id ++;
paul718e3742002-12-13 20:15:29 +0000210 }
211
hasso508e53e2004-05-18 18:57:06 +0000212 /* Point-to-Point interfaces */
213 if (if_is_pointopoint (oi->interface))
214 {
paul1eb8ef22005-04-07 07:30:20 +0000215 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
hasso508e53e2004-05-18 18:57:06 +0000216 {
hasso508e53e2004-05-18 18:57:06 +0000217 if (on->state != OSPF6_NEIGHBOR_FULL)
218 continue;
paul718e3742002-12-13 20:15:29 +0000219
hasso508e53e2004-05-18 18:57:06 +0000220 lsdesc->type = OSPF6_ROUTER_LSDESC_POINTTOPOINT;
221 lsdesc->metric = htons (oi->cost);
222 lsdesc->interface_id = htonl (oi->interface->ifindex);
223 lsdesc->neighbor_interface_id = htonl (on->ifindex);
224 lsdesc->neighbor_router_id = on->router_id;
225
226 lsdesc++;
227 }
228 }
229
230 /* Broadcast and NBMA interfaces */
231 if (if_is_broadcast (oi->interface))
232 {
233 /* If this router is not DR,
234 and If this router not fully adjacent with DR,
235 this interface is not transit yet: ignore. */
236 if (oi->state != OSPF6_INTERFACE_DR)
237 {
238 drouter = ospf6_neighbor_lookup (oi->drouter, oi);
239 if (drouter == NULL || drouter->state != OSPF6_NEIGHBOR_FULL)
240 continue;
241 }
242
243 lsdesc->type = OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK;
244 lsdesc->metric = htons (oi->cost);
245 lsdesc->interface_id = htonl (oi->interface->ifindex);
246 if (oi->state != OSPF6_INTERFACE_DR)
247 {
248 lsdesc->neighbor_interface_id = htonl (drouter->ifindex);
249 lsdesc->neighbor_router_id = drouter->router_id;
250 }
251 else
252 {
253 lsdesc->neighbor_interface_id = htonl (oi->interface->ifindex);
254 lsdesc->neighbor_router_id = oi->area->ospf6->router_id;
255 }
256
257 lsdesc++;
258 }
259
260 /* Virtual links */
261 /* xxx */
262 /* Point-to-Multipoint interfaces */
263 /* xxx */
paul718e3742002-12-13 20:15:29 +0000264 }
hasso508e53e2004-05-18 18:57:06 +0000265
266 if ((caddr_t) lsdesc != (caddr_t) router_lsa +
267 sizeof (struct ospf6_router_lsa))
268 {
269 /* Fill LSA Header */
270 lsa_header->age = 0;
271 lsa_header->type = htons (OSPF6_LSTYPE_ROUTER);
272 lsa_header->id = htonl (link_state_id);
273 lsa_header->adv_router = oa->ospf6->router_id;
274 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000275 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
276 lsa_header->adv_router, oa->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000277 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
278
279 /* LSA checksum */
280 ospf6_lsa_checksum (lsa_header);
281
282 /* create LSA */
283 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000284
285 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000286 ospf6_lsa_originate_area (lsa, oa);
hasso508e53e2004-05-18 18:57:06 +0000287
288 link_state_id ++;
289 }
hasso6452df02004-08-15 05:52:07 +0000290 else
291 {
hasso1e058382004-09-01 21:36:14 +0000292 if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER))
hassoc6487d62004-12-24 06:00:11 +0000293 zlog_debug ("Nothing to describe in Router-LSA, suppress");
hasso6452df02004-08-15 05:52:07 +0000294 }
hasso508e53e2004-05-18 18:57:06 +0000295
296 /* Do premature-aging of rest, undesired Router-LSAs */
297 type = ntohs (OSPF6_LSTYPE_ROUTER);
298 router = oa->ospf6->router_id;
299 for (lsa = ospf6_lsdb_type_router_head (type, router, oa->lsdb); lsa;
300 lsa = ospf6_lsdb_type_router_next (type, router, lsa))
301 {
302 if (ntohl (lsa->header->id) < link_state_id)
303 continue;
hasso6452df02004-08-15 05:52:07 +0000304 ospf6_lsa_purge (lsa);
hasso508e53e2004-05-18 18:57:06 +0000305 }
hasso508e53e2004-05-18 18:57:06 +0000306
307 return 0;
308}
309
hasso508e53e2004-05-18 18:57:06 +0000310/*******************************/
311/* RFC2740 3.4.3.2 Network-LSA */
312/*******************************/
313
314int
315ospf6_network_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
316{
317 char *start, *end, *current;
318 struct ospf6_network_lsa *network_lsa;
319 struct ospf6_network_lsdesc *lsdesc;
320 char buf[128], options[32];
321
322 network_lsa = (struct ospf6_network_lsa *)
323 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
324
325 ospf6_options_printbuf (network_lsa->options, options, sizeof (options));
hasso049207c2004-08-04 20:02:13 +0000326 vty_out (vty, " Options: %s%s", options, VNL);
hasso508e53e2004-05-18 18:57:06 +0000327
328 start = (char *) network_lsa + sizeof (struct ospf6_network_lsa);
329 end = (char *) lsa->header + ntohs (lsa->header->length);
330 for (current = start; current + sizeof (struct ospf6_network_lsdesc) <= end;
331 current += sizeof (struct ospf6_network_lsdesc))
332 {
333 lsdesc = (struct ospf6_network_lsdesc *) current;
334 inet_ntop (AF_INET, &lsdesc->router_id, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000335 vty_out (vty, " Attached Router: %s%s", buf, VNL);
hasso508e53e2004-05-18 18:57:06 +0000336 }
337 return 0;
paul718e3742002-12-13 20:15:29 +0000338}
339
hasso6452df02004-08-15 05:52:07 +0000340int
341ospf6_network_lsa_originate (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000342{
hasso6452df02004-08-15 05:52:07 +0000343 struct ospf6_interface *oi;
344
hasso508e53e2004-05-18 18:57:06 +0000345 char buffer [OSPF6_MAX_LSASIZE];
346 struct ospf6_lsa_header *lsa_header;
paul718e3742002-12-13 20:15:29 +0000347
hasso508e53e2004-05-18 18:57:06 +0000348 int count;
349 struct ospf6_lsa *old, *lsa;
350 struct ospf6_network_lsa *network_lsa;
351 struct ospf6_network_lsdesc *lsdesc;
352 struct ospf6_neighbor *on;
353 struct ospf6_link_lsa *link_lsa;
hasso52dc7ee2004-09-23 19:18:23 +0000354 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +0000355 u_int16_t type;
356
hasso6452df02004-08-15 05:52:07 +0000357 oi = (struct ospf6_interface *) THREAD_ARG (thread);
358 oi->thread_network_lsa = NULL;
359
360 /* The interface must be enabled until here. A Network-LSA of a
361 disabled interface (but was once enabled) should be flushed
362 by ospf6_lsa_refresh (), and does not come here. */
363 assert (oi->area);
paul718e3742002-12-13 20:15:29 +0000364
hasso508e53e2004-05-18 18:57:06 +0000365 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_NETWORK),
366 htonl (oi->interface->ifindex),
367 oi->area->ospf6->router_id, oi->area->lsdb);
paul718e3742002-12-13 20:15:29 +0000368
hasso508e53e2004-05-18 18:57:06 +0000369 /* Do not originate Network-LSA if not DR */
370 if (oi->state != OSPF6_INTERFACE_DR)
paul718e3742002-12-13 20:15:29 +0000371 {
hasso508e53e2004-05-18 18:57:06 +0000372 if (old)
hasso6452df02004-08-15 05:52:07 +0000373 ospf6_lsa_purge (old);
374 return 0;
paul718e3742002-12-13 20:15:29 +0000375 }
hasso508e53e2004-05-18 18:57:06 +0000376
hasso1e058382004-09-01 21:36:14 +0000377 if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK))
hassoc6487d62004-12-24 06:00:11 +0000378 zlog_debug ("Originate Network-LSA for Interface %s", oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000379
380 /* If none of neighbor is adjacent to us */
381 count = 0;
paul1eb8ef22005-04-07 07:30:20 +0000382
383 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
384 if (on->state == OSPF6_NEIGHBOR_FULL)
385 count++;
386
hasso508e53e2004-05-18 18:57:06 +0000387 if (count == 0)
388 {
hasso1e058382004-09-01 21:36:14 +0000389 if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK))
hassoc6487d62004-12-24 06:00:11 +0000390 zlog_debug ("Interface stub, ignore");
hasso508e53e2004-05-18 18:57:06 +0000391 if (old)
hasso6452df02004-08-15 05:52:07 +0000392 ospf6_lsa_purge (old);
393 return 0;
hasso508e53e2004-05-18 18:57:06 +0000394 }
395
396 /* prepare buffer */
397 memset (buffer, 0, sizeof (buffer));
398 lsa_header = (struct ospf6_lsa_header *) buffer;
399 network_lsa = (struct ospf6_network_lsa *)
400 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
401
402 /* Collect the interface's Link-LSAs to describe
403 network's optional capabilities */
404 type = htons (OSPF6_LSTYPE_LINK);
405 for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa;
406 lsa = ospf6_lsdb_type_next (type, lsa))
407 {
408 link_lsa = (struct ospf6_link_lsa *)
409 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
410 network_lsa->options[0] |= link_lsa->options[0];
411 network_lsa->options[1] |= link_lsa->options[1];
412 network_lsa->options[2] |= link_lsa->options[2];
413 }
414
415 lsdesc = (struct ospf6_network_lsdesc *)
416 ((caddr_t) network_lsa + sizeof (struct ospf6_network_lsa));
417
418 /* set Link Description to the router itself */
419 lsdesc->router_id = oi->area->ospf6->router_id;
420 lsdesc++;
421
422 /* Walk through the neighbors */
paul1eb8ef22005-04-07 07:30:20 +0000423 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
hasso508e53e2004-05-18 18:57:06 +0000424 {
hasso508e53e2004-05-18 18:57:06 +0000425 if (on->state != OSPF6_NEIGHBOR_FULL)
426 continue;
427
428 /* set this neighbor's Router-ID to LSA */
429 lsdesc->router_id = on->router_id;
430 lsdesc++;
431 }
432
433 /* Fill LSA Header */
434 lsa_header->age = 0;
435 lsa_header->type = htons (OSPF6_LSTYPE_NETWORK);
436 lsa_header->id = htonl (oi->interface->ifindex);
437 lsa_header->adv_router = oi->area->ospf6->router_id;
438 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000439 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
440 lsa_header->adv_router, oi->area->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000441 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
442
443 /* LSA checksum */
444 ospf6_lsa_checksum (lsa_header);
445
446 /* create LSA */
447 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000448
449 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000450 ospf6_lsa_originate_area (lsa, oi->area);
hasso508e53e2004-05-18 18:57:06 +0000451
452 return 0;
453}
454
455
456/****************************/
457/* RFC2740 3.4.3.6 Link-LSA */
458/****************************/
459
460int
461ospf6_link_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
462{
paul718e3742002-12-13 20:15:29 +0000463 char *start, *end, *current;
hasso508e53e2004-05-18 18:57:06 +0000464 struct ospf6_link_lsa *link_lsa;
465 int prefixnum;
466 char buf[128], options[32];
467 struct ospf6_prefix *prefix;
paul0c083ee2004-10-10 12:54:58 +0000468 const char *p, *mc, *la, *nu;
hasso508e53e2004-05-18 18:57:06 +0000469 struct in6_addr in6;
paul718e3742002-12-13 20:15:29 +0000470
hasso508e53e2004-05-18 18:57:06 +0000471 link_lsa = (struct ospf6_link_lsa *)
472 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000473
hasso508e53e2004-05-18 18:57:06 +0000474 ospf6_options_printbuf (link_lsa->options, options, sizeof (options));
475 inet_ntop (AF_INET6, &link_lsa->linklocal_addr, buf, sizeof (buf));
476 prefixnum = ntohl (link_lsa->prefix_num);
paul718e3742002-12-13 20:15:29 +0000477
hasso508e53e2004-05-18 18:57:06 +0000478 vty_out (vty, " Priority: %d Options: %s%s",
hasso049207c2004-08-04 20:02:13 +0000479 link_lsa->priority, options, VNL);
480 vty_out (vty, " LinkLocal Address: %s%s", buf, VNL);
481 vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL);
paul718e3742002-12-13 20:15:29 +0000482
hasso508e53e2004-05-18 18:57:06 +0000483 start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
484 end = (char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000485 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix))
486 {
487 prefix = (struct ospf6_prefix *) current;
hasso508e53e2004-05-18 18:57:06 +0000488 if (prefix->prefix_length == 0 ||
489 current + OSPF6_PREFIX_SIZE (prefix) > end)
490 break;
paul718e3742002-12-13 20:15:29 +0000491
hasso508e53e2004-05-18 18:57:06 +0000492 p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ?
493 "P" : "--");
494 mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ?
495 "MC" : "--");
496 la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ?
497 "LA" : "--");
498 nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ?
499 "NU" : "--");
500 vty_out (vty, " Prefix Options: %s|%s|%s|%s%s",
hasso049207c2004-08-04 20:02:13 +0000501 p, mc, la, nu, VNL);
paul718e3742002-12-13 20:15:29 +0000502
hasso508e53e2004-05-18 18:57:06 +0000503 memset (&in6, 0, sizeof (in6));
504 memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
505 OSPF6_PREFIX_SPACE (prefix->prefix_length));
paul718e3742002-12-13 20:15:29 +0000506 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
507 vty_out (vty, " Prefix: %s/%d%s",
hasso049207c2004-08-04 20:02:13 +0000508 buf, prefix->prefix_length, VNL);
paul718e3742002-12-13 20:15:29 +0000509 }
510
511 return 0;
512}
513
hasso6452df02004-08-15 05:52:07 +0000514int
515ospf6_link_lsa_originate (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000516{
hasso6452df02004-08-15 05:52:07 +0000517 struct ospf6_interface *oi;
518
hasso508e53e2004-05-18 18:57:06 +0000519 char buffer[OSPF6_MAX_LSASIZE];
520 struct ospf6_lsa_header *lsa_header;
521 struct ospf6_lsa *old, *lsa;
paul718e3742002-12-13 20:15:29 +0000522
hasso508e53e2004-05-18 18:57:06 +0000523 struct ospf6_link_lsa *link_lsa;
524 struct ospf6_route *route;
525 struct ospf6_prefix *op;
paul718e3742002-12-13 20:15:29 +0000526
hasso6452df02004-08-15 05:52:07 +0000527 oi = (struct ospf6_interface *) THREAD_ARG (thread);
528 oi->thread_link_lsa = NULL;
529
530 assert (oi->area);
paul718e3742002-12-13 20:15:29 +0000531
532 /* find previous LSA */
hasso508e53e2004-05-18 18:57:06 +0000533 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_LINK),
534 htonl (oi->interface->ifindex),
535 oi->area->ospf6->router_id, oi->lsdb);
paul718e3742002-12-13 20:15:29 +0000536
hasso508e53e2004-05-18 18:57:06 +0000537 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
paul718e3742002-12-13 20:15:29 +0000538 {
539 if (old)
hasso6452df02004-08-15 05:52:07 +0000540 ospf6_lsa_purge (old);
541 return 0;
paul718e3742002-12-13 20:15:29 +0000542 }
543
hasso1e058382004-09-01 21:36:14 +0000544 if (IS_OSPF6_DEBUG_ORIGINATE (LINK))
hassoc6487d62004-12-24 06:00:11 +0000545 zlog_debug ("Originate Link-LSA for Interface %s", oi->interface->name);
paul718e3742002-12-13 20:15:29 +0000546
hasso508e53e2004-05-18 18:57:06 +0000547 /* can't make Link-LSA if linklocal address not set */
548 if (oi->linklocal_addr == NULL)
paul718e3742002-12-13 20:15:29 +0000549 {
hasso1e058382004-09-01 21:36:14 +0000550 if (IS_OSPF6_DEBUG_ORIGINATE (LINK))
hassoc6487d62004-12-24 06:00:11 +0000551 zlog_debug ("No Linklocal address on %s, defer originating",
hasso508e53e2004-05-18 18:57:06 +0000552 oi->interface->name);
553 if (old)
hasso6452df02004-08-15 05:52:07 +0000554 ospf6_lsa_purge (old);
555 return 0;
hasso508e53e2004-05-18 18:57:06 +0000556 }
557
558 /* prepare buffer */
559 memset (buffer, 0, sizeof (buffer));
560 lsa_header = (struct ospf6_lsa_header *) buffer;
561 link_lsa = (struct ospf6_link_lsa *)
562 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
563
564 /* Fill Link-LSA */
565 link_lsa->priority = oi->priority;
566 memcpy (link_lsa->options, oi->area->options, 3);
567 memcpy (&link_lsa->linklocal_addr, oi->linklocal_addr,
568 sizeof (struct in6_addr));
569 link_lsa->prefix_num = htonl (oi->route_connected->count);
570
571 op = (struct ospf6_prefix *)
572 ((caddr_t) link_lsa + sizeof (struct ospf6_link_lsa));
573
574 /* connected prefix to advertise */
575 for (route = ospf6_route_head (oi->route_connected); route;
576 route = ospf6_route_next (route))
577 {
578 op->prefix_length = route->prefix.prefixlen;
579 op->prefix_options = route->path.prefix_options;
580 op->prefix_metric = htons (0);
581 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
582 OSPF6_PREFIX_SPACE (op->prefix_length));
583 op = OSPF6_PREFIX_NEXT (op);
584 }
585
586 /* Fill LSA Header */
587 lsa_header->age = 0;
588 lsa_header->type = htons (OSPF6_LSTYPE_LINK);
589 lsa_header->id = htonl (oi->interface->ifindex);
590 lsa_header->adv_router = oi->area->ospf6->router_id;
591 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000592 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
593 lsa_header->adv_router, oi->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000594 lsa_header->length = htons ((caddr_t) op - (caddr_t) buffer);
595
596 /* LSA checksum */
597 ospf6_lsa_checksum (lsa_header);
598
599 /* create LSA */
600 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000601
602 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000603 ospf6_lsa_originate_interface (lsa, oi);
hasso508e53e2004-05-18 18:57:06 +0000604
605 return 0;
606}
607
608
609/*****************************************/
610/* RFC2740 3.4.3.7 Intra-Area-Prefix-LSA */
611/*****************************************/
612
613int
614ospf6_intra_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
615{
616 char *start, *end, *current;
617 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
618 int prefixnum;
619 char buf[128];
620 struct ospf6_prefix *prefix;
621 char id[16], adv_router[16];
paul0c083ee2004-10-10 12:54:58 +0000622 const char *p, *mc, *la, *nu;
hasso508e53e2004-05-18 18:57:06 +0000623 struct in6_addr in6;
624
625 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
626 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
627
628 prefixnum = ntohs (intra_prefix_lsa->prefix_num);
629
hasso049207c2004-08-04 20:02:13 +0000630 vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL);
hasso508e53e2004-05-18 18:57:06 +0000631
632 inet_ntop (AF_INET, &intra_prefix_lsa->ref_id, id, sizeof (id));
633 inet_ntop (AF_INET, &intra_prefix_lsa->ref_adv_router,
634 adv_router, sizeof (adv_router));
635 vty_out (vty, " Reference: %s Id: %s Adv: %s%s",
hasso1e058382004-09-01 21:36:14 +0000636 ospf6_lstype_name (intra_prefix_lsa->ref_type), id, adv_router,
hasso049207c2004-08-04 20:02:13 +0000637 VNL);
hasso508e53e2004-05-18 18:57:06 +0000638
639 start = (char *) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa);
640 end = (char *) lsa->header + ntohs (lsa->header->length);
641 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix))
642 {
643 prefix = (struct ospf6_prefix *) current;
644 if (prefix->prefix_length == 0 ||
645 current + OSPF6_PREFIX_SIZE (prefix) > end)
646 break;
647
648 p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ?
649 "P" : "--");
650 mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ?
651 "MC" : "--");
652 la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ?
653 "LA" : "--");
654 nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ?
655 "NU" : "--");
656 vty_out (vty, " Prefix Options: %s|%s|%s|%s%s",
hasso049207c2004-08-04 20:02:13 +0000657 p, mc, la, nu, VNL);
hasso508e53e2004-05-18 18:57:06 +0000658
659 memset (&in6, 0, sizeof (in6));
660 memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
661 OSPF6_PREFIX_SPACE (prefix->prefix_length));
662 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
663 vty_out (vty, " Prefix: %s/%d%s",
hasso049207c2004-08-04 20:02:13 +0000664 buf, prefix->prefix_length, VNL);
hasso508e53e2004-05-18 18:57:06 +0000665 }
666
667 return 0;
668}
669
hasso6452df02004-08-15 05:52:07 +0000670int
671ospf6_intra_prefix_lsa_originate_stub (struct thread *thread)
hasso508e53e2004-05-18 18:57:06 +0000672{
hasso6452df02004-08-15 05:52:07 +0000673 struct ospf6_area *oa;
674
hasso508e53e2004-05-18 18:57:06 +0000675 char buffer[OSPF6_MAX_LSASIZE];
676 struct ospf6_lsa_header *lsa_header;
677 struct ospf6_lsa *old, *lsa;
678
679 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
680 struct ospf6_interface *oi;
681 struct ospf6_neighbor *on;
682 struct ospf6_route *route;
683 struct ospf6_prefix *op;
hasso52dc7ee2004-09-23 19:18:23 +0000684 struct listnode *i, *j;
hasso508e53e2004-05-18 18:57:06 +0000685 int full_count = 0;
686 unsigned short prefix_num = 0;
687 char buf[BUFSIZ];
688 struct ospf6_route_table *route_advertise;
689
hasso6452df02004-08-15 05:52:07 +0000690 oa = (struct ospf6_area *) THREAD_ARG (thread);
691 oa->thread_intra_prefix_lsa = NULL;
692
hasso508e53e2004-05-18 18:57:06 +0000693 /* find previous LSA */
694 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX),
695 htonl (0), oa->ospf6->router_id, oa->lsdb);
696
hasso6452df02004-08-15 05:52:07 +0000697 if (! IS_AREA_ENABLED (oa))
hasso508e53e2004-05-18 18:57:06 +0000698 {
699 if (old)
hasso6452df02004-08-15 05:52:07 +0000700 ospf6_lsa_purge (old);
701 return 0;
hasso508e53e2004-05-18 18:57:06 +0000702 }
703
hasso1e058382004-09-01 21:36:14 +0000704 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000705 zlog_debug ("Originate Intra-Area-Prefix-LSA for area %s's stub prefix",
hasso508e53e2004-05-18 18:57:06 +0000706 oa->name);
707
708 /* prepare buffer */
709 memset (buffer, 0, sizeof (buffer));
710 lsa_header = (struct ospf6_lsa_header *) buffer;
711 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
712 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
713
714 /* Fill Intra-Area-Prefix-LSA */
715 intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_ROUTER);
716 intra_prefix_lsa->ref_id = htonl (0);
717 intra_prefix_lsa->ref_adv_router = oa->ospf6->router_id;
718
719 route_advertise = ospf6_route_table_create ();
720
paul1eb8ef22005-04-07 07:30:20 +0000721 for (ALL_LIST_ELEMENTS_RO (oa->if_list, i, oi))
hasso508e53e2004-05-18 18:57:06 +0000722 {
hasso508e53e2004-05-18 18:57:06 +0000723 if (oi->state == OSPF6_INTERFACE_DOWN)
724 {
hasso1e058382004-09-01 21:36:14 +0000725 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000726 zlog_debug (" Interface %s is down, ignore", oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000727 continue;
728 }
729
730 full_count = 0;
paul1eb8ef22005-04-07 07:30:20 +0000731
732 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
733 if (on->state == OSPF6_NEIGHBOR_FULL)
734 full_count++;
735
hasso508e53e2004-05-18 18:57:06 +0000736 if (oi->state != OSPF6_INTERFACE_LOOPBACK &&
737 oi->state != OSPF6_INTERFACE_POINTTOPOINT &&
738 full_count != 0)
739 {
hasso1e058382004-09-01 21:36:14 +0000740 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000741 zlog_debug (" Interface %s is not stub, ignore",
hasso508e53e2004-05-18 18:57:06 +0000742 oi->interface->name);
743 continue;
744 }
745
hasso1e058382004-09-01 21:36:14 +0000746 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000747 zlog_debug (" Interface %s:", oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000748
749 /* connected prefix to advertise */
750 for (route = ospf6_route_head (oi->route_connected); route;
751 route = ospf6_route_best_next (route))
752 {
hasso1e058382004-09-01 21:36:14 +0000753 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hasso508e53e2004-05-18 18:57:06 +0000754 {
755 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000756 zlog_debug (" include %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000757 }
758 ospf6_route_add (ospf6_route_copy (route), route_advertise);
759 }
760 }
761
762 if (route_advertise->count == 0)
763 {
764 if (old)
hasso6452df02004-08-15 05:52:07 +0000765 ospf6_lsa_purge (old);
hasso508e53e2004-05-18 18:57:06 +0000766 ospf6_route_table_delete (route_advertise);
hasso6452df02004-08-15 05:52:07 +0000767 return 0;
hasso508e53e2004-05-18 18:57:06 +0000768 }
769
770 /* put prefixes to advertise */
771 prefix_num = 0;
772 op = (struct ospf6_prefix *)
773 ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa));
774 for (route = ospf6_route_head (route_advertise); route;
775 route = ospf6_route_best_next (route))
776 {
777 op->prefix_length = route->prefix.prefixlen;
778 op->prefix_options = route->path.prefix_options;
779 op->prefix_metric = htons (route->path.cost);
780 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
781 OSPF6_PREFIX_SPACE (op->prefix_length));
782 op = OSPF6_PREFIX_NEXT (op);
783 prefix_num++;
784 }
785
786 ospf6_route_table_delete (route_advertise);
787
788 if (prefix_num == 0)
789 {
hasso1e058382004-09-01 21:36:14 +0000790 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000791 zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise");
hasso6452df02004-08-15 05:52:07 +0000792 return 0;
hasso508e53e2004-05-18 18:57:06 +0000793 }
794
795 intra_prefix_lsa->prefix_num = htons (prefix_num);
796
797 /* Fill LSA Header */
798 lsa_header->age = 0;
799 lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
800 lsa_header->id = htonl (0);
801 lsa_header->adv_router = oa->ospf6->router_id;
802 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000803 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
804 lsa_header->adv_router, oa->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000805 lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header);
806
807 /* LSA checksum */
808 ospf6_lsa_checksum (lsa_header);
809
810 /* create LSA */
811 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000812
813 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000814 ospf6_lsa_originate_area (lsa, oa);
815
816 return 0;
hasso508e53e2004-05-18 18:57:06 +0000817}
818
hasso6452df02004-08-15 05:52:07 +0000819
820int
821ospf6_intra_prefix_lsa_originate_transit (struct thread *thread)
hasso508e53e2004-05-18 18:57:06 +0000822{
hasso6452df02004-08-15 05:52:07 +0000823 struct ospf6_interface *oi;
824
hasso508e53e2004-05-18 18:57:06 +0000825 char buffer[OSPF6_MAX_LSASIZE];
826 struct ospf6_lsa_header *lsa_header;
827 struct ospf6_lsa *old, *lsa;
828
829 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
830 struct ospf6_neighbor *on;
831 struct ospf6_route *route;
832 struct ospf6_prefix *op;
hasso52dc7ee2004-09-23 19:18:23 +0000833 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +0000834 int full_count = 0;
835 unsigned short prefix_num = 0;
836 struct ospf6_route_table *route_advertise;
837 struct ospf6_link_lsa *link_lsa;
838 char *start, *end, *current;
839 u_int16_t type;
840 char buf[BUFSIZ];
841
hasso6452df02004-08-15 05:52:07 +0000842 oi = (struct ospf6_interface *) THREAD_ARG (thread);
843 oi->thread_intra_prefix_lsa = NULL;
844
845 assert (oi->area);
hasso508e53e2004-05-18 18:57:06 +0000846
847 /* find previous LSA */
848 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX),
849 htonl (oi->interface->ifindex),
850 oi->area->ospf6->router_id, oi->area->lsdb);
851
852 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
853 {
854 if (old)
hasso6452df02004-08-15 05:52:07 +0000855 ospf6_lsa_purge (old);
856 return 0;
hasso508e53e2004-05-18 18:57:06 +0000857 }
858
hasso1e058382004-09-01 21:36:14 +0000859 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000860 zlog_debug ("Originate Intra-Area-Prefix-LSA for interface %s's prefix",
hasso508e53e2004-05-18 18:57:06 +0000861 oi->interface->name);
862
863 /* prepare buffer */
864 memset (buffer, 0, sizeof (buffer));
865 lsa_header = (struct ospf6_lsa_header *) buffer;
866 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
867 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
868
869 /* Fill Intra-Area-Prefix-LSA */
870 intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_NETWORK);
871 intra_prefix_lsa->ref_id = htonl (oi->interface->ifindex);
872 intra_prefix_lsa->ref_adv_router = oi->area->ospf6->router_id;
873
874 if (oi->state != OSPF6_INTERFACE_DR)
875 {
hasso1e058382004-09-01 21:36:14 +0000876 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000877 zlog_debug (" Interface is not DR");
hasso508e53e2004-05-18 18:57:06 +0000878 if (old)
hasso6452df02004-08-15 05:52:07 +0000879 ospf6_lsa_purge (old);
880 return 0;
hasso508e53e2004-05-18 18:57:06 +0000881 }
882
883 full_count = 0;
paul1eb8ef22005-04-07 07:30:20 +0000884 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
885 if (on->state == OSPF6_NEIGHBOR_FULL)
886 full_count++;
887
hasso508e53e2004-05-18 18:57:06 +0000888 if (full_count == 0)
889 {
hasso1e058382004-09-01 21:36:14 +0000890 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000891 zlog_debug (" Interface is stub");
hasso508e53e2004-05-18 18:57:06 +0000892 if (old)
hasso6452df02004-08-15 05:52:07 +0000893 ospf6_lsa_purge (old);
894 return 0;
hasso508e53e2004-05-18 18:57:06 +0000895 }
896
897 /* connected prefix to advertise */
898 route_advertise = ospf6_route_table_create ();
899
900 type = ntohs (OSPF6_LSTYPE_LINK);
901 for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa;
902 lsa = ospf6_lsdb_type_next (type, lsa))
903 {
904 if (OSPF6_LSA_IS_MAXAGE (lsa))
paul718e3742002-12-13 20:15:29 +0000905 continue;
906
hasso1e058382004-09-01 21:36:14 +0000907 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000908 zlog_debug (" include prefix from %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000909
hasso508e53e2004-05-18 18:57:06 +0000910 if (lsa->header->adv_router != oi->area->ospf6->router_id)
paul718e3742002-12-13 20:15:29 +0000911 {
hasso508e53e2004-05-18 18:57:06 +0000912 on = ospf6_neighbor_lookup (lsa->header->adv_router, oi);
913 if (on == NULL || on->state != OSPF6_NEIGHBOR_FULL)
paul718e3742002-12-13 20:15:29 +0000914 {
hasso1e058382004-09-01 21:36:14 +0000915 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000916 zlog_debug (" Neighbor not found or not Full, ignore");
paul718e3742002-12-13 20:15:29 +0000917 continue;
918 }
919 }
920
hasso508e53e2004-05-18 18:57:06 +0000921 link_lsa = (struct ospf6_link_lsa *)
922 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000923
hasso508e53e2004-05-18 18:57:06 +0000924 prefix_num = (unsigned short) ntohl (link_lsa->prefix_num);
925 start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
926 end = (char *) lsa->header + ntohs (lsa->header->length);
927 for (current = start; current < end && prefix_num;
928 current += OSPF6_PREFIX_SIZE (op))
paul718e3742002-12-13 20:15:29 +0000929 {
hasso508e53e2004-05-18 18:57:06 +0000930 op = (struct ospf6_prefix *) current;
931 if (op->prefix_length == 0 ||
932 current + OSPF6_PREFIX_SIZE (op) > end)
933 break;
paul718e3742002-12-13 20:15:29 +0000934
hasso508e53e2004-05-18 18:57:06 +0000935 route = ospf6_route_create ();
936
937 route->type = OSPF6_DEST_TYPE_NETWORK;
938 route->prefix.family = AF_INET6;
939 route->prefix.prefixlen = op->prefix_length;
940 memset (&route->prefix.u.prefix6, 0, sizeof (struct in6_addr));
941 memcpy (&route->prefix.u.prefix6, OSPF6_PREFIX_BODY (op),
942 OSPF6_PREFIX_SPACE (op->prefix_length));
943
944 route->path.origin.type = lsa->header->type;
945 route->path.origin.id = lsa->header->id;
946 route->path.origin.adv_router = lsa->header->adv_router;
947 route->path.options[0] = link_lsa->options[0];
948 route->path.options[1] = link_lsa->options[1];
949 route->path.options[2] = link_lsa->options[2];
950 route->path.prefix_options = op->prefix_options;
951 route->path.area_id = oi->area->area_id;
952 route->path.type = OSPF6_PATH_TYPE_INTRA;
953
hasso1e058382004-09-01 21:36:14 +0000954 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
paul718e3742002-12-13 20:15:29 +0000955 {
hasso508e53e2004-05-18 18:57:06 +0000956 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000957 zlog_debug (" include %s", buf);
paul718e3742002-12-13 20:15:29 +0000958 }
959
hasso508e53e2004-05-18 18:57:06 +0000960 ospf6_route_add (route, route_advertise);
961 prefix_num--;
paul718e3742002-12-13 20:15:29 +0000962 }
hasso1e058382004-09-01 21:36:14 +0000963 if (current != end && IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000964 zlog_debug ("Trailing garbage in %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000965 }
966
hasso508e53e2004-05-18 18:57:06 +0000967 op = (struct ospf6_prefix *)
968 ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa));
969
970 prefix_num = 0;
971 for (route = ospf6_route_head (route_advertise); route;
972 route = ospf6_route_best_next (route))
paul718e3742002-12-13 20:15:29 +0000973 {
hasso508e53e2004-05-18 18:57:06 +0000974 op->prefix_length = route->prefix.prefixlen;
975 op->prefix_options = route->path.prefix_options;
976 op->prefix_metric = htons (0);
977 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
978 OSPF6_PREFIX_SPACE (op->prefix_length));
979 op = OSPF6_PREFIX_NEXT (op);
980 prefix_num++;
981 }
982
983 ospf6_route_table_delete (route_advertise);
984
985 if (prefix_num == 0)
986 {
hasso1e058382004-09-01 21:36:14 +0000987 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000988 zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise");
hasso6452df02004-08-15 05:52:07 +0000989 return 0;
paul718e3742002-12-13 20:15:29 +0000990 }
991
hasso508e53e2004-05-18 18:57:06 +0000992 intra_prefix_lsa->prefix_num = htons (prefix_num);
paul718e3742002-12-13 20:15:29 +0000993
hasso508e53e2004-05-18 18:57:06 +0000994 /* Fill LSA Header */
995 lsa_header->age = 0;
996 lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
997 lsa_header->id = htonl (oi->interface->ifindex);
998 lsa_header->adv_router = oi->area->ospf6->router_id;
999 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +00001000 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
1001 lsa_header->adv_router, oi->area->lsdb);
hasso508e53e2004-05-18 18:57:06 +00001002 lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header);
paul718e3742002-12-13 20:15:29 +00001003
hasso508e53e2004-05-18 18:57:06 +00001004 /* LSA checksum */
1005 ospf6_lsa_checksum (lsa_header);
paul718e3742002-12-13 20:15:29 +00001006
hasso508e53e2004-05-18 18:57:06 +00001007 /* create LSA */
1008 lsa = ospf6_lsa_create (lsa_header);
paul718e3742002-12-13 20:15:29 +00001009
hasso508e53e2004-05-18 18:57:06 +00001010 /* Originate */
hasso6452df02004-08-15 05:52:07 +00001011 ospf6_lsa_originate_area (lsa, oi->area);
paul718e3742002-12-13 20:15:29 +00001012
1013 return 0;
1014}
1015
1016void
hasso508e53e2004-05-18 18:57:06 +00001017ospf6_intra_prefix_lsa_add (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001018{
hasso508e53e2004-05-18 18:57:06 +00001019 struct ospf6_area *oa;
1020 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
1021 struct prefix ls_prefix;
1022 struct ospf6_route *route, *ls_entry;
1023 int i, prefix_num;
1024 struct ospf6_prefix *op;
1025 char *start, *current, *end;
1026 char buf[64];
paul718e3742002-12-13 20:15:29 +00001027
hassoccb59b12004-08-25 09:10:37 +00001028 if (OSPF6_LSA_IS_MAXAGE (lsa))
1029 return;
1030
hasso1e058382004-09-01 21:36:14 +00001031 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001032 zlog_debug ("%s found", lsa->name);
paul718e3742002-12-13 20:15:29 +00001033
hasso6452df02004-08-15 05:52:07 +00001034 oa = OSPF6_AREA (lsa->lsdb->data);
1035
hasso508e53e2004-05-18 18:57:06 +00001036 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
1037 OSPF6_LSA_HEADER_END (lsa->header);
1038 if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_ROUTER))
1039 ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router,
1040 htonl (0), &ls_prefix);
1041 else if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_NETWORK))
1042 ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router,
1043 intra_prefix_lsa->ref_id, &ls_prefix);
1044 else
1045 {
hasso1e058382004-09-01 21:36:14 +00001046 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001047 zlog_debug ("Unknown reference LS-type: %#hx",
1048 ntohs (intra_prefix_lsa->ref_type));
hasso508e53e2004-05-18 18:57:06 +00001049 return;
1050 }
paul718e3742002-12-13 20:15:29 +00001051
hasso508e53e2004-05-18 18:57:06 +00001052 ls_entry = ospf6_route_lookup (&ls_prefix, oa->spf_table);
1053 if (ls_entry == NULL)
1054 {
hasso1e058382004-09-01 21:36:14 +00001055 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hasso508e53e2004-05-18 18:57:06 +00001056 {
1057 ospf6_linkstate_prefix2str (&ls_prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +00001058 zlog_debug ("LS entry does not exist: %s", buf);
hasso508e53e2004-05-18 18:57:06 +00001059 }
1060 return;
1061 }
paul718e3742002-12-13 20:15:29 +00001062
hasso508e53e2004-05-18 18:57:06 +00001063 prefix_num = ntohs (intra_prefix_lsa->prefix_num);
1064 start = (caddr_t) intra_prefix_lsa +
1065 sizeof (struct ospf6_intra_prefix_lsa);
1066 end = OSPF6_LSA_END (lsa->header);
1067 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op))
1068 {
1069 op = (struct ospf6_prefix *) current;
1070 if (prefix_num == 0)
1071 break;
1072 if (end < current + OSPF6_PREFIX_SIZE (op))
1073 break;
1074
1075 route = ospf6_route_create ();
hassoccb59b12004-08-25 09:10:37 +00001076
1077 memset (&route->prefix, 0, sizeof (struct prefix));
hasso508e53e2004-05-18 18:57:06 +00001078 route->prefix.family = AF_INET6;
hassoccb59b12004-08-25 09:10:37 +00001079 route->prefix.prefixlen = op->prefix_length;
1080 ospf6_prefix_in6_addr (&route->prefix.u.prefix6, op);
1081
hasso508e53e2004-05-18 18:57:06 +00001082 route->type = OSPF6_DEST_TYPE_NETWORK;
1083 route->path.origin.type = lsa->header->type;
1084 route->path.origin.id = lsa->header->id;
1085 route->path.origin.adv_router = lsa->header->adv_router;
1086 route->path.prefix_options = op->prefix_options;
1087 route->path.area_id = oa->area_id;
1088 route->path.type = OSPF6_PATH_TYPE_INTRA;
1089 route->path.metric_type = 1;
1090 route->path.cost = ls_entry->path.cost +
1091 ntohs (op->prefix_metric);
1092
1093 for (i = 0; ospf6_nexthop_is_set (&ls_entry->nexthop[i]) &&
1094 i < OSPF6_MULTI_PATH_LIMIT; i++)
1095 ospf6_nexthop_copy (&route->nexthop[i], &ls_entry->nexthop[i]);
1096
hasso1e058382004-09-01 21:36:14 +00001097 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hasso508e53e2004-05-18 18:57:06 +00001098 {
1099 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +00001100 zlog_debug (" add %s", buf);
hasso508e53e2004-05-18 18:57:06 +00001101 }
1102
1103 ospf6_route_add (route, oa->route_table);
1104 prefix_num--;
1105 }
1106
hasso1e058382004-09-01 21:36:14 +00001107 if (current != end && IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001108 zlog_debug ("Trailing garbage ignored");
paul718e3742002-12-13 20:15:29 +00001109}
1110
1111void
hasso508e53e2004-05-18 18:57:06 +00001112ospf6_intra_prefix_lsa_remove (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001113{
hasso508e53e2004-05-18 18:57:06 +00001114 struct ospf6_area *oa;
1115 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
1116 struct prefix prefix;
1117 struct ospf6_route *route;
1118 int prefix_num;
1119 struct ospf6_prefix *op;
1120 char *start, *current, *end;
1121 char buf[64];
1122
hasso1e058382004-09-01 21:36:14 +00001123 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001124 zlog_debug ("%s disappearing", lsa->name);
hasso508e53e2004-05-18 18:57:06 +00001125
hasso6452df02004-08-15 05:52:07 +00001126 oa = OSPF6_AREA (lsa->lsdb->data);
1127
hasso508e53e2004-05-18 18:57:06 +00001128 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
1129 OSPF6_LSA_HEADER_END (lsa->header);
1130
1131 prefix_num = ntohs (intra_prefix_lsa->prefix_num);
1132 start = (caddr_t) intra_prefix_lsa +
1133 sizeof (struct ospf6_intra_prefix_lsa);
1134 end = OSPF6_LSA_END (lsa->header);
1135 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op))
1136 {
1137 op = (struct ospf6_prefix *) current;
1138 if (prefix_num == 0)
1139 break;
1140 if (end < current + OSPF6_PREFIX_SIZE (op))
1141 break;
1142 prefix_num--;
1143
hassoccb59b12004-08-25 09:10:37 +00001144 memset (&prefix, 0, sizeof (struct prefix));
hasso508e53e2004-05-18 18:57:06 +00001145 prefix.family = AF_INET6;
1146 prefix.prefixlen = op->prefix_length;
1147 ospf6_prefix_in6_addr (&prefix.u.prefix6, op);
1148
1149 route = ospf6_route_lookup (&prefix, oa->route_table);
1150 if (route == NULL)
1151 continue;
1152
1153 for (ospf6_route_lock (route);
1154 route && ospf6_route_is_prefix (&prefix, route);
1155 route = ospf6_route_next (route))
1156 {
1157 if (route->type != OSPF6_DEST_TYPE_NETWORK)
1158 continue;
1159 if (route->path.area_id != oa->area_id)
1160 continue;
1161 if (route->path.type != OSPF6_PATH_TYPE_INTRA)
1162 continue;
1163 if (route->path.origin.type != lsa->header->type ||
1164 route->path.origin.id != lsa->header->id ||
1165 route->path.origin.adv_router != lsa->header->adv_router)
1166 continue;
1167
hasso1e058382004-09-01 21:36:14 +00001168 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hasso508e53e2004-05-18 18:57:06 +00001169 {
1170 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +00001171 zlog_debug ("remove %s", buf);
hasso508e53e2004-05-18 18:57:06 +00001172 }
1173 ospf6_route_remove (route, oa->route_table);
1174 }
1175 }
1176
hasso1e058382004-09-01 21:36:14 +00001177 if (current != end && IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001178 zlog_debug ("Trailing garbage ignored");
paul718e3742002-12-13 20:15:29 +00001179}
1180
1181void
hasso508e53e2004-05-18 18:57:06 +00001182ospf6_intra_route_calculation (struct ospf6_area *oa)
paul718e3742002-12-13 20:15:29 +00001183{
hasso508e53e2004-05-18 18:57:06 +00001184 struct ospf6_route *route;
1185 u_int16_t type;
1186 struct ospf6_lsa *lsa;
1187 void (*hook_add) (struct ospf6_route *) = NULL;
1188 void (*hook_remove) (struct ospf6_route *) = NULL;
1189
hasso1e058382004-09-01 21:36:14 +00001190 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001191 zlog_debug ("Re-examin intra-routes for area %s", oa->name);
hasso508e53e2004-05-18 18:57:06 +00001192
1193 hook_add = oa->route_table->hook_add;
1194 hook_remove = oa->route_table->hook_remove;
1195 oa->route_table->hook_add = NULL;
1196 oa->route_table->hook_remove = NULL;
1197
1198 for (route = ospf6_route_head (oa->route_table); route;
1199 route = ospf6_route_next (route))
1200 route->flag = OSPF6_ROUTE_REMOVE;
1201
1202 type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
1203 for (lsa = ospf6_lsdb_type_head (type, oa->lsdb); lsa;
1204 lsa = ospf6_lsdb_type_next (type, lsa))
1205 ospf6_intra_prefix_lsa_add (lsa);
1206
1207 oa->route_table->hook_add = hook_add;
1208 oa->route_table->hook_remove = hook_remove;
1209
1210 for (route = ospf6_route_head (oa->route_table); route;
1211 route = ospf6_route_next (route))
1212 {
1213 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE) &&
1214 CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD))
1215 {
1216 UNSET_FLAG (route->flag, OSPF6_ROUTE_REMOVE);
1217 UNSET_FLAG (route->flag, OSPF6_ROUTE_ADD);
1218 }
1219
1220 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
1221 ospf6_route_remove (route, oa->route_table);
1222 else if (CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD) ||
1223 CHECK_FLAG (route->flag, OSPF6_ROUTE_CHANGE))
1224 {
1225 if (hook_add)
1226 (*hook_add) (route);
1227 }
1228
1229 route->flag = 0;
1230 }
1231
hasso1e058382004-09-01 21:36:14 +00001232 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001233 zlog_debug ("Re-examin intra-routes for area %s: Done", oa->name);
hasso508e53e2004-05-18 18:57:06 +00001234}
1235
1236void
hasso6452df02004-08-15 05:52:07 +00001237ospf6_intra_brouter_calculation (struct ospf6_area *oa)
hasso508e53e2004-05-18 18:57:06 +00001238{
1239 struct ospf6_route *lsentry, *copy;
1240 void (*hook_add) (struct ospf6_route *) = NULL;
1241 void (*hook_remove) (struct ospf6_route *) = NULL;
hassoccb59b12004-08-25 09:10:37 +00001242 char buf[16];
hasso508e53e2004-05-18 18:57:06 +00001243
hasso6452df02004-08-15 05:52:07 +00001244 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
hassoc6487d62004-12-24 06:00:11 +00001245 zlog_debug ("Border-router calculation for area %s", oa->name);
hasso508e53e2004-05-18 18:57:06 +00001246
hasso6452df02004-08-15 05:52:07 +00001247 hook_add = oa->ospf6->brouter_table->hook_add;
1248 hook_remove = oa->ospf6->brouter_table->hook_remove;
1249 oa->ospf6->brouter_table->hook_add = NULL;
1250 oa->ospf6->brouter_table->hook_remove = NULL;
hasso508e53e2004-05-18 18:57:06 +00001251
hasso6452df02004-08-15 05:52:07 +00001252 /* withdraw the previous router entries for the area */
1253 for (lsentry = ospf6_route_head (oa->ospf6->brouter_table); lsentry;
hasso508e53e2004-05-18 18:57:06 +00001254 lsentry = ospf6_route_next (lsentry))
1255 {
1256 if (lsentry->path.area_id != oa->area_id)
1257 continue;
1258 lsentry->flag = OSPF6_ROUTE_REMOVE;
1259 }
1260
1261 for (lsentry = ospf6_route_head (oa->spf_table); lsentry;
1262 lsentry = ospf6_route_next (lsentry))
1263 {
1264 if (lsentry->type != OSPF6_DEST_TYPE_LINKSTATE)
1265 continue;
1266 if (ospf6_linkstate_prefix_id (&lsentry->prefix) != htonl (0))
1267 continue;
hasso6452df02004-08-15 05:52:07 +00001268 if (! CHECK_FLAG (lsentry->path.router_bits, OSPF6_ROUTER_BIT_E) &&
1269 ! CHECK_FLAG (lsentry->path.router_bits, OSPF6_ROUTER_BIT_B))
hasso508e53e2004-05-18 18:57:06 +00001270 continue;
1271
1272 copy = ospf6_route_copy (lsentry);
1273 copy->type = OSPF6_DEST_TYPE_ROUTER;
hassoccb59b12004-08-25 09:10:37 +00001274 copy->path.area_id = oa->area_id;
hasso6452df02004-08-15 05:52:07 +00001275 ospf6_route_add (copy, oa->ospf6->brouter_table);
hassoccb59b12004-08-25 09:10:37 +00001276
1277 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1278 {
1279 inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&copy->prefix),
1280 buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +00001281 zlog_debug ("Re-install router entry %s", buf);
hassoccb59b12004-08-25 09:10:37 +00001282 }
hasso508e53e2004-05-18 18:57:06 +00001283 }
1284
hasso6452df02004-08-15 05:52:07 +00001285 oa->ospf6->brouter_table->hook_add = hook_add;
1286 oa->ospf6->brouter_table->hook_remove = hook_remove;
hasso508e53e2004-05-18 18:57:06 +00001287
hasso6452df02004-08-15 05:52:07 +00001288 for (lsentry = ospf6_route_head (oa->ospf6->brouter_table); lsentry;
hasso508e53e2004-05-18 18:57:06 +00001289 lsentry = ospf6_route_next (lsentry))
1290 {
1291 if (lsentry->path.area_id != oa->area_id)
1292 continue;
1293
hasso9428f2d2004-09-13 14:01:12 +00001294 if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_WAS_REMOVED))
1295 continue;
1296
hasso508e53e2004-05-18 18:57:06 +00001297 if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE) &&
1298 CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_ADD))
1299 {
1300 UNSET_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE);
1301 UNSET_FLAG (lsentry->flag, OSPF6_ROUTE_ADD);
1302 }
1303
1304 if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE))
hasso6452df02004-08-15 05:52:07 +00001305 ospf6_route_remove (lsentry, oa->ospf6->brouter_table);
hasso508e53e2004-05-18 18:57:06 +00001306 else if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_ADD) ||
1307 CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_CHANGE))
1308 {
hassoccb59b12004-08-25 09:10:37 +00001309 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1310 {
1311 inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&lsentry->prefix),
1312 buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +00001313 zlog_debug ("Call hook for router entry %s", buf);
hassoccb59b12004-08-25 09:10:37 +00001314 }
hasso508e53e2004-05-18 18:57:06 +00001315 if (hook_add)
1316 (*hook_add) (lsentry);
1317 }
1318
1319 lsentry->flag = 0;
1320 }
1321
hasso6452df02004-08-15 05:52:07 +00001322 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
hassoc6487d62004-12-24 06:00:11 +00001323 zlog_debug ("Border-router calculation for area %s: Done", oa->name);
paul718e3742002-12-13 20:15:29 +00001324}
1325
hasso6452df02004-08-15 05:52:07 +00001326struct ospf6_lsa_handler router_handler =
1327{
1328 OSPF6_LSTYPE_ROUTER,
1329 "Router",
1330 ospf6_router_lsa_show
1331};
1332
1333struct ospf6_lsa_handler network_handler =
1334{
1335 OSPF6_LSTYPE_NETWORK,
1336 "Network",
1337 ospf6_network_lsa_show
1338};
1339
1340struct ospf6_lsa_handler link_handler =
1341{
1342 OSPF6_LSTYPE_LINK,
1343 "Link",
1344 ospf6_link_lsa_show
1345};
1346
1347struct ospf6_lsa_handler intra_prefix_handler =
1348{
1349 OSPF6_LSTYPE_INTRA_PREFIX,
1350 "Intra-Prefix",
1351 ospf6_intra_prefix_lsa_show
1352};
1353
paul718e3742002-12-13 20:15:29 +00001354void
1355ospf6_intra_init ()
1356{
hasso6452df02004-08-15 05:52:07 +00001357 ospf6_install_lsa_handler (&router_handler);
1358 ospf6_install_lsa_handler (&network_handler);
1359 ospf6_install_lsa_handler (&link_handler);
1360 ospf6_install_lsa_handler (&intra_prefix_handler);
paul718e3742002-12-13 20:15:29 +00001361}
1362
1363