blob: 5c01a5869fd86efcdec219809733301a49c8797c [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 switch (lsa->data->type)
212 {
213 case OSPF_OPAQUE_LINK_LSA:
214 /* Exclude type-9 LSAs that does not have the same "oi" with "nbr". */
Paul Jakmad71ea652011-03-22 15:23:55 +0000215 if (nbr->oi && ospf_if_exists (lsa->oi) != nbr->oi)
paul09e4efd2003-01-18 00:12:02 +0000216 return 0;
217 break;
218 case OSPF_OPAQUE_AREA_LSA:
219 /*
220 * It is assured by the caller function "nsm_negotiation_done()"
221 * that every given LSA belongs to the same area with "nbr".
222 */
223 break;
224 case OSPF_OPAQUE_AS_LSA:
225 default:
226 break;
227 }
paul09e4efd2003-01-18 00:12:02 +0000228
paul2d598362003-01-17 23:48:42 +0000229 /* Stay away from any Local Translated Type-7 LSAs */
230 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
231 return 0;
paul2d598362003-01-17 23:48:42 +0000232
233 if (IS_LSA_MAXAGE (lsa))
234 ospf_ls_retransmit_add (nbr, lsa);
235 else
236 ospf_lsdb_add (&nbr->db_sum, lsa);
237
238 return 0;
239}
240
241void
242ospf_db_summary_clear (struct ospf_neighbor *nbr)
243{
244 struct ospf_lsdb *lsdb;
245 int i;
246
247 lsdb = &nbr->db_sum;
248 for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
249 {
250 struct route_table *table = lsdb->type[i].db;
251 struct route_node *rn;
252
253 for (rn = route_top (table); rn; rn = route_next (rn))
254 if (rn->info)
255 ospf_lsdb_delete (&nbr->db_sum, rn->info);
256 }
257}
258
David Lamparter6b0655a2014-06-04 06:53:35 +0200259
paul2d598362003-01-17 23:48:42 +0000260
paul2d598362003-01-17 23:48:42 +0000261/* The area link state database consists of the router-LSAs,
262 network-LSAs and summary-LSAs contained in the area structure,
paul68980082003-03-25 05:07:42 +0000263 along with the AS-external-LSAs contained in the global structure.
264 AS-external-LSAs are omitted from a virtual neighbor's Database
paul2d598362003-01-17 23:48:42 +0000265 summary list. AS-external-LSAs are omitted from the Database
266 summary list if the area has been configured as a stub. */
paul4dadc292005-05-06 21:37:42 +0000267static int
paul2d598362003-01-17 23:48:42 +0000268nsm_negotiation_done (struct ospf_neighbor *nbr)
269{
paul68980082003-03-25 05:07:42 +0000270 struct ospf_area *area = nbr->oi->area;
271 struct ospf_lsa *lsa;
272 struct route_node *rn;
paul2d598362003-01-17 23:48:42 +0000273
paul68980082003-03-25 05:07:42 +0000274 LSDB_LOOP (ROUTER_LSDB (area), rn, lsa)
275 ospf_db_summary_add (nbr, lsa);
276 LSDB_LOOP (NETWORK_LSDB (area), rn, lsa)
277 ospf_db_summary_add (nbr, lsa);
278 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
279 ospf_db_summary_add (nbr, lsa);
280 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
281 ospf_db_summary_add (nbr, lsa);
paul2d598362003-01-17 23:48:42 +0000282
paul2d598362003-01-17 23:48:42 +0000283 /* Process only if the neighbor is opaque capable. */
284 if (CHECK_FLAG (nbr->options, OSPF_OPTION_O))
285 {
paul68980082003-03-25 05:07:42 +0000286 LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa)
287 ospf_db_summary_add (nbr, lsa);
288 LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa)
289 ospf_db_summary_add (nbr, lsa);
paul2d598362003-01-17 23:48:42 +0000290 }
paul2d598362003-01-17 23:48:42 +0000291
hassof4833e92005-06-20 20:42:26 +0000292 if (CHECK_FLAG (nbr->options, OSPF_OPTION_NP))
293 {
294 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
295 ospf_db_summary_add (nbr, lsa);
296 }
297
paul68980082003-03-25 05:07:42 +0000298 if (nbr->oi->type != OSPF_IFTYPE_VIRTUALLINK
299 && area->external_routing == OSPF_AREA_DEFAULT)
300 LSDB_LOOP (EXTERNAL_LSDB (nbr->oi->ospf), rn, lsa)
301 ospf_db_summary_add (nbr, lsa);
paul2d598362003-01-17 23:48:42 +0000302
paul68980082003-03-25 05:07:42 +0000303 if (CHECK_FLAG (nbr->options, OSPF_OPTION_O)
304 && (nbr->oi->type != OSPF_IFTYPE_VIRTUALLINK
305 && area->external_routing == OSPF_AREA_DEFAULT))
306 LSDB_LOOP (OPAQUE_AS_LSDB (nbr->oi->ospf), rn, lsa)
307 ospf_db_summary_add (nbr, lsa);
paul2d598362003-01-17 23:48:42 +0000308
Dinesh Duttf687b622015-05-19 18:03:50 -0700309 /* Send Link State Request. */
310 if (nbr->t_ls_req == NULL)
311 ospf_ls_req_send (nbr);
312
paul2d598362003-01-17 23:48:42 +0000313 return 0;
314}
315
paul4dadc292005-05-06 21:37:42 +0000316static int
paul2d598362003-01-17 23:48:42 +0000317nsm_exchange_done (struct ospf_neighbor *nbr)
318{
paul2d598362003-01-17 23:48:42 +0000319 if (ospf_ls_request_isempty (nbr))
320 return NSM_Full;
Dinesh Duttf687b622015-05-19 18:03:50 -0700321
322 if (nbr->t_ls_req == NULL)
323 ospf_ls_req_send (nbr);
324
paul2d598362003-01-17 23:48:42 +0000325 return NSM_Loading;
326}
327
paul4dadc292005-05-06 21:37:42 +0000328static int
paul2d598362003-01-17 23:48:42 +0000329nsm_adj_ok (struct ospf_neighbor *nbr)
330{
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000331 int next_state = nbr->state;
332 int adj = nsm_should_adj (nbr);
paul2d598362003-01-17 23:48:42 +0000333
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000334 if (nbr->state == NSM_TwoWay && adj == 1)
paul2d598362003-01-17 23:48:42 +0000335 next_state = NSM_ExStart;
Paul Jakmad7b0fb62006-07-04 13:35:24 +0000336 else if (nbr->state >= NSM_ExStart && adj == 0)
paul2d598362003-01-17 23:48:42 +0000337 next_state = NSM_TwoWay;
338
339 return next_state;
340}
341
Paul Jakmad1b1cd82006-07-04 13:50:44 +0000342/* Clear adjacency related state for a neighbour, intended where nbr
343 * transitions from > ExStart (i.e. a Full or forming adjacency)
344 * to <= ExStart.
345 */
346static void
347nsm_clear_adj (struct ospf_neighbor *nbr)
paul2d598362003-01-17 23:48:42 +0000348{
349 /* Clear Database Summary list. */
350 if (!ospf_db_summary_isempty (nbr))
351 ospf_db_summary_clear (nbr);
352
353 /* Clear Link State Request list. */
354 if (!ospf_ls_request_isempty (nbr))
355 ospf_ls_request_delete_all (nbr);
356
357 /* Clear Link State Retransmission list. */
358 if (!ospf_ls_retransmit_isempty (nbr))
359 ospf_ls_retransmit_clear (nbr);
paul2d598362003-01-17 23:48:42 +0000360
paul2d598362003-01-17 23:48:42 +0000361 if (CHECK_FLAG (nbr->options, OSPF_OPTION_O))
362 UNSET_FLAG (nbr->options, OSPF_OPTION_O);
paul2d598362003-01-17 23:48:42 +0000363}
364
paul4dadc292005-05-06 21:37:42 +0000365static int
paul2d598362003-01-17 23:48:42 +0000366nsm_kill_nbr (struct ospf_neighbor *nbr)
367{
Paul Jakma478aab92006-04-03 21:25:32 +0000368 /* killing nbr_self is invalid */
Paul Jakma478aab92006-04-03 21:25:32 +0000369 if (nbr == nbr->oi->nbr_self)
Paul Jakma1f2c2742006-07-10 07:45:13 +0000370 {
371 assert (nbr != nbr->oi->nbr_self);
372 return 0;
373 }
Paul Jakma478aab92006-04-03 21:25:32 +0000374
paul2d598362003-01-17 23:48:42 +0000375 if (nbr->oi->type == OSPF_IFTYPE_NBMA && nbr->nbr_nbma != NULL)
376 {
377 struct ospf_nbr_nbma *nbr_nbma = nbr->nbr_nbma;
378
379 nbr_nbma->nbr = NULL;
380 nbr_nbma->state_change = nbr->state_change;
381
382 nbr->nbr_nbma = NULL;
383
384 OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer,
385 nbr_nbma->v_poll);
386
387 if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
ajs2a42e282004-12-08 18:43:03 +0000388 zlog_debug ("NSM[%s:%s]: Down (PollIntervalTimer scheduled)",
paul2d598362003-01-17 23:48:42 +0000389 IF_NAME (nbr->oi), inet_ntoa (nbr->address.u.prefix4));
390 }
391
paul2d598362003-01-17 23:48:42 +0000392 return 0;
393}
394
paul2d598362003-01-17 23:48:42 +0000395/* Neighbor State Machine */
396struct {
paul4dadc292005-05-06 21:37:42 +0000397 int (*func) (struct ospf_neighbor *);
paul2d598362003-01-17 23:48:42 +0000398 int next_state;
399} NSM [OSPF_NSM_STATE_MAX][OSPF_NSM_EVENT_MAX] =
400{
401 {
402 /* DependUpon: dummy state. */
Paul Jakma539e1522006-07-11 17:49:22 +0000403 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000404 { NULL, NSM_DependUpon }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000405 { NULL, NSM_DependUpon }, /* Start */
406 { NULL, NSM_DependUpon }, /* 2-WayReceived */
407 { NULL, NSM_DependUpon }, /* NegotiationDone */
408 { NULL, NSM_DependUpon }, /* ExchangeDone */
409 { NULL, NSM_DependUpon }, /* BadLSReq */
410 { NULL, NSM_DependUpon }, /* LoadingDone */
411 { NULL, NSM_DependUpon }, /* AdjOK? */
412 { NULL, NSM_DependUpon }, /* SeqNumberMismatch */
413 { NULL, NSM_DependUpon }, /* 1-WayReceived */
414 { NULL, NSM_DependUpon }, /* KillNbr */
415 { NULL, NSM_DependUpon }, /* InactivityTimer */
416 { NULL, NSM_DependUpon }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000417 },
418 {
Paul Jakma1f2c2742006-07-10 07:45:13 +0000419 /* Deleted: dummy state. */
Paul Jakma539e1522006-07-11 17:49:22 +0000420 { NULL, NSM_Deleted }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000421 { NULL, NSM_Deleted }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000422 { NULL, NSM_Deleted }, /* Start */
423 { NULL, NSM_Deleted }, /* 2-WayReceived */
424 { NULL, NSM_Deleted }, /* NegotiationDone */
425 { NULL, NSM_Deleted }, /* ExchangeDone */
426 { NULL, NSM_Deleted }, /* BadLSReq */
427 { NULL, NSM_Deleted }, /* LoadingDone */
428 { NULL, NSM_Deleted }, /* AdjOK? */
429 { NULL, NSM_Deleted }, /* SeqNumberMismatch */
430 { NULL, NSM_Deleted }, /* 1-WayReceived */
431 { NULL, NSM_Deleted }, /* KillNbr */
432 { NULL, NSM_Deleted }, /* InactivityTimer */
433 { NULL, NSM_Deleted }, /* LLDown */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000434 },
435 {
paul2d598362003-01-17 23:48:42 +0000436 /* Down: */
Paul Jakma539e1522006-07-11 17:49:22 +0000437 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000438 { nsm_packet_received, NSM_Init }, /* PacketReceived */
paul2d598362003-01-17 23:48:42 +0000439 { nsm_start, NSM_Attempt }, /* Start */
Paul Jakma539e1522006-07-11 17:49:22 +0000440 { NULL, NSM_Down }, /* 2-WayReceived */
441 { NULL, NSM_Down }, /* NegotiationDone */
442 { NULL, NSM_Down }, /* ExchangeDone */
443 { NULL, NSM_Down }, /* BadLSReq */
444 { NULL, NSM_Down }, /* LoadingDone */
445 { NULL, NSM_Down }, /* AdjOK? */
446 { NULL, NSM_Down }, /* SeqNumberMismatch */
447 { NULL, NSM_Down }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000448 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000449 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
450 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000451 },
452 {
453 /* Attempt: */
Paul Jakma539e1522006-07-11 17:49:22 +0000454 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000455 { nsm_packet_received, NSM_Init }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000456 { NULL, NSM_Attempt }, /* Start */
457 { NULL, NSM_Attempt }, /* 2-WayReceived */
458 { NULL, NSM_Attempt }, /* NegotiationDone */
459 { NULL, NSM_Attempt }, /* ExchangeDone */
460 { NULL, NSM_Attempt }, /* BadLSReq */
461 { NULL, NSM_Attempt }, /* LoadingDone */
462 { NULL, NSM_Attempt }, /* AdjOK? */
463 { NULL, NSM_Attempt }, /* SeqNumberMismatch */
464 { NULL, NSM_Attempt }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000465 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000466 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
467 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000468 },
469 {
470 /* Init: */
Paul Jakma539e1522006-07-11 17:49:22 +0000471 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000472 { nsm_packet_received, NSM_Init }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000473 { NULL, NSM_Init }, /* Start */
paul2d598362003-01-17 23:48:42 +0000474 { nsm_twoway_received, NSM_DependUpon }, /* 2-WayReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000475 { NULL, NSM_Init }, /* NegotiationDone */
476 { NULL, NSM_Init }, /* ExchangeDone */
477 { NULL, NSM_Init }, /* BadLSReq */
478 { NULL, NSM_Init }, /* LoadingDone */
479 { NULL, NSM_Init }, /* AdjOK? */
480 { NULL, NSM_Init }, /* SeqNumberMismatch */
481 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000482 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000483 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
484 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000485 },
486 {
487 /* 2-Way: */
Paul Jakma539e1522006-07-11 17:49:22 +0000488 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000489 { nsm_packet_received, NSM_TwoWay }, /* HelloReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000490 { NULL, NSM_TwoWay }, /* Start */
491 { NULL, NSM_TwoWay }, /* 2-WayReceived */
492 { NULL, NSM_TwoWay }, /* NegotiationDone */
493 { NULL, NSM_TwoWay }, /* ExchangeDone */
494 { NULL, NSM_TwoWay }, /* BadLSReq */
495 { NULL, NSM_TwoWay }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000496 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000497 { NULL, NSM_TwoWay }, /* SeqNumberMismatch */
498 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000499 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000500 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
501 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000502 },
503 {
504 /* ExStart: */
Paul Jakma539e1522006-07-11 17:49:22 +0000505 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000506 { nsm_packet_received, NSM_ExStart }, /* PacaketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000507 { NULL, NSM_ExStart }, /* Start */
508 { NULL, NSM_ExStart }, /* 2-WayReceived */
paul2d598362003-01-17 23:48:42 +0000509 { nsm_negotiation_done, NSM_Exchange }, /* NegotiationDone */
Paul Jakma539e1522006-07-11 17:49:22 +0000510 { NULL, NSM_ExStart }, /* ExchangeDone */
511 { NULL, NSM_ExStart }, /* BadLSReq */
512 { NULL, NSM_ExStart }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000513 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000514 { NULL, NSM_ExStart }, /* SeqNumberMismatch */
515 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000516 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000517 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
518 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000519 },
520 {
521 /* Exchange: */
Paul Jakma539e1522006-07-11 17:49:22 +0000522 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000523 { nsm_packet_received, NSM_Exchange }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000524 { NULL, NSM_Exchange }, /* Start */
525 { NULL, NSM_Exchange }, /* 2-WayReceived */
526 { NULL, NSM_Exchange }, /* NegotiationDone */
paul2d598362003-01-17 23:48:42 +0000527 { nsm_exchange_done, NSM_DependUpon }, /* ExchangeDone */
Paul Jakma539e1522006-07-11 17:49:22 +0000528 { NULL, NSM_ExStart }, /* BadLSReq */
529 { NULL, NSM_Exchange }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000530 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000531 { NULL, NSM_ExStart }, /* SeqNumberMismatch */
532 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000533 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000534 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
535 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000536 },
537 {
538 /* Loading: */
Paul Jakma539e1522006-07-11 17:49:22 +0000539 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000540 { nsm_packet_received, NSM_Loading }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000541 { NULL, NSM_Loading }, /* Start */
542 { NULL, NSM_Loading }, /* 2-WayReceived */
543 { NULL, NSM_Loading }, /* NegotiationDone */
544 { NULL, NSM_Loading }, /* ExchangeDone */
545 { NULL, NSM_ExStart }, /* BadLSReq */
546 { NULL, NSM_Full }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000547 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000548 { NULL, NSM_ExStart }, /* SeqNumberMismatch */
549 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000550 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000551 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
552 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000553 },
554 { /* Full: */
Paul Jakma539e1522006-07-11 17:49:22 +0000555 { NULL, NSM_DependUpon }, /* NoEvent */
Paul Jakma57c5c652010-01-07 06:12:53 +0000556 { nsm_packet_received, NSM_Full }, /* PacketReceived */
Paul Jakma539e1522006-07-11 17:49:22 +0000557 { NULL, NSM_Full }, /* Start */
558 { NULL, NSM_Full }, /* 2-WayReceived */
559 { NULL, NSM_Full }, /* NegotiationDone */
560 { NULL, NSM_Full }, /* ExchangeDone */
561 { NULL, NSM_ExStart }, /* BadLSReq */
562 { NULL, NSM_Full }, /* LoadingDone */
paul2d598362003-01-17 23:48:42 +0000563 { nsm_adj_ok, NSM_DependUpon }, /* AdjOK? */
Paul Jakma539e1522006-07-11 17:49:22 +0000564 { NULL, NSM_ExStart }, /* SeqNumberMismatch */
565 { NULL, NSM_Init }, /* 1-WayReceived */
Paul Jakma1f2c2742006-07-10 07:45:13 +0000566 { nsm_kill_nbr, NSM_Deleted }, /* KillNbr */
Paul Jakma539e1522006-07-11 17:49:22 +0000567 { nsm_kill_nbr, NSM_Deleted }, /* InactivityTimer */
568 { nsm_kill_nbr, NSM_Deleted }, /* LLDown */
paul2d598362003-01-17 23:48:42 +0000569 },
570};
571
Paul Jakma30a22312008-08-15 14:05:22 +0100572static const char *ospf_nsm_event_str[] =
paul2d598362003-01-17 23:48:42 +0000573{
574 "NoEvent",
Paul Jakma57c5c652010-01-07 06:12:53 +0000575 "PacketReceived",
paul2d598362003-01-17 23:48:42 +0000576 "Start",
577 "2-WayReceived",
578 "NegotiationDone",
579 "ExchangeDone",
580 "BadLSReq",
581 "LoadingDone",
582 "AdjOK?",
583 "SeqNumberMismatch",
584 "1-WayReceived",
585 "KillNbr",
586 "InactivityTimer",
587 "LLDown",
588};
589
Paul Jakma3d63f382006-07-11 17:52:53 +0000590static void
591nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event)
592{
593 /* Logging change of status. */
594 if (IS_DEBUG_OSPF (nsm, NSM_STATUS))
595 zlog_debug ("NSM[%s:%s]: State change %s -> %s (%s)",
596 IF_NAME (nbr->oi), inet_ntoa (nbr->router_id),
597 LOOKUP (ospf_nsm_state_msg, nbr->state),
598 LOOKUP (ospf_nsm_state_msg, next_state),
599 ospf_nsm_event_str [event]);
600
601 /* Optionally notify about adjacency changes */
602 if (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_CHANGES) &&
603 (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL) ||
604 (next_state == NSM_Full) || (next_state < nbr->state)))
605 zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)",
606 inet_ntoa (nbr->router_id), IF_NAME (nbr->oi),
607 LOOKUP (ospf_nsm_state_msg, nbr->state),
608 LOOKUP (ospf_nsm_state_msg, next_state),
609 ospf_nsm_event_str [event]);
610
Paul Jakma3fed4162006-07-25 20:44:12 +0000611 /* Advance in NSM */
612 if (next_state > nbr->state)
Paul Jakma2518efd2006-08-27 06:49:29 +0000613 nbr->ts_last_progress = recent_relative_time ();
Paul Jakma3fed4162006-07-25 20:44:12 +0000614 else /* regression in NSM */
615 {
Paul Jakma2518efd2006-08-27 06:49:29 +0000616 nbr->ts_last_regress = recent_relative_time ();
Paul Jakma3fed4162006-07-25 20:44:12 +0000617 nbr->last_regress_str = ospf_nsm_event_str [event];
618 }
Paul Jakma90c33172006-07-11 17:57:25 +0000619
Paul Jakma3d63f382006-07-11 17:52:53 +0000620}
621
Andrew Certainde54b262012-12-04 13:40:58 -0800622static void
paul2d598362003-01-17 23:48:42 +0000623nsm_change_state (struct ospf_neighbor *nbr, int state)
624{
paul68980082003-03-25 05:07:42 +0000625 struct ospf_interface *oi = nbr->oi;
paul2d598362003-01-17 23:48:42 +0000626 struct ospf_area *vl_area = NULL;
627 u_char old_state;
628 int x;
629 int force = 1;
630
paul2d598362003-01-17 23:48:42 +0000631 /* Preserve old status. */
632 old_state = nbr->state;
633
634 /* Change to new status. */
635 nbr->state = state;
636
637 /* Statistics. */
638 nbr->state_change++;
639
paul2d598362003-01-17 23:48:42 +0000640 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
paul68980082003-03-25 05:07:42 +0000641 vl_area = ospf_area_lookup_by_area_id (oi->ospf, oi->vl_data->vl_area_id);
Andrew J. Schorrd7e60dd2006-06-29 20:20:52 +0000642
Christian Franke7a9d9832013-07-10 11:56:18 +0000643 /* Generate NeighborChange ISM event.
644 *
645 * In response to NeighborChange, DR election is rerun. The information
646 * from the election process is required by the router-lsa construction.
647 *
648 * Therefore, trigger the event prior to refreshing the LSAs. */
649 switch (oi->state) {
650 case ISM_DROther:
651 case ISM_Backup:
652 case ISM_DR:
653 if ((old_state < NSM_TwoWay && state >= NSM_TwoWay) ||
654 (old_state >= NSM_TwoWay && state < NSM_TwoWay))
655 OSPF_ISM_EVENT_EXECUTE (oi, ISM_NeighborChange);
656 break;
657 default:
658 /* ISM_PointToPoint -> ISM_Down, ISM_Loopback -> ISM_Down, etc. */
659 break;
660 }
661
paul2d598362003-01-17 23:48:42 +0000662 /* One of the neighboring routers changes to/from the FULL state. */
663 if ((old_state != NSM_Full && state == NSM_Full) ||
664 (old_state == NSM_Full && state != NSM_Full))
ajs3aa8d5f2004-12-11 18:00:06 +0000665 {
paul2d598362003-01-17 23:48:42 +0000666 if (state == NSM_Full)
667 {
668 oi->full_nbrs++;
669 oi->area->full_nbrs++;
670
paul68980082003-03-25 05:07:42 +0000671 ospf_check_abr_status (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000672
673 if (oi->type == OSPF_IFTYPE_VIRTUALLINK && vl_area)
674 if (++vl_area->full_vls == 1)
paul68980082003-03-25 05:07:42 +0000675 ospf_schedule_abr_task (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000676
677 /* kevinm: refresh any redistributions */
paul68980082003-03-25 05:07:42 +0000678 for (x = ZEBRA_ROUTE_SYSTEM; x < ZEBRA_ROUTE_MAX; x++)
679 {
680 if (x == ZEBRA_ROUTE_OSPF || x == ZEBRA_ROUTE_OSPF6)
681 continue;
682 ospf_external_lsa_refresh_type (oi->ospf, x, force);
683 }
Daniel Ng9fd49582008-08-13 20:37:52 +0100684 /* XXX: Clearly some thing is wrong with refresh of external LSAs
685 * this added to hack around defaults not refreshing after a timer
686 * jump.
687 */
688 ospf_external_lsa_refresh_default (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000689 }
690 else
691 {
692 oi->full_nbrs--;
693 oi->area->full_nbrs--;
694
paul68980082003-03-25 05:07:42 +0000695 ospf_check_abr_status (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000696
697 if (oi->type == OSPF_IFTYPE_VIRTUALLINK && vl_area)
698 if (vl_area->full_vls > 0)
699 if (--vl_area->full_vls == 0)
paul68980082003-03-25 05:07:42 +0000700 ospf_schedule_abr_task (oi->ospf);
paul2d598362003-01-17 23:48:42 +0000701 }
702
ajs3aa8d5f2004-12-11 18:00:06 +0000703 zlog_info ("nsm_change_state(%s, %s -> %s): "
704 "scheduling new router-LSA origination",
705 inet_ntoa (nbr->router_id),
706 LOOKUP(ospf_nsm_state_msg, old_state),
707 LOOKUP(ospf_nsm_state_msg, state));
paul2d598362003-01-17 23:48:42 +0000708
Paul Jakmac363d382010-01-24 22:42:13 +0000709 ospf_router_lsa_update_area (oi->area);
paul2d598362003-01-17 23:48:42 +0000710
711 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
712 {
713 struct ospf_area *vl_area =
paul68980082003-03-25 05:07:42 +0000714 ospf_area_lookup_by_area_id (oi->ospf, oi->vl_data->vl_area_id);
paul2d598362003-01-17 23:48:42 +0000715
716 if (vl_area)
Paul Jakmac363d382010-01-24 22:42:13 +0000717 ospf_router_lsa_update_area (vl_area);
paul2d598362003-01-17 23:48:42 +0000718 }
719
720 /* Originate network-LSA. */
721 if (oi->state == ISM_DR)
722 {
723 if (oi->network_lsa_self && oi->full_nbrs == 0)
724 {
725 ospf_lsa_flush_area (oi->network_lsa_self, oi->area);
Paul Jakma1fe6ed32006-07-26 09:37:26 +0000726 ospf_lsa_unlock (&oi->network_lsa_self);
paul2d598362003-01-17 23:48:42 +0000727 oi->network_lsa_self = NULL;
paul2d598362003-01-17 23:48:42 +0000728 }
729 else
Paul Jakmac363d382010-01-24 22:42:13 +0000730 ospf_network_lsa_update (oi);
paul2d598362003-01-17 23:48:42 +0000731 }
732 }
733
paul2d598362003-01-17 23:48:42 +0000734 ospf_opaque_nsm_change (nbr, old_state);
paul2d598362003-01-17 23:48:42 +0000735
Paul Jakmad1b1cd82006-07-04 13:50:44 +0000736 /* State changes from > ExStart to <= ExStart should clear any Exchange
737 * or Full/LSA Update related lists and state.
738 * Potential causal events: BadLSReq, SeqNumberMismatch, AdjOK?
Paul Jakmad1b1cd82006-07-04 13:50:44 +0000739 */
Paul Jakma539e1522006-07-11 17:49:22 +0000740 if ((old_state > NSM_ExStart) && (state <= NSM_ExStart))
Paul Jakmad1b1cd82006-07-04 13:50:44 +0000741 nsm_clear_adj (nbr);
742
paul2d598362003-01-17 23:48:42 +0000743 /* Start DD exchange protocol */
744 if (state == NSM_ExStart)
745 {
746 if (nbr->dd_seqnum == 0)
Paul Jakma2518efd2006-08-27 06:49:29 +0000747 nbr->dd_seqnum = quagga_time (NULL);
paul2d598362003-01-17 23:48:42 +0000748 else
749 nbr->dd_seqnum++;
750
751 nbr->dd_flags = OSPF_DD_FLAG_I|OSPF_DD_FLAG_M|OSPF_DD_FLAG_MS;
752 ospf_db_desc_send (nbr);
753 }
754
755 /* clear cryptographic sequence number */
756 if (state == NSM_Down)
757 nbr->crypt_seqnum = 0;
758
paul2d598362003-01-17 23:48:42 +0000759 /* Preserve old status? */
760}
761
762/* Execute NSM event process. */
763int
764ospf_nsm_event (struct thread *thread)
765{
766 int event;
767 int next_state;
768 struct ospf_neighbor *nbr;
paul2d598362003-01-17 23:48:42 +0000769
770 nbr = THREAD_ARG (thread);
771 event = THREAD_VAL (thread);
paul2d598362003-01-17 23:48:42 +0000772
Paul Jakma3d63f382006-07-11 17:52:53 +0000773 if (IS_DEBUG_OSPF (nsm, NSM_EVENTS))
774 zlog_debug ("NSM[%s:%s]: %s (%s)", IF_NAME (nbr->oi),
775 inet_ntoa (nbr->router_id),
776 LOOKUP (ospf_nsm_state_msg, nbr->state),
777 ospf_nsm_event_str [event]);
778
Paul Jakma539e1522006-07-11 17:49:22 +0000779 next_state = NSM [nbr->state][event].next_state;
paul2d598362003-01-17 23:48:42 +0000780
Paul Jakma539e1522006-07-11 17:49:22 +0000781 /* Call function. */
782 if (NSM [nbr->state][event].func != NULL)
Paul Jakmaba0beb42006-07-04 13:44:19 +0000783 {
Paul Jakma539e1522006-07-11 17:49:22 +0000784 int func_state = (*(NSM [nbr->state][event].func))(nbr);
Paul Jakmaba0beb42006-07-04 13:44:19 +0000785
Paul Jakma539e1522006-07-11 17:49:22 +0000786 if (NSM [nbr->state][event].next_state == NSM_DependUpon)
787 next_state = func_state;
788 else if (func_state)
789 {
790 /* There's a mismatch between the FSM tables and what an FSM
791 * action/state-change function returned. State changes which
792 * do not have conditional/DependUpon next-states should not
793 * try set next_state.
794 */
795 zlog_warn ("NSM[%s:%s]: %s (%s): "
796 "Warning: action tried to change next_state to %s",
797 IF_NAME (nbr->oi), inet_ntoa (nbr->router_id),
798 LOOKUP (ospf_nsm_state_msg, nbr->state),
799 ospf_nsm_event_str [event],
800 LOOKUP (ospf_nsm_state_msg, func_state));
801 }
Paul Jakmaba0beb42006-07-04 13:44:19 +0000802 }
paul2d598362003-01-17 23:48:42 +0000803
Paul Jakma539e1522006-07-11 17:49:22 +0000804 assert (next_state != NSM_DependUpon);
805
paul2d598362003-01-17 23:48:42 +0000806 /* If state is changed. */
807 if (next_state != nbr->state)
Paul Jakma3d63f382006-07-11 17:52:53 +0000808 {
809 nsm_notice_state_change (nbr, next_state, event);
Fernando Sotob6404392015-05-11 20:52:00 +0000810#ifdef HAVE_SNMP
811 int send_trap_virt = 0;
812 int send_trap = 0;
813 /* Terminal state or regression */
814 if ((next_state == NSM_Full)
815 || (next_state == NSM_TwoWay)
816 || (next_state < nbr->state))
817 {
818 /* ospfVirtNbrStateChange */
819 if (nbr->oi->type == OSPF_IFTYPE_VIRTUALLINK)
820 send_trap_virt = 1;
821 /* ospfNbrStateChange trap */
822 else
823 /* To/From FULL, only managed by DR */
824 if (((next_state != NSM_Full) && (nbr->state != NSM_Full))
825 || (nbr->oi->state == ISM_DR))
826 send_trap = 1;
827 }
828#endif
Paul Jakma3d63f382006-07-11 17:52:53 +0000829 nsm_change_state (nbr, next_state);
Fernando Sotob6404392015-05-11 20:52:00 +0000830
831#ifdef HAVE_SNMP
832 if (send_trap_virt) {
833 ospfTrapVirtNbrStateChange(nbr);
834 } else if (send_trap) {
835 ospfTrapNbrStateChange(nbr);
836 }
837#endif
Paul Jakma3d63f382006-07-11 17:52:53 +0000838 }
paul2d598362003-01-17 23:48:42 +0000839
840 /* Make sure timer is set. */
841 nsm_timer_set (nbr);
842
Paul Jakma1f2c2742006-07-10 07:45:13 +0000843 /* When event is NSM_KillNbr, InactivityTimer or LLDown, the neighbor
844 * is deleted.
845 *
846 * Rather than encode knowledge here of which events lead to NBR
847 * delete, we take our cue from the NSM table, via the dummy
848 * 'Deleted' neighbour state.
849 */
850 if (nbr->state == NSM_Deleted)
851 ospf_nbr_delete (nbr);
852
paul2d598362003-01-17 23:48:42 +0000853 return 0;
854}
855
856/* Check loading state. */
857void
858ospf_check_nbr_loading (struct ospf_neighbor *nbr)
859{
860 if (nbr->state == NSM_Loading)
861 {
862 if (ospf_ls_request_isempty (nbr))
863 OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_LoadingDone);
864 else if (nbr->ls_req_last == NULL)
865 ospf_ls_req_event (nbr);
866 }
867}