2 * OSPF version 2 Neighbor State Machine
3 * From RFC2328 [OSPF Version 2]
4 * Copyright (C) 1999, 2000 Toshiaki Takada
6 * This file is part of GNU Zebra.
8 * GNU Zebra is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Zebra; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
37 #include "ospfd/ospfd.h"
38 #include "ospfd/ospf_interface.h"
39 #include "ospfd/ospf_ism.h"
40 #include "ospfd/ospf_asbr.h"
41 #include "ospfd/ospf_lsa.h"
42 #include "ospfd/ospf_lsdb.h"
43 #include "ospfd/ospf_neighbor.h"
44 #include "ospfd/ospf_nsm.h"
45 #include "ospfd/ospf_network.h"
46 #include "ospfd/ospf_packet.h"
47 #include "ospfd/ospf_dump.h"
48 #include "ospfd/ospf_flood.h"
49 #include "ospfd/ospf_abr.h"
51 void nsm_reset_nbr (struct ospf_neighbor
*);
54 /* OSPF NSM Timer functions. */
56 ospf_inactivity_timer (struct thread
*thread
)
58 struct ospf_neighbor
*nbr
;
60 nbr
= THREAD_ARG (thread
);
61 nbr
->t_inactivity
= NULL
;
63 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
64 zlog (NULL
, LOG_DEBUG
, "NSM[%s:%s]: Timer (Inactivity timer expire)",
65 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->router_id
));
67 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_InactivityTimer
);
73 ospf_db_desc_timer (struct thread
*thread
)
75 struct ospf_interface
*oi
;
76 struct ospf_neighbor
*nbr
;
78 nbr
= THREAD_ARG (thread
);
79 nbr
->t_db_desc
= NULL
;
83 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
84 zlog (NULL
, LOG_INFO
, "NSM[%s:%s]: Timer (DD Retransmit timer expire)",
85 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->src
));
87 /* resent last send DD packet. */
88 assert (nbr
->last_send
);
89 ospf_db_desc_resend (nbr
);
91 /* DD Retransmit timer set. */
92 OSPF_NSM_TIMER_ON (nbr
->t_db_desc
, ospf_db_desc_timer
, nbr
->v_db_desc
);
97 /* Hook function called after ospf NSM event is occured. */
100 nsm_timer_set (struct ospf_neighbor
*nbr
)
105 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
106 OSPF_NSM_TIMER_OFF (nbr
->t_ls_upd
);
109 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
110 OSPF_NSM_TIMER_OFF (nbr
->t_ls_upd
);
113 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
114 OSPF_NSM_TIMER_OFF (nbr
->t_ls_upd
);
117 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
118 OSPF_NSM_TIMER_OFF (nbr
->t_ls_upd
);
121 OSPF_NSM_TIMER_ON (nbr
->t_db_desc
, ospf_db_desc_timer
, nbr
->v_db_desc
);
122 OSPF_NSM_TIMER_OFF (nbr
->t_ls_upd
);
125 OSPF_NSM_TIMER_ON (nbr
->t_ls_upd
, ospf_ls_upd_timer
, nbr
->v_ls_upd
);
126 if (!IS_SET_DD_MS (nbr
->dd_flags
))
127 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
130 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
133 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
136 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
142 /* OSPF NSM functions. */
144 nsm_ignore (struct ospf_neighbor
*nbr
)
146 if (IS_DEBUG_OSPF (nsm
, NSM_EVENTS
))
147 zlog (NULL
, LOG_INFO
, "NSM[%s:%s]: nsm_ignore called",
148 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->router_id
));
154 nsm_hello_received (struct ospf_neighbor
*nbr
)
156 /* Start or Restart Inactivity Timer. */
157 OSPF_NSM_TIMER_OFF (nbr
->t_inactivity
);
159 OSPF_NSM_TIMER_ON (nbr
->t_inactivity
, ospf_inactivity_timer
,
162 if (nbr
->oi
->type
== OSPF_IFTYPE_NBMA
&& nbr
->nbr_nbma
)
163 OSPF_POLL_TIMER_OFF (nbr
->nbr_nbma
->t_poll
);
169 nsm_start (struct ospf_neighbor
*nbr
)
175 OSPF_POLL_TIMER_OFF (nbr
->nbr_nbma
->t_poll
);
177 OSPF_NSM_TIMER_OFF (nbr
->t_inactivity
);
179 OSPF_NSM_TIMER_ON (nbr
->t_inactivity
, ospf_inactivity_timer
,
186 nsm_twoway_received (struct ospf_neighbor
*nbr
)
188 struct ospf_interface
*oi
;
189 int next_state
= NSM_TwoWay
;
193 /* These netowork types must be adjacency. */
194 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
||
195 oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
||
196 oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
197 next_state
= NSM_ExStart
;
199 /* Router itself is the DRouter or the BDRouter. */
200 if (IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &DR (oi
)) ||
201 IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &BDR (oi
)))
202 next_state
= NSM_ExStart
;
204 /* Neighboring Router is the DRouter or the BDRouter. */
205 if (IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->d_router
) ||
206 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
))
207 next_state
= NSM_ExStart
;
213 ospf_db_summary_count (struct ospf_neighbor
*nbr
)
215 return ospf_lsdb_count_all (&nbr
->db_sum
);
219 ospf_db_summary_isempty (struct ospf_neighbor
*nbr
)
221 return ospf_lsdb_isempty (&nbr
->db_sum
);
225 ospf_db_summary_add (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
227 #ifdef HAVE_OPAQUE_LSA
228 switch (lsa
->data
->type
)
230 case OSPF_OPAQUE_LINK_LSA
:
231 /* Exclude type-9 LSAs that does not have the same "oi" with "nbr". */
232 if (lsa
->oi
!= nbr
->oi
)
235 case OSPF_OPAQUE_AREA_LSA
:
237 * It is assured by the caller function "nsm_negotiation_done()"
238 * that every given LSA belongs to the same area with "nbr".
241 case OSPF_OPAQUE_AS_LSA
:
245 #endif /* HAVE_OPAQUE_LSA */
248 /* Stay away from any Local Translated Type-7 LSAs */
249 if (CHECK_FLAG (lsa
->flags
, OSPF_LSA_LOCAL_XLT
))
251 #endif /* HAVE_NSSA */
253 if (IS_LSA_MAXAGE (lsa
))
254 ospf_ls_retransmit_add (nbr
, lsa
);
256 ospf_lsdb_add (&nbr
->db_sum
, lsa
);
262 ospf_db_summary_clear (struct ospf_neighbor
*nbr
)
264 struct ospf_lsdb
*lsdb
;
268 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
270 struct route_table
*table
= lsdb
->type
[i
].db
;
271 struct route_node
*rn
;
273 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
275 ospf_lsdb_delete (&nbr
->db_sum
, rn
->info
);
281 /* The area link state database consists of the router-LSAs,
282 network-LSAs and summary-LSAs contained in the area structure,
283 along with the AS-external-LSAs contained in the global structure.
284 AS-external-LSAs are omitted from a virtual neighbor's Database
285 summary list. AS-external-LSAs are omitted from the Database
286 summary list if the area has been configured as a stub. */
288 nsm_negotiation_done (struct ospf_neighbor
*nbr
)
290 struct ospf_area
*area
= nbr
->oi
->area
;
291 struct ospf_lsa
*lsa
;
292 struct route_node
*rn
;
294 LSDB_LOOP (ROUTER_LSDB (area
), rn
, lsa
)
295 ospf_db_summary_add (nbr
, lsa
);
296 LSDB_LOOP (NETWORK_LSDB (area
), rn
, lsa
)
297 ospf_db_summary_add (nbr
, lsa
);
298 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
299 ospf_db_summary_add (nbr
, lsa
);
300 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
301 ospf_db_summary_add (nbr
, lsa
);
303 #ifdef HAVE_OPAQUE_LSA
304 /* Process only if the neighbor is opaque capable. */
305 if (CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
307 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
308 ospf_db_summary_add (nbr
, lsa
);
309 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
310 ospf_db_summary_add (nbr
, lsa
);
312 #endif /* HAVE_OPAQUE_LSA */
314 if (nbr
->oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
315 && area
->external_routing
== OSPF_AREA_DEFAULT
)
316 LSDB_LOOP (EXTERNAL_LSDB (nbr
->oi
->ospf
), rn
, lsa
)
317 ospf_db_summary_add (nbr
, lsa
);
319 #ifdef HAVE_OPAQUE_LSA
320 if (CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
)
321 && (nbr
->oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
322 && area
->external_routing
== OSPF_AREA_DEFAULT
))
323 LSDB_LOOP (OPAQUE_AS_LSDB (nbr
->oi
->ospf
), rn
, lsa
)
324 ospf_db_summary_add (nbr
, lsa
);
325 #endif /* HAVE_OPAQUE_LSA */
331 nsm_exchange_done (struct ospf_neighbor
*nbr
)
333 if (ospf_ls_request_isempty (nbr
))
336 /* Cancel dd retransmit timer. */
337 /* OSPF_NSM_TIMER_OFF (nbr->t_db_desc); */
339 /* Send Link State Request. */
340 ospf_ls_req_send (nbr
);
346 nsm_bad_ls_req (struct ospf_neighbor
*nbr
)
348 /* Clear neighbor. */
355 nsm_adj_ok (struct ospf_neighbor
*nbr
)
357 struct ospf_interface
*oi
;
362 next_state
= nbr
->state
;
364 /* These netowork types must be adjacency. */
365 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
366 || oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
367 || oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
370 /* Router itself is the DRouter or the BDRouter. */
371 if (IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &DR (oi
))
372 || IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &BDR (oi
)))
375 if (IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &DR (oi
))
376 || IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &BDR (oi
)))
379 if (nbr
->state
== NSM_TwoWay
&& flag
== 1)
380 next_state
= NSM_ExStart
;
381 else if (nbr
->state
>= NSM_ExStart
&& flag
== 0)
382 next_state
= NSM_TwoWay
;
388 nsm_seq_number_mismatch (struct ospf_neighbor
*nbr
)
390 /* Clear neighbor. */
397 nsm_oneway_received (struct ospf_neighbor
*nbr
)
399 /* Clear neighbor. */
406 nsm_reset_nbr (struct ospf_neighbor
*nbr
)
408 /* Clear Database Summary list. */
409 if (!ospf_db_summary_isempty (nbr
))
410 ospf_db_summary_clear (nbr
);
412 /* Clear Link State Request list. */
413 if (!ospf_ls_request_isempty (nbr
))
414 ospf_ls_request_delete_all (nbr
);
416 /* Clear Link State Retransmission list. */
417 if (!ospf_ls_retransmit_isempty (nbr
))
418 ospf_ls_retransmit_clear (nbr
);
421 OSPF_NSM_TIMER_OFF (nbr
->t_db_desc
);
422 OSPF_NSM_TIMER_OFF (nbr
->t_ls_req
);
423 OSPF_NSM_TIMER_OFF (nbr
->t_ls_upd
);
424 OSPF_NSM_TIMER_OFF (nbr
->t_hello_reply
);
426 #ifdef HAVE_OPAQUE_LSA
427 if (CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
428 UNSET_FLAG (nbr
->options
, OSPF_OPTION_O
);
429 #endif /* HAVE_OPAQUE_LSA */
433 nsm_kill_nbr (struct ospf_neighbor
*nbr
)
435 /* call it here because we cannot call it from ospf_nsm_event */
436 nsm_change_state (nbr
, NSM_Down
);
438 /* Reset neighbor. */
441 if (nbr
->oi
->type
== OSPF_IFTYPE_NBMA
&& nbr
->nbr_nbma
!= NULL
)
443 struct ospf_nbr_nbma
*nbr_nbma
= nbr
->nbr_nbma
;
445 nbr_nbma
->nbr
= NULL
;
446 nbr_nbma
->state_change
= nbr
->state_change
;
448 nbr
->nbr_nbma
= NULL
;
450 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
453 if (IS_DEBUG_OSPF (nsm
, NSM_EVENTS
))
454 zlog_info ("NSM[%s:%s]: Down (PollIntervalTimer scheduled)",
455 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->address
.u
.prefix4
));
458 /* Delete neighbor from interface. */
459 ospf_nbr_delete (nbr
);
465 nsm_inactivity_timer (struct ospf_neighbor
*nbr
)
474 nsm_ll_down (struct ospf_neighbor
*nbr
)
476 /* Reset neighbor. */
477 /*nsm_reset_nbr (nbr);*/
485 /* Neighbor State Machine */
489 } NSM
[OSPF_NSM_STATE_MAX
][OSPF_NSM_EVENT_MAX
] =
492 /* DependUpon: dummy state. */
493 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
494 { nsm_ignore
, NSM_DependUpon
}, /* HelloReceived */
495 { nsm_ignore
, NSM_DependUpon
}, /* Start */
496 { nsm_ignore
, NSM_DependUpon
}, /* 2-WayReceived */
497 { nsm_ignore
, NSM_DependUpon
}, /* NegotiationDone */
498 { nsm_ignore
, NSM_DependUpon
}, /* ExchangeDone */
499 { nsm_ignore
, NSM_DependUpon
}, /* BadLSReq */
500 { nsm_ignore
, NSM_DependUpon
}, /* LoadingDone */
501 { nsm_ignore
, NSM_DependUpon
}, /* AdjOK? */
502 { nsm_ignore
, NSM_DependUpon
}, /* SeqNumberMismatch */
503 { nsm_ignore
, NSM_DependUpon
}, /* 1-WayReceived */
504 { nsm_ignore
, NSM_DependUpon
}, /* KillNbr */
505 { nsm_ignore
, NSM_DependUpon
}, /* InactivityTimer */
506 { nsm_ignore
, NSM_DependUpon
}, /* LLDown */
510 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
511 { nsm_hello_received
, NSM_Init
}, /* HelloReceived */
512 { nsm_start
, NSM_Attempt
}, /* Start */
513 { nsm_ignore
, NSM_Down
}, /* 2-WayReceived */
514 { nsm_ignore
, NSM_Down
}, /* NegotiationDone */
515 { nsm_ignore
, NSM_Down
}, /* ExchangeDone */
516 { nsm_ignore
, NSM_Down
}, /* BadLSReq */
517 { nsm_ignore
, NSM_Down
}, /* LoadingDone */
518 { nsm_ignore
, NSM_Down
}, /* AdjOK? */
519 { nsm_ignore
, NSM_Down
}, /* SeqNumberMismatch */
520 { nsm_ignore
, NSM_Down
}, /* 1-WayReceived */
521 { nsm_kill_nbr
, NSM_Down
}, /* KillNbr */
522 { nsm_inactivity_timer
, NSM_Down
}, /* InactivityTimer */
523 { nsm_ll_down
, NSM_Down
}, /* LLDown */
527 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
528 { nsm_hello_received
, NSM_Init
}, /* HelloReceived */
529 { nsm_ignore
, NSM_Attempt
}, /* Start */
530 { nsm_ignore
, NSM_Attempt
}, /* 2-WayReceived */
531 { nsm_ignore
, NSM_Attempt
}, /* NegotiationDone */
532 { nsm_ignore
, NSM_Attempt
}, /* ExchangeDone */
533 { nsm_ignore
, NSM_Attempt
}, /* BadLSReq */
534 { nsm_ignore
, NSM_Attempt
}, /* LoadingDone */
535 { nsm_ignore
, NSM_Attempt
}, /* AdjOK? */
536 { nsm_ignore
, NSM_Attempt
}, /* SeqNumberMismatch */
537 { nsm_ignore
, NSM_Attempt
}, /* 1-WayReceived */
538 { nsm_kill_nbr
, NSM_Down
}, /* KillNbr */
539 { nsm_inactivity_timer
, NSM_Down
}, /* InactivityTimer */
540 { nsm_ll_down
, NSM_Down
}, /* LLDown */
544 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
545 { nsm_hello_received
, NSM_Init
}, /* HelloReceived */
546 { nsm_ignore
, NSM_Init
}, /* Start */
547 { nsm_twoway_received
, NSM_DependUpon
}, /* 2-WayReceived */
548 { nsm_ignore
, NSM_Init
}, /* NegotiationDone */
549 { nsm_ignore
, NSM_Init
}, /* ExchangeDone */
550 { nsm_ignore
, NSM_Init
}, /* BadLSReq */
551 { nsm_ignore
, NSM_Init
}, /* LoadingDone */
552 { nsm_ignore
, NSM_Init
}, /* AdjOK? */
553 { nsm_ignore
, NSM_Init
}, /* SeqNumberMismatch */
554 { nsm_ignore
, NSM_Init
}, /* 1-WayReceived */
555 { nsm_kill_nbr
, NSM_Down
}, /* KillNbr */
556 { nsm_inactivity_timer
, NSM_Down
}, /* InactivityTimer */
557 { nsm_ll_down
, NSM_Down
}, /* LLDown */
561 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
562 { nsm_hello_received
, NSM_TwoWay
}, /* HelloReceived */
563 { nsm_ignore
, NSM_TwoWay
}, /* Start */
564 { nsm_ignore
, NSM_TwoWay
}, /* 2-WayReceived */
565 { nsm_ignore
, NSM_TwoWay
}, /* NegotiationDone */
566 { nsm_ignore
, NSM_TwoWay
}, /* ExchangeDone */
567 { nsm_ignore
, NSM_TwoWay
}, /* BadLSReq */
568 { nsm_ignore
, NSM_TwoWay
}, /* LoadingDone */
569 { nsm_adj_ok
, NSM_DependUpon
}, /* AdjOK? */
570 { nsm_ignore
, NSM_TwoWay
}, /* SeqNumberMismatch */
571 { nsm_oneway_received
, NSM_Init
}, /* 1-WayReceived */
572 { nsm_kill_nbr
, NSM_Down
}, /* KillNbr */
573 { nsm_inactivity_timer
, NSM_Down
}, /* InactivityTimer */
574 { nsm_ll_down
, NSM_Down
}, /* LLDown */
578 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
579 { nsm_hello_received
, NSM_ExStart
}, /* HelloReceived */
580 { nsm_ignore
, NSM_ExStart
}, /* Start */
581 { nsm_ignore
, NSM_ExStart
}, /* 2-WayReceived */
582 { nsm_negotiation_done
, NSM_Exchange
}, /* NegotiationDone */
583 { nsm_ignore
, NSM_ExStart
}, /* ExchangeDone */
584 { nsm_ignore
, NSM_ExStart
}, /* BadLSReq */
585 { nsm_ignore
, NSM_ExStart
}, /* LoadingDone */
586 { nsm_adj_ok
, NSM_DependUpon
}, /* AdjOK? */
587 { nsm_ignore
, NSM_ExStart
}, /* SeqNumberMismatch */
588 { nsm_oneway_received
, NSM_Init
}, /* 1-WayReceived */
589 { nsm_kill_nbr
, NSM_Down
}, /* KillNbr */
590 { nsm_inactivity_timer
, NSM_Down
}, /* InactivityTimer */
591 { nsm_ll_down
, NSM_Down
}, /* LLDown */
595 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
596 { nsm_hello_received
, NSM_Exchange
}, /* HelloReceived */
597 { nsm_ignore
, NSM_Exchange
}, /* Start */
598 { nsm_ignore
, NSM_Exchange
}, /* 2-WayReceived */
599 { nsm_ignore
, NSM_Exchange
}, /* NegotiationDone */
600 { nsm_exchange_done
, NSM_DependUpon
}, /* ExchangeDone */
601 { nsm_bad_ls_req
, NSM_ExStart
}, /* BadLSReq */
602 { nsm_ignore
, NSM_Exchange
}, /* LoadingDone */
603 { nsm_adj_ok
, NSM_DependUpon
}, /* AdjOK? */
604 { nsm_seq_number_mismatch
, NSM_ExStart
}, /* SeqNumberMismatch */
605 { nsm_oneway_received
, NSM_Init
}, /* 1-WayReceived */
606 { nsm_kill_nbr
, NSM_Down
}, /* KillNbr */
607 { nsm_inactivity_timer
, NSM_Down
}, /* InactivityTimer */
608 { nsm_ll_down
, NSM_Down
}, /* LLDown */
612 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
613 { nsm_hello_received
, NSM_Loading
}, /* HelloReceived */
614 { nsm_ignore
, NSM_Loading
}, /* Start */
615 { nsm_ignore
, NSM_Loading
}, /* 2-WayReceived */
616 { nsm_ignore
, NSM_Loading
}, /* NegotiationDone */
617 { nsm_ignore
, NSM_Loading
}, /* ExchangeDone */
618 { nsm_bad_ls_req
, NSM_ExStart
}, /* BadLSReq */
619 { nsm_ignore
, NSM_Full
}, /* LoadingDone */
620 { nsm_adj_ok
, NSM_DependUpon
}, /* AdjOK? */
621 { nsm_seq_number_mismatch
, NSM_ExStart
}, /* SeqNumberMismatch */
622 { nsm_oneway_received
, NSM_Init
}, /* 1-WayReceived */
623 { nsm_kill_nbr
, NSM_Down
}, /* KillNbr */
624 { nsm_inactivity_timer
, NSM_Down
}, /* InactivityTimer */
625 { nsm_ll_down
, NSM_Down
}, /* LLDown */
628 { nsm_ignore
, NSM_DependUpon
}, /* NoEvent */
629 { nsm_hello_received
, NSM_Full
}, /* HelloReceived */
630 { nsm_ignore
, NSM_Full
}, /* Start */
631 { nsm_ignore
, NSM_Full
}, /* 2-WayReceived */
632 { nsm_ignore
, NSM_Full
}, /* NegotiationDone */
633 { nsm_ignore
, NSM_Full
}, /* ExchangeDone */
634 { nsm_bad_ls_req
, NSM_ExStart
}, /* BadLSReq */
635 { nsm_ignore
, NSM_Full
}, /* LoadingDone */
636 { nsm_adj_ok
, NSM_DependUpon
}, /* AdjOK? */
637 { nsm_seq_number_mismatch
, NSM_ExStart
}, /* SeqNumberMismatch */
638 { nsm_oneway_received
, NSM_Init
}, /* 1-WayReceived */
639 { nsm_kill_nbr
, NSM_Down
}, /* KillNbr */
640 { nsm_inactivity_timer
, NSM_Down
}, /* InactivityTimer */
641 { nsm_ll_down
, NSM_Down
}, /* LLDown */
645 static char *ospf_nsm_event_str
[] =
664 nsm_change_state (struct ospf_neighbor
*nbr
, int state
)
666 struct ospf_interface
*oi
= nbr
->oi
;
667 struct ospf_area
*vl_area
= NULL
;
672 /* Logging change of status. */
673 if (IS_DEBUG_OSPF (nsm
, NSM_STATUS
))
674 zlog_info ("NSM[%s:%s]: State change %s -> %s",
675 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->router_id
),
676 LOOKUP (ospf_nsm_state_msg
, nbr
->state
),
677 LOOKUP (ospf_nsm_state_msg
, state
));
679 /* Preserve old status. */
680 old_state
= nbr
->state
;
682 /* Change to new status. */
688 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
689 vl_area
= ospf_area_lookup_by_area_id (oi
->ospf
, oi
->vl_data
->vl_area_id
);
691 /* One of the neighboring routers changes to/from the FULL state. */
692 if ((old_state
!= NSM_Full
&& state
== NSM_Full
) ||
693 (old_state
== NSM_Full
&& state
!= NSM_Full
))
695 if (state
== NSM_Full
)
698 oi
->area
->full_nbrs
++;
700 ospf_check_abr_status (oi
->ospf
);
702 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
&& vl_area
)
703 if (++vl_area
->full_vls
== 1)
704 ospf_schedule_abr_task (oi
->ospf
);
706 /* kevinm: refresh any redistributions */
707 for (x
= ZEBRA_ROUTE_SYSTEM
; x
< ZEBRA_ROUTE_MAX
; x
++)
709 if (x
== ZEBRA_ROUTE_OSPF
|| x
== ZEBRA_ROUTE_OSPF6
)
711 ospf_external_lsa_refresh_type (oi
->ospf
, x
, force
);
717 oi
->area
->full_nbrs
--;
719 ospf_check_abr_status (oi
->ospf
);
721 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
&& vl_area
)
722 if (vl_area
->full_vls
> 0)
723 if (--vl_area
->full_vls
== 0)
724 ospf_schedule_abr_task (oi
->ospf
);
726 /* clear neighbor retransmit list */
727 if (!ospf_ls_retransmit_isempty (nbr
))
728 ospf_ls_retransmit_clear (nbr
);
731 zlog_info ("nsm_change_state(): "
732 "scheduling new router-LSA origination");
734 ospf_router_lsa_timer_add (oi
->area
);
736 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
738 struct ospf_area
*vl_area
=
739 ospf_area_lookup_by_area_id (oi
->ospf
, oi
->vl_data
->vl_area_id
);
742 ospf_router_lsa_timer_add (vl_area
);
745 /* Originate network-LSA. */
746 if (oi
->state
== ISM_DR
)
748 if (oi
->network_lsa_self
&& oi
->full_nbrs
== 0)
750 ospf_lsa_flush_area (oi
->network_lsa_self
, oi
->area
);
751 ospf_lsa_unlock (oi
->network_lsa_self
);
752 oi
->network_lsa_self
= NULL
;
753 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
756 ospf_network_lsa_timer_add (oi
);
760 #ifdef HAVE_OPAQUE_LSA
761 ospf_opaque_nsm_change (nbr
, old_state
);
762 #endif /* HAVE_OPAQUE_LSA */
764 /* Start DD exchange protocol */
765 if (state
== NSM_ExStart
)
767 if (nbr
->dd_seqnum
== 0)
768 nbr
->dd_seqnum
= time (NULL
);
772 nbr
->dd_flags
= OSPF_DD_FLAG_I
|OSPF_DD_FLAG_M
|OSPF_DD_FLAG_MS
;
773 ospf_db_desc_send (nbr
);
776 /* clear cryptographic sequence number */
777 if (state
== NSM_Down
)
778 nbr
->crypt_seqnum
= 0;
780 /* Generete NeighborChange ISM event. */
781 #ifdef BUGGY_ISM_TRANSITION
782 if ((old_state
< NSM_TwoWay
&& state
>= NSM_TwoWay
) ||
783 (old_state
>= NSM_TwoWay
&& state
< NSM_TwoWay
))
784 OSPF_ISM_EVENT_EXECUTE (oi
, ISM_NeighborChange
);
785 #else /* BUGGY_ISM_TRANSITION */
790 if ((old_state
< NSM_TwoWay
&& state
>= NSM_TwoWay
) ||
791 (old_state
>= NSM_TwoWay
&& state
< NSM_TwoWay
))
792 OSPF_ISM_EVENT_EXECUTE (oi
, ISM_NeighborChange
);
795 /* ISM_PointToPoint -> ISM_Down, ISM_Loopback -> ISM_Down, etc. */
798 #endif /* BUGGY_ISM_TRANSITION */
800 /* Performance hack. Send hello immideately when some neighbor enter
801 Init state. This whay we decrease neighbor discovery time. Gleb.*/
802 if (state
== NSM_Init
)
804 OSPF_ISM_TIMER_OFF (oi
->t_hello
);
805 OSPF_ISM_TIMER_ON (oi
->t_hello
, ospf_hello_timer
, 1);
808 /* Preserve old status? */
811 /* Execute NSM event process. */
813 ospf_nsm_event (struct thread
*thread
)
817 struct ospf_neighbor
*nbr
;
818 struct in_addr router_id
;
820 struct ospf_interface
*oi
;
822 nbr
= THREAD_ARG (thread
);
823 event
= THREAD_VAL (thread
);
824 router_id
= nbr
->router_id
;
826 old_state
= nbr
->state
;
830 next_state
= (*(NSM
[nbr
->state
][event
].func
))(nbr
);
832 /* When event is NSM_KillNbr or InactivityTimer, the neighbor is
834 if (event
== NSM_KillNbr
|| event
== NSM_InactivityTimer
)
836 if (IS_DEBUG_OSPF (nsm
, NSM_EVENTS
))
837 zlog_info ("NSM[%s:%s]: neighbor deleted",
838 IF_NAME (oi
), inet_ntoa (router_id
));
840 /* Timers are canceled in ospf_nbr_free, moreover we cannot call
841 nsm_timer_set here because nbr is freed already!!!*/
842 /*nsm_timer_set (nbr);*/
848 next_state
= NSM
[nbr
->state
][event
].next_state
;
850 if (IS_DEBUG_OSPF (nsm
, NSM_EVENTS
))
851 zlog_info ("NSM[%s:%s]: %s (%s)", IF_NAME (oi
),
852 inet_ntoa (nbr
->router_id
),
853 LOOKUP (ospf_nsm_state_msg
, nbr
->state
),
854 ospf_nsm_event_str
[event
]);
856 /* If state is changed. */
857 if (next_state
!= nbr
->state
)
858 nsm_change_state (nbr
, next_state
);
860 /* Make sure timer is set. */
866 /* Check loading state. */
868 ospf_check_nbr_loading (struct ospf_neighbor
*nbr
)
870 if (nbr
->state
== NSM_Loading
)
872 if (ospf_ls_request_isempty (nbr
))
873 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_LoadingDone
);
874 else if (nbr
->ls_req_last
== NULL
)
875 ospf_ls_req_event (nbr
);