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