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(uint32_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(uint32_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(uint8_t 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 if (next_state
== OSPF6_NEIGHBOR_FULL
)
192 on
->ospf6_if
->area
->intra_prefix_originate
= 1;
194 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on
->ospf6_if
->area
);
196 if ((prev_state
== OSPF6_NEIGHBOR_LOADING
||
197 prev_state
== OSPF6_NEIGHBOR_EXCHANGE
) &&
198 next_state
== OSPF6_NEIGHBOR_FULL
) {
199 OSPF6_AS_EXTERN_LSA_SCHEDULE(on
->ospf6_if
);
200 on
->ospf6_if
->area
->full_nbrs
++;
203 if (prev_state
== OSPF6_NEIGHBOR_FULL
)
204 on
->ospf6_if
->area
->full_nbrs
--;
207 if ((prev_state
== OSPF6_NEIGHBOR_EXCHANGE
208 || prev_state
== OSPF6_NEIGHBOR_LOADING
)
209 && (next_state
!= OSPF6_NEIGHBOR_EXCHANGE
210 && next_state
!= OSPF6_NEIGHBOR_LOADING
))
211 ospf6_maxage_remove(on
->ospf6_if
->area
->ospf6
);
213 hook_call(ospf6_neighbor_change
, on
, next_state
, prev_state
);
214 ospf6_bfd_trigger_event(on
, prev_state
, next_state
);
217 /* RFC2328 section 10.4 */
218 static int need_adjacency(struct ospf6_neighbor
*on
)
220 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_POINTTOPOINT
221 || on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
222 || on
->ospf6_if
->state
== OSPF6_INTERFACE_BDR
)
225 if (on
->ospf6_if
->drouter
== on
->router_id
226 || on
->ospf6_if
->bdrouter
== on
->router_id
)
232 int hello_received(struct thread
*thread
)
234 struct ospf6_neighbor
*on
;
236 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
239 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
240 zlog_debug("Neighbor Event %s: *HelloReceived*", on
->name
);
242 /* reset Inactivity Timer */
243 THREAD_OFF(on
->inactivity_timer
);
244 on
->inactivity_timer
= NULL
;
245 thread_add_timer(master
, inactivity_timer
, on
,
246 on
->ospf6_if
->dead_interval
, &on
->inactivity_timer
);
248 if (on
->state
<= OSPF6_NEIGHBOR_DOWN
)
249 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
250 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD
);
255 int twoway_received(struct thread
*thread
)
257 struct ospf6_neighbor
*on
;
259 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
262 if (on
->state
> OSPF6_NEIGHBOR_INIT
)
265 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
266 zlog_debug("Neighbor Event %s: *2Way-Received*", on
->name
);
268 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
270 if (!need_adjacency(on
)) {
271 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
272 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
276 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
277 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
278 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
279 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
280 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
282 THREAD_OFF(on
->thread_send_dbdesc
);
283 on
->thread_send_dbdesc
= NULL
;
284 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
285 &on
->thread_send_dbdesc
);
290 int negotiation_done(struct thread
*thread
)
292 struct ospf6_neighbor
*on
;
293 struct ospf6_lsa
*lsa
;
295 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
298 if (on
->state
!= OSPF6_NEIGHBOR_EXSTART
)
301 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
302 zlog_debug("Neighbor Event %s: *NegotiationDone*", on
->name
);
305 ospf6_lsdb_remove_all(on
->summary_list
);
306 ospf6_lsdb_remove_all(on
->request_list
);
307 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
308 ospf6_decrement_retrans_count(lsa
);
309 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
312 /* Interface scoped LSAs */
313 for (ALL_LSDB(on
->ospf6_if
->lsdb
, lsa
)) {
314 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
315 ospf6_increment_retrans_count(lsa
);
316 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
318 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
321 /* Area scoped LSAs */
322 for (ALL_LSDB(on
->ospf6_if
->area
->lsdb
, lsa
)) {
323 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
324 ospf6_increment_retrans_count(lsa
);
325 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
327 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
331 for (ALL_LSDB(on
->ospf6_if
->area
->ospf6
->lsdb
, lsa
)) {
332 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
333 ospf6_increment_retrans_count(lsa
);
334 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
336 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
339 UNSET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
340 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE
, on
,
341 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE
);
346 int exchange_done(struct thread
*thread
)
348 struct ospf6_neighbor
*on
;
350 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
353 if (on
->state
!= OSPF6_NEIGHBOR_EXCHANGE
)
356 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
357 zlog_debug("Neighbor Event %s: *ExchangeDone*", on
->name
);
359 THREAD_OFF(on
->thread_send_dbdesc
);
360 ospf6_lsdb_remove_all(on
->dbdesc_list
);
363 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
364 on->ospf6_if->dead_interval);
367 if (on
->request_list
->count
== 0)
368 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
369 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
371 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING
, on
,
372 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
374 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
375 &on
->thread_send_lsreq
);
381 /* Check loading state. */
382 void ospf6_check_nbr_loading(struct ospf6_neighbor
*on
)
385 /* RFC2328 Section 10.9: When the neighbor responds to these requests
386 with the proper Link State Update packet(s), the Link state request
387 list is truncated and a new Link State Request packet is sent.
389 if ((on
->state
== OSPF6_NEIGHBOR_LOADING
)
390 || (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
)) {
391 if (on
->request_list
->count
== 0)
392 thread_add_event(master
, loading_done
, on
, 0, NULL
);
393 else if (on
->last_ls_req
== NULL
) {
394 if (on
->thread_send_lsreq
!= NULL
)
395 THREAD_OFF(on
->thread_send_lsreq
);
396 on
->thread_send_lsreq
= NULL
;
397 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
398 &on
->thread_send_lsreq
);
403 int loading_done(struct thread
*thread
)
405 struct ospf6_neighbor
*on
;
407 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
410 if (on
->state
!= OSPF6_NEIGHBOR_LOADING
)
413 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
414 zlog_debug("Neighbor Event %s: *LoadingDone*", on
->name
);
416 assert(on
->request_list
->count
== 0);
418 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
419 OSPF6_NEIGHBOR_EVENT_LOADING_DONE
);
424 int adj_ok(struct thread
*thread
)
426 struct ospf6_neighbor
*on
;
427 struct ospf6_lsa
*lsa
;
429 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
432 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
433 zlog_debug("Neighbor Event %s: *AdjOK?*", on
->name
);
435 if (on
->state
== OSPF6_NEIGHBOR_TWOWAY
&& need_adjacency(on
)) {
436 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
437 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
438 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
439 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
440 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
442 THREAD_OFF(on
->thread_send_dbdesc
);
443 on
->thread_send_dbdesc
= NULL
;
444 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
445 &on
->thread_send_dbdesc
);
447 } else if (on
->state
>= OSPF6_NEIGHBOR_EXSTART
&& !need_adjacency(on
)) {
448 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
449 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
450 ospf6_lsdb_remove_all(on
->summary_list
);
451 ospf6_lsdb_remove_all(on
->request_list
);
452 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
453 ospf6_decrement_retrans_count(lsa
);
454 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
461 int seqnumber_mismatch(struct thread
*thread
)
463 struct ospf6_neighbor
*on
;
464 struct ospf6_lsa
*lsa
;
466 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
469 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
472 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
473 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on
->name
);
475 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
476 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH
);
477 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
478 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
479 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
481 ospf6_lsdb_remove_all(on
->summary_list
);
482 ospf6_lsdb_remove_all(on
->request_list
);
483 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
484 ospf6_decrement_retrans_count(lsa
);
485 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
488 THREAD_OFF(on
->thread_send_dbdesc
);
489 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
491 on
->thread_send_dbdesc
= NULL
;
492 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
493 &on
->thread_send_dbdesc
);
498 int bad_lsreq(struct thread
*thread
)
500 struct ospf6_neighbor
*on
;
501 struct ospf6_lsa
*lsa
;
503 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
506 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
509 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
510 zlog_debug("Neighbor Event %s: *BadLSReq*", on
->name
);
512 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
513 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ
);
514 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
515 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
516 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
518 ospf6_lsdb_remove_all(on
->summary_list
);
519 ospf6_lsdb_remove_all(on
->request_list
);
520 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
521 ospf6_decrement_retrans_count(lsa
);
522 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
525 THREAD_OFF(on
->thread_send_dbdesc
);
526 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
528 on
->thread_send_dbdesc
= NULL
;
529 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
530 &on
->thread_send_dbdesc
);
535 int oneway_received(struct thread
*thread
)
537 struct ospf6_neighbor
*on
;
538 struct ospf6_lsa
*lsa
;
540 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
543 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
546 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
547 zlog_debug("Neighbor Event %s: *1Way-Received*", on
->name
);
549 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
550 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD
);
551 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
553 ospf6_lsdb_remove_all(on
->summary_list
);
554 ospf6_lsdb_remove_all(on
->request_list
);
555 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
556 ospf6_decrement_retrans_count(lsa
);
557 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
560 THREAD_OFF(on
->thread_send_dbdesc
);
561 THREAD_OFF(on
->thread_send_lsreq
);
562 THREAD_OFF(on
->thread_send_lsupdate
);
563 THREAD_OFF(on
->thread_send_lsack
);
568 int inactivity_timer(struct thread
*thread
)
570 struct ospf6_neighbor
*on
;
572 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
575 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
576 zlog_debug("Neighbor Event %s: *InactivityTimer*", on
->name
);
578 on
->inactivity_timer
= NULL
;
579 on
->drouter
= on
->prev_drouter
= 0;
580 on
->bdrouter
= on
->prev_bdrouter
= 0;
582 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN
, on
,
583 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER
);
584 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
586 listnode_delete(on
->ospf6_if
->neighbor_list
, on
);
587 ospf6_neighbor_delete(on
);
594 /* show neighbor structure */
595 static void ospf6_neighbor_show(struct vty
*vty
, struct ospf6_neighbor
*on
)
604 /* Router-ID (Name) */
605 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
606 #ifdef HAVE_GETNAMEINFO
609 #endif /*HAVE_GETNAMEINFO*/
613 if (on
->inactivity_timer
) {
614 s
= monotime_until(&on
->inactivity_timer
->u
.sands
, NULL
)
621 snprintf(deadtime
, sizeof(deadtime
), "%02ld:%02ld:%02ld", h
, m
, s
);
624 if (if_is_pointopoint(on
->ospf6_if
->interface
))
625 snprintf(nstate
, sizeof(nstate
), "PointToPoint");
627 if (on
->router_id
== on
->drouter
)
628 snprintf(nstate
, sizeof(nstate
), "DR");
629 else if (on
->router_id
== on
->bdrouter
)
630 snprintf(nstate
, sizeof(nstate
), "BDR");
632 snprintf(nstate
, sizeof(nstate
), "DROther");
636 monotime_since(&on
->last_changed
, &res
);
637 timerstring(&res
, duration
, sizeof(duration
));
640 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
641 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
645 vty_out(vty
, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id
,
646 on
->priority
, deadtime
, ospf6_neighbor_state_str
[on
->state
],
647 nstate
, duration
, on
->ospf6_if
->interface
->name
,
648 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
651 static void ospf6_neighbor_show_drchoice(struct vty
*vty
,
652 struct ospf6_neighbor
*on
)
655 char drouter
[16], bdrouter
[16];
657 struct timeval now
, res
;
660 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
661 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
665 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
666 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
667 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
670 timersub(&now
, &on
->last_changed
, &res
);
671 timerstring(&res
, duration
, sizeof(duration
));
673 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id
,
674 ospf6_neighbor_state_str
[on
->state
], duration
, drouter
,
675 bdrouter
, on
->ospf6_if
->interface
->name
,
676 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
679 static void ospf6_neighbor_show_detail(struct vty
*vty
,
680 struct ospf6_neighbor
*on
)
682 char drouter
[16], bdrouter
[16];
683 char linklocal_addr
[64], duration
[32];
684 struct timeval now
, res
;
685 struct ospf6_lsa
*lsa
;
687 inet_ntop(AF_INET6
, &on
->linklocal_addr
, linklocal_addr
,
688 sizeof(linklocal_addr
));
689 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
690 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
693 timersub(&now
, &on
->last_changed
, &res
);
694 timerstring(&res
, duration
, sizeof(duration
));
696 vty_out(vty
, " Neighbor %s\n", on
->name
);
697 vty_out(vty
, " Area %s via interface %s (ifindex %d)\n",
698 on
->ospf6_if
->area
->name
, on
->ospf6_if
->interface
->name
,
699 on
->ospf6_if
->interface
->ifindex
);
700 vty_out(vty
, " His IfIndex: %d Link-local address: %s\n",
701 on
->ifindex
, linklocal_addr
);
702 vty_out(vty
, " State %s for a duration of %s\n",
703 ospf6_neighbor_state_str
[on
->state
], duration
);
704 vty_out(vty
, " His choice of DR/BDR %s/%s, Priority %d\n", drouter
,
705 bdrouter
, on
->priority
);
706 vty_out(vty
, " DbDesc status: %s%s%s SeqNum: %#lx\n",
707 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
) ? "Initial "
709 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
) ? "More " : ""),
710 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
) ? "Master"
712 (unsigned long)ntohl(on
->dbdesc_seqnum
));
714 vty_out(vty
, " Summary-List: %d LSAs\n", on
->summary_list
->count
);
715 for (ALL_LSDB(on
->summary_list
, lsa
))
716 vty_out(vty
, " %s\n", lsa
->name
);
718 vty_out(vty
, " Request-List: %d LSAs\n", on
->request_list
->count
);
719 for (ALL_LSDB(on
->request_list
, lsa
))
720 vty_out(vty
, " %s\n", lsa
->name
);
722 vty_out(vty
, " Retrans-List: %d LSAs\n", on
->retrans_list
->count
);
723 for (ALL_LSDB(on
->retrans_list
, lsa
))
724 vty_out(vty
, " %s\n", lsa
->name
);
727 if (on
->thread_send_dbdesc
)
728 timersub(&on
->thread_send_dbdesc
->u
.sands
, &now
, &res
);
729 timerstring(&res
, duration
, sizeof(duration
));
730 vty_out(vty
, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
731 on
->dbdesc_list
->count
, duration
,
732 (on
->thread_send_dbdesc
? "on" : "off"));
733 for (ALL_LSDB(on
->dbdesc_list
, lsa
))
734 vty_out(vty
, " %s\n", lsa
->name
);
737 if (on
->thread_send_lsreq
)
738 timersub(&on
->thread_send_lsreq
->u
.sands
, &now
, &res
);
739 timerstring(&res
, duration
, sizeof(duration
));
740 vty_out(vty
, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
741 on
->request_list
->count
, duration
,
742 (on
->thread_send_lsreq
? "on" : "off"));
743 for (ALL_LSDB(on
->request_list
, lsa
))
744 vty_out(vty
, " %s\n", lsa
->name
);
747 if (on
->thread_send_lsupdate
)
748 timersub(&on
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
749 timerstring(&res
, duration
, sizeof(duration
));
751 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
752 on
->lsupdate_list
->count
, duration
,
753 (on
->thread_send_lsupdate
? "on" : "off"));
754 for (ALL_LSDB(on
->lsupdate_list
, lsa
))
755 vty_out(vty
, " %s\n", lsa
->name
);
758 if (on
->thread_send_lsack
)
759 timersub(&on
->thread_send_lsack
->u
.sands
, &now
, &res
);
760 timerstring(&res
, duration
, sizeof(duration
));
761 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
762 on
->lsack_list
->count
, duration
,
763 (on
->thread_send_lsack
? "on" : "off"));
764 for (ALL_LSDB(on
->lsack_list
, lsa
))
765 vty_out(vty
, " %s\n", lsa
->name
);
767 ospf6_bfd_show_info(vty
, on
->bfd_info
, 0);
770 DEFUN (show_ipv6_ospf6_neighbor
,
771 show_ipv6_ospf6_neighbor_cmd
,
772 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
778 "Display DR choices\n")
781 struct ospf6_neighbor
*on
;
782 struct ospf6_interface
*oi
;
783 struct ospf6_area
*oa
;
784 struct listnode
*i
, *j
, *k
;
785 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
787 OSPF6_CMD_CHECK_RUNNING();
788 showfunc
= ospf6_neighbor_show
;
791 if (!strncmp(argv
[idx_type
]->arg
, "de", 2))
792 showfunc
= ospf6_neighbor_show_detail
;
793 else if (!strncmp(argv
[idx_type
]->arg
, "dr", 2))
794 showfunc
= ospf6_neighbor_show_drchoice
;
797 if (showfunc
== ospf6_neighbor_show
)
798 vty_out(vty
, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
799 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
800 "Duration", "I/F", "State");
801 else if (showfunc
== ospf6_neighbor_show_drchoice
)
802 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
803 "State", "Duration", "DR", "BDR", "I/F", "State");
805 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
806 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
807 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
808 (*showfunc
)(vty
, on
);
814 DEFUN (show_ipv6_ospf6_neighbor_one
,
815 show_ipv6_ospf6_neighbor_one_cmd
,
816 "show ipv6 ospf6 neighbor A.B.C.D",
821 "Specify Router-ID as IPv4 address notation\n"
825 struct ospf6_neighbor
*on
;
826 struct ospf6_interface
*oi
;
827 struct ospf6_area
*oa
;
828 struct listnode
*i
, *j
, *k
;
829 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
832 OSPF6_CMD_CHECK_RUNNING();
833 showfunc
= ospf6_neighbor_show_detail
;
835 if ((inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
)) != 1) {
836 vty_out(vty
, "Router-ID is not parsable: %s\n",
837 argv
[idx_ipv4
]->arg
);
841 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
842 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
843 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
844 (*showfunc
)(vty
, on
);
849 void ospf6_neighbor_init(void)
851 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_cmd
);
852 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_one_cmd
);
855 DEFUN (debug_ospf6_neighbor
,
856 debug_ospf6_neighbor_cmd
,
857 "debug ospf6 neighbor [<state|event>]",
860 "Debug OSPFv3 Neighbor\n"
861 "Debug OSPFv3 Neighbor State Change\n"
862 "Debug OSPFv3 Neighbor Event\n")
865 unsigned char level
= 0;
868 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
869 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
870 else if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
871 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
873 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
875 OSPF6_DEBUG_NEIGHBOR_ON(level
);
880 DEFUN (no_debug_ospf6_neighbor
,
881 no_debug_ospf6_neighbor_cmd
,
882 "no debug ospf6 neighbor [<state|event>]",
886 "Debug OSPFv3 Neighbor\n"
887 "Debug OSPFv3 Neighbor State Change\n"
888 "Debug OSPFv3 Neighbor Event\n")
891 unsigned char level
= 0;
894 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
895 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
896 if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
897 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
899 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
901 OSPF6_DEBUG_NEIGHBOR_OFF(level
);
906 DEFUN (no_debug_ospf6
,
914 struct ospf6_lsa_handler
*handler
= NULL
;
916 OSPF6_DEBUG_ABR_OFF();
917 OSPF6_DEBUG_ASBR_OFF();
918 OSPF6_DEBUG_BROUTER_OFF();
919 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
920 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
921 OSPF6_DEBUG_FLOODING_OFF();
922 OSPF6_DEBUG_INTERFACE_OFF();
924 for (i
= 0; i
< vector_active(ospf6_lsa_handler_vector
); i
++) {
925 handler
= vector_slot(ospf6_lsa_handler_vector
, i
);
927 if (handler
!= NULL
) {
928 UNSET_FLAG(handler
->debug
, OSPF6_LSA_DEBUG
);
932 for (i
= 0; i
< 6; i
++)
933 OSPF6_DEBUG_MESSAGE_OFF(i
,
934 OSPF6_DEBUG_NEIGHBOR_STATE
935 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
937 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
938 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
939 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE
);
940 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA
);
941 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER
);
942 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY
);
943 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS
);
944 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME
);
945 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE
);
946 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
);
951 int config_write_ospf6_debug_neighbor(struct vty
*vty
)
953 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
954 vty_out(vty
, "debug ospf6 neighbor\n");
955 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
))
956 vty_out(vty
, "debug ospf6 neighbor state\n");
957 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
958 vty_out(vty
, "debug ospf6 neighbor event\n");
962 void install_element_ospf6_debug_neighbor(void)
964 install_element(ENABLE_NODE
, &debug_ospf6_neighbor_cmd
);
965 install_element(ENABLE_NODE
, &no_debug_ospf6_neighbor_cmd
);
966 install_element(ENABLE_NODE
, &no_debug_ospf6_cmd
);
967 install_element(CONFIG_NODE
, &debug_ospf6_neighbor_cmd
);
968 install_element(CONFIG_NODE
, &no_debug_ospf6_neighbor_cmd
);
969 install_element(CONFIG_NODE
, &no_debug_ospf6_cmd
);