blob: 1dc0c7b37b14fc9aa4fc24e01b87a1761ff0db0a [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
paul718e3742002-12-13 20:15:29 +000022#include <zebra.h>
23
24#include "log.h"
hasso508e53e2004-05-18 18:57:06 +000025#include "memory.h"
paul718e3742002-12-13 20:15:29 +000026#include "thread.h"
27#include "linklist.h"
28#include "vty.h"
29#include "command.h"
30
hasso508e53e2004-05-18 18:57:06 +000031#include "ospf6d.h"
32#include "ospf6_proto.h"
paul718e3742002-12-13 20:15:29 +000033#include "ospf6_lsa.h"
34#include "ospf6_lsdb.h"
hasso508e53e2004-05-18 18:57:06 +000035#include "ospf6_message.h"
36#include "ospf6_top.h"
37#include "ospf6_area.h"
38#include "ospf6_interface.h"
39#include "ospf6_neighbor.h"
40#include "ospf6_intra.h"
hasso3b4cd3a2004-05-18 19:28:32 +000041#include "ospf6_flood.h"
paul718e3742002-12-13 20:15:29 +000042
hasso508e53e2004-05-18 18:57:06 +000043unsigned char conf_debug_ospf6_neighbor = 0;
44
45char *ospf6_neighbor_state_str[] =
46{ "None", "Down", "Attempt", "Init", "Twoway", "ExStart", "ExChange",
47 "Loading", "Full", NULL };
paul718e3742002-12-13 20:15:29 +000048
49int
hasso508e53e2004-05-18 18:57:06 +000050ospf6_neighbor_cmp (void *va, void *vb)
paul718e3742002-12-13 20:15:29 +000051{
hasso508e53e2004-05-18 18:57:06 +000052 struct ospf6_neighbor *ona = (struct ospf6_neighbor *) va;
53 struct ospf6_neighbor *onb = (struct ospf6_neighbor *) vb;
54 return (ntohl (ona->router_id) - ntohl (onb->router_id));
paul718e3742002-12-13 20:15:29 +000055}
56
hasso508e53e2004-05-18 18:57:06 +000057struct ospf6_neighbor *
58ospf6_neighbor_lookup (u_int32_t router_id,
59 struct ospf6_interface *oi)
paul718e3742002-12-13 20:15:29 +000060{
hasso508e53e2004-05-18 18:57:06 +000061 listnode n;
62 struct ospf6_neighbor *on;
paul718e3742002-12-13 20:15:29 +000063
hasso508e53e2004-05-18 18:57:06 +000064 for (n = listhead (oi->neighbor_list); n; nextnode (n))
paul718e3742002-12-13 20:15:29 +000065 {
hasso508e53e2004-05-18 18:57:06 +000066 on = (struct ospf6_neighbor *) getdata (n);
67 if (on->router_id == router_id)
68 return on;
paul718e3742002-12-13 20:15:29 +000069 }
hasso508e53e2004-05-18 18:57:06 +000070 return (struct ospf6_neighbor *) NULL;
paul718e3742002-12-13 20:15:29 +000071}
72
73/* create ospf6_neighbor */
74struct ospf6_neighbor *
hasso508e53e2004-05-18 18:57:06 +000075ospf6_neighbor_create (u_int32_t router_id, struct ospf6_interface *oi)
paul718e3742002-12-13 20:15:29 +000076{
hasso508e53e2004-05-18 18:57:06 +000077 struct ospf6_neighbor *on;
78 char buf[16];
paul718e3742002-12-13 20:15:29 +000079
hasso508e53e2004-05-18 18:57:06 +000080 on = (struct ospf6_neighbor *)
paul718e3742002-12-13 20:15:29 +000081 XMALLOC (MTYPE_OSPF6_NEIGHBOR, sizeof (struct ospf6_neighbor));
hasso508e53e2004-05-18 18:57:06 +000082 if (on == NULL)
paul718e3742002-12-13 20:15:29 +000083 {
84 zlog_warn ("neighbor: malloc failed");
85 return NULL;
86 }
87
hasso508e53e2004-05-18 18:57:06 +000088 memset (on, 0, sizeof (struct ospf6_neighbor));
paul718e3742002-12-13 20:15:29 +000089 inet_ntop (AF_INET, &router_id, buf, sizeof (buf));
hasso508e53e2004-05-18 18:57:06 +000090 snprintf (on->name, sizeof (on->name), "%s%%%s",
91 buf, oi->interface->name);
92 on->ospf6_if = oi;
93 on->state = OSPF6_NEIGHBOR_DOWN;
94 gettimeofday (&on->last_changed, (struct timezone *) NULL);
95 on->router_id = router_id;
paul718e3742002-12-13 20:15:29 +000096
hasso508e53e2004-05-18 18:57:06 +000097 on->summary_list = ospf6_lsdb_create ();
98 on->request_list = ospf6_lsdb_create ();
99 on->retrans_list = ospf6_lsdb_create ();
paul718e3742002-12-13 20:15:29 +0000100
hasso508e53e2004-05-18 18:57:06 +0000101 on->dbdesc_list = ospf6_lsdb_create ();
102 on->lsreq_list = ospf6_lsdb_create ();
103 on->lsupdate_list = ospf6_lsdb_create ();
104 on->lsack_list = ospf6_lsdb_create ();
paul718e3742002-12-13 20:15:29 +0000105
hasso508e53e2004-05-18 18:57:06 +0000106 listnode_add_sort (oi->neighbor_list, on);
107 return on;
paul718e3742002-12-13 20:15:29 +0000108}
109
110void
hasso508e53e2004-05-18 18:57:06 +0000111ospf6_neighbor_delete (struct ospf6_neighbor *on)
paul718e3742002-12-13 20:15:29 +0000112{
hasso3b4cd3a2004-05-18 19:28:32 +0000113 struct ospf6_lsa *lsa;
114
hasso508e53e2004-05-18 18:57:06 +0000115 ospf6_lsdb_remove_all (on->summary_list);
116 ospf6_lsdb_remove_all (on->request_list);
hasso3b4cd3a2004-05-18 19:28:32 +0000117 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
118 lsa = ospf6_lsdb_next (lsa))
119 {
120 ospf6_decrement_onretrans (lsa);
121 ospf6_lsdb_remove (lsa, on->retrans_list);
122 }
paul718e3742002-12-13 20:15:29 +0000123
hasso508e53e2004-05-18 18:57:06 +0000124 ospf6_lsdb_remove_all (on->dbdesc_list);
125 ospf6_lsdb_remove_all (on->lsreq_list);
126 ospf6_lsdb_remove_all (on->lsupdate_list);
127 ospf6_lsdb_remove_all (on->lsack_list);
paul718e3742002-12-13 20:15:29 +0000128
hasso508e53e2004-05-18 18:57:06 +0000129 ospf6_lsdb_delete (on->summary_list);
130 ospf6_lsdb_delete (on->request_list);
131 ospf6_lsdb_delete (on->retrans_list);
paul718e3742002-12-13 20:15:29 +0000132
hasso508e53e2004-05-18 18:57:06 +0000133 ospf6_lsdb_delete (on->dbdesc_list);
134 ospf6_lsdb_delete (on->lsreq_list);
135 ospf6_lsdb_delete (on->lsupdate_list);
136 ospf6_lsdb_delete (on->lsack_list);
paul718e3742002-12-13 20:15:29 +0000137
hasso508e53e2004-05-18 18:57:06 +0000138 THREAD_OFF (on->inactivity_timer);
139
140 THREAD_OFF (on->thread_send_dbdesc);
141 THREAD_OFF (on->thread_send_lsreq);
142 THREAD_OFF (on->thread_send_lsupdate);
143 THREAD_OFF (on->thread_send_lsack);
144
145 XFREE (MTYPE_OSPF6_NEIGHBOR, on);
paul718e3742002-12-13 20:15:29 +0000146}
147
hasso508e53e2004-05-18 18:57:06 +0000148static void
149ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on)
paul718e3742002-12-13 20:15:29 +0000150{
hasso508e53e2004-05-18 18:57:06 +0000151 u_char prev_state;
paul718e3742002-12-13 20:15:29 +0000152
hasso508e53e2004-05-18 18:57:06 +0000153 prev_state = on->state;
154 on->state = next_state;
155
156 if (prev_state == next_state)
157 return;
158
159 gettimeofday (&on->last_changed, (struct timezone *) NULL);
160
161 /* log */
162 if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
paul718e3742002-12-13 20:15:29 +0000163 {
hasso508e53e2004-05-18 18:57:06 +0000164 zlog_info ("Neighbor state change %s: [%s]->[%s]", on->name,
165 ospf6_neighbor_state_str[prev_state],
166 ospf6_neighbor_state_str[next_state]);
paul718e3742002-12-13 20:15:29 +0000167 }
hasso508e53e2004-05-18 18:57:06 +0000168
169 if (prev_state == OSPF6_NEIGHBOR_FULL || next_state == OSPF6_NEIGHBOR_FULL)
170 {
171 OSPF6_ROUTER_LSA_SCHEDULE (on->ospf6_if->area);
172 if (on->ospf6_if->state == OSPF6_INTERFACE_DR)
173 {
174 OSPF6_NETWORK_LSA_SCHEDULE (on->ospf6_if);
175 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (on->ospf6_if);
176 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (on->ospf6_if->area);
177 }
178 }
179
180#ifdef XXX
181 if (prev_state == NBS_FULL || next_state == NBS_FULL)
182 nbs_full_change (on->ospf6_interface);
183
184 /* check for LSAs that already reached MaxAge */
185 if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE ||
186 prev_state == OSPF6_NEIGHBOR_LOADING) &&
187 (next_state != OSPF6_NEIGHBOR_EXCHANGE &&
188 next_state != OSPF6_NEIGHBOR_LOADING))
189 {
190 ospf6_maxage_remover ();
191 }
192#endif /*XXX*/
193
paul718e3742002-12-13 20:15:29 +0000194}
195
hasso508e53e2004-05-18 18:57:06 +0000196/* RFC2328 section 10.4 */
197int
198need_adjacency (struct ospf6_neighbor *on)
199{
200 if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT ||
201 on->ospf6_if->state == OSPF6_INTERFACE_DR ||
202 on->ospf6_if->state == OSPF6_INTERFACE_BDR)
203 return 1;
204
205 if (on->ospf6_if->drouter == on->router_id ||
206 on->ospf6_if->bdrouter == on->router_id)
207 return 1;
208
209 return 0;
210}
211
212int
213hello_received (struct thread *thread)
214{
215 struct ospf6_neighbor *on;
216
217 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
218 assert (on);
219
220 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
221 zlog_info ("Neighbor Event %s: *HelloReceived*", on->name);
222
223 /* reset Inactivity Timer */
224 THREAD_OFF (on->inactivity_timer);
225 on->inactivity_timer = thread_add_timer (master, inactivity_timer, on,
226 on->ospf6_if->dead_interval);
227
228 if (on->state <= OSPF6_NEIGHBOR_DOWN)
229 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on);
230
231 return 0;
232}
233
234int
235twoway_received (struct thread *thread)
236{
237 struct ospf6_neighbor *on;
238
239 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
240 assert (on);
241
242 if (on->state > OSPF6_NEIGHBOR_INIT)
243 return 0;
244
245 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
246 zlog_info ("Neighbor Event %s: *2Way-Received*", on->name);
247
248 thread_add_event (master, neighbor_change, on->ospf6_if, 0);
249
250 if (! need_adjacency (on))
251 {
252 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on);
253 return 0;
254 }
255
256 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
257 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
258 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
259 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
260
261 THREAD_OFF (on->thread_send_dbdesc);
262 on->thread_send_dbdesc =
263 thread_add_event (master, ospf6_dbdesc_send, on, 0);
264
265 return 0;
266}
267
268int
269negotiation_done (struct thread *thread)
270{
271 struct ospf6_neighbor *on;
272 struct ospf6_lsa *lsa;
273
274 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
275 assert (on);
276
277 if (on->state != OSPF6_NEIGHBOR_EXSTART)
278 return 0;
279
280 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
281 zlog_info ("Neighbor Event %s: *NegotiationDone*", on->name);
282
283 /* clear ls-list */
284 ospf6_lsdb_remove_all (on->summary_list);
285 ospf6_lsdb_remove_all (on->request_list);
hasso3b4cd3a2004-05-18 19:28:32 +0000286 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
287 lsa = ospf6_lsdb_next (lsa))
288 {
289 ospf6_decrement_onretrans (lsa);
290 ospf6_lsdb_remove (lsa, on->retrans_list);
291 }
hasso508e53e2004-05-18 18:57:06 +0000292
293 /* Interface scoped LSAs */
294 for (lsa = ospf6_lsdb_head (on->ospf6_if->lsdb); lsa;
295 lsa = ospf6_lsdb_next (lsa))
296 {
297 if (IS_OSPF6_DEBUG_LSA (DATABASE))
298 zlog_info ("Add copy of %s to %s of %s", lsa->name,
299 (OSPF6_LSA_IS_MAXAGE (lsa) ? "retrans_list" :
300 "summary_list"), on->name);
301 if (OSPF6_LSA_IS_MAXAGE (lsa))
hasso3b4cd3a2004-05-18 19:28:32 +0000302 {
303 lsa->onretrans++;
304 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
305 }
hasso508e53e2004-05-18 18:57:06 +0000306 else
307 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
308 }
309
310 /* Area scoped LSAs */
311 for (lsa = ospf6_lsdb_head (on->ospf6_if->area->lsdb); lsa;
312 lsa = ospf6_lsdb_next (lsa))
313 {
314 if (IS_OSPF6_DEBUG_LSA (DATABASE))
315 zlog_info ("Add copy of %s to %s of %s", lsa->name,
316 (OSPF6_LSA_IS_MAXAGE (lsa) ? "retrans_list" :
317 "summary_list"), on->name);
318 if (OSPF6_LSA_IS_MAXAGE (lsa))
hasso3b4cd3a2004-05-18 19:28:32 +0000319 {
320 lsa->onretrans++;
321 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
322 }
hasso508e53e2004-05-18 18:57:06 +0000323 else
324 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
325 }
326
327 /* AS scoped LSAs */
328 for (lsa = ospf6_lsdb_head (on->ospf6_if->area->ospf6->lsdb); lsa;
329 lsa = ospf6_lsdb_next (lsa))
330 {
331 if (IS_OSPF6_DEBUG_LSA (DATABASE))
332 zlog_info ("Add copy of %s to %s of %s", lsa->name,
333 (OSPF6_LSA_IS_MAXAGE (lsa) ? "retrans_list" :
334 "summary_list"), on->name);
335 if (OSPF6_LSA_IS_MAXAGE (lsa))
hasso3b4cd3a2004-05-18 19:28:32 +0000336 {
337 lsa->onretrans++;
338 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
339 }
hasso508e53e2004-05-18 18:57:06 +0000340 else
341 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
342 }
343
344 UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
345 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXCHANGE, on);
346
347 return 0;
348}
349
350int
351exchange_done (struct thread *thread)
352{
353 struct ospf6_neighbor *on;
354
355 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
356 assert (on);
357
358 if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
359 return 0;
360
361 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
362 zlog_info ("Neighbor Event %s: *ExchangeDone*", on->name);
363
364 THREAD_OFF (on->thread_send_dbdesc);
365 ospf6_lsdb_remove_all (on->dbdesc_list);
366
367/* XXX
368 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
369 on->ospf6_if->dead_interval);
370*/
371
372 if (on->request_list->count == 0)
373 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on);
374 else
375 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_LOADING, on);
376
377 return 0;
378}
379
380int
381loading_done (struct thread *thread)
382{
383 struct ospf6_neighbor *on;
384
385 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
386 assert (on);
387
388 if (on->state != OSPF6_NEIGHBOR_LOADING)
389 return 0;
390
391 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
392 zlog_info ("Neighbor Event %s: *LoadingDone*", on->name);
393
394 assert (on->request_list->count == 0);
395
396 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on);
397
398 return 0;
399}
400
401int
402adj_ok (struct thread *thread)
403{
404 struct ospf6_neighbor *on;
hasso3b4cd3a2004-05-18 19:28:32 +0000405 struct ospf6_lsa *lsa;
hasso508e53e2004-05-18 18:57:06 +0000406
407 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
408 assert (on);
409
410 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
411 zlog_info ("Neighbor Event %s: *AdjOK?*", on->name);
412
413 if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency (on))
414 {
415 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
416 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
417 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
418 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
419
420 THREAD_OFF (on->thread_send_dbdesc);
421 on->thread_send_dbdesc =
422 thread_add_event (master, ospf6_dbdesc_send, on, 0);
423
424 }
425 else if (on->state >= OSPF6_NEIGHBOR_EXSTART &&
426 ! need_adjacency (on))
427 {
428 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on);
429 ospf6_lsdb_remove_all (on->summary_list);
430 ospf6_lsdb_remove_all (on->request_list);
hasso3b4cd3a2004-05-18 19:28:32 +0000431 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
432 lsa = ospf6_lsdb_next (lsa))
433 {
434 ospf6_decrement_onretrans (lsa);
435 ospf6_lsdb_remove (lsa, on->retrans_list);
436 }
hasso508e53e2004-05-18 18:57:06 +0000437 }
438
439 return 0;
440}
441
442int
443seqnumber_mismatch (struct thread *thread)
444{
445 struct ospf6_neighbor *on;
hasso3b4cd3a2004-05-18 19:28:32 +0000446 struct ospf6_lsa *lsa;
hasso508e53e2004-05-18 18:57:06 +0000447
448 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
449 assert (on);
450
451 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
452 return 0;
453
454 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
455 zlog_info ("Neighbor Event %s: *SeqNumberMismatch*", on->name);
456
457 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
458 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
459 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
460 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
461
462 ospf6_lsdb_remove_all (on->summary_list);
463 ospf6_lsdb_remove_all (on->request_list);
hasso3b4cd3a2004-05-18 19:28:32 +0000464 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
465 lsa = ospf6_lsdb_next (lsa))
466 {
467 ospf6_decrement_onretrans (lsa);
468 ospf6_lsdb_remove (lsa, on->retrans_list);
469 }
hasso508e53e2004-05-18 18:57:06 +0000470
471 THREAD_OFF (on->thread_send_dbdesc);
472 on->thread_send_dbdesc =
473 thread_add_event (master, ospf6_dbdesc_send, on, 0);
474
475 return 0;
476}
477
478int
479bad_lsreq (struct thread *thread)
480{
481 struct ospf6_neighbor *on;
hasso3b4cd3a2004-05-18 19:28:32 +0000482 struct ospf6_lsa *lsa;
hasso508e53e2004-05-18 18:57:06 +0000483
484 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
485 assert (on);
486
487 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
488 return 0;
489
490 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
491 zlog_info ("Neighbor Event %s: *BadLSReq*", on->name);
492
493 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
494 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
495 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
496 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
497
498 ospf6_lsdb_remove_all (on->summary_list);
499 ospf6_lsdb_remove_all (on->request_list);
hasso3b4cd3a2004-05-18 19:28:32 +0000500 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
501 lsa = ospf6_lsdb_next (lsa))
502 {
503 ospf6_decrement_onretrans (lsa);
504 ospf6_lsdb_remove (lsa, on->retrans_list);
505 }
hasso508e53e2004-05-18 18:57:06 +0000506
507 THREAD_OFF (on->thread_send_dbdesc);
508 on->thread_send_dbdesc =
509 thread_add_event (master, ospf6_dbdesc_send, on, 0);
510
511 return 0;
512}
513
514int
515oneway_received (struct thread *thread)
516{
517 struct ospf6_neighbor *on;
hasso3b4cd3a2004-05-18 19:28:32 +0000518 struct ospf6_lsa *lsa;
hasso508e53e2004-05-18 18:57:06 +0000519
520 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
521 assert (on);
522
523 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
524 return 0;
525
526 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
527 zlog_info ("Neighbor Event %s: *1Way-Received*", on->name);
528
529 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on);
530 thread_add_event (master, neighbor_change, on->ospf6_if, 0);
531
532 ospf6_lsdb_remove_all (on->summary_list);
533 ospf6_lsdb_remove_all (on->request_list);
hasso3b4cd3a2004-05-18 19:28:32 +0000534 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
535 lsa = ospf6_lsdb_next (lsa))
536 {
537 ospf6_decrement_onretrans (lsa);
538 ospf6_lsdb_remove (lsa, on->retrans_list);
539 }
hasso508e53e2004-05-18 18:57:06 +0000540
541 THREAD_OFF (on->thread_send_dbdesc);
542 THREAD_OFF (on->thread_send_lsreq);
543 THREAD_OFF (on->thread_send_lsupdate);
544 THREAD_OFF (on->thread_send_lsack);
545
546 return 0;
547}
548
549int
550inactivity_timer (struct thread *thread)
551{
552 struct ospf6_neighbor *on;
553
554 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
555 assert (on);
556
557 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
558 zlog_info ("Neighbor Event %s: *InactivityTimer*", on->name);
559
560 on->inactivity_timer = NULL;
561 on->drouter = on->prev_drouter = 0;
562 on->bdrouter = on->prev_bdrouter = 0;
563
564 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_DOWN, on);
565 thread_add_event (master, neighbor_change, on->ospf6_if, 0);
566
567 listnode_delete (on->ospf6_if->neighbor_list, on);
568 ospf6_neighbor_delete (on);
569
570 return 0;
571}
572
573
paul718e3742002-12-13 20:15:29 +0000574
575/* vty functions */
576/* show neighbor structure */
577void
hasso508e53e2004-05-18 18:57:06 +0000578ospf6_neighbor_show (struct vty *vty, struct ospf6_neighbor *on)
paul718e3742002-12-13 20:15:29 +0000579{
580 char router_id[16];
hasso508e53e2004-05-18 18:57:06 +0000581 char duration[16];
582 struct timeval now, res;
583 char nstate[16];
584 char deadtime[16];
585 long h, m, s;
586
587 /* Router-ID (Name) */
588 inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
589#ifdef HAVE_GETNAMEINFO
590 {
591 }
592#endif /*HAVE_GETNAMEINFO*/
593
594 gettimeofday (&now, NULL);
595
596 /* Dead time */
597 h = m = s = 0;
598 if (on->inactivity_timer)
599 {
600 s = on->inactivity_timer->u.sands.tv_sec - now.tv_sec;
601 h = s / 3600;
602 s -= h * 3600;
603 m = s / 60;
604 s -= m * 60;
605 }
606 snprintf (deadtime, sizeof (deadtime), "%02ld:%02ld:%02ld", h, m, s);
607
608 /* Neighbor State */
609 if (if_is_pointopoint (on->ospf6_if->interface))
610 snprintf (nstate, sizeof (nstate), "PointToPoint");
611 else
612 {
613 if (on->router_id == on->drouter)
614 snprintf (nstate, sizeof (nstate), "DR");
615 else if (on->router_id == on->bdrouter)
616 snprintf (nstate, sizeof (nstate), "BDR");
617 else
618 snprintf (nstate, sizeof (nstate), "DROther");
619 }
620
621 /* Duration */
622 timersub (&now, &on->last_changed, &res);
623 timerstring (&res, duration, sizeof (duration));
624
625 /*
626 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
627 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
628 "I/F", "State", VTY_NEWLINE);
629 */
630
631 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
632 router_id, on->priority, deadtime,
633 ospf6_neighbor_state_str[on->state], nstate, duration,
634 on->ospf6_if->interface->name,
635 ospf6_interface_state_str[on->ospf6_if->state], VTY_NEWLINE);
636}
637
638void
639ospf6_neighbor_show_drchoice (struct vty *vty, struct ospf6_neighbor *on)
640{
641 char router_id[16];
642 char drouter[16], bdrouter[16];
paul718e3742002-12-13 20:15:29 +0000643 char duration[16];
644 struct timeval now, res;
645
646/*
647 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
648 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
649 "State", VTY_NEWLINE);
650*/
651
hasso508e53e2004-05-18 18:57:06 +0000652 inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
653 inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
654 inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
paul718e3742002-12-13 20:15:29 +0000655
656 gettimeofday (&now, NULL);
hasso508e53e2004-05-18 18:57:06 +0000657 timersub (&now, &on->last_changed, &res);
658 timerstring (&res, duration, sizeof (duration));
paul718e3742002-12-13 20:15:29 +0000659
660 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
hasso508e53e2004-05-18 18:57:06 +0000661 router_id, ospf6_neighbor_state_str[on->state],
662 duration, drouter, bdrouter, on->ospf6_if->interface->name,
663 ospf6_interface_state_str[on->ospf6_if->state],
paul718e3742002-12-13 20:15:29 +0000664 VTY_NEWLINE);
665}
666
667void
hasso508e53e2004-05-18 18:57:06 +0000668ospf6_neighbor_show_detail (struct vty *vty, struct ospf6_neighbor *on)
paul718e3742002-12-13 20:15:29 +0000669{
hasso508e53e2004-05-18 18:57:06 +0000670 char drouter[16], bdrouter[16];
671 char linklocal_addr[64], duration[32];
paul718e3742002-12-13 20:15:29 +0000672 struct timeval now, res;
hasso508e53e2004-05-18 18:57:06 +0000673 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000674
hasso508e53e2004-05-18 18:57:06 +0000675 inet_ntop (AF_INET6, &on->linklocal_addr, linklocal_addr,
676 sizeof (linklocal_addr));
677 inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
678 inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
paul718e3742002-12-13 20:15:29 +0000679
680 gettimeofday (&now, NULL);
hasso508e53e2004-05-18 18:57:06 +0000681 timersub (&now, &on->last_changed, &res);
682 timerstring (&res, duration, sizeof (duration));
paul718e3742002-12-13 20:15:29 +0000683
hasso508e53e2004-05-18 18:57:06 +0000684 vty_out (vty, " Neighbor %s%s", on->name,
685 VTY_NEWLINE);
686 vty_out (vty, " Area %s via interface %s (ifindex %d)%s",
687 on->ospf6_if->area->name,
688 on->ospf6_if->interface->name,
689 on->ospf6_if->interface->ifindex,
690 VTY_NEWLINE);
691 vty_out (vty, " His IfIndex: %d Link-local address: %s%s",
692 on->ifindex, linklocal_addr,
693 VTY_NEWLINE);
694 vty_out (vty, " State %s for a duration of %s%s",
695 ospf6_neighbor_state_str[on->state], duration,
696 VTY_NEWLINE);
697 vty_out (vty, " His choice of DR/BDR %s/%s, Priority %d%s",
698 drouter, bdrouter, on->priority,
699 VTY_NEWLINE);
700 vty_out (vty, " DbDesc status: %s%s%s SeqNum: %#lx%s",
701 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial " : ""),
702 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " : ""),
703 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ?
704 "Master" : "Slave"), (u_long) ntohl (on->dbdesc_seqnum),
paul718e3742002-12-13 20:15:29 +0000705 VTY_NEWLINE);
706
hasso508e53e2004-05-18 18:57:06 +0000707 vty_out (vty, " Summary-List: %d LSAs%s", on->summary_list->count,
708 VTY_NEWLINE);
709 for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
710 lsa = ospf6_lsdb_next (lsa))
711 vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000712
hasso508e53e2004-05-18 18:57:06 +0000713 vty_out (vty, " Request-List: %d LSAs%s", on->request_list->count,
714 VTY_NEWLINE);
715 for (lsa = ospf6_lsdb_head (on->request_list); lsa;
716 lsa = ospf6_lsdb_next (lsa))
717 vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
718
719 vty_out (vty, " Retrans-List: %d LSAs%s", on->retrans_list->count,
720 VTY_NEWLINE);
721 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
722 lsa = ospf6_lsdb_next (lsa))
723 vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
724
725 timerclear (&res);
726 if (on->thread_send_dbdesc)
727 timersub (&on->thread_send_dbdesc->u.sands, &now, &res);
728 timerstring (&res, duration, sizeof (duration));
729 vty_out (vty, " %d Pending LSAs for DbDesc in Time %s [thread %s]%s",
730 on->dbdesc_list->count, duration,
731 (on->thread_send_dbdesc ? "on" : "off"),
732 VTY_NEWLINE);
733 for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
734 lsa = ospf6_lsdb_next (lsa))
735 vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
736
737 timerclear (&res);
738 if (on->thread_send_lsreq)
739 timersub (&on->thread_send_lsreq->u.sands, &now, &res);
740 timerstring (&res, duration, sizeof (duration));
741 vty_out (vty, " %d Pending LSAs for LSReq in Time %s [thread %s]%s",
742 on->lsreq_list->count, duration,
743 (on->thread_send_lsreq ? "on" : "off"),
744 VTY_NEWLINE);
745 for (lsa = ospf6_lsdb_head (on->lsreq_list); lsa;
746 lsa = ospf6_lsdb_next (lsa))
747 vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
748
749 timerclear (&res);
750 if (on->thread_send_lsupdate)
751 timersub (&on->thread_send_lsupdate->u.sands, &now, &res);
752 timerstring (&res, duration, sizeof (duration));
753 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
754 on->lsupdate_list->count, duration,
755 (on->thread_send_lsupdate ? "on" : "off"),
756 VTY_NEWLINE);
757 for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
758 lsa = ospf6_lsdb_next (lsa))
759 vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
760
761 timerclear (&res);
762 if (on->thread_send_lsack)
763 timersub (&on->thread_send_lsack->u.sands, &now, &res);
764 timerstring (&res, duration, sizeof (duration));
765 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
766 on->lsack_list->count, duration,
767 (on->thread_send_lsack ? "on" : "off"),
768 VTY_NEWLINE);
769 for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
770 lsa = ospf6_lsdb_next (lsa))
771 vty_out (vty, " %s%s", lsa->name, VTY_NEWLINE);
772
paul718e3742002-12-13 20:15:29 +0000773}
774
hasso508e53e2004-05-18 18:57:06 +0000775DEFUN (show_ipv6_ospf6_neighbor,
paul718e3742002-12-13 20:15:29 +0000776 show_ipv6_ospf6_neighbor_cmd,
777 "show ipv6 ospf6 neighbor",
778 SHOW_STR
779 IP6_STR
780 OSPF6_STR
781 "Neighbor list\n"
hasso508e53e2004-05-18 18:57:06 +0000782 )
paul718e3742002-12-13 20:15:29 +0000783{
hasso508e53e2004-05-18 18:57:06 +0000784 struct ospf6_neighbor *on;
785 struct ospf6_interface *oi;
786 struct ospf6_area *oa;
787 listnode i, j, k;
788 void (*showfunc) (struct vty *, struct ospf6_neighbor *);
paul718e3742002-12-13 20:15:29 +0000789
790 OSPF6_CMD_CHECK_RUNNING ();
hasso508e53e2004-05-18 18:57:06 +0000791 showfunc = ospf6_neighbor_show;
792
793 if (argc)
794 {
795 if (! strncmp (argv[0], "de", 2))
796 showfunc = ospf6_neighbor_show_detail;
797 else if (! strncmp (argv[0], "dr", 2))
798 showfunc = ospf6_neighbor_show_drchoice;
799 }
800
801 if (showfunc == ospf6_neighbor_show)
802 vty_out (vty, "%-15s %3s %11s %6s/%-12s %11s %s[%s]%s",
803 "Neighbor ID", "Pri", "DeadTime", "State", "IfState", "Duration",
804 "I/F", "State", VTY_NEWLINE);
805 else if (showfunc == ospf6_neighbor_show_drchoice)
806 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
807 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
808 "State", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000809
810 for (i = listhead (ospf6->area_list); i; nextnode (i))
811 {
hasso508e53e2004-05-18 18:57:06 +0000812 oa = (struct ospf6_area *) getdata (i);
813 for (j = listhead (oa->if_list); j; nextnode (j))
paul718e3742002-12-13 20:15:29 +0000814 {
hasso508e53e2004-05-18 18:57:06 +0000815 oi = (struct ospf6_interface *) getdata (j);
816 for (k = listhead (oi->neighbor_list); k; nextnode (k))
paul718e3742002-12-13 20:15:29 +0000817 {
hasso508e53e2004-05-18 18:57:06 +0000818 on = (struct ospf6_neighbor *) getdata (k);
819 (*showfunc) (vty, on);
paul718e3742002-12-13 20:15:29 +0000820 }
821 }
822 }
hasso508e53e2004-05-18 18:57:06 +0000823 return CMD_SUCCESS;
824}
paul718e3742002-12-13 20:15:29 +0000825
hasso508e53e2004-05-18 18:57:06 +0000826ALIAS (show_ipv6_ospf6_neighbor,
827 show_ipv6_ospf6_neighbor_detail_cmd,
828 "show ipv6 ospf6 neighbor (detail|drchoice)",
829 SHOW_STR
830 IP6_STR
831 OSPF6_STR
832 "Neighbor list\n"
833 "Display details\n"
834 "Display DR choices\n"
835 );
836
837DEFUN (show_ipv6_ospf6_neighbor_one,
838 show_ipv6_ospf6_neighbor_one_cmd,
839 "show ipv6 ospf6 neighbor A.B.C.D",
840 SHOW_STR
841 IP6_STR
842 OSPF6_STR
843 "Neighbor list\n"
844 "Specify Router-ID as IPv4 address notation\n"
845 )
846{
847 struct ospf6_neighbor *on;
848 struct ospf6_interface *oi;
849 struct ospf6_area *oa;
850 listnode i, j, k;
851 void (*showfunc) (struct vty *, struct ospf6_neighbor *);
852 u_int32_t router_id;
853
854 OSPF6_CMD_CHECK_RUNNING ();
855 showfunc = ospf6_neighbor_show_detail;
856
857 if ((inet_pton (AF_INET, argv[0], &router_id)) != 1)
858 {
859 vty_out (vty, "Router-ID is not parsable: %s%s", argv[0],
860 VTY_NEWLINE);
861 return CMD_SUCCESS;
862 }
863
864 for (i = listhead (ospf6->area_list); i; nextnode (i))
865 {
866 oa = (struct ospf6_area *) getdata (i);
867 for (j = listhead (oa->if_list); j; nextnode (j))
868 {
869 oi = (struct ospf6_interface *) getdata (j);
870 for (k = listhead (oi->neighbor_list); k; nextnode (k))
871 {
872 on = (struct ospf6_neighbor *) getdata (k);
873 if (on->router_id == router_id)
874 (*showfunc) (vty, on);
875 }
876 }
877 }
paul718e3742002-12-13 20:15:29 +0000878 return CMD_SUCCESS;
879}
880
881void
882ospf6_neighbor_init ()
883{
884 install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
hasso508e53e2004-05-18 18:57:06 +0000885 install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_detail_cmd);
paul718e3742002-12-13 20:15:29 +0000886 install_element (ENABLE_NODE, &show_ipv6_ospf6_neighbor_cmd);
hasso508e53e2004-05-18 18:57:06 +0000887 install_element (ENABLE_NODE, &show_ipv6_ospf6_neighbor_detail_cmd);
paul718e3742002-12-13 20:15:29 +0000888}
889
hasso508e53e2004-05-18 18:57:06 +0000890DEFUN (debug_ospf6_neighbor,
891 debug_ospf6_neighbor_cmd,
892 "debug ospf6 neighbor",
893 DEBUG_STR
894 OSPF6_STR
895 "Debug OSPFv3 Neighbor\n"
896 )
897{
898 unsigned char level = 0;
899 if (argc)
900 {
901 if (! strncmp (argv[0], "s", 1))
902 level = OSPF6_DEBUG_NEIGHBOR_STATE;
903 if (! strncmp (argv[0], "e", 1))
904 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
905 }
906 else
907 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
908
909 OSPF6_DEBUG_NEIGHBOR_ON (level);
910 return CMD_SUCCESS;
911}
912
913ALIAS (debug_ospf6_neighbor,
914 debug_ospf6_neighbor_detail_cmd,
915 "debug ospf6 neighbor (state|event)",
916 DEBUG_STR
917 OSPF6_STR
918 "Debug OSPFv3 Neighbor\n"
919 "Debug OSPFv3 Neighbor State Change\n"
920 "Debug OSPFv3 Neighbor Event\n"
921 );
922
923DEFUN (no_debug_ospf6_neighbor,
924 no_debug_ospf6_neighbor_cmd,
925 "no debug ospf6 neighbor",
926 NO_STR
927 DEBUG_STR
928 OSPF6_STR
929 "Debug OSPFv3 Neighbor\n"
930 )
931{
932 unsigned char level = 0;
933 if (argc)
934 {
935 if (! strncmp (argv[0], "s", 1))
936 level = OSPF6_DEBUG_NEIGHBOR_STATE;
937 if (! strncmp (argv[0], "e", 1))
938 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
939 }
940 else
941 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
942
943 OSPF6_DEBUG_NEIGHBOR_OFF (level);
944 return CMD_SUCCESS;
945}
946
947ALIAS (no_debug_ospf6_neighbor,
948 no_debug_ospf6_neighbor_detail_cmd,
949 "no debug ospf6 neighbor (state|event)",
950 NO_STR
951 DEBUG_STR
952 OSPF6_STR
953 "Debug OSPFv3 Neighbor\n"
954 "Debug OSPFv3 Neighbor State Change\n"
955 "Debug OSPFv3 Neighbor Event\n"
956 );
957
958int
959config_write_ospf6_debug_neighbor (struct vty *vty)
960{
961 if (IS_OSPF6_DEBUG_NEIGHBOR (STATE) &&
962 IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
963 vty_out (vty, "debug ospf6 neighbor%s", VTY_NEWLINE);
964 else if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
965 vty_out (vty, "debug ospf6 neighbor state%s", VTY_NEWLINE);
966 else if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
967 vty_out (vty, "debug ospf6 neighbor event%s", VTY_NEWLINE);
968 return 0;
969}
970
971void
972install_element_ospf6_debug_neighbor ()
973{
974 install_element (ENABLE_NODE, &debug_ospf6_neighbor_cmd);
975 install_element (ENABLE_NODE, &debug_ospf6_neighbor_detail_cmd);
976 install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
977 install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_detail_cmd);
978 install_element (CONFIG_NODE, &debug_ospf6_neighbor_cmd);
979 install_element (CONFIG_NODE, &debug_ospf6_neighbor_detail_cmd);
980 install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
981 install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_detail_cmd);
982}
983
984
paul718e3742002-12-13 20:15:29 +0000985