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_9_2_start_shutdown;
169sctp_state_fn_t sctp_sf_do_9_2_shutdown_ack;
170sctp_state_fn_t sctp_sf_ignore_other;
171sctp_state_fn_t sctp_sf_cookie_wait_icmp_abort;
172
173
174sctp_state_fn_t sctp_sf_do_6_3_3_rtx;
175sctp_state_fn_t sctp_sf_do_6_2_sack;
176sctp_state_fn_t sctp_sf_autoclose_timer_expire;
177
178
179__u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
180const sctp_sm_table_entry_t *sctp_sm_lookup_event(sctp_event_t,
181 sctp_state_t,
182 sctp_subtype_t);
183int sctp_chunk_iif(const struct sctp_chunk *);
184struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
185 struct sctp_chunk *,
186 gfp_t gfp);
187__u32 sctp_generate_verification_tag(void);
188void sctp_populate_tie_tags(__u8 *cookie, __u32 curTag, __u32 hisTag);
189
190
191struct sctp_chunk *sctp_make_init(const struct sctp_association *,
192 const struct sctp_bind_addr *,
193 gfp_t gfp, int vparam_len);
194struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *,
195 const struct sctp_chunk *,
196 const gfp_t gfp,
197 const int unkparam_len);
198struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *,
199 const struct sctp_chunk *);
200struct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *,
201 const struct sctp_chunk *);
202struct sctp_chunk *sctp_make_cwr(const struct sctp_association *,
203 const __u32 lowest_tsn,
204 const struct sctp_chunk *);
205struct sctp_chunk * sctp_make_datafrag_empty(struct sctp_association *,
206 const struct sctp_sndrcvinfo *sinfo,
207 int len, const __u8 flags,
208 __u16 ssn);
209struct sctp_chunk *sctp_make_ecne(const struct sctp_association *,
210 const __u32);
211struct sctp_chunk *sctp_make_sack(const struct sctp_association *);
212struct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc,
213 const struct sctp_chunk *chunk);
214struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc,
215 const struct sctp_chunk *);
216struct sctp_chunk *sctp_make_shutdown_complete(const struct sctp_association *,
217 const struct sctp_chunk *);
218void sctp_init_cause(struct sctp_chunk *, __be16 cause, size_t);
219struct sctp_chunk *sctp_make_abort(const struct sctp_association *,
220 const struct sctp_chunk *,
221 const size_t hint);
222struct sctp_chunk *sctp_make_abort_no_data(const struct sctp_association *,
223 const struct sctp_chunk *,
224 __u32 tsn);
225struct sctp_chunk *sctp_make_abort_user(const struct sctp_association *,
226 const struct msghdr *, size_t msg_len);
227struct sctp_chunk *sctp_make_abort_violation(const struct sctp_association *,
228 const struct sctp_chunk *,
229 const __u8 *,
230 const size_t );
231struct sctp_chunk *sctp_make_violation_paramlen(const struct sctp_association *,
232 const struct sctp_chunk *,
233 struct sctp_paramhdr *);
234struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *,
235 const struct sctp_transport *,
236 const void *payload,
237 const size_t paylen);
238struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *,
239 const struct sctp_chunk *,
240 const void *payload,
241 const size_t paylen);
242struct sctp_chunk *sctp_make_op_error(const struct sctp_association *,
243 const struct sctp_chunk *chunk,
244 __be16 cause_code,
245 const void *payload,
246 size_t paylen);
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);
281
282void sctp_ootb_pkt_free(struct sctp_packet *);
283
284struct sctp_association *sctp_unpack_cookie(const struct sctp_endpoint *,
285 const struct sctp_association *,
286 struct sctp_chunk *,
287 gfp_t gfp, int *err,
288 struct sctp_chunk **err_chk_p);
289int sctp_addip_addr_config(struct sctp_association *, sctp_param_t,
290 struct sockaddr_storage*, int);
291
292
293__u32 sctp_generate_tag(const struct sctp_endpoint *);
294__u32 sctp_generate_tsn(const struct sctp_endpoint *);
295
296
297extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
298
299
300
301static inline __u16 sctp_data_size(struct sctp_chunk *chunk)
302{
303 __u16 size;
304
305 size = ntohs(chunk->chunk_hdr->length);
306 size -= sizeof(sctp_data_chunk_t);
307
308 return size;
309}
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
340enum {
341 TSN_SIGN_BIT = (1<<31)
342};
343
344static inline int TSN_lt(__u32 s, __u32 t)
345{
346 return (((s) - (t)) & TSN_SIGN_BIT);
347}
348
349static inline int TSN_lte(__u32 s, __u32 t)
350{
351 return (((s) == (t)) || (((s) - (t)) & TSN_SIGN_BIT));
352}
353
354
355
356
357
358
359
360
361
362
363
364enum {
365 SSN_SIGN_BIT = (1<<15)
366};
367
368static inline int SSN_lt(__u16 s, __u16 t)
369{
370 return (((s) - (t)) & SSN_SIGN_BIT);
371}
372
373static inline int SSN_lte(__u16 s, __u16 t)
374{
375 return (((s) == (t)) || (((s) - (t)) & SSN_SIGN_BIT));
376}
377
378
379
380
381
382
383enum {
384 ADDIP_SERIAL_SIGN_BIT = (1<<31)
385};
386
387static inline int ADDIP_SERIAL_gte(__u16 s, __u16 t)
388{
389 return (((s) == (t)) || (((t) - (s)) & ADDIP_SERIAL_SIGN_BIT));
390}
391
392
393static inline int
394sctp_vtag_verify(const struct sctp_chunk *chunk,
395 const struct sctp_association *asoc)
396{
397
398
399
400
401
402
403 if (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)
404 return 1;
405
406 return 0;
407}
408
409
410
411
412static inline int
413sctp_vtag_verify_either(const struct sctp_chunk *chunk,
414 const struct sctp_association *asoc)
415{
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437 if ((!sctp_test_T_bit(chunk) &&
438 (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)) ||
439 (sctp_test_T_bit(chunk) &&
440 (ntohl(chunk->sctp_hdr->vtag) == asoc->c.peer_vtag))) {
441 return 1;
442 }
443
444 return 0;
445}
446
447#endif
448