]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_neighbor.c
Merge branch 'cmaster-next' into vtysh-grammar
[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 quagga_gettime (QUAGGA_CLK_MONOTONIC, &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 quagga_gettime (QUAGGA_CLK_MONOTONIC, &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 now, 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 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
649
650 /* Dead time */
651 h = m = s = 0;
652 if (on->inactivity_timer)
653 {
654 s = on->inactivity_timer->u.sands.tv_sec - recent_relative_time().tv_sec;
655 h = s / 3600;
656 s -= h * 3600;
657 m = s / 60;
658 s -= m * 60;
659 }
660 snprintf (deadtime, sizeof (deadtime), "%02ld:%02ld:%02ld", h, m, s);
661
662 /* Neighbor State */
663 if (if_is_pointopoint (on->ospf6_if->interface))
664 snprintf (nstate, sizeof (nstate), "PointToPoint");
665 else
666 {
667 if (on->router_id == on->drouter)
668 snprintf (nstate, sizeof (nstate), "DR");
669 else if (on->router_id == on->bdrouter)
670 snprintf (nstate, sizeof (nstate), "BDR");
671 else
672 snprintf (nstate, sizeof (nstate), "DROther");
673 }
674
675 /* Duration */
676 timersub (&now, &on->last_changed, &res);
677 timerstring (&res, duration, sizeof (duration));
678
679 /*
680 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
681 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
682 "I/F", "State", VNL);
683 */
684
685 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
686 router_id, on->priority, deadtime,
687 ospf6_neighbor_state_str[on->state], nstate, duration,
688 on->ospf6_if->interface->name,
689 ospf6_interface_state_str[on->ospf6_if->state], VNL);
690 }
691
692 static void
693 ospf6_neighbor_show_drchoice (struct vty *vty, struct ospf6_neighbor *on)
694 {
695 char router_id[16];
696 char drouter[16], bdrouter[16];
697 char duration[16];
698 struct timeval now, res;
699
700 /*
701 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
702 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
703 "State", VNL);
704 */
705
706 inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
707 inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
708 inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
709
710 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
711 timersub (&now, &on->last_changed, &res);
712 timerstring (&res, duration, sizeof (duration));
713
714 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
715 router_id, ospf6_neighbor_state_str[on->state],
716 duration, drouter, bdrouter, on->ospf6_if->interface->name,
717 ospf6_interface_state_str[on->ospf6_if->state],
718 VNL);
719 }
720
721 static void
722 ospf6_neighbor_show_detail (struct vty *vty, struct ospf6_neighbor *on)
723 {
724 char drouter[16], bdrouter[16];
725 char linklocal_addr[64], duration[32];
726 struct timeval now, res;
727 struct ospf6_lsa *lsa;
728
729 inet_ntop (AF_INET6, &on->linklocal_addr, linklocal_addr,
730 sizeof (linklocal_addr));
731 inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
732 inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
733
734 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
735 timersub (&now, &on->last_changed, &res);
736 timerstring (&res, duration, sizeof (duration));
737
738 vty_out (vty, " Neighbor %s%s", on->name,
739 VNL);
740 vty_out (vty, " Area %s via interface %s (ifindex %d)%s",
741 on->ospf6_if->area->name,
742 on->ospf6_if->interface->name,
743 on->ospf6_if->interface->ifindex,
744 VNL);
745 vty_out (vty, " His IfIndex: %d Link-local address: %s%s",
746 on->ifindex, linklocal_addr,
747 VNL);
748 vty_out (vty, " State %s for a duration of %s%s",
749 ospf6_neighbor_state_str[on->state], duration,
750 VNL);
751 vty_out (vty, " His choice of DR/BDR %s/%s, Priority %d%s",
752 drouter, bdrouter, on->priority,
753 VNL);
754 vty_out (vty, " DbDesc status: %s%s%s SeqNum: %#lx%s",
755 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial " : ""),
756 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " : ""),
757 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ?
758 "Master" : "Slave"), (u_long) ntohl (on->dbdesc_seqnum),
759 VNL);
760
761 vty_out (vty, " Summary-List: %d LSAs%s", on->summary_list->count,
762 VNL);
763 for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
764 lsa = ospf6_lsdb_next (lsa))
765 vty_out (vty, " %s%s", lsa->name, VNL);
766
767 vty_out (vty, " Request-List: %d LSAs%s", on->request_list->count,
768 VNL);
769 for (lsa = ospf6_lsdb_head (on->request_list); lsa;
770 lsa = ospf6_lsdb_next (lsa))
771 vty_out (vty, " %s%s", lsa->name, VNL);
772
773 vty_out (vty, " Retrans-List: %d LSAs%s", on->retrans_list->count,
774 VNL);
775 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
776 lsa = ospf6_lsdb_next (lsa))
777 vty_out (vty, " %s%s", lsa->name, VNL);
778
779 timerclear (&res);
780 if (on->thread_send_dbdesc)
781 timersub (&on->thread_send_dbdesc->u.sands, &now, &res);
782 timerstring (&res, duration, sizeof (duration));
783 vty_out (vty, " %d Pending LSAs for DbDesc in Time %s [thread %s]%s",
784 on->dbdesc_list->count, duration,
785 (on->thread_send_dbdesc ? "on" : "off"),
786 VNL);
787 for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
788 lsa = ospf6_lsdb_next (lsa))
789 vty_out (vty, " %s%s", lsa->name, VNL);
790
791 timerclear (&res);
792 if (on->thread_send_lsreq)
793 timersub (&on->thread_send_lsreq->u.sands, &now, &res);
794 timerstring (&res, duration, sizeof (duration));
795 vty_out (vty, " %d Pending LSAs for LSReq in Time %s [thread %s]%s",
796 on->request_list->count, duration,
797 (on->thread_send_lsreq ? "on" : "off"),
798 VNL);
799 for (lsa = ospf6_lsdb_head (on->request_list); lsa;
800 lsa = ospf6_lsdb_next (lsa))
801 vty_out (vty, " %s%s", lsa->name, VNL);
802
803 timerclear (&res);
804 if (on->thread_send_lsupdate)
805 timersub (&on->thread_send_lsupdate->u.sands, &now, &res);
806 timerstring (&res, duration, sizeof (duration));
807 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
808 on->lsupdate_list->count, duration,
809 (on->thread_send_lsupdate ? "on" : "off"),
810 VNL);
811 for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
812 lsa = ospf6_lsdb_next (lsa))
813 vty_out (vty, " %s%s", lsa->name, VNL);
814
815 timerclear (&res);
816 if (on->thread_send_lsack)
817 timersub (&on->thread_send_lsack->u.sands, &now, &res);
818 timerstring (&res, duration, sizeof (duration));
819 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
820 on->lsack_list->count, duration,
821 (on->thread_send_lsack ? "on" : "off"),
822 VNL);
823 for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
824 lsa = ospf6_lsdb_next (lsa))
825 vty_out (vty, " %s%s", lsa->name, VNL);
826
827 ospf6_bfd_show_info(vty, on->bfd_info, 0);
828 }
829
830 DEFUN (show_ipv6_ospf6_neighbor,
831 show_ipv6_ospf6_neighbor_cmd,
832 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
833 SHOW_STR
834 IP6_STR
835 OSPF6_STR
836 "Neighbor list\n"
837 "Display details\n"
838 "Display DR choices\n")
839 {
840 int idx_type = 4;
841 struct ospf6_neighbor *on;
842 struct ospf6_interface *oi;
843 struct ospf6_area *oa;
844 struct listnode *i, *j, *k;
845 void (*showfunc) (struct vty *, struct ospf6_neighbor *);
846
847 OSPF6_CMD_CHECK_RUNNING ();
848 showfunc = ospf6_neighbor_show;
849
850 if (argc == 5)
851 {
852 if (! strncmp (argv[idx_type]->arg, "de", 2))
853 showfunc = ospf6_neighbor_show_detail;
854 else if (! strncmp (argv[idx_type]->arg, "dr", 2))
855 showfunc = ospf6_neighbor_show_drchoice;
856 }
857
858 if (showfunc == ospf6_neighbor_show)
859 vty_out (vty, "%-15s %3s %11s %6s/%-12s %11s %s[%s]%s",
860 "Neighbor ID", "Pri", "DeadTime", "State", "IfState", "Duration",
861 "I/F", "State", VNL);
862 else if (showfunc == ospf6_neighbor_show_drchoice)
863 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
864 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
865 "State", VNL);
866
867 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa))
868 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
869 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
870 (*showfunc) (vty, on);
871
872 return CMD_SUCCESS;
873 }
874
875
876 DEFUN (show_ipv6_ospf6_neighbor_one,
877 show_ipv6_ospf6_neighbor_one_cmd,
878 "show ipv6 ospf6 neighbor A.B.C.D",
879 SHOW_STR
880 IP6_STR
881 OSPF6_STR
882 "Neighbor list\n"
883 "Specify Router-ID as IPv4 address notation\n"
884 )
885 {
886 int idx_ipv4 = 4;
887 struct ospf6_neighbor *on;
888 struct ospf6_interface *oi;
889 struct ospf6_area *oa;
890 struct listnode *i, *j, *k;
891 void (*showfunc) (struct vty *, struct ospf6_neighbor *);
892 u_int32_t router_id;
893
894 OSPF6_CMD_CHECK_RUNNING ();
895 showfunc = ospf6_neighbor_show_detail;
896
897 if ((inet_pton (AF_INET, argv[idx_ipv4]->arg, &router_id)) != 1)
898 {
899 vty_out (vty, "Router-ID is not parsable: %s%s", argv[idx_ipv4]->arg,
900 VNL);
901 return CMD_SUCCESS;
902 }
903
904 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa))
905 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
906 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
907 (*showfunc) (vty, on);
908
909 return CMD_SUCCESS;
910 }
911
912 void
913 ospf6_neighbor_init (void)
914 {
915 install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
916 }
917
918 DEFUN (debug_ospf6_neighbor,
919 debug_ospf6_neighbor_cmd,
920 "debug ospf6 neighbor [<state|event>]",
921 DEBUG_STR
922 OSPF6_STR
923 "Debug OSPFv3 Neighbor\n"
924 "Debug OSPFv3 Neighbor State Change\n"
925 "Debug OSPFv3 Neighbor Event\n")
926 {
927 int idx_type = 3;
928 unsigned char level = 0;
929
930 if (argc == 4)
931 {
932 if (! strncmp (argv[idx_type]->arg, "s", 1))
933 level = OSPF6_DEBUG_NEIGHBOR_STATE;
934 else if (! strncmp (argv[idx_type]->arg, "e", 1))
935 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
936 }
937 else
938 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
939
940 OSPF6_DEBUG_NEIGHBOR_ON (level);
941 return CMD_SUCCESS;
942 }
943
944
945 DEFUN (no_debug_ospf6_neighbor,
946 no_debug_ospf6_neighbor_cmd,
947 "no debug ospf6 neighbor [<state|event>]",
948 NO_STR
949 DEBUG_STR
950 OSPF6_STR
951 "Debug OSPFv3 Neighbor\n"
952 "Debug OSPFv3 Neighbor State Change\n"
953 "Debug OSPFv3 Neighbor Event\n")
954 {
955 int idx_type = 4;
956 unsigned char level = 0;
957
958 if (argc == 5)
959 {
960 if (! strncmp (argv[idx_type]->arg, "s", 1))
961 level = OSPF6_DEBUG_NEIGHBOR_STATE;
962 if (! strncmp (argv[idx_type]->arg, "e", 1))
963 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
964 }
965 else
966 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
967
968 OSPF6_DEBUG_NEIGHBOR_OFF (level);
969 return CMD_SUCCESS;
970 }
971
972
973 DEFUN (no_debug_ospf6,
974 no_debug_ospf6_cmd,
975 "no debug ospf6",
976 NO_STR
977 DEBUG_STR
978 OSPF6_STR)
979 {
980 u_int i;
981 struct ospf6_lsa_handler *handler = NULL;
982
983 OSPF6_DEBUG_ABR_OFF ();
984 OSPF6_DEBUG_ASBR_OFF ();
985 OSPF6_DEBUG_BROUTER_OFF ();
986 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF ();
987 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF ();
988 OSPF6_DEBUG_FLOODING_OFF ();
989 OSPF6_DEBUG_INTERFACE_OFF ();
990
991 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
992 {
993 handler = vector_slot (ospf6_lsa_handler_vector, i);
994
995 if (handler != NULL)
996 {
997 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
998 }
999 }
1000
1001 for (i = 0; i < 6; i++)
1002 OSPF6_DEBUG_MESSAGE_OFF (i, OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT);
1003
1004 OSPF6_DEBUG_NEIGHBOR_OFF (OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT);
1005 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_TABLE);
1006 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_INTRA);
1007 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_INTER);
1008 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_MEMORY);
1009 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_PROCESS);
1010 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_TIME);
1011 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_DATABASE);
1012 OSPF6_DEBUG_ZEBRA_OFF (OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV);
1013
1014 return CMD_SUCCESS;
1015 }
1016
1017 int
1018 config_write_ospf6_debug_neighbor (struct vty *vty)
1019 {
1020 if (IS_OSPF6_DEBUG_NEIGHBOR (STATE) &&
1021 IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
1022 vty_out (vty, "debug ospf6 neighbor%s", VNL);
1023 else if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
1024 vty_out (vty, "debug ospf6 neighbor state%s", VNL);
1025 else if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
1026 vty_out (vty, "debug ospf6 neighbor event%s", VNL);
1027 return 0;
1028 }
1029
1030 void
1031 install_element_ospf6_debug_neighbor (void)
1032 {
1033 install_element (ENABLE_NODE, &debug_ospf6_neighbor_cmd);
1034 install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
1035 install_element (ENABLE_NODE, &no_debug_ospf6_cmd);
1036 install_element (CONFIG_NODE, &debug_ospf6_neighbor_cmd);
1037 install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
1038 install_element (CONFIG_NODE, &no_debug_ospf6_cmd);
1039 }
1040
1041
1042