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