18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* SCTP kernel implementation 38c2ecf20Sopenharmony_ci * (C) Copyright IBM Corp. 2001, 2004 48c2ecf20Sopenharmony_ci * Copyright (c) 1999-2000 Cisco, Inc. 58c2ecf20Sopenharmony_ci * Copyright (c) 1999-2001 Motorola, Inc. 68c2ecf20Sopenharmony_ci * Copyright (c) 2001 Intel Corp. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * This file is part of the SCTP kernel implementation 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * These are definitions needed by the state machine. 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Please send any bug reports or fixes you make to the 138c2ecf20Sopenharmony_ci * email addresses: 148c2ecf20Sopenharmony_ci * lksctp developers <linux-sctp@vger.kernel.org> 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * Written or modified by: 178c2ecf20Sopenharmony_ci * La Monte H.P. Yarroll <piggy@acm.org> 188c2ecf20Sopenharmony_ci * Karl Knutson <karl@athena.chicago.il.us> 198c2ecf20Sopenharmony_ci * Xingang Guo <xingang.guo@intel.com> 208c2ecf20Sopenharmony_ci * Jon Grimm <jgrimm@us.ibm.com> 218c2ecf20Sopenharmony_ci * Dajiang Zhang <dajiang.zhang@nokia.com> 228c2ecf20Sopenharmony_ci * Sridhar Samudrala <sri@us.ibm.com> 238c2ecf20Sopenharmony_ci * Daisy Chang <daisyc@us.ibm.com> 248c2ecf20Sopenharmony_ci * Ardelle Fan <ardelle.fan@intel.com> 258c2ecf20Sopenharmony_ci * Kevin Gao <kevin.gao@intel.com> 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include <linux/types.h> 298c2ecf20Sopenharmony_ci#include <linux/compiler.h> 308c2ecf20Sopenharmony_ci#include <linux/slab.h> 318c2ecf20Sopenharmony_ci#include <linux/in.h> 328c2ecf20Sopenharmony_ci#include <net/sctp/command.h> 338c2ecf20Sopenharmony_ci#include <net/sctp/sctp.h> 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#ifndef __sctp_sm_h__ 368c2ecf20Sopenharmony_ci#define __sctp_sm_h__ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* 398c2ecf20Sopenharmony_ci * Possible values for the disposition are: 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_cienum sctp_disposition { 428c2ecf20Sopenharmony_ci SCTP_DISPOSITION_DISCARD, /* No further processing. */ 438c2ecf20Sopenharmony_ci SCTP_DISPOSITION_CONSUME, /* Process return values normally. */ 448c2ecf20Sopenharmony_ci SCTP_DISPOSITION_NOMEM, /* We ran out of memory--recover. */ 458c2ecf20Sopenharmony_ci SCTP_DISPOSITION_DELETE_TCB, /* Close the association. */ 468c2ecf20Sopenharmony_ci SCTP_DISPOSITION_ABORT, /* Close the association NOW. */ 478c2ecf20Sopenharmony_ci SCTP_DISPOSITION_VIOLATION, /* The peer is misbehaving. */ 488c2ecf20Sopenharmony_ci SCTP_DISPOSITION_NOT_IMPL, /* This entry is not implemented. */ 498c2ecf20Sopenharmony_ci SCTP_DISPOSITION_ERROR, /* This is plain old user error. */ 508c2ecf20Sopenharmony_ci SCTP_DISPOSITION_BUG, /* This is a bug. */ 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_citypedef enum sctp_disposition (sctp_state_fn_t) ( 548c2ecf20Sopenharmony_ci struct net *net, 558c2ecf20Sopenharmony_ci const struct sctp_endpoint *ep, 568c2ecf20Sopenharmony_ci const struct sctp_association *asoc, 578c2ecf20Sopenharmony_ci const union sctp_subtype type, 588c2ecf20Sopenharmony_ci void *arg, 598c2ecf20Sopenharmony_ci struct sctp_cmd_seq *commands); 608c2ecf20Sopenharmony_citypedef void (sctp_timer_event_t) (struct timer_list *); 618c2ecf20Sopenharmony_cistruct sctp_sm_table_entry { 628c2ecf20Sopenharmony_ci sctp_state_fn_t *fn; 638c2ecf20Sopenharmony_ci const char *name; 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* A naming convention of "sctp_sf_xxx" applies to all the state functions 678c2ecf20Sopenharmony_ci * currently in use. 688c2ecf20Sopenharmony_ci */ 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* Prototypes for generic state functions. */ 718c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_not_impl; 728c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_bug; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* Prototypes for gener timer state functions. */ 758c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_timer_ignore; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* Prototypes for chunk state functions. */ 788c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_1_abort; 798c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_wait_abort; 808c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_echoed_abort; 818c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_pending_abort; 828c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_sent_abort; 838c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_ack_sent_abort; 848c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_1B_init; 858c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_1C_ack; 868c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_1D_ce; 878c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_1E_ca; 888c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_4_C; 898c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_eat_data_6_2; 908c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_eat_data_fast_4_4; 918c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_eat_sack_6_2; 928c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_operr_notify; 938c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_t1_init_timer_expire; 948c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_t1_cookie_timer_expire; 958c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_t2_timer_expire; 968c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_t4_timer_expire; 978c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_t5_timer_expire; 988c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_sendbeat_8_3; 998c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_beat_8_3; 1008c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_backbeat_8_3; 1018c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_final; 1028c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_shutdown; 1038c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_shut_ctsn; 1048c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_ecn_cwr; 1058c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_ecne; 1068c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_ootb; 1078c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_pdiscard; 1088c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_violation; 1098c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_discard_chunk; 1108c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_2_1_siminit; 1118c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_2_2_dupinit; 1128c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_2_3_initack; 1138c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_5_2_4_dupcook; 1148c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_unk_chunk; 1158c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_8_5_1_E_sa; 1168c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_echoed_err; 1178c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_asconf; 1188c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_asconf_ack; 1198c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_reconf; 1208c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_reshutack; 1218c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_eat_fwd_tsn; 1228c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_eat_fwd_tsn_fast; 1238c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_eat_auth; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* Prototypes for primitive event state functions. */ 1268c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_asoc; 1278c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_send; 1288c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_prm_shutdown; 1298c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_wait_prm_shutdown; 1308c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_echoed_prm_shutdown; 1318c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_1_prm_abort; 1328c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_wait_prm_abort; 1338c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_echoed_prm_abort; 1348c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_pending_prm_abort; 1358c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_sent_prm_abort; 1368c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_shutdown_ack_sent_prm_abort; 1378c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_error_closed; 1388c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_error_shutdown; 1398c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_ignore_primitive; 1408c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_requestheartbeat; 1418c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_asconf; 1428c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_prm_reconf; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/* Prototypes for other event state functions. */ 1458c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_no_pending_tsn; 1468c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_start_shutdown; 1478c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_9_2_shutdown_ack; 1488c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_ignore_other; 1498c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_cookie_wait_icmp_abort; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci/* Prototypes for timeout event state functions. */ 1528c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_6_3_3_rtx; 1538c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_send_reconf; 1548c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_do_6_2_sack; 1558c2ecf20Sopenharmony_cisctp_state_fn_t sctp_sf_autoclose_timer_expire; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci/* Prototypes for utility support functions. */ 1588c2ecf20Sopenharmony_ci__u8 sctp_get_chunk_type(struct sctp_chunk *chunk); 1598c2ecf20Sopenharmony_ciconst struct sctp_sm_table_entry *sctp_sm_lookup_event( 1608c2ecf20Sopenharmony_ci struct net *net, 1618c2ecf20Sopenharmony_ci enum sctp_event_type event_type, 1628c2ecf20Sopenharmony_ci enum sctp_state state, 1638c2ecf20Sopenharmony_ci union sctp_subtype event_subtype); 1648c2ecf20Sopenharmony_ciint sctp_chunk_iif(const struct sctp_chunk *); 1658c2ecf20Sopenharmony_cistruct sctp_association *sctp_make_temp_asoc(const struct sctp_endpoint *, 1668c2ecf20Sopenharmony_ci struct sctp_chunk *, 1678c2ecf20Sopenharmony_ci gfp_t gfp); 1688c2ecf20Sopenharmony_ci__u32 sctp_generate_verification_tag(void); 1698c2ecf20Sopenharmony_civoid sctp_populate_tie_tags(__u8 *cookie, __u32 curTag, __u32 hisTag); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci/* Prototypes for chunk-building functions. */ 1728c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_init(const struct sctp_association *asoc, 1738c2ecf20Sopenharmony_ci const struct sctp_bind_addr *bp, 1748c2ecf20Sopenharmony_ci gfp_t gfp, int vparam_len); 1758c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_init_ack(const struct sctp_association *asoc, 1768c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk, 1778c2ecf20Sopenharmony_ci const gfp_t gfp, const int unkparam_len); 1788c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_cookie_echo(const struct sctp_association *asoc, 1798c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk); 1808c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_cookie_ack(const struct sctp_association *asoc, 1818c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk); 1828c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_cwr(const struct sctp_association *asoc, 1838c2ecf20Sopenharmony_ci const __u32 lowest_tsn, 1848c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk); 1858c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_idata(const struct sctp_association *asoc, 1868c2ecf20Sopenharmony_ci __u8 flags, int paylen, gfp_t gfp); 1878c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_ifwdtsn(const struct sctp_association *asoc, 1888c2ecf20Sopenharmony_ci __u32 new_cum_tsn, size_t nstreams, 1898c2ecf20Sopenharmony_ci struct sctp_ifwdtsn_skip *skiplist); 1908c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_datafrag_empty(const struct sctp_association *asoc, 1918c2ecf20Sopenharmony_ci const struct sctp_sndrcvinfo *sinfo, 1928c2ecf20Sopenharmony_ci int len, __u8 flags, gfp_t gfp); 1938c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_ecne(const struct sctp_association *asoc, 1948c2ecf20Sopenharmony_ci const __u32 lowest_tsn); 1958c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_sack(struct sctp_association *asoc); 1968c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_shutdown(const struct sctp_association *asoc, 1978c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk); 1988c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc, 1998c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk); 2008c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_shutdown_complete( 2018c2ecf20Sopenharmony_ci const struct sctp_association *asoc, 2028c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk); 2038c2ecf20Sopenharmony_ciint sctp_init_cause(struct sctp_chunk *chunk, __be16 cause, size_t paylen); 2048c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_abort(const struct sctp_association *asoc, 2058c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk, 2068c2ecf20Sopenharmony_ci const size_t hint); 2078c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_abort_no_data(const struct sctp_association *asoc, 2088c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk, 2098c2ecf20Sopenharmony_ci __u32 tsn); 2108c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_abort_user(const struct sctp_association *asoc, 2118c2ecf20Sopenharmony_ci struct msghdr *msg, size_t msg_len); 2128c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_abort_violation( 2138c2ecf20Sopenharmony_ci const struct sctp_association *asoc, 2148c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk, 2158c2ecf20Sopenharmony_ci const __u8 *payload, 2168c2ecf20Sopenharmony_ci const size_t paylen); 2178c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_violation_paramlen( 2188c2ecf20Sopenharmony_ci const struct sctp_association *asoc, 2198c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk, 2208c2ecf20Sopenharmony_ci struct sctp_paramhdr *param); 2218c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_violation_max_retrans( 2228c2ecf20Sopenharmony_ci const struct sctp_association *asoc, 2238c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk); 2248c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc, 2258c2ecf20Sopenharmony_ci const struct sctp_transport *transport); 2268c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc, 2278c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk, 2288c2ecf20Sopenharmony_ci const void *payload, 2298c2ecf20Sopenharmony_ci const size_t paylen); 2308c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc, 2318c2ecf20Sopenharmony_ci const struct sctp_chunk *chunk, 2328c2ecf20Sopenharmony_ci __be16 cause_code, const void *payload, 2338c2ecf20Sopenharmony_ci size_t paylen, size_t reserve_tail); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc, 2368c2ecf20Sopenharmony_ci union sctp_addr *laddr, 2378c2ecf20Sopenharmony_ci struct sockaddr *addrs, 2388c2ecf20Sopenharmony_ci int addrcnt, __be16 flags); 2398c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc, 2408c2ecf20Sopenharmony_ci union sctp_addr *addr); 2418c2ecf20Sopenharmony_cibool sctp_verify_asconf(const struct sctp_association *asoc, 2428c2ecf20Sopenharmony_ci struct sctp_chunk *chunk, bool addr_param_needed, 2438c2ecf20Sopenharmony_ci struct sctp_paramhdr **errp); 2448c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc, 2458c2ecf20Sopenharmony_ci struct sctp_chunk *asconf); 2468c2ecf20Sopenharmony_ciint sctp_process_asconf_ack(struct sctp_association *asoc, 2478c2ecf20Sopenharmony_ci struct sctp_chunk *asconf_ack); 2488c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc, 2498c2ecf20Sopenharmony_ci __u32 new_cum_tsn, size_t nstreams, 2508c2ecf20Sopenharmony_ci struct sctp_fwdtsn_skip *skiplist); 2518c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc, 2528c2ecf20Sopenharmony_ci __u16 key_id); 2538c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_req(const struct sctp_association *asoc, 2548c2ecf20Sopenharmony_ci __u16 stream_num, __be16 *stream_list, 2558c2ecf20Sopenharmony_ci bool out, bool in); 2568c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_tsnreq( 2578c2ecf20Sopenharmony_ci const struct sctp_association *asoc); 2588c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_addstrm( 2598c2ecf20Sopenharmony_ci const struct sctp_association *asoc, 2608c2ecf20Sopenharmony_ci __u16 out, __u16 in); 2618c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_resp(const struct sctp_association *asoc, 2628c2ecf20Sopenharmony_ci __u32 result, __u32 sn); 2638c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_make_strreset_tsnresp(struct sctp_association *asoc, 2648c2ecf20Sopenharmony_ci __u32 result, __u32 sn, 2658c2ecf20Sopenharmony_ci __u32 sender_tsn, 2668c2ecf20Sopenharmony_ci __u32 receiver_tsn); 2678c2ecf20Sopenharmony_cibool sctp_verify_reconf(const struct sctp_association *asoc, 2688c2ecf20Sopenharmony_ci struct sctp_chunk *chunk, 2698c2ecf20Sopenharmony_ci struct sctp_paramhdr **errp); 2708c2ecf20Sopenharmony_civoid sctp_chunk_assign_tsn(struct sctp_chunk *chunk); 2718c2ecf20Sopenharmony_civoid sctp_chunk_assign_ssn(struct sctp_chunk *chunk); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci/* Prototypes for stream-processing functions. */ 2748c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_outreq( 2758c2ecf20Sopenharmony_ci struct sctp_association *asoc, 2768c2ecf20Sopenharmony_ci union sctp_params param, 2778c2ecf20Sopenharmony_ci struct sctp_ulpevent **evp); 2788c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_inreq( 2798c2ecf20Sopenharmony_ci struct sctp_association *asoc, 2808c2ecf20Sopenharmony_ci union sctp_params param, 2818c2ecf20Sopenharmony_ci struct sctp_ulpevent **evp); 2828c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_tsnreq( 2838c2ecf20Sopenharmony_ci struct sctp_association *asoc, 2848c2ecf20Sopenharmony_ci union sctp_params param, 2858c2ecf20Sopenharmony_ci struct sctp_ulpevent **evp); 2868c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_addstrm_out( 2878c2ecf20Sopenharmony_ci struct sctp_association *asoc, 2888c2ecf20Sopenharmony_ci union sctp_params param, 2898c2ecf20Sopenharmony_ci struct sctp_ulpevent **evp); 2908c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_addstrm_in( 2918c2ecf20Sopenharmony_ci struct sctp_association *asoc, 2928c2ecf20Sopenharmony_ci union sctp_params param, 2938c2ecf20Sopenharmony_ci struct sctp_ulpevent **evp); 2948c2ecf20Sopenharmony_cistruct sctp_chunk *sctp_process_strreset_resp( 2958c2ecf20Sopenharmony_ci struct sctp_association *asoc, 2968c2ecf20Sopenharmony_ci union sctp_params param, 2978c2ecf20Sopenharmony_ci struct sctp_ulpevent **evp); 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci/* Prototypes for statetable processing. */ 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ciint sctp_do_sm(struct net *net, enum sctp_event_type event_type, 3028c2ecf20Sopenharmony_ci union sctp_subtype subtype, enum sctp_state state, 3038c2ecf20Sopenharmony_ci struct sctp_endpoint *ep, struct sctp_association *asoc, 3048c2ecf20Sopenharmony_ci void *event_arg, gfp_t gfp); 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci/* 2nd level prototypes */ 3078c2ecf20Sopenharmony_civoid sctp_generate_t3_rtx_event(struct timer_list *t); 3088c2ecf20Sopenharmony_civoid sctp_generate_heartbeat_event(struct timer_list *t); 3098c2ecf20Sopenharmony_civoid sctp_generate_reconf_event(struct timer_list *t); 3108c2ecf20Sopenharmony_civoid sctp_generate_proto_unreach_event(struct timer_list *t); 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_civoid sctp_ootb_pkt_free(struct sctp_packet *packet); 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistruct sctp_association *sctp_unpack_cookie( 3158c2ecf20Sopenharmony_ci const struct sctp_endpoint *ep, 3168c2ecf20Sopenharmony_ci const struct sctp_association *asoc, 3178c2ecf20Sopenharmony_ci struct sctp_chunk *chunk, 3188c2ecf20Sopenharmony_ci gfp_t gfp, int *err, 3198c2ecf20Sopenharmony_ci struct sctp_chunk **err_chk_p); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci/* 3rd level prototypes */ 3228c2ecf20Sopenharmony_ci__u32 sctp_generate_tag(const struct sctp_endpoint *ep); 3238c2ecf20Sopenharmony_ci__u32 sctp_generate_tsn(const struct sctp_endpoint *ep); 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci/* Extern declarations for major data structures. */ 3268c2ecf20Sopenharmony_ciextern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES]; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci/* Get the size of a DATA chunk payload. */ 3308c2ecf20Sopenharmony_cistatic inline __u16 sctp_data_size(struct sctp_chunk *chunk) 3318c2ecf20Sopenharmony_ci{ 3328c2ecf20Sopenharmony_ci __u16 size; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci size = ntohs(chunk->chunk_hdr->length); 3358c2ecf20Sopenharmony_ci size -= sctp_datachk_len(&chunk->asoc->stream); 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci return size; 3388c2ecf20Sopenharmony_ci} 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci/* Compare two TSNs */ 3418c2ecf20Sopenharmony_ci#define TSN_lt(a,b) \ 3428c2ecf20Sopenharmony_ci (typecheck(__u32, a) && \ 3438c2ecf20Sopenharmony_ci typecheck(__u32, b) && \ 3448c2ecf20Sopenharmony_ci ((__s32)((a) - (b)) < 0)) 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci#define TSN_lte(a,b) \ 3478c2ecf20Sopenharmony_ci (typecheck(__u32, a) && \ 3488c2ecf20Sopenharmony_ci typecheck(__u32, b) && \ 3498c2ecf20Sopenharmony_ci ((__s32)((a) - (b)) <= 0)) 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci/* Compare two MIDs */ 3528c2ecf20Sopenharmony_ci#define MID_lt(a, b) \ 3538c2ecf20Sopenharmony_ci (typecheck(__u32, a) && \ 3548c2ecf20Sopenharmony_ci typecheck(__u32, b) && \ 3558c2ecf20Sopenharmony_ci ((__s32)((a) - (b)) < 0)) 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci/* Compare two SSNs */ 3588c2ecf20Sopenharmony_ci#define SSN_lt(a,b) \ 3598c2ecf20Sopenharmony_ci (typecheck(__u16, a) && \ 3608c2ecf20Sopenharmony_ci typecheck(__u16, b) && \ 3618c2ecf20Sopenharmony_ci ((__s16)((a) - (b)) < 0)) 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci/* ADDIP 3.1.1 */ 3648c2ecf20Sopenharmony_ci#define ADDIP_SERIAL_gte(a,b) \ 3658c2ecf20Sopenharmony_ci (typecheck(__u32, a) && \ 3668c2ecf20Sopenharmony_ci typecheck(__u32, b) && \ 3678c2ecf20Sopenharmony_ci ((__s32)((b) - (a)) <= 0)) 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci/* Check VTAG of the packet matches the sender's own tag. */ 3708c2ecf20Sopenharmony_cistatic inline int 3718c2ecf20Sopenharmony_cisctp_vtag_verify(const struct sctp_chunk *chunk, 3728c2ecf20Sopenharmony_ci const struct sctp_association *asoc) 3738c2ecf20Sopenharmony_ci{ 3748c2ecf20Sopenharmony_ci /* RFC 2960 Sec 8.5 When receiving an SCTP packet, the endpoint 3758c2ecf20Sopenharmony_ci * MUST ensure that the value in the Verification Tag field of 3768c2ecf20Sopenharmony_ci * the received SCTP packet matches its own Tag. If the received 3778c2ecf20Sopenharmony_ci * Verification Tag value does not match the receiver's own 3788c2ecf20Sopenharmony_ci * tag value, the receiver shall silently discard the packet... 3798c2ecf20Sopenharmony_ci */ 3808c2ecf20Sopenharmony_ci if (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag) 3818c2ecf20Sopenharmony_ci return 1; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci return 0; 3848c2ecf20Sopenharmony_ci} 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci/* Check VTAG of the packet matches the sender's own tag and the T bit is 3878c2ecf20Sopenharmony_ci * not set, OR its peer's tag and the T bit is set in the Chunk Flags. 3888c2ecf20Sopenharmony_ci */ 3898c2ecf20Sopenharmony_cistatic inline int 3908c2ecf20Sopenharmony_cisctp_vtag_verify_either(const struct sctp_chunk *chunk, 3918c2ecf20Sopenharmony_ci const struct sctp_association *asoc) 3928c2ecf20Sopenharmony_ci{ 3938c2ecf20Sopenharmony_ci /* RFC 2960 Section 8.5.1, sctpimpguide Section 2.41 3948c2ecf20Sopenharmony_ci * 3958c2ecf20Sopenharmony_ci * B) The receiver of a ABORT MUST accept the packet 3968c2ecf20Sopenharmony_ci * if the Verification Tag field of the packet matches its own tag 3978c2ecf20Sopenharmony_ci * and the T bit is not set 3988c2ecf20Sopenharmony_ci * OR 3998c2ecf20Sopenharmony_ci * it is set to its peer's tag and the T bit is set in the Chunk 4008c2ecf20Sopenharmony_ci * Flags. 4018c2ecf20Sopenharmony_ci * Otherwise, the receiver MUST silently discard the packet 4028c2ecf20Sopenharmony_ci * and take no further action. 4038c2ecf20Sopenharmony_ci * 4048c2ecf20Sopenharmony_ci * C) The receiver of a SHUTDOWN COMPLETE shall accept the packet 4058c2ecf20Sopenharmony_ci * if the Verification Tag field of the packet matches its own tag 4068c2ecf20Sopenharmony_ci * and the T bit is not set 4078c2ecf20Sopenharmony_ci * OR 4088c2ecf20Sopenharmony_ci * it is set to its peer's tag and the T bit is set in the Chunk 4098c2ecf20Sopenharmony_ci * Flags. 4108c2ecf20Sopenharmony_ci * Otherwise, the receiver MUST silently discard the packet 4118c2ecf20Sopenharmony_ci * and take no further action. An endpoint MUST ignore the 4128c2ecf20Sopenharmony_ci * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state. 4138c2ecf20Sopenharmony_ci */ 4148c2ecf20Sopenharmony_ci if ((!sctp_test_T_bit(chunk) && 4158c2ecf20Sopenharmony_ci (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)) || 4168c2ecf20Sopenharmony_ci (sctp_test_T_bit(chunk) && asoc->c.peer_vtag && 4178c2ecf20Sopenharmony_ci (ntohl(chunk->sctp_hdr->vtag) == asoc->c.peer_vtag))) { 4188c2ecf20Sopenharmony_ci return 1; 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci return 0; 4228c2ecf20Sopenharmony_ci} 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci#endif /* __sctp_sm_h__ */ 425