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
;
117 ospf6_lsdb_remove_all(on
->summary_list
);
118 ospf6_lsdb_remove_all(on
->request_list
);
119 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
120 ospf6_decrement_retrans_count(lsa
);
121 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
124 ospf6_lsdb_remove_all(on
->dbdesc_list
);
125 ospf6_lsdb_remove_all(on
->lsupdate_list
);
126 ospf6_lsdb_remove_all(on
->lsack_list
);
128 ospf6_lsdb_delete(on
->summary_list
);
129 ospf6_lsdb_delete(on
->request_list
);
130 ospf6_lsdb_delete(on
->retrans_list
);
132 ospf6_lsdb_delete(on
->dbdesc_list
);
133 ospf6_lsdb_delete(on
->lsupdate_list
);
134 ospf6_lsdb_delete(on
->lsack_list
);
136 THREAD_OFF(on
->inactivity_timer
);
138 THREAD_OFF(on
->thread_send_dbdesc
);
139 THREAD_OFF(on
->thread_send_lsreq
);
140 THREAD_OFF(on
->thread_send_lsupdate
);
141 THREAD_OFF(on
->thread_send_lsack
);
143 ospf6_bfd_reg_dereg_nbr(on
, ZEBRA_BFD_DEST_DEREGISTER
);
144 XFREE(MTYPE_OSPF6_NEIGHBOR
, on
);
147 static void ospf6_neighbor_state_change(uint8_t next_state
,
148 struct ospf6_neighbor
*on
, int event
)
152 prev_state
= on
->state
;
153 on
->state
= next_state
;
155 if (prev_state
== next_state
)
159 monotime(&on
->last_changed
);
162 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
)) {
163 zlog_debug("Neighbor state change %s: [%s]->[%s] (%s)",
164 on
->name
, ospf6_neighbor_state_str
[prev_state
],
165 ospf6_neighbor_state_str
[next_state
],
166 ospf6_neighbor_event_string(event
));
169 /* Optionally notify about adjacency changes */
170 if (CHECK_FLAG(on
->ospf6_if
->area
->ospf6
->config_flags
,
171 OSPF6_LOG_ADJACENCY_CHANGES
)
172 && (CHECK_FLAG(on
->ospf6_if
->area
->ospf6
->config_flags
,
173 OSPF6_LOG_ADJACENCY_DETAIL
)
174 || (next_state
== OSPF6_NEIGHBOR_FULL
)
175 || (next_state
< prev_state
)))
176 zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on
->name
,
177 ospf6_neighbor_state_str
[prev_state
],
178 ospf6_neighbor_state_str
[next_state
],
179 ospf6_neighbor_event_string(event
));
181 if (prev_state
== OSPF6_NEIGHBOR_FULL
182 || next_state
== OSPF6_NEIGHBOR_FULL
) {
183 OSPF6_ROUTER_LSA_SCHEDULE(on
->ospf6_if
->area
);
184 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
) {
185 OSPF6_NETWORK_LSA_SCHEDULE(on
->ospf6_if
);
186 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(on
->ospf6_if
);
188 if (next_state
== OSPF6_NEIGHBOR_FULL
)
189 on
->ospf6_if
->area
->intra_prefix_originate
= 1;
191 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on
->ospf6_if
->area
);
193 if ((prev_state
== OSPF6_NEIGHBOR_LOADING
||
194 prev_state
== OSPF6_NEIGHBOR_EXCHANGE
) &&
195 next_state
== OSPF6_NEIGHBOR_FULL
) {
196 OSPF6_AS_EXTERN_LSA_SCHEDULE(on
->ospf6_if
);
197 on
->ospf6_if
->area
->full_nbrs
++;
200 if (prev_state
== OSPF6_NEIGHBOR_FULL
)
201 on
->ospf6_if
->area
->full_nbrs
--;
204 if ((prev_state
== OSPF6_NEIGHBOR_EXCHANGE
205 || prev_state
== OSPF6_NEIGHBOR_LOADING
)
206 && (next_state
!= OSPF6_NEIGHBOR_EXCHANGE
207 && next_state
!= OSPF6_NEIGHBOR_LOADING
))
208 ospf6_maxage_remove(on
->ospf6_if
->area
->ospf6
);
210 hook_call(ospf6_neighbor_change
, on
, next_state
, prev_state
);
211 ospf6_bfd_trigger_event(on
, prev_state
, next_state
);
214 /* RFC2328 section 10.4 */
215 static int need_adjacency(struct ospf6_neighbor
*on
)
217 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_POINTTOPOINT
218 || on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
219 || on
->ospf6_if
->state
== OSPF6_INTERFACE_BDR
)
222 if (on
->ospf6_if
->drouter
== on
->router_id
223 || on
->ospf6_if
->bdrouter
== on
->router_id
)
229 int hello_received(struct thread
*thread
)
231 struct ospf6_neighbor
*on
;
233 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
236 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
237 zlog_debug("Neighbor Event %s: *HelloReceived*", on
->name
);
239 /* reset Inactivity Timer */
240 THREAD_OFF(on
->inactivity_timer
);
241 on
->inactivity_timer
= NULL
;
242 thread_add_timer(master
, inactivity_timer
, on
,
243 on
->ospf6_if
->dead_interval
, &on
->inactivity_timer
);
245 if (on
->state
<= OSPF6_NEIGHBOR_DOWN
)
246 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
247 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD
);
252 int twoway_received(struct thread
*thread
)
254 struct ospf6_neighbor
*on
;
256 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
259 if (on
->state
> OSPF6_NEIGHBOR_INIT
)
262 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
263 zlog_debug("Neighbor Event %s: *2Way-Received*", on
->name
);
265 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
267 if (!need_adjacency(on
)) {
268 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
269 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
273 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
274 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
275 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
276 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
277 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
279 THREAD_OFF(on
->thread_send_dbdesc
);
280 on
->thread_send_dbdesc
= NULL
;
281 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
282 &on
->thread_send_dbdesc
);
287 int negotiation_done(struct thread
*thread
)
289 struct ospf6_neighbor
*on
;
290 struct ospf6_lsa
*lsa
;
292 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
295 if (on
->state
!= OSPF6_NEIGHBOR_EXSTART
)
298 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
299 zlog_debug("Neighbor Event %s: *NegotiationDone*", on
->name
);
302 ospf6_lsdb_remove_all(on
->summary_list
);
303 ospf6_lsdb_remove_all(on
->request_list
);
304 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
305 ospf6_decrement_retrans_count(lsa
);
306 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
309 /* Interface scoped LSAs */
310 for (ALL_LSDB(on
->ospf6_if
->lsdb
, lsa
)) {
311 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
312 ospf6_increment_retrans_count(lsa
);
313 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
315 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
318 /* Area scoped LSAs */
319 for (ALL_LSDB(on
->ospf6_if
->area
->lsdb
, lsa
)) {
320 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
321 ospf6_increment_retrans_count(lsa
);
322 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
324 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
328 for (ALL_LSDB(on
->ospf6_if
->area
->ospf6
->lsdb
, lsa
)) {
329 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
330 ospf6_increment_retrans_count(lsa
);
331 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
333 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
336 UNSET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
337 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE
, on
,
338 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE
);
343 int exchange_done(struct thread
*thread
)
345 struct ospf6_neighbor
*on
;
347 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
350 if (on
->state
!= OSPF6_NEIGHBOR_EXCHANGE
)
353 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
354 zlog_debug("Neighbor Event %s: *ExchangeDone*", on
->name
);
356 THREAD_OFF(on
->thread_send_dbdesc
);
357 ospf6_lsdb_remove_all(on
->dbdesc_list
);
360 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
361 on->ospf6_if->dead_interval);
364 if (on
->request_list
->count
== 0)
365 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
366 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
368 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING
, on
,
369 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
371 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
372 &on
->thread_send_lsreq
);
378 /* Check loading state. */
379 void ospf6_check_nbr_loading(struct ospf6_neighbor
*on
)
382 /* RFC2328 Section 10.9: When the neighbor responds to these requests
383 with the proper Link State Update packet(s), the Link state request
384 list is truncated and a new Link State Request packet is sent.
386 if ((on
->state
== OSPF6_NEIGHBOR_LOADING
)
387 || (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
)) {
388 if (on
->request_list
->count
== 0)
389 thread_add_event(master
, loading_done
, on
, 0, NULL
);
390 else if (on
->last_ls_req
== NULL
) {
391 if (on
->thread_send_lsreq
!= NULL
)
392 THREAD_OFF(on
->thread_send_lsreq
);
393 on
->thread_send_lsreq
= NULL
;
394 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
395 &on
->thread_send_lsreq
);
400 int loading_done(struct thread
*thread
)
402 struct ospf6_neighbor
*on
;
404 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
407 if (on
->state
!= OSPF6_NEIGHBOR_LOADING
)
410 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
411 zlog_debug("Neighbor Event %s: *LoadingDone*", on
->name
);
413 assert(on
->request_list
->count
== 0);
415 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
416 OSPF6_NEIGHBOR_EVENT_LOADING_DONE
);
421 int adj_ok(struct thread
*thread
)
423 struct ospf6_neighbor
*on
;
424 struct ospf6_lsa
*lsa
;
426 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
429 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
430 zlog_debug("Neighbor Event %s: *AdjOK?*", on
->name
);
432 if (on
->state
== OSPF6_NEIGHBOR_TWOWAY
&& need_adjacency(on
)) {
433 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
434 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
435 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
436 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
437 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
439 THREAD_OFF(on
->thread_send_dbdesc
);
440 on
->thread_send_dbdesc
= NULL
;
441 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
442 &on
->thread_send_dbdesc
);
444 } else if (on
->state
>= OSPF6_NEIGHBOR_EXSTART
&& !need_adjacency(on
)) {
445 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
446 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
447 ospf6_lsdb_remove_all(on
->summary_list
);
448 ospf6_lsdb_remove_all(on
->request_list
);
449 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
450 ospf6_decrement_retrans_count(lsa
);
451 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
458 int seqnumber_mismatch(struct thread
*thread
)
460 struct ospf6_neighbor
*on
;
461 struct ospf6_lsa
*lsa
;
463 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
466 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
469 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
470 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on
->name
);
472 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
473 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH
);
474 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
475 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
476 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
478 ospf6_lsdb_remove_all(on
->summary_list
);
479 ospf6_lsdb_remove_all(on
->request_list
);
480 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
481 ospf6_decrement_retrans_count(lsa
);
482 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
485 THREAD_OFF(on
->thread_send_dbdesc
);
486 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
488 on
->thread_send_dbdesc
= NULL
;
489 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
490 &on
->thread_send_dbdesc
);
495 int bad_lsreq(struct thread
*thread
)
497 struct ospf6_neighbor
*on
;
498 struct ospf6_lsa
*lsa
;
500 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
503 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
506 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
507 zlog_debug("Neighbor Event %s: *BadLSReq*", on
->name
);
509 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
510 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ
);
511 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
512 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
513 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
515 ospf6_lsdb_remove_all(on
->summary_list
);
516 ospf6_lsdb_remove_all(on
->request_list
);
517 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
518 ospf6_decrement_retrans_count(lsa
);
519 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
522 THREAD_OFF(on
->thread_send_dbdesc
);
523 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
525 on
->thread_send_dbdesc
= NULL
;
526 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
527 &on
->thread_send_dbdesc
);
532 int oneway_received(struct thread
*thread
)
534 struct ospf6_neighbor
*on
;
535 struct ospf6_lsa
*lsa
;
537 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
540 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
543 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
544 zlog_debug("Neighbor Event %s: *1Way-Received*", on
->name
);
546 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
547 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD
);
548 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
550 ospf6_lsdb_remove_all(on
->summary_list
);
551 ospf6_lsdb_remove_all(on
->request_list
);
552 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
553 ospf6_decrement_retrans_count(lsa
);
554 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
557 THREAD_OFF(on
->thread_send_dbdesc
);
558 THREAD_OFF(on
->thread_send_lsreq
);
559 THREAD_OFF(on
->thread_send_lsupdate
);
560 THREAD_OFF(on
->thread_send_lsack
);
565 int inactivity_timer(struct thread
*thread
)
567 struct ospf6_neighbor
*on
;
569 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
572 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
573 zlog_debug("Neighbor Event %s: *InactivityTimer*", on
->name
);
575 on
->inactivity_timer
= NULL
;
576 on
->drouter
= on
->prev_drouter
= 0;
577 on
->bdrouter
= on
->prev_bdrouter
= 0;
579 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN
, on
,
580 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER
);
581 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
583 listnode_delete(on
->ospf6_if
->neighbor_list
, on
);
584 ospf6_neighbor_delete(on
);
591 /* show neighbor structure */
592 static void ospf6_neighbor_show(struct vty
*vty
, struct ospf6_neighbor
*on
)
601 /* Router-ID (Name) */
602 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
603 #ifdef HAVE_GETNAMEINFO
606 #endif /*HAVE_GETNAMEINFO*/
610 if (on
->inactivity_timer
) {
611 s
= monotime_until(&on
->inactivity_timer
->u
.sands
, NULL
)
618 snprintf(deadtime
, sizeof(deadtime
), "%02ld:%02ld:%02ld", h
, m
, s
);
621 if (on
->ospf6_if
->type
== OSPF_IFTYPE_POINTOPOINT
)
622 snprintf(nstate
, sizeof(nstate
), "PointToPoint");
624 if (on
->router_id
== on
->drouter
)
625 snprintf(nstate
, sizeof(nstate
), "DR");
626 else if (on
->router_id
== on
->bdrouter
)
627 snprintf(nstate
, sizeof(nstate
), "BDR");
629 snprintf(nstate
, sizeof(nstate
), "DROther");
633 monotime_since(&on
->last_changed
, &res
);
634 timerstring(&res
, duration
, sizeof(duration
));
637 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
638 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
642 vty_out(vty
, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id
,
643 on
->priority
, deadtime
, ospf6_neighbor_state_str
[on
->state
],
644 nstate
, duration
, on
->ospf6_if
->interface
->name
,
645 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
648 static void ospf6_neighbor_show_drchoice(struct vty
*vty
,
649 struct ospf6_neighbor
*on
)
652 char drouter
[16], bdrouter
[16];
654 struct timeval now
, res
;
657 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
658 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
662 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
663 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
664 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
667 timersub(&now
, &on
->last_changed
, &res
);
668 timerstring(&res
, duration
, sizeof(duration
));
670 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id
,
671 ospf6_neighbor_state_str
[on
->state
], duration
, drouter
,
672 bdrouter
, on
->ospf6_if
->interface
->name
,
673 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
676 static void ospf6_neighbor_show_detail(struct vty
*vty
,
677 struct ospf6_neighbor
*on
)
679 char drouter
[16], bdrouter
[16];
680 char linklocal_addr
[64], duration
[32];
681 struct timeval now
, res
;
682 struct ospf6_lsa
*lsa
;
684 inet_ntop(AF_INET6
, &on
->linklocal_addr
, linklocal_addr
,
685 sizeof(linklocal_addr
));
686 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
687 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
690 timersub(&now
, &on
->last_changed
, &res
);
691 timerstring(&res
, duration
, sizeof(duration
));
693 vty_out(vty
, " Neighbor %s\n", on
->name
);
694 vty_out(vty
, " Area %s via interface %s (ifindex %d)\n",
695 on
->ospf6_if
->area
->name
, on
->ospf6_if
->interface
->name
,
696 on
->ospf6_if
->interface
->ifindex
);
697 vty_out(vty
, " His IfIndex: %d Link-local address: %s\n",
698 on
->ifindex
, linklocal_addr
);
699 vty_out(vty
, " State %s for a duration of %s\n",
700 ospf6_neighbor_state_str
[on
->state
], duration
);
701 vty_out(vty
, " His choice of DR/BDR %s/%s, Priority %d\n", drouter
,
702 bdrouter
, on
->priority
);
703 vty_out(vty
, " DbDesc status: %s%s%s SeqNum: %#lx\n",
704 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
) ? "Initial "
706 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
) ? "More " : ""),
707 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
) ? "Master"
709 (unsigned long)ntohl(on
->dbdesc_seqnum
));
711 vty_out(vty
, " Summary-List: %d LSAs\n", on
->summary_list
->count
);
712 for (ALL_LSDB(on
->summary_list
, lsa
))
713 vty_out(vty
, " %s\n", lsa
->name
);
715 vty_out(vty
, " Request-List: %d LSAs\n", on
->request_list
->count
);
716 for (ALL_LSDB(on
->request_list
, lsa
))
717 vty_out(vty
, " %s\n", lsa
->name
);
719 vty_out(vty
, " Retrans-List: %d LSAs\n", on
->retrans_list
->count
);
720 for (ALL_LSDB(on
->retrans_list
, lsa
))
721 vty_out(vty
, " %s\n", lsa
->name
);
724 if (on
->thread_send_dbdesc
)
725 timersub(&on
->thread_send_dbdesc
->u
.sands
, &now
, &res
);
726 timerstring(&res
, duration
, sizeof(duration
));
727 vty_out(vty
, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
728 on
->dbdesc_list
->count
, duration
,
729 (on
->thread_send_dbdesc
? "on" : "off"));
730 for (ALL_LSDB(on
->dbdesc_list
, lsa
))
731 vty_out(vty
, " %s\n", lsa
->name
);
734 if (on
->thread_send_lsreq
)
735 timersub(&on
->thread_send_lsreq
->u
.sands
, &now
, &res
);
736 timerstring(&res
, duration
, sizeof(duration
));
737 vty_out(vty
, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
738 on
->request_list
->count
, duration
,
739 (on
->thread_send_lsreq
? "on" : "off"));
740 for (ALL_LSDB(on
->request_list
, lsa
))
741 vty_out(vty
, " %s\n", lsa
->name
);
744 if (on
->thread_send_lsupdate
)
745 timersub(&on
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
746 timerstring(&res
, duration
, sizeof(duration
));
748 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
749 on
->lsupdate_list
->count
, duration
,
750 (on
->thread_send_lsupdate
? "on" : "off"));
751 for (ALL_LSDB(on
->lsupdate_list
, lsa
))
752 vty_out(vty
, " %s\n", lsa
->name
);
755 if (on
->thread_send_lsack
)
756 timersub(&on
->thread_send_lsack
->u
.sands
, &now
, &res
);
757 timerstring(&res
, duration
, sizeof(duration
));
758 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
759 on
->lsack_list
->count
, duration
,
760 (on
->thread_send_lsack
? "on" : "off"));
761 for (ALL_LSDB(on
->lsack_list
, lsa
))
762 vty_out(vty
, " %s\n", lsa
->name
);
764 ospf6_bfd_show_info(vty
, on
->bfd_info
, 0);
767 DEFUN (show_ipv6_ospf6_neighbor
,
768 show_ipv6_ospf6_neighbor_cmd
,
769 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
775 "Display DR choices\n")
778 struct ospf6_neighbor
*on
;
779 struct ospf6_interface
*oi
;
780 struct ospf6_area
*oa
;
781 struct listnode
*i
, *j
, *k
;
782 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
784 OSPF6_CMD_CHECK_RUNNING();
785 showfunc
= ospf6_neighbor_show
;
788 if (!strncmp(argv
[idx_type
]->arg
, "de", 2))
789 showfunc
= ospf6_neighbor_show_detail
;
790 else if (!strncmp(argv
[idx_type
]->arg
, "dr", 2))
791 showfunc
= ospf6_neighbor_show_drchoice
;
794 if (showfunc
== ospf6_neighbor_show
)
795 vty_out(vty
, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
796 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
797 "Duration", "I/F", "State");
798 else if (showfunc
== ospf6_neighbor_show_drchoice
)
799 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
800 "State", "Duration", "DR", "BDR", "I/F", "State");
802 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
803 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
804 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
805 (*showfunc
)(vty
, on
);
811 DEFUN (show_ipv6_ospf6_neighbor_one
,
812 show_ipv6_ospf6_neighbor_one_cmd
,
813 "show ipv6 ospf6 neighbor A.B.C.D",
818 "Specify Router-ID as IPv4 address notation\n"
822 struct ospf6_neighbor
*on
;
823 struct ospf6_interface
*oi
;
824 struct ospf6_area
*oa
;
825 struct listnode
*i
, *j
, *k
;
826 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
829 OSPF6_CMD_CHECK_RUNNING();
830 showfunc
= ospf6_neighbor_show_detail
;
832 if ((inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
)) != 1) {
833 vty_out(vty
, "Router-ID is not parsable: %s\n",
834 argv
[idx_ipv4
]->arg
);
838 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
839 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
840 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
841 (*showfunc
)(vty
, on
);
846 void ospf6_neighbor_init(void)
848 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_cmd
);
849 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_one_cmd
);
852 DEFUN (debug_ospf6_neighbor
,
853 debug_ospf6_neighbor_cmd
,
854 "debug ospf6 neighbor [<state|event>]",
857 "Debug OSPFv3 Neighbor\n"
858 "Debug OSPFv3 Neighbor State Change\n"
859 "Debug OSPFv3 Neighbor Event\n")
862 unsigned char level
= 0;
865 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
866 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
867 else if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
868 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
870 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
872 OSPF6_DEBUG_NEIGHBOR_ON(level
);
877 DEFUN (no_debug_ospf6_neighbor
,
878 no_debug_ospf6_neighbor_cmd
,
879 "no debug ospf6 neighbor [<state|event>]",
883 "Debug OSPFv3 Neighbor\n"
884 "Debug OSPFv3 Neighbor State Change\n"
885 "Debug OSPFv3 Neighbor Event\n")
888 unsigned char level
= 0;
891 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
892 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
893 if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
894 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
896 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
898 OSPF6_DEBUG_NEIGHBOR_OFF(level
);
903 DEFUN (no_debug_ospf6
,
911 struct ospf6_lsa_handler
*handler
= NULL
;
913 OSPF6_DEBUG_ABR_OFF();
914 OSPF6_DEBUG_ASBR_OFF();
915 OSPF6_DEBUG_BROUTER_OFF();
916 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
917 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
918 OSPF6_DEBUG_FLOODING_OFF();
919 OSPF6_DEBUG_INTERFACE_OFF();
921 for (i
= 0; i
< vector_active(ospf6_lsa_handler_vector
); i
++) {
922 handler
= vector_slot(ospf6_lsa_handler_vector
, i
);
924 if (handler
!= NULL
) {
925 UNSET_FLAG(handler
->lh_debug
, OSPF6_LSA_DEBUG
);
929 for (i
= 0; i
< 6; i
++)
930 OSPF6_DEBUG_MESSAGE_OFF(i
,
931 OSPF6_DEBUG_NEIGHBOR_STATE
932 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
934 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
935 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
936 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE
);
937 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA
);
938 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER
);
939 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY
);
940 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS
);
941 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME
);
942 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE
);
943 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
);
948 int config_write_ospf6_debug_neighbor(struct vty
*vty
)
950 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
951 vty_out(vty
, "debug ospf6 neighbor\n");
952 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
))
953 vty_out(vty
, "debug ospf6 neighbor state\n");
954 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
955 vty_out(vty
, "debug ospf6 neighbor event\n");
959 void install_element_ospf6_debug_neighbor(void)
961 install_element(ENABLE_NODE
, &debug_ospf6_neighbor_cmd
);
962 install_element(ENABLE_NODE
, &no_debug_ospf6_neighbor_cmd
);
963 install_element(ENABLE_NODE
, &no_debug_ospf6_cmd
);
964 install_element(CONFIG_NODE
, &debug_ospf6_neighbor_cmd
);
965 install_element(CONFIG_NODE
, &no_debug_ospf6_neighbor_cmd
);
966 install_element(CONFIG_NODE
, &no_debug_ospf6_cmd
);