]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_neighbor.c
Merge remote-tracking branch 'origin/stable/2.0'
[mirror_frr.git] / ospf6d / ospf6_neighbor.c
1 /*
2 * Copyright (C) 2003 Yasuhiro Ohara
3 *
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 "log.h"
25 #include "memory.h"
26 #include "thread.h"
27 #include "linklist.h"
28 #include "vty.h"
29 #include "command.h"
30
31 #include "ospf6_proto.h"
32 #include "ospf6_lsa.h"
33 #include "ospf6_lsdb.h"
34 #include "ospf6_message.h"
35 #include "ospf6_top.h"
36 #include "ospf6_area.h"
37 #include "ospf6_interface.h"
38 #include "ospf6_neighbor.h"
39 #include "ospf6_intra.h"
40 #include "ospf6_flood.h"
41 #include "ospf6_snmp.h"
42 #include "ospf6d.h"
43 #include "ospf6_bfd.h"
44 #include "ospf6_abr.h"
45 #include "ospf6_asbr.h"
46 #include "ospf6_lsa.h"
47 #include "ospf6_spf.h"
48 #include "ospf6_zebra.h"
49
50 unsigned char conf_debug_ospf6_neighbor = 0;
51
52 const char *ospf6_neighbor_state_str[] =
53 { "None", "Down", "Attempt", "Init", "Twoway", "ExStart", "ExChange",
54 "Loading", "Full", NULL };
55
56 int
57 ospf6_neighbor_cmp (void *va, void *vb)
58 {
59 struct ospf6_neighbor *ona = (struct ospf6_neighbor *) va;
60 struct ospf6_neighbor *onb = (struct ospf6_neighbor *) vb;
61 return (ntohl (ona->router_id) < ntohl (onb->router_id) ? -1 : 1);
62 }
63
64 struct ospf6_neighbor *
65 ospf6_neighbor_lookup (u_int32_t router_id,
66 struct ospf6_interface *oi)
67 {
68 struct listnode *n;
69 struct ospf6_neighbor *on;
70
71 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, n, on))
72 if (on->router_id == router_id)
73 return on;
74
75 return (struct ospf6_neighbor *) NULL;
76 }
77
78 /* create ospf6_neighbor */
79 struct ospf6_neighbor *
80 ospf6_neighbor_create (u_int32_t router_id, struct ospf6_interface *oi)
81 {
82 struct ospf6_neighbor *on;
83 char buf[16];
84
85 on = (struct ospf6_neighbor *)
86 XMALLOC (MTYPE_OSPF6_NEIGHBOR, sizeof (struct ospf6_neighbor));
87 if (on == NULL)
88 {
89 zlog_warn ("neighbor: malloc failed");
90 return NULL;
91 }
92
93 memset (on, 0, sizeof (struct ospf6_neighbor));
94 inet_ntop (AF_INET, &router_id, buf, sizeof (buf));
95 snprintf (on->name, sizeof (on->name), "%s%%%s",
96 buf, oi->interface->name);
97 on->ospf6_if = oi;
98 on->state = OSPF6_NEIGHBOR_DOWN;
99 on->state_change = 0;
100 monotime(&on->last_changed);
101 on->router_id = router_id;
102
103 on->summary_list = ospf6_lsdb_create (on);
104 on->request_list = ospf6_lsdb_create (on);
105 on->retrans_list = ospf6_lsdb_create (on);
106
107 on->dbdesc_list = ospf6_lsdb_create (on);
108 on->lsupdate_list = ospf6_lsdb_create (on);
109 on->lsack_list = ospf6_lsdb_create (on);
110
111 listnode_add_sort (oi->neighbor_list, on);
112
113 ospf6_bfd_info_nbr_create(oi, on);
114 return on;
115 }
116
117 void
118 ospf6_neighbor_delete (struct ospf6_neighbor *on)
119 {
120 struct ospf6_lsa *lsa;
121
122 ospf6_lsdb_remove_all (on->summary_list);
123 ospf6_lsdb_remove_all (on->request_list);
124 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
125 lsa = ospf6_lsdb_next (lsa))
126 {
127 ospf6_decrement_retrans_count (lsa);
128 ospf6_lsdb_remove (lsa, on->retrans_list);
129 }
130
131 ospf6_lsdb_remove_all (on->dbdesc_list);
132 ospf6_lsdb_remove_all (on->lsupdate_list);
133 ospf6_lsdb_remove_all (on->lsack_list);
134
135 ospf6_lsdb_delete (on->summary_list);
136 ospf6_lsdb_delete (on->request_list);
137 ospf6_lsdb_delete (on->retrans_list);
138
139 ospf6_lsdb_delete (on->dbdesc_list);
140 ospf6_lsdb_delete (on->lsupdate_list);
141 ospf6_lsdb_delete (on->lsack_list);
142
143 THREAD_OFF (on->inactivity_timer);
144
145 THREAD_OFF (on->thread_send_dbdesc);
146 THREAD_OFF (on->thread_send_lsreq);
147 THREAD_OFF (on->thread_send_lsupdate);
148 THREAD_OFF (on->thread_send_lsack);
149
150 ospf6_bfd_reg_dereg_nbr(on, ZEBRA_BFD_DEST_DEREGISTER);
151 XFREE (MTYPE_OSPF6_NEIGHBOR, on);
152 }
153
154 static void
155 ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on, int event)
156 {
157 u_char prev_state;
158
159 prev_state = on->state;
160 on->state = next_state;
161
162 if (prev_state == next_state)
163 return;
164
165 on->state_change++;
166 monotime(&on->last_changed);
167
168 /* log */
169 if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
170 {
171 zlog_debug ("Neighbor state change %s: [%s]->[%s] (%s)", on->name,
172 ospf6_neighbor_state_str[prev_state],
173 ospf6_neighbor_state_str[next_state],
174 ospf6_neighbor_event_string(event));
175 }
176
177 /* Optionally notify about adjacency changes */
178 if (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
179 OSPF6_LOG_ADJACENCY_CHANGES) &&
180 (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
181 OSPF6_LOG_ADJACENCY_DETAIL) ||
182 (next_state == OSPF6_NEIGHBOR_FULL) || (next_state < prev_state)))
183 zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
184 ospf6_neighbor_state_str[prev_state],
185 ospf6_neighbor_state_str[next_state],
186 ospf6_neighbor_event_string(event));
187
188 if (prev_state == OSPF6_NEIGHBOR_FULL || next_state == OSPF6_NEIGHBOR_FULL)
189 {
190 OSPF6_ROUTER_LSA_SCHEDULE (on->ospf6_if->area);
191 if (on->ospf6_if->state == OSPF6_INTERFACE_DR)
192 {
193 OSPF6_NETWORK_LSA_SCHEDULE (on->ospf6_if);
194 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (on->ospf6_if);
195 }
196 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (on->ospf6_if->area);
197 }
198
199 if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE ||
200 prev_state == OSPF6_NEIGHBOR_LOADING) &&
201 (next_state != OSPF6_NEIGHBOR_EXCHANGE &&
202 next_state != OSPF6_NEIGHBOR_LOADING))
203 ospf6_maxage_remove (on->ospf6_if->area->ospf6);
204
205 #ifdef HAVE_SNMP
206 /* Terminal state or regression */
207 if ((next_state == OSPF6_NEIGHBOR_FULL) ||
208 (next_state == OSPF6_NEIGHBOR_TWOWAY) ||
209 (next_state < prev_state))
210 ospf6TrapNbrStateChange (on);
211 #endif
212 ospf6_bfd_trigger_event(on, prev_state, next_state);
213 }
214
215 /* RFC2328 section 10.4 */
216 static int
217 need_adjacency (struct ospf6_neighbor *on)
218 {
219 if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT ||
220 on->ospf6_if->state == OSPF6_INTERFACE_DR ||
221 on->ospf6_if->state == OSPF6_INTERFACE_BDR)
222 return 1;
223
224 if (on->ospf6_if->drouter == on->router_id ||
225 on->ospf6_if->bdrouter == on->router_id)
226 return 1;
227
228 return 0;
229 }
230
231 int
232 hello_received (struct thread *thread)
233 {
234 struct ospf6_neighbor *on;
235
236 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
237 assert (on);
238
239 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
240 zlog_debug ("Neighbor Event %s: *HelloReceived*", on->name);
241
242 /* reset Inactivity Timer */
243 THREAD_OFF (on->inactivity_timer);
244 on->inactivity_timer = thread_add_timer (master, inactivity_timer, on,
245 on->ospf6_if->dead_interval);
246
247 if (on->state <= OSPF6_NEIGHBOR_DOWN)
248 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on,
249 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD);
250
251 return 0;
252 }
253
254 int
255 twoway_received (struct thread *thread)
256 {
257 struct ospf6_neighbor *on;
258
259 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
260 assert (on);
261
262 if (on->state > OSPF6_NEIGHBOR_INIT)
263 return 0;
264
265 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
266 zlog_debug ("Neighbor Event %s: *2Way-Received*", on->name);
267
268 thread_add_event (master, neighbor_change, on->ospf6_if, 0);
269
270 if (! need_adjacency (on))
271 {
272 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on,
273 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
274 return 0;
275 }
276
277 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
278 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
279 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
280 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
281 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
282
283 THREAD_OFF (on->thread_send_dbdesc);
284 on->thread_send_dbdesc =
285 thread_add_event (master, ospf6_dbdesc_send, on, 0);
286
287 return 0;
288 }
289
290 int
291 negotiation_done (struct thread *thread)
292 {
293 struct ospf6_neighbor *on;
294 struct ospf6_lsa *lsa;
295
296 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
297 assert (on);
298
299 if (on->state != OSPF6_NEIGHBOR_EXSTART)
300 return 0;
301
302 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
303 zlog_debug ("Neighbor Event %s: *NegotiationDone*", on->name);
304
305 /* clear ls-list */
306 ospf6_lsdb_remove_all (on->summary_list);
307 ospf6_lsdb_remove_all (on->request_list);
308 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
309 lsa = ospf6_lsdb_next (lsa))
310 {
311 ospf6_decrement_retrans_count (lsa);
312 ospf6_lsdb_remove (lsa, on->retrans_list);
313 }
314
315 /* Interface scoped LSAs */
316 for (lsa = ospf6_lsdb_head (on->ospf6_if->lsdb); lsa;
317 lsa = ospf6_lsdb_next (lsa))
318 {
319 if (OSPF6_LSA_IS_MAXAGE (lsa))
320 {
321 ospf6_increment_retrans_count (lsa);
322 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
323 }
324 else
325 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
326 }
327
328 /* Area scoped LSAs */
329 for (lsa = ospf6_lsdb_head (on->ospf6_if->area->lsdb); lsa;
330 lsa = ospf6_lsdb_next (lsa))
331 {
332 if (OSPF6_LSA_IS_MAXAGE (lsa))
333 {
334 ospf6_increment_retrans_count (lsa);
335 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
336 }
337 else
338 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
339 }
340
341 /* AS scoped LSAs */
342 for (lsa = ospf6_lsdb_head (on->ospf6_if->area->ospf6->lsdb); lsa;
343 lsa = ospf6_lsdb_next (lsa))
344 {
345 if (OSPF6_LSA_IS_MAXAGE (lsa))
346 {
347 ospf6_increment_retrans_count (lsa);
348 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
349 }
350 else
351 ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
352 }
353
354 UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
355 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXCHANGE, on,
356 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE);
357
358 return 0;
359 }
360
361 int
362 exchange_done (struct thread *thread)
363 {
364 struct ospf6_neighbor *on;
365
366 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
367 assert (on);
368
369 if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
370 return 0;
371
372 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
373 zlog_debug ("Neighbor Event %s: *ExchangeDone*", on->name);
374
375 THREAD_OFF (on->thread_send_dbdesc);
376 ospf6_lsdb_remove_all (on->dbdesc_list);
377
378 /* XXX
379 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
380 on->ospf6_if->dead_interval);
381 */
382
383 if (on->request_list->count == 0)
384 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on,
385 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
386 else
387 {
388 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_LOADING, on,
389 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
390
391 if (on->thread_send_lsreq == NULL)
392 on->thread_send_lsreq =
393 thread_add_event (master, ospf6_lsreq_send, on, 0);
394 }
395
396 return 0;
397 }
398
399 /* Check loading state. */
400 void
401 ospf6_check_nbr_loading (struct ospf6_neighbor *on)
402 {
403
404 /* RFC2328 Section 10.9: When the neighbor responds to these requests
405 with the proper Link State Update packet(s), the Link state request
406 list is truncated and a new Link State Request packet is sent.
407 */
408 if ((on->state == OSPF6_NEIGHBOR_LOADING) ||
409 (on->state == OSPF6_NEIGHBOR_EXCHANGE))
410 {
411 if (on->request_list->count == 0)
412 thread_add_event (master, loading_done, on, 0);
413 else if (on->last_ls_req == NULL)
414 {
415 if (on->thread_send_lsreq != NULL)
416 THREAD_OFF (on->thread_send_lsreq);
417 on->thread_send_lsreq =
418 thread_add_event (master, ospf6_lsreq_send, on, 0);
419 }
420 }
421 }
422
423 int
424 loading_done (struct thread *thread)
425 {
426 struct ospf6_neighbor *on;
427
428 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
429 assert (on);
430
431 if (on->state != OSPF6_NEIGHBOR_LOADING)
432 return 0;
433
434 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
435 zlog_debug ("Neighbor Event %s: *LoadingDone*", on->name);
436
437 assert (on->request_list->count == 0);
438
439 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on,
440 OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
441
442 return 0;
443 }
444
445 int
446 adj_ok (struct thread *thread)
447 {
448 struct ospf6_neighbor *on;
449 struct ospf6_lsa *lsa;
450
451 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
452 assert (on);
453
454 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
455 zlog_debug ("Neighbor Event %s: *AdjOK?*", on->name);
456
457 if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency (on))
458 {
459 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
460 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
461 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
462 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
463 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
464
465 THREAD_OFF (on->thread_send_dbdesc);
466 on->thread_send_dbdesc =
467 thread_add_event (master, ospf6_dbdesc_send, on, 0);
468
469 }
470 else if (on->state >= OSPF6_NEIGHBOR_EXSTART &&
471 ! need_adjacency (on))
472 {
473 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on,
474 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
475 ospf6_lsdb_remove_all (on->summary_list);
476 ospf6_lsdb_remove_all (on->request_list);
477 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
478 lsa = ospf6_lsdb_next (lsa))
479 {
480 ospf6_decrement_retrans_count (lsa);
481 ospf6_lsdb_remove (lsa, on->retrans_list);
482 }
483 }
484
485 return 0;
486 }
487
488 int
489 seqnumber_mismatch (struct thread *thread)
490 {
491 struct ospf6_neighbor *on;
492 struct ospf6_lsa *lsa;
493
494 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
495 assert (on);
496
497 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
498 return 0;
499
500 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
501 zlog_debug ("Neighbor Event %s: *SeqNumberMismatch*", on->name);
502
503 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
504 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH);
505 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
506 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
507 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
508
509 ospf6_lsdb_remove_all (on->summary_list);
510 ospf6_lsdb_remove_all (on->request_list);
511 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
512 lsa = ospf6_lsdb_next (lsa))
513 {
514 ospf6_decrement_retrans_count (lsa);
515 ospf6_lsdb_remove (lsa, on->retrans_list);
516 }
517
518 THREAD_OFF (on->thread_send_dbdesc);
519 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
520
521 on->thread_send_dbdesc =
522 thread_add_event (master, ospf6_dbdesc_send, on, 0);
523
524 return 0;
525 }
526
527 int
528 bad_lsreq (struct thread *thread)
529 {
530 struct ospf6_neighbor *on;
531 struct ospf6_lsa *lsa;
532
533 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
534 assert (on);
535
536 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
537 return 0;
538
539 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
540 zlog_debug ("Neighbor Event %s: *BadLSReq*", on->name);
541
542 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
543 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ);
544 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
545 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
546 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
547
548 ospf6_lsdb_remove_all (on->summary_list);
549 ospf6_lsdb_remove_all (on->request_list);
550 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
551 lsa = ospf6_lsdb_next (lsa))
552 {
553 ospf6_decrement_retrans_count (lsa);
554 ospf6_lsdb_remove (lsa, on->retrans_list);
555 }
556
557 THREAD_OFF (on->thread_send_dbdesc);
558 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
559
560 on->thread_send_dbdesc =
561 thread_add_event (master, ospf6_dbdesc_send, on, 0);
562
563 return 0;
564 }
565
566 int
567 oneway_received (struct thread *thread)
568 {
569 struct ospf6_neighbor *on;
570 struct ospf6_lsa *lsa;
571
572 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
573 assert (on);
574
575 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
576 return 0;
577
578 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
579 zlog_debug ("Neighbor Event %s: *1Way-Received*", on->name);
580
581 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on,
582 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
583 thread_add_event (master, neighbor_change, on->ospf6_if, 0);
584
585 ospf6_lsdb_remove_all (on->summary_list);
586 ospf6_lsdb_remove_all (on->request_list);
587 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
588 lsa = ospf6_lsdb_next (lsa))
589 {
590 ospf6_decrement_retrans_count (lsa);
591 ospf6_lsdb_remove (lsa, on->retrans_list);
592 }
593
594 THREAD_OFF (on->thread_send_dbdesc);
595 THREAD_OFF (on->thread_send_lsreq);
596 THREAD_OFF (on->thread_send_lsupdate);
597 THREAD_OFF (on->thread_send_lsack);
598
599 return 0;
600 }
601
602 int
603 inactivity_timer (struct thread *thread)
604 {
605 struct ospf6_neighbor *on;
606
607 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
608 assert (on);
609
610 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
611 zlog_debug ("Neighbor Event %s: *InactivityTimer*", on->name);
612
613 on->inactivity_timer = NULL;
614 on->drouter = on->prev_drouter = 0;
615 on->bdrouter = on->prev_bdrouter = 0;
616
617 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_DOWN, on,
618 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
619 thread_add_event (master, neighbor_change, on->ospf6_if, 0);
620
621 listnode_delete (on->ospf6_if->neighbor_list, on);
622 ospf6_neighbor_delete (on);
623
624 return 0;
625 }
626
627
628
629 /* vty functions */
630 /* show neighbor structure */
631 static void
632 ospf6_neighbor_show (struct vty *vty, struct ospf6_neighbor *on)
633 {
634 char router_id[16];
635 char duration[16];
636 struct timeval res;
637 char nstate[16];
638 char deadtime[16];
639 long h, m, s;
640
641 /* Router-ID (Name) */
642 inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
643 #ifdef HAVE_GETNAMEINFO
644 {
645 }
646 #endif /*HAVE_GETNAMEINFO*/
647
648 /* Dead time */
649 h = m = s = 0;
650 if (on->inactivity_timer)
651 {
652 s = monotime_until(&on->inactivity_timer->u.sands, NULL) / 1000000LL;
653 h = s / 3600;
654 s -= h * 3600;
655 m = s / 60;
656 s -= m * 60;
657 }
658 snprintf (deadtime, sizeof (deadtime), "%02ld:%02ld:%02ld", h, m, s);
659
660 /* Neighbor State */
661 if (if_is_pointopoint (on->ospf6_if->interface))
662 snprintf (nstate, sizeof (nstate), "PointToPoint");
663 else
664 {
665 if (on->router_id == on->drouter)
666 snprintf (nstate, sizeof (nstate), "DR");
667 else if (on->router_id == on->bdrouter)
668 snprintf (nstate, sizeof (nstate), "BDR");
669 else
670 snprintf (nstate, sizeof (nstate), "DROther");
671 }
672
673 /* Duration */
674 monotime_since(&on->last_changed, &res);
675 timerstring (&res, duration, sizeof (duration));
676
677 /*
678 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
679 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
680 "I/F", "State", VNL);
681 */
682
683 vty_out (vty, "%-15s %3d %11s %8s/%-12s %11s %s[%s]%s",
684 router_id, on->priority, deadtime,
685 ospf6_neighbor_state_str[on->state], nstate, duration,
686 on->ospf6_if->interface->name,
687 ospf6_interface_state_str[on->ospf6_if->state], VNL);
688 }
689
690 static void
691 ospf6_neighbor_show_drchoice (struct vty *vty, struct ospf6_neighbor *on)
692 {
693 char router_id[16];
694 char drouter[16], bdrouter[16];
695 char duration[16];
696 struct timeval now, res;
697
698 /*
699 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
700 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
701 "State", VNL);
702 */
703
704 inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
705 inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
706 inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
707
708 monotime(&now);
709 timersub (&now, &on->last_changed, &res);
710 timerstring (&res, duration, sizeof (duration));
711
712 vty_out (vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]%s",
713 router_id, ospf6_neighbor_state_str[on->state],
714 duration, drouter, bdrouter, on->ospf6_if->interface->name,
715 ospf6_interface_state_str[on->ospf6_if->state],
716 VNL);
717 }
718
719 static void
720 ospf6_neighbor_show_detail (struct vty *vty, struct ospf6_neighbor *on)
721 {
722 char drouter[16], bdrouter[16];
723 char linklocal_addr[64], duration[32];
724 struct timeval now, res;
725 struct ospf6_lsa *lsa;
726
727 inet_ntop (AF_INET6, &on->linklocal_addr, linklocal_addr,
728 sizeof (linklocal_addr));
729 inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
730 inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
731
732 monotime(&now);
733 timersub (&now, &on->last_changed, &res);
734 timerstring (&res, duration, sizeof (duration));
735
736 vty_out (vty, " Neighbor %s%s", on->name,
737 VNL);
738 vty_out (vty, " Area %s via interface %s (ifindex %d)%s",
739 on->ospf6_if->area->name,
740 on->ospf6_if->interface->name,
741 on->ospf6_if->interface->ifindex,
742 VNL);
743 vty_out (vty, " His IfIndex: %d Link-local address: %s%s",
744 on->ifindex, linklocal_addr,
745 VNL);
746 vty_out (vty, " State %s for a duration of %s%s",
747 ospf6_neighbor_state_str[on->state], duration,
748 VNL);
749 vty_out (vty, " His choice of DR/BDR %s/%s, Priority %d%s",
750 drouter, bdrouter, on->priority,
751 VNL);
752 vty_out (vty, " DbDesc status: %s%s%s SeqNum: %#lx%s",
753 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial " : ""),
754 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " : ""),
755 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ?
756 "Master" : "Slave"), (u_long) ntohl (on->dbdesc_seqnum),
757 VNL);
758
759 vty_out (vty, " Summary-List: %d LSAs%s", on->summary_list->count,
760 VNL);
761 for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
762 lsa = ospf6_lsdb_next (lsa))
763 vty_out (vty, " %s%s", lsa->name, VNL);
764
765 vty_out (vty, " Request-List: %d LSAs%s", on->request_list->count,
766 VNL);
767 for (lsa = ospf6_lsdb_head (on->request_list); lsa;
768 lsa = ospf6_lsdb_next (lsa))
769 vty_out (vty, " %s%s", lsa->name, VNL);
770
771 vty_out (vty, " Retrans-List: %d LSAs%s", on->retrans_list->count,
772 VNL);
773 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
774 lsa = ospf6_lsdb_next (lsa))
775 vty_out (vty, " %s%s", lsa->name, VNL);
776
777 timerclear (&res);
778 if (on->thread_send_dbdesc)
779 timersub (&on->thread_send_dbdesc->u.sands, &now, &res);
780 timerstring (&res, duration, sizeof (duration));
781 vty_out (vty, " %d Pending LSAs for DbDesc in Time %s [thread %s]%s",
782 on->dbdesc_list->count, duration,
783 (on->thread_send_dbdesc ? "on" : "off"),
784 VNL);
785 for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
786 lsa = ospf6_lsdb_next (lsa))
787 vty_out (vty, " %s%s", lsa->name, VNL);
788
789 timerclear (&res);
790 if (on->thread_send_lsreq)
791 timersub (&on->thread_send_lsreq->u.sands, &now, &res);
792 timerstring (&res, duration, sizeof (duration));
793 vty_out (vty, " %d Pending LSAs for LSReq in Time %s [thread %s]%s",
794 on->request_list->count, duration,
795 (on->thread_send_lsreq ? "on" : "off"),
796 VNL);
797 for (lsa = ospf6_lsdb_head (on->request_list); lsa;
798 lsa = ospf6_lsdb_next (lsa))
799 vty_out (vty, " %s%s", lsa->name, VNL);
800
801 timerclear (&res);
802 if (on->thread_send_lsupdate)
803 timersub (&on->thread_send_lsupdate->u.sands, &now, &res);
804 timerstring (&res, duration, sizeof (duration));
805 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
806 on->lsupdate_list->count, duration,
807 (on->thread_send_lsupdate ? "on" : "off"),
808 VNL);
809 for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
810 lsa = ospf6_lsdb_next (lsa))
811 vty_out (vty, " %s%s", lsa->name, VNL);
812
813 timerclear (&res);
814 if (on->thread_send_lsack)
815 timersub (&on->thread_send_lsack->u.sands, &now, &res);
816 timerstring (&res, duration, sizeof (duration));
817 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
818 on->lsack_list->count, duration,
819 (on->thread_send_lsack ? "on" : "off"),
820 VNL);
821 for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
822 lsa = ospf6_lsdb_next (lsa))
823 vty_out (vty, " %s%s", lsa->name, VNL);
824
825 ospf6_bfd_show_info(vty, on->bfd_info, 0);
826 }
827
828 DEFUN (show_ipv6_ospf6_neighbor,
829 show_ipv6_ospf6_neighbor_cmd,
830 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
831 SHOW_STR
832 IP6_STR
833 OSPF6_STR
834 "Neighbor list\n"
835 "Display details\n"
836 "Display DR choices\n")
837 {
838 int idx_type = 4;
839 struct ospf6_neighbor *on;
840 struct ospf6_interface *oi;
841 struct ospf6_area *oa;
842 struct listnode *i, *j, *k;
843 void (*showfunc) (struct vty *, struct ospf6_neighbor *);
844
845 OSPF6_CMD_CHECK_RUNNING ();
846 showfunc = ospf6_neighbor_show;
847
848 if (argc == 5)
849 {
850 if (! strncmp (argv[idx_type]->arg, "de", 2))
851 showfunc = ospf6_neighbor_show_detail;
852 else if (! strncmp (argv[idx_type]->arg, "dr", 2))
853 showfunc = ospf6_neighbor_show_drchoice;
854 }
855
856 if (showfunc == ospf6_neighbor_show)
857 vty_out (vty, "%-15s %3s %11s %8s/%-12s %11s %s[%s]%s",
858 "Neighbor ID", "Pri", "DeadTime", "State", "IfState", "Duration",
859 "I/F", "State", VNL);
860 else if (showfunc == ospf6_neighbor_show_drchoice)
861 vty_out (vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]%s",
862 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
863 "State", VNL);
864
865 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa))
866 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
867 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
868 (*showfunc) (vty, on);
869
870 return CMD_SUCCESS;
871 }
872
873
874 DEFUN (show_ipv6_ospf6_neighbor_one,
875 show_ipv6_ospf6_neighbor_one_cmd,
876 "show ipv6 ospf6 neighbor A.B.C.D",
877 SHOW_STR
878 IP6_STR
879 OSPF6_STR
880 "Neighbor list\n"
881 "Specify Router-ID as IPv4 address notation\n"
882 )
883 {
884 int idx_ipv4 = 4;
885 struct ospf6_neighbor *on;
886 struct ospf6_interface *oi;
887 struct ospf6_area *oa;
888 struct listnode *i, *j, *k;
889 void (*showfunc) (struct vty *, struct ospf6_neighbor *);
890 u_int32_t router_id;
891
892 OSPF6_CMD_CHECK_RUNNING ();
893 showfunc = ospf6_neighbor_show_detail;
894
895 if ((inet_pton (AF_INET, argv[idx_ipv4]->arg, &router_id)) != 1)
896 {
897 vty_out (vty, "Router-ID is not parsable: %s%s", argv[idx_ipv4]->arg,
898 VNL);
899 return CMD_SUCCESS;
900 }
901
902 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa))
903 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
904 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
905 (*showfunc) (vty, on);
906
907 return CMD_SUCCESS;
908 }
909
910 void
911 ospf6_neighbor_init (void)
912 {
913 install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
914 install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_one_cmd);
915 }
916
917 DEFUN (debug_ospf6_neighbor,
918 debug_ospf6_neighbor_cmd,
919 "debug ospf6 neighbor [<state|event>]",
920 DEBUG_STR
921 OSPF6_STR
922 "Debug OSPFv3 Neighbor\n"
923 "Debug OSPFv3 Neighbor State Change\n"
924 "Debug OSPFv3 Neighbor Event\n")
925 {
926 int idx_type = 3;
927 unsigned char level = 0;
928
929 if (argc == 4)
930 {
931 if (! strncmp (argv[idx_type]->arg, "s", 1))
932 level = OSPF6_DEBUG_NEIGHBOR_STATE;
933 else if (! strncmp (argv[idx_type]->arg, "e", 1))
934 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
935 }
936 else
937 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
938
939 OSPF6_DEBUG_NEIGHBOR_ON (level);
940 return CMD_SUCCESS;
941 }
942
943
944 DEFUN (no_debug_ospf6_neighbor,
945 no_debug_ospf6_neighbor_cmd,
946 "no debug ospf6 neighbor [<state|event>]",
947 NO_STR
948 DEBUG_STR
949 OSPF6_STR
950 "Debug OSPFv3 Neighbor\n"
951 "Debug OSPFv3 Neighbor State Change\n"
952 "Debug OSPFv3 Neighbor Event\n")
953 {
954 int idx_type = 4;
955 unsigned char level = 0;
956
957 if (argc == 5)
958 {
959 if (! strncmp (argv[idx_type]->arg, "s", 1))
960 level = OSPF6_DEBUG_NEIGHBOR_STATE;
961 if (! strncmp (argv[idx_type]->arg, "e", 1))
962 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
963 }
964 else
965 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
966
967 OSPF6_DEBUG_NEIGHBOR_OFF (level);
968 return CMD_SUCCESS;
969 }
970
971
972 DEFUN (no_debug_ospf6,
973 no_debug_ospf6_cmd,
974 "no debug ospf6",
975 NO_STR
976 DEBUG_STR
977 OSPF6_STR)
978 {
979 u_int i;
980 struct ospf6_lsa_handler *handler = NULL;
981
982 OSPF6_DEBUG_ABR_OFF ();
983 OSPF6_DEBUG_ASBR_OFF ();
984 OSPF6_DEBUG_BROUTER_OFF ();
985 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF ();
986 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF ();
987 OSPF6_DEBUG_FLOODING_OFF ();
988 OSPF6_DEBUG_INTERFACE_OFF ();
989
990 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
991 {
992 handler = vector_slot (ospf6_lsa_handler_vector, i);
993
994 if (handler != NULL)
995 {
996 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
997 }
998 }
999
1000 for (i = 0; i < 6; i++)
1001 OSPF6_DEBUG_MESSAGE_OFF (i, OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT);
1002
1003 OSPF6_DEBUG_NEIGHBOR_OFF (OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT);
1004 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_TABLE);
1005 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_INTRA);
1006 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_INTER);
1007 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_MEMORY);
1008 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_PROCESS);
1009 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_TIME);
1010 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_DATABASE);
1011 OSPF6_DEBUG_ZEBRA_OFF (OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV);
1012
1013 return CMD_SUCCESS;
1014 }
1015
1016 int
1017 config_write_ospf6_debug_neighbor (struct vty *vty)
1018 {
1019 if (IS_OSPF6_DEBUG_NEIGHBOR (STATE) &&
1020 IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
1021 vty_out (vty, "debug ospf6 neighbor%s", VNL);
1022 else if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
1023 vty_out (vty, "debug ospf6 neighbor state%s", VNL);
1024 else if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
1025 vty_out (vty, "debug ospf6 neighbor event%s", VNL);
1026 return 0;
1027 }
1028
1029 void
1030 install_element_ospf6_debug_neighbor (void)
1031 {
1032 install_element (ENABLE_NODE, &debug_ospf6_neighbor_cmd);
1033 install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
1034 install_element (ENABLE_NODE, &no_debug_ospf6_cmd);
1035 install_element (CONFIG_NODE, &debug_ospf6_neighbor_cmd);
1036 install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
1037 install_element (CONFIG_NODE, &no_debug_ospf6_cmd);
1038 }
1039
1040
1041