1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
33static const struct sctp_sm_table_entry
34primitive_event_table[SCTP_NUM_PRIMITIVE_TYPES][SCTP_STATE_NUM_STATES];
35static const struct sctp_sm_table_entry
36other_event_table[SCTP_NUM_OTHER_TYPES][SCTP_STATE_NUM_STATES];
37static const struct sctp_sm_table_entry
38timeout_event_table[SCTP_NUM_TIMEOUT_TYPES][SCTP_STATE_NUM_STATES];
39
40static 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
46static 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
65const 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
85 return &bug;
86 }
87}
88
89#define TYPE_SCTP_FUNC(func) {.fn = func, .name = #func}
90
91#define TYPE_SCTP_DATA { \
92 \
93 TYPE_SCTP_FUNC(sctp_sf_ootb), \
94 \
95 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
96 \
97 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
98 \
99 TYPE_SCTP_FUNC(sctp_sf_eat_data_6_2), \
100 \
101 TYPE_SCTP_FUNC(sctp_sf_eat_data_6_2), \
102 \
103 TYPE_SCTP_FUNC(sctp_sf_eat_data_fast_4_4), \
104 \
105 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
106 \
107 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
108}
109
110#define TYPE_SCTP_INIT { \
111 \
112 TYPE_SCTP_FUNC(sctp_sf_do_5_1B_init), \
113 \
114 TYPE_SCTP_FUNC(sctp_sf_do_5_2_1_siminit), \
115 \
116 TYPE_SCTP_FUNC(sctp_sf_do_5_2_1_siminit), \
117 \
118 TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \
119 \
120 TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \
121 \
122 TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \
123 \
124 TYPE_SCTP_FUNC(sctp_sf_do_5_2_2_dupinit), \
125 \
126 TYPE_SCTP_FUNC(sctp_sf_do_9_2_reshutack), \
127}
128
129#define TYPE_SCTP_INIT_ACK { \
130 \
131 TYPE_SCTP_FUNC(sctp_sf_do_5_2_3_initack), \
132 \
133 TYPE_SCTP_FUNC(sctp_sf_do_5_1C_ack), \
134 \
135 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
136 \
137 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
138 \
139 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
140 \
141 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
142 \
143 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
144 \
145 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
146}
147
148#define TYPE_SCTP_SACK { \
149 \
150 TYPE_SCTP_FUNC(sctp_sf_ootb), \
151 \
152 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
153 \
154 TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \
155 \
156 TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \
157 \
158 TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \
159 \
160 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
161 \
162 TYPE_SCTP_FUNC(sctp_sf_eat_sack_6_2), \
163 \
164 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
165}
166
167#define TYPE_SCTP_HEARTBEAT { \
168 \
169 TYPE_SCTP_FUNC(sctp_sf_ootb), \
170 \
171 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
172 \
173 TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
174 \
175 TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
176 \
177 TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
178 \
179 TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
180 \
181 TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
182 \
183 \
184 TYPE_SCTP_FUNC(sctp_sf_beat_8_3), \
185}
186
187#define TYPE_SCTP_HEARTBEAT_ACK { \
188 \
189 TYPE_SCTP_FUNC(sctp_sf_ootb), \
190 \
191 TYPE_SCTP_FUNC(sctp_sf_violation), \
192 \
193 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
194 \
195 TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \
196 \
197 TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \
198 \
199 TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \
200 \
201 TYPE_SCTP_FUNC(sctp_sf_backbeat_8_3), \
202 \
203 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
204}
205
206#define TYPE_SCTP_ABORT { \
207 \
208 TYPE_SCTP_FUNC(sctp_sf_pdiscard), \
209 \
210 TYPE_SCTP_FUNC(sctp_sf_cookie_wait_abort), \
211 \
212 TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_abort), \
213 \
214 TYPE_SCTP_FUNC(sctp_sf_do_9_1_abort), \
215 \
216 TYPE_SCTP_FUNC(sctp_sf_shutdown_pending_abort), \
217 \
218 TYPE_SCTP_FUNC(sctp_sf_shutdown_sent_abort), \
219 \
220 TYPE_SCTP_FUNC(sctp_sf_do_9_1_abort), \
221 \
222 TYPE_SCTP_FUNC(sctp_sf_shutdown_ack_sent_abort), \
223}
224
225#define TYPE_SCTP_SHUTDOWN { \
226 \
227 TYPE_SCTP_FUNC(sctp_sf_ootb), \
228 \
229 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
230 \
231 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
232 \
233 TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown), \
234 \
235 TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown), \
236 \
237 TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown_ack), \
238 \
239 TYPE_SCTP_FUNC(sctp_sf_do_9_2_shut_ctsn), \
240 \
241 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
242}
243
244#define TYPE_SCTP_SHUTDOWN_ACK { \
245 \
246 TYPE_SCTP_FUNC(sctp_sf_ootb), \
247 \
248 TYPE_SCTP_FUNC(sctp_sf_do_8_5_1_E_sa), \
249 \
250 TYPE_SCTP_FUNC(sctp_sf_do_8_5_1_E_sa), \
251 \
252 TYPE_SCTP_FUNC(sctp_sf_violation), \
253 \
254 TYPE_SCTP_FUNC(sctp_sf_violation), \
255 \
256 TYPE_SCTP_FUNC(sctp_sf_do_9_2_final), \
257 \
258 TYPE_SCTP_FUNC(sctp_sf_violation), \
259 \
260 TYPE_SCTP_FUNC(sctp_sf_do_9_2_final), \
261}
262
263#define TYPE_SCTP_ERROR { \
264 \
265 TYPE_SCTP_FUNC(sctp_sf_ootb), \
266 \
267 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
268 \
269 TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_err), \
270 \
271 TYPE_SCTP_FUNC(sctp_sf_operr_notify), \
272 \
273 TYPE_SCTP_FUNC(sctp_sf_operr_notify), \
274 \
275 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
276 \
277 TYPE_SCTP_FUNC(sctp_sf_operr_notify), \
278 \
279 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
280}
281
282#define TYPE_SCTP_COOKIE_ECHO { \
283 \
284 TYPE_SCTP_FUNC(sctp_sf_do_5_1D_ce), \
285 \
286 TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
287 \
288 TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
289 \
290 TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
291 \
292 TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
293 \
294 TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
295 \
296 TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
297 \
298 TYPE_SCTP_FUNC(sctp_sf_do_5_2_4_dupcook), \
299}
300
301#define TYPE_SCTP_COOKIE_ACK { \
302 \
303 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
304 \
305 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
306 \
307 TYPE_SCTP_FUNC(sctp_sf_do_5_1E_ca), \
308 \
309 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
310 \
311 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
312 \
313 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
314 \
315 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
316 \
317 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
318}
319
320#define TYPE_SCTP_ECN_ECNE { \
321 \
322 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
323 \
324 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
325 \
326 TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
327 \
328 TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
329 \
330 TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
331 \
332 TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
333 \
334 TYPE_SCTP_FUNC(sctp_sf_do_ecne), \
335 \
336 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
337}
338
339#define TYPE_SCTP_ECN_CWR { \
340 \
341 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
342 \
343 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
344 \
345 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
346 \
347 TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \
348 \
349 TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \
350 \
351 TYPE_SCTP_FUNC(sctp_sf_do_ecn_cwr), \
352 \
353 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
354 \
355 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
356}
357
358#define TYPE_SCTP_SHUTDOWN_COMPLETE { \
359 \
360 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
361 \
362 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
363 \
364 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
365 \
366 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
367 \
368 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
369 \
370 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
371 \
372 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
373 \
374 TYPE_SCTP_FUNC(sctp_sf_do_4_C), \
375}
376
377
378
379
380
381
382static const struct sctp_sm_table_entry
383chunk_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};
400
401#define TYPE_SCTP_ASCONF { \
402 \
403 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
404 \
405 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
406 \
407 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
408 \
409 TYPE_SCTP_FUNC(sctp_sf_do_asconf), \
410 \
411 TYPE_SCTP_FUNC(sctp_sf_do_asconf), \
412 \
413 TYPE_SCTP_FUNC(sctp_sf_do_asconf), \
414 \
415 TYPE_SCTP_FUNC(sctp_sf_do_asconf), \
416 \
417 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
418}
419
420#define TYPE_SCTP_ASCONF_ACK { \
421 \
422 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
423 \
424 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
425 \
426 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
427 \
428 TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \
429 \
430 TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \
431 \
432 TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \
433 \
434 TYPE_SCTP_FUNC(sctp_sf_do_asconf_ack), \
435 \
436 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
437}
438
439
440
441
442static const struct sctp_sm_table_entry
443addip_chunk_event_table[SCTP_NUM_ADDIP_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
444 TYPE_SCTP_ASCONF,
445 TYPE_SCTP_ASCONF_ACK,
446};
447
448#define TYPE_SCTP_FWD_TSN { \
449 \
450 TYPE_SCTP_FUNC(sctp_sf_ootb), \
451 \
452 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
453 \
454 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
455 \
456 TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn), \
457 \
458 TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn), \
459 \
460 TYPE_SCTP_FUNC(sctp_sf_eat_fwd_tsn_fast), \
461 \
462 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
463 \
464 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
465}
466
467
468
469
470static const struct sctp_sm_table_entry
471prsctp_chunk_event_table[SCTP_NUM_PRSCTP_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
472 TYPE_SCTP_FWD_TSN,
473};
474
475#define TYPE_SCTP_RECONF { \
476 \
477 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
478 \
479 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
480 \
481 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
482 \
483 TYPE_SCTP_FUNC(sctp_sf_do_reconf), \
484 \
485 TYPE_SCTP_FUNC(sctp_sf_do_reconf), \
486 \
487 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
488 \
489 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
490 \
491 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
492}
493
494
495
496
497static const struct sctp_sm_table_entry
498reconf_chunk_event_table[SCTP_NUM_RECONF_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
499 TYPE_SCTP_RECONF,
500};
501
502#define TYPE_SCTP_AUTH { \
503 \
504 TYPE_SCTP_FUNC(sctp_sf_ootb), \
505 \
506 TYPE_SCTP_FUNC(sctp_sf_discard_chunk), \
507 \
508 TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
509 \
510 TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
511 \
512 TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
513 \
514 TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
515 \
516 TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
517 \
518 TYPE_SCTP_FUNC(sctp_sf_eat_auth), \
519}
520
521
522
523
524static const struct sctp_sm_table_entry
525auth_chunk_event_table[SCTP_NUM_AUTH_CHUNK_TYPES][SCTP_STATE_NUM_STATES] = {
526 TYPE_SCTP_AUTH,
527};
528
529static const struct sctp_sm_table_entry
530pad_chunk_event_table[SCTP_STATE_NUM_STATES] = {
531
532 TYPE_SCTP_FUNC(sctp_sf_discard_chunk),
533
534 TYPE_SCTP_FUNC(sctp_sf_discard_chunk),
535
536 TYPE_SCTP_FUNC(sctp_sf_discard_chunk),
537
538 TYPE_SCTP_FUNC(sctp_sf_discard_chunk),
539
540 TYPE_SCTP_FUNC(sctp_sf_discard_chunk),
541
542 TYPE_SCTP_FUNC(sctp_sf_discard_chunk),
543
544 TYPE_SCTP_FUNC(sctp_sf_discard_chunk),
545
546 TYPE_SCTP_FUNC(sctp_sf_discard_chunk),
547};
548
549static const struct sctp_sm_table_entry
550chunk_event_table_unknown[SCTP_STATE_NUM_STATES] = {
551
552 TYPE_SCTP_FUNC(sctp_sf_ootb),
553
554 TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
555
556 TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
557
558 TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
559
560 TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
561
562 TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
563
564 TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
565
566 TYPE_SCTP_FUNC(sctp_sf_unk_chunk),
567};
568
569
570#define TYPE_SCTP_PRIMITIVE_ASSOCIATE { \
571 \
572 TYPE_SCTP_FUNC(sctp_sf_do_prm_asoc), \
573 \
574 TYPE_SCTP_FUNC(sctp_sf_not_impl), \
575 \
576 TYPE_SCTP_FUNC(sctp_sf_not_impl), \
577 \
578 TYPE_SCTP_FUNC(sctp_sf_not_impl), \
579 \
580 TYPE_SCTP_FUNC(sctp_sf_not_impl), \
581 \
582 TYPE_SCTP_FUNC(sctp_sf_not_impl), \
583 \
584 TYPE_SCTP_FUNC(sctp_sf_not_impl), \
585 \
586 TYPE_SCTP_FUNC(sctp_sf_not_impl), \
587}
588
589#define TYPE_SCTP_PRIMITIVE_SHUTDOWN { \
590 \
591 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
592 \
593 TYPE_SCTP_FUNC(sctp_sf_cookie_wait_prm_shutdown), \
594 \
595 TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_prm_shutdown),\
596 \
597 TYPE_SCTP_FUNC(sctp_sf_do_9_2_prm_shutdown), \
598 \
599 TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \
600 \
601 TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \
602 \
603 TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \
604 \
605 TYPE_SCTP_FUNC(sctp_sf_ignore_primitive), \
606}
607
608#define TYPE_SCTP_PRIMITIVE_ABORT { \
609 \
610 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
611 \
612 TYPE_SCTP_FUNC(sctp_sf_cookie_wait_prm_abort), \
613 \
614 TYPE_SCTP_FUNC(sctp_sf_cookie_echoed_prm_abort), \
615 \
616 TYPE_SCTP_FUNC(sctp_sf_do_9_1_prm_abort), \
617 \
618 TYPE_SCTP_FUNC(sctp_sf_shutdown_pending_prm_abort), \
619 \
620 TYPE_SCTP_FUNC(sctp_sf_shutdown_sent_prm_abort), \
621 \
622 TYPE_SCTP_FUNC(sctp_sf_do_9_1_prm_abort), \
623 \
624 TYPE_SCTP_FUNC(sctp_sf_shutdown_ack_sent_prm_abort), \
625}
626
627#define TYPE_SCTP_PRIMITIVE_SEND { \
628 \
629 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
630 \
631 TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \
632 \
633 TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \
634 \
635 TYPE_SCTP_FUNC(sctp_sf_do_prm_send), \
636 \
637 TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
638 \
639 TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
640 \
641 TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
642 \
643 TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
644}
645
646#define TYPE_SCTP_PRIMITIVE_REQUESTHEARTBEAT { \
647 \
648 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
649 \
650 TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \
651 \
652 TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \
653 \
654 TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \
655 \
656 TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \
657 \
658 TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \
659 \
660 TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \
661 \
662 TYPE_SCTP_FUNC(sctp_sf_do_prm_requestheartbeat), \
663}
664
665#define TYPE_SCTP_PRIMITIVE_ASCONF { \
666 \
667 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
668 \
669 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
670 \
671 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
672 \
673 TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \
674 \
675 TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \
676 \
677 TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \
678 \
679 TYPE_SCTP_FUNC(sctp_sf_do_prm_asconf), \
680 \
681 TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
682}
683
684#define TYPE_SCTP_PRIMITIVE_RECONF { \
685 \
686 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
687 \
688 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
689 \
690 TYPE_SCTP_FUNC(sctp_sf_error_closed), \
691 \
692 TYPE_SCTP_FUNC(sctp_sf_do_prm_reconf), \
693 \
694 TYPE_SCTP_FUNC(sctp_sf_do_prm_reconf), \
695 \
696 TYPE_SCTP_FUNC(sctp_sf_do_prm_reconf), \
697 \
698 TYPE_SCTP_FUNC(sctp_sf_do_prm_reconf), \
699 \
700 TYPE_SCTP_FUNC(sctp_sf_error_shutdown), \
701}
702
703
704
705
706static const struct sctp_sm_table_entry
707primitive_event_table[SCTP_NUM_PRIMITIVE_TYPES][SCTP_STATE_NUM_STATES] = {
708 TYPE_SCTP_PRIMITIVE_ASSOCIATE,
709 TYPE_SCTP_PRIMITIVE_SHUTDOWN,
710 TYPE_SCTP_PRIMITIVE_ABORT,
711 TYPE_SCTP_PRIMITIVE_SEND,
712 TYPE_SCTP_PRIMITIVE_REQUESTHEARTBEAT,
713 TYPE_SCTP_PRIMITIVE_ASCONF,
714 TYPE_SCTP_PRIMITIVE_RECONF,
715};
716
717#define TYPE_SCTP_OTHER_NO_PENDING_TSN { \
718 \
719 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
720 \
721 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
722 \
723 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
724 \
725 TYPE_SCTP_FUNC(sctp_sf_do_no_pending_tsn), \
726 \
727 TYPE_SCTP_FUNC(sctp_sf_do_9_2_start_shutdown), \
728 \
729 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
730 \
731 TYPE_SCTP_FUNC(sctp_sf_do_9_2_shutdown_ack), \
732 \
733 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
734}
735
736#define TYPE_SCTP_OTHER_ICMP_PROTO_UNREACH { \
737 \
738 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
739 \
740 TYPE_SCTP_FUNC(sctp_sf_cookie_wait_icmp_abort), \
741 \
742 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
743 \
744 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
745 \
746 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
747 \
748 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
749 \
750 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
751 \
752 TYPE_SCTP_FUNC(sctp_sf_ignore_other), \
753}
754
755static const struct sctp_sm_table_entry
756other_event_table[SCTP_NUM_OTHER_TYPES][SCTP_STATE_NUM_STATES] = {
757 TYPE_SCTP_OTHER_NO_PENDING_TSN,
758 TYPE_SCTP_OTHER_ICMP_PROTO_UNREACH,
759};
760
761#define TYPE_SCTP_EVENT_TIMEOUT_NONE { \
762 \
763 TYPE_SCTP_FUNC(sctp_sf_bug), \
764 \
765 TYPE_SCTP_FUNC(sctp_sf_bug), \
766 \
767 TYPE_SCTP_FUNC(sctp_sf_bug), \
768 \
769 TYPE_SCTP_FUNC(sctp_sf_bug), \
770 \
771 TYPE_SCTP_FUNC(sctp_sf_bug), \
772 \
773 TYPE_SCTP_FUNC(sctp_sf_bug), \
774 \
775 TYPE_SCTP_FUNC(sctp_sf_bug), \
776 \
777 TYPE_SCTP_FUNC(sctp_sf_bug), \
778}
779
780#define TYPE_SCTP_EVENT_TIMEOUT_T1_COOKIE { \
781 \
782 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
783 \
784 TYPE_SCTP_FUNC(sctp_sf_bug), \
785 \
786 TYPE_SCTP_FUNC(sctp_sf_t1_cookie_timer_expire), \
787 \
788 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
789 \
790 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
791 \
792 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
793 \
794 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
795 \
796 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
797}
798
799#define TYPE_SCTP_EVENT_TIMEOUT_T1_INIT { \
800 \
801 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
802 \
803 TYPE_SCTP_FUNC(sctp_sf_t1_init_timer_expire), \
804 \
805 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
806 \
807 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
808 \
809 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
810 \
811 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
812 \
813 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
814 \
815 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
816}
817
818#define TYPE_SCTP_EVENT_TIMEOUT_T2_SHUTDOWN { \
819 \
820 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
821 \
822 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
823 \
824 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
825 \
826 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
827 \
828 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
829 \
830 TYPE_SCTP_FUNC(sctp_sf_t2_timer_expire), \
831 \
832 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
833 \
834 TYPE_SCTP_FUNC(sctp_sf_t2_timer_expire), \
835}
836
837#define TYPE_SCTP_EVENT_TIMEOUT_T3_RTX { \
838 \
839 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
840 \
841 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
842 \
843 TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \
844 \
845 TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \
846 \
847 TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \
848 \
849 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
850 \
851 TYPE_SCTP_FUNC(sctp_sf_do_6_3_3_rtx), \
852 \
853 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
854}
855
856#define TYPE_SCTP_EVENT_TIMEOUT_T4_RTO { \
857 \
858 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
859 \
860 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
861 \
862 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
863 \
864 TYPE_SCTP_FUNC(sctp_sf_t4_timer_expire), \
865 \
866 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
867 \
868 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
869 \
870 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
871 \
872 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
873}
874
875#define TYPE_SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD { \
876 \
877 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
878 \
879 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
880 \
881 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
882 \
883 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
884 \
885 TYPE_SCTP_FUNC(sctp_sf_t5_timer_expire), \
886 \
887 TYPE_SCTP_FUNC(sctp_sf_t5_timer_expire), \
888 \
889 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
890 \
891 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
892}
893
894#define TYPE_SCTP_EVENT_TIMEOUT_HEARTBEAT { \
895 \
896 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
897 \
898 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
899 \
900 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
901 \
902 TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \
903 \
904 TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \
905 \
906 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
907 \
908 TYPE_SCTP_FUNC(sctp_sf_sendbeat_8_3), \
909 \
910 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
911}
912
913#define TYPE_SCTP_EVENT_TIMEOUT_SACK { \
914 \
915 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
916 \
917 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
918 \
919 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
920 \
921 TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \
922 \
923 TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \
924 \
925 TYPE_SCTP_FUNC(sctp_sf_do_6_2_sack), \
926 \
927 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
928 \
929 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
930}
931
932#define TYPE_SCTP_EVENT_TIMEOUT_AUTOCLOSE { \
933 \
934 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
935 \
936 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
937 \
938 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
939 \
940 TYPE_SCTP_FUNC(sctp_sf_autoclose_timer_expire), \
941 \
942 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
943 \
944 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
945 \
946 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
947 \
948 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
949}
950
951#define TYPE_SCTP_EVENT_TIMEOUT_RECONF { \
952 \
953 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
954 \
955 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
956 \
957 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
958 \
959 TYPE_SCTP_FUNC(sctp_sf_send_reconf), \
960 \
961 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
962 \
963 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
964 \
965 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
966 \
967 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
968}
969
970#define TYPE_SCTP_EVENT_TIMEOUT_PROBE { \
971 \
972 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
973 \
974 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
975 \
976 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
977 \
978 TYPE_SCTP_FUNC(sctp_sf_send_probe), \
979 \
980 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
981 \
982 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
983 \
984 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
985 \
986 TYPE_SCTP_FUNC(sctp_sf_timer_ignore), \
987}
988
989static const struct sctp_sm_table_entry
990timeout_event_table[SCTP_NUM_TIMEOUT_TYPES][SCTP_STATE_NUM_STATES] = {
991 TYPE_SCTP_EVENT_TIMEOUT_NONE,
992 TYPE_SCTP_EVENT_TIMEOUT_T1_COOKIE,
993 TYPE_SCTP_EVENT_TIMEOUT_T1_INIT,
994 TYPE_SCTP_EVENT_TIMEOUT_T2_SHUTDOWN,
995 TYPE_SCTP_EVENT_TIMEOUT_T3_RTX,
996 TYPE_SCTP_EVENT_TIMEOUT_T4_RTO,
997 TYPE_SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD,
998 TYPE_SCTP_EVENT_TIMEOUT_HEARTBEAT,
999 TYPE_SCTP_EVENT_TIMEOUT_RECONF,
1000 TYPE_SCTP_EVENT_TIMEOUT_PROBE,
1001 TYPE_SCTP_EVENT_TIMEOUT_SACK,
1002 TYPE_SCTP_EVENT_TIMEOUT_AUTOCLOSE,
1003};
1004
1005static const struct sctp_sm_table_entry *sctp_chunk_event_lookup(
1006 struct net *net,
1007 enum sctp_cid cid,
1008 enum sctp_state state)
1009{
1010 if (state > SCTP_STATE_MAX)
1011 return &bug;
1012
1013 if (cid == SCTP_CID_I_DATA)
1014 cid = SCTP_CID_DATA;
1015
1016 if (cid <= SCTP_CID_BASE_MAX)
1017 return &chunk_event_table[cid][state];
1018
1019 switch ((u16)cid) {
1020 case SCTP_CID_FWD_TSN:
1021 case SCTP_CID_I_FWD_TSN:
1022 return &prsctp_chunk_event_table[0][state];
1023
1024 case SCTP_CID_ASCONF:
1025 return &addip_chunk_event_table[0][state];
1026
1027 case SCTP_CID_ASCONF_ACK:
1028 return &addip_chunk_event_table[1][state];
1029
1030 case SCTP_CID_RECONF:
1031 return &reconf_chunk_event_table[0][state];
1032
1033 case SCTP_CID_AUTH:
1034 return &auth_chunk_event_table[0][state];
1035
1036 case SCTP_CID_PAD:
1037 return &pad_chunk_event_table[state];
1038 }
1039
1040 return &chunk_event_table_unknown[state];
1041}
1042