xref: /linux/net/sctp/sm_statetable.c (revision 666ed8bfd1de3b091cf32ca03b651757dd86cfff)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* SCTP kernel implementation
3  * (C) Copyright IBM Corp. 2001, 2004
4  * Copyright (c) 1999-2000 Cisco, Inc.
5  * Copyright (c) 1999-2001 Motorola, Inc.
6  * Copyright (c) 2001 Intel Corp.
7  * Copyright (c) 2001 Nokia, Inc.
8  *
9  * This file is part of the SCTP kernel implementation
10  *
11  * These are the state tables for the SCTP state machine.
12  *
13  * Please send any bug reports or fixes you make to the
14  * email address(es):
15  *    lksctp developers <linux-sctp@vger.kernel.org>
16  *
17  * Written or modified by:
18  *    La Monte H.P. Yarroll <piggy@acm.org>
19  *    Karl Knutson          <karl@athena.chicago.il.us>
20  *    Jon Grimm             <jgrimm@us.ibm.com>
21  *    Hui Huang		    <hui.huang@nokia.com>
22  *    Daisy Chang	    <daisyc@us.ibm.com>
23  *    Ardelle Fan	    <ardelle.fan@intel.com>
24  *    Sridhar Samudrala	    <sri@us.ibm.com>
25  */
26 
27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 
29 #include <linux/skbuff.h>
30 #include <net/sctp/sctp.h>
31 #include <net/sctp/sm.h>
32 
33 static const struct sctp_sm_table_entry
34 primitive_event_table[SCTP_NUM_PRIMITIVE_TYPES][SCTP_STATE_NUM_STATES];
35 static const struct sctp_sm_table_entry
36 other_event_table[SCTP_NUM_OTHER_TYPES][SCTP_STATE_NUM_STATES];
37 static const struct sctp_sm_table_entry
38 timeout_event_table[SCTP_NUM_TIMEOUT_TYPES][SCTP_STATE_NUM_STATES];
39 
40 static const struct sctp_sm_table_entry *sctp_chunk_event_lookup(
41 						struct net *net,
42 						enum sctp_cid cid,
43 						enum sctp_state state);
44 
45 
46 static const struct sctp_sm_table_entry bug = {
47 	.fn = sctp_sf_bug,
48 	.name = "sctp_sf_bug"
49 };
50 
51 #define DO_LOOKUP(_max, _type, _table)					\
52 ({									\
53 	const struct sctp_sm_table_entry *rtn;				\
54 									\
55 	if ((event_subtype._type > (_max))) {				\
56 		pr_warn("table %p possible attack: event %d exceeds max %d\n", \
57 			_table, event_subtype._type, _max);		\
58 		rtn = &bug;						\
59 	} else								\
60 		rtn = &_table[event_subtype._type][(int)state];		\
61 									\
62 	rtn;								\
63 })
64 
65 const struct sctp_sm_table_entry *sctp_sm_lookup_event(
66 					struct net *net,
67 					enum sctp_event_type event_type,
68 					enum sctp_state state,
69 					union sctp_subtype event_subtype)
70 {
71 	switch (event_type) {
72 	case SCTP_EVENT_T_CHUNK:
73 		return sctp_chunk_event_lookup(net, event_subtype.chunk, state);
74 	case SCTP_EVENT_T_TIMEOUT:
75 		return DO_LOOKUP(SCTP_EVENT_TIMEOUT_MAX, timeout,
76 				 timeout_event_table);
77 	case SCTP_EVENT_T_OTHER:
78 		return DO_LOOKUP(SCTP_EVENT_OTHER_MAX, other,
79 				 other_event_table);
80 	case SCTP_EVENT_T_PRIMITIVE:
81 		return DO_LOOKUP(SCTP_EVENT_PRIMITIVE_MAX, primitive,
82 				 primitive_event_table);
83 	default:
84 		/* Yikes!  We got an illegal event type.  */
85 		return &bug;
86 	}
87 }
88 
89 #define TYPE_SCTP_FUNC(func) {.fn = func, .name = #func}
90 
91 #define TYPE_SCTP_DATA { \
92 	/* SCTP_STATE_CLOSED */ \
93 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
94 	/* SCTP_STATE_COOKIE_WAIT */ \
95 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
96 	/* SCTP_STATE_COOKIE_ECHOED */ \
97 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
98 	/* SCTP_STATE_ESTABLISHED */ \
99 	TYPE_SCTP_FUNC(sctp_sf_eat_data_6_2), \
100 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
101 	TYPE_SCTP_FUNC(sctp_sf_eat_data_6_2), \
102 	/* SCTP_STATE_SHUTDOWN_SENT */ \
103 	TYPE_SCTP_FUNC(sctp_sf_eat_data_fast_4_4), \
104 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
105 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
106 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
107 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
108 } /* TYPE_SCTP_DATA */
109 
110 #define TYPE_SCTP_INIT { \
111 	/* SCTP_STATE_CLOSED */ \
112 	TYPE_SCTP_FUNC(sctp_sf_do_5_1B_init), \
113 	/* SCTP_STATE_COOKIE_WAIT */ \
114 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_1_siminit), \
115 	/* SCTP_STATE_COOKIE_ECHOED */ \
116 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_1_siminit), \
117 	/* SCTP_STATE_ESTABLISHED */ \
118 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \
119 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
120 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \
121 	/* SCTP_STATE_SHUTDOWN_SENT */ \
122 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \
123 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
124 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \
125 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
126 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_reshutack), \
127 } /* TYPE_SCTP_INIT */
128 
129 #define TYPE_SCTP_INIT_ACK { \
130 	/* SCTP_STATE_CLOSED */ \
131 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_3_initack), \
132 	/* SCTP_STATE_COOKIE_WAIT */ \
133 	TYPE_SCTP_FUNC(sctp_sf_do_5_1C_ack), \
134 	/* SCTP_STATE_COOKIE_ECHOED */ \
135 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
136 	/* SCTP_STATE_ESTABLISHED */ \
137 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
138 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
139 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
140 	/* SCTP_STATE_SHUTDOWN_SENT */ \
141 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
142 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
143 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
144 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
145 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
146 } /* TYPE_SCTP_INIT_ACK */
147 
148 #define TYPE_SCTP_SACK { \
149 	/* SCTP_STATE_CLOSED */ \
150 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
151 	/* SCTP_STATE_COOKIE_WAIT */ \
152 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
153 	/* SCTP_STATE_COOKIE_ECHOED */ \
154 	TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \
155 	/* SCTP_STATE_ESTABLISHED */ \
156 	TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \
157 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
158 	TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \
159 	/* SCTP_STATE_SHUTDOWN_SENT */ \
160 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
161 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
162 	TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \
163 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
164 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
165 } /* TYPE_SCTP_SACK */
166 
167 #define TYPE_SCTP_HEARTBEAT { \
168 	/* SCTP_STATE_CLOSED */ \
169 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
170 	/* SCTP_STATE_COOKIE_WAIT */ \
171 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
172 	/* SCTP_STATE_COOKIE_ECHOED */ \
173 	TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
174 	/* SCTP_STATE_ESTABLISHED */ \
175 	TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
176 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
177 	TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
178 	/* SCTP_STATE_SHUTDOWN_SENT */ \
179 	TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
180 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
181 	TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
182 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
183 	/* This should not happen, but we are nice.  */ \
184 	TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
185 } /* TYPE_SCTP_HEARTBEAT */
186 
187 #define TYPE_SCTP_HEARTBEAT_ACK { \
188 	/* SCTP_STATE_CLOSED */ \
189 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
190 	/* SCTP_STATE_COOKIE_WAIT */ \
191 	TYPE_SCTP_FUNC(sctp_sf_violation), \
192 	/* SCTP_STATE_COOKIE_ECHOED */ \
193 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
194 	/* SCTP_STATE_ESTABLISHED */ \
195 	TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \
196 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
197 	TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \
198 	/* SCTP_STATE_SHUTDOWN_SENT */ \
199 	TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \
200 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
201 	TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \
202 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
203 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
204 } /* TYPE_SCTP_HEARTBEAT_ACK */
205 
206 #define TYPE_SCTP_ABORT { \
207 	/* SCTP_STATE_CLOSED */ \
208 	TYPE_SCTP_FUNC(sctp_sf_pdiscard), \
209 	/* SCTP_STATE_COOKIE_WAIT */ \
210 	TYPE_SCTP_FUNC(sctp_sf_cookie_wait_abort), \
211 	/* SCTP_STATE_COOKIE_ECHOED */ \
212 	TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_abort), \
213 	/* SCTP_STATE_ESTABLISHED */ \
214 	TYPE_SCTP_FUNC(sctp_sf_do_9_1_abort), \
215 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
216 	TYPE_SCTP_FUNC(sctp_sf_shutdown_pending_abort), \
217 	/* SCTP_STATE_SHUTDOWN_SENT */ \
218 	TYPE_SCTP_FUNC(sctp_sf_shutdown_sent_abort), \
219 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
220 	TYPE_SCTP_FUNC(sctp_sf_do_9_1_abort), \
221 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
222 	TYPE_SCTP_FUNC(sctp_sf_shutdown_ack_sent_abort), \
223 } /* TYPE_SCTP_ABORT */
224 
225 #define TYPE_SCTP_SHUTDOWN { \
226 	/* SCTP_STATE_CLOSED */ \
227 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
228 	/* SCTP_STATE_COOKIE_WAIT */ \
229 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
230 	/* SCTP_STATE_COOKIE_ECHOED */ \
231 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
232 	/* SCTP_STATE_ESTABLISHED */ \
233 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown), \
234 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
235 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown), \
236 	/* SCTP_STATE_SHUTDOWN_SENT */ \
237 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown_ack), \
238 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
239 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_shut_ctsn), \
240 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
241 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
242 } /* TYPE_SCTP_SHUTDOWN */
243 
244 #define TYPE_SCTP_SHUTDOWN_ACK { \
245 	/* SCTP_STATE_CLOSED */ \
246 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
247 	/* SCTP_STATE_COOKIE_WAIT */ \
248 	TYPE_SCTP_FUNC(sctp_sf_do_8_5_1_E_sa), \
249 	/* SCTP_STATE_COOKIE_ECHOED */ \
250 	TYPE_SCTP_FUNC(sctp_sf_do_8_5_1_E_sa), \
251 	/* SCTP_STATE_ESTABLISHED */ \
252 	TYPE_SCTP_FUNC(sctp_sf_violation), \
253 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
254 	TYPE_SCTP_FUNC(sctp_sf_violation), \
255 	/* SCTP_STATE_SHUTDOWN_SENT */ \
256 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_final), \
257 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
258 	TYPE_SCTP_FUNC(sctp_sf_violation), \
259 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
260 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_final), \
261 } /* TYPE_SCTP_SHUTDOWN_ACK */
262 
263 #define TYPE_SCTP_ERROR { \
264 	/* SCTP_STATE_CLOSED */ \
265 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
266 	/* SCTP_STATE_COOKIE_WAIT */ \
267 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
268 	/* SCTP_STATE_COOKIE_ECHOED */ \
269 	TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_err), \
270 	/* SCTP_STATE_ESTABLISHED */ \
271 	TYPE_SCTP_FUNC(sctp_sf_operr_notify), \
272 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
273 	TYPE_SCTP_FUNC(sctp_sf_operr_notify), \
274 	/* SCTP_STATE_SHUTDOWN_SENT */ \
275 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
276 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
277 	TYPE_SCTP_FUNC(sctp_sf_operr_notify), \
278 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
279 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
280 } /* TYPE_SCTP_ERROR */
281 
282 #define TYPE_SCTP_COOKIE_ECHO { \
283 	/* SCTP_STATE_CLOSED */ \
284 	TYPE_SCTP_FUNC(sctp_sf_do_5_1D_ce), \
285 	/* SCTP_STATE_COOKIE_WAIT */ \
286 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
287 	/* SCTP_STATE_COOKIE_ECHOED */ \
288 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
289 	/* SCTP_STATE_ESTABLISHED */ \
290 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
291 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
292 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
293 	/* SCTP_STATE_SHUTDOWN_SENT */ \
294 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
295 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
296 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
297 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
298 	TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
299 } /* TYPE_SCTP_COOKIE_ECHO */
300 
301 #define TYPE_SCTP_COOKIE_ACK { \
302 	/* SCTP_STATE_CLOSED */ \
303 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
304 	/* SCTP_STATE_COOKIE_WAIT */ \
305 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
306 	/* SCTP_STATE_COOKIE_ECHOED */ \
307 	TYPE_SCTP_FUNC(sctp_sf_do_5_1E_ca), \
308 	/* SCTP_STATE_ESTABLISHED */ \
309 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
310 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
311 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
312 	/* SCTP_STATE_SHUTDOWN_SENT */ \
313 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
314 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
315 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
316 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
317 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
318 } /* TYPE_SCTP_COOKIE_ACK */
319 
320 #define TYPE_SCTP_ECN_ECNE { \
321 	/* SCTP_STATE_CLOSED */ \
322 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
323 	/* SCTP_STATE_COOKIE_WAIT */ \
324 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
325 	/* SCTP_STATE_COOKIE_ECHOED */ \
326 	TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
327 	/* SCTP_STATE_ESTABLISHED */ \
328 	TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
329 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
330 	TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
331 	/* SCTP_STATE_SHUTDOWN_SENT */ \
332 	TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
333 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
334 	TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
335 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
336 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
337 } /* TYPE_SCTP_ECN_ECNE */
338 
339 #define TYPE_SCTP_ECN_CWR { \
340 	/* SCTP_STATE_CLOSED */ \
341 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
342 	/* SCTP_STATE_COOKIE_WAIT */ \
343 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
344 	/* SCTP_STATE_COOKIE_ECHOED */ \
345 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
346 	/* SCTP_STATE_ESTABLISHED */ \
347 	TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \
348 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
349 	TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \
350 	/* SCTP_STATE_SHUTDOWN_SENT */ \
351 	TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \
352 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
353 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
354 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
355 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
356 } /* TYPE_SCTP_ECN_CWR */
357 
358 #define TYPE_SCTP_SHUTDOWN_COMPLETE { \
359 	/* SCTP_STATE_CLOSED */ \
360 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
361 	/* SCTP_STATE_COOKIE_WAIT */ \
362 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
363 	/* SCTP_STATE_COOKIE_ECHOED */ \
364 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
365 	/* SCTP_STATE_ESTABLISHED */ \
366 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
367 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
368 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
369 	/* SCTP_STATE_SHUTDOWN_SENT */ \
370 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
371 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
372 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
373 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
374 	TYPE_SCTP_FUNC(sctp_sf_do_4_C), \
375 } /* TYPE_SCTP_SHUTDOWN_COMPLETE */
376 
377 /* The primary index for this table is the chunk type.
378  * The secondary index for this table is the state.
379  *
380  * For base protocol (RFC 2960).
381  */
382 static const struct sctp_sm_table_entry
383 chunk_event_table[SCTP_NUM_BASE_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
384 	TYPE_SCTP_DATA,
385 	TYPE_SCTP_INIT,
386 	TYPE_SCTP_INIT_ACK,
387 	TYPE_SCTP_SACK,
388 	TYPE_SCTP_HEARTBEAT,
389 	TYPE_SCTP_HEARTBEAT_ACK,
390 	TYPE_SCTP_ABORT,
391 	TYPE_SCTP_SHUTDOWN,
392 	TYPE_SCTP_SHUTDOWN_ACK,
393 	TYPE_SCTP_ERROR,
394 	TYPE_SCTP_COOKIE_ECHO,
395 	TYPE_SCTP_COOKIE_ACK,
396 	TYPE_SCTP_ECN_ECNE,
397 	TYPE_SCTP_ECN_CWR,
398 	TYPE_SCTP_SHUTDOWN_COMPLETE,
399 }; /* state_fn_t chunk_event_table[][] */
400 
401 #define TYPE_SCTP_ASCONF { \
402 	/* SCTP_STATE_CLOSED */ \
403 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
404 	/* SCTP_STATE_COOKIE_WAIT */ \
405 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
406 	/* SCTP_STATE_COOKIE_ECHOED */ \
407 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
408 	/* SCTP_STATE_ESTABLISHED */ \
409 	TYPE_SCTP_FUNC(sctp_sf_do_asconf), \
410 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
411 	TYPE_SCTP_FUNC(sctp_sf_do_asconf), \
412 	/* SCTP_STATE_SHUTDOWN_SENT */ \
413 	TYPE_SCTP_FUNC(sctp_sf_do_asconf), \
414 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
415 	TYPE_SCTP_FUNC(sctp_sf_do_asconf), \
416 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
417 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
418 } /* TYPE_SCTP_ASCONF */
419 
420 #define TYPE_SCTP_ASCONF_ACK { \
421 	/* SCTP_STATE_CLOSED */ \
422 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
423 	/* SCTP_STATE_COOKIE_WAIT */ \
424 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
425 	/* SCTP_STATE_COOKIE_ECHOED */ \
426 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
427 	/* SCTP_STATE_ESTABLISHED */ \
428 	TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \
429 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
430 	TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \
431 	/* SCTP_STATE_SHUTDOWN_SENT */ \
432 	TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \
433 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
434 	TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \
435 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
436 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
437 } /* TYPE_SCTP_ASCONF_ACK */
438 
439 /* The primary index for this table is the chunk type.
440  * The secondary index for this table is the state.
441  */
442 static const struct sctp_sm_table_entry
443 addip_chunk_event_table[SCTP_NUM_ADDIP_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
444 	TYPE_SCTP_ASCONF,
445 	TYPE_SCTP_ASCONF_ACK,
446 }; /*state_fn_t addip_chunk_event_table[][] */
447 
448 #define TYPE_SCTP_FWD_TSN { \
449 	/* SCTP_STATE_CLOSED */ \
450 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
451 	/* SCTP_STATE_COOKIE_WAIT */ \
452 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
453 	/* SCTP_STATE_COOKIE_ECHOED */ \
454 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
455 	/* SCTP_STATE_ESTABLISHED */ \
456 	TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn), \
457 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
458 	TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn), \
459 	/* SCTP_STATE_SHUTDOWN_SENT */ \
460 	TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn_fast), \
461 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
462 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
463 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
464 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
465 } /* TYPE_SCTP_FWD_TSN */
466 
467 /* The primary index for this table is the chunk type.
468  * The secondary index for this table is the state.
469  */
470 static const struct sctp_sm_table_entry
471 prsctp_chunk_event_table[SCTP_NUM_PRSCTP_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
472 	TYPE_SCTP_FWD_TSN,
473 }; /*state_fn_t prsctp_chunk_event_table[][] */
474 
475 #define TYPE_SCTP_RECONF { \
476 	/* SCTP_STATE_CLOSED */ \
477 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
478 	/* SCTP_STATE_COOKIE_WAIT */ \
479 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
480 	/* SCTP_STATE_COOKIE_ECHOED */ \
481 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
482 	/* SCTP_STATE_ESTABLISHED */ \
483 	TYPE_SCTP_FUNC(sctp_sf_do_reconf), \
484 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
485 	TYPE_SCTP_FUNC(sctp_sf_do_reconf), \
486 	/* SCTP_STATE_SHUTDOWN_SENT */ \
487 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
488 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
489 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
490 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
491 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
492 } /* TYPE_SCTP_RECONF */
493 
494 /* The primary index for this table is the chunk type.
495  * The secondary index for this table is the state.
496  */
497 static const struct sctp_sm_table_entry
498 reconf_chunk_event_table[SCTP_NUM_RECONF_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
499 	TYPE_SCTP_RECONF,
500 }; /*state_fn_t reconf_chunk_event_table[][] */
501 
502 #define TYPE_SCTP_AUTH { \
503 	/* SCTP_STATE_CLOSED */ \
504 	TYPE_SCTP_FUNC(sctp_sf_ootb), \
505 	/* SCTP_STATE_COOKIE_WAIT */ \
506 	TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
507 	/* SCTP_STATE_COOKIE_ECHOED */ \
508 	TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
509 	/* SCTP_STATE_ESTABLISHED */ \
510 	TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
511 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
512 	TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
513 	/* SCTP_STATE_SHUTDOWN_SENT */ \
514 	TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
515 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
516 	TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
517 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
518 	TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
519 } /* TYPE_SCTP_AUTH */
520 
521 /* The primary index for this table is the chunk type.
522  * The secondary index for this table is the state.
523  */
524 static const struct sctp_sm_table_entry
525 auth_chunk_event_table[SCTP_NUM_AUTH_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
526 	TYPE_SCTP_AUTH,
527 }; /*state_fn_t auth_chunk_event_table[][] */
528 
529 static const struct sctp_sm_table_entry
530 chunk_event_table_unknown[SCTP_STATE_NUM_STATES] = {
531 	/* SCTP_STATE_CLOSED */
532 	TYPE_SCTP_FUNC(sctp_sf_ootb),
533 	/* SCTP_STATE_COOKIE_WAIT */
534 	TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
535 	/* SCTP_STATE_COOKIE_ECHOED */
536 	TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
537 	/* SCTP_STATE_ESTABLISHED */
538 	TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
539 	/* SCTP_STATE_SHUTDOWN_PENDING */
540 	TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
541 	/* SCTP_STATE_SHUTDOWN_SENT */
542 	TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
543 	/* SCTP_STATE_SHUTDOWN_RECEIVED */
544 	TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
545 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */
546 	TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
547 };	/* chunk unknown */
548 
549 
550 #define TYPE_SCTP_PRIMITIVE_ASSOCIATE  { \
551 	/* SCTP_STATE_CLOSED */ \
552 	TYPE_SCTP_FUNC(sctp_sf_do_prm_asoc), \
553 	/* SCTP_STATE_COOKIE_WAIT */ \
554 	TYPE_SCTP_FUNC(sctp_sf_not_impl), \
555 	/* SCTP_STATE_COOKIE_ECHOED */ \
556 	TYPE_SCTP_FUNC(sctp_sf_not_impl), \
557 	/* SCTP_STATE_ESTABLISHED */ \
558 	TYPE_SCTP_FUNC(sctp_sf_not_impl), \
559 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
560 	TYPE_SCTP_FUNC(sctp_sf_not_impl), \
561 	/* SCTP_STATE_SHUTDOWN_SENT */ \
562 	TYPE_SCTP_FUNC(sctp_sf_not_impl), \
563 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
564 	TYPE_SCTP_FUNC(sctp_sf_not_impl), \
565 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
566 	TYPE_SCTP_FUNC(sctp_sf_not_impl), \
567 } /* TYPE_SCTP_PRIMITIVE_ASSOCIATE */
568 
569 #define TYPE_SCTP_PRIMITIVE_SHUTDOWN  { \
570 	/* SCTP_STATE_CLOSED */ \
571 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
572 	/* SCTP_STATE_COOKIE_WAIT */ \
573 	TYPE_SCTP_FUNC(sctp_sf_cookie_wait_prm_shutdown), \
574 	/* SCTP_STATE_COOKIE_ECHOED */ \
575 	TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_prm_shutdown),\
576 	/* SCTP_STATE_ESTABLISHED */ \
577 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_prm_shutdown), \
578 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
579 	TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \
580 	/* SCTP_STATE_SHUTDOWN_SENT */ \
581 	TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \
582 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
583 	TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \
584 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
585 	TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \
586 } /* TYPE_SCTP_PRIMITIVE_SHUTDOWN */
587 
588 #define TYPE_SCTP_PRIMITIVE_ABORT  { \
589 	/* SCTP_STATE_CLOSED */ \
590 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
591 	/* SCTP_STATE_COOKIE_WAIT */ \
592 	TYPE_SCTP_FUNC(sctp_sf_cookie_wait_prm_abort), \
593 	/* SCTP_STATE_COOKIE_ECHOED */ \
594 	TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_prm_abort), \
595 	/* SCTP_STATE_ESTABLISHED */ \
596 	TYPE_SCTP_FUNC(sctp_sf_do_9_1_prm_abort), \
597 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
598 	TYPE_SCTP_FUNC(sctp_sf_shutdown_pending_prm_abort), \
599 	/* SCTP_STATE_SHUTDOWN_SENT */ \
600 	TYPE_SCTP_FUNC(sctp_sf_shutdown_sent_prm_abort), \
601 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
602 	TYPE_SCTP_FUNC(sctp_sf_do_9_1_prm_abort), \
603 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
604 	TYPE_SCTP_FUNC(sctp_sf_shutdown_ack_sent_prm_abort), \
605 } /* TYPE_SCTP_PRIMITIVE_ABORT */
606 
607 #define TYPE_SCTP_PRIMITIVE_SEND  { \
608 	/* SCTP_STATE_CLOSED */ \
609 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
610 	/* SCTP_STATE_COOKIE_WAIT */ \
611 	TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \
612 	/* SCTP_STATE_COOKIE_ECHOED */ \
613 	TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \
614 	/* SCTP_STATE_ESTABLISHED */ \
615 	TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \
616 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
617 	TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
618 	/* SCTP_STATE_SHUTDOWN_SENT */ \
619 	TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
620 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
621 	TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
622 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
623 	TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
624 } /* TYPE_SCTP_PRIMITIVE_SEND */
625 
626 #define TYPE_SCTP_PRIMITIVE_REQUESTHEARTBEAT  { \
627 	/* SCTP_STATE_CLOSED */ \
628 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
629 	/* SCTP_STATE_COOKIE_WAIT */ \
630 	TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat),          \
631 	/* SCTP_STATE_COOKIE_ECHOED */ \
632 	TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat),          \
633 	/* SCTP_STATE_ESTABLISHED */ \
634 	TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat),          \
635 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
636 	TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat),          \
637 	/* SCTP_STATE_SHUTDOWN_SENT */ \
638 	TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat),          \
639 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
640 	TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat),          \
641 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
642 	TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat),          \
643 } /* TYPE_SCTP_PRIMITIVE_REQUESTHEARTBEAT */
644 
645 #define TYPE_SCTP_PRIMITIVE_ASCONF { \
646 	/* SCTP_STATE_CLOSED */ \
647 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
648 	/* SCTP_STATE_COOKIE_WAIT */ \
649 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
650 	/* SCTP_STATE_COOKIE_ECHOED */ \
651 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
652 	/* SCTP_STATE_ESTABLISHED */ \
653 	TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \
654 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
655 	TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \
656 	/* SCTP_STATE_SHUTDOWN_SENT */ \
657 	TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \
658 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
659 	TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \
660 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
661 	TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
662 } /* TYPE_SCTP_PRIMITIVE_ASCONF */
663 
664 #define TYPE_SCTP_PRIMITIVE_RECONF { \
665 	/* SCTP_STATE_CLOSED */ \
666 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
667 	/* SCTP_STATE_COOKIE_WAIT */ \
668 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
669 	/* SCTP_STATE_COOKIE_ECHOED */ \
670 	TYPE_SCTP_FUNC(sctp_sf_error_closed), \
671 	/* SCTP_STATE_ESTABLISHED */ \
672 	TYPE_SCTP_FUNC(sctp_sf_do_prm_reconf), \
673 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
674 	TYPE_SCTP_FUNC(sctp_sf_do_prm_reconf), \
675 	/* SCTP_STATE_SHUTDOWN_SENT */ \
676 	TYPE_SCTP_FUNC(sctp_sf_do_prm_reconf), \
677 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
678 	TYPE_SCTP_FUNC(sctp_sf_do_prm_reconf), \
679 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
680 	TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
681 } /* TYPE_SCTP_PRIMITIVE_RECONF */
682 
683 /* The primary index for this table is the primitive type.
684  * The secondary index for this table is the state.
685  */
686 static const struct sctp_sm_table_entry
687 primitive_event_table[SCTP_NUM_PRIMITIVE_TYPES][SCTP_STATE_NUM_STATES] = {
688 	TYPE_SCTP_PRIMITIVE_ASSOCIATE,
689 	TYPE_SCTP_PRIMITIVE_SHUTDOWN,
690 	TYPE_SCTP_PRIMITIVE_ABORT,
691 	TYPE_SCTP_PRIMITIVE_SEND,
692 	TYPE_SCTP_PRIMITIVE_REQUESTHEARTBEAT,
693 	TYPE_SCTP_PRIMITIVE_ASCONF,
694 	TYPE_SCTP_PRIMITIVE_RECONF,
695 };
696 
697 #define TYPE_SCTP_OTHER_NO_PENDING_TSN  { \
698 	/* SCTP_STATE_CLOSED */ \
699 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
700 	/* SCTP_STATE_COOKIE_WAIT */ \
701 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
702 	/* SCTP_STATE_COOKIE_ECHOED */ \
703 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
704 	/* SCTP_STATE_ESTABLISHED */ \
705 	TYPE_SCTP_FUNC(sctp_sf_do_no_pending_tsn), \
706 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
707 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_start_shutdown), \
708 	/* SCTP_STATE_SHUTDOWN_SENT */ \
709 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
710 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
711 	TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown_ack), \
712 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
713 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
714 }
715 
716 #define TYPE_SCTP_OTHER_ICMP_PROTO_UNREACH  { \
717 	/* SCTP_STATE_CLOSED */ \
718 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
719 	/* SCTP_STATE_COOKIE_WAIT */ \
720 	TYPE_SCTP_FUNC(sctp_sf_cookie_wait_icmp_abort), \
721 	/* SCTP_STATE_COOKIE_ECHOED */ \
722 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
723 	/* SCTP_STATE_ESTABLISHED */ \
724 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
725 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
726 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
727 	/* SCTP_STATE_SHUTDOWN_SENT */ \
728 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
729 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
730 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
731 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
732 	TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
733 }
734 
735 static const struct sctp_sm_table_entry
736 other_event_table[SCTP_NUM_OTHER_TYPES][SCTP_STATE_NUM_STATES] = {
737 	TYPE_SCTP_OTHER_NO_PENDING_TSN,
738 	TYPE_SCTP_OTHER_ICMP_PROTO_UNREACH,
739 };
740 
741 #define TYPE_SCTP_EVENT_TIMEOUT_NONE { \
742 	/* SCTP_STATE_CLOSED */ \
743 	TYPE_SCTP_FUNC(sctp_sf_bug), \
744 	/* SCTP_STATE_COOKIE_WAIT */ \
745 	TYPE_SCTP_FUNC(sctp_sf_bug), \
746 	/* SCTP_STATE_COOKIE_ECHOED */ \
747 	TYPE_SCTP_FUNC(sctp_sf_bug), \
748 	/* SCTP_STATE_ESTABLISHED */ \
749 	TYPE_SCTP_FUNC(sctp_sf_bug), \
750 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
751 	TYPE_SCTP_FUNC(sctp_sf_bug), \
752 	/* SCTP_STATE_SHUTDOWN_SENT */ \
753 	TYPE_SCTP_FUNC(sctp_sf_bug), \
754 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
755 	TYPE_SCTP_FUNC(sctp_sf_bug), \
756 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
757 	TYPE_SCTP_FUNC(sctp_sf_bug), \
758 }
759 
760 #define TYPE_SCTP_EVENT_TIMEOUT_T1_COOKIE { \
761 	/* SCTP_STATE_CLOSED */ \
762 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
763 	/* SCTP_STATE_COOKIE_WAIT */ \
764 	TYPE_SCTP_FUNC(sctp_sf_bug), \
765 	/* SCTP_STATE_COOKIE_ECHOED */ \
766 	TYPE_SCTP_FUNC(sctp_sf_t1_cookie_timer_expire), \
767 	/* SCTP_STATE_ESTABLISHED */ \
768 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
769 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
770 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
771 	/* SCTP_STATE_SHUTDOWN_SENT */ \
772 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
773 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
774 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
775 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
776 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
777 }
778 
779 #define TYPE_SCTP_EVENT_TIMEOUT_T1_INIT { \
780 	/* SCTP_STATE_CLOSED */ \
781 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
782 	/* SCTP_STATE_COOKIE_WAIT */ \
783 	TYPE_SCTP_FUNC(sctp_sf_t1_init_timer_expire), \
784 	/* SCTP_STATE_COOKIE_ECHOED */ \
785 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
786 	/* SCTP_STATE_ESTABLISHED */ \
787 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
788 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
789 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
790 	/* SCTP_STATE_SHUTDOWN_SENT */ \
791 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
792 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
793 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
794 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
795 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
796 }
797 
798 #define TYPE_SCTP_EVENT_TIMEOUT_T2_SHUTDOWN { \
799 	/* SCTP_STATE_CLOSED */ \
800 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
801 	/* SCTP_STATE_COOKIE_WAIT */ \
802 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
803 	/* SCTP_STATE_COOKIE_ECHOED */ \
804 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
805 	/* SCTP_STATE_ESTABLISHED */ \
806 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
807 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
808 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
809 	/* SCTP_STATE_SHUTDOWN_SENT */ \
810 	TYPE_SCTP_FUNC(sctp_sf_t2_timer_expire), \
811 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
812 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
813 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
814 	TYPE_SCTP_FUNC(sctp_sf_t2_timer_expire), \
815 }
816 
817 #define TYPE_SCTP_EVENT_TIMEOUT_T3_RTX { \
818 	/* SCTP_STATE_CLOSED */ \
819 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
820 	/* SCTP_STATE_COOKIE_WAIT */ \
821 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
822 	/* SCTP_STATE_COOKIE_ECHOED */ \
823 	TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \
824 	/* SCTP_STATE_ESTABLISHED */ \
825 	TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \
826 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
827 	TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \
828 	/* SCTP_STATE_SHUTDOWN_SENT */ \
829 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
830 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
831 	TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \
832 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
833 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
834 }
835 
836 #define TYPE_SCTP_EVENT_TIMEOUT_T4_RTO { \
837 	/* SCTP_STATE_CLOSED */ \
838 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
839 	/* SCTP_STATE_COOKIE_WAIT */ \
840 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
841 	/* SCTP_STATE_COOKIE_ECHOED */ \
842 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
843 	/* SCTP_STATE_ESTABLISHED */ \
844 	TYPE_SCTP_FUNC(sctp_sf_t4_timer_expire), \
845 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
846 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
847 	/* SCTP_STATE_SHUTDOWN_SENT */ \
848 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
849 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
850 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
851 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
852 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
853 }
854 
855 #define TYPE_SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD { \
856 	/* SCTP_STATE_CLOSED */ \
857 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
858 	/* SCTP_STATE_COOKIE_WAIT */ \
859 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
860 	/* SCTP_STATE_COOKIE_ECHOED */ \
861 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
862 	/* SCTP_STATE_ESTABLISHED */ \
863 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
864 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
865 	TYPE_SCTP_FUNC(sctp_sf_t5_timer_expire), \
866 	/* SCTP_STATE_SHUTDOWN_SENT */ \
867 	TYPE_SCTP_FUNC(sctp_sf_t5_timer_expire), \
868 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
869 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
870 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
871 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
872 }
873 
874 #define TYPE_SCTP_EVENT_TIMEOUT_HEARTBEAT { \
875 	/* SCTP_STATE_CLOSED */ \
876 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
877 	/* SCTP_STATE_COOKIE_WAIT */ \
878 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
879 	/* SCTP_STATE_COOKIE_ECHOED */ \
880 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
881 	/* SCTP_STATE_ESTABLISHED */ \
882 	TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \
883 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
884 	TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \
885 	/* SCTP_STATE_SHUTDOWN_SENT */ \
886 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
887 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
888 	TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \
889 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
890 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
891 }
892 
893 #define TYPE_SCTP_EVENT_TIMEOUT_SACK { \
894 	/* SCTP_STATE_CLOSED */ \
895 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
896 	/* SCTP_STATE_COOKIE_WAIT */ \
897 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
898 	/* SCTP_STATE_COOKIE_ECHOED */ \
899 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
900 	/* SCTP_STATE_ESTABLISHED */ \
901 	TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \
902 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
903 	TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \
904 	/* SCTP_STATE_SHUTDOWN_SENT */ \
905 	TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \
906 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
907 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
908 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
909 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
910 }
911 
912 #define TYPE_SCTP_EVENT_TIMEOUT_AUTOCLOSE { \
913 	/* SCTP_STATE_CLOSED */ \
914 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
915 	/* SCTP_STATE_COOKIE_WAIT */ \
916 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
917 	/* SCTP_STATE_COOKIE_ECHOED */ \
918 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
919 	/* SCTP_STATE_ESTABLISHED */ \
920 	TYPE_SCTP_FUNC(sctp_sf_autoclose_timer_expire), \
921 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
922 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
923 	/* SCTP_STATE_SHUTDOWN_SENT */ \
924 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
925 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
926 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
927 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
928 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
929 }
930 
931 #define TYPE_SCTP_EVENT_TIMEOUT_RECONF { \
932 	/* SCTP_STATE_CLOSED */ \
933 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
934 	/* SCTP_STATE_COOKIE_WAIT */ \
935 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
936 	/* SCTP_STATE_COOKIE_ECHOED */ \
937 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
938 	/* SCTP_STATE_ESTABLISHED */ \
939 	TYPE_SCTP_FUNC(sctp_sf_send_reconf), \
940 	/* SCTP_STATE_SHUTDOWN_PENDING */ \
941 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
942 	/* SCTP_STATE_SHUTDOWN_SENT */ \
943 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
944 	/* SCTP_STATE_SHUTDOWN_RECEIVED */ \
945 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
946 	/* SCTP_STATE_SHUTDOWN_ACK_SENT */ \
947 	TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
948 }
949 
950 static const struct sctp_sm_table_entry
951 timeout_event_table[SCTP_NUM_TIMEOUT_TYPES][SCTP_STATE_NUM_STATES] = {
952 	TYPE_SCTP_EVENT_TIMEOUT_NONE,
953 	TYPE_SCTP_EVENT_TIMEOUT_T1_COOKIE,
954 	TYPE_SCTP_EVENT_TIMEOUT_T1_INIT,
955 	TYPE_SCTP_EVENT_TIMEOUT_T2_SHUTDOWN,
956 	TYPE_SCTP_EVENT_TIMEOUT_T3_RTX,
957 	TYPE_SCTP_EVENT_TIMEOUT_T4_RTO,
958 	TYPE_SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD,
959 	TYPE_SCTP_EVENT_TIMEOUT_HEARTBEAT,
960 	TYPE_SCTP_EVENT_TIMEOUT_RECONF,
961 	TYPE_SCTP_EVENT_TIMEOUT_SACK,
962 	TYPE_SCTP_EVENT_TIMEOUT_AUTOCLOSE,
963 };
964 
965 static const struct sctp_sm_table_entry *sctp_chunk_event_lookup(
966 						struct net *net,
967 						enum sctp_cid cid,
968 						enum sctp_state state)
969 {
970 	if (state > SCTP_STATE_MAX)
971 		return &bug;
972 
973 	if (cid == SCTP_CID_I_DATA)
974 		cid = SCTP_CID_DATA;
975 
976 	if (cid <= SCTP_CID_BASE_MAX)
977 		return &chunk_event_table[cid][state];
978 
979 	switch ((u16)cid) {
980 	case SCTP_CID_FWD_TSN:
981 	case SCTP_CID_I_FWD_TSN:
982 		return &prsctp_chunk_event_table[0][state];
983 
984 	case SCTP_CID_ASCONF:
985 		return &addip_chunk_event_table[0][state];
986 
987 	case SCTP_CID_ASCONF_ACK:
988 		return &addip_chunk_event_table[1][state];
989 
990 	case SCTP_CID_RECONF:
991 		return &reconf_chunk_event_table[0][state];
992 
993 	case SCTP_CID_AUTH:
994 		return &auth_chunk_event_table[0][state];
995 	}
996 
997 	return &chunk_event_table_unknown[state];
998 }
999