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