147505b8bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
260c778b2SVlad Yasevich /* SCTP kernel implementation
31da177e4SLinus Torvalds * (C) Copyright IBM Corp. 2001, 2004
41da177e4SLinus Torvalds * Copyright (c) 1999-2000 Cisco, Inc.
51da177e4SLinus Torvalds * Copyright (c) 1999-2001 Motorola, Inc.
61da177e4SLinus Torvalds * Copyright (c) 2001 Intel Corp.
71da177e4SLinus Torvalds *
860c778b2SVlad Yasevich * This file is part of the SCTP kernel implementation
91da177e4SLinus Torvalds *
101da177e4SLinus Torvalds * These are definitions needed by the state machine.
111da177e4SLinus Torvalds *
121da177e4SLinus Torvalds * Please send any bug reports or fixes you make to the
131da177e4SLinus Torvalds * email addresses:
1491705c61SDaniel Borkmann * lksctp developers <linux-sctp@vger.kernel.org>
151da177e4SLinus Torvalds *
161da177e4SLinus Torvalds * Written or modified by:
171da177e4SLinus Torvalds * La Monte H.P. Yarroll <piggy@acm.org>
181da177e4SLinus Torvalds * Karl Knutson <karl@athena.chicago.il.us>
191da177e4SLinus Torvalds * Xingang Guo <xingang.guo@intel.com>
201da177e4SLinus Torvalds * Jon Grimm <jgrimm@us.ibm.com>
211da177e4SLinus Torvalds * Dajiang Zhang <dajiang.zhang@nokia.com>
221da177e4SLinus Torvalds * Sridhar Samudrala <sri@us.ibm.com>
231da177e4SLinus Torvalds * Daisy Chang <daisyc@us.ibm.com>
241da177e4SLinus Torvalds * Ardelle Fan <ardelle.fan@intel.com>
251da177e4SLinus Torvalds * Kevin Gao <kevin.gao@intel.com>
261da177e4SLinus Torvalds */
271da177e4SLinus Torvalds
281da177e4SLinus Torvalds #include <linux/types.h>
291da177e4SLinus Torvalds #include <linux/compiler.h>
301da177e4SLinus Torvalds #include <linux/slab.h>
311da177e4SLinus Torvalds #include <linux/in.h>
321da177e4SLinus Torvalds #include <net/sctp/command.h>
331da177e4SLinus Torvalds #include <net/sctp/sctp.h>
341da177e4SLinus Torvalds
351da177e4SLinus Torvalds #ifndef __sctp_sm_h__
361da177e4SLinus Torvalds #define __sctp_sm_h__
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds /*
391da177e4SLinus Torvalds * Possible values for the disposition are:
401da177e4SLinus Torvalds */
41172a1599SXin Long enum sctp_disposition {
421da177e4SLinus Torvalds SCTP_DISPOSITION_DISCARD, /* No further processing. */
431da177e4SLinus Torvalds SCTP_DISPOSITION_CONSUME, /* Process return values normally. */
441da177e4SLinus Torvalds SCTP_DISPOSITION_NOMEM, /* We ran out of memory--recover. */
451da177e4SLinus Torvalds SCTP_DISPOSITION_DELETE_TCB, /* Close the association. */
461da177e4SLinus Torvalds SCTP_DISPOSITION_ABORT, /* Close the association NOW. */
471da177e4SLinus Torvalds SCTP_DISPOSITION_VIOLATION, /* The peer is misbehaving. */
481da177e4SLinus Torvalds SCTP_DISPOSITION_NOT_IMPL, /* This entry is not implemented. */
491da177e4SLinus Torvalds SCTP_DISPOSITION_ERROR, /* This is plain old user error. */
501da177e4SLinus Torvalds SCTP_DISPOSITION_BUG, /* This is a bug. */
51172a1599SXin Long };
521da177e4SLinus Torvalds
53172a1599SXin Long typedef enum sctp_disposition (sctp_state_fn_t) (
54172a1599SXin Long struct net *net,
55172a1599SXin Long const struct sctp_endpoint *ep,
56172a1599SXin Long const struct sctp_association *asoc,
57bfc6f827SXin Long const union sctp_subtype type,
581da177e4SLinus Torvalds void *arg,
59172a1599SXin Long struct sctp_cmd_seq *commands);
609c3b5751SKees Cook typedef void (sctp_timer_event_t) (struct timer_list *);
618ee821aeSXin Long struct sctp_sm_table_entry {
621da177e4SLinus Torvalds sctp_state_fn_t *fn;
631da177e4SLinus Torvalds const char *name;
648ee821aeSXin Long };
651da177e4SLinus Torvalds
661da177e4SLinus Torvalds /* A naming convention of "sctp_sf_xxx" applies to all the state functions
671da177e4SLinus Torvalds * currently in use.
681da177e4SLinus Torvalds */
691da177e4SLinus Torvalds
701da177e4SLinus Torvalds /* Prototypes for generic state functions. */
711da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_not_impl;
721da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_bug;
731da177e4SLinus Torvalds
741da177e4SLinus Torvalds /* Prototypes for gener timer state functions. */
751da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_timer_ignore;
761da177e4SLinus Torvalds
771da177e4SLinus Torvalds /* Prototypes for chunk state functions. */
781da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_9_1_abort;
791da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_cookie_wait_abort;
801da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_cookie_echoed_abort;
811da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_shutdown_pending_abort;
821da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_shutdown_sent_abort;
831da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_shutdown_ack_sent_abort;
841da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_5_1B_init;
851da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_5_1C_ack;
861da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_5_1D_ce;
871da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_5_1E_ca;
881da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_4_C;
891da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_eat_data_6_2;
901da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_eat_data_fast_4_4;
911da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_eat_sack_6_2;
921da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_operr_notify;
933f7a87d2SFrank Filz sctp_state_fn_t sctp_sf_t1_init_timer_expire;
943f7a87d2SFrank Filz sctp_state_fn_t sctp_sf_t1_cookie_timer_expire;
951da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_t2_timer_expire;
961da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_t4_timer_expire;
971da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_t5_timer_expire;
981da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_sendbeat_8_3;
991da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_beat_8_3;
1001da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_backbeat_8_3;
1011da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_9_2_final;
1021da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_9_2_shutdown;
1032e3f92daSWei Yongjun sctp_state_fn_t sctp_sf_do_9_2_shut_ctsn;
1041da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_ecn_cwr;
1051da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_ecne;
1061da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_ootb;
1071da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_pdiscard;
1081da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_violation;
1091da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_discard_chunk;
1101da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_5_2_1_siminit;
1111da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_5_2_2_dupinit;
112610ab73aSVlad Yasevich sctp_state_fn_t sctp_sf_do_5_2_3_initack;
1131da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_5_2_4_dupcook;
1141da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_unk_chunk;
1151da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_8_5_1_E_sa;
1161da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_cookie_echoed_err;
1171da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_asconf;
1181da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_asconf_ack;
1192040d3d7SXin Long sctp_state_fn_t sctp_sf_do_reconf;
1201da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_9_2_reshutack;
1211da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_eat_fwd_tsn;
1221da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_eat_fwd_tsn_fast;
123bbd0d598SVlad Yasevich sctp_state_fn_t sctp_sf_eat_auth;
1241da177e4SLinus Torvalds
1251da177e4SLinus Torvalds /* Prototypes for primitive event state functions. */
1261da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_prm_asoc;
1271da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_prm_send;
1281da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_9_2_prm_shutdown;
1291da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_cookie_wait_prm_shutdown;
1301da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_cookie_echoed_prm_shutdown;
1311da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_9_1_prm_abort;
1321da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_cookie_wait_prm_abort;
1331da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_cookie_echoed_prm_abort;
1341da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_shutdown_pending_prm_abort;
1351da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_shutdown_sent_prm_abort;
1361da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_shutdown_ack_sent_prm_abort;
1371da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_error_closed;
1381da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_error_shutdown;
1391da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_ignore_primitive;
1401da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_prm_requestheartbeat;
1411da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_prm_asconf;
1427a090b04SXin Long sctp_state_fn_t sctp_sf_do_prm_reconf;
1431da177e4SLinus Torvalds
1441da177e4SLinus Torvalds /* Prototypes for other event state functions. */
145e1cdd553SWei Yongjun sctp_state_fn_t sctp_sf_do_no_pending_tsn;
1461da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_9_2_start_shutdown;
1471da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_9_2_shutdown_ack;
1481da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_ignore_other;
1491da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_cookie_wait_icmp_abort;
1501da177e4SLinus Torvalds
1511da177e4SLinus Torvalds /* Prototypes for timeout event state functions. */
1521da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_6_3_3_rtx;
1537b9438deSXin Long sctp_state_fn_t sctp_sf_send_reconf;
15492548ec2SXin Long sctp_state_fn_t sctp_sf_send_probe;
1551da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_do_6_2_sack;
1561da177e4SLinus Torvalds sctp_state_fn_t sctp_sf_autoclose_timer_expire;
1571da177e4SLinus Torvalds
1581da177e4SLinus Torvalds /* Prototypes for utility support functions. */
1598ee821aeSXin Long const struct sctp_sm_table_entry *sctp_sm_lookup_event(
160bfc6f827SXin Long struct net *net,
16188ee48c1SXin Long enum sctp_event_type event_type,
16252106019SXin Long enum sctp_state state,
163bfc6f827SXin Long union sctp_subtype event_subtype);
1641da177e4SLinus Torvalds int sctp_chunk_iif(const struct sctp_chunk *);
1651da177e4SLinus Torvalds struct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *,
1661da177e4SLinus Torvalds struct sctp_chunk *,
167dd0fc66fSAl Viro gfp_t gfp);
1681da177e4SLinus Torvalds
1691da177e4SLinus Torvalds /* Prototypes for chunk-building functions. */
170327c0dabSXin Long struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
171327c0dabSXin Long const struct sctp_bind_addr *bp,
172dd0fc66fSAl Viro gfp_t gfp, int vparam_len);
173327c0dabSXin Long struct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc,
174327c0dabSXin Long const struct sctp_chunk *chunk,
175327c0dabSXin Long const gfp_t gfp, const int unkparam_len);
176327c0dabSXin Long struct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *asoc,
177327c0dabSXin Long const struct sctp_chunk *chunk);
178327c0dabSXin Long struct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *asoc,
179327c0dabSXin Long const struct sctp_chunk *chunk);
180327c0dabSXin Long struct sctp_chunk *sctp_make_cwr(const struct sctp_association *asoc,
1811da177e4SLinus Torvalds const __u32 lowest_tsn,
182327c0dabSXin Long const struct sctp_chunk *chunk);
183ad05a7a0SXin Long struct sctp_chunk *sctp_make_idata(const struct sctp_association *asoc,
184ad05a7a0SXin Long __u8 flags, int paylen, gfp_t gfp);
1852d07a49aSXin Long struct sctp_chunk *sctp_make_ifwdtsn(const struct sctp_association *asoc,
1862d07a49aSXin Long __u32 new_cum_tsn, size_t nstreams,
1872d07a49aSXin Long struct sctp_ifwdtsn_skip *skiplist);
1880c3f6f65SXin Long struct sctp_chunk *sctp_make_datafrag_empty(const struct sctp_association *asoc,
1891da177e4SLinus Torvalds const struct sctp_sndrcvinfo *sinfo,
1900c3f6f65SXin Long int len, __u8 flags, gfp_t gfp);
191327c0dabSXin Long struct sctp_chunk *sctp_make_ecne(const struct sctp_association *asoc,
192327c0dabSXin Long const __u32 lowest_tsn);
19347b3ba51SMarcelo Ricardo Leitner struct sctp_chunk *sctp_make_sack(struct sctp_association *asoc);
1941da177e4SLinus Torvalds struct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc,
1951da177e4SLinus Torvalds const struct sctp_chunk *chunk);
1961da177e4SLinus Torvalds struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc,
197327c0dabSXin Long const struct sctp_chunk *chunk);
198327c0dabSXin Long struct sctp_chunk *sctp_make_shutdown_complete(
199327c0dabSXin Long const struct sctp_association *asoc,
200327c0dabSXin Long const struct sctp_chunk *chunk);
2016d3e8aa8SMarcelo Ricardo Leitner int sctp_init_cause(struct sctp_chunk *chunk, __be16 cause, size_t paylen);
202327c0dabSXin Long struct sctp_chunk *sctp_make_abort(const struct sctp_association *asoc,
203327c0dabSXin Long const struct sctp_chunk *chunk,
2041da177e4SLinus Torvalds const size_t hint);
205327c0dabSXin Long struct sctp_chunk *sctp_make_abort_no_data(const struct sctp_association *asoc,
206327c0dabSXin Long const struct sctp_chunk *chunk,
2071da177e4SLinus Torvalds __u32 tsn);
208327c0dabSXin Long struct sctp_chunk *sctp_make_abort_user(const struct sctp_association *asoc,
209327c0dabSXin Long struct msghdr *msg, size_t msg_len);
210327c0dabSXin Long struct sctp_chunk *sctp_make_abort_violation(
211327c0dabSXin Long const struct sctp_association *asoc,
212327c0dabSXin Long const struct sctp_chunk *chunk,
213327c0dabSXin Long const __u8 *payload,
214327c0dabSXin Long const size_t paylen);
215327c0dabSXin Long struct sctp_chunk *sctp_make_violation_paramlen(
216327c0dabSXin Long const struct sctp_association *asoc,
217327c0dabSXin Long const struct sctp_chunk *chunk,
218327c0dabSXin Long struct sctp_paramhdr *param);
219327c0dabSXin Long struct sctp_chunk *sctp_make_violation_max_retrans(
220327c0dabSXin Long const struct sctp_association *asoc,
221327c0dabSXin Long const struct sctp_chunk *chunk);
222e38d86b3SXin Long struct sctp_chunk *sctp_make_new_encap_port(
223e38d86b3SXin Long const struct sctp_association *asoc,
224e38d86b3SXin Long const struct sctp_chunk *chunk);
225327c0dabSXin Long struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
226fe59379bSXin Long const struct sctp_transport *transport,
227fe59379bSXin Long __u32 probe_size);
228327c0dabSXin Long struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc,
229327c0dabSXin Long const struct sctp_chunk *chunk,
2301da177e4SLinus Torvalds const void *payload,
2311da177e4SLinus Torvalds const size_t paylen);
232745a3211SXin Long struct sctp_chunk *sctp_make_pad(const struct sctp_association *asoc, int len);
233327c0dabSXin Long struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,
2341da177e4SLinus Torvalds const struct sctp_chunk *chunk,
235327c0dabSXin Long __be16 cause_code, const void *payload,
236327c0dabSXin Long size_t paylen, size_t reserve_tail);
2371da177e4SLinus Torvalds
238327c0dabSXin Long struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
239327c0dabSXin Long union sctp_addr *laddr,
240327c0dabSXin Long struct sockaddr *addrs,
241327c0dabSXin Long int addrcnt, __be16 flags);
2421da177e4SLinus Torvalds struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
2431da177e4SLinus Torvalds union sctp_addr *addr);
2449de7922bSDaniel Borkmann bool sctp_verify_asconf(const struct sctp_association *asoc,
2459de7922bSDaniel Borkmann struct sctp_chunk *chunk, bool addr_param_needed,
2466f4c618dSWei Yongjun struct sctp_paramhdr **errp);
2471da177e4SLinus Torvalds struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
2481da177e4SLinus Torvalds struct sctp_chunk *asconf);
2491da177e4SLinus Torvalds int sctp_process_asconf_ack(struct sctp_association *asoc,
2501da177e4SLinus Torvalds struct sctp_chunk *asconf_ack);
2511da177e4SLinus Torvalds struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
2521da177e4SLinus Torvalds __u32 new_cum_tsn, size_t nstreams,
2531da177e4SLinus Torvalds struct sctp_fwdtsn_skip *skiplist);
2541b1e0bc9SXin Long struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc,
2551b1e0bc9SXin Long __u16 key_id);
256327c0dabSXin Long struct sctp_chunk *sctp_make_strreset_req(const struct sctp_association *asoc,
2571da4fc97SXin Long __u16 stream_num, __be16 *stream_list,
258cc16f00fSXin Long bool out, bool in);
259c56480a1SXin Long struct sctp_chunk *sctp_make_strreset_tsnreq(
260c56480a1SXin Long const struct sctp_association *asoc);
26178098117SXin Long struct sctp_chunk *sctp_make_strreset_addstrm(
26278098117SXin Long const struct sctp_association *asoc,
26378098117SXin Long __u16 out, __u16 in);
264327c0dabSXin Long struct sctp_chunk *sctp_make_strreset_resp(const struct sctp_association *asoc,
265bd4b9f8bSXin Long __u32 result, __u32 sn);
266327c0dabSXin Long struct sctp_chunk *sctp_make_strreset_tsnresp(struct sctp_association *asoc,
267bd4b9f8bSXin Long __u32 result, __u32 sn,
268327c0dabSXin Long __u32 sender_tsn,
269327c0dabSXin Long __u32 receiver_tsn);
270ea625043SXin Long bool sctp_verify_reconf(const struct sctp_association *asoc,
271ea625043SXin Long struct sctp_chunk *chunk,
272ea625043SXin Long struct sctp_paramhdr **errp);
273327c0dabSXin Long void sctp_chunk_assign_tsn(struct sctp_chunk *chunk);
274327c0dabSXin Long void sctp_chunk_assign_ssn(struct sctp_chunk *chunk);
2751da177e4SLinus Torvalds
27681054476SXin Long /* Prototypes for stream-processing functions. */
27781054476SXin Long struct sctp_chunk *sctp_process_strreset_outreq(
27881054476SXin Long struct sctp_association *asoc,
27981054476SXin Long union sctp_params param,
28081054476SXin Long struct sctp_ulpevent **evp);
28116e1a919SXin Long struct sctp_chunk *sctp_process_strreset_inreq(
28216e1a919SXin Long struct sctp_association *asoc,
28316e1a919SXin Long union sctp_params param,
28416e1a919SXin Long struct sctp_ulpevent **evp);
285692787ceSXin Long struct sctp_chunk *sctp_process_strreset_tsnreq(
286692787ceSXin Long struct sctp_association *asoc,
287692787ceSXin Long union sctp_params param,
288692787ceSXin Long struct sctp_ulpevent **evp);
28950a41591SXin Long struct sctp_chunk *sctp_process_strreset_addstrm_out(
29050a41591SXin Long struct sctp_association *asoc,
29150a41591SXin Long union sctp_params param,
29250a41591SXin Long struct sctp_ulpevent **evp);
293c5c4ebb3SXin Long struct sctp_chunk *sctp_process_strreset_addstrm_in(
294c5c4ebb3SXin Long struct sctp_association *asoc,
295c5c4ebb3SXin Long union sctp_params param,
296c5c4ebb3SXin Long struct sctp_ulpevent **evp);
29711ae76e6SXin Long struct sctp_chunk *sctp_process_strreset_resp(
29811ae76e6SXin Long struct sctp_association *asoc,
29911ae76e6SXin Long union sctp_params param,
30011ae76e6SXin Long struct sctp_ulpevent **evp);
30181054476SXin Long
3021da177e4SLinus Torvalds /* Prototypes for statetable processing. */
3031da177e4SLinus Torvalds
30488ee48c1SXin Long int sctp_do_sm(struct net *net, enum sctp_event_type event_type,
305bfc6f827SXin Long union sctp_subtype subtype, enum sctp_state state,
30661f0eb07SXin Long struct sctp_endpoint *ep, struct sctp_association *asoc,
30761f0eb07SXin Long void *event_arg, gfp_t gfp);
3081da177e4SLinus Torvalds
3091da177e4SLinus Torvalds /* 2nd level prototypes */
3109c3b5751SKees Cook void sctp_generate_t3_rtx_event(struct timer_list *t);
3119c3b5751SKees Cook void sctp_generate_heartbeat_event(struct timer_list *t);
3129c3b5751SKees Cook void sctp_generate_reconf_event(struct timer_list *t);
31392548ec2SXin Long void sctp_generate_probe_event(struct timer_list *t);
3149c3b5751SKees Cook void sctp_generate_proto_unreach_event(struct timer_list *t);
3151da177e4SLinus Torvalds
31634b4e29bSXin Long void sctp_ootb_pkt_free(struct sctp_packet *packet);
3171da177e4SLinus Torvalds
318327c0dabSXin Long struct sctp_association *sctp_unpack_cookie(
319327c0dabSXin Long const struct sctp_endpoint *ep,
32034b4e29bSXin Long const struct sctp_association *asoc,
32134b4e29bSXin Long struct sctp_chunk *chunk,
322dd0fc66fSAl Viro gfp_t gfp, int *err,
3231da177e4SLinus Torvalds struct sctp_chunk **err_chk_p);
3241da177e4SLinus Torvalds
3251da177e4SLinus Torvalds /* 3rd level prototypes */
32634b4e29bSXin Long __u32 sctp_generate_tag(const struct sctp_endpoint *ep);
32734b4e29bSXin Long __u32 sctp_generate_tsn(const struct sctp_endpoint *ep);
3281da177e4SLinus Torvalds
3291da177e4SLinus Torvalds /* Extern declarations for major data structures. */
3301da177e4SLinus Torvalds extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
3311da177e4SLinus Torvalds
3321da177e4SLinus Torvalds
3331da177e4SLinus Torvalds /* Get the size of a DATA chunk payload. */
sctp_data_size(struct sctp_chunk * chunk)3341da177e4SLinus Torvalds static inline __u16 sctp_data_size(struct sctp_chunk *chunk)
3351da177e4SLinus Torvalds {
3361da177e4SLinus Torvalds __u16 size;
3371da177e4SLinus Torvalds
3381da177e4SLinus Torvalds size = ntohs(chunk->chunk_hdr->length);
3395660b9d9SXin Long size -= sctp_datachk_len(&chunk->asoc->stream);
3401da177e4SLinus Torvalds
3411da177e4SLinus Torvalds return size;
3421da177e4SLinus Torvalds }
3431da177e4SLinus Torvalds
3441da177e4SLinus Torvalds /* Compare two TSNs */
345182691d0SMarcelo Ricardo Leitner #define TSN_lt(a,b) \
346182691d0SMarcelo Ricardo Leitner (typecheck(__u32, a) && \
347182691d0SMarcelo Ricardo Leitner typecheck(__u32, b) && \
348182691d0SMarcelo Ricardo Leitner ((__s32)((a) - (b)) < 0))
3491da177e4SLinus Torvalds
350182691d0SMarcelo Ricardo Leitner #define TSN_lte(a,b) \
351182691d0SMarcelo Ricardo Leitner (typecheck(__u32, a) && \
352182691d0SMarcelo Ricardo Leitner typecheck(__u32, b) && \
353182691d0SMarcelo Ricardo Leitner ((__s32)((a) - (b)) <= 0))
3541da177e4SLinus Torvalds
3559d4ceaf1SXin Long /* Compare two MIDs */
3569d4ceaf1SXin Long #define MID_lt(a, b) \
3579d4ceaf1SXin Long (typecheck(__u32, a) && \
3589d4ceaf1SXin Long typecheck(__u32, b) && \
3599d4ceaf1SXin Long ((__s32)((a) - (b)) < 0))
3609d4ceaf1SXin Long
3611da177e4SLinus Torvalds /* Compare two SSNs */
362182691d0SMarcelo Ricardo Leitner #define SSN_lt(a,b) \
363182691d0SMarcelo Ricardo Leitner (typecheck(__u16, a) && \
364182691d0SMarcelo Ricardo Leitner typecheck(__u16, b) && \
365182691d0SMarcelo Ricardo Leitner ((__s16)((a) - (b)) < 0))
3661da177e4SLinus Torvalds
367182691d0SMarcelo Ricardo Leitner /* ADDIP 3.1.1 */
368182691d0SMarcelo Ricardo Leitner #define ADDIP_SERIAL_gte(a,b) \
369182691d0SMarcelo Ricardo Leitner (typecheck(__u32, a) && \
370182691d0SMarcelo Ricardo Leitner typecheck(__u32, b) && \
371182691d0SMarcelo Ricardo Leitner ((__s32)((b) - (a)) <= 0))
3721da177e4SLinus Torvalds
3731da177e4SLinus Torvalds /* Check VTAG of the packet matches the sender's own tag. */
3741da177e4SLinus Torvalds static inline int
sctp_vtag_verify(const struct sctp_chunk * chunk,const struct sctp_association * asoc)3751da177e4SLinus Torvalds sctp_vtag_verify(const struct sctp_chunk *chunk,
3761da177e4SLinus Torvalds const struct sctp_association *asoc)
3771da177e4SLinus Torvalds {
3781da177e4SLinus Torvalds /* RFC 2960 Sec 8.5 When receiving an SCTP packet, the endpoint
3791da177e4SLinus Torvalds * MUST ensure that the value in the Verification Tag field of
3801da177e4SLinus Torvalds * the received SCTP packet matches its own Tag. If the received
3811da177e4SLinus Torvalds * Verification Tag value does not match the receiver's own
3821da177e4SLinus Torvalds * tag value, the receiver shall silently discard the packet...
3831da177e4SLinus Torvalds */
384*075718fdSXin Long if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
385*075718fdSXin Long return 0;
3861da177e4SLinus Torvalds
387a1dd2cf2SXin Long chunk->transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
388*075718fdSXin Long return 1;
3891da177e4SLinus Torvalds }
3901da177e4SLinus Torvalds
391047a2428SJerome Forissier /* Check VTAG of the packet matches the sender's own tag and the T bit is
392047a2428SJerome Forissier * not set, OR its peer's tag and the T bit is set in the Chunk Flags.
3931da177e4SLinus Torvalds */
3941da177e4SLinus Torvalds static inline int
sctp_vtag_verify_either(const struct sctp_chunk * chunk,const struct sctp_association * asoc)3951da177e4SLinus Torvalds sctp_vtag_verify_either(const struct sctp_chunk *chunk,
3961da177e4SLinus Torvalds const struct sctp_association *asoc)
3971da177e4SLinus Torvalds {
398047a2428SJerome Forissier /* RFC 2960 Section 8.5.1, sctpimpguide Section 2.41
3991da177e4SLinus Torvalds *
400047a2428SJerome Forissier * B) The receiver of a ABORT MUST accept the packet
401047a2428SJerome Forissier * if the Verification Tag field of the packet matches its own tag
402047a2428SJerome Forissier * and the T bit is not set
403047a2428SJerome Forissier * OR
404047a2428SJerome Forissier * it is set to its peer's tag and the T bit is set in the Chunk
405047a2428SJerome Forissier * Flags.
406047a2428SJerome Forissier * Otherwise, the receiver MUST silently discard the packet
4071da177e4SLinus Torvalds * and take no further action.
4081da177e4SLinus Torvalds *
409047a2428SJerome Forissier * C) The receiver of a SHUTDOWN COMPLETE shall accept the packet
410047a2428SJerome Forissier * if the Verification Tag field of the packet matches its own tag
411047a2428SJerome Forissier * and the T bit is not set
412047a2428SJerome Forissier * OR
413047a2428SJerome Forissier * it is set to its peer's tag and the T bit is set in the Chunk
414047a2428SJerome Forissier * Flags.
415047a2428SJerome Forissier * Otherwise, the receiver MUST silently discard the packet
416047a2428SJerome Forissier * and take no further action. An endpoint MUST ignore the
417047a2428SJerome Forissier * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
4181da177e4SLinus Torvalds */
419047a2428SJerome Forissier if ((!sctp_test_T_bit(chunk) &&
420047a2428SJerome Forissier (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)) ||
42152688d6eSWei Yongjun (sctp_test_T_bit(chunk) && asoc->c.peer_vtag &&
422047a2428SJerome Forissier (ntohl(chunk->sctp_hdr->vtag) == asoc->c.peer_vtag))) {
4231da177e4SLinus Torvalds return 1;
4241da177e4SLinus Torvalds }
4251da177e4SLinus Torvalds
4261da177e4SLinus Torvalds return 0;
4271da177e4SLinus Torvalds }
4281da177e4SLinus Torvalds
4291da177e4SLinus Torvalds #endif /* __sctp_sm_h__ */
430