blob: 0e6814e22b5aa55fc36f4b92aba95104332d8a26 [file] [log] [blame]
paul2d598362003-01-17 23:48:42 +00001/*
2 * OSPF version 2 Neighbor State Machine
3 * From RFC2328 [OSPF Version 2]
4 * Copyright (C) 1999, 2000 Toshiaki Takada
5 *
6 * This file is part of GNU Zebra.
7 *
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
11 * later version.
12 *
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.
17 *
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
21 * 02111-1307, USA.
22 */
23
24#include <zebra.h>
25
26#include "thread.h"
27#include "memory.h"
28#include "hash.h"
29#include "linklist.h"
30#include "prefix.h"
31#include "if.h"
32#include "table.h"
33#include "stream.h"
34#include "table.h"
35#include "log.h"
36
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"
vincent5e4914c2005-09-29 16:34:30 +000050#include "ospfd/ospf_snmp.h"
paul2d598362003-01-17 23:48:42 +000051
Paul Jakmad1b1cd82006-07-04 13:50:44 +000052static void nsm_clear_adj (struct ospf_neighbor *);
David Lamparter6b0655a2014-06-04 06:53:35 +020053
paul2d598362003-01-17 23:48:42 +000054/* OSPF NSM Timer functions. */
paul4dadc292005-05-06 21:37:42 +000055static int
paul2d598362003-01-17 23:48:42 +000056ospf_inactivity_timer (struct thread *thread)
57{
58 struct ospf_neighbor *nbr;
59
60 nbr = THREAD_ARG (thread);
61 nbr->t_inactivity = NULL;
62
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));
66
67 OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_InactivityTimer);
68
69 return 0;
70}
71
paul4dadc292005-05-06 21:37:42 +000072static int
paul2d598362003-01-17 23:48:42 +000073ospf_db_desc_timer (struct thread *thread)
74{
paul2d598362003-01-17 23:48:42 +000075 struct ospf_neighbor *nbr;
76
77 nbr = THREAD_ARG (thread);
78 nbr->t_db_desc = NULL;
79
paul2d598362003-01-17 23:48:42 +000080 if (IS_DEBUG_OSPF (nsm, NSM_TIMERS))
ajs2a42e282004-12-08 18:43:03 +000081 zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (DD Retransmit timer expire)",
paul2d598362003-01-17 23:48:42 +000082 IF_NAME (nbr->oi), inet_ntoa (nbr->src));
83
84 /* resent last send DD packet. */
85 assert (nbr->last_send);
86 ospf_db_desc_resend (nbr);
87
88 /* DD Retransmit timer set. */
89 OSPF_NSM_TIMER_ON (nbr->t_db_desc, ospf_db_desc_timer, nbr->v_db_desc);
90
91 return 0;
92}
93
Paul Jakma1f2c2742006-07-10 07:45:13 +000094/* Hook function called after ospf NSM event is occured.
95 *
96 * Set/clear any timers whose condition is implicit to the neighbour
97 * state. There may be other timers which are set/unset according to other
98 * state.
99 *
100 * We rely on this function to properly clear timers in lower states,
101 * particularly before deleting a neighbour.
102 */
paul4dadc292005-05-06 21:37:42 +0000103static void
paul2d598362003-01-17 23:48:42 +0000104nsm_timer_set (struct ospf_neighbor *nbr)
105{
106 switch (nbr->state)
107 {
Paul Jakma1f2c2742006-07-10 07:45:13 +0000108 case NSM_Deleted:
paul2d598362003-01-17 23:48:42 +0000109 case NSM_Down:
Paul Jakmae55dd532006-07-04 13:46:14 +0000110 OSPF_NSM_TIMER_OFF (nbr->t_inactivity);
Paul Jakma1f2c2742006-07-10 07:45:13 +0000111 OSPF_NSM_TIMER_OFF (nbr->t_hello_reply);
paul2d598362003-01-17 23:48:42 +0000112 case NSM_Attempt:
paul2d598362003-01-17 23:48:42 +0000113 case NSM_Init:
paul2d598362003-01-17 23:48:42 +0000114 case NSM_TwoWay:
115 OSPF_NSM_TIMER_OFF (nbr->t_db_desc);
116 OSPF_NSM_TIMER_OFF (nbr->t_ls_upd);
Paul Jakmae55dd532006-07-04 13:46:14 +0000117 OSPF_NSM_TIMER_OFF (nbr->t_ls_req);
paul2d598362003-01-17 23:48:42 +0000118 break;
119 case NSM_ExStart:
120 OSPF_NSM_TIMER_ON (nbr->t_db_desc, ospf_db_desc_timer, nbr->v_db_desc);
121 OSPF_NSM_TIMER_OFF (nbr->t_ls_upd);
Paul Jakmae55dd532006-07-04 13:46:14 +0000122 OSPF_NSM_TIMER_OFF (nbr->t_ls_req);
paul2d598362003-01-17 23:48:42 +0000123 break;
124 case NSM_Exchange:
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);
128 break;
129 case NSM_Loading:
paul2d598362003-01-17 23:48:42 +0000130 case NSM_Full:
paul2d598362003-01-17 23:48:42 +0000131 default:
132 OSPF_NSM_TIMER_OFF (nbr->t_db_desc);
133 break;
134 }
135}
136
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000137/* 10.4 of RFC2328, indicate whether an adjacency is appropriate with
138 * the given neighbour
139 */
140static int
141nsm_should_adj (struct ospf_neighbor *nbr)
142{
Paul Jakmaf7a76ab2006-07-04 13:57:49 +0000143 struct ospf_interface *oi = nbr->oi;
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000144
Paul Jakmaf7a76ab2006-07-04 13:57:49 +0000145 /* These network types must always form adjacencies. */
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000146 if (oi->type == OSPF_IFTYPE_POINTOPOINT
147 || oi->type == OSPF_IFTYPE_POINTOMULTIPOINT
Paul Jakmaf7a76ab2006-07-04 13:57:49 +0000148 || oi->type == OSPF_IFTYPE_VIRTUALLINK
149 /* Router itself is the DRouter or the BDRouter. */
150 || IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))
151 || IPV4_ADDR_SAME (&oi->address->u.prefix4, &BDR (oi))
152 /* Neighboring Router is the DRouter or the BDRouter. */
153 || IPV4_ADDR_SAME (&nbr->address.u.prefix4, &DR (oi))
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000154 || IPV4_ADDR_SAME (&nbr->address.u.prefix4, &BDR (oi)))
155 return 1;
156
157 return 0;
158}
David Lamparter6b0655a2014-06-04 06:53:35 +0200159
paul2d598362003-01-17 23:48:42 +0000160/* OSPF NSM functions. */
paul4dadc292005-05-06 21:37:42 +0000161static int
Paul Jakma57c5c652010-01-07 06:12:53 +0000162nsm_packet_received (struct ospf_neighbor *nbr)
paul2d598362003-01-17 23:48:42 +0000163{
164 /* Start or Restart Inactivity Timer. */
165 OSPF_NSM_TIMER_OFF (nbr->t_inactivity);
166
167 OSPF_NSM_TIMER_ON (nbr->t_inactivity, ospf_inactivity_timer,
168 nbr->v_inactivity);
169
170 if (nbr->oi->type == OSPF_IFTYPE_NBMA && nbr->nbr_nbma)
171 OSPF_POLL_TIMER_OFF (nbr->nbr_nbma->t_poll);
172
173 return 0;
174}
175
paul4dadc292005-05-06 21:37:42 +0000176static int
paul2d598362003-01-17 23:48:42 +0000177nsm_start (struct ospf_neighbor *nbr)
178{
paul2d598362003-01-17 23:48:42 +0000179 if (nbr->nbr_nbma)
180 OSPF_POLL_TIMER_OFF (nbr->nbr_nbma->t_poll);
181
182 OSPF_NSM_TIMER_OFF (nbr->t_inactivity);
183
184 OSPF_NSM_TIMER_ON (nbr->t_inactivity, ospf_inactivity_timer,
185 nbr->v_inactivity);
186
187 return 0;
188}
189
paul4dadc292005-05-06 21:37:42 +0000190static int
paul2d598362003-01-17 23:48:42 +0000191nsm_twoway_received (struct ospf_neighbor *nbr)
192{
Paul Jakmaf7a76ab2006-07-04 13:57:49 +0000193 return (nsm_should_adj (nbr) ? NSM_ExStart : NSM_TwoWay);
paul2d598362003-01-17 23:48:42 +0000194}
195
196int
197ospf_db_summary_count (struct ospf_neighbor *nbr)
198{
199 return ospf_lsdb_count_all (&nbr->db_sum);
200}
201
202int
203ospf_db_summary_isempty (struct ospf_neighbor *nbr)
204{
205 return ospf_lsdb_isempty (&nbr->db_sum);
206}
207
paul4dadc292005-05-06 21:37:42 +0000208static int
paul68980082003-03-25 05:07:42 +0000209ospf_db_summary_add (struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
paul2d598362003-01-17 23:48:42 +0000210{
paul09e4efd2003-01-18 00:12:02 +0000211#ifdef HAVE_OPAQUE_LSA
212 switch (lsa->data->type)
213 {
214 case OSPF_OPAQUE_LINK_LSA:
215 /* Exclude type-9 LSAs that does not have the same "oi" with "nbr". */
Paul Jakmad71ea652011-03-22 15:23:55 +0000216 if (nbr->oi && ospf_if_exists (lsa->oi) != nbr->oi)
paul09e4efd2003-01-18 00:12:02 +0000217 return 0;
218 break;
219 case OSPF_OPAQUE_AREA_LSA:
220 /*
221 * It is assured by the caller function "nsm_negotiation_done()"
222 * that every given LSA belongs to the same area with "nbr".
223 */
224 break;
225 case OSPF_OPAQUE_AS_LSA:
226 default:
227 break;
228 }
229#endif /* HAVE_OPAQUE_LSA */
230
paul2d598362003-01-17 23:48:42 +0000231 /* Stay away from any Local Translated Type-7 LSAs */
232 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
233 return 0;
paul2d598362003-01-17 23:48:42 +0000234
235 if (IS_LSA_MAXAGE (lsa))
236 ospf_ls_retransmit_add (nbr, lsa);
237 else
238 ospf_lsdb_add (&nbr->db_sum, lsa);
239
240 return 0;
241}
242
243void
244ospf_db_summary_clear (struct ospf_neighbor *nbr)
245{
246 struct ospf_lsdb *lsdb;
247 int i;
248
249 lsdb = &nbr->db_sum;
250 for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
251 {
252 struct route_table *table = lsdb->type[i].db;
253 struct route_node *rn;
254
255 for (rn = route_top (table); rn; rn = route_next (rn))
256 if (rn->info)
257 ospf_lsdb_delete (&nbr->db_sum, rn->info);
258 }
259}
260
David Lamparter6b0655a2014-06-04 06:53:35 +0200261
paul2d598362003-01-17 23:48:42 +0000262
paul2d598362003-01-17 23:48:42 +0000263/* The area link state database consists of the router-LSAs,
264 network-LSAs and summary-LSAs contained in the area structure,
paul68980082003-03-25 05:07:42 +0000265 along with the AS-external-LSAs contained in the global structure.
266 AS-external-LSAs are omitted from a virtual neighbor's Database
paul2d598362003-01-17 23:48:42 +0000267 summary list. AS-external-LSAs are omitted from the Database
268 summary list if the area has been configured as a stub. */
paul4dadc292005-05-06 21:37:42 +0000269static int
paul2d598362003-01-17 23:48:42 +0000270nsm_negotiation_done (struct ospf_neighbor *nbr)
271{
paul68980082003-03-25 05:07:42 +0000272 struct ospf_area *area = nbr->oi->area;
273 struct ospf_lsa *lsa;
274 struct route_node *rn;
paul2d598362003-01-17 23:48:42 +0000275
paul68980082003-03-25 05:07:42 +0000276 LSDB_LOOP (ROUTER_LSDB (area), rn, lsa)
277 ospf_db_summary_add (nbr, lsa);
278 LSDB_LOOP (NETWORK_LSDB (area), rn, lsa)
279 ospf_db_summary_add (nbr, lsa);
280 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
281 ospf_db_summary_add (nbr, lsa);
282 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
283 ospf_db_summary_add (nbr, lsa);
paul2d598362003-01-17 23:48:42 +0000284
paul2d598362003-01-17 23:48:42 +0000285#ifdef HAVE_OPAQUE_LSA
286 /* Process only if the neighbor is opaque capable. */
287 if (CHECK_FLAG (nbr->options, OSPF_OPTION_O))
288 {
paul68980082003-03-25 05:07:42 +0000289 LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa)
290 ospf_db_summary_add (nbr, lsa);
291 LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa)
292 ospf_db_summary_add (nbr, lsa);
paul2d598362003-01-17 23:48:42 +0000293 }
294#endif /* HAVE_OPAQUE_LSA */
295
hassof4833e92005-06-20 20:42:26 +0000296 if (CHECK_FLAG (nbr->options, OSPF_OPTION_NP))
297 {
298 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
299 ospf_db_summary_add (nbr, lsa);
300 }
301
paul68980082003-03-25 05:07:42 +0000302 if (nbr->oi->type != OSPF_IFTYPE_VIRTUALLINK
303 && area->external_routing == OSPF_AREA_DEFAULT)
304 LSDB_LOOP (EXTERNAL_LSDB (nbr->oi->ospf), rn, lsa)
305 ospf_db_summary_add (nbr, lsa);
paul2d598362003-01-17 23:48:42 +0000306
307#ifdef HAVE_OPAQUE_LSA
paul68980082003-03-25 05:07:42 +0000308 if (CHECK_FLAG (nbr->options, OSPF_OPTION_O)
309 && (nbr->oi->type != OSPF_IFTYPE_VIRTUALLINK
310 && area->external_routing == OSPF_AREA_DEFAULT))
311 LSDB_LOOP (OPAQUE_AS_LSDB (nbr->oi->ospf), rn, lsa)
312 ospf_db_summary_add (nbr, lsa);
paul2d598362003-01-17 23:48:42 +0000313#endif /* HAVE_OPAQUE_LSA */
314
paul2d598362003-01-17 23:48:42 +0000315 return 0;
316}
317
paul4dadc292005-05-06 21:37:42 +0000318static int
paul2d598362003-01-17 23:48:42 +0000319nsm_exchange_done (struct ospf_neighbor *nbr)
320{
paul2d598362003-01-17 23:48:42 +0000321 if (ospf_ls_request_isempty (nbr))
322 return NSM_Full;
323
paul2d598362003-01-17 23:48:42 +0000324 /* Send Link State Request. */
325 ospf_ls_req_send (nbr);
326
327 return NSM_Loading;
328}
329
paul4dadc292005-05-06 21:37:42 +0000330static int
paul2d598362003-01-17 23:48:42 +0000331nsm_adj_ok (struct ospf_neighbor *nbr)
332{
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000333 int next_state = nbr->state;
334 int adj = nsm_should_adj (nbr);
paul2d598362003-01-17 23:48:42 +0000335
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000336 if (nbr->state == NSM_TwoWay && adj == 1)
paul2d598362003-01-17 23:48:42 +0000337 next_state = NSM_ExStart;
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000338 else if (nbr->state >= NSM_ExStart && adj == 0)
paul2d598362003-01-17 23:48:42 +0000339 next_state = NSM_TwoWay;
340
341 return next_state;
342}
343
Paul Jakmad1b1cd82006-07-04 13:50:44 +0000344/* Clear adjacency related state for a neighbour, intended where nbr
345 * transitions from > ExStart (i.e. a Full or forming adjacency)
346 * to <= ExStart.
347 */
348static void
349nsm_clear_adj (struct ospf_neighbor *nbr)
paul2d598362003-01-17 23:48:42 +0000350{
351 /* Clear Database Summary list. */
352 if (!ospf_db_summary_isempty (nbr))
353 ospf_db_summary_clear (nbr);
354
355 /* Clear Link State Request list. */
356 if (!ospf_ls_request_isempty (nbr))
357 ospf_ls_request_delete_all (nbr);
358
359 /* Clear Link State Retransmission list. */
360 if (!ospf_ls_retransmit_isempty (nbr))
361 ospf_ls_retransmit_clear (nbr);
paul2d598362003-01-17 23:48:42 +0000362
363#ifdef HAVE_OPAQUE_LSA
364 if (CHECK_FLAG (nbr->options, OSPF_OPTION_O))
365 UNSET_FLAG (nbr->options, OSPF_OPTION_O);
366#endif /* HAVE_OPAQUE_LSA */
367}
368
paul4dadc292005-05-06 21:37:42 +0000369static int
paul2d598362003-01-17 23:48:42 +0000370nsm_kill_nbr (struct ospf_neighbor *nbr)
371{
Paul Jakma478aab92006-04-03 21:25:32 +0000372 /* killing nbr_self is invalid */
Paul Jakma478aab92006-04-03 21:25:32 +0000373 if (nbr == nbr->oi->nbr_self)
Paul Jakma1f2c2742006-07-10 07:45:13 +0000374 {
375 assert (nbr != nbr->oi->nbr_self);
376 return 0;
377 }
Paul Jakma478aab92006-04-03 21:25:32 +0000378
paul2d598362003-01-17 23:48:42 +0000379 if (nbr->oi->type == OSPF_IFTYPE_NBMA && nbr->nbr_nbma != NULL)
380 {
381 struct ospf_nbr_nbma *nbr_nbma = nbr->nbr_nbma;
382
383 nbr_nbma->nbr = NULL;
384 nbr_nbma->state_change = nbr->state_change;
385
386 nbr->nbr_nbma = NULL;
387
388 OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer,
389 nbr_nbma->v_poll);
390
391 if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
ajs2a42e282004-12-08 18:43:03 +0000392 zlog_debug ("NSM[%s:%s]: Down (PollIntervalTimer scheduled)",
paul2d598362003-01-17 23:48:42 +0000393 IF_NAME (nbr->oi), inet_ntoa (nbr->address.u.prefix4));
394 }
395
paul2d598362003-01-17 23:48:42 +0000396 return 0;
397}
398
paul2d598362003-01-17 23:48:42 +0000399/* Neighbor State Machine */
400struct {
paul4dadc292005-05-06 21:37:42 +0000401 int (*func) (struct ospf_neighbor *);
paul2d598362003-01-17 23:48:42 +0000402 int next_state;
403} NSM [OSPF_NSM_STATE_MAX][OSPF_NSM_EVENT_MAX] =
404{
405 {
406 /* DependUpon: dummy state. */
Paul Jakma539e1522006-07-11 17:49:22 +0000407 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000408 { NULL, NSM_DependUpon }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000409 { NULL, NSM_DependUpon }, /* Start */
410 { NULL, NSM_DependUpon }, /* 2-WayReceived */
411 { NULL, NSM_DependUpon }, /* NegotiationDone */
412 { NULL, NSM_DependUpon }, /* ExchangeDone */
413 { NULL, NSM_DependUpon }, /* BadLSReq */
414 { NULL, NSM_DependUpon }, /* LoadingDone */
415 { NULL, NSM_DependUpon }, /* AdjOK? */
416 { NULL, NSM_DependUpon }, /* SeqNumberMismatch */
417 { NULL, NSM_DependUpon }, /* 1-WayReceived */
418 { NULL, NSM_DependUpon }, /* KillNbr */
419 { NULL, NSM_DependUpon }, /* InactivityTimer */
420 { NULL, NSM_DependUpon }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000421 },
422 {
Paul Jakma1f2c2742006-07-10 07:45:13 +0000423 /* Deleted: dummy state. */
Paul Jakma539e1522006-07-11 17:49:22 +0000424 { NULL, NSM_Deleted }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000425 { NULL, NSM_Deleted }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000426 { NULL, NSM_Deleted }, /* Start */
427 { NULL, NSM_Deleted }, /* 2-WayReceived */
428 { NULL, NSM_Deleted }, /* NegotiationDone */
429 { NULL, NSM_Deleted }, /* ExchangeDone */
430 { NULL, NSM_Deleted }, /* BadLSReq */
431 { NULL, NSM_Deleted }, /* LoadingDone */
432 { NULL, NSM_Deleted }, /* AdjOK? */
433 { NULL, NSM_Deleted }, /* SeqNumberMismatch */
434 { NULL, NSM_Deleted }, /* 1-WayReceived */
435 { NULL, NSM_Deleted }, /* KillNbr */
436 { NULL, NSM_Deleted }, /* InactivityTimer */
437 { NULL, NSM_Deleted }, /* LLDown */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000438 },
439 {
paul2d598362003-01-17 23:48:42 +0000440 /* Down: */
Paul Jakma539e1522006-07-11 17:49:22 +0000441 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000442 { nsm_packet_received, NSM_Init }, /* PacketReceived */
paul2d598362003-01-17 23:48:42 +0000443 { nsm_start, NSM_Attempt }, /* Start */
Paul Jakma539e1522006-07-11 17:49:22 +0000444 { NULL, NSM_Down }, /* 2-WayReceived */
445 { NULL, NSM_Down }, /* NegotiationDone */
446 { NULL, NSM_Down }, /* ExchangeDone */
447 { NULL, NSM_Down }, /* BadLSReq */
448 { NULL, NSM_Down }, /* LoadingDone */
449 { NULL, NSM_Down }, /* AdjOK? */
450 { NULL, NSM_Down }, /* SeqNumberMismatch */
451 { NULL, NSM_Down }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000452 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000453 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
454 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000455 },
456 {
457 /* Attempt: */
Paul Jakma539e1522006-07-11 17:49:22 +0000458 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000459 { nsm_packet_received, NSM_Init }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000460 { NULL, NSM_Attempt }, /* Start */
461 { NULL, NSM_Attempt }, /* 2-WayReceived */
462 { NULL, NSM_Attempt }, /* NegotiationDone */
463 { NULL, NSM_Attempt }, /* ExchangeDone */
464 { NULL, NSM_Attempt }, /* BadLSReq */
465 { NULL, NSM_Attempt }, /* LoadingDone */
466 { NULL, NSM_Attempt }, /* AdjOK? */
467 { NULL, NSM_Attempt }, /* SeqNumberMismatch */
468 { NULL, NSM_Attempt }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000469 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000470 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
471 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000472 },
473 {
474 /* Init: */
Paul Jakma539e1522006-07-11 17:49:22 +0000475 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000476 { nsm_packet_received, NSM_Init }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000477 { NULL, NSM_Init }, /* Start */
paul2d598362003-01-17 23:48:42 +0000478 { nsm_twoway_received, NSM_DependUpon }, /* 2-WayReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000479 { NULL, NSM_Init }, /* NegotiationDone */
480 { NULL, NSM_Init }, /* ExchangeDone */
481 { NULL, NSM_Init }, /* BadLSReq */
482 { NULL, NSM_Init }, /* LoadingDone */
483 { NULL, NSM_Init }, /* AdjOK? */
484 { NULL, NSM_Init }, /* SeqNumberMismatch */
485 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000486 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000487 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
488 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000489 },
490 {
491 /* 2-Way: */
Paul Jakma539e1522006-07-11 17:49:22 +0000492 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000493 { nsm_packet_received, NSM_TwoWay }, /* HelloReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000494 { NULL, NSM_TwoWay }, /* Start */
495 { NULL, NSM_TwoWay }, /* 2-WayReceived */
496 { NULL, NSM_TwoWay }, /* NegotiationDone */
497 { NULL, NSM_TwoWay }, /* ExchangeDone */
498 { NULL, NSM_TwoWay }, /* BadLSReq */
499 { NULL, NSM_TwoWay }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000500 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000501 { NULL, NSM_TwoWay }, /* SeqNumberMismatch */
502 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000503 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000504 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
505 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000506 },
507 {
508 /* ExStart: */
Paul Jakma539e1522006-07-11 17:49:22 +0000509 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000510 { nsm_packet_received, NSM_ExStart }, /* PacaketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000511 { NULL, NSM_ExStart }, /* Start */
512 { NULL, NSM_ExStart }, /* 2-WayReceived */
paul2d598362003-01-17 23:48:42 +0000513 { nsm_negotiation_done, NSM_Exchange }, /* NegotiationDone */
Paul Jakma539e1522006-07-11 17:49:22 +0000514 { NULL, NSM_ExStart }, /* ExchangeDone */
515 { NULL, NSM_ExStart }, /* BadLSReq */
516 { NULL, NSM_ExStart }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000517 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000518 { NULL, NSM_ExStart }, /* SeqNumberMismatch */
519 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000520 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000521 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
522 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000523 },
524 {
525 /* Exchange: */
Paul Jakma539e1522006-07-11 17:49:22 +0000526 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000527 { nsm_packet_received, NSM_Exchange }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000528 { NULL, NSM_Exchange }, /* Start */
529 { NULL, NSM_Exchange }, /* 2-WayReceived */
530 { NULL, NSM_Exchange }, /* NegotiationDone */
paul2d598362003-01-17 23:48:42 +0000531 { nsm_exchange_done, NSM_DependUpon }, /* ExchangeDone */
Paul Jakma539e1522006-07-11 17:49:22 +0000532 { NULL, NSM_ExStart }, /* BadLSReq */
533 { NULL, NSM_Exchange }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000534 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000535 { NULL, NSM_ExStart }, /* SeqNumberMismatch */
536 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000537 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000538 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
539 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000540 },
541 {
542 /* Loading: */
Paul Jakma539e1522006-07-11 17:49:22 +0000543 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000544 { nsm_packet_received, NSM_Loading }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000545 { NULL, NSM_Loading }, /* Start */
546 { NULL, NSM_Loading }, /* 2-WayReceived */
547 { NULL, NSM_Loading }, /* NegotiationDone */
548 { NULL, NSM_Loading }, /* ExchangeDone */
549 { NULL, NSM_ExStart }, /* BadLSReq */
550 { NULL, NSM_Full }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000551 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000552 { NULL, NSM_ExStart }, /* SeqNumberMismatch */
553 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000554 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000555 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
556 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000557 },
558 { /* Full: */
Paul Jakma539e1522006-07-11 17:49:22 +0000559 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000560 { nsm_packet_received, NSM_Full }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000561 { NULL, NSM_Full }, /* Start */
562 { NULL, NSM_Full }, /* 2-WayReceived */
563 { NULL, NSM_Full }, /* NegotiationDone */
564 { NULL, NSM_Full }, /* ExchangeDone */
565 { NULL, NSM_ExStart }, /* BadLSReq */
566 { NULL, NSM_Full }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000567 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000568 { NULL, NSM_ExStart }, /* SeqNumberMismatch */
569 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000570 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000571 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
572 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000573 },
574};
575
Paul Jakma30a22312008-08-15 14:05:22 +0100576static const char *ospf_nsm_event_str[] =
paul2d598362003-01-17 23:48:42 +0000577{
578 "NoEvent",
Paul Jakma57c5c652010-01-07 06:12:53 +0000579 "PacketReceived",
paul2d598362003-01-17 23:48:42 +0000580 "Start",
581 "2-WayReceived",
582 "NegotiationDone",
583 "ExchangeDone",
584 "BadLSReq",
585 "LoadingDone",
586 "AdjOK?",
587 "SeqNumberMismatch",
588 "1-WayReceived",
589 "KillNbr",
590 "InactivityTimer",
591 "LLDown",
592};
593
Paul Jakma3d63f382006-07-11 17:52:53 +0000594static void
595nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event)
596{
597 /* Logging change of status. */
598 if (IS_DEBUG_OSPF (nsm, NSM_STATUS))
599 zlog_debug ("NSM[%s:%s]: State change %s -> %s (%s)",
600 IF_NAME (nbr->oi), inet_ntoa (nbr->router_id),
601 LOOKUP (ospf_nsm_state_msg, nbr->state),
602 LOOKUP (ospf_nsm_state_msg, next_state),
603 ospf_nsm_event_str [event]);
604
605 /* Optionally notify about adjacency changes */
606 if (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_CHANGES) &&
607 (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL) ||
608 (next_state == NSM_Full) || (next_state < nbr->state)))
609 zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)",
610 inet_ntoa (nbr->router_id), IF_NAME (nbr->oi),
611 LOOKUP (ospf_nsm_state_msg, nbr->state),
612 LOOKUP (ospf_nsm_state_msg, next_state),
613 ospf_nsm_event_str [event]);
614
Paul Jakma3fed4162006-07-25 20:44:12 +0000615 /* Advance in NSM */
616 if (next_state > nbr->state)
Paul Jakma2518efd2006-08-27 06:49:29 +0000617 nbr->ts_last_progress = recent_relative_time ();
Paul Jakma3fed4162006-07-25 20:44:12 +0000618 else /* regression in NSM */
619 {
Paul Jakma2518efd2006-08-27 06:49:29 +0000620 nbr->ts_last_regress = recent_relative_time ();
Paul Jakma3fed4162006-07-25 20:44:12 +0000621 nbr->last_regress_str = ospf_nsm_event_str [event];
622 }
Paul Jakma90c33172006-07-11 17:57:25 +0000623
Paul Jakma3d63f382006-07-11 17:52:53 +0000624#ifdef HAVE_SNMP
625 /* Terminal state or regression */
626 if ((next_state == NSM_Full)
627 || (next_state == NSM_TwoWay)
628 || (next_state < nbr->state))
629 {
630 /* ospfVirtNbrStateChange */
631 if (nbr->oi->type == OSPF_IFTYPE_VIRTUALLINK)
632 ospfTrapVirtNbrStateChange(nbr);
633 /* ospfNbrStateChange trap */
634 else
635 /* To/From FULL, only managed by DR */
636 if (((next_state != NSM_Full) && (nbr->state != NSM_Full))
637 || (nbr->oi->state == ISM_DR))
638 ospfTrapNbrStateChange(nbr);
639 }
640#endif
641}
642
Andrew Certainde54b262012-12-04 13:40:58 -0800643static void
paul2d598362003-01-17 23:48:42 +0000644nsm_change_state (struct ospf_neighbor *nbr, int state)
645{
paul68980082003-03-25 05:07:42 +0000646 struct ospf_interface *oi = nbr->oi;
paul2d598362003-01-17 23:48:42 +0000647 struct ospf_area *vl_area = NULL;
648 u_char old_state;
649 int x;
650 int force = 1;
651
paul2d598362003-01-17 23:48:42 +0000652 /* Preserve old status. */
653 old_state = nbr->state;
654
655 /* Change to new status. */
656 nbr->state = state;
657
658 /* Statistics. */
659 nbr->state_change++;
660
paul2d598362003-01-17 23:48:42 +0000661 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000662 vl_area = ospf_area_lookup_by_area_id (oi->ospf, oi->vl_data->vl_area_id);
Andrew J. Schorrd7e60dd2006-06-29 20:20:52 +0000663
Christian Franke7a9d9832013-07-10 11:56:18 +0000664 /* Generate NeighborChange ISM event.
665 *
666 * In response to NeighborChange, DR election is rerun. The information
667 * from the election process is required by the router-lsa construction.
668 *
669 * Therefore, trigger the event prior to refreshing the LSAs. */
670 switch (oi->state) {
671 case ISM_DROther:
672 case ISM_Backup:
673 case ISM_DR:
674 if ((old_state < NSM_TwoWay && state >= NSM_TwoWay) ||
675 (old_state >= NSM_TwoWay && state < NSM_TwoWay))
676 OSPF_ISM_EVENT_EXECUTE (oi, ISM_NeighborChange);
677 break;
678 default:
679 /* ISM_PointToPoint -> ISM_Down, ISM_Loopback -> ISM_Down, etc. */
680 break;
681 }
682
paul2d598362003-01-17 23:48:42 +0000683 /* One of the neighboring routers changes to/from the FULL state. */
684 if ((old_state != NSM_Full && state == NSM_Full) ||
685 (old_state == NSM_Full && state != NSM_Full))
ajs3aa8d5f2004-12-11 18:00:06 +0000686 {
paul2d598362003-01-17 23:48:42 +0000687 if (state == NSM_Full)
688 {
689 oi->full_nbrs++;
690 oi->area->full_nbrs++;
691
paul68980082003-03-25 05:07:42 +0000692 ospf_check_abr_status (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000693
694 if (oi->type == OSPF_IFTYPE_VIRTUALLINK && vl_area)
695 if (++vl_area->full_vls == 1)
paul68980082003-03-25 05:07:42 +0000696 ospf_schedule_abr_task (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000697
698 /* kevinm: refresh any redistributions */
paul68980082003-03-25 05:07:42 +0000699 for (x = ZEBRA_ROUTE_SYSTEM; x < ZEBRA_ROUTE_MAX; x++)
700 {
701 if (x == ZEBRA_ROUTE_OSPF || x == ZEBRA_ROUTE_OSPF6)
702 continue;
703 ospf_external_lsa_refresh_type (oi->ospf, x, force);
704 }
Daniel Ng9fd49582008-08-13 20:37:52 +0100705 /* XXX: Clearly some thing is wrong with refresh of external LSAs
706 * this added to hack around defaults not refreshing after a timer
707 * jump.
708 */
709 ospf_external_lsa_refresh_default (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000710 }
711 else
712 {
713 oi->full_nbrs--;
714 oi->area->full_nbrs--;
715
paul68980082003-03-25 05:07:42 +0000716 ospf_check_abr_status (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000717
718 if (oi->type == OSPF_IFTYPE_VIRTUALLINK && vl_area)
719 if (vl_area->full_vls > 0)
720 if (--vl_area->full_vls == 0)
paul68980082003-03-25 05:07:42 +0000721 ospf_schedule_abr_task (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000722 }
723
ajs3aa8d5f2004-12-11 18:00:06 +0000724 zlog_info ("nsm_change_state(%s, %s -> %s): "
725 "scheduling new router-LSA origination",
726 inet_ntoa (nbr->router_id),
727 LOOKUP(ospf_nsm_state_msg, old_state),
728 LOOKUP(ospf_nsm_state_msg, state));
paul2d598362003-01-17 23:48:42 +0000729
Paul Jakmac363d382010-01-24 22:42:13 +0000730 ospf_router_lsa_update_area (oi->area);
paul2d598362003-01-17 23:48:42 +0000731
732 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
733 {
734 struct ospf_area *vl_area =
paul68980082003-03-25 05:07:42 +0000735 ospf_area_lookup_by_area_id (oi->ospf, oi->vl_data->vl_area_id);
paul2d598362003-01-17 23:48:42 +0000736
737 if (vl_area)
Paul Jakmac363d382010-01-24 22:42:13 +0000738 ospf_router_lsa_update_area (vl_area);
paul2d598362003-01-17 23:48:42 +0000739 }
740
741 /* Originate network-LSA. */
742 if (oi->state == ISM_DR)
743 {
744 if (oi->network_lsa_self && oi->full_nbrs == 0)
745 {
746 ospf_lsa_flush_area (oi->network_lsa_self, oi->area);
Paul Jakma1fe6ed32006-07-26 09:37:26 +0000747 ospf_lsa_unlock (&oi->network_lsa_self);
paul2d598362003-01-17 23:48:42 +0000748 oi->network_lsa_self = NULL;
paul2d598362003-01-17 23:48:42 +0000749 }
750 else
Paul Jakmac363d382010-01-24 22:42:13 +0000751 ospf_network_lsa_update (oi);
paul2d598362003-01-17 23:48:42 +0000752 }
753 }
754
755#ifdef HAVE_OPAQUE_LSA
756 ospf_opaque_nsm_change (nbr, old_state);
757#endif /* HAVE_OPAQUE_LSA */
758
Paul Jakmad1b1cd82006-07-04 13:50:44 +0000759 /* State changes from > ExStart to <= ExStart should clear any Exchange
760 * or Full/LSA Update related lists and state.
761 * Potential causal events: BadLSReq, SeqNumberMismatch, AdjOK?
Paul Jakmad1b1cd82006-07-04 13:50:44 +0000762 */
Paul Jakma539e1522006-07-11 17:49:22 +0000763 if ((old_state > NSM_ExStart) && (state <= NSM_ExStart))
Paul Jakmad1b1cd82006-07-04 13:50:44 +0000764 nsm_clear_adj (nbr);
765
paul2d598362003-01-17 23:48:42 +0000766 /* Start DD exchange protocol */
767 if (state == NSM_ExStart)
768 {
769 if (nbr->dd_seqnum == 0)
Paul Jakma2518efd2006-08-27 06:49:29 +0000770 nbr->dd_seqnum = quagga_time (NULL);
paul2d598362003-01-17 23:48:42 +0000771 else
772 nbr->dd_seqnum++;
773
774 nbr->dd_flags = OSPF_DD_FLAG_I|OSPF_DD_FLAG_M|OSPF_DD_FLAG_MS;
775 ospf_db_desc_send (nbr);
776 }
777
778 /* clear cryptographic sequence number */
779 if (state == NSM_Down)
780 nbr->crypt_seqnum = 0;
781
paul2d598362003-01-17 23:48:42 +0000782 /* Preserve old status? */
783}
784
785/* Execute NSM event process. */
786int
787ospf_nsm_event (struct thread *thread)
788{
789 int event;
790 int next_state;
791 struct ospf_neighbor *nbr;
paul2d598362003-01-17 23:48:42 +0000792
793 nbr = THREAD_ARG (thread);
794 event = THREAD_VAL (thread);
paul2d598362003-01-17 23:48:42 +0000795
Paul Jakma3d63f382006-07-11 17:52:53 +0000796 if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
797 zlog_debug ("NSM[%s:%s]: %s (%s)", IF_NAME (nbr->oi),
798 inet_ntoa (nbr->router_id),
799 LOOKUP (ospf_nsm_state_msg, nbr->state),
800 ospf_nsm_event_str [event]);
801
Paul Jakma539e1522006-07-11 17:49:22 +0000802 next_state = NSM [nbr->state][event].next_state;
paul2d598362003-01-17 23:48:42 +0000803
Paul Jakma539e1522006-07-11 17:49:22 +0000804 /* Call function. */
805 if (NSM [nbr->state][event].func != NULL)
Paul Jakmaba0beb42006-07-04 13:44:19 +0000806 {
Paul Jakma539e1522006-07-11 17:49:22 +0000807 int func_state = (*(NSM [nbr->state][event].func))(nbr);
Paul Jakmaba0beb42006-07-04 13:44:19 +0000808
Paul Jakma539e1522006-07-11 17:49:22 +0000809 if (NSM [nbr->state][event].next_state == NSM_DependUpon)
810 next_state = func_state;
811 else if (func_state)
812 {
813 /* There's a mismatch between the FSM tables and what an FSM
814 * action/state-change function returned. State changes which
815 * do not have conditional/DependUpon next-states should not
816 * try set next_state.
817 */
818 zlog_warn ("NSM[%s:%s]: %s (%s): "
819 "Warning: action tried to change next_state to %s",
820 IF_NAME (nbr->oi), inet_ntoa (nbr->router_id),
821 LOOKUP (ospf_nsm_state_msg, nbr->state),
822 ospf_nsm_event_str [event],
823 LOOKUP (ospf_nsm_state_msg, func_state));
824 }
Paul Jakmaba0beb42006-07-04 13:44:19 +0000825 }
paul2d598362003-01-17 23:48:42 +0000826
Paul Jakma539e1522006-07-11 17:49:22 +0000827 assert (next_state != NSM_DependUpon);
828
paul2d598362003-01-17 23:48:42 +0000829 /* If state is changed. */
830 if (next_state != nbr->state)
Paul Jakma3d63f382006-07-11 17:52:53 +0000831 {
832 nsm_notice_state_change (nbr, next_state, event);
833 nsm_change_state (nbr, next_state);
834 }
paul2d598362003-01-17 23:48:42 +0000835
836 /* Make sure timer is set. */
837 nsm_timer_set (nbr);
838
Paul Jakma1f2c2742006-07-10 07:45:13 +0000839 /* When event is NSM_KillNbr, InactivityTimer or LLDown, the neighbor
840 * is deleted.
841 *
842 * Rather than encode knowledge here of which events lead to NBR
843 * delete, we take our cue from the NSM table, via the dummy
844 * 'Deleted' neighbour state.
845 */
846 if (nbr->state == NSM_Deleted)
847 ospf_nbr_delete (nbr);
848
paul2d598362003-01-17 23:48:42 +0000849 return 0;
850}
851
852/* Check loading state. */
853void
854ospf_check_nbr_loading (struct ospf_neighbor *nbr)
855{
856 if (nbr->state == NSM_Loading)
857 {
858 if (ospf_ls_request_isempty (nbr))
859 OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_LoadingDone);
860 else if (nbr->ls_req_last == NULL)
861 ospf_ls_req_event (nbr);
862 }
863}