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
;
62 return (ntohl(ona
->router_id
) < ntohl(onb
->router_id
) ? -1 : 1);
65 struct ospf6_neighbor
*ospf6_neighbor_lookup(u_int32_t router_id
,
66 struct ospf6_interface
*oi
)
69 struct ospf6_neighbor
*on
;
71 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, n
, on
))
72 if (on
->router_id
== router_id
)
75 return (struct ospf6_neighbor
*)NULL
;
78 /* create ospf6_neighbor */
79 struct ospf6_neighbor
*ospf6_neighbor_create(u_int32_t router_id
,
80 struct ospf6_interface
*oi
)
82 struct ospf6_neighbor
*on
;
85 on
= (struct ospf6_neighbor
*)XMALLOC(MTYPE_OSPF6_NEIGHBOR
,
86 sizeof(struct ospf6_neighbor
));
88 zlog_warn("neighbor: malloc failed");
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
,
97 on
->state
= OSPF6_NEIGHBOR_DOWN
;
99 monotime(&on
->last_changed
);
100 on
->router_id
= router_id
;
102 on
->summary_list
= ospf6_lsdb_create(on
);
103 on
->request_list
= ospf6_lsdb_create(on
);
104 on
->retrans_list
= ospf6_lsdb_create(on
);
106 on
->dbdesc_list
= ospf6_lsdb_create(on
);
107 on
->lsupdate_list
= ospf6_lsdb_create(on
);
108 on
->lsack_list
= ospf6_lsdb_create(on
);
110 listnode_add_sort(oi
->neighbor_list
, on
);
112 ospf6_bfd_info_nbr_create(oi
, on
);
116 void ospf6_neighbor_delete(struct ospf6_neighbor
*on
)
118 struct ospf6_lsa
*lsa
;
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
);
127 ospf6_lsdb_remove_all(on
->dbdesc_list
);
128 ospf6_lsdb_remove_all(on
->lsupdate_list
);
129 ospf6_lsdb_remove_all(on
->lsack_list
);
131 ospf6_lsdb_delete(on
->summary_list
);
132 ospf6_lsdb_delete(on
->request_list
);
133 ospf6_lsdb_delete(on
->retrans_list
);
135 ospf6_lsdb_delete(on
->dbdesc_list
);
136 ospf6_lsdb_delete(on
->lsupdate_list
);
137 ospf6_lsdb_delete(on
->lsack_list
);
139 THREAD_OFF(on
->inactivity_timer
);
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
);
146 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_DEREGISTER
);
147 XFREE(MTYPE_OSPF6_NEIGHBOR
, on
);
150 static void ospf6_neighbor_state_change(u_char next_state
,
151 struct ospf6_neighbor
*on
, int event
)
155 prev_state
= on
->state
;
156 on
->state
= next_state
;
158 if (prev_state
== next_state
)
162 monotime(&on
->last_changed
);
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
));
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
));
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
);
191 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on
->ospf6_if
->area
);
193 if (prev_state
== OSPF6_NEIGHBOR_LOADING
194 && next_state
== OSPF6_NEIGHBOR_FULL
) {
195 OSPF6_AS_EXTERN_LSA_SCHEDULE(on
->ospf6_if
);
196 on
->ospf6_if
->area
->full_nbrs
++;
199 if (prev_state
== OSPF6_NEIGHBOR_FULL
)
200 on
->ospf6_if
->area
->full_nbrs
--;
203 if ((prev_state
== OSPF6_NEIGHBOR_EXCHANGE
204 || prev_state
== OSPF6_NEIGHBOR_LOADING
)
205 && (next_state
!= OSPF6_NEIGHBOR_EXCHANGE
206 && next_state
!= OSPF6_NEIGHBOR_LOADING
))
207 ospf6_maxage_remove(on
->ospf6_if
->area
->ospf6
);
209 hook_call(ospf6_neighbor_change
, on
, next_state
, prev_state
);
210 ospf6_bfd_trigger_event(on
, prev_state
, next_state
);
213 /* RFC2328 section 10.4 */
214 static int need_adjacency(struct ospf6_neighbor
*on
)
216 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_POINTTOPOINT
217 || on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
218 || on
->ospf6_if
->state
== OSPF6_INTERFACE_BDR
)
221 if (on
->ospf6_if
->drouter
== on
->router_id
222 || on
->ospf6_if
->bdrouter
== on
->router_id
)
228 int hello_received(struct thread
*thread
)
230 struct ospf6_neighbor
*on
;
232 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
235 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
236 zlog_debug("Neighbor Event %s: *HelloReceived*", on
->name
);
238 /* reset Inactivity Timer */
239 THREAD_OFF(on
->inactivity_timer
);
240 on
->inactivity_timer
= NULL
;
241 thread_add_timer(master
, inactivity_timer
, on
,
242 on
->ospf6_if
->dead_interval
, &on
->inactivity_timer
);
244 if (on
->state
<= OSPF6_NEIGHBOR_DOWN
)
245 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
246 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD
);
251 int twoway_received(struct thread
*thread
)
253 struct ospf6_neighbor
*on
;
255 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
258 if (on
->state
> OSPF6_NEIGHBOR_INIT
)
261 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
262 zlog_debug("Neighbor Event %s: *2Way-Received*", on
->name
);
264 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
266 if (!need_adjacency(on
)) {
267 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
268 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
272 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
273 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
274 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
275 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
276 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
278 THREAD_OFF(on
->thread_send_dbdesc
);
279 on
->thread_send_dbdesc
= NULL
;
280 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
281 &on
->thread_send_dbdesc
);
286 int negotiation_done(struct thread
*thread
)
288 struct ospf6_neighbor
*on
;
289 struct ospf6_lsa
*lsa
;
291 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
294 if (on
->state
!= OSPF6_NEIGHBOR_EXSTART
)
297 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
298 zlog_debug("Neighbor Event %s: *NegotiationDone*", on
->name
);
301 ospf6_lsdb_remove_all(on
->summary_list
);
302 ospf6_lsdb_remove_all(on
->request_list
);
303 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
304 ospf6_decrement_retrans_count(lsa
);
305 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
308 /* Interface scoped LSAs */
309 for (ALL_LSDB(on
->ospf6_if
->lsdb
, lsa
)) {
310 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
311 ospf6_increment_retrans_count(lsa
);
312 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
314 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
317 /* Area scoped LSAs */
318 for (ALL_LSDB(on
->ospf6_if
->area
->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
);
327 for (ALL_LSDB(on
->ospf6_if
->area
->ospf6
->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
);
335 UNSET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
336 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE
, on
,
337 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE
);
342 int exchange_done(struct thread
*thread
)
344 struct ospf6_neighbor
*on
;
346 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
349 if (on
->state
!= OSPF6_NEIGHBOR_EXCHANGE
)
352 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
353 zlog_debug("Neighbor Event %s: *ExchangeDone*", on
->name
);
355 THREAD_OFF(on
->thread_send_dbdesc
);
356 ospf6_lsdb_remove_all(on
->dbdesc_list
);
359 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
360 on->ospf6_if->dead_interval);
363 if (on
->request_list
->count
== 0)
364 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
365 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
367 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING
, on
,
368 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
370 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
371 &on
->thread_send_lsreq
);
377 /* Check loading state. */
378 void ospf6_check_nbr_loading(struct ospf6_neighbor
*on
)
381 /* RFC2328 Section 10.9: When the neighbor responds to these requests
382 with the proper Link State Update packet(s), the Link state request
383 list is truncated and a new Link State Request packet is sent.
385 if ((on
->state
== OSPF6_NEIGHBOR_LOADING
)
386 || (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
)) {
387 if (on
->request_list
->count
== 0)
388 thread_add_event(master
, loading_done
, on
, 0, NULL
);
389 else if (on
->last_ls_req
== NULL
) {
390 if (on
->thread_send_lsreq
!= NULL
)
391 THREAD_OFF(on
->thread_send_lsreq
);
392 on
->thread_send_lsreq
= NULL
;
393 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
394 &on
->thread_send_lsreq
);
399 int loading_done(struct thread
*thread
)
401 struct ospf6_neighbor
*on
;
403 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
406 if (on
->state
!= OSPF6_NEIGHBOR_LOADING
)
409 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
410 zlog_debug("Neighbor Event %s: *LoadingDone*", on
->name
);
412 assert(on
->request_list
->count
== 0);
414 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
415 OSPF6_NEIGHBOR_EVENT_LOADING_DONE
);
420 int adj_ok(struct thread
*thread
)
422 struct ospf6_neighbor
*on
;
423 struct ospf6_lsa
*lsa
;
425 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
428 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
429 zlog_debug("Neighbor Event %s: *AdjOK?*", on
->name
);
431 if (on
->state
== OSPF6_NEIGHBOR_TWOWAY
&& need_adjacency(on
)) {
432 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
433 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
434 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
435 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
436 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
438 THREAD_OFF(on
->thread_send_dbdesc
);
439 on
->thread_send_dbdesc
= NULL
;
440 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
441 &on
->thread_send_dbdesc
);
443 } else if (on
->state
>= OSPF6_NEIGHBOR_EXSTART
&& !need_adjacency(on
)) {
444 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
445 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
446 ospf6_lsdb_remove_all(on
->summary_list
);
447 ospf6_lsdb_remove_all(on
->request_list
);
448 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
449 ospf6_decrement_retrans_count(lsa
);
450 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
457 int seqnumber_mismatch(struct thread
*thread
)
459 struct ospf6_neighbor
*on
;
460 struct ospf6_lsa
*lsa
;
462 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
465 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
468 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
469 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on
->name
);
471 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
472 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH
);
473 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
474 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
475 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
477 ospf6_lsdb_remove_all(on
->summary_list
);
478 ospf6_lsdb_remove_all(on
->request_list
);
479 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
480 ospf6_decrement_retrans_count(lsa
);
481 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
484 THREAD_OFF(on
->thread_send_dbdesc
);
485 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
487 on
->thread_send_dbdesc
= NULL
;
488 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
489 &on
->thread_send_dbdesc
);
494 int bad_lsreq(struct thread
*thread
)
496 struct ospf6_neighbor
*on
;
497 struct ospf6_lsa
*lsa
;
499 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
502 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
505 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
506 zlog_debug("Neighbor Event %s: *BadLSReq*", on
->name
);
508 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
509 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ
);
510 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
511 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
512 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
514 ospf6_lsdb_remove_all(on
->summary_list
);
515 ospf6_lsdb_remove_all(on
->request_list
);
516 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
517 ospf6_decrement_retrans_count(lsa
);
518 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
521 THREAD_OFF(on
->thread_send_dbdesc
);
522 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
524 on
->thread_send_dbdesc
= NULL
;
525 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
526 &on
->thread_send_dbdesc
);
531 int oneway_received(struct thread
*thread
)
533 struct ospf6_neighbor
*on
;
534 struct ospf6_lsa
*lsa
;
536 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
539 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
542 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
543 zlog_debug("Neighbor Event %s: *1Way-Received*", on
->name
);
545 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
546 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD
);
547 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
549 ospf6_lsdb_remove_all(on
->summary_list
);
550 ospf6_lsdb_remove_all(on
->request_list
);
551 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
552 ospf6_decrement_retrans_count(lsa
);
553 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
556 THREAD_OFF(on
->thread_send_dbdesc
);
557 THREAD_OFF(on
->thread_send_lsreq
);
558 THREAD_OFF(on
->thread_send_lsupdate
);
559 THREAD_OFF(on
->thread_send_lsack
);
564 int inactivity_timer(struct thread
*thread
)
566 struct ospf6_neighbor
*on
;
568 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
571 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
572 zlog_debug("Neighbor Event %s: *InactivityTimer*", on
->name
);
574 on
->inactivity_timer
= NULL
;
575 on
->drouter
= on
->prev_drouter
= 0;
576 on
->bdrouter
= on
->prev_bdrouter
= 0;
578 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN
, on
,
579 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER
);
580 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
582 listnode_delete(on
->ospf6_if
->neighbor_list
, on
);
583 ospf6_neighbor_delete(on
);
590 /* show neighbor structure */
591 static void ospf6_neighbor_show(struct vty
*vty
, struct ospf6_neighbor
*on
)
600 /* Router-ID (Name) */
601 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
602 #ifdef HAVE_GETNAMEINFO
605 #endif /*HAVE_GETNAMEINFO*/
609 if (on
->inactivity_timer
) {
610 s
= monotime_until(&on
->inactivity_timer
->u
.sands
, NULL
)
617 snprintf(deadtime
, sizeof(deadtime
), "%02ld:%02ld:%02ld", h
, m
, s
);
620 if (if_is_pointopoint(on
->ospf6_if
->interface
))
621 snprintf(nstate
, sizeof(nstate
), "PointToPoint");
623 if (on
->router_id
== on
->drouter
)
624 snprintf(nstate
, sizeof(nstate
), "DR");
625 else if (on
->router_id
== on
->bdrouter
)
626 snprintf(nstate
, sizeof(nstate
), "BDR");
628 snprintf(nstate
, sizeof(nstate
), "DROther");
632 monotime_since(&on
->last_changed
, &res
);
633 timerstring(&res
, duration
, sizeof(duration
));
636 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
637 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
641 vty_out(vty
, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id
,
642 on
->priority
, deadtime
, ospf6_neighbor_state_str
[on
->state
],
643 nstate
, duration
, on
->ospf6_if
->interface
->name
,
644 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
647 static void ospf6_neighbor_show_drchoice(struct vty
*vty
,
648 struct ospf6_neighbor
*on
)
651 char drouter
[16], bdrouter
[16];
653 struct timeval now
, res
;
656 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
657 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
661 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
662 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
663 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
666 timersub(&now
, &on
->last_changed
, &res
);
667 timerstring(&res
, duration
, sizeof(duration
));
669 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id
,
670 ospf6_neighbor_state_str
[on
->state
], duration
, drouter
,
671 bdrouter
, on
->ospf6_if
->interface
->name
,
672 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
675 static void ospf6_neighbor_show_detail(struct vty
*vty
,
676 struct ospf6_neighbor
*on
)
678 char drouter
[16], bdrouter
[16];
679 char linklocal_addr
[64], duration
[32];
680 struct timeval now
, res
;
681 struct ospf6_lsa
*lsa
;
683 inet_ntop(AF_INET6
, &on
->linklocal_addr
, linklocal_addr
,
684 sizeof(linklocal_addr
));
685 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
686 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
689 timersub(&now
, &on
->last_changed
, &res
);
690 timerstring(&res
, duration
, sizeof(duration
));
692 vty_out(vty
, " Neighbor %s\n", on
->name
);
693 vty_out(vty
, " Area %s via interface %s (ifindex %d)\n",
694 on
->ospf6_if
->area
->name
, on
->ospf6_if
->interface
->name
,
695 on
->ospf6_if
->interface
->ifindex
);
696 vty_out(vty
, " His IfIndex: %d Link-local address: %s\n",
697 on
->ifindex
, linklocal_addr
);
698 vty_out(vty
, " State %s for a duration of %s\n",
699 ospf6_neighbor_state_str
[on
->state
], duration
);
700 vty_out(vty
, " His choice of DR/BDR %s/%s, Priority %d\n", drouter
,
701 bdrouter
, on
->priority
);
702 vty_out(vty
, " DbDesc status: %s%s%s SeqNum: %#lx\n",
703 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
) ? "Initial "
705 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
) ? "More " : ""),
706 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
) ? "Master"
708 (u_long
)ntohl(on
->dbdesc_seqnum
));
710 vty_out(vty
, " Summary-List: %d LSAs\n", on
->summary_list
->count
);
711 for (ALL_LSDB(on
->summary_list
, lsa
))
712 vty_out(vty
, " %s\n", lsa
->name
);
714 vty_out(vty
, " Request-List: %d LSAs\n", on
->request_list
->count
);
715 for (ALL_LSDB(on
->request_list
, lsa
))
716 vty_out(vty
, " %s\n", lsa
->name
);
718 vty_out(vty
, " Retrans-List: %d LSAs\n", on
->retrans_list
->count
);
719 for (ALL_LSDB(on
->retrans_list
, lsa
))
720 vty_out(vty
, " %s\n", lsa
->name
);
723 if (on
->thread_send_dbdesc
)
724 timersub(&on
->thread_send_dbdesc
->u
.sands
, &now
, &res
);
725 timerstring(&res
, duration
, sizeof(duration
));
726 vty_out(vty
, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
727 on
->dbdesc_list
->count
, duration
,
728 (on
->thread_send_dbdesc
? "on" : "off"));
729 for (ALL_LSDB(on
->dbdesc_list
, lsa
))
730 vty_out(vty
, " %s\n", lsa
->name
);
733 if (on
->thread_send_lsreq
)
734 timersub(&on
->thread_send_lsreq
->u
.sands
, &now
, &res
);
735 timerstring(&res
, duration
, sizeof(duration
));
736 vty_out(vty
, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
737 on
->request_list
->count
, duration
,
738 (on
->thread_send_lsreq
? "on" : "off"));
739 for (ALL_LSDB(on
->request_list
, lsa
))
740 vty_out(vty
, " %s\n", lsa
->name
);
743 if (on
->thread_send_lsupdate
)
744 timersub(&on
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
745 timerstring(&res
, duration
, sizeof(duration
));
747 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
748 on
->lsupdate_list
->count
, duration
,
749 (on
->thread_send_lsupdate
? "on" : "off"));
750 for (ALL_LSDB(on
->lsupdate_list
, lsa
))
751 vty_out(vty
, " %s\n", lsa
->name
);
754 if (on
->thread_send_lsack
)
755 timersub(&on
->thread_send_lsack
->u
.sands
, &now
, &res
);
756 timerstring(&res
, duration
, sizeof(duration
));
757 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
758 on
->lsack_list
->count
, duration
,
759 (on
->thread_send_lsack
? "on" : "off"));
760 for (ALL_LSDB(on
->lsack_list
, lsa
))
761 vty_out(vty
, " %s\n", lsa
->name
);
763 ospf6_bfd_show_info(vty
, on
->bfd_info
, 0);
766 DEFUN (show_ipv6_ospf6_neighbor
,
767 show_ipv6_ospf6_neighbor_cmd
,
768 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
774 "Display DR choices\n")
777 struct ospf6_neighbor
*on
;
778 struct ospf6_interface
*oi
;
779 struct ospf6_area
*oa
;
780 struct listnode
*i
, *j
, *k
;
781 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
783 OSPF6_CMD_CHECK_RUNNING();
784 showfunc
= ospf6_neighbor_show
;
787 if (!strncmp(argv
[idx_type
]->arg
, "de", 2))
788 showfunc
= ospf6_neighbor_show_detail
;
789 else if (!strncmp(argv
[idx_type
]->arg
, "dr", 2))
790 showfunc
= ospf6_neighbor_show_drchoice
;
793 if (showfunc
== ospf6_neighbor_show
)
794 vty_out(vty
, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
795 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
796 "Duration", "I/F", "State");
797 else if (showfunc
== ospf6_neighbor_show_drchoice
)
798 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
799 "State", "Duration", "DR", "BDR", "I/F", "State");
801 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
802 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
803 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
804 (*showfunc
)(vty
, on
);
810 DEFUN (show_ipv6_ospf6_neighbor_one
,
811 show_ipv6_ospf6_neighbor_one_cmd
,
812 "show ipv6 ospf6 neighbor A.B.C.D",
817 "Specify Router-ID as IPv4 address notation\n"
821 struct ospf6_neighbor
*on
;
822 struct ospf6_interface
*oi
;
823 struct ospf6_area
*oa
;
824 struct listnode
*i
, *j
, *k
;
825 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
828 OSPF6_CMD_CHECK_RUNNING();
829 showfunc
= ospf6_neighbor_show_detail
;
831 if ((inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
)) != 1) {
832 vty_out(vty
, "Router-ID is not parsable: %s\n",
833 argv
[idx_ipv4
]->arg
);
837 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
838 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
839 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
840 (*showfunc
)(vty
, on
);
845 void ospf6_neighbor_init(void)
847 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_cmd
);
848 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_one_cmd
);
851 DEFUN (debug_ospf6_neighbor
,
852 debug_ospf6_neighbor_cmd
,
853 "debug ospf6 neighbor [<state|event>]",
856 "Debug OSPFv3 Neighbor\n"
857 "Debug OSPFv3 Neighbor State Change\n"
858 "Debug OSPFv3 Neighbor Event\n")
861 unsigned char level
= 0;
864 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
865 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
866 else if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
867 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
869 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
871 OSPF6_DEBUG_NEIGHBOR_ON(level
);
876 DEFUN (no_debug_ospf6_neighbor
,
877 no_debug_ospf6_neighbor_cmd
,
878 "no debug ospf6 neighbor [<state|event>]",
882 "Debug OSPFv3 Neighbor\n"
883 "Debug OSPFv3 Neighbor State Change\n"
884 "Debug OSPFv3 Neighbor Event\n")
887 unsigned char level
= 0;
890 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
891 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
892 if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
893 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
895 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
897 OSPF6_DEBUG_NEIGHBOR_OFF(level
);
902 DEFUN (no_debug_ospf6
,
910 struct ospf6_lsa_handler
*handler
= NULL
;
912 OSPF6_DEBUG_ABR_OFF();
913 OSPF6_DEBUG_ASBR_OFF();
914 OSPF6_DEBUG_BROUTER_OFF();
915 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
916 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
917 OSPF6_DEBUG_FLOODING_OFF();
918 OSPF6_DEBUG_INTERFACE_OFF();
920 for (i
= 0; i
< vector_active(ospf6_lsa_handler_vector
); i
++) {
921 handler
= vector_slot(ospf6_lsa_handler_vector
, i
);
923 if (handler
!= NULL
) {
924 UNSET_FLAG(handler
->debug
, OSPF6_LSA_DEBUG
);
928 for (i
= 0; i
< 6; i
++)
929 OSPF6_DEBUG_MESSAGE_OFF(i
,
930 OSPF6_DEBUG_NEIGHBOR_STATE
931 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
933 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
934 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
935 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE
);
936 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA
);
937 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER
);
938 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY
);
939 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS
);
940 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME
);
941 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE
);
942 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
);
947 int config_write_ospf6_debug_neighbor(struct vty
*vty
)
949 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
950 vty_out(vty
, "debug ospf6 neighbor\n");
951 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
))
952 vty_out(vty
, "debug ospf6 neighbor state\n");
953 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
954 vty_out(vty
, "debug ospf6 neighbor event\n");
958 void install_element_ospf6_debug_neighbor(void)
960 install_element(ENABLE_NODE
, &debug_ospf6_neighbor_cmd
);
961 install_element(ENABLE_NODE
, &no_debug_ospf6_neighbor_cmd
);
962 install_element(ENABLE_NODE
, &no_debug_ospf6_cmd
);
963 install_element(CONFIG_NODE
, &debug_ospf6_neighbor_cmd
);
964 install_element(CONFIG_NODE
, &no_debug_ospf6_neighbor_cmd
);
965 install_element(CONFIG_NODE
, &no_debug_ospf6_cmd
);