blob: b13ae9b1fe2d6bcca9b229c10e6d19b1c017a0f7 [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
22#include <zebra.h>
23
24#include "memory.h"
25#include "log.h"
26#include "command.h"
hasso508e53e2004-05-18 18:57:06 +000027#include "prefix.h"
28#include "table.h"
hasso049207c2004-08-04 20:02:13 +000029#include "vty.h"
paul718e3742002-12-13 20:15:29 +000030
hasso508e53e2004-05-18 18:57:06 +000031#include "ospf6_proto.h"
32#include "ospf6_lsa.h"
paul718e3742002-12-13 20:15:29 +000033#include "ospf6_lsdb.h"
hasso049207c2004-08-04 20:02:13 +000034#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000035
paul718e3742002-12-13 20:15:29 +000036struct ospf6_lsdb *
hasso6452df02004-08-15 05:52:07 +000037ospf6_lsdb_create (void *data)
paul718e3742002-12-13 20:15:29 +000038{
39 struct ospf6_lsdb *lsdb;
40
41 lsdb = XCALLOC (MTYPE_OSPF6_LSDB, sizeof (struct ospf6_lsdb));
42 if (lsdb == NULL)
43 {
44 zlog_warn ("Can't malloc lsdb");
45 return NULL;
46 }
47 memset (lsdb, 0, sizeof (struct ospf6_lsdb));
48
hasso6452df02004-08-15 05:52:07 +000049 lsdb->data = data;
paul718e3742002-12-13 20:15:29 +000050 lsdb->table = route_table_init ();
51 return lsdb;
52}
53
54void
55ospf6_lsdb_delete (struct ospf6_lsdb *lsdb)
56{
Dinesh Dutta765eb92013-08-24 07:55:14 +000057 if (lsdb != NULL)
58 {
59 ospf6_lsdb_remove_all (lsdb);
60 route_table_finish (lsdb->table);
61 XFREE (MTYPE_OSPF6_LSDB, lsdb);
62 }
paul718e3742002-12-13 20:15:29 +000063}
64
65static void
hasso508e53e2004-05-18 18:57:06 +000066ospf6_lsdb_set_key (struct prefix_ipv6 *key, void *value, int len)
paul718e3742002-12-13 20:15:29 +000067{
hasso508e53e2004-05-18 18:57:06 +000068 assert (key->prefixlen % 8 == 0);
paul718e3742002-12-13 20:15:29 +000069
hasso508e53e2004-05-18 18:57:06 +000070 memcpy ((caddr_t) &key->prefix + key->prefixlen / 8,
71 (caddr_t) value, len);
paul718e3742002-12-13 20:15:29 +000072 key->family = AF_INET6;
hasso508e53e2004-05-18 18:57:06 +000073 key->prefixlen += len * 8;
paul718e3742002-12-13 20:15:29 +000074}
75
Dinesh Dutte39d0532013-08-24 07:55:36 +000076#ifdef DEBUG
hasso508e53e2004-05-18 18:57:06 +000077static void
78_lsdb_count_assert (struct ospf6_lsdb *lsdb)
79{
80 struct ospf6_lsa *debug;
paul0c083ee2004-10-10 12:54:58 +000081 unsigned int num = 0;
hasso508e53e2004-05-18 18:57:06 +000082 for (debug = ospf6_lsdb_head (lsdb); debug;
83 debug = ospf6_lsdb_next (debug))
84 num++;
85
86 if (num == lsdb->count)
87 return;
88
hassoc6487d62004-12-24 06:00:11 +000089 zlog_debug ("PANIC !! lsdb[%p]->count = %d, real = %d",
hasso3b687352004-08-19 06:56:53 +000090 lsdb, lsdb->count, num);
91 for (debug = ospf6_lsdb_head (lsdb); debug;
92 debug = ospf6_lsdb_next (debug))
hassoc6487d62004-12-24 06:00:11 +000093 zlog_debug ("%p %p %s lsdb[%p]", debug->prev, debug->next, debug->name,
hasso3b687352004-08-19 06:56:53 +000094 debug->lsdb);
hassoc6487d62004-12-24 06:00:11 +000095 zlog_debug ("DUMP END");
hasso3b687352004-08-19 06:56:53 +000096
hasso508e53e2004-05-18 18:57:06 +000097 assert (num == lsdb->count);
98}
99#define ospf6_lsdb_count_assert(t) (_lsdb_count_assert (t))
Dinesh Dutte39d0532013-08-24 07:55:36 +0000100#else /*DEBUG*/
hasso508e53e2004-05-18 18:57:06 +0000101#define ospf6_lsdb_count_assert(t) ((void) 0)
Dinesh Dutte39d0532013-08-24 07:55:36 +0000102#endif /*DEBUG*/
hasso508e53e2004-05-18 18:57:06 +0000103
paul718e3742002-12-13 20:15:29 +0000104void
105ospf6_lsdb_add (struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
106{
paul718e3742002-12-13 20:15:29 +0000107 struct prefix_ipv6 key;
Dinesh Dutta765eb92013-08-24 07:55:14 +0000108 struct route_node *current;
109 struct ospf6_lsa *old = NULL;
paul718e3742002-12-13 20:15:29 +0000110
hasso508e53e2004-05-18 18:57:06 +0000111 memset (&key, 0, sizeof (key));
112 ospf6_lsdb_set_key (&key, &lsa->header->type, sizeof (lsa->header->type));
113 ospf6_lsdb_set_key (&key, &lsa->header->adv_router,
114 sizeof (lsa->header->adv_router));
115 ospf6_lsdb_set_key (&key, &lsa->header->id, sizeof (lsa->header->id));
paul718e3742002-12-13 20:15:29 +0000116
hasso508e53e2004-05-18 18:57:06 +0000117 current = route_node_get (lsdb->table, (struct prefix *) &key);
118 old = current->info;
119 current->info = lsa;
Dinesh Dutta765eb92013-08-24 07:55:14 +0000120 lsa->rn = current;
paul718e3742002-12-13 20:15:29 +0000121 ospf6_lsa_lock (lsa);
122
Dinesh Dutta765eb92013-08-24 07:55:14 +0000123 if (!old)
hasso508e53e2004-05-18 18:57:06 +0000124 {
Dinesh Dutta765eb92013-08-24 07:55:14 +0000125 lsdb->count++;
126
127 if (OSPF6_LSA_IS_MAXAGE (lsa))
128 {
129 if (lsdb->hook_remove)
130 (*lsdb->hook_remove) (lsa);
131 }
132 else
133 {
134 if (lsdb->hook_add)
135 (*lsdb->hook_add) (lsa);
136 }
hasso508e53e2004-05-18 18:57:06 +0000137 }
paul718e3742002-12-13 20:15:29 +0000138 else
hasso508e53e2004-05-18 18:57:06 +0000139 {
hasso508e53e2004-05-18 18:57:06 +0000140 if (OSPF6_LSA_IS_CHANGED (old, lsa))
141 {
142 if (OSPF6_LSA_IS_MAXAGE (lsa))
143 {
144 if (lsdb->hook_remove)
145 {
146 (*lsdb->hook_remove) (old);
147 (*lsdb->hook_remove) (lsa);
148 }
149 }
hassoccb59b12004-08-25 09:10:37 +0000150 else if (OSPF6_LSA_IS_MAXAGE (old))
151 {
152 if (lsdb->hook_add)
153 (*lsdb->hook_add) (lsa);
154 }
hasso508e53e2004-05-18 18:57:06 +0000155 else
156 {
157 if (lsdb->hook_remove)
158 (*lsdb->hook_remove) (old);
159 if (lsdb->hook_add)
160 (*lsdb->hook_add) (lsa);
161 }
162 }
Dinesh Dutta765eb92013-08-24 07:55:14 +0000163 ospf6_lsa_unlock (old);
hasso508e53e2004-05-18 18:57:06 +0000164 }
hasso508e53e2004-05-18 18:57:06 +0000165
166 ospf6_lsdb_count_assert (lsdb);
paul718e3742002-12-13 20:15:29 +0000167}
168
169void
170ospf6_lsdb_remove (struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
171{
hasso508e53e2004-05-18 18:57:06 +0000172 struct route_node *node;
paul718e3742002-12-13 20:15:29 +0000173 struct prefix_ipv6 key;
paul718e3742002-12-13 20:15:29 +0000174
hasso508e53e2004-05-18 18:57:06 +0000175 memset (&key, 0, sizeof (key));
176 ospf6_lsdb_set_key (&key, &lsa->header->type, sizeof (lsa->header->type));
177 ospf6_lsdb_set_key (&key, &lsa->header->adv_router,
178 sizeof (lsa->header->adv_router));
179 ospf6_lsdb_set_key (&key, &lsa->header->id, sizeof (lsa->header->id));
paul718e3742002-12-13 20:15:29 +0000180
hasso508e53e2004-05-18 18:57:06 +0000181 node = route_node_lookup (lsdb->table, (struct prefix *) &key);
182 assert (node && node->info == lsa);
paul718e3742002-12-13 20:15:29 +0000183
hasso508e53e2004-05-18 18:57:06 +0000184 node->info = NULL;
paul718e3742002-12-13 20:15:29 +0000185 lsdb->count--;
paul718e3742002-12-13 20:15:29 +0000186
hasso508e53e2004-05-18 18:57:06 +0000187 if (lsdb->hook_remove)
188 (*lsdb->hook_remove) (lsa);
paul718e3742002-12-13 20:15:29 +0000189
Dinesh Dutta765eb92013-08-24 07:55:14 +0000190 route_unlock_node (node); /* to free the lookup lock */
191 route_unlock_node (node); /* to free the original lock */
hasso508e53e2004-05-18 18:57:06 +0000192 ospf6_lsa_unlock (lsa);
hasso6452df02004-08-15 05:52:07 +0000193
hasso508e53e2004-05-18 18:57:06 +0000194 ospf6_lsdb_count_assert (lsdb);
paul718e3742002-12-13 20:15:29 +0000195}
196
197struct ospf6_lsa *
198ospf6_lsdb_lookup (u_int16_t type, u_int32_t id, u_int32_t adv_router,
hasso508e53e2004-05-18 18:57:06 +0000199 struct ospf6_lsdb *lsdb)
paul718e3742002-12-13 20:15:29 +0000200{
hasso508e53e2004-05-18 18:57:06 +0000201 struct route_node *node;
202 struct prefix_ipv6 key;
paul718e3742002-12-13 20:15:29 +0000203
hasso508e53e2004-05-18 18:57:06 +0000204 if (lsdb == NULL)
205 return NULL;
paul718e3742002-12-13 20:15:29 +0000206
hasso508e53e2004-05-18 18:57:06 +0000207 memset (&key, 0, sizeof (key));
208 ospf6_lsdb_set_key (&key, &type, sizeof (type));
209 ospf6_lsdb_set_key (&key, &adv_router, sizeof (adv_router));
210 ospf6_lsdb_set_key (&key, &id, sizeof (id));
paul718e3742002-12-13 20:15:29 +0000211
hasso508e53e2004-05-18 18:57:06 +0000212 node = route_node_lookup (lsdb->table, (struct prefix *) &key);
213 if (node == NULL || node->info == NULL)
214 return NULL;
Dinesh Dutta765eb92013-08-24 07:55:14 +0000215
216 route_unlock_node (node);
hasso508e53e2004-05-18 18:57:06 +0000217 return (struct ospf6_lsa *) node->info;
paul718e3742002-12-13 20:15:29 +0000218}
219
hasso2680aa22004-11-25 20:54:46 +0000220struct ospf6_lsa *
221ospf6_lsdb_lookup_next (u_int16_t type, u_int32_t id, u_int32_t adv_router,
222 struct ospf6_lsdb *lsdb)
223{
224 struct route_node *node;
225 struct route_node *matched = NULL;
226 struct prefix_ipv6 key;
227 struct prefix *p;
228
229 if (lsdb == NULL)
230 return NULL;
231
232 memset (&key, 0, sizeof (key));
233 ospf6_lsdb_set_key (&key, &type, sizeof (type));
234 ospf6_lsdb_set_key (&key, &adv_router, sizeof (adv_router));
235 ospf6_lsdb_set_key (&key, &id, sizeof (id));
236 p = (struct prefix *) &key;
237
238 {
239 char buf[64];
240 prefix2str (p, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000241 zlog_debug ("lsdb_lookup_next: key: %s", buf);
hasso2680aa22004-11-25 20:54:46 +0000242 }
243
244 node = lsdb->table->top;
245 /* walk down tree. */
246 while (node && node->p.prefixlen <= p->prefixlen &&
247 prefix_match (&node->p, p))
248 {
249 matched = node;
Stephen Hemminger1352ef32009-12-09 14:43:17 +0300250 node = node->link[prefix_bit(&p->u.prefix, node->p.prefixlen)];
hasso2680aa22004-11-25 20:54:46 +0000251 }
252
253 if (matched)
254 node = matched;
255 else
256 node = lsdb->table->top;
257 route_lock_node (node);
258
259 /* skip to real existing entry */
260 while (node && node->info == NULL)
261 node = route_next (node);
262
263 if (! node)
264 return NULL;
265
266 if (prefix_same (&node->p, p))
267 {
hasso2680aa22004-11-25 20:54:46 +0000268 node = route_next (node);
269 while (node && node->info == NULL)
270 node = route_next (node);
hasso2680aa22004-11-25 20:54:46 +0000271 }
272
273 if (! node)
274 return NULL;
275
276 route_unlock_node (node);
277 return (struct ospf6_lsa *) node->info;
278}
279
hasso508e53e2004-05-18 18:57:06 +0000280/* Iteration function */
281struct ospf6_lsa *
282ospf6_lsdb_head (struct ospf6_lsdb *lsdb)
paul718e3742002-12-13 20:15:29 +0000283{
hasso508e53e2004-05-18 18:57:06 +0000284 struct route_node *node;
paul718e3742002-12-13 20:15:29 +0000285
hasso508e53e2004-05-18 18:57:06 +0000286 node = route_top (lsdb->table);
287 if (node == NULL)
288 return NULL;
paul718e3742002-12-13 20:15:29 +0000289
hasso508e53e2004-05-18 18:57:06 +0000290 /* skip to the existing lsdb entry */
291 while (node && node->info == NULL)
292 node = route_next (node);
293 if (node == NULL)
294 return NULL;
295
hasso508e53e2004-05-18 18:57:06 +0000296 if (node->info)
297 ospf6_lsa_lock ((struct ospf6_lsa *) node->info);
298 return (struct ospf6_lsa *) node->info;
299}
300
301struct ospf6_lsa *
302ospf6_lsdb_next (struct ospf6_lsa *lsa)
303{
Dinesh Dutta765eb92013-08-24 07:55:14 +0000304 struct route_node *node = lsa->rn;
305 struct ospf6_lsa *next = NULL;
306
307 do {
308 node = route_next (node);
309 } while (node && node->info == NULL);
310
311 if ((node != NULL) && (node->info != NULL))
312 {
313 next = node->info;
314 ospf6_lsa_lock (next);
315 }
hasso508e53e2004-05-18 18:57:06 +0000316
317 ospf6_lsa_unlock (lsa);
hasso508e53e2004-05-18 18:57:06 +0000318 return next;
319}
320
hasso508e53e2004-05-18 18:57:06 +0000321struct ospf6_lsa *
322ospf6_lsdb_type_router_head (u_int16_t type, u_int32_t adv_router,
323 struct ospf6_lsdb *lsdb)
324{
325 struct route_node *node;
326 struct prefix_ipv6 key;
327 struct ospf6_lsa *lsa;
328
329 memset (&key, 0, sizeof (key));
330 ospf6_lsdb_set_key (&key, &type, sizeof (type));
331 ospf6_lsdb_set_key (&key, &adv_router, sizeof (adv_router));
332
333 node = lsdb->table->top;
334
335 /* Walk down tree. */
336 while (node && node->p.prefixlen <= key.prefixlen &&
337 prefix_match (&node->p, (struct prefix *) &key))
Stephen Hemminger813f6a02009-12-10 16:13:09 +0300338 node = node->link[prefix6_bit(&key.prefix, node->p.prefixlen)];
hasso508e53e2004-05-18 18:57:06 +0000339
340 if (node)
341 route_lock_node (node);
342 while (node && node->info == NULL)
343 node = route_next (node);
344
345 if (node == NULL)
346 return NULL;
hasso508e53e2004-05-18 18:57:06 +0000347
348 if (! prefix_match ((struct prefix *) &key, &node->p))
349 return NULL;
350
351 lsa = node->info;
352 ospf6_lsa_lock (lsa);
353
354 return lsa;
355}
356
357struct ospf6_lsa *
358ospf6_lsdb_type_router_next (u_int16_t type, u_int32_t adv_router,
359 struct ospf6_lsa *lsa)
360{
Dinesh Dutta765eb92013-08-24 07:55:14 +0000361 struct ospf6_lsa *next = ospf6_lsdb_next(lsa);
hasso508e53e2004-05-18 18:57:06 +0000362
363 if (next)
paul718e3742002-12-13 20:15:29 +0000364 {
hasso508e53e2004-05-18 18:57:06 +0000365 if (next->header->type != type ||
366 next->header->adv_router != adv_router)
Dinesh Dutta765eb92013-08-24 07:55:14 +0000367 {
368 route_unlock_node (next->rn);
369 ospf6_lsa_unlock (next);
370 next = NULL;
371 }
paul718e3742002-12-13 20:15:29 +0000372 }
373
hasso508e53e2004-05-18 18:57:06 +0000374 return next;
375}
paul718e3742002-12-13 20:15:29 +0000376
hasso508e53e2004-05-18 18:57:06 +0000377struct ospf6_lsa *
378ospf6_lsdb_type_head (u_int16_t type, struct ospf6_lsdb *lsdb)
379{
380 struct route_node *node;
381 struct prefix_ipv6 key;
382 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000383
hasso508e53e2004-05-18 18:57:06 +0000384 memset (&key, 0, sizeof (key));
385 ospf6_lsdb_set_key (&key, &type, sizeof (type));
paul718e3742002-12-13 20:15:29 +0000386
hasso508e53e2004-05-18 18:57:06 +0000387 /* Walk down tree. */
388 node = lsdb->table->top;
389 while (node && node->p.prefixlen <= key.prefixlen &&
390 prefix_match (&node->p, (struct prefix *) &key))
Stephen Hemminger813f6a02009-12-10 16:13:09 +0300391 node = node->link[prefix6_bit(&key.prefix, node->p.prefixlen)];
paul718e3742002-12-13 20:15:29 +0000392
hasso508e53e2004-05-18 18:57:06 +0000393 if (node)
394 route_lock_node (node);
395 while (node && node->info == NULL)
396 node = route_next (node);
paul718e3742002-12-13 20:15:29 +0000397
hasso508e53e2004-05-18 18:57:06 +0000398 if (node == NULL)
399 return NULL;
paul718e3742002-12-13 20:15:29 +0000400
hasso508e53e2004-05-18 18:57:06 +0000401 if (! prefix_match ((struct prefix *) &key, &node->p))
402 return NULL;
403
404 lsa = node->info;
405 ospf6_lsa_lock (lsa);
406
407 return lsa;
408}
409
410struct ospf6_lsa *
411ospf6_lsdb_type_next (u_int16_t type, struct ospf6_lsa *lsa)
412{
Dinesh Dutta765eb92013-08-24 07:55:14 +0000413 struct ospf6_lsa *next = ospf6_lsdb_next (lsa);
hasso508e53e2004-05-18 18:57:06 +0000414
415 if (next)
416 {
417 if (next->header->type != type)
Dinesh Dutta765eb92013-08-24 07:55:14 +0000418 {
419 route_unlock_node (next->rn);
420 ospf6_lsa_unlock (next);
421 next = NULL;
422 }
hasso508e53e2004-05-18 18:57:06 +0000423 }
424
hasso508e53e2004-05-18 18:57:06 +0000425 return next;
paul718e3742002-12-13 20:15:29 +0000426}
427
428void
429ospf6_lsdb_remove_all (struct ospf6_lsdb *lsdb)
430{
paul718e3742002-12-13 20:15:29 +0000431 struct ospf6_lsa *lsa;
Dinesh Dutta765eb92013-08-24 07:55:14 +0000432
433 if (lsdb == NULL)
434 return;
435
hasso508e53e2004-05-18 18:57:06 +0000436 for (lsa = ospf6_lsdb_head (lsdb); lsa; lsa = ospf6_lsdb_next (lsa))
437 ospf6_lsdb_remove (lsa, lsdb);
paul718e3742002-12-13 20:15:29 +0000438}
439
Dinesh Dutta765eb92013-08-24 07:55:14 +0000440void
441ospf6_lsdb_lsa_unlock (struct ospf6_lsa *lsa)
442{
443 if (lsa != NULL)
444 {
445 if (lsa->rn != NULL)
446 route_unlock_node (lsa->rn);
447 ospf6_lsa_unlock (lsa);
448 }
449}
450
Dinesh Dutt2449fcd2013-08-24 07:54:17 +0000451int
452ospf6_lsdb_maxage_remover (struct ospf6_lsdb *lsdb)
453{
454 int reschedule = 0;
455 struct ospf6_lsa *lsa;
456
457 for (lsa = ospf6_lsdb_head (lsdb); lsa; lsa = ospf6_lsdb_next (lsa))
458 {
459 if (! OSPF6_LSA_IS_MAXAGE (lsa))
460 continue;
461 if (lsa->retrans_count != 0)
462 {
463 reschedule = 1;
464 continue;
465 }
466 if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
467 zlog_debug ("Remove MaxAge %s", lsa->name);
468 ospf6_lsdb_remove (lsa, lsdb);
469 }
470
471 return (reschedule);
472}
473
hasso049207c2004-08-04 20:02:13 +0000474void
475ospf6_lsdb_show (struct vty *vty, int level,
476 u_int16_t *type, u_int32_t *id, u_int32_t *adv_router,
477 struct ospf6_lsdb *lsdb)
478{
479 struct ospf6_lsa *lsa;
480 void (*showfunc) (struct vty *, struct ospf6_lsa *) = NULL;
481
482 if (level == OSPF6_LSDB_SHOW_LEVEL_NORMAL)
483 showfunc = ospf6_lsa_show_summary;
484 else if (level == OSPF6_LSDB_SHOW_LEVEL_DETAIL)
485 showfunc = ospf6_lsa_show;
486 else if (level == OSPF6_LSDB_SHOW_LEVEL_INTERNAL)
487 showfunc = ospf6_lsa_show_internal;
488 else if (level == OSPF6_LSDB_SHOW_LEVEL_DUMP)
489 showfunc = ospf6_lsa_show_dump;
490
491 if (type && id && adv_router)
492 {
493 lsa = ospf6_lsdb_lookup (*type, *id, *adv_router, lsdb);
494 if (lsa)
495 {
496 if (level == OSPF6_LSDB_SHOW_LEVEL_NORMAL)
497 ospf6_lsa_show (vty, lsa);
498 else
499 (*showfunc) (vty, lsa);
500 }
501 return;
502 }
503
504 if (level == OSPF6_LSDB_SHOW_LEVEL_NORMAL)
505 ospf6_lsa_show_summary_header (vty);
506
507 if (type && adv_router)
508 lsa = ospf6_lsdb_type_router_head (*type, *adv_router, lsdb);
509 else if (type)
510 lsa = ospf6_lsdb_type_head (*type, lsdb);
511 else
512 lsa = ospf6_lsdb_head (lsdb);
513 while (lsa)
514 {
515 if ((! adv_router || lsa->header->adv_router == *adv_router) &&
516 (! id || lsa->header->id == *id))
517 (*showfunc) (vty, lsa);
518
519 if (type && adv_router)
520 lsa = ospf6_lsdb_type_router_next (*type, *adv_router, lsa);
521 else if (type)
522 lsa = ospf6_lsdb_type_next (*type, lsa);
523 else
524 lsa = ospf6_lsdb_next (lsa);
525 }
526}
527
528/* Decide new Link State ID to originate.
529 note return value is network byte order */
530u_int32_t
531ospf6_new_ls_id (u_int16_t type, u_int32_t adv_router,
532 struct ospf6_lsdb *lsdb)
533{
534 struct ospf6_lsa *lsa;
535 u_int32_t id = 1;
536
537 for (lsa = ospf6_lsdb_type_router_head (type, adv_router, lsdb); lsa;
538 lsa = ospf6_lsdb_type_router_next (type, adv_router, lsa))
539 {
540 if (ntohl (lsa->header->id) < id)
541 continue;
542 if (ntohl (lsa->header->id) > id)
Tom Goff16c1c482009-12-01 21:12:38 +0300543 {
Dinesh Dutta765eb92013-08-24 07:55:14 +0000544 ospf6_lsdb_lsa_unlock (lsa);
hasso6452df02004-08-15 05:52:07 +0000545 break;
Tom Goff16c1c482009-12-01 21:12:38 +0300546 }
hasso049207c2004-08-04 20:02:13 +0000547 id++;
548 }
549
550 return ((u_int32_t) htonl (id));
551}
552
553/* Decide new LS sequence number to originate.
554 note return value is network byte order */
555u_int32_t
556ospf6_new_ls_seqnum (u_int16_t type, u_int32_t id, u_int32_t adv_router,
557 struct ospf6_lsdb *lsdb)
558{
559 struct ospf6_lsa *lsa;
560 signed long seqnum = 0;
561
562 /* if current database copy not found, return InitialSequenceNumber */
563 lsa = ospf6_lsdb_lookup (type, id, adv_router, lsdb);
564 if (lsa == NULL)
Dinesh Dutt8551e6d2013-10-22 17:42:18 -0700565 seqnum = OSPF_INITIAL_SEQUENCE_NUMBER;
hasso049207c2004-08-04 20:02:13 +0000566 else
567 seqnum = (signed long) ntohl (lsa->header->seqnum) + 1;
568
569 return ((u_int32_t) htonl (seqnum));
570}
571
paul718e3742002-12-13 20:15:29 +0000572