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