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
);
199 if ((prev_state
== OSPF6_NEIGHBOR_EXCHANGE
200 || prev_state
== OSPF6_NEIGHBOR_LOADING
)
201 && (next_state
!= OSPF6_NEIGHBOR_EXCHANGE
202 && next_state
!= OSPF6_NEIGHBOR_LOADING
))
203 ospf6_maxage_remove(on
->ospf6_if
->area
->ospf6
);
205 hook_call(ospf6_neighbor_change
, on
, next_state
, prev_state
);
206 ospf6_bfd_trigger_event(on
, prev_state
, next_state
);
209 /* RFC2328 section 10.4 */
210 static int need_adjacency(struct ospf6_neighbor
*on
)
212 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_POINTTOPOINT
213 || on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
214 || on
->ospf6_if
->state
== OSPF6_INTERFACE_BDR
)
217 if (on
->ospf6_if
->drouter
== on
->router_id
218 || on
->ospf6_if
->bdrouter
== on
->router_id
)
224 int hello_received(struct thread
*thread
)
226 struct ospf6_neighbor
*on
;
228 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
231 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
232 zlog_debug("Neighbor Event %s: *HelloReceived*", on
->name
);
234 /* reset Inactivity Timer */
235 THREAD_OFF(on
->inactivity_timer
);
236 on
->inactivity_timer
= NULL
;
237 thread_add_timer(master
, inactivity_timer
, on
,
238 on
->ospf6_if
->dead_interval
, &on
->inactivity_timer
);
240 if (on
->state
<= OSPF6_NEIGHBOR_DOWN
)
241 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
242 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD
);
247 int twoway_received(struct thread
*thread
)
249 struct ospf6_neighbor
*on
;
251 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
254 if (on
->state
> OSPF6_NEIGHBOR_INIT
)
257 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
258 zlog_debug("Neighbor Event %s: *2Way-Received*", on
->name
);
260 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
262 if (!need_adjacency(on
)) {
263 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
264 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
268 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
269 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
270 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
271 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
272 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
274 THREAD_OFF(on
->thread_send_dbdesc
);
275 on
->thread_send_dbdesc
= NULL
;
276 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
277 &on
->thread_send_dbdesc
);
282 int negotiation_done(struct thread
*thread
)
284 struct ospf6_neighbor
*on
;
285 struct ospf6_lsa
*lsa
;
287 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
290 if (on
->state
!= OSPF6_NEIGHBOR_EXSTART
)
293 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
294 zlog_debug("Neighbor Event %s: *NegotiationDone*", on
->name
);
297 ospf6_lsdb_remove_all(on
->summary_list
);
298 ospf6_lsdb_remove_all(on
->request_list
);
299 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
300 ospf6_decrement_retrans_count(lsa
);
301 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
304 /* Interface scoped LSAs */
305 for (ALL_LSDB(on
->ospf6_if
->lsdb
, lsa
)) {
306 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
307 ospf6_increment_retrans_count(lsa
);
308 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
310 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
313 /* Area scoped LSAs */
314 for (ALL_LSDB(on
->ospf6_if
->area
->lsdb
, lsa
)) {
315 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
316 ospf6_increment_retrans_count(lsa
);
317 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
319 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
323 for (ALL_LSDB(on
->ospf6_if
->area
->ospf6
->lsdb
, lsa
)) {
324 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
325 ospf6_increment_retrans_count(lsa
);
326 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
328 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
331 UNSET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
332 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE
, on
,
333 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE
);
338 int exchange_done(struct thread
*thread
)
340 struct ospf6_neighbor
*on
;
342 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
345 if (on
->state
!= OSPF6_NEIGHBOR_EXCHANGE
)
348 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
349 zlog_debug("Neighbor Event %s: *ExchangeDone*", on
->name
);
351 THREAD_OFF(on
->thread_send_dbdesc
);
352 ospf6_lsdb_remove_all(on
->dbdesc_list
);
355 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
356 on->ospf6_if->dead_interval);
359 if (on
->request_list
->count
== 0)
360 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
361 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
363 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING
, on
,
364 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
366 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
367 &on
->thread_send_lsreq
);
373 /* Check loading state. */
374 void ospf6_check_nbr_loading(struct ospf6_neighbor
*on
)
377 /* RFC2328 Section 10.9: When the neighbor responds to these requests
378 with the proper Link State Update packet(s), the Link state request
379 list is truncated and a new Link State Request packet is sent.
381 if ((on
->state
== OSPF6_NEIGHBOR_LOADING
)
382 || (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
)) {
383 if (on
->request_list
->count
== 0)
384 thread_add_event(master
, loading_done
, on
, 0, NULL
);
385 else if (on
->last_ls_req
== NULL
) {
386 if (on
->thread_send_lsreq
!= NULL
)
387 THREAD_OFF(on
->thread_send_lsreq
);
388 on
->thread_send_lsreq
= NULL
;
389 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
390 &on
->thread_send_lsreq
);
395 int loading_done(struct thread
*thread
)
397 struct ospf6_neighbor
*on
;
399 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
402 if (on
->state
!= OSPF6_NEIGHBOR_LOADING
)
405 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
406 zlog_debug("Neighbor Event %s: *LoadingDone*", on
->name
);
408 assert(on
->request_list
->count
== 0);
410 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
411 OSPF6_NEIGHBOR_EVENT_LOADING_DONE
);
416 int adj_ok(struct thread
*thread
)
418 struct ospf6_neighbor
*on
;
419 struct ospf6_lsa
*lsa
;
421 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
424 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
425 zlog_debug("Neighbor Event %s: *AdjOK?*", on
->name
);
427 if (on
->state
== OSPF6_NEIGHBOR_TWOWAY
&& need_adjacency(on
)) {
428 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
429 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
430 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
431 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
432 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
434 THREAD_OFF(on
->thread_send_dbdesc
);
435 on
->thread_send_dbdesc
= NULL
;
436 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
437 &on
->thread_send_dbdesc
);
439 } else if (on
->state
>= OSPF6_NEIGHBOR_EXSTART
&& !need_adjacency(on
)) {
440 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
441 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
442 ospf6_lsdb_remove_all(on
->summary_list
);
443 ospf6_lsdb_remove_all(on
->request_list
);
444 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
445 ospf6_decrement_retrans_count(lsa
);
446 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
453 int seqnumber_mismatch(struct thread
*thread
)
455 struct ospf6_neighbor
*on
;
456 struct ospf6_lsa
*lsa
;
458 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
461 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
464 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
465 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on
->name
);
467 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
468 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH
);
469 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
470 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
471 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
473 ospf6_lsdb_remove_all(on
->summary_list
);
474 ospf6_lsdb_remove_all(on
->request_list
);
475 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
476 ospf6_decrement_retrans_count(lsa
);
477 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
480 THREAD_OFF(on
->thread_send_dbdesc
);
481 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
483 on
->thread_send_dbdesc
= NULL
;
484 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
485 &on
->thread_send_dbdesc
);
490 int bad_lsreq(struct thread
*thread
)
492 struct ospf6_neighbor
*on
;
493 struct ospf6_lsa
*lsa
;
495 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
498 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
501 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
502 zlog_debug("Neighbor Event %s: *BadLSReq*", on
->name
);
504 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
505 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ
);
506 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
507 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
508 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
510 ospf6_lsdb_remove_all(on
->summary_list
);
511 ospf6_lsdb_remove_all(on
->request_list
);
512 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
513 ospf6_decrement_retrans_count(lsa
);
514 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
517 THREAD_OFF(on
->thread_send_dbdesc
);
518 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
520 on
->thread_send_dbdesc
= NULL
;
521 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
522 &on
->thread_send_dbdesc
);
527 int oneway_received(struct thread
*thread
)
529 struct ospf6_neighbor
*on
;
530 struct ospf6_lsa
*lsa
;
532 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
535 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
538 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
539 zlog_debug("Neighbor Event %s: *1Way-Received*", on
->name
);
541 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
542 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD
);
543 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
545 ospf6_lsdb_remove_all(on
->summary_list
);
546 ospf6_lsdb_remove_all(on
->request_list
);
547 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
548 ospf6_decrement_retrans_count(lsa
);
549 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
552 THREAD_OFF(on
->thread_send_dbdesc
);
553 THREAD_OFF(on
->thread_send_lsreq
);
554 THREAD_OFF(on
->thread_send_lsupdate
);
555 THREAD_OFF(on
->thread_send_lsack
);
560 int inactivity_timer(struct thread
*thread
)
562 struct ospf6_neighbor
*on
;
564 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
567 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
568 zlog_debug("Neighbor Event %s: *InactivityTimer*", on
->name
);
570 on
->inactivity_timer
= NULL
;
571 on
->drouter
= on
->prev_drouter
= 0;
572 on
->bdrouter
= on
->prev_bdrouter
= 0;
574 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN
, on
,
575 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER
);
576 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
578 listnode_delete(on
->ospf6_if
->neighbor_list
, on
);
579 ospf6_neighbor_delete(on
);
586 /* show neighbor structure */
587 static void ospf6_neighbor_show(struct vty
*vty
, struct ospf6_neighbor
*on
)
596 /* Router-ID (Name) */
597 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
598 #ifdef HAVE_GETNAMEINFO
601 #endif /*HAVE_GETNAMEINFO*/
605 if (on
->inactivity_timer
) {
606 s
= monotime_until(&on
->inactivity_timer
->u
.sands
, NULL
)
613 snprintf(deadtime
, sizeof(deadtime
), "%02ld:%02ld:%02ld", h
, m
, s
);
616 if (if_is_pointopoint(on
->ospf6_if
->interface
))
617 snprintf(nstate
, sizeof(nstate
), "PointToPoint");
619 if (on
->router_id
== on
->drouter
)
620 snprintf(nstate
, sizeof(nstate
), "DR");
621 else if (on
->router_id
== on
->bdrouter
)
622 snprintf(nstate
, sizeof(nstate
), "BDR");
624 snprintf(nstate
, sizeof(nstate
), "DROther");
628 monotime_since(&on
->last_changed
, &res
);
629 timerstring(&res
, duration
, sizeof(duration
));
632 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
633 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
637 vty_out(vty
, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id
,
638 on
->priority
, deadtime
, ospf6_neighbor_state_str
[on
->state
],
639 nstate
, duration
, on
->ospf6_if
->interface
->name
,
640 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
643 static void ospf6_neighbor_show_drchoice(struct vty
*vty
,
644 struct ospf6_neighbor
*on
)
647 char drouter
[16], bdrouter
[16];
649 struct timeval now
, res
;
652 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
653 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
657 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
658 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
659 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
662 timersub(&now
, &on
->last_changed
, &res
);
663 timerstring(&res
, duration
, sizeof(duration
));
665 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id
,
666 ospf6_neighbor_state_str
[on
->state
], duration
, drouter
,
667 bdrouter
, on
->ospf6_if
->interface
->name
,
668 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
671 static void ospf6_neighbor_show_detail(struct vty
*vty
,
672 struct ospf6_neighbor
*on
)
674 char drouter
[16], bdrouter
[16];
675 char linklocal_addr
[64], duration
[32];
676 struct timeval now
, res
;
677 struct ospf6_lsa
*lsa
;
679 inet_ntop(AF_INET6
, &on
->linklocal_addr
, linklocal_addr
,
680 sizeof(linklocal_addr
));
681 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
682 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
685 timersub(&now
, &on
->last_changed
, &res
);
686 timerstring(&res
, duration
, sizeof(duration
));
688 vty_out(vty
, " Neighbor %s\n", on
->name
);
689 vty_out(vty
, " Area %s via interface %s (ifindex %d)\n",
690 on
->ospf6_if
->area
->name
, on
->ospf6_if
->interface
->name
,
691 on
->ospf6_if
->interface
->ifindex
);
692 vty_out(vty
, " His IfIndex: %d Link-local address: %s\n",
693 on
->ifindex
, linklocal_addr
);
694 vty_out(vty
, " State %s for a duration of %s\n",
695 ospf6_neighbor_state_str
[on
->state
], duration
);
696 vty_out(vty
, " His choice of DR/BDR %s/%s, Priority %d\n", drouter
,
697 bdrouter
, on
->priority
);
698 vty_out(vty
, " DbDesc status: %s%s%s SeqNum: %#lx\n",
699 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
) ? "Initial "
701 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
) ? "More " : ""),
702 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
) ? "Master"
704 (u_long
)ntohl(on
->dbdesc_seqnum
));
706 vty_out(vty
, " Summary-List: %d LSAs\n", on
->summary_list
->count
);
707 for (ALL_LSDB(on
->summary_list
, lsa
))
708 vty_out(vty
, " %s\n", lsa
->name
);
710 vty_out(vty
, " Request-List: %d LSAs\n", on
->request_list
->count
);
711 for (ALL_LSDB(on
->request_list
, lsa
))
712 vty_out(vty
, " %s\n", lsa
->name
);
714 vty_out(vty
, " Retrans-List: %d LSAs\n", on
->retrans_list
->count
);
715 for (ALL_LSDB(on
->retrans_list
, lsa
))
716 vty_out(vty
, " %s\n", lsa
->name
);
719 if (on
->thread_send_dbdesc
)
720 timersub(&on
->thread_send_dbdesc
->u
.sands
, &now
, &res
);
721 timerstring(&res
, duration
, sizeof(duration
));
722 vty_out(vty
, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
723 on
->dbdesc_list
->count
, duration
,
724 (on
->thread_send_dbdesc
? "on" : "off"));
725 for (ALL_LSDB(on
->dbdesc_list
, lsa
))
726 vty_out(vty
, " %s\n", lsa
->name
);
729 if (on
->thread_send_lsreq
)
730 timersub(&on
->thread_send_lsreq
->u
.sands
, &now
, &res
);
731 timerstring(&res
, duration
, sizeof(duration
));
732 vty_out(vty
, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
733 on
->request_list
->count
, duration
,
734 (on
->thread_send_lsreq
? "on" : "off"));
735 for (ALL_LSDB(on
->request_list
, lsa
))
736 vty_out(vty
, " %s\n", lsa
->name
);
739 if (on
->thread_send_lsupdate
)
740 timersub(&on
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
741 timerstring(&res
, duration
, sizeof(duration
));
743 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
744 on
->lsupdate_list
->count
, duration
,
745 (on
->thread_send_lsupdate
? "on" : "off"));
746 for (ALL_LSDB(on
->lsupdate_list
, lsa
))
747 vty_out(vty
, " %s\n", lsa
->name
);
750 if (on
->thread_send_lsack
)
751 timersub(&on
->thread_send_lsack
->u
.sands
, &now
, &res
);
752 timerstring(&res
, duration
, sizeof(duration
));
753 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
754 on
->lsack_list
->count
, duration
,
755 (on
->thread_send_lsack
? "on" : "off"));
756 for (ALL_LSDB(on
->lsack_list
, lsa
))
757 vty_out(vty
, " %s\n", lsa
->name
);
759 ospf6_bfd_show_info(vty
, on
->bfd_info
, 0);
762 DEFUN (show_ipv6_ospf6_neighbor
,
763 show_ipv6_ospf6_neighbor_cmd
,
764 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
770 "Display DR choices\n")
773 struct ospf6_neighbor
*on
;
774 struct ospf6_interface
*oi
;
775 struct ospf6_area
*oa
;
776 struct listnode
*i
, *j
, *k
;
777 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
779 OSPF6_CMD_CHECK_RUNNING();
780 showfunc
= ospf6_neighbor_show
;
783 if (!strncmp(argv
[idx_type
]->arg
, "de", 2))
784 showfunc
= ospf6_neighbor_show_detail
;
785 else if (!strncmp(argv
[idx_type
]->arg
, "dr", 2))
786 showfunc
= ospf6_neighbor_show_drchoice
;
789 if (showfunc
== ospf6_neighbor_show
)
790 vty_out(vty
, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
791 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
792 "Duration", "I/F", "State");
793 else if (showfunc
== ospf6_neighbor_show_drchoice
)
794 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
795 "State", "Duration", "DR", "BDR", "I/F", "State");
797 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
798 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
799 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
800 (*showfunc
)(vty
, on
);
806 DEFUN (show_ipv6_ospf6_neighbor_one
,
807 show_ipv6_ospf6_neighbor_one_cmd
,
808 "show ipv6 ospf6 neighbor A.B.C.D",
813 "Specify Router-ID as IPv4 address notation\n"
817 struct ospf6_neighbor
*on
;
818 struct ospf6_interface
*oi
;
819 struct ospf6_area
*oa
;
820 struct listnode
*i
, *j
, *k
;
821 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
824 OSPF6_CMD_CHECK_RUNNING();
825 showfunc
= ospf6_neighbor_show_detail
;
827 if ((inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
)) != 1) {
828 vty_out(vty
, "Router-ID is not parsable: %s\n",
829 argv
[idx_ipv4
]->arg
);
833 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
834 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
835 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
836 (*showfunc
)(vty
, on
);
841 void ospf6_neighbor_init(void)
843 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_cmd
);
844 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_one_cmd
);
847 DEFUN (debug_ospf6_neighbor
,
848 debug_ospf6_neighbor_cmd
,
849 "debug ospf6 neighbor [<state|event>]",
852 "Debug OSPFv3 Neighbor\n"
853 "Debug OSPFv3 Neighbor State Change\n"
854 "Debug OSPFv3 Neighbor Event\n")
857 unsigned char level
= 0;
860 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
861 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
862 else if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
863 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
865 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
867 OSPF6_DEBUG_NEIGHBOR_ON(level
);
872 DEFUN (no_debug_ospf6_neighbor
,
873 no_debug_ospf6_neighbor_cmd
,
874 "no 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 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_OFF(level
);
898 DEFUN (no_debug_ospf6
,
906 struct ospf6_lsa_handler
*handler
= NULL
;
908 OSPF6_DEBUG_ABR_OFF();
909 OSPF6_DEBUG_ASBR_OFF();
910 OSPF6_DEBUG_BROUTER_OFF();
911 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
912 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
913 OSPF6_DEBUG_FLOODING_OFF();
914 OSPF6_DEBUG_INTERFACE_OFF();
916 for (i
= 0; i
< vector_active(ospf6_lsa_handler_vector
); i
++) {
917 handler
= vector_slot(ospf6_lsa_handler_vector
, i
);
919 if (handler
!= NULL
) {
920 UNSET_FLAG(handler
->debug
, OSPF6_LSA_DEBUG
);
924 for (i
= 0; i
< 6; i
++)
925 OSPF6_DEBUG_MESSAGE_OFF(i
,
926 OSPF6_DEBUG_NEIGHBOR_STATE
927 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
929 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
930 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
931 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE
);
932 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA
);
933 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER
);
934 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY
);
935 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS
);
936 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME
);
937 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE
);
938 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
);
943 int config_write_ospf6_debug_neighbor(struct vty
*vty
)
945 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
946 vty_out(vty
, "debug ospf6 neighbor\n");
947 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
))
948 vty_out(vty
, "debug ospf6 neighbor state\n");
949 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
950 vty_out(vty
, "debug ospf6 neighbor event\n");
954 void install_element_ospf6_debug_neighbor(void)
956 install_element(ENABLE_NODE
, &debug_ospf6_neighbor_cmd
);
957 install_element(ENABLE_NODE
, &no_debug_ospf6_neighbor_cmd
);
958 install_element(ENABLE_NODE
, &no_debug_ospf6_cmd
);
959 install_element(CONFIG_NODE
, &debug_ospf6_neighbor_cmd
);
960 install_element(CONFIG_NODE
, &no_debug_ospf6_neighbor_cmd
);
961 install_element(CONFIG_NODE
, &no_debug_ospf6_cmd
);