]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_neighbor.c
Merge pull request #806 from dwalton76/bgpd-set-ipv4-vpn-nexthop
[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 (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
127 lsa = ospf6_lsdb_next (lsa))
128 {
129 ospf6_decrement_retrans_count (lsa);
130 ospf6_lsdb_remove (lsa, on->retrans_list);
131 }
132
133 ospf6_lsdb_remove_all (on->dbdesc_list);
134 ospf6_lsdb_remove_all (on->lsupdate_list);
135 ospf6_lsdb_remove_all (on->lsack_list);
136
137 ospf6_lsdb_delete (on->summary_list);
138 ospf6_lsdb_delete (on->request_list);
139 ospf6_lsdb_delete (on->retrans_list);
140
141 ospf6_lsdb_delete (on->dbdesc_list);
142 ospf6_lsdb_delete (on->lsupdate_list);
143 ospf6_lsdb_delete (on->lsack_list);
144
145 THREAD_OFF (on->inactivity_timer);
146
147 THREAD_OFF (on->thread_send_dbdesc);
148 THREAD_OFF (on->thread_send_lsreq);
149 THREAD_OFF (on->thread_send_lsupdate);
150 THREAD_OFF (on->thread_send_lsack);
151
152 ospf6_bfd_reg_dereg_nbr(on, ZEBRA_BFD_DEST_DEREGISTER);
153 XFREE (MTYPE_OSPF6_NEIGHBOR, on);
154 }
155
156 static void
157 ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on, int event)
158 {
159 u_char prev_state;
160
161 prev_state = on->state;
162 on->state = next_state;
163
164 if (prev_state == next_state)
165 return;
166
167 on->state_change++;
168 monotime(&on->last_changed);
169
170 /* log */
171 if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
172 {
173 zlog_debug ("Neighbor state change %s: [%s]->[%s] (%s)", on->name,
174 ospf6_neighbor_state_str[prev_state],
175 ospf6_neighbor_state_str[next_state],
176 ospf6_neighbor_event_string(event));
177 }
178
179 /* Optionally notify about adjacency changes */
180 if (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
181 OSPF6_LOG_ADJACENCY_CHANGES) &&
182 (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
183 OSPF6_LOG_ADJACENCY_DETAIL) ||
184 (next_state == OSPF6_NEIGHBOR_FULL) || (next_state < prev_state)))
185 zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
186 ospf6_neighbor_state_str[prev_state],
187 ospf6_neighbor_state_str[next_state],
188 ospf6_neighbor_event_string(event));
189
190 if (prev_state == OSPF6_NEIGHBOR_FULL || next_state == OSPF6_NEIGHBOR_FULL)
191 {
192 OSPF6_ROUTER_LSA_SCHEDULE (on->ospf6_if->area);
193 if (on->ospf6_if->state == OSPF6_INTERFACE_DR)
194 {
195 OSPF6_NETWORK_LSA_SCHEDULE (on->ospf6_if);
196 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (on->ospf6_if);
197 }
198 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (on->ospf6_if->area);
199 }
200
201 if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE ||
202 prev_state == OSPF6_NEIGHBOR_LOADING) &&
203 (next_state != OSPF6_NEIGHBOR_EXCHANGE &&
204 next_state != OSPF6_NEIGHBOR_LOADING))
205 ospf6_maxage_remove (on->ospf6_if->area->ospf6);
206
207 hook_call(ospf6_neighbor_change, on, next_state, prev_state);
208 ospf6_bfd_trigger_event(on, prev_state, next_state);
209 }
210
211 /* RFC2328 section 10.4 */
212 static int
213 need_adjacency (struct ospf6_neighbor *on)
214 {
215 if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT ||
216 on->ospf6_if->state == OSPF6_INTERFACE_DR ||
217 on->ospf6_if->state == OSPF6_INTERFACE_BDR)
218 return 1;
219
220 if (on->ospf6_if->drouter == on->router_id ||
221 on->ospf6_if->bdrouter == on->router_id)
222 return 1;
223
224 return 0;
225 }
226
227 int
228 hello_received (struct thread *thread)
229 {
230 struct ospf6_neighbor *on;
231
232 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
233 assert (on);
234
235 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
236 zlog_debug ("Neighbor Event %s: *HelloReceived*", on->name);
237
238 /* reset Inactivity Timer */
239 THREAD_OFF (on->inactivity_timer);
240 on->inactivity_timer = NULL;
241 thread_add_timer(master, inactivity_timer, on, on->ospf6_if->dead_interval,
242 &on->inactivity_timer);
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 = NULL;
282 thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc);
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 = NULL;
414 thread_add_event(master, ospf6_lsreq_send, on, 0,
415 &on->thread_send_lsreq);
416 }
417 }
418 }
419
420 int
421 loading_done (struct thread *thread)
422 {
423 struct ospf6_neighbor *on;
424
425 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
426 assert (on);
427
428 if (on->state != OSPF6_NEIGHBOR_LOADING)
429 return 0;
430
431 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
432 zlog_debug ("Neighbor Event %s: *LoadingDone*", on->name);
433
434 assert (on->request_list->count == 0);
435
436 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on,
437 OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
438
439 return 0;
440 }
441
442 int
443 adj_ok (struct thread *thread)
444 {
445 struct ospf6_neighbor *on;
446 struct ospf6_lsa *lsa;
447
448 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
449 assert (on);
450
451 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
452 zlog_debug ("Neighbor Event %s: *AdjOK?*", on->name);
453
454 if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency (on))
455 {
456 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
457 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
458 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
459 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
460 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
461
462 THREAD_OFF (on->thread_send_dbdesc);
463 on->thread_send_dbdesc = NULL;
464 thread_add_event(master, ospf6_dbdesc_send, on, 0,
465 &on->thread_send_dbdesc);
466
467 }
468 else if (on->state >= OSPF6_NEIGHBOR_EXSTART &&
469 ! need_adjacency (on))
470 {
471 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on,
472 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
473 ospf6_lsdb_remove_all (on->summary_list);
474 ospf6_lsdb_remove_all (on->request_list);
475 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
476 lsa = ospf6_lsdb_next (lsa))
477 {
478 ospf6_decrement_retrans_count (lsa);
479 ospf6_lsdb_remove (lsa, on->retrans_list);
480 }
481 }
482
483 return 0;
484 }
485
486 int
487 seqnumber_mismatch (struct thread *thread)
488 {
489 struct ospf6_neighbor *on;
490 struct ospf6_lsa *lsa;
491
492 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
493 assert (on);
494
495 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
496 return 0;
497
498 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
499 zlog_debug ("Neighbor Event %s: *SeqNumberMismatch*", on->name);
500
501 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
502 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH);
503 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
504 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
505 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
506
507 ospf6_lsdb_remove_all (on->summary_list);
508 ospf6_lsdb_remove_all (on->request_list);
509 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
510 lsa = ospf6_lsdb_next (lsa))
511 {
512 ospf6_decrement_retrans_count (lsa);
513 ospf6_lsdb_remove (lsa, on->retrans_list);
514 }
515
516 THREAD_OFF (on->thread_send_dbdesc);
517 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
518
519 on->thread_send_dbdesc = NULL;
520 thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc);
521
522 return 0;
523 }
524
525 int
526 bad_lsreq (struct thread *thread)
527 {
528 struct ospf6_neighbor *on;
529 struct ospf6_lsa *lsa;
530
531 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
532 assert (on);
533
534 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
535 return 0;
536
537 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
538 zlog_debug ("Neighbor Event %s: *BadLSReq*", on->name);
539
540 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on,
541 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ);
542 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
543 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
544 SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
545
546 ospf6_lsdb_remove_all (on->summary_list);
547 ospf6_lsdb_remove_all (on->request_list);
548 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
549 lsa = ospf6_lsdb_next (lsa))
550 {
551 ospf6_decrement_retrans_count (lsa);
552 ospf6_lsdb_remove (lsa, on->retrans_list);
553 }
554
555 THREAD_OFF (on->thread_send_dbdesc);
556 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
557
558 on->thread_send_dbdesc = NULL;
559 thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc);
560
561 return 0;
562 }
563
564 int
565 oneway_received (struct thread *thread)
566 {
567 struct ospf6_neighbor *on;
568 struct ospf6_lsa *lsa;
569
570 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
571 assert (on);
572
573 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
574 return 0;
575
576 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
577 zlog_debug ("Neighbor Event %s: *1Way-Received*", on->name);
578
579 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on,
580 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
581 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
582
583 ospf6_lsdb_remove_all (on->summary_list);
584 ospf6_lsdb_remove_all (on->request_list);
585 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
586 lsa = ospf6_lsdb_next (lsa))
587 {
588 ospf6_decrement_retrans_count (lsa);
589 ospf6_lsdb_remove (lsa, on->retrans_list);
590 }
591
592 THREAD_OFF (on->thread_send_dbdesc);
593 THREAD_OFF (on->thread_send_lsreq);
594 THREAD_OFF (on->thread_send_lsupdate);
595 THREAD_OFF (on->thread_send_lsack);
596
597 return 0;
598 }
599
600 int
601 inactivity_timer (struct thread *thread)
602 {
603 struct ospf6_neighbor *on;
604
605 on = (struct ospf6_neighbor *) THREAD_ARG (thread);
606 assert (on);
607
608 if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
609 zlog_debug ("Neighbor Event %s: *InactivityTimer*", on->name);
610
611 on->inactivity_timer = NULL;
612 on->drouter = on->prev_drouter = 0;
613 on->bdrouter = on->prev_bdrouter = 0;
614
615 ospf6_neighbor_state_change (OSPF6_NEIGHBOR_DOWN, on,
616 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
617 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
618
619 listnode_delete (on->ospf6_if->neighbor_list, on);
620 ospf6_neighbor_delete (on);
621
622 return 0;
623 }
624
625
626
627 /* vty functions */
628 /* show neighbor structure */
629 static void
630 ospf6_neighbor_show (struct vty *vty, struct ospf6_neighbor *on)
631 {
632 char router_id[16];
633 char duration[16];
634 struct timeval res;
635 char nstate[16];
636 char deadtime[16];
637 long h, m, s;
638
639 /* Router-ID (Name) */
640 inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
641 #ifdef HAVE_GETNAMEINFO
642 {
643 }
644 #endif /*HAVE_GETNAMEINFO*/
645
646 /* Dead time */
647 h = m = s = 0;
648 if (on->inactivity_timer)
649 {
650 s = monotime_until(&on->inactivity_timer->u.sands, NULL) / 1000000LL;
651 h = s / 3600;
652 s -= h * 3600;
653 m = s / 60;
654 s -= m * 60;
655 }
656 snprintf (deadtime, sizeof (deadtime), "%02ld:%02ld:%02ld", h, m, s);
657
658 /* Neighbor State */
659 if (if_is_pointopoint (on->ospf6_if->interface))
660 snprintf (nstate, sizeof (nstate), "PointToPoint");
661 else
662 {
663 if (on->router_id == on->drouter)
664 snprintf (nstate, sizeof (nstate), "DR");
665 else if (on->router_id == on->bdrouter)
666 snprintf (nstate, sizeof (nstate), "BDR");
667 else
668 snprintf (nstate, sizeof (nstate), "DROther");
669 }
670
671 /* Duration */
672 monotime_since(&on->last_changed, &res);
673 timerstring (&res, duration, sizeof (duration));
674
675 /*
676 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
677 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
678 "I/F", "State");
679 */
680
681 vty_out (vty, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n",
682 router_id, on->priority, deadtime,
683 ospf6_neighbor_state_str[on->state], nstate, duration,
684 on->ospf6_if->interface->name,
685 ospf6_interface_state_str[on->ospf6_if->state]);
686 }
687
688 static void
689 ospf6_neighbor_show_drchoice (struct vty *vty, struct ospf6_neighbor *on)
690 {
691 char router_id[16];
692 char drouter[16], bdrouter[16];
693 char duration[16];
694 struct timeval now, res;
695
696 /*
697 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
698 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
699 "State");
700 */
701
702 inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
703 inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
704 inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
705
706 monotime(&now);
707 timersub (&now, &on->last_changed, &res);
708 timerstring (&res, duration, sizeof (duration));
709
710 vty_out (vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n",
711 router_id, ospf6_neighbor_state_str[on->state],
712 duration, drouter, bdrouter, on->ospf6_if->interface->name,
713 ospf6_interface_state_str[on->ospf6_if->state]);
714 }
715
716 static void
717 ospf6_neighbor_show_detail (struct vty *vty, struct ospf6_neighbor *on)
718 {
719 char drouter[16], bdrouter[16];
720 char linklocal_addr[64], duration[32];
721 struct timeval now, res;
722 struct ospf6_lsa *lsa;
723
724 inet_ntop (AF_INET6, &on->linklocal_addr, linklocal_addr,
725 sizeof (linklocal_addr));
726 inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
727 inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
728
729 monotime(&now);
730 timersub (&now, &on->last_changed, &res);
731 timerstring (&res, duration, sizeof (duration));
732
733 vty_out (vty, " Neighbor %s\n", on->name);
734 vty_out (vty, " Area %s via interface %s (ifindex %d)\n",
735 on->ospf6_if->area->name,
736 on->ospf6_if->interface->name,
737 on->ospf6_if->interface->ifindex);
738 vty_out (vty, " His IfIndex: %d Link-local address: %s\n",
739 on->ifindex, linklocal_addr);
740 vty_out (vty, " State %s for a duration of %s\n",
741 ospf6_neighbor_state_str[on->state], duration);
742 vty_out (vty, " His choice of DR/BDR %s/%s, Priority %d\n",
743 drouter, bdrouter, on->priority);
744 vty_out (vty, " DbDesc status: %s%s%s SeqNum: %#lx\n",
745 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial " : ""),
746 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " : ""),
747 (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ?
748 "Master" : "Slave"), (u_long) ntohl (on->dbdesc_seqnum));
749
750 vty_out (vty, " Summary-List: %d LSAs\n", on->summary_list->count);
751 for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
752 lsa = ospf6_lsdb_next (lsa))
753 vty_out (vty, " %s\n", lsa->name);
754
755 vty_out (vty, " Request-List: %d LSAs\n", on->request_list->count);
756 for (lsa = ospf6_lsdb_head (on->request_list); lsa;
757 lsa = ospf6_lsdb_next (lsa))
758 vty_out (vty, " %s\n", lsa->name);
759
760 vty_out (vty, " Retrans-List: %d LSAs\n", on->retrans_list->count);
761 for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
762 lsa = ospf6_lsdb_next (lsa))
763 vty_out (vty, " %s\n", lsa->name);
764
765 timerclear (&res);
766 if (on->thread_send_dbdesc)
767 timersub (&on->thread_send_dbdesc->u.sands, &now, &res);
768 timerstring (&res, duration, sizeof (duration));
769 vty_out (vty, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
770 on->dbdesc_list->count, duration,
771 (on->thread_send_dbdesc ? "on" : "off"));
772 for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
773 lsa = ospf6_lsdb_next (lsa))
774 vty_out (vty, " %s\n", lsa->name);
775
776 timerclear (&res);
777 if (on->thread_send_lsreq)
778 timersub (&on->thread_send_lsreq->u.sands, &now, &res);
779 timerstring (&res, duration, sizeof (duration));
780 vty_out (vty, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
781 on->request_list->count, duration,
782 (on->thread_send_lsreq ? "on" : "off"));
783 for (lsa = ospf6_lsdb_head (on->request_list); lsa;
784 lsa = ospf6_lsdb_next (lsa))
785 vty_out (vty, " %s\n", lsa->name);
786
787 timerclear (&res);
788 if (on->thread_send_lsupdate)
789 timersub (&on->thread_send_lsupdate->u.sands, &now, &res);
790 timerstring (&res, duration, sizeof (duration));
791 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
792 on->lsupdate_list->count, duration,
793 (on->thread_send_lsupdate ? "on" : "off"));
794 for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
795 lsa = ospf6_lsdb_next (lsa))
796 vty_out (vty, " %s\n", lsa->name);
797
798 timerclear (&res);
799 if (on->thread_send_lsack)
800 timersub (&on->thread_send_lsack->u.sands, &now, &res);
801 timerstring (&res, duration, sizeof (duration));
802 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
803 on->lsack_list->count, duration,
804 (on->thread_send_lsack ? "on" : "off"));
805 for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
806 lsa = ospf6_lsdb_next (lsa))
807 vty_out (vty, " %s\n", lsa->name);
808
809 ospf6_bfd_show_info(vty, on->bfd_info, 0);
810 }
811
812 DEFUN (show_ipv6_ospf6_neighbor,
813 show_ipv6_ospf6_neighbor_cmd,
814 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
815 SHOW_STR
816 IP6_STR
817 OSPF6_STR
818 "Neighbor list\n"
819 "Display details\n"
820 "Display DR choices\n")
821 {
822 int idx_type = 4;
823 struct ospf6_neighbor *on;
824 struct ospf6_interface *oi;
825 struct ospf6_area *oa;
826 struct listnode *i, *j, *k;
827 void (*showfunc) (struct vty *, struct ospf6_neighbor *);
828
829 OSPF6_CMD_CHECK_RUNNING ();
830 showfunc = ospf6_neighbor_show;
831
832 if (argc == 5)
833 {
834 if (! strncmp (argv[idx_type]->arg, "de", 2))
835 showfunc = ospf6_neighbor_show_detail;
836 else if (! strncmp (argv[idx_type]->arg, "dr", 2))
837 showfunc = ospf6_neighbor_show_drchoice;
838 }
839
840 if (showfunc == ospf6_neighbor_show)
841 vty_out (vty, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
842 "Neighbor ID", "Pri", "DeadTime", "State", "IfState", "Duration",
843 "I/F", "State");
844 else if (showfunc == ospf6_neighbor_show_drchoice)
845 vty_out (vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n",
846 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
847 "State");
848
849 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa))
850 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
851 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
852 (*showfunc) (vty, on);
853
854 return CMD_SUCCESS;
855 }
856
857
858 DEFUN (show_ipv6_ospf6_neighbor_one,
859 show_ipv6_ospf6_neighbor_one_cmd,
860 "show ipv6 ospf6 neighbor A.B.C.D",
861 SHOW_STR
862 IP6_STR
863 OSPF6_STR
864 "Neighbor list\n"
865 "Specify Router-ID as IPv4 address notation\n"
866 )
867 {
868 int idx_ipv4 = 4;
869 struct ospf6_neighbor *on;
870 struct ospf6_interface *oi;
871 struct ospf6_area *oa;
872 struct listnode *i, *j, *k;
873 void (*showfunc) (struct vty *, struct ospf6_neighbor *);
874 u_int32_t router_id;
875
876 OSPF6_CMD_CHECK_RUNNING ();
877 showfunc = ospf6_neighbor_show_detail;
878
879 if ((inet_pton (AF_INET, argv[idx_ipv4]->arg, &router_id)) != 1)
880 {
881 vty_out (vty, "Router-ID is not parsable: %s\n", argv[idx_ipv4]->arg);
882 return CMD_SUCCESS;
883 }
884
885 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa))
886 for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
887 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
888 (*showfunc) (vty, on);
889
890 return CMD_SUCCESS;
891 }
892
893 void
894 ospf6_neighbor_init (void)
895 {
896 install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
897 install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_one_cmd);
898 }
899
900 DEFUN (debug_ospf6_neighbor,
901 debug_ospf6_neighbor_cmd,
902 "debug ospf6 neighbor [<state|event>]",
903 DEBUG_STR
904 OSPF6_STR
905 "Debug OSPFv3 Neighbor\n"
906 "Debug OSPFv3 Neighbor State Change\n"
907 "Debug OSPFv3 Neighbor Event\n")
908 {
909 int idx_type = 3;
910 unsigned char level = 0;
911
912 if (argc == 4)
913 {
914 if (! strncmp (argv[idx_type]->arg, "s", 1))
915 level = OSPF6_DEBUG_NEIGHBOR_STATE;
916 else if (! strncmp (argv[idx_type]->arg, "e", 1))
917 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
918 }
919 else
920 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
921
922 OSPF6_DEBUG_NEIGHBOR_ON (level);
923 return CMD_SUCCESS;
924 }
925
926
927 DEFUN (no_debug_ospf6_neighbor,
928 no_debug_ospf6_neighbor_cmd,
929 "no debug ospf6 neighbor [<state|event>]",
930 NO_STR
931 DEBUG_STR
932 OSPF6_STR
933 "Debug OSPFv3 Neighbor\n"
934 "Debug OSPFv3 Neighbor State Change\n"
935 "Debug OSPFv3 Neighbor Event\n")
936 {
937 int idx_type = 4;
938 unsigned char level = 0;
939
940 if (argc == 5)
941 {
942 if (! strncmp (argv[idx_type]->arg, "s", 1))
943 level = OSPF6_DEBUG_NEIGHBOR_STATE;
944 if (! strncmp (argv[idx_type]->arg, "e", 1))
945 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
946 }
947 else
948 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
949
950 OSPF6_DEBUG_NEIGHBOR_OFF (level);
951 return CMD_SUCCESS;
952 }
953
954
955 DEFUN (no_debug_ospf6,
956 no_debug_ospf6_cmd,
957 "no debug ospf6",
958 NO_STR
959 DEBUG_STR
960 OSPF6_STR)
961 {
962 u_int i;
963 struct ospf6_lsa_handler *handler = NULL;
964
965 OSPF6_DEBUG_ABR_OFF ();
966 OSPF6_DEBUG_ASBR_OFF ();
967 OSPF6_DEBUG_BROUTER_OFF ();
968 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF ();
969 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF ();
970 OSPF6_DEBUG_FLOODING_OFF ();
971 OSPF6_DEBUG_INTERFACE_OFF ();
972
973 for (i = 0; i < vector_active (ospf6_lsa_handler_vector); i++)
974 {
975 handler = vector_slot (ospf6_lsa_handler_vector, i);
976
977 if (handler != NULL)
978 {
979 UNSET_FLAG (handler->debug, OSPF6_LSA_DEBUG);
980 }
981 }
982
983 for (i = 0; i < 6; i++)
984 OSPF6_DEBUG_MESSAGE_OFF (i, OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT);
985
986 OSPF6_DEBUG_NEIGHBOR_OFF (OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT);
987 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_TABLE);
988 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_INTRA);
989 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_INTER);
990 OSPF6_DEBUG_ROUTE_OFF (OSPF6_DEBUG_ROUTE_MEMORY);
991 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_PROCESS);
992 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_TIME);
993 OSPF6_DEBUG_SPF_OFF (OSPF6_DEBUG_SPF_DATABASE);
994 OSPF6_DEBUG_ZEBRA_OFF (OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV);
995
996 return CMD_SUCCESS;
997 }
998
999 int
1000 config_write_ospf6_debug_neighbor (struct vty *vty)
1001 {
1002 if (IS_OSPF6_DEBUG_NEIGHBOR (STATE) &&
1003 IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
1004 vty_out (vty, "debug ospf6 neighbor\n");
1005 else if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
1006 vty_out (vty, "debug ospf6 neighbor state\n");
1007 else if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
1008 vty_out (vty, "debug ospf6 neighbor event\n");
1009 return 0;
1010 }
1011
1012 void
1013 install_element_ospf6_debug_neighbor (void)
1014 {
1015 install_element (ENABLE_NODE, &debug_ospf6_neighbor_cmd);
1016 install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
1017 install_element (ENABLE_NODE, &no_debug_ospf6_cmd);
1018 install_element (CONFIG_NODE, &debug_ospf6_neighbor_cmd);
1019 install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
1020 install_element (CONFIG_NODE, &no_debug_ospf6_cmd);
1021 }
1022
1023
1024