2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
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
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"
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"
48 DEFINE_HOOK(ospf6_neighbor_change
,
49 (struct ospf6_neighbor
* on
, int state
, int next_state
),
50 (on
, state
, next_state
))
52 unsigned char conf_debug_ospf6_neighbor
= 0;
54 const char *const ospf6_neighbor_state_str
[] = {
55 "None", "Down", "Attempt", "Init", "Twoway",
56 "ExStart", "ExChange", "Loading", "Full", NULL
};
58 const char *const ospf6_neighbor_event_str
[] = {
59 "NoEvent", "HelloReceived", "2-WayReceived", "NegotiationDone",
60 "ExchangeDone", "LoadingDone", "AdjOK?", "SeqNumberMismatch",
61 "BadLSReq", "1-WayReceived", "InactivityTimer",
64 int ospf6_neighbor_cmp(void *va
, void *vb
)
66 struct ospf6_neighbor
*ona
= (struct ospf6_neighbor
*)va
;
67 struct ospf6_neighbor
*onb
= (struct ospf6_neighbor
*)vb
;
69 if (ona
->router_id
== onb
->router_id
)
72 return (ntohl(ona
->router_id
) < ntohl(onb
->router_id
)) ? -1 : 1;
75 struct ospf6_neighbor
*ospf6_neighbor_lookup(uint32_t router_id
,
76 struct ospf6_interface
*oi
)
79 struct ospf6_neighbor
*on
;
81 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, n
, on
))
82 if (on
->router_id
== router_id
)
85 return (struct ospf6_neighbor
*)NULL
;
88 /* create ospf6_neighbor */
89 struct ospf6_neighbor
*ospf6_neighbor_create(uint32_t router_id
,
90 struct ospf6_interface
*oi
)
92 struct ospf6_neighbor
*on
;
95 on
= XCALLOC(MTYPE_OSPF6_NEIGHBOR
, sizeof(struct ospf6_neighbor
));
96 inet_ntop(AF_INET
, &router_id
, buf
, sizeof(buf
));
97 snprintf(on
->name
, sizeof(on
->name
), "%s%%%s", buf
,
100 on
->state
= OSPF6_NEIGHBOR_DOWN
;
101 on
->state_change
= 0;
102 monotime(&on
->last_changed
);
103 on
->router_id
= router_id
;
105 on
->summary_list
= ospf6_lsdb_create(on
);
106 on
->request_list
= ospf6_lsdb_create(on
);
107 on
->retrans_list
= ospf6_lsdb_create(on
);
109 on
->dbdesc_list
= ospf6_lsdb_create(on
);
110 on
->lsupdate_list
= ospf6_lsdb_create(on
);
111 on
->lsack_list
= ospf6_lsdb_create(on
);
113 listnode_add_sort(oi
->neighbor_list
, on
);
115 ospf6_bfd_info_nbr_create(oi
, on
);
119 void ospf6_neighbor_delete(struct ospf6_neighbor
*on
)
121 struct ospf6_lsa
*lsa
, *lsa_next
;
122 const struct route_node
*iterend
;
124 ospf6_lsdb_remove_all(on
->summary_list
);
125 ospf6_lsdb_remove_all(on
->request_list
);
127 for (iterend
= ospf6_lsdb_head(on
->retrans_list
, 0, 0, 0, &lsa
); lsa
;
129 lsa_next
= ospf6_lsdb_next(iterend
, lsa
);
130 ospf6_decrement_retrans_count(lsa
);
131 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
134 ospf6_lsdb_remove_all(on
->dbdesc_list
);
135 ospf6_lsdb_remove_all(on
->lsupdate_list
);
136 ospf6_lsdb_remove_all(on
->lsack_list
);
138 ospf6_lsdb_delete(on
->summary_list
);
139 ospf6_lsdb_delete(on
->request_list
);
140 ospf6_lsdb_delete(on
->retrans_list
);
142 ospf6_lsdb_delete(on
->dbdesc_list
);
143 ospf6_lsdb_delete(on
->lsupdate_list
);
144 ospf6_lsdb_delete(on
->lsack_list
);
146 THREAD_OFF(on
->inactivity_timer
);
148 THREAD_OFF(on
->thread_send_dbdesc
);
149 THREAD_OFF(on
->thread_send_lsreq
);
150 THREAD_OFF(on
->thread_send_lsupdate
);
151 THREAD_OFF(on
->thread_send_lsack
);
153 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_DEREGISTER
);
154 XFREE(MTYPE_OSPF6_NEIGHBOR
, on
);
157 static void ospf6_neighbor_state_change(uint8_t next_state
,
158 struct ospf6_neighbor
*on
, int event
)
162 prev_state
= on
->state
;
163 on
->state
= next_state
;
165 if (prev_state
== next_state
)
169 monotime(&on
->last_changed
);
172 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
)) {
173 zlog_debug("Neighbor state change %s: [%s]->[%s] (%s)",
174 on
->name
, ospf6_neighbor_state_str
[prev_state
],
175 ospf6_neighbor_state_str
[next_state
],
176 ospf6_neighbor_event_string(event
));
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
)
185 || (next_state
< prev_state
)))
186 zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on
->name
,
187 ospf6_neighbor_state_str
[prev_state
],
188 ospf6_neighbor_state_str
[next_state
],
189 ospf6_neighbor_event_string(event
));
191 if (prev_state
== OSPF6_NEIGHBOR_FULL
192 || next_state
== OSPF6_NEIGHBOR_FULL
) {
193 OSPF6_ROUTER_LSA_SCHEDULE(on
->ospf6_if
->area
);
194 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
) {
195 OSPF6_NETWORK_LSA_SCHEDULE(on
->ospf6_if
);
196 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(on
->ospf6_if
);
198 if (next_state
== OSPF6_NEIGHBOR_FULL
)
199 on
->ospf6_if
->area
->intra_prefix_originate
= 1;
201 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on
->ospf6_if
->area
);
203 if ((prev_state
== OSPF6_NEIGHBOR_LOADING
||
204 prev_state
== OSPF6_NEIGHBOR_EXCHANGE
) &&
205 next_state
== OSPF6_NEIGHBOR_FULL
) {
206 OSPF6_AS_EXTERN_LSA_SCHEDULE(on
->ospf6_if
);
207 on
->ospf6_if
->area
->full_nbrs
++;
210 if (prev_state
== OSPF6_NEIGHBOR_FULL
)
211 on
->ospf6_if
->area
->full_nbrs
--;
214 if ((prev_state
== OSPF6_NEIGHBOR_EXCHANGE
215 || prev_state
== OSPF6_NEIGHBOR_LOADING
)
216 && (next_state
!= OSPF6_NEIGHBOR_EXCHANGE
217 && next_state
!= OSPF6_NEIGHBOR_LOADING
))
218 ospf6_maxage_remove(on
->ospf6_if
->area
->ospf6
);
220 hook_call(ospf6_neighbor_change
, on
, next_state
, prev_state
);
221 ospf6_bfd_trigger_event(on
, prev_state
, next_state
);
224 /* RFC2328 section 10.4 */
225 static int need_adjacency(struct ospf6_neighbor
*on
)
227 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_POINTTOPOINT
228 || on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
229 || on
->ospf6_if
->state
== OSPF6_INTERFACE_BDR
)
232 if (on
->ospf6_if
->drouter
== on
->router_id
233 || on
->ospf6_if
->bdrouter
== on
->router_id
)
239 int hello_received(struct thread
*thread
)
241 struct ospf6_neighbor
*on
;
243 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
246 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
247 zlog_debug("Neighbor Event %s: *HelloReceived*", on
->name
);
249 /* reset Inactivity Timer */
250 THREAD_OFF(on
->inactivity_timer
);
251 on
->inactivity_timer
= NULL
;
252 thread_add_timer(master
, inactivity_timer
, on
,
253 on
->ospf6_if
->dead_interval
, &on
->inactivity_timer
);
255 if (on
->state
<= OSPF6_NEIGHBOR_DOWN
)
256 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
257 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD
);
262 int twoway_received(struct thread
*thread
)
264 struct ospf6_neighbor
*on
;
266 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
269 if (on
->state
> OSPF6_NEIGHBOR_INIT
)
272 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
273 zlog_debug("Neighbor Event %s: *2Way-Received*", on
->name
);
275 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
277 if (!need_adjacency(on
)) {
278 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
279 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
283 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
284 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
285 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
286 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
287 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
289 THREAD_OFF(on
->thread_send_dbdesc
);
290 on
->thread_send_dbdesc
= NULL
;
291 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
292 &on
->thread_send_dbdesc
);
297 int negotiation_done(struct thread
*thread
)
299 struct ospf6_neighbor
*on
;
300 struct ospf6_lsa
*lsa
, *lsa_next
;
301 const struct route_node
*iterend
;
303 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
306 if (on
->state
!= OSPF6_NEIGHBOR_EXSTART
)
309 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
310 zlog_debug("Neighbor Event %s: *NegotiationDone*", on
->name
);
313 ospf6_lsdb_remove_all(on
->summary_list
);
314 ospf6_lsdb_remove_all(on
->request_list
);
316 for (iterend
= ospf6_lsdb_head(on
->retrans_list
, 0, 0, 0, &lsa
); lsa
;
318 lsa_next
= ospf6_lsdb_next(iterend
, lsa
);
319 ospf6_decrement_retrans_count(lsa
);
320 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
323 /* Interface scoped LSAs */
324 for (ALL_LSDB(on
->ospf6_if
->lsdb
, lsa
)) {
325 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
326 ospf6_increment_retrans_count(lsa
);
327 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
329 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
332 /* Area scoped LSAs */
333 for (ALL_LSDB(on
->ospf6_if
->area
->lsdb
, lsa
)) {
334 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
335 ospf6_increment_retrans_count(lsa
);
336 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
338 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
342 for (ALL_LSDB(on
->ospf6_if
->area
->ospf6
->lsdb
, lsa
)) {
343 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
344 ospf6_increment_retrans_count(lsa
);
345 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
347 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
350 UNSET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
351 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE
, on
,
352 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE
);
357 int exchange_done(struct thread
*thread
)
359 struct ospf6_neighbor
*on
;
361 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
364 if (on
->state
!= OSPF6_NEIGHBOR_EXCHANGE
)
367 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
368 zlog_debug("Neighbor Event %s: *ExchangeDone*", on
->name
);
370 THREAD_OFF(on
->thread_send_dbdesc
);
371 ospf6_lsdb_remove_all(on
->dbdesc_list
);
374 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
375 on->ospf6_if->dead_interval);
378 if (on
->request_list
->count
== 0)
379 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
380 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
382 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING
, on
,
383 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
385 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
386 &on
->thread_send_lsreq
);
392 /* Check loading state. */
393 void ospf6_check_nbr_loading(struct ospf6_neighbor
*on
)
396 /* RFC2328 Section 10.9: When the neighbor responds to these requests
397 with the proper Link State Update packet(s), the Link state request
398 list is truncated and a new Link State Request packet is sent.
400 if ((on
->state
== OSPF6_NEIGHBOR_LOADING
)
401 || (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
)) {
402 if (on
->request_list
->count
== 0)
403 thread_add_event(master
, loading_done
, on
, 0, NULL
);
404 else if (on
->last_ls_req
== NULL
) {
405 if (on
->thread_send_lsreq
!= NULL
)
406 THREAD_OFF(on
->thread_send_lsreq
);
407 on
->thread_send_lsreq
= NULL
;
408 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
409 &on
->thread_send_lsreq
);
414 int loading_done(struct thread
*thread
)
416 struct ospf6_neighbor
*on
;
418 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
421 if (on
->state
!= OSPF6_NEIGHBOR_LOADING
)
424 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
425 zlog_debug("Neighbor Event %s: *LoadingDone*", on
->name
);
427 assert(on
->request_list
->count
== 0);
429 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
430 OSPF6_NEIGHBOR_EVENT_LOADING_DONE
);
435 int adj_ok(struct thread
*thread
)
437 struct ospf6_neighbor
*on
;
438 struct ospf6_lsa
*lsa
;
440 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
443 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
444 zlog_debug("Neighbor Event %s: *AdjOK?*", on
->name
);
446 if (on
->state
== OSPF6_NEIGHBOR_TWOWAY
&& need_adjacency(on
)) {
447 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
448 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
449 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
450 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
451 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
453 THREAD_OFF(on
->thread_send_dbdesc
);
454 on
->thread_send_dbdesc
= NULL
;
455 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
456 &on
->thread_send_dbdesc
);
458 } else if (on
->state
>= OSPF6_NEIGHBOR_EXSTART
&& !need_adjacency(on
)) {
459 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
460 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
461 ospf6_lsdb_remove_all(on
->summary_list
);
462 ospf6_lsdb_remove_all(on
->request_list
);
463 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
464 ospf6_decrement_retrans_count(lsa
);
465 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
472 int seqnumber_mismatch(struct thread
*thread
)
474 struct ospf6_neighbor
*on
;
475 struct ospf6_lsa
*lsa
;
477 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
480 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
483 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
484 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on
->name
);
486 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
487 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH
);
488 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
489 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
490 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
492 ospf6_lsdb_remove_all(on
->summary_list
);
493 ospf6_lsdb_remove_all(on
->request_list
);
494 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
495 ospf6_decrement_retrans_count(lsa
);
496 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
499 THREAD_OFF(on
->thread_send_dbdesc
);
500 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
502 on
->thread_send_dbdesc
= NULL
;
503 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
504 &on
->thread_send_dbdesc
);
509 int bad_lsreq(struct thread
*thread
)
511 struct ospf6_neighbor
*on
;
512 struct ospf6_lsa
*lsa
, *lsa_next
;
513 const struct route_node
*iterend
;
515 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
518 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
521 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
522 zlog_debug("Neighbor Event %s: *BadLSReq*", on
->name
);
524 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
525 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ
);
526 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
527 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
528 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
530 ospf6_lsdb_remove_all(on
->summary_list
);
531 ospf6_lsdb_remove_all(on
->request_list
);
533 for (iterend
= ospf6_lsdb_head(on
->retrans_list
, 0, 0, 0, &lsa
); lsa
;
535 lsa_next
= ospf6_lsdb_next(iterend
, lsa
);
536 ospf6_decrement_retrans_count(lsa
);
537 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
540 THREAD_OFF(on
->thread_send_dbdesc
);
541 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
543 on
->thread_send_dbdesc
= NULL
;
544 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
545 &on
->thread_send_dbdesc
);
550 int oneway_received(struct thread
*thread
)
552 struct ospf6_neighbor
*on
;
553 struct ospf6_lsa
*lsa
, *lsa_next
;
554 const struct route_node
*iterend
;
556 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
559 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
562 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
563 zlog_debug("Neighbor Event %s: *1Way-Received*", on
->name
);
565 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
566 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD
);
567 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
569 ospf6_lsdb_remove_all(on
->summary_list
);
570 ospf6_lsdb_remove_all(on
->request_list
);
571 for (iterend
= ospf6_lsdb_head(on
->retrans_list
, 0, 0, 0, &lsa
); lsa
;
573 lsa_next
= ospf6_lsdb_next(iterend
, lsa
);
574 ospf6_decrement_retrans_count(lsa
);
575 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
578 THREAD_OFF(on
->thread_send_dbdesc
);
579 THREAD_OFF(on
->thread_send_lsreq
);
580 THREAD_OFF(on
->thread_send_lsupdate
);
581 THREAD_OFF(on
->thread_send_lsack
);
586 int inactivity_timer(struct thread
*thread
)
588 struct ospf6_neighbor
*on
;
590 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
593 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
594 zlog_debug("Neighbor Event %s: *InactivityTimer*", on
->name
);
596 on
->inactivity_timer
= NULL
;
597 on
->drouter
= on
->prev_drouter
= 0;
598 on
->bdrouter
= on
->prev_bdrouter
= 0;
600 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN
, on
,
601 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER
);
602 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
604 listnode_delete(on
->ospf6_if
->neighbor_list
, on
);
605 ospf6_neighbor_delete(on
);
612 /* show neighbor structure */
613 static void ospf6_neighbor_show(struct vty
*vty
, struct ospf6_neighbor
*on
)
622 /* Router-ID (Name) */
623 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
624 #ifdef HAVE_GETNAMEINFO
627 #endif /*HAVE_GETNAMEINFO*/
631 if (on
->inactivity_timer
) {
632 s
= monotime_until(&on
->inactivity_timer
->u
.sands
, NULL
)
639 snprintf(deadtime
, sizeof(deadtime
), "%02ld:%02ld:%02ld", h
, m
, s
);
642 if (on
->ospf6_if
->type
== OSPF_IFTYPE_POINTOPOINT
)
643 snprintf(nstate
, sizeof(nstate
), "PointToPoint");
645 if (on
->router_id
== on
->drouter
)
646 snprintf(nstate
, sizeof(nstate
), "DR");
647 else if (on
->router_id
== on
->bdrouter
)
648 snprintf(nstate
, sizeof(nstate
), "BDR");
650 snprintf(nstate
, sizeof(nstate
), "DROther");
654 monotime_since(&on
->last_changed
, &res
);
655 timerstring(&res
, duration
, sizeof(duration
));
658 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
659 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
663 vty_out(vty
, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id
,
664 on
->priority
, deadtime
, ospf6_neighbor_state_str
[on
->state
],
665 nstate
, duration
, on
->ospf6_if
->interface
->name
,
666 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
669 static void ospf6_neighbor_show_drchoice(struct vty
*vty
,
670 struct ospf6_neighbor
*on
)
673 char drouter
[16], bdrouter
[16];
675 struct timeval now
, res
;
678 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
679 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
683 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
684 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
685 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
688 timersub(&now
, &on
->last_changed
, &res
);
689 timerstring(&res
, duration
, sizeof(duration
));
691 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id
,
692 ospf6_neighbor_state_str
[on
->state
], duration
, drouter
,
693 bdrouter
, on
->ospf6_if
->interface
->name
,
694 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
697 static void ospf6_neighbor_show_detail(struct vty
*vty
,
698 struct ospf6_neighbor
*on
)
700 char drouter
[16], bdrouter
[16];
701 char linklocal_addr
[64], duration
[32];
702 struct timeval now
, res
;
703 struct ospf6_lsa
*lsa
;
705 inet_ntop(AF_INET6
, &on
->linklocal_addr
, linklocal_addr
,
706 sizeof(linklocal_addr
));
707 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
708 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
711 timersub(&now
, &on
->last_changed
, &res
);
712 timerstring(&res
, duration
, sizeof(duration
));
714 vty_out(vty
, " Neighbor %s\n", on
->name
);
715 vty_out(vty
, " Area %s via interface %s (ifindex %d)\n",
716 on
->ospf6_if
->area
->name
, on
->ospf6_if
->interface
->name
,
717 on
->ospf6_if
->interface
->ifindex
);
718 vty_out(vty
, " His IfIndex: %d Link-local address: %s\n",
719 on
->ifindex
, linklocal_addr
);
720 vty_out(vty
, " State %s for a duration of %s\n",
721 ospf6_neighbor_state_str
[on
->state
], duration
);
722 vty_out(vty
, " His choice of DR/BDR %s/%s, Priority %d\n", drouter
,
723 bdrouter
, on
->priority
);
724 vty_out(vty
, " DbDesc status: %s%s%s SeqNum: %#lx\n",
725 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
) ? "Initial "
727 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
) ? "More " : ""),
728 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
) ? "Master"
730 (unsigned long)ntohl(on
->dbdesc_seqnum
));
732 vty_out(vty
, " Summary-List: %d LSAs\n", on
->summary_list
->count
);
733 for (ALL_LSDB(on
->summary_list
, lsa
))
734 vty_out(vty
, " %s\n", lsa
->name
);
736 vty_out(vty
, " Request-List: %d LSAs\n", on
->request_list
->count
);
737 for (ALL_LSDB(on
->request_list
, lsa
))
738 vty_out(vty
, " %s\n", lsa
->name
);
740 vty_out(vty
, " Retrans-List: %d LSAs\n", on
->retrans_list
->count
);
741 for (ALL_LSDB(on
->retrans_list
, lsa
))
742 vty_out(vty
, " %s\n", lsa
->name
);
745 if (on
->thread_send_dbdesc
)
746 timersub(&on
->thread_send_dbdesc
->u
.sands
, &now
, &res
);
747 timerstring(&res
, duration
, sizeof(duration
));
748 vty_out(vty
, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
749 on
->dbdesc_list
->count
, duration
,
750 (on
->thread_send_dbdesc
? "on" : "off"));
751 for (ALL_LSDB(on
->dbdesc_list
, lsa
))
752 vty_out(vty
, " %s\n", lsa
->name
);
755 if (on
->thread_send_lsreq
)
756 timersub(&on
->thread_send_lsreq
->u
.sands
, &now
, &res
);
757 timerstring(&res
, duration
, sizeof(duration
));
758 vty_out(vty
, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
759 on
->request_list
->count
, duration
,
760 (on
->thread_send_lsreq
? "on" : "off"));
761 for (ALL_LSDB(on
->request_list
, lsa
))
762 vty_out(vty
, " %s\n", lsa
->name
);
765 if (on
->thread_send_lsupdate
)
766 timersub(&on
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
767 timerstring(&res
, duration
, sizeof(duration
));
769 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
770 on
->lsupdate_list
->count
, duration
,
771 (on
->thread_send_lsupdate
? "on" : "off"));
772 for (ALL_LSDB(on
->lsupdate_list
, lsa
))
773 vty_out(vty
, " %s\n", lsa
->name
);
776 if (on
->thread_send_lsack
)
777 timersub(&on
->thread_send_lsack
->u
.sands
, &now
, &res
);
778 timerstring(&res
, duration
, sizeof(duration
));
779 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
780 on
->lsack_list
->count
, duration
,
781 (on
->thread_send_lsack
? "on" : "off"));
782 for (ALL_LSDB(on
->lsack_list
, lsa
))
783 vty_out(vty
, " %s\n", lsa
->name
);
785 ospf6_bfd_show_info(vty
, on
->bfd_info
, 0);
788 DEFUN (show_ipv6_ospf6_neighbor
,
789 show_ipv6_ospf6_neighbor_cmd
,
790 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
796 "Display DR choices\n")
799 struct ospf6_neighbor
*on
;
800 struct ospf6_interface
*oi
;
801 struct ospf6_area
*oa
;
802 struct listnode
*i
, *j
, *k
;
803 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
805 OSPF6_CMD_CHECK_RUNNING();
806 showfunc
= ospf6_neighbor_show
;
809 if (!strncmp(argv
[idx_type
]->arg
, "de", 2))
810 showfunc
= ospf6_neighbor_show_detail
;
811 else if (!strncmp(argv
[idx_type
]->arg
, "dr", 2))
812 showfunc
= ospf6_neighbor_show_drchoice
;
815 if (showfunc
== ospf6_neighbor_show
)
816 vty_out(vty
, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
817 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
818 "Duration", "I/F", "State");
819 else if (showfunc
== ospf6_neighbor_show_drchoice
)
820 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
821 "State", "Duration", "DR", "BDR", "I/F", "State");
823 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
824 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
825 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
826 (*showfunc
)(vty
, on
);
832 DEFUN (show_ipv6_ospf6_neighbor_one
,
833 show_ipv6_ospf6_neighbor_one_cmd
,
834 "show ipv6 ospf6 neighbor A.B.C.D",
839 "Specify Router-ID as IPv4 address notation\n"
843 struct ospf6_neighbor
*on
;
844 struct ospf6_interface
*oi
;
845 struct ospf6_area
*oa
;
846 struct listnode
*i
, *j
, *k
;
847 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
850 OSPF6_CMD_CHECK_RUNNING();
851 showfunc
= ospf6_neighbor_show_detail
;
853 if ((inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
)) != 1) {
854 vty_out(vty
, "Router-ID is not parsable: %s\n",
855 argv
[idx_ipv4
]->arg
);
859 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
860 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
861 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
862 (*showfunc
)(vty
, on
);
867 void ospf6_neighbor_init(void)
869 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_cmd
);
870 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_one_cmd
);
873 DEFUN (debug_ospf6_neighbor
,
874 debug_ospf6_neighbor_cmd
,
875 "debug ospf6 neighbor [<state|event>]",
878 "Debug OSPFv3 Neighbor\n"
879 "Debug OSPFv3 Neighbor State Change\n"
880 "Debug OSPFv3 Neighbor Event\n")
883 unsigned char level
= 0;
886 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
887 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
888 else if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
889 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
891 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
893 OSPF6_DEBUG_NEIGHBOR_ON(level
);
898 DEFUN (no_debug_ospf6_neighbor
,
899 no_debug_ospf6_neighbor_cmd
,
900 "no debug ospf6 neighbor [<state|event>]",
904 "Debug OSPFv3 Neighbor\n"
905 "Debug OSPFv3 Neighbor State Change\n"
906 "Debug OSPFv3 Neighbor Event\n")
909 unsigned char level
= 0;
912 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
913 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
914 if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
915 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
917 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
919 OSPF6_DEBUG_NEIGHBOR_OFF(level
);
924 DEFUN (no_debug_ospf6
,
932 struct ospf6_lsa_handler
*handler
= NULL
;
934 OSPF6_DEBUG_ABR_OFF();
935 OSPF6_DEBUG_ASBR_OFF();
936 OSPF6_DEBUG_BROUTER_OFF();
937 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
938 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
939 OSPF6_DEBUG_FLOODING_OFF();
940 OSPF6_DEBUG_INTERFACE_OFF();
942 for (i
= 0; i
< vector_active(ospf6_lsa_handler_vector
); i
++) {
943 handler
= vector_slot(ospf6_lsa_handler_vector
, i
);
945 if (handler
!= NULL
) {
946 UNSET_FLAG(handler
->lh_debug
, OSPF6_LSA_DEBUG
);
950 for (i
= 0; i
< 6; i
++)
951 OSPF6_DEBUG_MESSAGE_OFF(i
,
952 OSPF6_DEBUG_NEIGHBOR_STATE
953 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
955 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
956 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
957 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE
);
958 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA
);
959 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER
);
960 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY
);
961 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS
);
962 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME
);
963 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE
);
964 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
);
969 int config_write_ospf6_debug_neighbor(struct vty
*vty
)
971 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
972 vty_out(vty
, "debug ospf6 neighbor\n");
973 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
))
974 vty_out(vty
, "debug ospf6 neighbor state\n");
975 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
976 vty_out(vty
, "debug ospf6 neighbor event\n");
980 void install_element_ospf6_debug_neighbor(void)
982 install_element(ENABLE_NODE
, &debug_ospf6_neighbor_cmd
);
983 install_element(ENABLE_NODE
, &no_debug_ospf6_neighbor_cmd
);
984 install_element(ENABLE_NODE
, &no_debug_ospf6_cmd
);
985 install_element(CONFIG_NODE
, &debug_ospf6_neighbor_cmd
);
986 install_element(CONFIG_NODE
, &no_debug_ospf6_neighbor_cmd
);
987 install_element(CONFIG_NODE
, &no_debug_ospf6_cmd
);