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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50#include <linux/types.h>
51#include <linux/compiler.h>
52#include <linux/slab.h>
53#include <linux/in.h>
54#include <net/sctp/command.h>
55#include <net/sctp/sctp.h>
56
57#ifndef __sctp_sm_h__
58#define __sctp_sm_h__
59
60
61
62
63typedef enum {
64 SCTP_DISPOSITION_DISCARD,
65 SCTP_DISPOSITION_CONSUME,
66 SCTP_DISPOSITION_NOMEM,
67 SCTP_DISPOSITION_DELETE_TCB,
68 SCTP_DISPOSITION_ABORT,
69 SCTP_DISPOSITION_VIOLATION,
70 SCTP_DISPOSITION_NOT_IMPL,
71 SCTP_DISPOSITION_ERROR,
72 SCTP_DISPOSITION_BUG,
73} sctp_disposition_t;
74
75typedef struct {
76 int name;
77 int action;
78} sctp_sm_command_t;
79
80typedef sctp_disposition_t (sctp_state_fn_t) (const struct sctp_endpoint *,
81 const struct sctp_association *,
82 const sctp_subtype_t type,
83 void *arg,
84 sctp_cmd_seq_t *);
85typedef void (sctp_timer_event_t) (unsigned long);
86typedef struct {
87 sctp_state_fn_t *fn;
88 const char *name;
89} sctp_sm_table_entry_t;
90
91
92
93
94
95
96sctp_state_fn_t sctp_sf_not_impl;
97sctp_state_fn_t sctp_sf_bug;
98
99
100sctp_state_fn_t sctp_sf_timer_ignore;
101
102
103sctp_state_fn_t sctp_sf_do_9_1_abort;
104sctp_state_fn_t sctp_sf_cookie_wait_abort;
105sctp_state_fn_t sctp_sf_cookie_echoed_abort;
106sctp_state_fn_t sctp_sf_shutdown_pending_abort;
107sctp_state_fn_t sctp_sf_shutdown_sent_abort;
108sctp_state_fn_t sctp_sf_shutdown_ack_sent_abort;
109sctp_state_fn_t sctp_sf_do_5_1B_init;
110sctp_state_fn_t sctp_sf_do_5_1C_ack;
111sctp_state_fn_t sctp_sf_do_5_1D_ce;
112sctp_state_fn_t sctp_sf_do_5_1E_ca;
113sctp_state_fn_t sctp_sf_do_4_C;
114sctp_state_fn_t sctp_sf_eat_data_6_2;
115sctp_state_fn_t sctp_sf_eat_data_fast_4_4;
116sctp_state_fn_t sctp_sf_eat_sack_6_2;
117sctp_state_fn_t sctp_sf_operr_notify;
118sctp_state_fn_t sctp_sf_t1_init_timer_expire;
119sctp_state_fn_t sctp_sf_t1_cookie_timer_expire;
120sctp_state_fn_t sctp_sf_t2_timer_expire;
121sctp_state_fn_t sctp_sf_t4_timer_expire;
122sctp_state_fn_t sctp_sf_t5_timer_expire;
123sctp_state_fn_t sctp_sf_sendbeat_8_3;
124sctp_state_fn_t sctp_sf_beat_8_3;
125sctp_state_fn_t sctp_sf_backbeat_8_3;
126sctp_state_fn_t sctp_sf_do_9_2_final;
127sctp_state_fn_t sctp_sf_do_9_2_shutdown;
128sctp_state_fn_t sctp_sf_do_9_2_shut_ctsn;
129sctp_state_fn_t sctp_sf_do_ecn_cwr;
130sctp_state_fn_t sctp_sf_do_ecne;
131sctp_state_fn_t sctp_sf_ootb;
132sctp_state_fn_t sctp_sf_pdiscard;
133sctp_state_fn_t sctp_sf_violation;
134sctp_state_fn_t sctp_sf_discard_chunk;
135sctp_state_fn_t sctp_sf_do_5_2_1_siminit;
136sctp_state_fn_t sctp_sf_do_5_2_2_dupinit;
137sctp_state_fn_t sctp_sf_do_5_2_3_initack;
138sctp_state_fn_t sctp_sf_do_5_2_4_dupcook;
139sctp_state_fn_t sctp_sf_unk_chunk;
140sctp_state_fn_t sctp_sf_do_8_5_1_E_sa;
141sctp_state_fn_t sctp_sf_cookie_echoed_err;
142sctp_state_fn_t sctp_sf_do_asconf;
143sctp_state_fn_t sctp_sf_do_asconf_ack;
144sctp_state_fn_t sctp_sf_do_9_2_reshutack;
145sctp_state_fn_t sctp_sf_eat_fwd_tsn;
146sctp_state_fn_t sctp_sf_eat_fwd_tsn_fast;
147sctp_state_fn_t sctp_sf_eat_auth;
148
149
150sctp_state_fn_t sctp_sf_do_prm_asoc;
151sctp_state_fn_t sctp_sf_do_prm_send;
152sctp_state_fn_t sctp_sf_do_9_2_prm_shutdown;
153sctp_state_fn_t sctp_sf_cookie_wait_prm_shutdown;
154sctp_state_fn_t sctp_sf_cookie_echoed_prm_shutdown;
155sctp_state_fn_t sctp_sf_do_9_1_prm_abort;
156sctp_state_fn_t sctp_sf_cookie_wait_prm_abort;
157sctp_state_fn_t sctp_sf_cookie_echoed_prm_abort;
158sctp_state_fn_t sctp_sf_shutdown_pending_prm_abort;
159sctp_state_fn_t sctp_sf_shutdown_sent_prm_abort;
160sctp_state_fn_t sctp_sf_shutdown_ack_sent_prm_abort;
161sctp_state_fn_t sctp_sf_error_closed;
162sctp_state_fn_t sctp_sf_error_shutdown;
163sctp_state_fn_t sctp_sf_ignore_primitive;
164sctp_state_fn_t sctp_sf_do_prm_requestheartbeat;
165sctp_state_fn_t sctp_sf_do_prm_asconf;
166
167
168sctp_state_fn_t sctp_sf_do_no_pending_tsn;
169sctp_state_fn_t sctp_sf_do_9_2_start_shutdown;
170sctp_state_fn_t sctp_sf_do_9_2_shutdown_ack;
171sctp_state_fn_t sctp_sf_ignore_other;
172sctp_state_fn_t sctp_sf_cookie_wait_icmp_abort;
173
174
175sctp_state_fn_t sctp_sf_do_6_3_3_rtx;
176sctp_state_fn_t sctp_sf_do_6_2_sack;
177sctp_state_fn_t sctp_sf_autoclose_timer_expire;
178
179
180__u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
181const sctp_sm_table_entry_t *sctp_sm_lookup_event(sctp_event_t,
182 sctp_state_t,
183 sctp_subtype_t);
184int sctp_chunk_iif(const struct sctp_chunk *);
185struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
186 struct sctp_chunk *,
187 gfp_t gfp);
188__u32 sctp_generate_verification_tag(void);
189void sctp_populate_tie_tags(__u8 *cookie, __u32 curTag, __u32 hisTag);
190
191
192struct sctp_chunk *sctp_make_init(const struct sctp_association *,
193 const struct sctp_bind_addr *,
194 gfp_t gfp, int vparam_len);
195struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *,
196 const struct sctp_chunk *,
197 const gfp_t gfp,
198 const int unkparam_len);
199struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *,
200 const struct sctp_chunk *);
201struct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *,
202 const struct sctp_chunk *);
203struct sctp_chunk *sctp_make_cwr(const struct sctp_association *,
204 const __u32 lowest_tsn,
205 const struct sctp_chunk *);
206struct sctp_chunk * sctp_make_datafrag_empty(struct sctp_association *,
207 const struct sctp_sndrcvinfo *sinfo,
208 int len, const __u8 flags,
209 __u16 ssn);
210struct sctp_chunk *sctp_make_ecne(const struct sctp_association *,
211 const __u32);
212struct sctp_chunk *sctp_make_sack(const struct sctp_association *);
213struct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc,
214 const struct sctp_chunk *chunk);
215struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc,
216 const struct sctp_chunk *);
217struct sctp_chunk *sctp_make_shutdown_complete(const struct sctp_association *,
218 const struct sctp_chunk *);
219void sctp_init_cause(struct sctp_chunk *, __be16 cause, size_t);
220struct sctp_chunk *sctp_make_abort(const struct sctp_association *,
221 const struct sctp_chunk *,
222 const size_t hint);
223struct sctp_chunk *sctp_make_abort_no_data(const struct sctp_association *,
224 const struct sctp_chunk *,
225 __u32 tsn);
226struct sctp_chunk *sctp_make_abort_user(const struct sctp_association *,
227 const struct msghdr *, size_t msg_len);
228struct sctp_chunk *sctp_make_abort_violation(const struct sctp_association *,
229 const struct sctp_chunk *,
230 const __u8 *,
231 const size_t );
232struct sctp_chunk *sctp_make_violation_paramlen(const struct sctp_association *,
233 const struct sctp_chunk *,
234 struct sctp_paramhdr *);
235struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *,
236 const struct sctp_transport *);
237struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *,
238 const struct sctp_chunk *,
239 const void *payload,
240 const size_t paylen);
241struct sctp_chunk *sctp_make_op_error(const struct sctp_association *,
242 const struct sctp_chunk *chunk,
243 __be16 cause_code,
244 const void *payload,
245 size_t paylen,
246 size_t reserve_tail);
247
248struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *,
249 union sctp_addr *,
250 struct sockaddr *,
251 int, __be16);
252struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
253 union sctp_addr *addr);
254int sctp_verify_asconf(const struct sctp_association *asoc,
255 struct sctp_paramhdr *param_hdr, void *chunk_end,
256 struct sctp_paramhdr **errp);
257struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
258 struct sctp_chunk *asconf);
259int sctp_process_asconf_ack(struct sctp_association *asoc,
260 struct sctp_chunk *asconf_ack);
261struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
262 __u32 new_cum_tsn, size_t nstreams,
263 struct sctp_fwdtsn_skip *skiplist);
264struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc);
265
266void sctp_chunk_assign_tsn(struct sctp_chunk *);
267void sctp_chunk_assign_ssn(struct sctp_chunk *);
268
269
270
271int sctp_do_sm(sctp_event_t event_type, sctp_subtype_t subtype,
272 sctp_state_t state,
273 struct sctp_endpoint *,
274 struct sctp_association *asoc,
275 void *event_arg,
276 gfp_t gfp);
277
278
279void sctp_generate_t3_rtx_event(unsigned long peer);
280void sctp_generate_heartbeat_event(unsigned long peer);
281void sctp_generate_proto_unreach_event(unsigned long peer);
282
283void sctp_ootb_pkt_free(struct sctp_packet *);
284
285struct sctp_association *sctp_unpack_cookie(const struct sctp_endpoint *,
286 const struct sctp_association *,
287 struct sctp_chunk *,
288 gfp_t gfp, int *err,
289 struct sctp_chunk **err_chk_p);
290int sctp_addip_addr_config(struct sctp_association *, sctp_param_t,
291 struct sockaddr_storage*, int);
292
293
294__u32 sctp_generate_tag(const struct sctp_endpoint *);
295__u32 sctp_generate_tsn(const struct sctp_endpoint *);
296
297
298extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
299
300
301
302static inline __u16 sctp_data_size(struct sctp_chunk *chunk)
303{
304 __u16 size;
305
306 size = ntohs(chunk->chunk_hdr->length);
307 size -= sizeof(sctp_data_chunk_t);
308
309 return size;
310}
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341enum {
342 TSN_SIGN_BIT = (1<<31)
343};
344
345static inline int TSN_lt(__u32 s, __u32 t)
346{
347 return ((s) - (t)) & TSN_SIGN_BIT;
348}
349
350static inline int TSN_lte(__u32 s, __u32 t)
351{
352 return ((s) == (t)) || (((s) - (t)) & TSN_SIGN_BIT);
353}
354
355
356
357
358
359
360
361
362
363
364
365enum {
366 SSN_SIGN_BIT = (1<<15)
367};
368
369static inline int SSN_lt(__u16 s, __u16 t)
370{
371 return ((s) - (t)) & SSN_SIGN_BIT;
372}
373
374static inline int SSN_lte(__u16 s, __u16 t)
375{
376 return ((s) == (t)) || (((s) - (t)) & SSN_SIGN_BIT);
377}
378
379
380
381
382
383
384enum {
385 ADDIP_SERIAL_SIGN_BIT = (1<<31)
386};
387
388static inline int ADDIP_SERIAL_gte(__u16 s, __u16 t)
389{
390 return ((s) == (t)) || (((t) - (s)) & ADDIP_SERIAL_SIGN_BIT);
391}
392
393
394static inline int
395sctp_vtag_verify(const struct sctp_chunk *chunk,
396 const struct sctp_association *asoc)
397{
398
399
400
401
402
403
404 if (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)
405 return 1;
406
407 return 0;
408}
409
410
411
412
413static inline int
414sctp_vtag_verify_either(const struct sctp_chunk *chunk,
415 const struct sctp_association *asoc)
416{
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438 if ((!sctp_test_T_bit(chunk) &&
439 (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)) ||
440 (sctp_test_T_bit(chunk) && asoc->c.peer_vtag &&
441 (ntohl(chunk->sctp_hdr->vtag) == asoc->c.peer_vtag))) {
442 return 1;
443 }
444
445 return 0;
446}
447
448#endif
449