162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* SCTP kernel implementation 362306a36Sopenharmony_ci * (C) Copyright IBM Corp. 2001, 2004 462306a36Sopenharmony_ci * Copyright (c) 1999-2000 Cisco, Inc. 562306a36Sopenharmony_ci * Copyright (c) 1999-2001 Motorola, Inc. 662306a36Sopenharmony_ci * Copyright (c) 2001 Intel Corp. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * This file is part of the SCTP kernel implementation 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * These are definitions needed by the state machine. 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * Please send any bug reports or fixes you make to the 1362306a36Sopenharmony_ci * email addresses: 1462306a36Sopenharmony_ci * lksctp developers <linux-sctp@vger.kernel.org> 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * Written or modified by: 1762306a36Sopenharmony_ci * La Monte H.P. Yarroll <piggy@acm.org> 1862306a36Sopenharmony_ci * Karl Knutson <karl@athena.chicago.il.us> 1962306a36Sopenharmony_ci * Xingang Guo <xingang.guo@intel.com> 2062306a36Sopenharmony_ci * Jon Grimm <jgrimm@us.ibm.com> 2162306a36Sopenharmony_ci * Dajiang Zhang <dajiang.zhang@nokia.com> 2262306a36Sopenharmony_ci * Sridhar Samudrala <sri@us.ibm.com> 2362306a36Sopenharmony_ci * Daisy Chang <daisyc@us.ibm.com> 2462306a36Sopenharmony_ci * Ardelle Fan <ardelle.fan@intel.com> 2562306a36Sopenharmony_ci * Kevin Gao <kevin.gao@intel.com> 2662306a36Sopenharmony_ci */ 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#include <linux/types.h> 2962306a36Sopenharmony_ci#include <linux/compiler.h> 3062306a36Sopenharmony_ci#include <linux/slab.h> 3162306a36Sopenharmony_ci#include <linux/in.h> 3262306a36Sopenharmony_ci#include <net/sctp/command.h> 3362306a36Sopenharmony_ci#include <net/sctp/sctp.h> 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#ifndef __sctp_sm_h__ 3662306a36Sopenharmony_ci#define __sctp_sm_h__ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* 3962306a36Sopenharmony_ci * Possible values for the disposition are: 4062306a36Sopenharmony_ci */ 4162306a36Sopenharmony_cienum sctp_disposition { 4262306a36Sopenharmony_ci SCTP_DISPOSITION_DISCARD, /* No further processing. */ 4362306a36Sopenharmony_ci SCTP_DISPOSITION_CONSUME, /* Process return values normally. */ 4462306a36Sopenharmony_ci SCTP_DISPOSITION_NOMEM, /* We ran out of memory--recover. */ 4562306a36Sopenharmony_ci SCTP_DISPOSITION_DELETE_TCB, /* Close the association. */ 4662306a36Sopenharmony_ci SCTP_DISPOSITION_ABORT, /* Close the association NOW. */ 4762306a36Sopenharmony_ci SCTP_DISPOSITION_VIOLATION, /* The peer is misbehaving. */ 4862306a36Sopenharmony_ci SCTP_DISPOSITION_NOT_IMPL, /* This entry is not implemented. */ 4962306a36Sopenharmony_ci SCTP_DISPOSITION_ERROR, /* This is plain old user error. */ 5062306a36Sopenharmony_ci SCTP_DISPOSITION_BUG, /* This is a bug. */ 5162306a36Sopenharmony_ci}; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_citypedef enum sctp_disposition (sctp_state_fn_t) ( 5462306a36Sopenharmony_ci struct net *net, 5562306a36Sopenharmony_ci const struct sctp_endpoint *ep, 5662306a36Sopenharmony_ci const struct sctp_association *asoc, 5762306a36Sopenharmony_ci const union sctp_subtype type, 5862306a36Sopenharmony_ci void *arg, 5962306a36Sopenharmony_ci struct sctp_cmd_seq *commands); 6062306a36Sopenharmony_citypedef void (sctp_timer_event_t) (struct timer_list *); 6162306a36Sopenharmony_cistruct sctp_sm_table_entry { 6262306a36Sopenharmony_ci sctp_state_fn_t *fn; 6362306a36Sopenharmony_ci const char *name; 6462306a36Sopenharmony_ci}; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* A naming convention of "sctp_sf_xxx" applies to all the state functions 6762306a36Sopenharmony_ci * currently in use. 6862306a36Sopenharmony_ci */ 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci/* Prototypes for generic state functions. */ 7162306a36Sopenharmony_cisctp_state_fn_t sctp_sf_not_impl; 7262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_bug; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci/* Prototypes for gener timer state functions. */ 7562306a36Sopenharmony_cisctp_state_fn_t sctp_sf_timer_ignore; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* Prototypes for chunk state functions. */ 7862306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_1_abort; 7962306a36Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_wait_abort; 8062306a36Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_echoed_abort; 8162306a36Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_pending_abort; 8262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_sent_abort; 8362306a36Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_ack_sent_abort; 8462306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_1B_init; 8562306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_1C_ack; 8662306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_1D_ce; 8762306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_1E_ca; 8862306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_4_C; 8962306a36Sopenharmony_cisctp_state_fn_t sctp_sf_eat_data_6_2; 9062306a36Sopenharmony_cisctp_state_fn_t sctp_sf_eat_data_fast_4_4; 9162306a36Sopenharmony_cisctp_state_fn_t sctp_sf_eat_sack_6_2; 9262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_operr_notify; 9362306a36Sopenharmony_cisctp_state_fn_t sctp_sf_t1_init_timer_expire; 9462306a36Sopenharmony_cisctp_state_fn_t sctp_sf_t1_cookie_timer_expire; 9562306a36Sopenharmony_cisctp_state_fn_t sctp_sf_t2_timer_expire; 9662306a36Sopenharmony_cisctp_state_fn_t sctp_sf_t4_timer_expire; 9762306a36Sopenharmony_cisctp_state_fn_t sctp_sf_t5_timer_expire; 9862306a36Sopenharmony_cisctp_state_fn_t sctp_sf_sendbeat_8_3; 9962306a36Sopenharmony_cisctp_state_fn_t sctp_sf_beat_8_3; 10062306a36Sopenharmony_cisctp_state_fn_t sctp_sf_backbeat_8_3; 10162306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_final; 10262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_shutdown; 10362306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_shut_ctsn; 10462306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_ecn_cwr; 10562306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_ecne; 10662306a36Sopenharmony_cisctp_state_fn_t sctp_sf_ootb; 10762306a36Sopenharmony_cisctp_state_fn_t sctp_sf_pdiscard; 10862306a36Sopenharmony_cisctp_state_fn_t sctp_sf_violation; 10962306a36Sopenharmony_cisctp_state_fn_t sctp_sf_discard_chunk; 11062306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_2_1_siminit; 11162306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_2_2_dupinit; 11262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_2_3_initack; 11362306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_2_4_dupcook; 11462306a36Sopenharmony_cisctp_state_fn_t sctp_sf_unk_chunk; 11562306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_8_5_1_E_sa; 11662306a36Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_echoed_err; 11762306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_asconf; 11862306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_asconf_ack; 11962306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_reconf; 12062306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_reshutack; 12162306a36Sopenharmony_cisctp_state_fn_t sctp_sf_eat_fwd_tsn; 12262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_eat_fwd_tsn_fast; 12362306a36Sopenharmony_cisctp_state_fn_t sctp_sf_eat_auth; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci/* Prototypes for primitive event state functions. */ 12662306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_asoc; 12762306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_send; 12862306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_prm_shutdown; 12962306a36Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_wait_prm_shutdown; 13062306a36Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_echoed_prm_shutdown; 13162306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_1_prm_abort; 13262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_wait_prm_abort; 13362306a36Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_echoed_prm_abort; 13462306a36Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_pending_prm_abort; 13562306a36Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_sent_prm_abort; 13662306a36Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_ack_sent_prm_abort; 13762306a36Sopenharmony_cisctp_state_fn_t sctp_sf_error_closed; 13862306a36Sopenharmony_cisctp_state_fn_t sctp_sf_error_shutdown; 13962306a36Sopenharmony_cisctp_state_fn_t sctp_sf_ignore_primitive; 14062306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_requestheartbeat; 14162306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_asconf; 14262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_reconf; 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci/* Prototypes for other event state functions. */ 14562306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_no_pending_tsn; 14662306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_start_shutdown; 14762306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_shutdown_ack; 14862306a36Sopenharmony_cisctp_state_fn_t sctp_sf_ignore_other; 14962306a36Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_wait_icmp_abort; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci/* Prototypes for timeout event state functions. */ 15262306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_6_3_3_rtx; 15362306a36Sopenharmony_cisctp_state_fn_t sctp_sf_send_reconf; 15462306a36Sopenharmony_cisctp_state_fn_t sctp_sf_send_probe; 15562306a36Sopenharmony_cisctp_state_fn_t sctp_sf_do_6_2_sack; 15662306a36Sopenharmony_cisctp_state_fn_t sctp_sf_autoclose_timer_expire; 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci/* Prototypes for utility support functions. */ 15962306a36Sopenharmony_ciconst struct sctp_sm_table_entry *sctp_sm_lookup_event( 16062306a36Sopenharmony_ci struct net *net, 16162306a36Sopenharmony_ci enum sctp_event_type event_type, 16262306a36Sopenharmony_ci enum sctp_state state, 16362306a36Sopenharmony_ci union sctp_subtype event_subtype); 16462306a36Sopenharmony_ciint sctp_chunk_iif(const struct sctp_chunk *); 16562306a36Sopenharmony_cistruct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *, 16662306a36Sopenharmony_ci struct sctp_chunk *, 16762306a36Sopenharmony_ci gfp_t gfp); 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci/* Prototypes for chunk-building functions. */ 17062306a36Sopenharmony_cistruct sctp_chunk *sctp_make_init(const struct sctp_association *asoc, 17162306a36Sopenharmony_ci const struct sctp_bind_addr *bp, 17262306a36Sopenharmony_ci gfp_t gfp, int vparam_len); 17362306a36Sopenharmony_cistruct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc, 17462306a36Sopenharmony_ci const struct sctp_chunk *chunk, 17562306a36Sopenharmony_ci const gfp_t gfp, const int unkparam_len); 17662306a36Sopenharmony_cistruct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *asoc, 17762306a36Sopenharmony_ci const struct sctp_chunk *chunk); 17862306a36Sopenharmony_cistruct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *asoc, 17962306a36Sopenharmony_ci const struct sctp_chunk *chunk); 18062306a36Sopenharmony_cistruct sctp_chunk *sctp_make_cwr(const struct sctp_association *asoc, 18162306a36Sopenharmony_ci const __u32 lowest_tsn, 18262306a36Sopenharmony_ci const struct sctp_chunk *chunk); 18362306a36Sopenharmony_cistruct sctp_chunk *sctp_make_idata(const struct sctp_association *asoc, 18462306a36Sopenharmony_ci __u8 flags, int paylen, gfp_t gfp); 18562306a36Sopenharmony_cistruct sctp_chunk *sctp_make_ifwdtsn(const struct sctp_association *asoc, 18662306a36Sopenharmony_ci __u32 new_cum_tsn, size_t nstreams, 18762306a36Sopenharmony_ci struct sctp_ifwdtsn_skip *skiplist); 18862306a36Sopenharmony_cistruct sctp_chunk *sctp_make_datafrag_empty(const struct sctp_association *asoc, 18962306a36Sopenharmony_ci const struct sctp_sndrcvinfo *sinfo, 19062306a36Sopenharmony_ci int len, __u8 flags, gfp_t gfp); 19162306a36Sopenharmony_cistruct sctp_chunk *sctp_make_ecne(const struct sctp_association *asoc, 19262306a36Sopenharmony_ci const __u32 lowest_tsn); 19362306a36Sopenharmony_cistruct sctp_chunk *sctp_make_sack(struct sctp_association *asoc); 19462306a36Sopenharmony_cistruct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc, 19562306a36Sopenharmony_ci const struct sctp_chunk *chunk); 19662306a36Sopenharmony_cistruct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc, 19762306a36Sopenharmony_ci const struct sctp_chunk *chunk); 19862306a36Sopenharmony_cistruct sctp_chunk *sctp_make_shutdown_complete( 19962306a36Sopenharmony_ci const struct sctp_association *asoc, 20062306a36Sopenharmony_ci const struct sctp_chunk *chunk); 20162306a36Sopenharmony_ciint sctp_init_cause(struct sctp_chunk *chunk, __be16 cause, size_t paylen); 20262306a36Sopenharmony_cistruct sctp_chunk *sctp_make_abort(const struct sctp_association *asoc, 20362306a36Sopenharmony_ci const struct sctp_chunk *chunk, 20462306a36Sopenharmony_ci const size_t hint); 20562306a36Sopenharmony_cistruct sctp_chunk *sctp_make_abort_no_data(const struct sctp_association *asoc, 20662306a36Sopenharmony_ci const struct sctp_chunk *chunk, 20762306a36Sopenharmony_ci __u32 tsn); 20862306a36Sopenharmony_cistruct sctp_chunk *sctp_make_abort_user(const struct sctp_association *asoc, 20962306a36Sopenharmony_ci struct msghdr *msg, size_t msg_len); 21062306a36Sopenharmony_cistruct sctp_chunk *sctp_make_abort_violation( 21162306a36Sopenharmony_ci const struct sctp_association *asoc, 21262306a36Sopenharmony_ci const struct sctp_chunk *chunk, 21362306a36Sopenharmony_ci const __u8 *payload, 21462306a36Sopenharmony_ci const size_t paylen); 21562306a36Sopenharmony_cistruct sctp_chunk *sctp_make_violation_paramlen( 21662306a36Sopenharmony_ci const struct sctp_association *asoc, 21762306a36Sopenharmony_ci const struct sctp_chunk *chunk, 21862306a36Sopenharmony_ci struct sctp_paramhdr *param); 21962306a36Sopenharmony_cistruct sctp_chunk *sctp_make_violation_max_retrans( 22062306a36Sopenharmony_ci const struct sctp_association *asoc, 22162306a36Sopenharmony_ci const struct sctp_chunk *chunk); 22262306a36Sopenharmony_cistruct sctp_chunk *sctp_make_new_encap_port( 22362306a36Sopenharmony_ci const struct sctp_association *asoc, 22462306a36Sopenharmony_ci const struct sctp_chunk *chunk); 22562306a36Sopenharmony_cistruct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc, 22662306a36Sopenharmony_ci const struct sctp_transport *transport, 22762306a36Sopenharmony_ci __u32 probe_size); 22862306a36Sopenharmony_cistruct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc, 22962306a36Sopenharmony_ci const struct sctp_chunk *chunk, 23062306a36Sopenharmony_ci const void *payload, 23162306a36Sopenharmony_ci const size_t paylen); 23262306a36Sopenharmony_cistruct sctp_chunk *sctp_make_pad(const struct sctp_association *asoc, int len); 23362306a36Sopenharmony_cistruct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc, 23462306a36Sopenharmony_ci const struct sctp_chunk *chunk, 23562306a36Sopenharmony_ci __be16 cause_code, const void *payload, 23662306a36Sopenharmony_ci size_t paylen, size_t reserve_tail); 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_cistruct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc, 23962306a36Sopenharmony_ci union sctp_addr *laddr, 24062306a36Sopenharmony_ci struct sockaddr *addrs, 24162306a36Sopenharmony_ci int addrcnt, __be16 flags); 24262306a36Sopenharmony_cistruct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc, 24362306a36Sopenharmony_ci union sctp_addr *addr); 24462306a36Sopenharmony_cibool sctp_verify_asconf(const struct sctp_association *asoc, 24562306a36Sopenharmony_ci struct sctp_chunk *chunk, bool addr_param_needed, 24662306a36Sopenharmony_ci struct sctp_paramhdr **errp); 24762306a36Sopenharmony_cistruct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc, 24862306a36Sopenharmony_ci struct sctp_chunk *asconf); 24962306a36Sopenharmony_ciint sctp_process_asconf_ack(struct sctp_association *asoc, 25062306a36Sopenharmony_ci struct sctp_chunk *asconf_ack); 25162306a36Sopenharmony_cistruct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc, 25262306a36Sopenharmony_ci __u32 new_cum_tsn, size_t nstreams, 25362306a36Sopenharmony_ci struct sctp_fwdtsn_skip *skiplist); 25462306a36Sopenharmony_cistruct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc, 25562306a36Sopenharmony_ci __u16 key_id); 25662306a36Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_req(const struct sctp_association *asoc, 25762306a36Sopenharmony_ci __u16 stream_num, __be16 *stream_list, 25862306a36Sopenharmony_ci bool out, bool in); 25962306a36Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_tsnreq( 26062306a36Sopenharmony_ci const struct sctp_association *asoc); 26162306a36Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_addstrm( 26262306a36Sopenharmony_ci const struct sctp_association *asoc, 26362306a36Sopenharmony_ci __u16 out, __u16 in); 26462306a36Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_resp(const struct sctp_association *asoc, 26562306a36Sopenharmony_ci __u32 result, __u32 sn); 26662306a36Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_tsnresp(struct sctp_association *asoc, 26762306a36Sopenharmony_ci __u32 result, __u32 sn, 26862306a36Sopenharmony_ci __u32 sender_tsn, 26962306a36Sopenharmony_ci __u32 receiver_tsn); 27062306a36Sopenharmony_cibool sctp_verify_reconf(const struct sctp_association *asoc, 27162306a36Sopenharmony_ci struct sctp_chunk *chunk, 27262306a36Sopenharmony_ci struct sctp_paramhdr **errp); 27362306a36Sopenharmony_civoid sctp_chunk_assign_tsn(struct sctp_chunk *chunk); 27462306a36Sopenharmony_civoid sctp_chunk_assign_ssn(struct sctp_chunk *chunk); 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci/* Prototypes for stream-processing functions. */ 27762306a36Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_outreq( 27862306a36Sopenharmony_ci struct sctp_association *asoc, 27962306a36Sopenharmony_ci union sctp_params param, 28062306a36Sopenharmony_ci struct sctp_ulpevent **evp); 28162306a36Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_inreq( 28262306a36Sopenharmony_ci struct sctp_association *asoc, 28362306a36Sopenharmony_ci union sctp_params param, 28462306a36Sopenharmony_ci struct sctp_ulpevent **evp); 28562306a36Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_tsnreq( 28662306a36Sopenharmony_ci struct sctp_association *asoc, 28762306a36Sopenharmony_ci union sctp_params param, 28862306a36Sopenharmony_ci struct sctp_ulpevent **evp); 28962306a36Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_addstrm_out( 29062306a36Sopenharmony_ci struct sctp_association *asoc, 29162306a36Sopenharmony_ci union sctp_params param, 29262306a36Sopenharmony_ci struct sctp_ulpevent **evp); 29362306a36Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_addstrm_in( 29462306a36Sopenharmony_ci struct sctp_association *asoc, 29562306a36Sopenharmony_ci union sctp_params param, 29662306a36Sopenharmony_ci struct sctp_ulpevent **evp); 29762306a36Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_resp( 29862306a36Sopenharmony_ci struct sctp_association *asoc, 29962306a36Sopenharmony_ci union sctp_params param, 30062306a36Sopenharmony_ci struct sctp_ulpevent **evp); 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci/* Prototypes for statetable processing. */ 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ciint sctp_do_sm(struct net *net, enum sctp_event_type event_type, 30562306a36Sopenharmony_ci union sctp_subtype subtype, enum sctp_state state, 30662306a36Sopenharmony_ci struct sctp_endpoint *ep, struct sctp_association *asoc, 30762306a36Sopenharmony_ci void *event_arg, gfp_t gfp); 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci/* 2nd level prototypes */ 31062306a36Sopenharmony_civoid sctp_generate_t3_rtx_event(struct timer_list *t); 31162306a36Sopenharmony_civoid sctp_generate_heartbeat_event(struct timer_list *t); 31262306a36Sopenharmony_civoid sctp_generate_reconf_event(struct timer_list *t); 31362306a36Sopenharmony_civoid sctp_generate_probe_event(struct timer_list *t); 31462306a36Sopenharmony_civoid sctp_generate_proto_unreach_event(struct timer_list *t); 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_civoid sctp_ootb_pkt_free(struct sctp_packet *packet); 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_cistruct sctp_association *sctp_unpack_cookie( 31962306a36Sopenharmony_ci const struct sctp_endpoint *ep, 32062306a36Sopenharmony_ci const struct sctp_association *asoc, 32162306a36Sopenharmony_ci struct sctp_chunk *chunk, 32262306a36Sopenharmony_ci gfp_t gfp, int *err, 32362306a36Sopenharmony_ci struct sctp_chunk **err_chk_p); 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci/* 3rd level prototypes */ 32662306a36Sopenharmony_ci__u32 sctp_generate_tag(const struct sctp_endpoint *ep); 32762306a36Sopenharmony_ci__u32 sctp_generate_tsn(const struct sctp_endpoint *ep); 32862306a36Sopenharmony_ci 32962306a36Sopenharmony_ci/* Extern declarations for major data structures. */ 33062306a36Sopenharmony_ciextern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES]; 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci 33362306a36Sopenharmony_ci/* Get the size of a DATA chunk payload. */ 33462306a36Sopenharmony_cistatic inline __u16 sctp_data_size(struct sctp_chunk *chunk) 33562306a36Sopenharmony_ci{ 33662306a36Sopenharmony_ci __u16 size; 33762306a36Sopenharmony_ci 33862306a36Sopenharmony_ci size = ntohs(chunk->chunk_hdr->length); 33962306a36Sopenharmony_ci size -= sctp_datachk_len(&chunk->asoc->stream); 34062306a36Sopenharmony_ci 34162306a36Sopenharmony_ci return size; 34262306a36Sopenharmony_ci} 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ci/* Compare two TSNs */ 34562306a36Sopenharmony_ci#define TSN_lt(a,b) \ 34662306a36Sopenharmony_ci (typecheck(__u32, a) && \ 34762306a36Sopenharmony_ci typecheck(__u32, b) && \ 34862306a36Sopenharmony_ci ((__s32)((a) - (b)) < 0)) 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ci#define TSN_lte(a,b) \ 35162306a36Sopenharmony_ci (typecheck(__u32, a) && \ 35262306a36Sopenharmony_ci typecheck(__u32, b) && \ 35362306a36Sopenharmony_ci ((__s32)((a) - (b)) <= 0)) 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ci/* Compare two MIDs */ 35662306a36Sopenharmony_ci#define MID_lt(a, b) \ 35762306a36Sopenharmony_ci (typecheck(__u32, a) && \ 35862306a36Sopenharmony_ci typecheck(__u32, b) && \ 35962306a36Sopenharmony_ci ((__s32)((a) - (b)) < 0)) 36062306a36Sopenharmony_ci 36162306a36Sopenharmony_ci/* Compare two SSNs */ 36262306a36Sopenharmony_ci#define SSN_lt(a,b) \ 36362306a36Sopenharmony_ci (typecheck(__u16, a) && \ 36462306a36Sopenharmony_ci typecheck(__u16, b) && \ 36562306a36Sopenharmony_ci ((__s16)((a) - (b)) < 0)) 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci/* ADDIP 3.1.1 */ 36862306a36Sopenharmony_ci#define ADDIP_SERIAL_gte(a,b) \ 36962306a36Sopenharmony_ci (typecheck(__u32, a) && \ 37062306a36Sopenharmony_ci typecheck(__u32, b) && \ 37162306a36Sopenharmony_ci ((__s32)((b) - (a)) <= 0)) 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ci/* Check VTAG of the packet matches the sender's own tag. */ 37462306a36Sopenharmony_cistatic inline int 37562306a36Sopenharmony_cisctp_vtag_verify(const struct sctp_chunk *chunk, 37662306a36Sopenharmony_ci const struct sctp_association *asoc) 37762306a36Sopenharmony_ci{ 37862306a36Sopenharmony_ci /* RFC 2960 Sec 8.5 When receiving an SCTP packet, the endpoint 37962306a36Sopenharmony_ci * MUST ensure that the value in the Verification Tag field of 38062306a36Sopenharmony_ci * the received SCTP packet matches its own Tag. If the received 38162306a36Sopenharmony_ci * Verification Tag value does not match the receiver's own 38262306a36Sopenharmony_ci * tag value, the receiver shall silently discard the packet... 38362306a36Sopenharmony_ci */ 38462306a36Sopenharmony_ci if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) 38562306a36Sopenharmony_ci return 0; 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci chunk->transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port; 38862306a36Sopenharmony_ci return 1; 38962306a36Sopenharmony_ci} 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_ci/* Check VTAG of the packet matches the sender's own tag and the T bit is 39262306a36Sopenharmony_ci * not set, OR its peer's tag and the T bit is set in the Chunk Flags. 39362306a36Sopenharmony_ci */ 39462306a36Sopenharmony_cistatic inline int 39562306a36Sopenharmony_cisctp_vtag_verify_either(const struct sctp_chunk *chunk, 39662306a36Sopenharmony_ci const struct sctp_association *asoc) 39762306a36Sopenharmony_ci{ 39862306a36Sopenharmony_ci /* RFC 2960 Section 8.5.1, sctpimpguide Section 2.41 39962306a36Sopenharmony_ci * 40062306a36Sopenharmony_ci * B) The receiver of a ABORT MUST accept the packet 40162306a36Sopenharmony_ci * if the Verification Tag field of the packet matches its own tag 40262306a36Sopenharmony_ci * and the T bit is not set 40362306a36Sopenharmony_ci * OR 40462306a36Sopenharmony_ci * it is set to its peer's tag and the T bit is set in the Chunk 40562306a36Sopenharmony_ci * Flags. 40662306a36Sopenharmony_ci * Otherwise, the receiver MUST silently discard the packet 40762306a36Sopenharmony_ci * and take no further action. 40862306a36Sopenharmony_ci * 40962306a36Sopenharmony_ci * C) The receiver of a SHUTDOWN COMPLETE shall accept the packet 41062306a36Sopenharmony_ci * if the Verification Tag field of the packet matches its own tag 41162306a36Sopenharmony_ci * and the T bit is not set 41262306a36Sopenharmony_ci * OR 41362306a36Sopenharmony_ci * it is set to its peer's tag and the T bit is set in the Chunk 41462306a36Sopenharmony_ci * Flags. 41562306a36Sopenharmony_ci * Otherwise, the receiver MUST silently discard the packet 41662306a36Sopenharmony_ci * and take no further action. An endpoint MUST ignore the 41762306a36Sopenharmony_ci * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state. 41862306a36Sopenharmony_ci */ 41962306a36Sopenharmony_ci if ((!sctp_test_T_bit(chunk) && 42062306a36Sopenharmony_ci (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)) || 42162306a36Sopenharmony_ci (sctp_test_T_bit(chunk) && asoc->c.peer_vtag && 42262306a36Sopenharmony_ci (ntohl(chunk->sctp_hdr->vtag) == asoc->c.peer_vtag))) { 42362306a36Sopenharmony_ci return 1; 42462306a36Sopenharmony_ci } 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_ci return 0; 42762306a36Sopenharmony_ci} 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci#endif /* __sctp_sm_h__ */ 430