xref: /OK3568_Linux_fs/kernel/include/net/sctp/sm.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /* SCTP kernel implementation
3*4882a593Smuzhiyun  * (C) Copyright IBM Corp. 2001, 2004
4*4882a593Smuzhiyun  * Copyright (c) 1999-2000 Cisco, Inc.
5*4882a593Smuzhiyun  * Copyright (c) 1999-2001 Motorola, Inc.
6*4882a593Smuzhiyun  * Copyright (c) 2001 Intel Corp.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * This file is part of the SCTP kernel implementation
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * These are definitions needed by the state machine.
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * Please send any bug reports or fixes you make to the
13*4882a593Smuzhiyun  * email addresses:
14*4882a593Smuzhiyun  *    lksctp developers <linux-sctp@vger.kernel.org>
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * Written or modified by:
17*4882a593Smuzhiyun  *    La Monte H.P. Yarroll <piggy@acm.org>
18*4882a593Smuzhiyun  *    Karl Knutson <karl@athena.chicago.il.us>
19*4882a593Smuzhiyun  *    Xingang Guo <xingang.guo@intel.com>
20*4882a593Smuzhiyun  *    Jon Grimm <jgrimm@us.ibm.com>
21*4882a593Smuzhiyun  *    Dajiang Zhang <dajiang.zhang@nokia.com>
22*4882a593Smuzhiyun  *    Sridhar Samudrala <sri@us.ibm.com>
23*4882a593Smuzhiyun  *    Daisy Chang <daisyc@us.ibm.com>
24*4882a593Smuzhiyun  *    Ardelle Fan <ardelle.fan@intel.com>
25*4882a593Smuzhiyun  *    Kevin Gao <kevin.gao@intel.com>
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #include <linux/types.h>
29*4882a593Smuzhiyun #include <linux/compiler.h>
30*4882a593Smuzhiyun #include <linux/slab.h>
31*4882a593Smuzhiyun #include <linux/in.h>
32*4882a593Smuzhiyun #include <net/sctp/command.h>
33*4882a593Smuzhiyun #include <net/sctp/sctp.h>
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #ifndef __sctp_sm_h__
36*4882a593Smuzhiyun #define __sctp_sm_h__
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun  * Possible values for the disposition are:
40*4882a593Smuzhiyun  */
41*4882a593Smuzhiyun enum sctp_disposition {
42*4882a593Smuzhiyun 	SCTP_DISPOSITION_DISCARD,	 /* No further processing.  */
43*4882a593Smuzhiyun 	SCTP_DISPOSITION_CONSUME,	 /* Process return values normally.  */
44*4882a593Smuzhiyun 	SCTP_DISPOSITION_NOMEM,		 /* We ran out of memory--recover.  */
45*4882a593Smuzhiyun 	SCTP_DISPOSITION_DELETE_TCB,	 /* Close the association.  */
46*4882a593Smuzhiyun 	SCTP_DISPOSITION_ABORT,		 /* Close the association NOW.  */
47*4882a593Smuzhiyun 	SCTP_DISPOSITION_VIOLATION,	 /* The peer is misbehaving.  */
48*4882a593Smuzhiyun 	SCTP_DISPOSITION_NOT_IMPL,	 /* This entry is not implemented.  */
49*4882a593Smuzhiyun 	SCTP_DISPOSITION_ERROR,		 /* This is plain old user error.  */
50*4882a593Smuzhiyun 	SCTP_DISPOSITION_BUG,		 /* This is a bug.  */
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun typedef enum sctp_disposition (sctp_state_fn_t) (
54*4882a593Smuzhiyun 					struct net *net,
55*4882a593Smuzhiyun 					const struct sctp_endpoint *ep,
56*4882a593Smuzhiyun 					const struct sctp_association *asoc,
57*4882a593Smuzhiyun 					const union sctp_subtype type,
58*4882a593Smuzhiyun 					void *arg,
59*4882a593Smuzhiyun 					struct sctp_cmd_seq *commands);
60*4882a593Smuzhiyun typedef void (sctp_timer_event_t) (struct timer_list *);
61*4882a593Smuzhiyun struct sctp_sm_table_entry {
62*4882a593Smuzhiyun 	sctp_state_fn_t *fn;
63*4882a593Smuzhiyun 	const char *name;
64*4882a593Smuzhiyun };
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /* A naming convention of "sctp_sf_xxx" applies to all the state functions
67*4882a593Smuzhiyun  * currently in use.
68*4882a593Smuzhiyun  */
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /* Prototypes for generic state functions. */
71*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_not_impl;
72*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_bug;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /* Prototypes for gener timer state functions. */
75*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_timer_ignore;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /* Prototypes for chunk state functions. */
78*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_1_abort;
79*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_cookie_wait_abort;
80*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_cookie_echoed_abort;
81*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_shutdown_pending_abort;
82*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_shutdown_sent_abort;
83*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_shutdown_ack_sent_abort;
84*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_5_1B_init;
85*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_5_1C_ack;
86*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_5_1D_ce;
87*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_5_1E_ca;
88*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_4_C;
89*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_eat_data_6_2;
90*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_eat_data_fast_4_4;
91*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_eat_sack_6_2;
92*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_operr_notify;
93*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_t1_init_timer_expire;
94*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_t1_cookie_timer_expire;
95*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_t2_timer_expire;
96*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_t4_timer_expire;
97*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_t5_timer_expire;
98*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_sendbeat_8_3;
99*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_beat_8_3;
100*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_backbeat_8_3;
101*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_2_final;
102*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_2_shutdown;
103*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_2_shut_ctsn;
104*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_ecn_cwr;
105*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_ecne;
106*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_ootb;
107*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_pdiscard;
108*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_violation;
109*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_discard_chunk;
110*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_5_2_1_siminit;
111*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_5_2_2_dupinit;
112*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_5_2_3_initack;
113*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_5_2_4_dupcook;
114*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_unk_chunk;
115*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_8_5_1_E_sa;
116*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_cookie_echoed_err;
117*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_asconf;
118*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_asconf_ack;
119*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_reconf;
120*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_2_reshutack;
121*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_eat_fwd_tsn;
122*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_eat_fwd_tsn_fast;
123*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_eat_auth;
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /* Prototypes for primitive event state functions.  */
126*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_prm_asoc;
127*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_prm_send;
128*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_2_prm_shutdown;
129*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_cookie_wait_prm_shutdown;
130*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_cookie_echoed_prm_shutdown;
131*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_1_prm_abort;
132*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_cookie_wait_prm_abort;
133*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_cookie_echoed_prm_abort;
134*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_shutdown_pending_prm_abort;
135*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_shutdown_sent_prm_abort;
136*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_shutdown_ack_sent_prm_abort;
137*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_error_closed;
138*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_error_shutdown;
139*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_ignore_primitive;
140*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_prm_requestheartbeat;
141*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_prm_asconf;
142*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_prm_reconf;
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /* Prototypes for other event state functions.  */
145*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_no_pending_tsn;
146*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_2_start_shutdown;
147*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_9_2_shutdown_ack;
148*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_ignore_other;
149*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_cookie_wait_icmp_abort;
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun /* Prototypes for timeout event state functions.  */
152*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_6_3_3_rtx;
153*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_send_reconf;
154*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_do_6_2_sack;
155*4882a593Smuzhiyun sctp_state_fn_t sctp_sf_autoclose_timer_expire;
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun /* Prototypes for utility support functions.  */
158*4882a593Smuzhiyun __u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
159*4882a593Smuzhiyun const struct sctp_sm_table_entry *sctp_sm_lookup_event(
160*4882a593Smuzhiyun 					struct net *net,
161*4882a593Smuzhiyun 					enum sctp_event_type event_type,
162*4882a593Smuzhiyun 					enum sctp_state state,
163*4882a593Smuzhiyun 					union sctp_subtype event_subtype);
164*4882a593Smuzhiyun int sctp_chunk_iif(const struct sctp_chunk *);
165*4882a593Smuzhiyun struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
166*4882a593Smuzhiyun 					     struct sctp_chunk *,
167*4882a593Smuzhiyun 					     gfp_t gfp);
168*4882a593Smuzhiyun __u32 sctp_generate_verification_tag(void);
169*4882a593Smuzhiyun void sctp_populate_tie_tags(__u8 *cookie, __u32 curTag, __u32 hisTag);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun /* Prototypes for chunk-building functions.  */
172*4882a593Smuzhiyun struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
173*4882a593Smuzhiyun 				  const struct sctp_bind_addr *bp,
174*4882a593Smuzhiyun 				  gfp_t gfp, int vparam_len);
175*4882a593Smuzhiyun struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
176*4882a593Smuzhiyun 				      const struct sctp_chunk *chunk,
177*4882a593Smuzhiyun 				      const gfp_t gfp, const int unkparam_len);
178*4882a593Smuzhiyun struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *asoc,
179*4882a593Smuzhiyun 					 const struct sctp_chunk *chunk);
180*4882a593Smuzhiyun struct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *asoc,
181*4882a593Smuzhiyun 					const struct sctp_chunk *chunk);
182*4882a593Smuzhiyun struct sctp_chunk *sctp_make_cwr(const struct sctp_association *asoc,
183*4882a593Smuzhiyun 				 const __u32 lowest_tsn,
184*4882a593Smuzhiyun 				 const struct sctp_chunk *chunk);
185*4882a593Smuzhiyun struct sctp_chunk *sctp_make_idata(const struct sctp_association *asoc,
186*4882a593Smuzhiyun 				   __u8 flags, int paylen, gfp_t gfp);
187*4882a593Smuzhiyun struct sctp_chunk *sctp_make_ifwdtsn(const struct sctp_association *asoc,
188*4882a593Smuzhiyun 				     __u32 new_cum_tsn, size_t nstreams,
189*4882a593Smuzhiyun 				     struct sctp_ifwdtsn_skip *skiplist);
190*4882a593Smuzhiyun struct sctp_chunk *sctp_make_datafrag_empty(const struct sctp_association *asoc,
191*4882a593Smuzhiyun 					    const struct sctp_sndrcvinfo *sinfo,
192*4882a593Smuzhiyun 					    int len, __u8 flags, gfp_t gfp);
193*4882a593Smuzhiyun struct sctp_chunk *sctp_make_ecne(const struct sctp_association *asoc,
194*4882a593Smuzhiyun 				  const __u32 lowest_tsn);
195*4882a593Smuzhiyun struct sctp_chunk *sctp_make_sack(struct sctp_association *asoc);
196*4882a593Smuzhiyun struct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc,
197*4882a593Smuzhiyun 				      const struct sctp_chunk *chunk);
198*4882a593Smuzhiyun struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc,
199*4882a593Smuzhiyun 					  const struct sctp_chunk *chunk);
200*4882a593Smuzhiyun struct sctp_chunk *sctp_make_shutdown_complete(
201*4882a593Smuzhiyun 					const struct sctp_association *asoc,
202*4882a593Smuzhiyun 					const struct sctp_chunk *chunk);
203*4882a593Smuzhiyun int sctp_init_cause(struct sctp_chunk *chunk, __be16 cause, size_t paylen);
204*4882a593Smuzhiyun struct sctp_chunk *sctp_make_abort(const struct sctp_association *asoc,
205*4882a593Smuzhiyun 				   const struct sctp_chunk *chunk,
206*4882a593Smuzhiyun 				   const size_t hint);
207*4882a593Smuzhiyun struct sctp_chunk *sctp_make_abort_no_data(const struct sctp_association *asoc,
208*4882a593Smuzhiyun 					   const struct sctp_chunk *chunk,
209*4882a593Smuzhiyun 					   __u32 tsn);
210*4882a593Smuzhiyun struct sctp_chunk *sctp_make_abort_user(const struct sctp_association *asoc,
211*4882a593Smuzhiyun 					struct msghdr *msg, size_t msg_len);
212*4882a593Smuzhiyun struct sctp_chunk *sctp_make_abort_violation(
213*4882a593Smuzhiyun 					const struct sctp_association *asoc,
214*4882a593Smuzhiyun 					const struct sctp_chunk *chunk,
215*4882a593Smuzhiyun 					const __u8 *payload,
216*4882a593Smuzhiyun 					const size_t paylen);
217*4882a593Smuzhiyun struct sctp_chunk *sctp_make_violation_paramlen(
218*4882a593Smuzhiyun 					const struct sctp_association *asoc,
219*4882a593Smuzhiyun 					const struct sctp_chunk *chunk,
220*4882a593Smuzhiyun 					struct sctp_paramhdr *param);
221*4882a593Smuzhiyun struct sctp_chunk *sctp_make_violation_max_retrans(
222*4882a593Smuzhiyun 					const struct sctp_association *asoc,
223*4882a593Smuzhiyun 					const struct sctp_chunk *chunk);
224*4882a593Smuzhiyun struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
225*4882a593Smuzhiyun 				       const struct sctp_transport *transport);
226*4882a593Smuzhiyun struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc,
227*4882a593Smuzhiyun 					   const struct sctp_chunk *chunk,
228*4882a593Smuzhiyun 					   const void *payload,
229*4882a593Smuzhiyun 					   const size_t paylen);
230*4882a593Smuzhiyun struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,
231*4882a593Smuzhiyun 				      const struct sctp_chunk *chunk,
232*4882a593Smuzhiyun 				      __be16 cause_code, const void *payload,
233*4882a593Smuzhiyun 				      size_t paylen, size_t reserve_tail);
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
236*4882a593Smuzhiyun 					      union sctp_addr *laddr,
237*4882a593Smuzhiyun 					      struct sockaddr *addrs,
238*4882a593Smuzhiyun 					      int addrcnt, __be16 flags);
239*4882a593Smuzhiyun struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
240*4882a593Smuzhiyun 					     union sctp_addr *addr);
241*4882a593Smuzhiyun bool sctp_verify_asconf(const struct sctp_association *asoc,
242*4882a593Smuzhiyun 			struct sctp_chunk *chunk, bool addr_param_needed,
243*4882a593Smuzhiyun 			struct sctp_paramhdr **errp);
244*4882a593Smuzhiyun struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
245*4882a593Smuzhiyun 				       struct sctp_chunk *asconf);
246*4882a593Smuzhiyun int sctp_process_asconf_ack(struct sctp_association *asoc,
247*4882a593Smuzhiyun 			    struct sctp_chunk *asconf_ack);
248*4882a593Smuzhiyun struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
249*4882a593Smuzhiyun 				    __u32 new_cum_tsn, size_t nstreams,
250*4882a593Smuzhiyun 				    struct sctp_fwdtsn_skip *skiplist);
251*4882a593Smuzhiyun struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc,
252*4882a593Smuzhiyun 				  __u16 key_id);
253*4882a593Smuzhiyun struct sctp_chunk *sctp_make_strreset_req(const struct sctp_association *asoc,
254*4882a593Smuzhiyun 					  __u16 stream_num, __be16 *stream_list,
255*4882a593Smuzhiyun 					  bool out, bool in);
256*4882a593Smuzhiyun struct sctp_chunk *sctp_make_strreset_tsnreq(
257*4882a593Smuzhiyun 					const struct sctp_association *asoc);
258*4882a593Smuzhiyun struct sctp_chunk *sctp_make_strreset_addstrm(
259*4882a593Smuzhiyun 					const struct sctp_association *asoc,
260*4882a593Smuzhiyun 					__u16 out, __u16 in);
261*4882a593Smuzhiyun struct sctp_chunk *sctp_make_strreset_resp(const struct sctp_association *asoc,
262*4882a593Smuzhiyun 					   __u32 result, __u32 sn);
263*4882a593Smuzhiyun struct sctp_chunk *sctp_make_strreset_tsnresp(struct sctp_association *asoc,
264*4882a593Smuzhiyun 					      __u32 result, __u32 sn,
265*4882a593Smuzhiyun 					      __u32 sender_tsn,
266*4882a593Smuzhiyun 					      __u32 receiver_tsn);
267*4882a593Smuzhiyun bool sctp_verify_reconf(const struct sctp_association *asoc,
268*4882a593Smuzhiyun 			struct sctp_chunk *chunk,
269*4882a593Smuzhiyun 			struct sctp_paramhdr **errp);
270*4882a593Smuzhiyun void sctp_chunk_assign_tsn(struct sctp_chunk *chunk);
271*4882a593Smuzhiyun void sctp_chunk_assign_ssn(struct sctp_chunk *chunk);
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun /* Prototypes for stream-processing functions.  */
274*4882a593Smuzhiyun struct sctp_chunk *sctp_process_strreset_outreq(
275*4882a593Smuzhiyun 				struct sctp_association *asoc,
276*4882a593Smuzhiyun 				union sctp_params param,
277*4882a593Smuzhiyun 				struct sctp_ulpevent **evp);
278*4882a593Smuzhiyun struct sctp_chunk *sctp_process_strreset_inreq(
279*4882a593Smuzhiyun 				struct sctp_association *asoc,
280*4882a593Smuzhiyun 				union sctp_params param,
281*4882a593Smuzhiyun 				struct sctp_ulpevent **evp);
282*4882a593Smuzhiyun struct sctp_chunk *sctp_process_strreset_tsnreq(
283*4882a593Smuzhiyun 				struct sctp_association *asoc,
284*4882a593Smuzhiyun 				union sctp_params param,
285*4882a593Smuzhiyun 				struct sctp_ulpevent **evp);
286*4882a593Smuzhiyun struct sctp_chunk *sctp_process_strreset_addstrm_out(
287*4882a593Smuzhiyun 				struct sctp_association *asoc,
288*4882a593Smuzhiyun 				union sctp_params param,
289*4882a593Smuzhiyun 				struct sctp_ulpevent **evp);
290*4882a593Smuzhiyun struct sctp_chunk *sctp_process_strreset_addstrm_in(
291*4882a593Smuzhiyun 				struct sctp_association *asoc,
292*4882a593Smuzhiyun 				union sctp_params param,
293*4882a593Smuzhiyun 				struct sctp_ulpevent **evp);
294*4882a593Smuzhiyun struct sctp_chunk *sctp_process_strreset_resp(
295*4882a593Smuzhiyun 				struct sctp_association *asoc,
296*4882a593Smuzhiyun 				union sctp_params param,
297*4882a593Smuzhiyun 				struct sctp_ulpevent **evp);
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun /* Prototypes for statetable processing. */
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun int sctp_do_sm(struct net *net, enum sctp_event_type event_type,
302*4882a593Smuzhiyun 	       union sctp_subtype subtype, enum sctp_state state,
303*4882a593Smuzhiyun 	       struct sctp_endpoint *ep, struct sctp_association *asoc,
304*4882a593Smuzhiyun 	       void *event_arg, gfp_t gfp);
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun /* 2nd level prototypes */
307*4882a593Smuzhiyun void sctp_generate_t3_rtx_event(struct timer_list *t);
308*4882a593Smuzhiyun void sctp_generate_heartbeat_event(struct timer_list *t);
309*4882a593Smuzhiyun void sctp_generate_reconf_event(struct timer_list *t);
310*4882a593Smuzhiyun void sctp_generate_proto_unreach_event(struct timer_list *t);
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun void sctp_ootb_pkt_free(struct sctp_packet *packet);
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun struct sctp_association *sctp_unpack_cookie(
315*4882a593Smuzhiyun 					const struct sctp_endpoint *ep,
316*4882a593Smuzhiyun 					const struct sctp_association *asoc,
317*4882a593Smuzhiyun 					struct sctp_chunk *chunk,
318*4882a593Smuzhiyun 					gfp_t gfp, int *err,
319*4882a593Smuzhiyun 					struct sctp_chunk **err_chk_p);
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun /* 3rd level prototypes */
322*4882a593Smuzhiyun __u32 sctp_generate_tag(const struct sctp_endpoint *ep);
323*4882a593Smuzhiyun __u32 sctp_generate_tsn(const struct sctp_endpoint *ep);
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun /* Extern declarations for major data structures.  */
326*4882a593Smuzhiyun extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun /* Get the size of a DATA chunk payload. */
sctp_data_size(struct sctp_chunk * chunk)330*4882a593Smuzhiyun static inline __u16 sctp_data_size(struct sctp_chunk *chunk)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun 	__u16 size;
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	size = ntohs(chunk->chunk_hdr->length);
335*4882a593Smuzhiyun 	size -= sctp_datachk_len(&chunk->asoc->stream);
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 	return size;
338*4882a593Smuzhiyun }
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun /* Compare two TSNs */
341*4882a593Smuzhiyun #define TSN_lt(a,b)	\
342*4882a593Smuzhiyun 	(typecheck(__u32, a) && \
343*4882a593Smuzhiyun 	 typecheck(__u32, b) && \
344*4882a593Smuzhiyun 	 ((__s32)((a) - (b)) < 0))
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun #define TSN_lte(a,b)	\
347*4882a593Smuzhiyun 	(typecheck(__u32, a) && \
348*4882a593Smuzhiyun 	 typecheck(__u32, b) && \
349*4882a593Smuzhiyun 	 ((__s32)((a) - (b)) <= 0))
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun /* Compare two MIDs */
352*4882a593Smuzhiyun #define MID_lt(a, b)	\
353*4882a593Smuzhiyun 	(typecheck(__u32, a) && \
354*4882a593Smuzhiyun 	 typecheck(__u32, b) && \
355*4882a593Smuzhiyun 	 ((__s32)((a) - (b)) < 0))
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun /* Compare two SSNs */
358*4882a593Smuzhiyun #define SSN_lt(a,b)		\
359*4882a593Smuzhiyun 	(typecheck(__u16, a) && \
360*4882a593Smuzhiyun 	 typecheck(__u16, b) && \
361*4882a593Smuzhiyun 	 ((__s16)((a) - (b)) < 0))
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun /* ADDIP 3.1.1 */
364*4882a593Smuzhiyun #define ADDIP_SERIAL_gte(a,b)	\
365*4882a593Smuzhiyun 	(typecheck(__u32, a) && \
366*4882a593Smuzhiyun 	 typecheck(__u32, b) && \
367*4882a593Smuzhiyun 	 ((__s32)((b) - (a)) <= 0))
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun /* Check VTAG of the packet matches the sender's own tag. */
370*4882a593Smuzhiyun static inline int
sctp_vtag_verify(const struct sctp_chunk * chunk,const struct sctp_association * asoc)371*4882a593Smuzhiyun sctp_vtag_verify(const struct sctp_chunk *chunk,
372*4882a593Smuzhiyun 		 const struct sctp_association *asoc)
373*4882a593Smuzhiyun {
374*4882a593Smuzhiyun 	/* RFC 2960 Sec 8.5 When receiving an SCTP packet, the endpoint
375*4882a593Smuzhiyun 	 * MUST ensure that the value in the Verification Tag field of
376*4882a593Smuzhiyun 	 * the received SCTP packet matches its own Tag. If the received
377*4882a593Smuzhiyun 	 * Verification Tag value does not match the receiver's own
378*4882a593Smuzhiyun 	 * tag value, the receiver shall silently discard the packet...
379*4882a593Smuzhiyun 	 */
380*4882a593Smuzhiyun         if (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)
381*4882a593Smuzhiyun                 return 1;
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun 	return 0;
384*4882a593Smuzhiyun }
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun /* Check VTAG of the packet matches the sender's own tag and the T bit is
387*4882a593Smuzhiyun  * not set, OR its peer's tag and the T bit is set in the Chunk Flags.
388*4882a593Smuzhiyun  */
389*4882a593Smuzhiyun static inline int
sctp_vtag_verify_either(const struct sctp_chunk * chunk,const struct sctp_association * asoc)390*4882a593Smuzhiyun sctp_vtag_verify_either(const struct sctp_chunk *chunk,
391*4882a593Smuzhiyun 			const struct sctp_association *asoc)
392*4882a593Smuzhiyun {
393*4882a593Smuzhiyun         /* RFC 2960 Section 8.5.1, sctpimpguide Section 2.41
394*4882a593Smuzhiyun 	 *
395*4882a593Smuzhiyun 	 * B) The receiver of a ABORT MUST accept the packet
396*4882a593Smuzhiyun 	 *    if the Verification Tag field of the packet matches its own tag
397*4882a593Smuzhiyun 	 *    and the T bit is not set
398*4882a593Smuzhiyun 	 *    OR
399*4882a593Smuzhiyun 	 *    it is set to its peer's tag and the T bit is set in the Chunk
400*4882a593Smuzhiyun 	 *    Flags.
401*4882a593Smuzhiyun 	 *    Otherwise, the receiver MUST silently discard the packet
402*4882a593Smuzhiyun 	 *    and take no further action.
403*4882a593Smuzhiyun 	 *
404*4882a593Smuzhiyun 	 * C) The receiver of a SHUTDOWN COMPLETE shall accept the packet
405*4882a593Smuzhiyun 	 *    if the Verification Tag field of the packet matches its own tag
406*4882a593Smuzhiyun 	 *    and the T bit is not set
407*4882a593Smuzhiyun 	 *    OR
408*4882a593Smuzhiyun 	 *    it is set to its peer's tag and the T bit is set in the Chunk
409*4882a593Smuzhiyun 	 *    Flags.
410*4882a593Smuzhiyun 	 *    Otherwise, the receiver MUST silently discard the packet
411*4882a593Smuzhiyun 	 *    and take no further action.  An endpoint MUST ignore the
412*4882a593Smuzhiyun 	 *    SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
413*4882a593Smuzhiyun 	 */
414*4882a593Smuzhiyun         if ((!sctp_test_T_bit(chunk) &&
415*4882a593Smuzhiyun              (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)) ||
416*4882a593Smuzhiyun 	    (sctp_test_T_bit(chunk) && asoc->c.peer_vtag &&
417*4882a593Smuzhiyun 	     (ntohl(chunk->sctp_hdr->vtag) == asoc->c.peer_vtag))) {
418*4882a593Smuzhiyun                 return 1;
419*4882a593Smuzhiyun 	}
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun 	return 0;
422*4882a593Smuzhiyun }
423*4882a593Smuzhiyun 
424*4882a593Smuzhiyun #endif /* __sctp_sm_h__ */
425