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
);
194 if ((prev_state
== OSPF6_NEIGHBOR_EXCHANGE
195 || prev_state
== OSPF6_NEIGHBOR_LOADING
)
196 && (next_state
!= OSPF6_NEIGHBOR_EXCHANGE
197 && next_state
!= OSPF6_NEIGHBOR_LOADING
))
198 ospf6_maxage_remove(on
->ospf6_if
->area
->ospf6
);
200 hook_call(ospf6_neighbor_change
, on
, next_state
, prev_state
);
201 ospf6_bfd_trigger_event(on
, prev_state
, next_state
);
204 /* RFC2328 section 10.4 */
205 static int need_adjacency(struct ospf6_neighbor
*on
)
207 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_POINTTOPOINT
208 || on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
209 || on
->ospf6_if
->state
== OSPF6_INTERFACE_BDR
)
212 if (on
->ospf6_if
->drouter
== on
->router_id
213 || on
->ospf6_if
->bdrouter
== on
->router_id
)
219 int hello_received(struct thread
*thread
)
221 struct ospf6_neighbor
*on
;
223 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
226 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
227 zlog_debug("Neighbor Event %s: *HelloReceived*", on
->name
);
229 /* reset Inactivity Timer */
230 THREAD_OFF(on
->inactivity_timer
);
231 on
->inactivity_timer
= NULL
;
232 thread_add_timer(master
, inactivity_timer
, on
,
233 on
->ospf6_if
->dead_interval
, &on
->inactivity_timer
);
235 if (on
->state
<= OSPF6_NEIGHBOR_DOWN
)
236 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
237 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD
);
242 int twoway_received(struct thread
*thread
)
244 struct ospf6_neighbor
*on
;
246 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
249 if (on
->state
> OSPF6_NEIGHBOR_INIT
)
252 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
253 zlog_debug("Neighbor Event %s: *2Way-Received*", on
->name
);
255 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
257 if (!need_adjacency(on
)) {
258 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
259 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
263 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
264 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
265 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
266 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
267 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
269 THREAD_OFF(on
->thread_send_dbdesc
);
270 on
->thread_send_dbdesc
= NULL
;
271 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
272 &on
->thread_send_dbdesc
);
277 int negotiation_done(struct thread
*thread
)
279 struct ospf6_neighbor
*on
;
280 struct ospf6_lsa
*lsa
;
282 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
285 if (on
->state
!= OSPF6_NEIGHBOR_EXSTART
)
288 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
289 zlog_debug("Neighbor Event %s: *NegotiationDone*", on
->name
);
292 ospf6_lsdb_remove_all(on
->summary_list
);
293 ospf6_lsdb_remove_all(on
->request_list
);
294 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
295 ospf6_decrement_retrans_count(lsa
);
296 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
299 /* Interface scoped LSAs */
300 for (ALL_LSDB(on
->ospf6_if
->lsdb
, lsa
)) {
301 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
302 ospf6_increment_retrans_count(lsa
);
303 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
305 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
308 /* Area scoped LSAs */
309 for (ALL_LSDB(on
->ospf6_if
->area
->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
);
318 for (ALL_LSDB(on
->ospf6_if
->area
->ospf6
->lsdb
, lsa
)) {
319 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
320 ospf6_increment_retrans_count(lsa
);
321 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
323 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
326 UNSET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
327 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE
, on
,
328 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE
);
333 int exchange_done(struct thread
*thread
)
335 struct ospf6_neighbor
*on
;
337 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
340 if (on
->state
!= OSPF6_NEIGHBOR_EXCHANGE
)
343 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
344 zlog_debug("Neighbor Event %s: *ExchangeDone*", on
->name
);
346 THREAD_OFF(on
->thread_send_dbdesc
);
347 ospf6_lsdb_remove_all(on
->dbdesc_list
);
350 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
351 on->ospf6_if->dead_interval);
354 if (on
->request_list
->count
== 0)
355 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
356 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
358 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING
, on
,
359 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
361 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
362 &on
->thread_send_lsreq
);
368 /* Check loading state. */
369 void ospf6_check_nbr_loading(struct ospf6_neighbor
*on
)
372 /* RFC2328 Section 10.9: When the neighbor responds to these requests
373 with the proper Link State Update packet(s), the Link state request
374 list is truncated and a new Link State Request packet is sent.
376 if ((on
->state
== OSPF6_NEIGHBOR_LOADING
)
377 || (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
)) {
378 if (on
->request_list
->count
== 0)
379 thread_add_event(master
, loading_done
, on
, 0, NULL
);
380 else if (on
->last_ls_req
== NULL
) {
381 if (on
->thread_send_lsreq
!= NULL
)
382 THREAD_OFF(on
->thread_send_lsreq
);
383 on
->thread_send_lsreq
= NULL
;
384 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
385 &on
->thread_send_lsreq
);
390 int loading_done(struct thread
*thread
)
392 struct ospf6_neighbor
*on
;
394 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
397 if (on
->state
!= OSPF6_NEIGHBOR_LOADING
)
400 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
401 zlog_debug("Neighbor Event %s: *LoadingDone*", on
->name
);
403 assert(on
->request_list
->count
== 0);
405 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
406 OSPF6_NEIGHBOR_EVENT_LOADING_DONE
);
411 int adj_ok(struct thread
*thread
)
413 struct ospf6_neighbor
*on
;
414 struct ospf6_lsa
*lsa
;
416 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
419 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
420 zlog_debug("Neighbor Event %s: *AdjOK?*", on
->name
);
422 if (on
->state
== OSPF6_NEIGHBOR_TWOWAY
&& need_adjacency(on
)) {
423 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
424 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
425 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
426 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
427 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
429 THREAD_OFF(on
->thread_send_dbdesc
);
430 on
->thread_send_dbdesc
= NULL
;
431 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
432 &on
->thread_send_dbdesc
);
434 } else if (on
->state
>= OSPF6_NEIGHBOR_EXSTART
&& !need_adjacency(on
)) {
435 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
436 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
437 ospf6_lsdb_remove_all(on
->summary_list
);
438 ospf6_lsdb_remove_all(on
->request_list
);
439 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
440 ospf6_decrement_retrans_count(lsa
);
441 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
448 int seqnumber_mismatch(struct thread
*thread
)
450 struct ospf6_neighbor
*on
;
451 struct ospf6_lsa
*lsa
;
453 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
456 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
459 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
460 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on
->name
);
462 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
463 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH
);
464 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
465 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
466 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
468 ospf6_lsdb_remove_all(on
->summary_list
);
469 ospf6_lsdb_remove_all(on
->request_list
);
470 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
471 ospf6_decrement_retrans_count(lsa
);
472 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
475 THREAD_OFF(on
->thread_send_dbdesc
);
476 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
478 on
->thread_send_dbdesc
= NULL
;
479 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
480 &on
->thread_send_dbdesc
);
485 int bad_lsreq(struct thread
*thread
)
487 struct ospf6_neighbor
*on
;
488 struct ospf6_lsa
*lsa
;
490 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
493 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
496 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
497 zlog_debug("Neighbor Event %s: *BadLSReq*", on
->name
);
499 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
500 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ
);
501 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
502 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
503 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
505 ospf6_lsdb_remove_all(on
->summary_list
);
506 ospf6_lsdb_remove_all(on
->request_list
);
507 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
508 ospf6_decrement_retrans_count(lsa
);
509 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
512 THREAD_OFF(on
->thread_send_dbdesc
);
513 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
515 on
->thread_send_dbdesc
= NULL
;
516 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
517 &on
->thread_send_dbdesc
);
522 int oneway_received(struct thread
*thread
)
524 struct ospf6_neighbor
*on
;
525 struct ospf6_lsa
*lsa
;
527 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
530 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
533 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
534 zlog_debug("Neighbor Event %s: *1Way-Received*", on
->name
);
536 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
537 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD
);
538 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
540 ospf6_lsdb_remove_all(on
->summary_list
);
541 ospf6_lsdb_remove_all(on
->request_list
);
542 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
543 ospf6_decrement_retrans_count(lsa
);
544 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
547 THREAD_OFF(on
->thread_send_dbdesc
);
548 THREAD_OFF(on
->thread_send_lsreq
);
549 THREAD_OFF(on
->thread_send_lsupdate
);
550 THREAD_OFF(on
->thread_send_lsack
);
555 int inactivity_timer(struct thread
*thread
)
557 struct ospf6_neighbor
*on
;
559 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
562 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
563 zlog_debug("Neighbor Event %s: *InactivityTimer*", on
->name
);
565 on
->inactivity_timer
= NULL
;
566 on
->drouter
= on
->prev_drouter
= 0;
567 on
->bdrouter
= on
->prev_bdrouter
= 0;
569 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN
, on
,
570 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER
);
571 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
573 listnode_delete(on
->ospf6_if
->neighbor_list
, on
);
574 ospf6_neighbor_delete(on
);
581 /* show neighbor structure */
582 static void ospf6_neighbor_show(struct vty
*vty
, struct ospf6_neighbor
*on
)
591 /* Router-ID (Name) */
592 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
593 #ifdef HAVE_GETNAMEINFO
596 #endif /*HAVE_GETNAMEINFO*/
600 if (on
->inactivity_timer
) {
601 s
= monotime_until(&on
->inactivity_timer
->u
.sands
, NULL
)
608 snprintf(deadtime
, sizeof(deadtime
), "%02ld:%02ld:%02ld", h
, m
, s
);
611 if (if_is_pointopoint(on
->ospf6_if
->interface
))
612 snprintf(nstate
, sizeof(nstate
), "PointToPoint");
614 if (on
->router_id
== on
->drouter
)
615 snprintf(nstate
, sizeof(nstate
), "DR");
616 else if (on
->router_id
== on
->bdrouter
)
617 snprintf(nstate
, sizeof(nstate
), "BDR");
619 snprintf(nstate
, sizeof(nstate
), "DROther");
623 monotime_since(&on
->last_changed
, &res
);
624 timerstring(&res
, duration
, sizeof(duration
));
627 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
628 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
632 vty_out(vty
, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id
,
633 on
->priority
, deadtime
, ospf6_neighbor_state_str
[on
->state
],
634 nstate
, duration
, on
->ospf6_if
->interface
->name
,
635 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
638 static void ospf6_neighbor_show_drchoice(struct vty
*vty
,
639 struct ospf6_neighbor
*on
)
642 char drouter
[16], bdrouter
[16];
644 struct timeval now
, res
;
647 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
648 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
652 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
653 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
654 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
657 timersub(&now
, &on
->last_changed
, &res
);
658 timerstring(&res
, duration
, sizeof(duration
));
660 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id
,
661 ospf6_neighbor_state_str
[on
->state
], duration
, drouter
,
662 bdrouter
, on
->ospf6_if
->interface
->name
,
663 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
666 static void ospf6_neighbor_show_detail(struct vty
*vty
,
667 struct ospf6_neighbor
*on
)
669 char drouter
[16], bdrouter
[16];
670 char linklocal_addr
[64], duration
[32];
671 struct timeval now
, res
;
672 struct ospf6_lsa
*lsa
;
674 inet_ntop(AF_INET6
, &on
->linklocal_addr
, linklocal_addr
,
675 sizeof(linklocal_addr
));
676 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
677 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
680 timersub(&now
, &on
->last_changed
, &res
);
681 timerstring(&res
, duration
, sizeof(duration
));
683 vty_out(vty
, " Neighbor %s\n", on
->name
);
684 vty_out(vty
, " Area %s via interface %s (ifindex %d)\n",
685 on
->ospf6_if
->area
->name
, on
->ospf6_if
->interface
->name
,
686 on
->ospf6_if
->interface
->ifindex
);
687 vty_out(vty
, " His IfIndex: %d Link-local address: %s\n",
688 on
->ifindex
, linklocal_addr
);
689 vty_out(vty
, " State %s for a duration of %s\n",
690 ospf6_neighbor_state_str
[on
->state
], duration
);
691 vty_out(vty
, " His choice of DR/BDR %s/%s, Priority %d\n", drouter
,
692 bdrouter
, on
->priority
);
693 vty_out(vty
, " DbDesc status: %s%s%s SeqNum: %#lx\n",
694 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
) ? "Initial "
696 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
) ? "More " : ""),
697 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
) ? "Master"
699 (u_long
)ntohl(on
->dbdesc_seqnum
));
701 vty_out(vty
, " Summary-List: %d LSAs\n", on
->summary_list
->count
);
702 for (ALL_LSDB(on
->summary_list
, lsa
))
703 vty_out(vty
, " %s\n", lsa
->name
);
705 vty_out(vty
, " Request-List: %d LSAs\n", on
->request_list
->count
);
706 for (ALL_LSDB(on
->request_list
, lsa
))
707 vty_out(vty
, " %s\n", lsa
->name
);
709 vty_out(vty
, " Retrans-List: %d LSAs\n", on
->retrans_list
->count
);
710 for (ALL_LSDB(on
->retrans_list
, lsa
))
711 vty_out(vty
, " %s\n", lsa
->name
);
714 if (on
->thread_send_dbdesc
)
715 timersub(&on
->thread_send_dbdesc
->u
.sands
, &now
, &res
);
716 timerstring(&res
, duration
, sizeof(duration
));
717 vty_out(vty
, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
718 on
->dbdesc_list
->count
, duration
,
719 (on
->thread_send_dbdesc
? "on" : "off"));
720 for (ALL_LSDB(on
->dbdesc_list
, lsa
))
721 vty_out(vty
, " %s\n", lsa
->name
);
724 if (on
->thread_send_lsreq
)
725 timersub(&on
->thread_send_lsreq
->u
.sands
, &now
, &res
);
726 timerstring(&res
, duration
, sizeof(duration
));
727 vty_out(vty
, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
728 on
->request_list
->count
, duration
,
729 (on
->thread_send_lsreq
? "on" : "off"));
730 for (ALL_LSDB(on
->request_list
, lsa
))
731 vty_out(vty
, " %s\n", lsa
->name
);
734 if (on
->thread_send_lsupdate
)
735 timersub(&on
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
736 timerstring(&res
, duration
, sizeof(duration
));
738 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
739 on
->lsupdate_list
->count
, duration
,
740 (on
->thread_send_lsupdate
? "on" : "off"));
741 for (ALL_LSDB(on
->lsupdate_list
, lsa
))
742 vty_out(vty
, " %s\n", lsa
->name
);
745 if (on
->thread_send_lsack
)
746 timersub(&on
->thread_send_lsack
->u
.sands
, &now
, &res
);
747 timerstring(&res
, duration
, sizeof(duration
));
748 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
749 on
->lsack_list
->count
, duration
,
750 (on
->thread_send_lsack
? "on" : "off"));
751 for (ALL_LSDB(on
->lsack_list
, lsa
))
752 vty_out(vty
, " %s\n", lsa
->name
);
754 ospf6_bfd_show_info(vty
, on
->bfd_info
, 0);
757 DEFUN (show_ipv6_ospf6_neighbor
,
758 show_ipv6_ospf6_neighbor_cmd
,
759 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
765 "Display DR choices\n")
768 struct ospf6_neighbor
*on
;
769 struct ospf6_interface
*oi
;
770 struct ospf6_area
*oa
;
771 struct listnode
*i
, *j
, *k
;
772 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
774 OSPF6_CMD_CHECK_RUNNING();
775 showfunc
= ospf6_neighbor_show
;
778 if (!strncmp(argv
[idx_type
]->arg
, "de", 2))
779 showfunc
= ospf6_neighbor_show_detail
;
780 else if (!strncmp(argv
[idx_type
]->arg
, "dr", 2))
781 showfunc
= ospf6_neighbor_show_drchoice
;
784 if (showfunc
== ospf6_neighbor_show
)
785 vty_out(vty
, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
786 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
787 "Duration", "I/F", "State");
788 else if (showfunc
== ospf6_neighbor_show_drchoice
)
789 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
790 "State", "Duration", "DR", "BDR", "I/F", "State");
792 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
793 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
794 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
795 (*showfunc
)(vty
, on
);
801 DEFUN (show_ipv6_ospf6_neighbor_one
,
802 show_ipv6_ospf6_neighbor_one_cmd
,
803 "show ipv6 ospf6 neighbor A.B.C.D",
808 "Specify Router-ID as IPv4 address notation\n"
812 struct ospf6_neighbor
*on
;
813 struct ospf6_interface
*oi
;
814 struct ospf6_area
*oa
;
815 struct listnode
*i
, *j
, *k
;
816 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
819 OSPF6_CMD_CHECK_RUNNING();
820 showfunc
= ospf6_neighbor_show_detail
;
822 if ((inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
)) != 1) {
823 vty_out(vty
, "Router-ID is not parsable: %s\n",
824 argv
[idx_ipv4
]->arg
);
828 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
829 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
830 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
831 (*showfunc
)(vty
, on
);
836 void ospf6_neighbor_init(void)
838 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_cmd
);
839 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_one_cmd
);
842 DEFUN (debug_ospf6_neighbor
,
843 debug_ospf6_neighbor_cmd
,
844 "debug ospf6 neighbor [<state|event>]",
847 "Debug OSPFv3 Neighbor\n"
848 "Debug OSPFv3 Neighbor State Change\n"
849 "Debug OSPFv3 Neighbor Event\n")
852 unsigned char level
= 0;
855 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
856 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
857 else if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
858 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
860 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
862 OSPF6_DEBUG_NEIGHBOR_ON(level
);
867 DEFUN (no_debug_ospf6_neighbor
,
868 no_debug_ospf6_neighbor_cmd
,
869 "no debug ospf6 neighbor [<state|event>]",
873 "Debug OSPFv3 Neighbor\n"
874 "Debug OSPFv3 Neighbor State Change\n"
875 "Debug OSPFv3 Neighbor Event\n")
878 unsigned char level
= 0;
881 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
882 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
883 if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
884 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
886 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
888 OSPF6_DEBUG_NEIGHBOR_OFF(level
);
893 DEFUN (no_debug_ospf6
,
901 struct ospf6_lsa_handler
*handler
= NULL
;
903 OSPF6_DEBUG_ABR_OFF();
904 OSPF6_DEBUG_ASBR_OFF();
905 OSPF6_DEBUG_BROUTER_OFF();
906 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
907 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
908 OSPF6_DEBUG_FLOODING_OFF();
909 OSPF6_DEBUG_INTERFACE_OFF();
911 for (i
= 0; i
< vector_active(ospf6_lsa_handler_vector
); i
++) {
912 handler
= vector_slot(ospf6_lsa_handler_vector
, i
);
914 if (handler
!= NULL
) {
915 UNSET_FLAG(handler
->debug
, OSPF6_LSA_DEBUG
);
919 for (i
= 0; i
< 6; i
++)
920 OSPF6_DEBUG_MESSAGE_OFF(i
,
921 OSPF6_DEBUG_NEIGHBOR_STATE
922 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
924 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
925 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
926 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE
);
927 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA
);
928 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER
);
929 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY
);
930 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS
);
931 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME
);
932 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE
);
933 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
);
938 int config_write_ospf6_debug_neighbor(struct vty
*vty
)
940 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
941 vty_out(vty
, "debug ospf6 neighbor\n");
942 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
))
943 vty_out(vty
, "debug ospf6 neighbor state\n");
944 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
945 vty_out(vty
, "debug ospf6 neighbor event\n");
949 void install_element_ospf6_debug_neighbor(void)
951 install_element(ENABLE_NODE
, &debug_ospf6_neighbor_cmd
);
952 install_element(ENABLE_NODE
, &no_debug_ospf6_neighbor_cmd
);
953 install_element(ENABLE_NODE
, &no_debug_ospf6_cmd
);
954 install_element(CONFIG_NODE
, &debug_ospf6_neighbor_cmd
);
955 install_element(CONFIG_NODE
, &no_debug_ospf6_neighbor_cmd
);
956 install_element(CONFIG_NODE
, &no_debug_ospf6_cmd
);