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