blob: 74a89642260266e74a34db610fa6ee644765eb00 [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;
112 listnode i, j;
113 struct ospf6_interface *oi;
114 struct ospf6_neighbor *on, *drouter = NULL;
115 struct ospf6_router_lsa *router_lsa;
116 struct ospf6_router_lsdesc *lsdesc;
117 u_int16_t type;
118 u_int32_t router;
119 int count;
paul718e3742002-12-13 20:15:29 +0000120
hasso6452df02004-08-15 05:52:07 +0000121 oa = (struct ospf6_area *) THREAD_ARG (thread);
122 oa->thread_router_lsa = NULL;
123
hasso508e53e2004-05-18 18:57:06 +0000124 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
125 zlog_info ("Originate Router-LSA for Area %s", oa->name);
paul718e3742002-12-13 20:15:29 +0000126
hasso508e53e2004-05-18 18:57:06 +0000127 memset (buffer, 0, sizeof (buffer));
128 lsa_header = (struct ospf6_lsa_header *) buffer;
129 router_lsa = (struct ospf6_router_lsa *)
130 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
131
132 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_V6);
133 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_E);
134 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_MC);
135 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_N);
136 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_R);
137 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_DC);
138
hasso6452df02004-08-15 05:52:07 +0000139 if (ospf6_is_router_abr (ospf6))
140 SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B);
141 else
142 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B);
hasso508e53e2004-05-18 18:57:06 +0000143 if (ospf6_asbr_is_asbr (ospf6))
144 SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E);
145 else
146 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E);
147 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_V);
148 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_W);
149
150 /* describe links for each interfaces */
151 lsdesc = (struct ospf6_router_lsdesc *)
152 ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa));
153
154 for (i = listhead (oa->if_list); i; nextnode (i))
paul718e3742002-12-13 20:15:29 +0000155 {
hasso508e53e2004-05-18 18:57:06 +0000156 oi = (struct ospf6_interface *) getdata (i);
157
158 /* Interfaces in state Down or Loopback are not described */
159 if (oi->state == OSPF6_INTERFACE_DOWN ||
160 oi->state == OSPF6_INTERFACE_LOOPBACK)
paul718e3742002-12-13 20:15:29 +0000161 continue;
162
hasso508e53e2004-05-18 18:57:06 +0000163 /* Nor are interfaces without any full adjacencies described */
164 count = 0;
165 for (j = listhead (oi->neighbor_list); j; nextnode (j))
paul718e3742002-12-13 20:15:29 +0000166 {
hasso508e53e2004-05-18 18:57:06 +0000167 on = (struct ospf6_neighbor *) getdata (j);
168 if (on->state == OSPF6_NEIGHBOR_FULL)
169 count++;
170 }
171 if (count == 0)
172 continue;
173
174 /* Multiple Router-LSA instance according to size limit setting */
175 if (oa->router_lsa_size_limit != 0 &&
176 (caddr_t) lsdesc + sizeof (struct ospf6_router_lsdesc) -
177 (caddr_t) buffer > oa->router_lsa_size_limit)
178 {
179 if ((caddr_t) lsdesc == (caddr_t) router_lsa +
180 sizeof (struct ospf6_router_lsa))
181 {
182 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
183 zlog_info ("Size limit setting for Router-LSA too short");
hasso6452df02004-08-15 05:52:07 +0000184 return 0;
hasso508e53e2004-05-18 18:57:06 +0000185 }
186
187 /* Fill LSA Header */
188 lsa_header->age = 0;
189 lsa_header->type = htons (OSPF6_LSTYPE_ROUTER);
190 lsa_header->id = htonl (link_state_id);
191 lsa_header->adv_router = oa->ospf6->router_id;
192 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000193 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
194 lsa_header->adv_router, oa->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000195 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
196
197 /* LSA checksum */
198 ospf6_lsa_checksum (lsa_header);
199
200 /* create LSA */
201 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000202
203 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000204 ospf6_lsa_originate_area (lsa, oa);
hasso508e53e2004-05-18 18:57:06 +0000205
206 /* Reset setting for consecutive origination */
207 memset ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa),
208 0, (caddr_t) lsdesc - (caddr_t) router_lsa);
209 lsdesc = (struct ospf6_router_lsdesc *)
210 ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa));
211 link_state_id ++;
paul718e3742002-12-13 20:15:29 +0000212 }
213
hasso508e53e2004-05-18 18:57:06 +0000214 /* Point-to-Point interfaces */
215 if (if_is_pointopoint (oi->interface))
216 {
217 for (j = listhead (oi->neighbor_list); j; nextnode (j))
218 {
219 on = (struct ospf6_neighbor *) getdata (j);
220 if (on->state != OSPF6_NEIGHBOR_FULL)
221 continue;
paul718e3742002-12-13 20:15:29 +0000222
hasso508e53e2004-05-18 18:57:06 +0000223 lsdesc->type = OSPF6_ROUTER_LSDESC_POINTTOPOINT;
224 lsdesc->metric = htons (oi->cost);
225 lsdesc->interface_id = htonl (oi->interface->ifindex);
226 lsdesc->neighbor_interface_id = htonl (on->ifindex);
227 lsdesc->neighbor_router_id = on->router_id;
228
229 lsdesc++;
230 }
231 }
232
233 /* Broadcast and NBMA interfaces */
234 if (if_is_broadcast (oi->interface))
235 {
236 /* If this router is not DR,
237 and If this router not fully adjacent with DR,
238 this interface is not transit yet: ignore. */
239 if (oi->state != OSPF6_INTERFACE_DR)
240 {
241 drouter = ospf6_neighbor_lookup (oi->drouter, oi);
242 if (drouter == NULL || drouter->state != OSPF6_NEIGHBOR_FULL)
243 continue;
244 }
245
246 lsdesc->type = OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK;
247 lsdesc->metric = htons (oi->cost);
248 lsdesc->interface_id = htonl (oi->interface->ifindex);
249 if (oi->state != OSPF6_INTERFACE_DR)
250 {
251 lsdesc->neighbor_interface_id = htonl (drouter->ifindex);
252 lsdesc->neighbor_router_id = drouter->router_id;
253 }
254 else
255 {
256 lsdesc->neighbor_interface_id = htonl (oi->interface->ifindex);
257 lsdesc->neighbor_router_id = oi->area->ospf6->router_id;
258 }
259
260 lsdesc++;
261 }
262
263 /* Virtual links */
264 /* xxx */
265 /* Point-to-Multipoint interfaces */
266 /* xxx */
paul718e3742002-12-13 20:15:29 +0000267 }
hasso508e53e2004-05-18 18:57:06 +0000268
269 if ((caddr_t) lsdesc != (caddr_t) router_lsa +
270 sizeof (struct ospf6_router_lsa))
271 {
272 /* Fill LSA Header */
273 lsa_header->age = 0;
274 lsa_header->type = htons (OSPF6_LSTYPE_ROUTER);
275 lsa_header->id = htonl (link_state_id);
276 lsa_header->adv_router = oa->ospf6->router_id;
277 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000278 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
279 lsa_header->adv_router, oa->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000280 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
281
282 /* LSA checksum */
283 ospf6_lsa_checksum (lsa_header);
284
285 /* create LSA */
286 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000287
288 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000289 ospf6_lsa_originate_area (lsa, oa);
hasso508e53e2004-05-18 18:57:06 +0000290
291 link_state_id ++;
292 }
hasso6452df02004-08-15 05:52:07 +0000293 else
294 {
295 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
296 zlog_info ("Nothing to describe in Router-LSA, suppress");
297 }
hasso508e53e2004-05-18 18:57:06 +0000298
299 /* Do premature-aging of rest, undesired Router-LSAs */
300 type = ntohs (OSPF6_LSTYPE_ROUTER);
301 router = oa->ospf6->router_id;
302 for (lsa = ospf6_lsdb_type_router_head (type, router, oa->lsdb); lsa;
303 lsa = ospf6_lsdb_type_router_next (type, router, lsa))
304 {
305 if (ntohl (lsa->header->id) < link_state_id)
306 continue;
hasso6452df02004-08-15 05:52:07 +0000307 ospf6_lsa_purge (lsa);
hasso508e53e2004-05-18 18:57:06 +0000308 }
hasso508e53e2004-05-18 18:57:06 +0000309
310 return 0;
311}
312
hasso508e53e2004-05-18 18:57:06 +0000313/*******************************/
314/* RFC2740 3.4.3.2 Network-LSA */
315/*******************************/
316
317int
318ospf6_network_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
319{
320 char *start, *end, *current;
321 struct ospf6_network_lsa *network_lsa;
322 struct ospf6_network_lsdesc *lsdesc;
323 char buf[128], options[32];
324
325 network_lsa = (struct ospf6_network_lsa *)
326 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
327
328 ospf6_options_printbuf (network_lsa->options, options, sizeof (options));
hasso049207c2004-08-04 20:02:13 +0000329 vty_out (vty, " Options: %s%s", options, VNL);
hasso508e53e2004-05-18 18:57:06 +0000330
331 start = (char *) network_lsa + sizeof (struct ospf6_network_lsa);
332 end = (char *) lsa->header + ntohs (lsa->header->length);
333 for (current = start; current + sizeof (struct ospf6_network_lsdesc) <= end;
334 current += sizeof (struct ospf6_network_lsdesc))
335 {
336 lsdesc = (struct ospf6_network_lsdesc *) current;
337 inet_ntop (AF_INET, &lsdesc->router_id, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000338 vty_out (vty, " Attached Router: %s%s", buf, VNL);
hasso508e53e2004-05-18 18:57:06 +0000339 }
340 return 0;
paul718e3742002-12-13 20:15:29 +0000341}
342
hasso6452df02004-08-15 05:52:07 +0000343int
344ospf6_network_lsa_originate (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000345{
hasso6452df02004-08-15 05:52:07 +0000346 struct ospf6_interface *oi;
347
hasso508e53e2004-05-18 18:57:06 +0000348 char buffer [OSPF6_MAX_LSASIZE];
349 struct ospf6_lsa_header *lsa_header;
paul718e3742002-12-13 20:15:29 +0000350
hasso508e53e2004-05-18 18:57:06 +0000351 int count;
352 struct ospf6_lsa *old, *lsa;
353 struct ospf6_network_lsa *network_lsa;
354 struct ospf6_network_lsdesc *lsdesc;
355 struct ospf6_neighbor *on;
356 struct ospf6_link_lsa *link_lsa;
357 listnode i;
358 u_int16_t type;
359
hasso6452df02004-08-15 05:52:07 +0000360 oi = (struct ospf6_interface *) THREAD_ARG (thread);
361 oi->thread_network_lsa = NULL;
362
363 /* The interface must be enabled until here. A Network-LSA of a
364 disabled interface (but was once enabled) should be flushed
365 by ospf6_lsa_refresh (), and does not come here. */
366 assert (oi->area);
paul718e3742002-12-13 20:15:29 +0000367
hasso508e53e2004-05-18 18:57:06 +0000368 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_NETWORK),
369 htonl (oi->interface->ifindex),
370 oi->area->ospf6->router_id, oi->area->lsdb);
paul718e3742002-12-13 20:15:29 +0000371
hasso508e53e2004-05-18 18:57:06 +0000372 /* Do not originate Network-LSA if not DR */
373 if (oi->state != OSPF6_INTERFACE_DR)
paul718e3742002-12-13 20:15:29 +0000374 {
hasso508e53e2004-05-18 18:57:06 +0000375 if (old)
hasso6452df02004-08-15 05:52:07 +0000376 ospf6_lsa_purge (old);
377 return 0;
paul718e3742002-12-13 20:15:29 +0000378 }
hasso508e53e2004-05-18 18:57:06 +0000379
380 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
381 zlog_info ("Originate Network-LSA for Interface %s", oi->interface->name);
382
383 /* If none of neighbor is adjacent to us */
384 count = 0;
385 for (i = listhead (oi->neighbor_list); i; nextnode (i))
386 {
387 on = (struct ospf6_neighbor *) getdata (i);
388 if (on->state == OSPF6_NEIGHBOR_FULL)
389 count++;
390 }
391 if (count == 0)
392 {
393 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
394 zlog_info ("Interface stub, ignore");
395 if (old)
hasso6452df02004-08-15 05:52:07 +0000396 ospf6_lsa_purge (old);
397 return 0;
hasso508e53e2004-05-18 18:57:06 +0000398 }
399
400 /* prepare buffer */
401 memset (buffer, 0, sizeof (buffer));
402 lsa_header = (struct ospf6_lsa_header *) buffer;
403 network_lsa = (struct ospf6_network_lsa *)
404 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
405
406 /* Collect the interface's Link-LSAs to describe
407 network's optional capabilities */
408 type = htons (OSPF6_LSTYPE_LINK);
409 for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa;
410 lsa = ospf6_lsdb_type_next (type, lsa))
411 {
412 link_lsa = (struct ospf6_link_lsa *)
413 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
414 network_lsa->options[0] |= link_lsa->options[0];
415 network_lsa->options[1] |= link_lsa->options[1];
416 network_lsa->options[2] |= link_lsa->options[2];
417 }
418
419 lsdesc = (struct ospf6_network_lsdesc *)
420 ((caddr_t) network_lsa + sizeof (struct ospf6_network_lsa));
421
422 /* set Link Description to the router itself */
423 lsdesc->router_id = oi->area->ospf6->router_id;
424 lsdesc++;
425
426 /* Walk through the neighbors */
427 for (i = listhead (oi->neighbor_list); i; nextnode (i))
428 {
429 on = (struct ospf6_neighbor *) getdata (i);
430
431 if (on->state != OSPF6_NEIGHBOR_FULL)
432 continue;
433
434 /* set this neighbor's Router-ID to LSA */
435 lsdesc->router_id = on->router_id;
436 lsdesc++;
437 }
438
439 /* Fill LSA Header */
440 lsa_header->age = 0;
441 lsa_header->type = htons (OSPF6_LSTYPE_NETWORK);
442 lsa_header->id = htonl (oi->interface->ifindex);
443 lsa_header->adv_router = oi->area->ospf6->router_id;
444 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000445 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
446 lsa_header->adv_router, oi->area->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000447 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
448
449 /* LSA checksum */
450 ospf6_lsa_checksum (lsa_header);
451
452 /* create LSA */
453 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000454
455 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000456 ospf6_lsa_originate_area (lsa, oi->area);
hasso508e53e2004-05-18 18:57:06 +0000457
458 return 0;
459}
460
461
462/****************************/
463/* RFC2740 3.4.3.6 Link-LSA */
464/****************************/
465
466int
467ospf6_link_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
468{
paul718e3742002-12-13 20:15:29 +0000469 char *start, *end, *current;
hasso508e53e2004-05-18 18:57:06 +0000470 struct ospf6_link_lsa *link_lsa;
471 int prefixnum;
472 char buf[128], options[32];
473 struct ospf6_prefix *prefix;
474 char *p, *mc, *la, *nu;
475 struct in6_addr in6;
paul718e3742002-12-13 20:15:29 +0000476
hasso508e53e2004-05-18 18:57:06 +0000477 link_lsa = (struct ospf6_link_lsa *)
478 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000479
hasso508e53e2004-05-18 18:57:06 +0000480 ospf6_options_printbuf (link_lsa->options, options, sizeof (options));
481 inet_ntop (AF_INET6, &link_lsa->linklocal_addr, buf, sizeof (buf));
482 prefixnum = ntohl (link_lsa->prefix_num);
paul718e3742002-12-13 20:15:29 +0000483
hasso508e53e2004-05-18 18:57:06 +0000484 vty_out (vty, " Priority: %d Options: %s%s",
hasso049207c2004-08-04 20:02:13 +0000485 link_lsa->priority, options, VNL);
486 vty_out (vty, " LinkLocal Address: %s%s", buf, VNL);
487 vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL);
paul718e3742002-12-13 20:15:29 +0000488
hasso508e53e2004-05-18 18:57:06 +0000489 start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
490 end = (char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000491 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix))
492 {
493 prefix = (struct ospf6_prefix *) current;
hasso508e53e2004-05-18 18:57:06 +0000494 if (prefix->prefix_length == 0 ||
495 current + OSPF6_PREFIX_SIZE (prefix) > end)
496 break;
paul718e3742002-12-13 20:15:29 +0000497
hasso508e53e2004-05-18 18:57:06 +0000498 p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ?
499 "P" : "--");
500 mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ?
501 "MC" : "--");
502 la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ?
503 "LA" : "--");
504 nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ?
505 "NU" : "--");
506 vty_out (vty, " Prefix Options: %s|%s|%s|%s%s",
hasso049207c2004-08-04 20:02:13 +0000507 p, mc, la, nu, VNL);
paul718e3742002-12-13 20:15:29 +0000508
hasso508e53e2004-05-18 18:57:06 +0000509 memset (&in6, 0, sizeof (in6));
510 memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
511 OSPF6_PREFIX_SPACE (prefix->prefix_length));
paul718e3742002-12-13 20:15:29 +0000512 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
513 vty_out (vty, " Prefix: %s/%d%s",
hasso049207c2004-08-04 20:02:13 +0000514 buf, prefix->prefix_length, VNL);
paul718e3742002-12-13 20:15:29 +0000515 }
516
517 return 0;
518}
519
hasso6452df02004-08-15 05:52:07 +0000520int
521ospf6_link_lsa_originate (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000522{
hasso6452df02004-08-15 05:52:07 +0000523 struct ospf6_interface *oi;
524
hasso508e53e2004-05-18 18:57:06 +0000525 char buffer[OSPF6_MAX_LSASIZE];
526 struct ospf6_lsa_header *lsa_header;
527 struct ospf6_lsa *old, *lsa;
paul718e3742002-12-13 20:15:29 +0000528
hasso508e53e2004-05-18 18:57:06 +0000529 struct ospf6_link_lsa *link_lsa;
530 struct ospf6_route *route;
531 struct ospf6_prefix *op;
paul718e3742002-12-13 20:15:29 +0000532
hasso6452df02004-08-15 05:52:07 +0000533 oi = (struct ospf6_interface *) THREAD_ARG (thread);
534 oi->thread_link_lsa = NULL;
535
536 assert (oi->area);
paul718e3742002-12-13 20:15:29 +0000537
538 /* find previous LSA */
hasso508e53e2004-05-18 18:57:06 +0000539 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_LINK),
540 htonl (oi->interface->ifindex),
541 oi->area->ospf6->router_id, oi->lsdb);
paul718e3742002-12-13 20:15:29 +0000542
hasso508e53e2004-05-18 18:57:06 +0000543 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
paul718e3742002-12-13 20:15:29 +0000544 {
545 if (old)
hasso6452df02004-08-15 05:52:07 +0000546 ospf6_lsa_purge (old);
547 return 0;
paul718e3742002-12-13 20:15:29 +0000548 }
549
hasso508e53e2004-05-18 18:57:06 +0000550 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
551 zlog_info ("Originate Link-LSA for Interface %s", oi->interface->name);
paul718e3742002-12-13 20:15:29 +0000552
hasso508e53e2004-05-18 18:57:06 +0000553 /* can't make Link-LSA if linklocal address not set */
554 if (oi->linklocal_addr == NULL)
paul718e3742002-12-13 20:15:29 +0000555 {
hasso508e53e2004-05-18 18:57:06 +0000556 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
557 zlog_info ("No Linklocal address on %s, defer originating",
558 oi->interface->name);
559 if (old)
hasso6452df02004-08-15 05:52:07 +0000560 ospf6_lsa_purge (old);
561 return 0;
hasso508e53e2004-05-18 18:57:06 +0000562 }
563
564 /* prepare buffer */
565 memset (buffer, 0, sizeof (buffer));
566 lsa_header = (struct ospf6_lsa_header *) buffer;
567 link_lsa = (struct ospf6_link_lsa *)
568 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
569
570 /* Fill Link-LSA */
571 link_lsa->priority = oi->priority;
572 memcpy (link_lsa->options, oi->area->options, 3);
573 memcpy (&link_lsa->linklocal_addr, oi->linklocal_addr,
574 sizeof (struct in6_addr));
575 link_lsa->prefix_num = htonl (oi->route_connected->count);
576
577 op = (struct ospf6_prefix *)
578 ((caddr_t) link_lsa + sizeof (struct ospf6_link_lsa));
579
580 /* connected prefix to advertise */
581 for (route = ospf6_route_head (oi->route_connected); route;
582 route = ospf6_route_next (route))
583 {
584 op->prefix_length = route->prefix.prefixlen;
585 op->prefix_options = route->path.prefix_options;
586 op->prefix_metric = htons (0);
587 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
588 OSPF6_PREFIX_SPACE (op->prefix_length));
589 op = OSPF6_PREFIX_NEXT (op);
590 }
591
592 /* Fill LSA Header */
593 lsa_header->age = 0;
594 lsa_header->type = htons (OSPF6_LSTYPE_LINK);
595 lsa_header->id = htonl (oi->interface->ifindex);
596 lsa_header->adv_router = oi->area->ospf6->router_id;
597 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000598 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
599 lsa_header->adv_router, oi->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000600 lsa_header->length = htons ((caddr_t) op - (caddr_t) buffer);
601
602 /* LSA checksum */
603 ospf6_lsa_checksum (lsa_header);
604
605 /* create LSA */
606 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000607
608 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000609 ospf6_lsa_originate_interface (lsa, oi);
hasso508e53e2004-05-18 18:57:06 +0000610
611 return 0;
612}
613
614
615/*****************************************/
616/* RFC2740 3.4.3.7 Intra-Area-Prefix-LSA */
617/*****************************************/
618
619int
620ospf6_intra_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
621{
622 char *start, *end, *current;
623 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
624 int prefixnum;
625 char buf[128];
626 struct ospf6_prefix *prefix;
627 char id[16], adv_router[16];
628 char *p, *mc, *la, *nu;
629 struct in6_addr in6;
630
631 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
632 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
633
634 prefixnum = ntohs (intra_prefix_lsa->prefix_num);
635
hasso049207c2004-08-04 20:02:13 +0000636 vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL);
hasso508e53e2004-05-18 18:57:06 +0000637
638 inet_ntop (AF_INET, &intra_prefix_lsa->ref_id, id, sizeof (id));
639 inet_ntop (AF_INET, &intra_prefix_lsa->ref_adv_router,
640 adv_router, sizeof (adv_router));
641 vty_out (vty, " Reference: %s Id: %s Adv: %s%s",
642 OSPF6_LSTYPE_NAME (intra_prefix_lsa->ref_type), id, adv_router,
hasso049207c2004-08-04 20:02:13 +0000643 VNL);
hasso508e53e2004-05-18 18:57:06 +0000644
645 start = (char *) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa);
646 end = (char *) lsa->header + ntohs (lsa->header->length);
647 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix))
648 {
649 prefix = (struct ospf6_prefix *) current;
650 if (prefix->prefix_length == 0 ||
651 current + OSPF6_PREFIX_SIZE (prefix) > end)
652 break;
653
654 p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ?
655 "P" : "--");
656 mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ?
657 "MC" : "--");
658 la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ?
659 "LA" : "--");
660 nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ?
661 "NU" : "--");
662 vty_out (vty, " Prefix Options: %s|%s|%s|%s%s",
hasso049207c2004-08-04 20:02:13 +0000663 p, mc, la, nu, VNL);
hasso508e53e2004-05-18 18:57:06 +0000664
665 memset (&in6, 0, sizeof (in6));
666 memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
667 OSPF6_PREFIX_SPACE (prefix->prefix_length));
668 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
669 vty_out (vty, " Prefix: %s/%d%s",
hasso049207c2004-08-04 20:02:13 +0000670 buf, prefix->prefix_length, VNL);
hasso508e53e2004-05-18 18:57:06 +0000671 }
672
673 return 0;
674}
675
hasso6452df02004-08-15 05:52:07 +0000676int
677ospf6_intra_prefix_lsa_originate_stub (struct thread *thread)
hasso508e53e2004-05-18 18:57:06 +0000678{
hasso6452df02004-08-15 05:52:07 +0000679 struct ospf6_area *oa;
680
hasso508e53e2004-05-18 18:57:06 +0000681 char buffer[OSPF6_MAX_LSASIZE];
682 struct ospf6_lsa_header *lsa_header;
683 struct ospf6_lsa *old, *lsa;
684
685 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
686 struct ospf6_interface *oi;
687 struct ospf6_neighbor *on;
688 struct ospf6_route *route;
689 struct ospf6_prefix *op;
690 listnode i, j;
691 int full_count = 0;
692 unsigned short prefix_num = 0;
693 char buf[BUFSIZ];
694 struct ospf6_route_table *route_advertise;
695
hasso6452df02004-08-15 05:52:07 +0000696 oa = (struct ospf6_area *) THREAD_ARG (thread);
697 oa->thread_intra_prefix_lsa = NULL;
698
hasso508e53e2004-05-18 18:57:06 +0000699 /* find previous LSA */
700 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX),
701 htonl (0), oa->ospf6->router_id, oa->lsdb);
702
hasso6452df02004-08-15 05:52:07 +0000703 if (! IS_AREA_ENABLED (oa))
hasso508e53e2004-05-18 18:57:06 +0000704 {
705 if (old)
hasso6452df02004-08-15 05:52:07 +0000706 ospf6_lsa_purge (old);
707 return 0;
hasso508e53e2004-05-18 18:57:06 +0000708 }
709
710 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
711 zlog_info ("Originate Intra-Area-Prefix-LSA for area %s's stub prefix",
712 oa->name);
713
714 /* prepare buffer */
715 memset (buffer, 0, sizeof (buffer));
716 lsa_header = (struct ospf6_lsa_header *) buffer;
717 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
718 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
719
720 /* Fill Intra-Area-Prefix-LSA */
721 intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_ROUTER);
722 intra_prefix_lsa->ref_id = htonl (0);
723 intra_prefix_lsa->ref_adv_router = oa->ospf6->router_id;
724
725 route_advertise = ospf6_route_table_create ();
726
727 for (i = listhead (oa->if_list); i; nextnode (i))
728 {
729 oi = (struct ospf6_interface *) getdata (i);
730
731 if (oi->state == OSPF6_INTERFACE_DOWN)
732 {
733 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
734 zlog_info (" Interface %s is down, ignore", oi->interface->name);
735 continue;
736 }
737
738 full_count = 0;
739 for (j = listhead (oi->neighbor_list); j; nextnode (j))
740 {
741 on = (struct ospf6_neighbor *) getdata (j);
742 if (on->state == OSPF6_NEIGHBOR_FULL)
743 full_count++;
744 }
745 if (oi->state != OSPF6_INTERFACE_LOOPBACK &&
746 oi->state != OSPF6_INTERFACE_POINTTOPOINT &&
747 full_count != 0)
748 {
749 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
750 zlog_info (" Interface %s is not stub, ignore",
751 oi->interface->name);
752 continue;
753 }
754
755 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
756 zlog_info (" Interface %s:", oi->interface->name);
757
758 /* connected prefix to advertise */
759 for (route = ospf6_route_head (oi->route_connected); route;
760 route = ospf6_route_best_next (route))
761 {
762 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
763 {
764 prefix2str (&route->prefix, buf, sizeof (buf));
765 zlog_info (" include %s", buf);
766 }
767 ospf6_route_add (ospf6_route_copy (route), route_advertise);
768 }
769 }
770
771 if (route_advertise->count == 0)
772 {
773 if (old)
hasso6452df02004-08-15 05:52:07 +0000774 ospf6_lsa_purge (old);
hasso508e53e2004-05-18 18:57:06 +0000775 ospf6_route_table_delete (route_advertise);
hasso6452df02004-08-15 05:52:07 +0000776 return 0;
hasso508e53e2004-05-18 18:57:06 +0000777 }
778
779 /* put prefixes to advertise */
780 prefix_num = 0;
781 op = (struct ospf6_prefix *)
782 ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa));
783 for (route = ospf6_route_head (route_advertise); route;
784 route = ospf6_route_best_next (route))
785 {
786 op->prefix_length = route->prefix.prefixlen;
787 op->prefix_options = route->path.prefix_options;
788 op->prefix_metric = htons (route->path.cost);
789 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
790 OSPF6_PREFIX_SPACE (op->prefix_length));
791 op = OSPF6_PREFIX_NEXT (op);
792 prefix_num++;
793 }
794
795 ospf6_route_table_delete (route_advertise);
796
797 if (prefix_num == 0)
798 {
799 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
800 zlog_info ("Quit to Advertise Intra-Prefix: no route to advertise");
hasso6452df02004-08-15 05:52:07 +0000801 return 0;
hasso508e53e2004-05-18 18:57:06 +0000802 }
803
804 intra_prefix_lsa->prefix_num = htons (prefix_num);
805
806 /* Fill LSA Header */
807 lsa_header->age = 0;
808 lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
809 lsa_header->id = htonl (0);
810 lsa_header->adv_router = oa->ospf6->router_id;
811 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000812 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
813 lsa_header->adv_router, oa->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000814 lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header);
815
816 /* LSA checksum */
817 ospf6_lsa_checksum (lsa_header);
818
819 /* create LSA */
820 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000821
822 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000823 ospf6_lsa_originate_area (lsa, oa);
824
825 return 0;
hasso508e53e2004-05-18 18:57:06 +0000826}
827
hasso6452df02004-08-15 05:52:07 +0000828
829int
830ospf6_intra_prefix_lsa_originate_transit (struct thread *thread)
hasso508e53e2004-05-18 18:57:06 +0000831{
hasso6452df02004-08-15 05:52:07 +0000832 struct ospf6_interface *oi;
833
hasso508e53e2004-05-18 18:57:06 +0000834 char buffer[OSPF6_MAX_LSASIZE];
835 struct ospf6_lsa_header *lsa_header;
836 struct ospf6_lsa *old, *lsa;
837
838 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
839 struct ospf6_neighbor *on;
840 struct ospf6_route *route;
841 struct ospf6_prefix *op;
842 listnode i;
843 int full_count = 0;
844 unsigned short prefix_num = 0;
845 struct ospf6_route_table *route_advertise;
846 struct ospf6_link_lsa *link_lsa;
847 char *start, *end, *current;
848 u_int16_t type;
849 char buf[BUFSIZ];
850
hasso6452df02004-08-15 05:52:07 +0000851 oi = (struct ospf6_interface *) THREAD_ARG (thread);
852 oi->thread_intra_prefix_lsa = NULL;
853
854 assert (oi->area);
hasso508e53e2004-05-18 18:57:06 +0000855
856 /* find previous LSA */
857 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX),
858 htonl (oi->interface->ifindex),
859 oi->area->ospf6->router_id, oi->area->lsdb);
860
861 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
862 {
863 if (old)
hasso6452df02004-08-15 05:52:07 +0000864 ospf6_lsa_purge (old);
865 return 0;
hasso508e53e2004-05-18 18:57:06 +0000866 }
867
868 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
869 zlog_info ("Originate Intra-Area-Prefix-LSA for interface %s's prefix",
870 oi->interface->name);
871
872 /* prepare buffer */
873 memset (buffer, 0, sizeof (buffer));
874 lsa_header = (struct ospf6_lsa_header *) buffer;
875 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
876 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
877
878 /* Fill Intra-Area-Prefix-LSA */
879 intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_NETWORK);
880 intra_prefix_lsa->ref_id = htonl (oi->interface->ifindex);
881 intra_prefix_lsa->ref_adv_router = oi->area->ospf6->router_id;
882
883 if (oi->state != OSPF6_INTERFACE_DR)
884 {
885 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
886 zlog_info (" Interface is not DR");
887 if (old)
hasso6452df02004-08-15 05:52:07 +0000888 ospf6_lsa_purge (old);
889 return 0;
hasso508e53e2004-05-18 18:57:06 +0000890 }
891
892 full_count = 0;
893 for (i = listhead (oi->neighbor_list); i; nextnode (i))
894 {
895 on = (struct ospf6_neighbor *) getdata (i);
896 if (on->state == OSPF6_NEIGHBOR_FULL)
897 full_count++;
898 }
899 if (full_count == 0)
900 {
901 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
902 zlog_info (" Interface is stub");
903 if (old)
hasso6452df02004-08-15 05:52:07 +0000904 ospf6_lsa_purge (old);
905 return 0;
hasso508e53e2004-05-18 18:57:06 +0000906 }
907
908 /* connected prefix to advertise */
909 route_advertise = ospf6_route_table_create ();
910
911 type = ntohs (OSPF6_LSTYPE_LINK);
912 for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa;
913 lsa = ospf6_lsdb_type_next (type, lsa))
914 {
915 if (OSPF6_LSA_IS_MAXAGE (lsa))
paul718e3742002-12-13 20:15:29 +0000916 continue;
917
hasso508e53e2004-05-18 18:57:06 +0000918 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
919 zlog_info (" include prefix from %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000920
hasso508e53e2004-05-18 18:57:06 +0000921 if (lsa->header->adv_router != oi->area->ospf6->router_id)
paul718e3742002-12-13 20:15:29 +0000922 {
hasso508e53e2004-05-18 18:57:06 +0000923 on = ospf6_neighbor_lookup (lsa->header->adv_router, oi);
924 if (on == NULL || on->state != OSPF6_NEIGHBOR_FULL)
paul718e3742002-12-13 20:15:29 +0000925 {
hasso508e53e2004-05-18 18:57:06 +0000926 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
927 zlog_info (" Neighbor not found or not Full, ignore");
paul718e3742002-12-13 20:15:29 +0000928 continue;
929 }
930 }
931
hasso508e53e2004-05-18 18:57:06 +0000932 link_lsa = (struct ospf6_link_lsa *)
933 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000934
hasso508e53e2004-05-18 18:57:06 +0000935 prefix_num = (unsigned short) ntohl (link_lsa->prefix_num);
936 start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
937 end = (char *) lsa->header + ntohs (lsa->header->length);
938 for (current = start; current < end && prefix_num;
939 current += OSPF6_PREFIX_SIZE (op))
paul718e3742002-12-13 20:15:29 +0000940 {
hasso508e53e2004-05-18 18:57:06 +0000941 op = (struct ospf6_prefix *) current;
942 if (op->prefix_length == 0 ||
943 current + OSPF6_PREFIX_SIZE (op) > end)
944 break;
paul718e3742002-12-13 20:15:29 +0000945
hasso508e53e2004-05-18 18:57:06 +0000946 route = ospf6_route_create ();
947
948 route->type = OSPF6_DEST_TYPE_NETWORK;
949 route->prefix.family = AF_INET6;
950 route->prefix.prefixlen = op->prefix_length;
951 memset (&route->prefix.u.prefix6, 0, sizeof (struct in6_addr));
952 memcpy (&route->prefix.u.prefix6, OSPF6_PREFIX_BODY (op),
953 OSPF6_PREFIX_SPACE (op->prefix_length));
954
955 route->path.origin.type = lsa->header->type;
956 route->path.origin.id = lsa->header->id;
957 route->path.origin.adv_router = lsa->header->adv_router;
958 route->path.options[0] = link_lsa->options[0];
959 route->path.options[1] = link_lsa->options[1];
960 route->path.options[2] = link_lsa->options[2];
961 route->path.prefix_options = op->prefix_options;
962 route->path.area_id = oi->area->area_id;
963 route->path.type = OSPF6_PATH_TYPE_INTRA;
964
965 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
paul718e3742002-12-13 20:15:29 +0000966 {
hasso508e53e2004-05-18 18:57:06 +0000967 prefix2str (&route->prefix, buf, sizeof (buf));
968 zlog_info (" include %s", buf);
paul718e3742002-12-13 20:15:29 +0000969 }
970
hasso508e53e2004-05-18 18:57:06 +0000971 ospf6_route_add (route, route_advertise);
972 prefix_num--;
paul718e3742002-12-13 20:15:29 +0000973 }
hasso508e53e2004-05-18 18:57:06 +0000974 if (current != end && IS_OSPF6_DEBUG_LSA (ORIGINATE))
975 zlog_info ("Trailing garbage in %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000976 }
977
hasso508e53e2004-05-18 18:57:06 +0000978 op = (struct ospf6_prefix *)
979 ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa));
980
981 prefix_num = 0;
982 for (route = ospf6_route_head (route_advertise); route;
983 route = ospf6_route_best_next (route))
paul718e3742002-12-13 20:15:29 +0000984 {
hasso508e53e2004-05-18 18:57:06 +0000985 op->prefix_length = route->prefix.prefixlen;
986 op->prefix_options = route->path.prefix_options;
987 op->prefix_metric = htons (0);
988 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
989 OSPF6_PREFIX_SPACE (op->prefix_length));
990 op = OSPF6_PREFIX_NEXT (op);
991 prefix_num++;
992 }
993
994 ospf6_route_table_delete (route_advertise);
995
996 if (prefix_num == 0)
997 {
998 if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
999 zlog_info ("Quit to Advertise Intra-Prefix: no route to advertise");
hasso6452df02004-08-15 05:52:07 +00001000 return 0;
paul718e3742002-12-13 20:15:29 +00001001 }
1002
hasso508e53e2004-05-18 18:57:06 +00001003 intra_prefix_lsa->prefix_num = htons (prefix_num);
paul718e3742002-12-13 20:15:29 +00001004
hasso508e53e2004-05-18 18:57:06 +00001005 /* Fill LSA Header */
1006 lsa_header->age = 0;
1007 lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
1008 lsa_header->id = htonl (oi->interface->ifindex);
1009 lsa_header->adv_router = oi->area->ospf6->router_id;
1010 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +00001011 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
1012 lsa_header->adv_router, oi->area->lsdb);
hasso508e53e2004-05-18 18:57:06 +00001013 lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header);
paul718e3742002-12-13 20:15:29 +00001014
hasso508e53e2004-05-18 18:57:06 +00001015 /* LSA checksum */
1016 ospf6_lsa_checksum (lsa_header);
paul718e3742002-12-13 20:15:29 +00001017
hasso508e53e2004-05-18 18:57:06 +00001018 /* create LSA */
1019 lsa = ospf6_lsa_create (lsa_header);
paul718e3742002-12-13 20:15:29 +00001020
hasso508e53e2004-05-18 18:57:06 +00001021 /* Originate */
hasso6452df02004-08-15 05:52:07 +00001022 ospf6_lsa_originate_area (lsa, oi->area);
paul718e3742002-12-13 20:15:29 +00001023
1024 return 0;
1025}
1026
1027void
hasso508e53e2004-05-18 18:57:06 +00001028ospf6_intra_prefix_lsa_add (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001029{
hasso508e53e2004-05-18 18:57:06 +00001030 struct ospf6_area *oa;
1031 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
1032 struct prefix ls_prefix;
1033 struct ospf6_route *route, *ls_entry;
1034 int i, prefix_num;
1035 struct ospf6_prefix *op;
1036 char *start, *current, *end;
1037 char buf[64];
paul718e3742002-12-13 20:15:29 +00001038
hasso508e53e2004-05-18 18:57:06 +00001039 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1040 zlog_info ("%s found", lsa->name);
paul718e3742002-12-13 20:15:29 +00001041
hasso6452df02004-08-15 05:52:07 +00001042 oa = OSPF6_AREA (lsa->lsdb->data);
1043
hasso508e53e2004-05-18 18:57:06 +00001044 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
1045 OSPF6_LSA_HEADER_END (lsa->header);
1046 if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_ROUTER))
1047 ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router,
1048 htonl (0), &ls_prefix);
1049 else if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_NETWORK))
1050 ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router,
1051 intra_prefix_lsa->ref_id, &ls_prefix);
1052 else
1053 {
1054 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1055 zlog_info ("Unknown reference LS-type: %#hx",
1056 ntohs (intra_prefix_lsa->ref_type));
1057 return;
1058 }
paul718e3742002-12-13 20:15:29 +00001059
hasso508e53e2004-05-18 18:57:06 +00001060 ls_entry = ospf6_route_lookup (&ls_prefix, oa->spf_table);
1061 if (ls_entry == NULL)
1062 {
1063 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1064 {
1065 ospf6_linkstate_prefix2str (&ls_prefix, buf, sizeof (buf));
1066 zlog_info ("LS entry does not exist: %s", buf);
1067 }
1068 return;
1069 }
paul718e3742002-12-13 20:15:29 +00001070
hasso508e53e2004-05-18 18:57:06 +00001071 prefix_num = ntohs (intra_prefix_lsa->prefix_num);
1072 start = (caddr_t) intra_prefix_lsa +
1073 sizeof (struct ospf6_intra_prefix_lsa);
1074 end = OSPF6_LSA_END (lsa->header);
1075 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op))
1076 {
1077 op = (struct ospf6_prefix *) current;
1078 if (prefix_num == 0)
1079 break;
1080 if (end < current + OSPF6_PREFIX_SIZE (op))
1081 break;
1082
1083 route = ospf6_route_create ();
1084 route->prefix.prefixlen = op->prefix_length;
1085 route->prefix.family = AF_INET6;
1086 memcpy (&route->prefix.u.prefix6, OSPF6_PREFIX_BODY (op),
1087 OSPF6_PREFIX_SPACE (op->prefix_length));
1088 route->type = OSPF6_DEST_TYPE_NETWORK;
1089 route->path.origin.type = lsa->header->type;
1090 route->path.origin.id = lsa->header->id;
1091 route->path.origin.adv_router = lsa->header->adv_router;
1092 route->path.prefix_options = op->prefix_options;
1093 route->path.area_id = oa->area_id;
1094 route->path.type = OSPF6_PATH_TYPE_INTRA;
1095 route->path.metric_type = 1;
1096 route->path.cost = ls_entry->path.cost +
1097 ntohs (op->prefix_metric);
1098
1099 for (i = 0; ospf6_nexthop_is_set (&ls_entry->nexthop[i]) &&
1100 i < OSPF6_MULTI_PATH_LIMIT; i++)
1101 ospf6_nexthop_copy (&route->nexthop[i], &ls_entry->nexthop[i]);
1102
1103 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1104 {
1105 prefix2str (&route->prefix, buf, sizeof (buf));
1106 zlog_info (" add %s", buf);
1107 }
1108
1109 ospf6_route_add (route, oa->route_table);
1110 prefix_num--;
1111 }
1112
1113 if (current != end && IS_OSPF6_DEBUG_ROUTE (INTRA))
1114 zlog_info ("Trailing garbage ignored");
paul718e3742002-12-13 20:15:29 +00001115}
1116
1117void
hasso508e53e2004-05-18 18:57:06 +00001118ospf6_intra_prefix_lsa_remove (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001119{
hasso508e53e2004-05-18 18:57:06 +00001120 struct ospf6_area *oa;
1121 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
1122 struct prefix prefix;
1123 struct ospf6_route *route;
1124 int prefix_num;
1125 struct ospf6_prefix *op;
1126 char *start, *current, *end;
1127 char buf[64];
1128
1129 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1130 zlog_info ("%s disappearing", lsa->name);
1131
hasso6452df02004-08-15 05:52:07 +00001132 oa = OSPF6_AREA (lsa->lsdb->data);
1133
hasso508e53e2004-05-18 18:57:06 +00001134 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
1135 OSPF6_LSA_HEADER_END (lsa->header);
1136
1137 prefix_num = ntohs (intra_prefix_lsa->prefix_num);
1138 start = (caddr_t) intra_prefix_lsa +
1139 sizeof (struct ospf6_intra_prefix_lsa);
1140 end = OSPF6_LSA_END (lsa->header);
1141 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op))
1142 {
1143 op = (struct ospf6_prefix *) current;
1144 if (prefix_num == 0)
1145 break;
1146 if (end < current + OSPF6_PREFIX_SIZE (op))
1147 break;
1148 prefix_num--;
1149
1150 prefix.family = AF_INET6;
1151 prefix.prefixlen = op->prefix_length;
1152 ospf6_prefix_in6_addr (&prefix.u.prefix6, op);
1153
1154 route = ospf6_route_lookup (&prefix, oa->route_table);
1155 if (route == NULL)
1156 continue;
1157
1158 for (ospf6_route_lock (route);
1159 route && ospf6_route_is_prefix (&prefix, route);
1160 route = ospf6_route_next (route))
1161 {
1162 if (route->type != OSPF6_DEST_TYPE_NETWORK)
1163 continue;
1164 if (route->path.area_id != oa->area_id)
1165 continue;
1166 if (route->path.type != OSPF6_PATH_TYPE_INTRA)
1167 continue;
1168 if (route->path.origin.type != lsa->header->type ||
1169 route->path.origin.id != lsa->header->id ||
1170 route->path.origin.adv_router != lsa->header->adv_router)
1171 continue;
1172
1173 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1174 {
1175 prefix2str (&route->prefix, buf, sizeof (buf));
1176 zlog_info ("remove %s", buf);
1177 }
1178 ospf6_route_remove (route, oa->route_table);
1179 }
1180 }
1181
1182 if (current != end && IS_OSPF6_DEBUG_ROUTE (INTRA))
1183 zlog_info ("Trailing garbage ignored");
paul718e3742002-12-13 20:15:29 +00001184}
1185
1186void
hasso508e53e2004-05-18 18:57:06 +00001187ospf6_intra_route_calculation (struct ospf6_area *oa)
paul718e3742002-12-13 20:15:29 +00001188{
hasso508e53e2004-05-18 18:57:06 +00001189 struct ospf6_route *route;
1190 u_int16_t type;
1191 struct ospf6_lsa *lsa;
1192 void (*hook_add) (struct ospf6_route *) = NULL;
1193 void (*hook_remove) (struct ospf6_route *) = NULL;
1194
1195 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1196 zlog_info ("Intra-area routing table calculation for area %s",
1197 oa->name);
1198
1199 hook_add = oa->route_table->hook_add;
1200 hook_remove = oa->route_table->hook_remove;
1201 oa->route_table->hook_add = NULL;
1202 oa->route_table->hook_remove = NULL;
1203
1204 for (route = ospf6_route_head (oa->route_table); route;
1205 route = ospf6_route_next (route))
1206 route->flag = OSPF6_ROUTE_REMOVE;
1207
1208 type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
1209 for (lsa = ospf6_lsdb_type_head (type, oa->lsdb); lsa;
1210 lsa = ospf6_lsdb_type_next (type, lsa))
1211 ospf6_intra_prefix_lsa_add (lsa);
1212
1213 oa->route_table->hook_add = hook_add;
1214 oa->route_table->hook_remove = hook_remove;
1215
1216 for (route = ospf6_route_head (oa->route_table); route;
1217 route = ospf6_route_next (route))
1218 {
1219 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE) &&
1220 CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD))
1221 {
1222 UNSET_FLAG (route->flag, OSPF6_ROUTE_REMOVE);
1223 UNSET_FLAG (route->flag, OSPF6_ROUTE_ADD);
1224 }
1225
1226 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
1227 ospf6_route_remove (route, oa->route_table);
1228 else if (CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD) ||
1229 CHECK_FLAG (route->flag, OSPF6_ROUTE_CHANGE))
1230 {
1231 if (hook_add)
1232 (*hook_add) (route);
1233 }
1234
1235 route->flag = 0;
1236 }
1237
1238 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1239 zlog_info ("Intra-area routing table calculation for area %s: Done",
1240 oa->name);
1241}
1242
1243void
hasso6452df02004-08-15 05:52:07 +00001244ospf6_intra_brouter_calculation (struct ospf6_area *oa)
hasso508e53e2004-05-18 18:57:06 +00001245{
1246 struct ospf6_route *lsentry, *copy;
1247 void (*hook_add) (struct ospf6_route *) = NULL;
1248 void (*hook_remove) (struct ospf6_route *) = NULL;
1249
hasso6452df02004-08-15 05:52:07 +00001250 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1251 zlog_info ("Border-router calculation for area %s", oa->name);
hasso508e53e2004-05-18 18:57:06 +00001252
hasso6452df02004-08-15 05:52:07 +00001253 hook_add = oa->ospf6->brouter_table->hook_add;
1254 hook_remove = oa->ospf6->brouter_table->hook_remove;
1255 oa->ospf6->brouter_table->hook_add = NULL;
1256 oa->ospf6->brouter_table->hook_remove = NULL;
hasso508e53e2004-05-18 18:57:06 +00001257
hasso6452df02004-08-15 05:52:07 +00001258 /* withdraw the previous router entries for the area */
1259 for (lsentry = ospf6_route_head (oa->ospf6->brouter_table); lsentry;
hasso508e53e2004-05-18 18:57:06 +00001260 lsentry = ospf6_route_next (lsentry))
1261 {
1262 if (lsentry->path.area_id != oa->area_id)
1263 continue;
1264 lsentry->flag = OSPF6_ROUTE_REMOVE;
1265 }
1266
1267 for (lsentry = ospf6_route_head (oa->spf_table); lsentry;
1268 lsentry = ospf6_route_next (lsentry))
1269 {
1270 if (lsentry->type != OSPF6_DEST_TYPE_LINKSTATE)
1271 continue;
1272 if (ospf6_linkstate_prefix_id (&lsentry->prefix) != htonl (0))
1273 continue;
hasso6452df02004-08-15 05:52:07 +00001274 if (! CHECK_FLAG (lsentry->path.router_bits, OSPF6_ROUTER_BIT_E) &&
1275 ! CHECK_FLAG (lsentry->path.router_bits, OSPF6_ROUTER_BIT_B))
hasso508e53e2004-05-18 18:57:06 +00001276 continue;
1277
1278 copy = ospf6_route_copy (lsentry);
1279 copy->type = OSPF6_DEST_TYPE_ROUTER;
1280 copy->prefix.family = AF_INET;
1281 copy->prefix.prefixlen = 32;
hasso6452df02004-08-15 05:52:07 +00001282 ospf6_route_add (copy, oa->ospf6->brouter_table);
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
1294 if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE) &&
1295 CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_ADD))
1296 {
1297 UNSET_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE);
1298 UNSET_FLAG (lsentry->flag, OSPF6_ROUTE_ADD);
1299 }
1300
1301 if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE))
hasso6452df02004-08-15 05:52:07 +00001302 ospf6_route_remove (lsentry, oa->ospf6->brouter_table);
hasso508e53e2004-05-18 18:57:06 +00001303 else if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_ADD) ||
1304 CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_CHANGE))
1305 {
1306 if (hook_add)
1307 (*hook_add) (lsentry);
1308 }
1309
1310 lsentry->flag = 0;
1311 }
1312
hasso6452df02004-08-15 05:52:07 +00001313 if (IS_OSPF6_DEBUG_ROUTE (INTRA))
1314 zlog_info ("Border-router calculation for area %s: Done", oa->name);
paul718e3742002-12-13 20:15:29 +00001315}
1316
hasso6452df02004-08-15 05:52:07 +00001317struct ospf6_lsa_handler router_handler =
1318{
1319 OSPF6_LSTYPE_ROUTER,
1320 "Router",
1321 ospf6_router_lsa_show
1322};
1323
1324struct ospf6_lsa_handler network_handler =
1325{
1326 OSPF6_LSTYPE_NETWORK,
1327 "Network",
1328 ospf6_network_lsa_show
1329};
1330
1331struct ospf6_lsa_handler link_handler =
1332{
1333 OSPF6_LSTYPE_LINK,
1334 "Link",
1335 ospf6_link_lsa_show
1336};
1337
1338struct ospf6_lsa_handler intra_prefix_handler =
1339{
1340 OSPF6_LSTYPE_INTRA_PREFIX,
1341 "Intra-Prefix",
1342 ospf6_intra_prefix_lsa_show
1343};
1344
paul718e3742002-12-13 20:15:29 +00001345void
1346ospf6_intra_init ()
1347{
hasso6452df02004-08-15 05:52:07 +00001348 ospf6_install_lsa_handler (&router_handler);
1349 ospf6_install_lsa_handler (&network_handler);
1350 ospf6_install_lsa_handler (&link_handler);
1351 ospf6_install_lsa_handler (&intra_prefix_handler);
paul718e3742002-12-13 20:15:29 +00001352}
1353
1354