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 *ospf6_neighbor_state_str
[] = {
55 "None", "Down", "Attempt", "Init", "Twoway",
56 "ExStart", "ExChange", "Loading", "Full", NULL
};
58 int ospf6_neighbor_cmp(void *va
, void *vb
)
60 struct ospf6_neighbor
*ona
= (struct ospf6_neighbor
*)va
;
61 struct ospf6_neighbor
*onb
= (struct ospf6_neighbor
*)vb
;
63 if (ona
->router_id
== onb
->router_id
)
66 return (ntohl(ona
->router_id
) < ntohl(onb
->router_id
)) ? -1 : 1;
69 struct ospf6_neighbor
*ospf6_neighbor_lookup(uint32_t router_id
,
70 struct ospf6_interface
*oi
)
73 struct ospf6_neighbor
*on
;
75 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, n
, on
))
76 if (on
->router_id
== router_id
)
79 return (struct ospf6_neighbor
*)NULL
;
82 /* create ospf6_neighbor */
83 struct ospf6_neighbor
*ospf6_neighbor_create(uint32_t router_id
,
84 struct ospf6_interface
*oi
)
86 struct ospf6_neighbor
*on
;
89 on
= XCALLOC(MTYPE_OSPF6_NEIGHBOR
, sizeof(struct ospf6_neighbor
));
90 inet_ntop(AF_INET
, &router_id
, buf
, sizeof(buf
));
91 snprintf(on
->name
, sizeof(on
->name
), "%s%%%s", buf
,
94 on
->state
= OSPF6_NEIGHBOR_DOWN
;
96 monotime(&on
->last_changed
);
97 on
->router_id
= router_id
;
99 on
->summary_list
= ospf6_lsdb_create(on
);
100 on
->request_list
= ospf6_lsdb_create(on
);
101 on
->retrans_list
= ospf6_lsdb_create(on
);
103 on
->dbdesc_list
= ospf6_lsdb_create(on
);
104 on
->lsupdate_list
= ospf6_lsdb_create(on
);
105 on
->lsack_list
= ospf6_lsdb_create(on
);
107 listnode_add_sort(oi
->neighbor_list
, on
);
109 ospf6_bfd_info_nbr_create(oi
, on
);
113 void ospf6_neighbor_delete(struct ospf6_neighbor
*on
)
115 struct ospf6_lsa
*lsa
, *lsa_next
;
116 const struct route_node
*iterend
;
118 ospf6_lsdb_remove_all(on
->summary_list
);
119 ospf6_lsdb_remove_all(on
->request_list
);
121 for (iterend
= ospf6_lsdb_head(on
->retrans_list
, 0, 0, 0, &lsa
); lsa
;
123 lsa_next
= ospf6_lsdb_next(iterend
, lsa
);
124 ospf6_decrement_retrans_count(lsa
);
125 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
128 ospf6_lsdb_remove_all(on
->dbdesc_list
);
129 ospf6_lsdb_remove_all(on
->lsupdate_list
);
130 ospf6_lsdb_remove_all(on
->lsack_list
);
132 ospf6_lsdb_delete(on
->summary_list
);
133 ospf6_lsdb_delete(on
->request_list
);
134 ospf6_lsdb_delete(on
->retrans_list
);
136 ospf6_lsdb_delete(on
->dbdesc_list
);
137 ospf6_lsdb_delete(on
->lsupdate_list
);
138 ospf6_lsdb_delete(on
->lsack_list
);
140 THREAD_OFF(on
->inactivity_timer
);
142 THREAD_OFF(on
->thread_send_dbdesc
);
143 THREAD_OFF(on
->thread_send_lsreq
);
144 THREAD_OFF(on
->thread_send_lsupdate
);
145 THREAD_OFF(on
->thread_send_lsack
);
147 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_DEREGISTER
);
148 XFREE(MTYPE_OSPF6_NEIGHBOR
, on
);
151 static void ospf6_neighbor_state_change(uint8_t next_state
,
152 struct ospf6_neighbor
*on
, int event
)
156 prev_state
= on
->state
;
157 on
->state
= next_state
;
159 if (prev_state
== next_state
)
163 monotime(&on
->last_changed
);
166 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
)) {
167 zlog_debug("Neighbor state change %s: [%s]->[%s] (%s)",
168 on
->name
, ospf6_neighbor_state_str
[prev_state
],
169 ospf6_neighbor_state_str
[next_state
],
170 ospf6_neighbor_event_string(event
));
173 /* Optionally notify about adjacency changes */
174 if (CHECK_FLAG(on
->ospf6_if
->area
->ospf6
->config_flags
,
175 OSPF6_LOG_ADJACENCY_CHANGES
)
176 && (CHECK_FLAG(on
->ospf6_if
->area
->ospf6
->config_flags
,
177 OSPF6_LOG_ADJACENCY_DETAIL
)
178 || (next_state
== OSPF6_NEIGHBOR_FULL
)
179 || (next_state
< prev_state
)))
180 zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on
->name
,
181 ospf6_neighbor_state_str
[prev_state
],
182 ospf6_neighbor_state_str
[next_state
],
183 ospf6_neighbor_event_string(event
));
185 if (prev_state
== OSPF6_NEIGHBOR_FULL
186 || next_state
== OSPF6_NEIGHBOR_FULL
) {
187 OSPF6_ROUTER_LSA_SCHEDULE(on
->ospf6_if
->area
);
188 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
) {
189 OSPF6_NETWORK_LSA_SCHEDULE(on
->ospf6_if
);
190 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(on
->ospf6_if
);
192 if (next_state
== OSPF6_NEIGHBOR_FULL
)
193 on
->ospf6_if
->area
->intra_prefix_originate
= 1;
195 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on
->ospf6_if
->area
);
197 if ((prev_state
== OSPF6_NEIGHBOR_LOADING
||
198 prev_state
== OSPF6_NEIGHBOR_EXCHANGE
) &&
199 next_state
== OSPF6_NEIGHBOR_FULL
) {
200 OSPF6_AS_EXTERN_LSA_SCHEDULE(on
->ospf6_if
);
201 on
->ospf6_if
->area
->full_nbrs
++;
204 if (prev_state
== OSPF6_NEIGHBOR_FULL
)
205 on
->ospf6_if
->area
->full_nbrs
--;
208 if ((prev_state
== OSPF6_NEIGHBOR_EXCHANGE
209 || prev_state
== OSPF6_NEIGHBOR_LOADING
)
210 && (next_state
!= OSPF6_NEIGHBOR_EXCHANGE
211 && next_state
!= OSPF6_NEIGHBOR_LOADING
))
212 ospf6_maxage_remove(on
->ospf6_if
->area
->ospf6
);
214 hook_call(ospf6_neighbor_change
, on
, next_state
, prev_state
);
215 ospf6_bfd_trigger_event(on
, prev_state
, next_state
);
218 /* RFC2328 section 10.4 */
219 static int need_adjacency(struct ospf6_neighbor
*on
)
221 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_POINTTOPOINT
222 || on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
223 || on
->ospf6_if
->state
== OSPF6_INTERFACE_BDR
)
226 if (on
->ospf6_if
->drouter
== on
->router_id
227 || on
->ospf6_if
->bdrouter
== on
->router_id
)
233 int hello_received(struct thread
*thread
)
235 struct ospf6_neighbor
*on
;
237 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
240 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
241 zlog_debug("Neighbor Event %s: *HelloReceived*", on
->name
);
243 /* reset Inactivity Timer */
244 THREAD_OFF(on
->inactivity_timer
);
245 on
->inactivity_timer
= NULL
;
246 thread_add_timer(master
, inactivity_timer
, on
,
247 on
->ospf6_if
->dead_interval
, &on
->inactivity_timer
);
249 if (on
->state
<= OSPF6_NEIGHBOR_DOWN
)
250 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
251 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD
);
256 int twoway_received(struct thread
*thread
)
258 struct ospf6_neighbor
*on
;
260 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
263 if (on
->state
> OSPF6_NEIGHBOR_INIT
)
266 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
267 zlog_debug("Neighbor Event %s: *2Way-Received*", on
->name
);
269 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
271 if (!need_adjacency(on
)) {
272 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
273 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
277 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
278 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
279 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
280 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
281 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
283 THREAD_OFF(on
->thread_send_dbdesc
);
284 on
->thread_send_dbdesc
= NULL
;
285 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
286 &on
->thread_send_dbdesc
);
291 int negotiation_done(struct thread
*thread
)
293 struct ospf6_neighbor
*on
;
294 struct ospf6_lsa
*lsa
, *lsa_next
;
295 const struct route_node
*iterend
;
297 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
300 if (on
->state
!= OSPF6_NEIGHBOR_EXSTART
)
303 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
304 zlog_debug("Neighbor Event %s: *NegotiationDone*", on
->name
);
307 ospf6_lsdb_remove_all(on
->summary_list
);
308 ospf6_lsdb_remove_all(on
->request_list
);
310 for (iterend
= ospf6_lsdb_head(on
->retrans_list
, 0, 0, 0, &lsa
); lsa
;
312 lsa_next
= ospf6_lsdb_next(iterend
, lsa
);
313 ospf6_decrement_retrans_count(lsa
);
314 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
317 /* Interface scoped LSAs */
318 for (ALL_LSDB(on
->ospf6_if
->lsdb
, lsa
)) {
319 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
320 ospf6_increment_retrans_count(lsa
);
321 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
323 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
326 /* Area scoped LSAs */
327 for (ALL_LSDB(on
->ospf6_if
->area
->lsdb
, lsa
)) {
328 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
329 ospf6_increment_retrans_count(lsa
);
330 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
332 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
336 for (ALL_LSDB(on
->ospf6_if
->area
->ospf6
->lsdb
, lsa
)) {
337 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
338 ospf6_increment_retrans_count(lsa
);
339 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
341 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
344 UNSET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
345 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE
, on
,
346 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE
);
351 int exchange_done(struct thread
*thread
)
353 struct ospf6_neighbor
*on
;
355 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
358 if (on
->state
!= OSPF6_NEIGHBOR_EXCHANGE
)
361 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
362 zlog_debug("Neighbor Event %s: *ExchangeDone*", on
->name
);
364 THREAD_OFF(on
->thread_send_dbdesc
);
365 ospf6_lsdb_remove_all(on
->dbdesc_list
);
368 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
369 on->ospf6_if->dead_interval);
372 if (on
->request_list
->count
== 0)
373 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
374 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
376 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING
, on
,
377 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
379 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
380 &on
->thread_send_lsreq
);
386 /* Check loading state. */
387 void ospf6_check_nbr_loading(struct ospf6_neighbor
*on
)
390 /* RFC2328 Section 10.9: When the neighbor responds to these requests
391 with the proper Link State Update packet(s), the Link state request
392 list is truncated and a new Link State Request packet is sent.
394 if ((on
->state
== OSPF6_NEIGHBOR_LOADING
)
395 || (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
)) {
396 if (on
->request_list
->count
== 0)
397 thread_add_event(master
, loading_done
, on
, 0, NULL
);
398 else if (on
->last_ls_req
== NULL
) {
399 if (on
->thread_send_lsreq
!= NULL
)
400 THREAD_OFF(on
->thread_send_lsreq
);
401 on
->thread_send_lsreq
= NULL
;
402 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
403 &on
->thread_send_lsreq
);
408 int loading_done(struct thread
*thread
)
410 struct ospf6_neighbor
*on
;
412 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
415 if (on
->state
!= OSPF6_NEIGHBOR_LOADING
)
418 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
419 zlog_debug("Neighbor Event %s: *LoadingDone*", on
->name
);
421 assert(on
->request_list
->count
== 0);
423 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
424 OSPF6_NEIGHBOR_EVENT_LOADING_DONE
);
429 int adj_ok(struct thread
*thread
)
431 struct ospf6_neighbor
*on
;
432 struct ospf6_lsa
*lsa
;
434 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
437 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
438 zlog_debug("Neighbor Event %s: *AdjOK?*", on
->name
);
440 if (on
->state
== OSPF6_NEIGHBOR_TWOWAY
&& need_adjacency(on
)) {
441 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
442 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
443 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
444 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
445 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
447 THREAD_OFF(on
->thread_send_dbdesc
);
448 on
->thread_send_dbdesc
= NULL
;
449 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
450 &on
->thread_send_dbdesc
);
452 } else if (on
->state
>= OSPF6_NEIGHBOR_EXSTART
&& !need_adjacency(on
)) {
453 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
454 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
455 ospf6_lsdb_remove_all(on
->summary_list
);
456 ospf6_lsdb_remove_all(on
->request_list
);
457 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
458 ospf6_decrement_retrans_count(lsa
);
459 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
466 int seqnumber_mismatch(struct thread
*thread
)
468 struct ospf6_neighbor
*on
;
469 struct ospf6_lsa
*lsa
;
471 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
474 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
477 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
478 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on
->name
);
480 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
481 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH
);
482 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
483 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
484 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
486 ospf6_lsdb_remove_all(on
->summary_list
);
487 ospf6_lsdb_remove_all(on
->request_list
);
488 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
489 ospf6_decrement_retrans_count(lsa
);
490 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
493 THREAD_OFF(on
->thread_send_dbdesc
);
494 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
496 on
->thread_send_dbdesc
= NULL
;
497 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
498 &on
->thread_send_dbdesc
);
503 int bad_lsreq(struct thread
*thread
)
505 struct ospf6_neighbor
*on
;
506 struct ospf6_lsa
*lsa
, *lsa_next
;
507 const struct route_node
*iterend
;
509 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
512 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
515 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
516 zlog_debug("Neighbor Event %s: *BadLSReq*", on
->name
);
518 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
519 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ
);
520 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
521 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
522 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
524 ospf6_lsdb_remove_all(on
->summary_list
);
525 ospf6_lsdb_remove_all(on
->request_list
);
527 for (iterend
= ospf6_lsdb_head(on
->retrans_list
, 0, 0, 0, &lsa
); lsa
;
529 lsa_next
= ospf6_lsdb_next(iterend
, lsa
);
530 ospf6_decrement_retrans_count(lsa
);
531 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
534 THREAD_OFF(on
->thread_send_dbdesc
);
535 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
537 on
->thread_send_dbdesc
= NULL
;
538 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
539 &on
->thread_send_dbdesc
);
544 int oneway_received(struct thread
*thread
)
546 struct ospf6_neighbor
*on
;
547 struct ospf6_lsa
*lsa
, *lsa_next
;
548 const struct route_node
*iterend
;
550 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
553 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
556 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
557 zlog_debug("Neighbor Event %s: *1Way-Received*", on
->name
);
559 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
560 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD
);
561 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
563 ospf6_lsdb_remove_all(on
->summary_list
);
564 ospf6_lsdb_remove_all(on
->request_list
);
565 for (iterend
= ospf6_lsdb_head(on
->retrans_list
, 0, 0, 0, &lsa
); lsa
;
567 lsa_next
= ospf6_lsdb_next(iterend
, lsa
);
568 ospf6_decrement_retrans_count(lsa
);
569 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
572 THREAD_OFF(on
->thread_send_dbdesc
);
573 THREAD_OFF(on
->thread_send_lsreq
);
574 THREAD_OFF(on
->thread_send_lsupdate
);
575 THREAD_OFF(on
->thread_send_lsack
);
580 int inactivity_timer(struct thread
*thread
)
582 struct ospf6_neighbor
*on
;
584 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
587 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
588 zlog_debug("Neighbor Event %s: *InactivityTimer*", on
->name
);
590 on
->inactivity_timer
= NULL
;
591 on
->drouter
= on
->prev_drouter
= 0;
592 on
->bdrouter
= on
->prev_bdrouter
= 0;
594 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN
, on
,
595 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER
);
596 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
598 listnode_delete(on
->ospf6_if
->neighbor_list
, on
);
599 ospf6_neighbor_delete(on
);
606 /* show neighbor structure */
607 static void ospf6_neighbor_show(struct vty
*vty
, struct ospf6_neighbor
*on
)
616 /* Router-ID (Name) */
617 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
618 #ifdef HAVE_GETNAMEINFO
621 #endif /*HAVE_GETNAMEINFO*/
625 if (on
->inactivity_timer
) {
626 s
= monotime_until(&on
->inactivity_timer
->u
.sands
, NULL
)
633 snprintf(deadtime
, sizeof(deadtime
), "%02ld:%02ld:%02ld", h
, m
, s
);
636 if (on
->ospf6_if
->type
== OSPF_IFTYPE_POINTOPOINT
)
637 snprintf(nstate
, sizeof(nstate
), "PointToPoint");
639 if (on
->router_id
== on
->drouter
)
640 snprintf(nstate
, sizeof(nstate
), "DR");
641 else if (on
->router_id
== on
->bdrouter
)
642 snprintf(nstate
, sizeof(nstate
), "BDR");
644 snprintf(nstate
, sizeof(nstate
), "DROther");
648 monotime_since(&on
->last_changed
, &res
);
649 timerstring(&res
, duration
, sizeof(duration
));
652 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
653 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
657 vty_out(vty
, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id
,
658 on
->priority
, deadtime
, ospf6_neighbor_state_str
[on
->state
],
659 nstate
, duration
, on
->ospf6_if
->interface
->name
,
660 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
663 static void ospf6_neighbor_show_drchoice(struct vty
*vty
,
664 struct ospf6_neighbor
*on
)
667 char drouter
[16], bdrouter
[16];
669 struct timeval now
, res
;
672 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
673 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
677 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
678 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
679 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
682 timersub(&now
, &on
->last_changed
, &res
);
683 timerstring(&res
, duration
, sizeof(duration
));
685 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id
,
686 ospf6_neighbor_state_str
[on
->state
], duration
, drouter
,
687 bdrouter
, on
->ospf6_if
->interface
->name
,
688 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
691 static void ospf6_neighbor_show_detail(struct vty
*vty
,
692 struct ospf6_neighbor
*on
)
694 char drouter
[16], bdrouter
[16];
695 char linklocal_addr
[64], duration
[32];
696 struct timeval now
, res
;
697 struct ospf6_lsa
*lsa
;
699 inet_ntop(AF_INET6
, &on
->linklocal_addr
, linklocal_addr
,
700 sizeof(linklocal_addr
));
701 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
702 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
705 timersub(&now
, &on
->last_changed
, &res
);
706 timerstring(&res
, duration
, sizeof(duration
));
708 vty_out(vty
, " Neighbor %s\n", on
->name
);
709 vty_out(vty
, " Area %s via interface %s (ifindex %d)\n",
710 on
->ospf6_if
->area
->name
, on
->ospf6_if
->interface
->name
,
711 on
->ospf6_if
->interface
->ifindex
);
712 vty_out(vty
, " His IfIndex: %d Link-local address: %s\n",
713 on
->ifindex
, linklocal_addr
);
714 vty_out(vty
, " State %s for a duration of %s\n",
715 ospf6_neighbor_state_str
[on
->state
], duration
);
716 vty_out(vty
, " His choice of DR/BDR %s/%s, Priority %d\n", drouter
,
717 bdrouter
, on
->priority
);
718 vty_out(vty
, " DbDesc status: %s%s%s SeqNum: %#lx\n",
719 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
) ? "Initial "
721 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
) ? "More " : ""),
722 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
) ? "Master"
724 (unsigned long)ntohl(on
->dbdesc_seqnum
));
726 vty_out(vty
, " Summary-List: %d LSAs\n", on
->summary_list
->count
);
727 for (ALL_LSDB(on
->summary_list
, lsa
))
728 vty_out(vty
, " %s\n", lsa
->name
);
730 vty_out(vty
, " Request-List: %d LSAs\n", on
->request_list
->count
);
731 for (ALL_LSDB(on
->request_list
, lsa
))
732 vty_out(vty
, " %s\n", lsa
->name
);
734 vty_out(vty
, " Retrans-List: %d LSAs\n", on
->retrans_list
->count
);
735 for (ALL_LSDB(on
->retrans_list
, lsa
))
736 vty_out(vty
, " %s\n", lsa
->name
);
739 if (on
->thread_send_dbdesc
)
740 timersub(&on
->thread_send_dbdesc
->u
.sands
, &now
, &res
);
741 timerstring(&res
, duration
, sizeof(duration
));
742 vty_out(vty
, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
743 on
->dbdesc_list
->count
, duration
,
744 (on
->thread_send_dbdesc
? "on" : "off"));
745 for (ALL_LSDB(on
->dbdesc_list
, lsa
))
746 vty_out(vty
, " %s\n", lsa
->name
);
749 if (on
->thread_send_lsreq
)
750 timersub(&on
->thread_send_lsreq
->u
.sands
, &now
, &res
);
751 timerstring(&res
, duration
, sizeof(duration
));
752 vty_out(vty
, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
753 on
->request_list
->count
, duration
,
754 (on
->thread_send_lsreq
? "on" : "off"));
755 for (ALL_LSDB(on
->request_list
, lsa
))
756 vty_out(vty
, " %s\n", lsa
->name
);
759 if (on
->thread_send_lsupdate
)
760 timersub(&on
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
761 timerstring(&res
, duration
, sizeof(duration
));
763 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
764 on
->lsupdate_list
->count
, duration
,
765 (on
->thread_send_lsupdate
? "on" : "off"));
766 for (ALL_LSDB(on
->lsupdate_list
, lsa
))
767 vty_out(vty
, " %s\n", lsa
->name
);
770 if (on
->thread_send_lsack
)
771 timersub(&on
->thread_send_lsack
->u
.sands
, &now
, &res
);
772 timerstring(&res
, duration
, sizeof(duration
));
773 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
774 on
->lsack_list
->count
, duration
,
775 (on
->thread_send_lsack
? "on" : "off"));
776 for (ALL_LSDB(on
->lsack_list
, lsa
))
777 vty_out(vty
, " %s\n", lsa
->name
);
779 ospf6_bfd_show_info(vty
, on
->bfd_info
, 0);
782 DEFUN (show_ipv6_ospf6_neighbor
,
783 show_ipv6_ospf6_neighbor_cmd
,
784 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
790 "Display DR choices\n")
793 struct ospf6_neighbor
*on
;
794 struct ospf6_interface
*oi
;
795 struct ospf6_area
*oa
;
796 struct listnode
*i
, *j
, *k
;
797 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
799 OSPF6_CMD_CHECK_RUNNING();
800 showfunc
= ospf6_neighbor_show
;
803 if (!strncmp(argv
[idx_type
]->arg
, "de", 2))
804 showfunc
= ospf6_neighbor_show_detail
;
805 else if (!strncmp(argv
[idx_type
]->arg
, "dr", 2))
806 showfunc
= ospf6_neighbor_show_drchoice
;
809 if (showfunc
== ospf6_neighbor_show
)
810 vty_out(vty
, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
811 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
812 "Duration", "I/F", "State");
813 else if (showfunc
== ospf6_neighbor_show_drchoice
)
814 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
815 "State", "Duration", "DR", "BDR", "I/F", "State");
817 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
818 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
819 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
820 (*showfunc
)(vty
, on
);
826 DEFUN (show_ipv6_ospf6_neighbor_one
,
827 show_ipv6_ospf6_neighbor_one_cmd
,
828 "show ipv6 ospf6 neighbor A.B.C.D",
833 "Specify Router-ID as IPv4 address notation\n"
837 struct ospf6_neighbor
*on
;
838 struct ospf6_interface
*oi
;
839 struct ospf6_area
*oa
;
840 struct listnode
*i
, *j
, *k
;
841 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
844 OSPF6_CMD_CHECK_RUNNING();
845 showfunc
= ospf6_neighbor_show_detail
;
847 if ((inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
)) != 1) {
848 vty_out(vty
, "Router-ID is not parsable: %s\n",
849 argv
[idx_ipv4
]->arg
);
853 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
854 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
855 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
856 (*showfunc
)(vty
, on
);
861 void ospf6_neighbor_init(void)
863 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_cmd
);
864 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_one_cmd
);
867 DEFUN (debug_ospf6_neighbor
,
868 debug_ospf6_neighbor_cmd
,
869 "debug ospf6 neighbor [<state|event>]",
872 "Debug OSPFv3 Neighbor\n"
873 "Debug OSPFv3 Neighbor State Change\n"
874 "Debug OSPFv3 Neighbor Event\n")
877 unsigned char level
= 0;
880 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
881 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
882 else if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
883 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
885 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
887 OSPF6_DEBUG_NEIGHBOR_ON(level
);
892 DEFUN (no_debug_ospf6_neighbor
,
893 no_debug_ospf6_neighbor_cmd
,
894 "no debug ospf6 neighbor [<state|event>]",
898 "Debug OSPFv3 Neighbor\n"
899 "Debug OSPFv3 Neighbor State Change\n"
900 "Debug OSPFv3 Neighbor Event\n")
903 unsigned char level
= 0;
906 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
907 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
908 if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
909 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
911 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
913 OSPF6_DEBUG_NEIGHBOR_OFF(level
);
918 DEFUN (no_debug_ospf6
,
926 struct ospf6_lsa_handler
*handler
= NULL
;
928 OSPF6_DEBUG_ABR_OFF();
929 OSPF6_DEBUG_ASBR_OFF();
930 OSPF6_DEBUG_BROUTER_OFF();
931 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
932 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
933 OSPF6_DEBUG_FLOODING_OFF();
934 OSPF6_DEBUG_INTERFACE_OFF();
936 for (i
= 0; i
< vector_active(ospf6_lsa_handler_vector
); i
++) {
937 handler
= vector_slot(ospf6_lsa_handler_vector
, i
);
939 if (handler
!= NULL
) {
940 UNSET_FLAG(handler
->lh_debug
, OSPF6_LSA_DEBUG
);
944 for (i
= 0; i
< 6; i
++)
945 OSPF6_DEBUG_MESSAGE_OFF(i
,
946 OSPF6_DEBUG_NEIGHBOR_STATE
947 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
949 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
950 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
951 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE
);
952 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA
);
953 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER
);
954 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY
);
955 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS
);
956 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME
);
957 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE
);
958 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
);
963 int config_write_ospf6_debug_neighbor(struct vty
*vty
)
965 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
966 vty_out(vty
, "debug ospf6 neighbor\n");
967 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
))
968 vty_out(vty
, "debug ospf6 neighbor state\n");
969 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
970 vty_out(vty
, "debug ospf6 neighbor event\n");
974 void install_element_ospf6_debug_neighbor(void)
976 install_element(ENABLE_NODE
, &debug_ospf6_neighbor_cmd
);
977 install_element(ENABLE_NODE
, &no_debug_ospf6_neighbor_cmd
);
978 install_element(ENABLE_NODE
, &no_debug_ospf6_cmd
);
979 install_element(CONFIG_NODE
, &debug_ospf6_neighbor_cmd
);
980 install_element(CONFIG_NODE
, &no_debug_ospf6_neighbor_cmd
);
981 install_element(CONFIG_NODE
, &no_debug_ospf6_cmd
);