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 && next_state
== OSPF6_NEIGHBOR_FULL
) {
198 OSPF6_AS_EXTERN_LSA_SCHEDULE(on
->ospf6_if
);
199 on
->ospf6_if
->area
->full_nbrs
++;
202 if (prev_state
== OSPF6_NEIGHBOR_FULL
)
203 on
->ospf6_if
->area
->full_nbrs
--;
206 if ((prev_state
== OSPF6_NEIGHBOR_EXCHANGE
207 || prev_state
== OSPF6_NEIGHBOR_LOADING
)
208 && (next_state
!= OSPF6_NEIGHBOR_EXCHANGE
209 && next_state
!= OSPF6_NEIGHBOR_LOADING
))
210 ospf6_maxage_remove(on
->ospf6_if
->area
->ospf6
);
212 hook_call(ospf6_neighbor_change
, on
, next_state
, prev_state
);
213 ospf6_bfd_trigger_event(on
, prev_state
, next_state
);
216 /* RFC2328 section 10.4 */
217 static int need_adjacency(struct ospf6_neighbor
*on
)
219 if (on
->ospf6_if
->state
== OSPF6_INTERFACE_POINTTOPOINT
220 || on
->ospf6_if
->state
== OSPF6_INTERFACE_DR
221 || on
->ospf6_if
->state
== OSPF6_INTERFACE_BDR
)
224 if (on
->ospf6_if
->drouter
== on
->router_id
225 || on
->ospf6_if
->bdrouter
== on
->router_id
)
231 int hello_received(struct thread
*thread
)
233 struct ospf6_neighbor
*on
;
235 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
238 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
239 zlog_debug("Neighbor Event %s: *HelloReceived*", on
->name
);
241 /* reset Inactivity Timer */
242 THREAD_OFF(on
->inactivity_timer
);
243 on
->inactivity_timer
= NULL
;
244 thread_add_timer(master
, inactivity_timer
, on
,
245 on
->ospf6_if
->dead_interval
, &on
->inactivity_timer
);
247 if (on
->state
<= OSPF6_NEIGHBOR_DOWN
)
248 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
249 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD
);
254 int twoway_received(struct thread
*thread
)
256 struct ospf6_neighbor
*on
;
258 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
261 if (on
->state
> OSPF6_NEIGHBOR_INIT
)
264 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
265 zlog_debug("Neighbor Event %s: *2Way-Received*", on
->name
);
267 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
269 if (!need_adjacency(on
)) {
270 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
271 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
275 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
276 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD
);
277 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
278 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
279 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
281 THREAD_OFF(on
->thread_send_dbdesc
);
282 on
->thread_send_dbdesc
= NULL
;
283 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
284 &on
->thread_send_dbdesc
);
289 int negotiation_done(struct thread
*thread
)
291 struct ospf6_neighbor
*on
;
292 struct ospf6_lsa
*lsa
;
294 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
297 if (on
->state
!= OSPF6_NEIGHBOR_EXSTART
)
300 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
301 zlog_debug("Neighbor Event %s: *NegotiationDone*", on
->name
);
304 ospf6_lsdb_remove_all(on
->summary_list
);
305 ospf6_lsdb_remove_all(on
->request_list
);
306 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
307 ospf6_decrement_retrans_count(lsa
);
308 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
311 /* Interface scoped LSAs */
312 for (ALL_LSDB(on
->ospf6_if
->lsdb
, lsa
)) {
313 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
314 ospf6_increment_retrans_count(lsa
);
315 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
317 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
320 /* Area scoped LSAs */
321 for (ALL_LSDB(on
->ospf6_if
->area
->lsdb
, lsa
)) {
322 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
323 ospf6_increment_retrans_count(lsa
);
324 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
326 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
330 for (ALL_LSDB(on
->ospf6_if
->area
->ospf6
->lsdb
, lsa
)) {
331 if (OSPF6_LSA_IS_MAXAGE(lsa
)) {
332 ospf6_increment_retrans_count(lsa
);
333 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->retrans_list
);
335 ospf6_lsdb_add(ospf6_lsa_copy(lsa
), on
->summary_list
);
338 UNSET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
339 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE
, on
,
340 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE
);
345 int exchange_done(struct thread
*thread
)
347 struct ospf6_neighbor
*on
;
349 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
352 if (on
->state
!= OSPF6_NEIGHBOR_EXCHANGE
)
355 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
356 zlog_debug("Neighbor Event %s: *ExchangeDone*", on
->name
);
358 THREAD_OFF(on
->thread_send_dbdesc
);
359 ospf6_lsdb_remove_all(on
->dbdesc_list
);
362 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
363 on->ospf6_if->dead_interval);
366 if (on
->request_list
->count
== 0)
367 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
368 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
370 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING
, on
,
371 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE
);
373 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
374 &on
->thread_send_lsreq
);
380 /* Check loading state. */
381 void ospf6_check_nbr_loading(struct ospf6_neighbor
*on
)
384 /* RFC2328 Section 10.9: When the neighbor responds to these requests
385 with the proper Link State Update packet(s), the Link state request
386 list is truncated and a new Link State Request packet is sent.
388 if ((on
->state
== OSPF6_NEIGHBOR_LOADING
)
389 || (on
->state
== OSPF6_NEIGHBOR_EXCHANGE
)) {
390 if (on
->request_list
->count
== 0)
391 thread_add_event(master
, loading_done
, on
, 0, NULL
);
392 else if (on
->last_ls_req
== NULL
) {
393 if (on
->thread_send_lsreq
!= NULL
)
394 THREAD_OFF(on
->thread_send_lsreq
);
395 on
->thread_send_lsreq
= NULL
;
396 thread_add_event(master
, ospf6_lsreq_send
, on
, 0,
397 &on
->thread_send_lsreq
);
402 int loading_done(struct thread
*thread
)
404 struct ospf6_neighbor
*on
;
406 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
409 if (on
->state
!= OSPF6_NEIGHBOR_LOADING
)
412 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
413 zlog_debug("Neighbor Event %s: *LoadingDone*", on
->name
);
415 assert(on
->request_list
->count
== 0);
417 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL
, on
,
418 OSPF6_NEIGHBOR_EVENT_LOADING_DONE
);
423 int adj_ok(struct thread
*thread
)
425 struct ospf6_neighbor
*on
;
426 struct ospf6_lsa
*lsa
;
428 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
431 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
432 zlog_debug("Neighbor Event %s: *AdjOK?*", on
->name
);
434 if (on
->state
== OSPF6_NEIGHBOR_TWOWAY
&& need_adjacency(on
)) {
435 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
436 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
437 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
438 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
439 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
441 THREAD_OFF(on
->thread_send_dbdesc
);
442 on
->thread_send_dbdesc
= NULL
;
443 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
444 &on
->thread_send_dbdesc
);
446 } else if (on
->state
>= OSPF6_NEIGHBOR_EXSTART
&& !need_adjacency(on
)) {
447 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY
, on
,
448 OSPF6_NEIGHBOR_EVENT_ADJ_OK
);
449 ospf6_lsdb_remove_all(on
->summary_list
);
450 ospf6_lsdb_remove_all(on
->request_list
);
451 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
452 ospf6_decrement_retrans_count(lsa
);
453 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
460 int seqnumber_mismatch(struct thread
*thread
)
462 struct ospf6_neighbor
*on
;
463 struct ospf6_lsa
*lsa
;
465 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
468 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
471 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
472 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on
->name
);
474 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
475 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH
);
476 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
477 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
478 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
480 ospf6_lsdb_remove_all(on
->summary_list
);
481 ospf6_lsdb_remove_all(on
->request_list
);
482 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
483 ospf6_decrement_retrans_count(lsa
);
484 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
487 THREAD_OFF(on
->thread_send_dbdesc
);
488 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
490 on
->thread_send_dbdesc
= NULL
;
491 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
492 &on
->thread_send_dbdesc
);
497 int bad_lsreq(struct thread
*thread
)
499 struct ospf6_neighbor
*on
;
500 struct ospf6_lsa
*lsa
;
502 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
505 if (on
->state
< OSPF6_NEIGHBOR_EXCHANGE
)
508 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
509 zlog_debug("Neighbor Event %s: *BadLSReq*", on
->name
);
511 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART
, on
,
512 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ
);
513 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
);
514 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
);
515 SET_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
);
517 ospf6_lsdb_remove_all(on
->summary_list
);
518 ospf6_lsdb_remove_all(on
->request_list
);
519 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
520 ospf6_decrement_retrans_count(lsa
);
521 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
524 THREAD_OFF(on
->thread_send_dbdesc
);
525 on
->dbdesc_seqnum
++; /* Incr seqnum as per RFC2328, sec 10.3 */
527 on
->thread_send_dbdesc
= NULL
;
528 thread_add_event(master
, ospf6_dbdesc_send
, on
, 0,
529 &on
->thread_send_dbdesc
);
534 int oneway_received(struct thread
*thread
)
536 struct ospf6_neighbor
*on
;
537 struct ospf6_lsa
*lsa
;
539 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
542 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
545 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
546 zlog_debug("Neighbor Event %s: *1Way-Received*", on
->name
);
548 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT
, on
,
549 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD
);
550 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
552 ospf6_lsdb_remove_all(on
->summary_list
);
553 ospf6_lsdb_remove_all(on
->request_list
);
554 for (ALL_LSDB(on
->retrans_list
, lsa
)) {
555 ospf6_decrement_retrans_count(lsa
);
556 ospf6_lsdb_remove(lsa
, on
->retrans_list
);
559 THREAD_OFF(on
->thread_send_dbdesc
);
560 THREAD_OFF(on
->thread_send_lsreq
);
561 THREAD_OFF(on
->thread_send_lsupdate
);
562 THREAD_OFF(on
->thread_send_lsack
);
567 int inactivity_timer(struct thread
*thread
)
569 struct ospf6_neighbor
*on
;
571 on
= (struct ospf6_neighbor
*)THREAD_ARG(thread
);
574 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
575 zlog_debug("Neighbor Event %s: *InactivityTimer*", on
->name
);
577 on
->inactivity_timer
= NULL
;
578 on
->drouter
= on
->prev_drouter
= 0;
579 on
->bdrouter
= on
->prev_bdrouter
= 0;
581 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN
, on
,
582 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER
);
583 thread_add_event(master
, neighbor_change
, on
->ospf6_if
, 0, NULL
);
585 listnode_delete(on
->ospf6_if
->neighbor_list
, on
);
586 ospf6_neighbor_delete(on
);
593 /* show neighbor structure */
594 static void ospf6_neighbor_show(struct vty
*vty
, struct ospf6_neighbor
*on
)
603 /* Router-ID (Name) */
604 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
605 #ifdef HAVE_GETNAMEINFO
608 #endif /*HAVE_GETNAMEINFO*/
612 if (on
->inactivity_timer
) {
613 s
= monotime_until(&on
->inactivity_timer
->u
.sands
, NULL
)
620 snprintf(deadtime
, sizeof(deadtime
), "%02ld:%02ld:%02ld", h
, m
, s
);
623 if (if_is_pointopoint(on
->ospf6_if
->interface
))
624 snprintf(nstate
, sizeof(nstate
), "PointToPoint");
626 if (on
->router_id
== on
->drouter
)
627 snprintf(nstate
, sizeof(nstate
), "DR");
628 else if (on
->router_id
== on
->bdrouter
)
629 snprintf(nstate
, sizeof(nstate
), "BDR");
631 snprintf(nstate
, sizeof(nstate
), "DROther");
635 monotime_since(&on
->last_changed
, &res
);
636 timerstring(&res
, duration
, sizeof(duration
));
639 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
640 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
644 vty_out(vty
, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id
,
645 on
->priority
, deadtime
, ospf6_neighbor_state_str
[on
->state
],
646 nstate
, duration
, on
->ospf6_if
->interface
->name
,
647 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
650 static void ospf6_neighbor_show_drchoice(struct vty
*vty
,
651 struct ospf6_neighbor
*on
)
654 char drouter
[16], bdrouter
[16];
656 struct timeval now
, res
;
659 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
660 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
664 inet_ntop(AF_INET
, &on
->router_id
, router_id
, sizeof(router_id
));
665 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
666 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
669 timersub(&now
, &on
->last_changed
, &res
);
670 timerstring(&res
, duration
, sizeof(duration
));
672 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id
,
673 ospf6_neighbor_state_str
[on
->state
], duration
, drouter
,
674 bdrouter
, on
->ospf6_if
->interface
->name
,
675 ospf6_interface_state_str
[on
->ospf6_if
->state
]);
678 static void ospf6_neighbor_show_detail(struct vty
*vty
,
679 struct ospf6_neighbor
*on
)
681 char drouter
[16], bdrouter
[16];
682 char linklocal_addr
[64], duration
[32];
683 struct timeval now
, res
;
684 struct ospf6_lsa
*lsa
;
686 inet_ntop(AF_INET6
, &on
->linklocal_addr
, linklocal_addr
,
687 sizeof(linklocal_addr
));
688 inet_ntop(AF_INET
, &on
->drouter
, drouter
, sizeof(drouter
));
689 inet_ntop(AF_INET
, &on
->bdrouter
, bdrouter
, sizeof(bdrouter
));
692 timersub(&now
, &on
->last_changed
, &res
);
693 timerstring(&res
, duration
, sizeof(duration
));
695 vty_out(vty
, " Neighbor %s\n", on
->name
);
696 vty_out(vty
, " Area %s via interface %s (ifindex %d)\n",
697 on
->ospf6_if
->area
->name
, on
->ospf6_if
->interface
->name
,
698 on
->ospf6_if
->interface
->ifindex
);
699 vty_out(vty
, " His IfIndex: %d Link-local address: %s\n",
700 on
->ifindex
, linklocal_addr
);
701 vty_out(vty
, " State %s for a duration of %s\n",
702 ospf6_neighbor_state_str
[on
->state
], duration
);
703 vty_out(vty
, " His choice of DR/BDR %s/%s, Priority %d\n", drouter
,
704 bdrouter
, on
->priority
);
705 vty_out(vty
, " DbDesc status: %s%s%s SeqNum: %#lx\n",
706 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_IBIT
) ? "Initial "
708 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MBIT
) ? "More " : ""),
709 (CHECK_FLAG(on
->dbdesc_bits
, OSPF6_DBDESC_MSBIT
) ? "Master"
711 (unsigned long)ntohl(on
->dbdesc_seqnum
));
713 vty_out(vty
, " Summary-List: %d LSAs\n", on
->summary_list
->count
);
714 for (ALL_LSDB(on
->summary_list
, lsa
))
715 vty_out(vty
, " %s\n", lsa
->name
);
717 vty_out(vty
, " Request-List: %d LSAs\n", on
->request_list
->count
);
718 for (ALL_LSDB(on
->request_list
, lsa
))
719 vty_out(vty
, " %s\n", lsa
->name
);
721 vty_out(vty
, " Retrans-List: %d LSAs\n", on
->retrans_list
->count
);
722 for (ALL_LSDB(on
->retrans_list
, lsa
))
723 vty_out(vty
, " %s\n", lsa
->name
);
726 if (on
->thread_send_dbdesc
)
727 timersub(&on
->thread_send_dbdesc
->u
.sands
, &now
, &res
);
728 timerstring(&res
, duration
, sizeof(duration
));
729 vty_out(vty
, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
730 on
->dbdesc_list
->count
, duration
,
731 (on
->thread_send_dbdesc
? "on" : "off"));
732 for (ALL_LSDB(on
->dbdesc_list
, lsa
))
733 vty_out(vty
, " %s\n", lsa
->name
);
736 if (on
->thread_send_lsreq
)
737 timersub(&on
->thread_send_lsreq
->u
.sands
, &now
, &res
);
738 timerstring(&res
, duration
, sizeof(duration
));
739 vty_out(vty
, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
740 on
->request_list
->count
, duration
,
741 (on
->thread_send_lsreq
? "on" : "off"));
742 for (ALL_LSDB(on
->request_list
, lsa
))
743 vty_out(vty
, " %s\n", lsa
->name
);
746 if (on
->thread_send_lsupdate
)
747 timersub(&on
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
748 timerstring(&res
, duration
, sizeof(duration
));
750 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
751 on
->lsupdate_list
->count
, duration
,
752 (on
->thread_send_lsupdate
? "on" : "off"));
753 for (ALL_LSDB(on
->lsupdate_list
, lsa
))
754 vty_out(vty
, " %s\n", lsa
->name
);
757 if (on
->thread_send_lsack
)
758 timersub(&on
->thread_send_lsack
->u
.sands
, &now
, &res
);
759 timerstring(&res
, duration
, sizeof(duration
));
760 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
761 on
->lsack_list
->count
, duration
,
762 (on
->thread_send_lsack
? "on" : "off"));
763 for (ALL_LSDB(on
->lsack_list
, lsa
))
764 vty_out(vty
, " %s\n", lsa
->name
);
766 ospf6_bfd_show_info(vty
, on
->bfd_info
, 0);
769 DEFUN (show_ipv6_ospf6_neighbor
,
770 show_ipv6_ospf6_neighbor_cmd
,
771 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
777 "Display DR choices\n")
780 struct ospf6_neighbor
*on
;
781 struct ospf6_interface
*oi
;
782 struct ospf6_area
*oa
;
783 struct listnode
*i
, *j
, *k
;
784 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
786 OSPF6_CMD_CHECK_RUNNING();
787 showfunc
= ospf6_neighbor_show
;
790 if (!strncmp(argv
[idx_type
]->arg
, "de", 2))
791 showfunc
= ospf6_neighbor_show_detail
;
792 else if (!strncmp(argv
[idx_type
]->arg
, "dr", 2))
793 showfunc
= ospf6_neighbor_show_drchoice
;
796 if (showfunc
== ospf6_neighbor_show
)
797 vty_out(vty
, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
798 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
799 "Duration", "I/F", "State");
800 else if (showfunc
== ospf6_neighbor_show_drchoice
)
801 vty_out(vty
, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
802 "State", "Duration", "DR", "BDR", "I/F", "State");
804 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
805 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
806 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
807 (*showfunc
)(vty
, on
);
813 DEFUN (show_ipv6_ospf6_neighbor_one
,
814 show_ipv6_ospf6_neighbor_one_cmd
,
815 "show ipv6 ospf6 neighbor A.B.C.D",
820 "Specify Router-ID as IPv4 address notation\n"
824 struct ospf6_neighbor
*on
;
825 struct ospf6_interface
*oi
;
826 struct ospf6_area
*oa
;
827 struct listnode
*i
, *j
, *k
;
828 void (*showfunc
)(struct vty
*, struct ospf6_neighbor
*);
831 OSPF6_CMD_CHECK_RUNNING();
832 showfunc
= ospf6_neighbor_show_detail
;
834 if ((inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
)) != 1) {
835 vty_out(vty
, "Router-ID is not parsable: %s\n",
836 argv
[idx_ipv4
]->arg
);
840 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, i
, oa
))
841 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
842 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, k
, on
))
843 (*showfunc
)(vty
, on
);
848 void ospf6_neighbor_init(void)
850 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_cmd
);
851 install_element(VIEW_NODE
, &show_ipv6_ospf6_neighbor_one_cmd
);
854 DEFUN (debug_ospf6_neighbor
,
855 debug_ospf6_neighbor_cmd
,
856 "debug ospf6 neighbor [<state|event>]",
859 "Debug OSPFv3 Neighbor\n"
860 "Debug OSPFv3 Neighbor State Change\n"
861 "Debug OSPFv3 Neighbor Event\n")
864 unsigned char level
= 0;
867 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
868 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
869 else if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
870 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
872 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
874 OSPF6_DEBUG_NEIGHBOR_ON(level
);
879 DEFUN (no_debug_ospf6_neighbor
,
880 no_debug_ospf6_neighbor_cmd
,
881 "no debug ospf6 neighbor [<state|event>]",
885 "Debug OSPFv3 Neighbor\n"
886 "Debug OSPFv3 Neighbor State Change\n"
887 "Debug OSPFv3 Neighbor Event\n")
890 unsigned char level
= 0;
893 if (!strncmp(argv
[idx_type
]->arg
, "s", 1))
894 level
= OSPF6_DEBUG_NEIGHBOR_STATE
;
895 if (!strncmp(argv
[idx_type
]->arg
, "e", 1))
896 level
= OSPF6_DEBUG_NEIGHBOR_EVENT
;
898 level
= OSPF6_DEBUG_NEIGHBOR_STATE
| OSPF6_DEBUG_NEIGHBOR_EVENT
;
900 OSPF6_DEBUG_NEIGHBOR_OFF(level
);
905 DEFUN (no_debug_ospf6
,
913 struct ospf6_lsa_handler
*handler
= NULL
;
915 OSPF6_DEBUG_ABR_OFF();
916 OSPF6_DEBUG_ASBR_OFF();
917 OSPF6_DEBUG_BROUTER_OFF();
918 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
919 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
920 OSPF6_DEBUG_FLOODING_OFF();
921 OSPF6_DEBUG_INTERFACE_OFF();
923 for (i
= 0; i
< vector_active(ospf6_lsa_handler_vector
); i
++) {
924 handler
= vector_slot(ospf6_lsa_handler_vector
, i
);
926 if (handler
!= NULL
) {
927 UNSET_FLAG(handler
->debug
, OSPF6_LSA_DEBUG
);
931 for (i
= 0; i
< 6; i
++)
932 OSPF6_DEBUG_MESSAGE_OFF(i
,
933 OSPF6_DEBUG_NEIGHBOR_STATE
934 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
936 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
937 | OSPF6_DEBUG_NEIGHBOR_EVENT
);
938 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE
);
939 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA
);
940 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER
);
941 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY
);
942 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS
);
943 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME
);
944 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE
);
945 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND
| OSPF6_DEBUG_ZEBRA_RECV
);
950 int config_write_ospf6_debug_neighbor(struct vty
*vty
)
952 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
953 vty_out(vty
, "debug ospf6 neighbor\n");
954 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE
))
955 vty_out(vty
, "debug ospf6 neighbor state\n");
956 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT
))
957 vty_out(vty
, "debug ospf6 neighbor event\n");
961 void install_element_ospf6_debug_neighbor(void)
963 install_element(ENABLE_NODE
, &debug_ospf6_neighbor_cmd
);
964 install_element(ENABLE_NODE
, &no_debug_ospf6_neighbor_cmd
);
965 install_element(ENABLE_NODE
, &no_debug_ospf6_cmd
);
966 install_element(CONFIG_NODE
, &debug_ospf6_neighbor_cmd
);
967 install_element(CONFIG_NODE
, &no_debug_ospf6_neighbor_cmd
);
968 install_element(CONFIG_NODE
, &no_debug_ospf6_cmd
);