Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /* SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * (C) Copyright IBM Corp. 2001, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c) 1999-2000 Cisco, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 1999-2001 Motorola, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (c) 2001-2002 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (c) 2002      Nokia Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * This is part of the SCTP Linux Kernel Implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * These are the state functions for the state machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *    lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *    La Monte H.P. Yarroll <piggy@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *    Karl Knutson          <karl@athena.chicago.il.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *    Mathew Kotowsky       <kotowsky@sctp.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *    Sridhar Samudrala     <samudrala@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *    Jon Grimm             <jgrimm@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *    Hui Huang 	    <hui.huang@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *    Dajiang Zhang 	    <dajiang.zhang@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *    Daisy Chang	    <daisyc@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *    Ardelle Fan	    <ardelle.fan@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *    Ryan Layer	    <rmlayer@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *    Kevin Gao		    <kevin.gao@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <net/inet_ecn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <net/sctp/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <net/sctp/sm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <net/sctp/structs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <trace/events/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) static struct sctp_packet *sctp_abort_pkt_new(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 					struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 					const void *payload, size_t paylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) static int sctp_eat_data(const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 			 struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 			 struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static struct sctp_packet *sctp_ootb_pkt_new(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 					const struct sctp_chunk *chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) static void sctp_send_stale_cookie_err(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 				       const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 				       const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 				       const struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 				       struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 				       struct sctp_chunk *err_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static enum sctp_disposition sctp_sf_do_5_2_6_stale(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 					struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) static enum sctp_disposition sctp_sf_shut_8_4_5(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 					struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static enum sctp_disposition sctp_sf_tabort_8_4_8(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 					struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) static enum sctp_disposition sctp_stop_t1_and_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 					struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 					__be16 error, int sk_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 					struct sctp_transport *transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static enum sctp_disposition sctp_sf_abort_violation(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 					struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 					const __u8 *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 					const size_t paylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) static enum sctp_disposition sctp_sf_violation_chunklen(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 					struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) static enum sctp_disposition sctp_sf_violation_paramlen(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 					void *arg, void *ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 					struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static enum sctp_disposition sctp_sf_violation_ctsn(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 					struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) static enum sctp_disposition sctp_sf_violation_chunk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 					struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static enum sctp_ierror sctp_sf_authenticate(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 					struct sctp_chunk *chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static enum sctp_disposition __sctp_sf_do_9_1_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 					struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) static enum sctp_disposition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) __sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 			   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 			   const union sctp_subtype type, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 			   struct sctp_cmd_seq *commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) /* Small helper function that checks if the chunk length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159)  * is of the appropriate length.  The 'required_length' argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)  * is set to be the size of a specific chunk we are testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  * Return Values:  true  = Valid length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)  * 		   false = Invalid length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) static inline bool sctp_chunk_length_valid(struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 					   __u16 required_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	__u16 chunk_length = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	/* Previously already marked? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	if (unlikely(chunk->pdiscard))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	if (unlikely(chunk_length < required_length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) /* Check for format error in an ABORT chunk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static inline bool sctp_err_chunk_valid(struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	struct sctp_errhdr *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	sctp_walk_errors(err, chunk->chunk_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	return (void *)err == (void *)chunk->chunk_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) /**********************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)  * These are the state functions for handling chunk events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  **********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)  * Process the final SHUTDOWN COMPLETE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  * Section: 4 (C) (diagram), 9.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)  * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)  * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200)  * should stop the T2-shutdown timer and remove all knowledge of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201)  * association (and thus the association enters the CLOSED state).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203)  * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204)  * C) Rules for packet carrying SHUTDOWN COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205)  * ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206)  * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207)  *   if the Verification Tag field of the packet matches its own tag and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208)  *   the T bit is not set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209)  *   OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)  *   it is set to its peer's tag and the T bit is set in the Chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211)  *   Flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)  *   Otherwise, the receiver MUST silently discard the packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)  *   and take no further action.  An endpoint MUST ignore the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214)  *   SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) enum sctp_disposition sctp_sf_do_4_C(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 				     const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 				     const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 				     const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 				     void *arg, struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	struct sctp_ulpevent *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	if (!sctp_vtag_verify_either(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	/* RFC 2960 6.10 Bundling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	 * An endpoint MUST NOT bundle INIT, INIT ACK or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	 * SHUTDOWN COMPLETE with any other chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (!chunk->singleton)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	/* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	/* RFC 2960 10.2 SCTP-to-ULP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	 * H) SHUTDOWN COMPLETE notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	 * When SCTP completes the shutdown procedures (section 9.2) this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	 * notification is passed to the upper layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 					     0, 0, 0, NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	if (ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 				SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	/* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	 * not the chunk should be discarded. If the endpoint is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	 * T2-shutdown timer and remove all knowledge of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	 * association (and thus the association enters the CLOSED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	 * state).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			SCTP_STATE(SCTP_STATE_CLOSED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)  * Respond to a normal INIT chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)  * We are the side that is being asked for an association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291)  * Section: 5.1 Normal Establishment of an Association, B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292)  * B) "Z" shall respond immediately with an INIT ACK chunk.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293)  *    destination IP address of the INIT ACK MUST be set to the source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294)  *    IP address of the INIT to which this INIT ACK is responding.  In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295)  *    the response, besides filling in other parameters, "Z" must set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296)  *    Verification Tag field to Tag_A, and also provide its own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297)  *    Verification Tag (Tag_Z) in the Initiate Tag field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299)  * Verification Tag: Must be 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) enum sctp_disposition sctp_sf_do_5_1B_init(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	struct sctp_chunk *chunk = arg, *repl, *err_chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	struct sctp_unrecognized_param *unk_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	struct sctp_association *new_asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	/* Update socket peer label if first association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	if (security_sctp_assoc_request((struct sctp_endpoint *)ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 					chunk->skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	/* 6.10 Bundling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	 * An endpoint MUST NOT bundle INIT, INIT ACK or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	 * SHUTDOWN COMPLETE with any other chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	 * IG Section 2.11.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	 * Furthermore, we require that the receiver of an INIT chunk MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	 * enforce these rules by silently discarding an arriving packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	 * with an INIT chunk that is bundled with other chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	if (!chunk->singleton)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	/* Make sure that the INIT chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	 * Normally, this would cause an ABORT with a Protocol Violation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	 * error, but since we don't have an association, we'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	 * just discard the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	/* If the packet is an OOTB packet which is temporarily on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	 * control endpoint, respond with an ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	/* 3.1 A packet containing an INIT chunk MUST have a zero Verification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	 * Tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	if (chunk->sctp_hdr->vtag != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	/* If the INIT is coming toward a closing socket, we'll send back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	 * and ABORT.  Essentially, this catches the race of INIT being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	 * backloged to the socket at the same time as the user isses close().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	 * Since the socket and all its associations are going away, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	 * can treat this OOTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	if (sctp_sstate(ep->base.sk, CLOSING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	/* Verify the INIT chunk before processing it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	err_chunk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			      (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 			      &err_chunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		/* This chunk contains fatal error. It is to be discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		 * Send an ABORT, with causes if there is any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			packet = sctp_abort_pkt_new(net, ep, asoc, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 					(__u8 *)(err_chunk->chunk_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 					sizeof(struct sctp_chunkhdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 					ntohs(err_chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 					sizeof(struct sctp_chunkhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			sctp_chunk_free(err_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			if (packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 				sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 						SCTP_PACKET(packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 				SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 				return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 				return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 						    commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	/* Grab the INIT header.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	/* Tag the variable length parameters.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	if (!new_asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	if (sctp_assoc_set_bind_addr_from_ep(new_asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 					     sctp_scope(sctp_source(chunk)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 					     GFP_ATOMIC) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		goto nomem_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	/* The call, sctp_process_init(), can fail on memory allocation.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 			       (struct sctp_init_chunk *)chunk->chunk_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 			       GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		goto nomem_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	/* B) "Z" shall respond immediately with an INIT ACK chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	/* If there are errors need to be reported for unknown parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	 * make sure to reserve enough room in the INIT ACK for them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	if (err_chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		len = ntohs(err_chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		      sizeof(struct sctp_chunkhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		goto nomem_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	/* If there are errors need to be reported for unknown parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	 * include them in the outgoing INIT ACK as "Unrecognized parameter"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	 * parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		/* Get the "Unrecognized parameter" parameter(s) out of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		 * ERROR chunk generated by sctp_verify_init(). Since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		 * error cause code for "unknown parameter" and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		 * "Unrecognized parameter" type is the same, we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		 * construct the parameters in INIT ACK by copying the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		 * ERROR causes over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		unk_param = (struct sctp_unrecognized_param *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			    ((__u8 *)(err_chunk->chunk_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 			    sizeof(struct sctp_chunkhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		/* Replace the cause code with the "Unrecognized parameter"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		 * parameter type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		sctp_addto_chunk(repl, len, unk_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		sctp_chunk_free(err_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	 * Note:  After sending out INIT ACK with the State Cookie parameter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	 * "Z" MUST NOT allocate any resources, nor keep any states for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	 * new association.  Otherwise, "Z" will be vulnerable to resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	 * attacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) nomem_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	sctp_association_free(new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	if (err_chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		sctp_chunk_free(err_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)  * Respond to a normal INIT ACK chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)  * We are the side that is initiating the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)  * Section: 5.1 Normal Establishment of an Association, C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485)  * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486)  *    timer and leave COOKIE-WAIT state. "A" shall then send the State
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487)  *    Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488)  *    the T1-cookie timer, and enter the COOKIE-ECHOED state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490)  *    Note: The COOKIE ECHO chunk can be bundled with any pending outbound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491)  *    DATA chunks, but it MUST be the first chunk in the packet and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492)  *    until the COOKIE ACK is returned the sender MUST NOT send any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493)  *    other packets to the peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495)  * Verification Tag: 3.3.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496)  *   If the value of the Initiate Tag in a received INIT ACK chunk is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497)  *   found to be 0, the receiver MUST treat it as an error and close the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498)  *   association by transmitting an ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) enum sctp_disposition sctp_sf_do_5_1C_ack(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 					  const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 					  const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 					  const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 					  void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 					  struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	struct sctp_init_chunk *initchunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	struct sctp_chunk *err_chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	/* 6.10 Bundling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	 * An endpoint MUST NOT bundle INIT, INIT ACK or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	 * SHUTDOWN COMPLETE with any other chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	if (!chunk->singleton)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	/* Make sure that the INIT-ACK chunk has a valid length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_initack_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	/* Grab the INIT header.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	/* Verify the INIT chunk before processing it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	err_chunk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			      (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 			      &err_chunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		enum sctp_error error = SCTP_ERROR_NO_RESOURCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		/* This chunk contains fatal error. It is to be discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		 * Send an ABORT, with causes.  If there are no causes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		 * then there wasn't enough memory.  Just terminate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		 * the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 			packet = sctp_abort_pkt_new(net, ep, asoc, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 					(__u8 *)(err_chunk->chunk_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 					sizeof(struct sctp_chunkhdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 					ntohs(err_chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 					sizeof(struct sctp_chunkhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 			sctp_chunk_free(err_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 			if (packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 				sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 						SCTP_PACKET(packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 				SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 				error = SCTP_ERROR_INV_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		/* SCTP-AUTH, Section 6.3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		 *    It should be noted that if the receiver wants to tear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		 *    down an association in an authenticated way only, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		 *    handling of malformed packets should not result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		 *    tearing down the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		 * This means that if we only want to abort associations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		 * in an authenticated way (i.e AUTH+ABORT), then we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		 * can't destroy this association just because the packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		 * was malformed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 						asoc, chunk->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	/* Tag the variable length parameters.  Note that we never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	 * convert the parameters in an INIT chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	initchunk = (struct sctp_init_chunk *)chunk->chunk_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 			SCTP_PEER_INIT(initchunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	/* Reset init error count upon receipt of INIT-ACK.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	/* 5.1 C) "A" shall stop the T1-init timer and leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	 * COOKIE-WAIT state.  "A" shall then ... start the T1-cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	 * timer, and enter the COOKIE-ECHOED state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 			SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	/* SCTP-AUTH: genereate the assocition shared keys so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	 * we can potentially signe the COOKIE-ECHO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	/* 5.1 C) "A" shall then send the State Cookie received in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	 * INIT ACK chunk in a COOKIE ECHO chunk, ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	/* If there is any errors to report, send the ERROR chunk generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	 * for unknown parameters as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			SCTP_CHUNK(err_chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) static bool sctp_auth_chunk_verify(struct net *net, struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 				   const struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	struct sctp_chunk auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	if (!chunk->auth_chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	/* SCTP-AUTH:  auth_chunk pointer is only set when the cookie-echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	 * is supposed to be authenticated and we have to do delayed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	 * authentication.  We've just recreated the association using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	 * the information in the cookie and now it's much easier to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	 * do the authentication.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	/* Make sure that we and the peer are AUTH capable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	if (!net->sctp.auth_enable || !asoc->peer.auth_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	/* set-up our fake chunk so that we can process it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	auth.skb = chunk->auth_chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	auth.asoc = chunk->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	auth.sctp_hdr = chunk->sctp_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	auth.chunk_hdr = (struct sctp_chunkhdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 				skb_push(chunk->auth_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 					 sizeof(struct sctp_chunkhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	skb_pull(chunk->auth_chunk, sizeof(struct sctp_chunkhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	auth.transport = chunk->transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	return sctp_sf_authenticate(asoc, &auth) == SCTP_IERROR_NO_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660)  * Respond to a normal COOKIE ECHO chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661)  * We are the side that is being asked for an association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663)  * Section: 5.1 Normal Establishment of an Association, D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664)  * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665)  *    with a COOKIE ACK chunk after building a TCB and moving to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666)  *    the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667)  *    any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668)  *    chunk MUST be the first chunk in the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670)  *   IMPLEMENTATION NOTE: An implementation may choose to send the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671)  *   Communication Up notification to the SCTP user upon reception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672)  *   of a valid COOKIE ECHO chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674)  * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675)  * D) Rules for packet carrying a COOKIE ECHO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677)  * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678)  *   Initial Tag received in the INIT ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680)  * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 					 const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 					 const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 					 const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 					 void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 					 struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	struct sctp_ulpevent *ev, *ai_ev = NULL, *auth_ev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	struct sctp_association *new_asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	struct sctp_init_chunk *peer_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	struct sctp_chunk *err_chk_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	struct sctp_chunk *repl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	if (asoc && !sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	/* If the packet is an OOTB packet which is temporarily on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	 * control endpoint, respond with an ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	/* Make sure that the COOKIE_ECHO chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	 * In this case, we check that we have enough for at least a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	 * chunk header.  More detailed verification is done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	 * in sctp_unpack_cookie().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	/* If the endpoint is not listening or if the number of associations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	 * on the TCP-style socket exceed the max backlog, respond with an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	 * ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	if (!sctp_sstate(sk, LISTENING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	    (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	/* "Decode" the chunk.  We have no optional parameters so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	 * are in good shape.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	chunk->subh.cookie_hdr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		(struct sctp_signed_cookie *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 					 sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	/* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	 * "Z" will reply with a COOKIE ACK chunk after building a TCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	 * and moving to the ESTABLISHED state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 				      &err_chk_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	/* FIXME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	 * If the re-build failed, what is the proper error path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	 * from here?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	 * [We should abort the association. --piggy]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	if (!new_asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		/* FIXME: Several errors are possible.  A bad cookie should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		 * be silently discarded, but think about logging it too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		case -SCTP_IERROR_NOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 			goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		case -SCTP_IERROR_STALE_COOKIE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 			sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 						   err_chk_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 			return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		case -SCTP_IERROR_BAD_SIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 			return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	/* Delay state machine commands until later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	 * Re-build the bind address for the association is done in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	 * the sctp_unpack_cookie() already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	/* This is a brand-new association, so these are not yet side
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	 * effects--it is safe to run them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	if (!sctp_process_init(new_asoc, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			       &chunk->subh.cookie_hdr->c.peer_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			       peer_init, GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		goto nomem_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	/* SCTP-AUTH:  Now that we've populate required fields in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	 * sctp_process_init, set up the assocaition shared keys as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	 * necessary so that we can potentially authenticate the ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		goto nomem_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	if (!sctp_auth_chunk_verify(net, chunk, new_asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		sctp_association_free(new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	repl = sctp_make_cookie_ack(new_asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		goto nomem_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	/* RFC 2960 5.1 Normal Establishment of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	 * D) IMPLEMENTATION NOTE: An implementation may choose to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	 * send the Communication Up notification to the SCTP user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	 * upon reception of a valid COOKIE ECHO chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 					     new_asoc->c.sinit_num_ostreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 					     new_asoc->c.sinit_max_instreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 					     NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	if (!ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		goto nomem_ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	/* Sockets API Draft Section 5.3.1.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	 * When a peer sends a Adaptation Layer Indication parameter , SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	 * delivers this notification to inform the application that of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	 * peers requested adaptation layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	if (new_asoc->peer.adaptation_ind) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 							    GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		if (!ai_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 			goto nomem_aiev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	if (!new_asoc->peer.auth_capable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		auth_ev = sctp_ulpevent_make_authkey(new_asoc, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 						     SCTP_AUTH_NO_AUTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 						     GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		if (!auth_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			goto nomem_authev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	/* Add all the state machine commands now since we've created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	 * everything.  This way we don't introduce memory corruptions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	 * during side-effect processing and correclty count established
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	 * associations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			SCTP_STATE(SCTP_STATE_ESTABLISHED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	SCTP_INC_STATS(net, SCTP_MIB_PASSIVEESTABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	if (new_asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 				SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	/* This will send the COOKIE ACK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	/* Queue the ASSOC_CHANGE event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	/* Send up the Adaptation Layer Indication event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	if (ai_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 				SCTP_ULPEVENT(ai_ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	if (auth_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 				SCTP_ULPEVENT(auth_ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) nomem_authev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	sctp_ulpevent_free(ai_ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) nomem_aiev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	sctp_ulpevent_free(ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) nomem_ev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	sctp_chunk_free(repl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) nomem_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	sctp_association_free(new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888)  * Respond to a normal COOKIE ACK chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889)  * We are the side that is asking for an association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891)  * RFC 2960 5.1 Normal Establishment of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893)  * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894)  *    COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895)  *    timer. It may also notify its ULP about the successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896)  *    establishment of the association with a Communication Up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897)  *    notification (see Section 10).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899)  * Verification Tag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) enum sctp_disposition sctp_sf_do_5_1E_ca(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 					 const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 					 const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 					 const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 					 void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 					 struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	struct sctp_ulpevent *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	/* Verify that the chunk length for the COOKIE-ACK is OK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	 * If we don't do this, any bundled chunks may be junked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	/* Reset init error count upon receipt of COOKIE-ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	 * to avoid problems with the managemement of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	 * counter in stale cookie situations when a transition back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	 * from the COOKIE-ECHOED state to the COOKIE-WAIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	 * state is performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	/* Set peer label for connection. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	security_inet_conn_established(ep->base.sk, chunk->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	/* RFC 2960 5.1 Normal Establishment of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	 * from the COOKIE-ECHOED state to the ESTABLISHED state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	 * stopping the T1-cookie timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 			SCTP_STATE(SCTP_STATE_ESTABLISHED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	SCTP_INC_STATS(net, SCTP_MIB_ACTIVEESTABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 				SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	/* It may also notify its ULP about the successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	 * establishment of the association with a Communication Up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	 * notification (see Section 10).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 					     0, asoc->c.sinit_num_ostreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 					     asoc->c.sinit_max_instreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 					     NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (!ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	/* Sockets API Draft Section 5.3.1.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	 * When a peer sends a Adaptation Layer Indication parameter , SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	 * delivers this notification to inform the application that of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	 * peers requested adaptation layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	if (asoc->peer.adaptation_ind) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		if (!ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 			goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 				SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	if (!asoc->peer.auth_capable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		ev = sctp_ulpevent_make_authkey(asoc, 0, SCTP_AUTH_NO_AUTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 						GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		if (!ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 				SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) /* Generate and sendout a heartbeat packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) static enum sctp_disposition sctp_sf_heartbeat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	struct sctp_transport *transport = (struct sctp_transport *) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	struct sctp_chunk *reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	/* Send a heartbeat to our peer.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	reply = sctp_make_heartbeat(asoc, transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	if (!reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	/* Set rto_pending indicating that an RTT measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	 * is started with this heartbeat chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 			SCTP_TRANSPORT(transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /* Generate a HEARTBEAT packet on the given transport.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) enum sctp_disposition sctp_sf_sendbeat_8_3(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	struct sctp_transport *transport = (struct sctp_transport *) arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	if (asoc->overall_error_count >= asoc->max_retrans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 				SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		/* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 				SCTP_PERR(SCTP_ERROR_NO_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	/* Section 3.3.5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	 * The Sender-specific Heartbeat Info field should normally include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	 * information about the sender's current time when this HEARTBEAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	 * chunk is sent and the destination transport address to which this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	 * HEARTBEAT is sent (see Section 8.3).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (transport->param_flags & SPP_HB_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		if (SCTP_DISPOSITION_NOMEM ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 				sctp_sf_heartbeat(ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 						  commands))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 			return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		/* Set transport error counter and association error counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		 * when sending heartbeat.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 				SCTP_TRANSPORT(transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			SCTP_TRANSPORT(transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 			SCTP_TRANSPORT(transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) /* resend asoc strreset_chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) enum sctp_disposition sctp_sf_send_reconf(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 					  const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 					  const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 					  const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 					  void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 					  struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	struct sctp_transport *transport = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	if (asoc->overall_error_count >= asoc->max_retrans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 				SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		/* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 				SCTP_PERR(SCTP_ERROR_NO_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	sctp_chunk_hold(asoc->strreset_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 			SCTP_CHUNK(asoc->strreset_chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)  * Process an heartbeat request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)  * Section: 8.3 Path Heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)  * The receiver of the HEARTBEAT should immediately respond with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)  * HEARTBEAT ACK that contains the Heartbeat Information field copied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)  * from the received HEARTBEAT chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)  * Verification Tag:  8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)  * When receiving an SCTP packet, the endpoint MUST ensure that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)  * value in the Verification Tag field of the received SCTP packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)  * matches its own Tag. If the received Verification Tag value does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)  * match the receiver's own tag value, the receiver shall silently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)  * discard the packet and shall not process it any further except for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)  * those cases listed in Section 8.5.1 below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) enum sctp_disposition sctp_sf_beat_8_3(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 				       const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 				       const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 				       const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 				       void *arg, struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	struct sctp_paramhdr *param_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	struct sctp_chunk *reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	size_t paylen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	/* Make sure that the HEARTBEAT chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	if (!sctp_chunk_length_valid(chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 				     sizeof(struct sctp_heartbeat_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	/* 8.3 The receiver of the HEARTBEAT should immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	 * respond with a HEARTBEAT ACK that contains the Heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	 * Information field copied from the received HEARTBEAT chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	chunk->subh.hb_hdr = (struct sctp_heartbeathdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	param_hdr = (struct sctp_paramhdr *)chunk->subh.hb_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	paylen = ntohs(chunk->chunk_hdr->length) - sizeof(struct sctp_chunkhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	if (ntohs(param_hdr->length) > paylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 		return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 						  param_hdr, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if (!pskb_pull(chunk->skb, paylen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	reply = sctp_make_heartbeat_ack(asoc, chunk, param_hdr, paylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	if (!reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)  * Process the returning HEARTBEAT ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)  * Section: 8.3 Path Heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)  * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)  * should clear the error counter of the destination transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)  * address to which the HEARTBEAT was sent, and mark the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)  * transport address as active if it is not so marked. The endpoint may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)  * optionally report to the upper layer when an inactive destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)  * address is marked as active due to the reception of the latest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)  * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)  * clear the association overall error count as well (as defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)  * in section 8.1).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)  * The receiver of the HEARTBEAT ACK should also perform an RTT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)  * measurement for that destination transport address using the time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)  * value carried in the HEARTBEAT ACK chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)  * Verification Tag:  8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) enum sctp_disposition sctp_sf_backbeat_8_3(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	struct sctp_sender_hb_info *hbinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	struct sctp_transport *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	unsigned long max_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	union sctp_addr from_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	/* Make sure that the HEARTBEAT-ACK chunk has a valid length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 					    sizeof(*hbinfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	hbinfo = (struct sctp_sender_hb_info *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	/* Make sure that the length of the parameter is what we expect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	if (ntohs(hbinfo->param_hdr.length) != sizeof(*hbinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	from_addr = hbinfo->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	link = sctp_assoc_lookup_paddr(asoc, &from_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	/* This should never happen, but lets log it if so.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	if (unlikely(!link)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 		if (from_addr.sa.sa_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 			net_warn_ratelimited("%s association %p could not find address %pI6\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 					     __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 					     asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 					     &from_addr.v6.sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 			net_warn_ratelimited("%s association %p could not find address %pI4\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 					     __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 					     asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 					     &from_addr.v4.sin_addr.s_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	/* Validate the 64-bit random nonce. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	if (hbinfo->hb_nonce != link->hb_nonce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	max_interval = link->hbinterval + link->rto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	/* Check if the timestamp looks valid.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	if (time_after(hbinfo->sent_at, jiffies) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	    time_after(jiffies, hbinfo->sent_at + max_interval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 		pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 			 "for transport:%p\n", __func__, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	/* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	 * the HEARTBEAT should clear the error counter of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	 * destination transport address to which the HEARTBEAT was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	 * sent and mark the destination transport address as active if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	 * it is not so marked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) /* Helper function to send out an abort for the restart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)  * condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 				      struct sctp_chunk *init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 				      struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	union sctp_addr_param *addrparm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	struct sctp_errhdr *errhdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	char buffer[sizeof(*errhdr) + sizeof(*addrparm)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	struct sctp_packet *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	/* Build the error on the stack.   We are way to malloc crazy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	 * throughout the code today.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	errhdr = (struct sctp_errhdr *)buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	addrparm = (union sctp_addr_param *)errhdr->variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	/* Copy into a parm format. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	len = af->to_addr_param(ssa, addrparm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	len += sizeof(*errhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	errhdr->cause = SCTP_ERROR_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	errhdr->length = htons(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	/* Assign to the control socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	ep = sctp_sk(net->sctp.ctl_sock)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	/* Association is NULL since this may be a restart attack and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	 * want to send back the attacker's vtag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	pkt = sctp_abort_pkt_new(net, ep, NULL, init, errhdr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	if (!pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	/* Discard the rest of the inbound packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	/* Even if there is no memory, treat as a failure so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	 * the packet will get dropped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) static bool list_has_sctp_addr(const struct list_head *list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			       union sctp_addr *ipaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	struct sctp_transport *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	list_for_each_entry(addr, list, transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		if (sctp_cmp_addr_exact(ipaddr, &addr->ipaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) /* A restart is occurring, check to make sure no new addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)  * are being added as we may be under a takeover attack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 				       const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 				       struct sctp_chunk *init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 				       struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	struct net *net = new_asoc->base.net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	struct sctp_transport *new_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	int ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	/* Implementor's Guide - Section 5.2.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	 * ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	 * Before responding the endpoint MUST check to see if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	 * unexpected INIT adds new addresses to the association. If new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	 * addresses are added to the association, the endpoint MUST respond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	 * with an ABORT..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	/* Search through all current addresses and make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	 * we aren't adding any new ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			    transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		if (!list_has_sctp_addr(&asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 					&new_addr->ipaddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			sctp_sf_send_restart_abort(net, &new_addr->ipaddr, init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 						   commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	/* Return success if all addresses were found. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) /* Populate the verification/tie tags based on overlapping INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)  * scenario.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)  * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) static void sctp_tietags_populate(struct sctp_association *new_asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 				  const struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	switch (asoc->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	/* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	case SCTP_STATE_COOKIE_WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 		new_asoc->c.my_vtag     = asoc->c.my_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 		new_asoc->c.my_ttag     = asoc->c.my_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		new_asoc->c.peer_ttag   = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	case SCTP_STATE_COOKIE_ECHOED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		new_asoc->c.my_vtag     = asoc->c.my_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		new_asoc->c.my_ttag     = asoc->c.my_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		new_asoc->c.peer_ttag   = asoc->c.peer_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	/* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		new_asoc->c.my_ttag   = asoc->c.my_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		new_asoc->c.peer_ttag = asoc->c.peer_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	/* Other parameters for the endpoint SHOULD be copied from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	 * existing parameters of the association (e.g. number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	 * outbound streams) into the INIT ACK and cookie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	new_asoc->rwnd                  = asoc->rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	new_asoc->c.sinit_num_ostreams  = asoc->c.sinit_num_ostreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	new_asoc->c.initial_tsn         = asoc->c.initial_tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)  * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)  * handling action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)  * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)  * Returns value representing action to be taken.   These action values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)  * correspond to Action/Description values in RFC 2960, Table 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) static char sctp_tietags_compare(struct sctp_association *new_asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 				 const struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	/* In this case, the peer may have restarted.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	    (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	    (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	    (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 		return 'A';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	/* Collision case B. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	    ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	     (0 == asoc->c.peer_vtag))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 		return 'B';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	/* Collision case D. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	    (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		return 'D';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	/* Collision case C. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	    (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	    (0 == new_asoc->c.my_ttag) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	    (0 == new_asoc->c.peer_ttag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		return 'C';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	/* No match to any of the special cases; discard this packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	return 'E';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) /* Common helper routine for both duplicate and simulataneous INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)  * chunk handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) static enum sctp_disposition sctp_sf_do_unexpected_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	struct sctp_chunk *chunk = arg, *repl, *err_chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	struct sctp_unrecognized_param *unk_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	struct sctp_association *new_asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	enum sctp_disposition retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	/* Update socket peer label if first association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	if (security_sctp_assoc_request((struct sctp_endpoint *)ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 					chunk->skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	/* 6.10 Bundling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	 * An endpoint MUST NOT bundle INIT, INIT ACK or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	 * SHUTDOWN COMPLETE with any other chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	 * IG Section 2.11.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	 * Furthermore, we require that the receiver of an INIT chunk MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	 * enforce these rules by silently discarding an arriving packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	 * with an INIT chunk that is bundled with other chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	if (!chunk->singleton)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	/* Make sure that the INIT chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	/* 3.1 A packet containing an INIT chunk MUST have a zero Verification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	 * Tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	if (chunk->sctp_hdr->vtag != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	/* Grab the INIT header.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	/* Tag the variable length parameters.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	/* Verify the INIT chunk before processing it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	err_chunk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 			      (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 			      &err_chunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		/* This chunk contains fatal error. It is to be discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		 * Send an ABORT, with causes if there is any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 		if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 			packet = sctp_abort_pkt_new(net, ep, asoc, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 					(__u8 *)(err_chunk->chunk_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 					sizeof(struct sctp_chunkhdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 					ntohs(err_chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 					sizeof(struct sctp_chunkhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 			if (packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 				sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 						SCTP_PACKET(packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 				SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 				retval = SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 				retval = SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 			goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 						    commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	 * Other parameters for the endpoint SHOULD be copied from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	 * existing parameters of the association (e.g. number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	 * outbound streams) into the INIT ACK and cookie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	 * FIXME:  We are copying parameters from the endpoint not the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	 * association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	if (!new_asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	if (sctp_assoc_set_bind_addr_from_ep(new_asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 				sctp_scope(sctp_source(chunk)), GFP_ATOMIC) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	/* In the outbound INIT ACK the endpoint MUST copy its current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	 * Verification Tag and Peers Verification tag into a reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	 * place (local tie-tag and per tie-tag) within the state cookie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 			       (struct sctp_init_chunk *)chunk->chunk_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 			       GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	/* Make sure no new addresses are being added during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	 * restart.   Do not do this check for COOKIE-WAIT state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	 * since there are no peer addresses to check against.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	 * Upon return an ABORT will have been sent if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	if (!sctp_state(asoc, COOKIE_WAIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 		if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 						 commands)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 			retval = SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 			goto nomem_retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	sctp_tietags_populate(new_asoc, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	/* B) "Z" shall respond immediately with an INIT ACK chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	/* If there are errors need to be reported for unknown parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	 * make sure to reserve enough room in the INIT ACK for them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		len = ntohs(err_chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 		      sizeof(struct sctp_chunkhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	/* If there are errors need to be reported for unknown parameters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	 * include them in the outgoing INIT ACK as "Unrecognized parameter"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	 * parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		/* Get the "Unrecognized parameter" parameter(s) out of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		 * ERROR chunk generated by sctp_verify_init(). Since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 		 * error cause code for "unknown parameter" and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 		 * "Unrecognized parameter" type is the same, we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		 * construct the parameters in INIT ACK by copying the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 		 * ERROR causes over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 		unk_param = (struct sctp_unrecognized_param *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 			    ((__u8 *)(err_chunk->chunk_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 			    sizeof(struct sctp_chunkhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 		/* Replace the cause code with the "Unrecognized parameter"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 		 * parameter type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 		sctp_addto_chunk(repl, len, unk_param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	 * Note: After sending out INIT ACK with the State Cookie parameter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	 * "Z" MUST NOT allocate any resources for this new association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	 * Otherwise, "Z" will be vulnerable to resource attacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	retval = SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	retval = SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) nomem_retval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	if (new_asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 		sctp_association_free(new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	if (err_chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 		sctp_chunk_free(err_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)  * Handle simultaneous INIT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)  * This means we started an INIT and then we got an INIT request from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)  * our peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)  * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)  * This usually indicates an initialization collision, i.e., each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)  * endpoint is attempting, at about the same time, to establish an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)  * association with the other endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)  * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)  * endpoint MUST respond with an INIT ACK using the same parameters it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)  * sent in its original INIT chunk (including its Verification Tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)  * unchanged). These original parameters are combined with those from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)  * newly received INIT chunk. The endpoint shall also generate a State
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)  * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)  * INIT to calculate the State Cookie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)  * After that, the endpoint MUST NOT change its state, the T1-init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)  * timer shall be left running and the corresponding TCB MUST NOT be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)  * destroyed. The normal procedures for handling State Cookies when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659)  * a TCB exists will resolve the duplicate INITs to a single association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)  * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)  * its Tie-Tags with the Tag information of itself and its peer (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)  * section 5.2.2 for a description of the Tie-Tags).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)  * Verification Tag: Not explicit, but an INIT can not have a valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)  * verification tag, so we skip the check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) enum sctp_disposition sctp_sf_do_5_2_1_siminit(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	/* Call helper to do the real work for both simulataneous and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	 * duplicate INIT chunk handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)  * Handle duplicated INIT messages.  These are usually delayed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)  * restransmissions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)  * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)  * COOKIE-ECHOED and COOKIE-WAIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)  * Unless otherwise stated, upon reception of an unexpected INIT for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)  * this association, the endpoint shall generate an INIT ACK with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)  * State Cookie.  In the outbound INIT ACK the endpoint MUST copy its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)  * current Verification Tag and peer's Verification Tag into a reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)  * place within the state cookie.  We shall refer to these locations as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)  * the Peer's-Tie-Tag and the Local-Tie-Tag.  The outbound SCTP packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)  * containing this INIT ACK MUST carry a Verification Tag value equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)  * the Initiation Tag found in the unexpected INIT.  And the INIT ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)  * MUST contain a new Initiation Tag (randomly generated see Section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)  * 5.3.1).  Other parameters for the endpoint SHOULD be copied from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)  * existing parameters of the association (e.g. number of outbound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)  * streams) into the INIT ACK and cookie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)  * After sending out the INIT ACK, the endpoint shall take no further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)  * actions, i.e., the existing association, including its current state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712)  * and the corresponding TCB MUST NOT be changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)  * Note: Only when a TCB exists and the association is not in a COOKIE-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)  * WAIT state are the Tie-Tags populated.  For a normal association INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)  * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)  * set to 0 (indicating that no previous TCB existed).  The INIT ACK and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)  * State Cookie are populated as specified in section 5.2.1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)  * Verification Tag: Not specified, but an INIT has no way of knowing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)  * what the verification tag could be, so we ignore it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) enum sctp_disposition sctp_sf_do_5_2_2_dupinit(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	/* Call helper to do the real work for both simulataneous and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	 * duplicate INIT chunk handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)  * Unexpected INIT-ACK handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)  * Section 5.2.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)  * If an INIT ACK received by an endpoint in any state other than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)  * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)  * An unexpected INIT ACK usually indicates the processing of an old or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)  * duplicated INIT chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) enum sctp_disposition sctp_sf_do_5_2_3_initack(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	/* Per the above section, we'll discard the chunk if we have an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	 * endpoint.  If this is an OOTB INIT-ACK, treat it as such.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	if (ep == sctp_sk(net->sctp.ctl_sock)->ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 		return sctp_sf_ootb(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 		return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)  * Section 5.2.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)  *  A)  In this case, the peer may have restarted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) static enum sctp_disposition sctp_sf_do_dupcook_a(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 					struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 					struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 					struct sctp_association *new_asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	struct sctp_init_chunk *peer_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	enum sctp_disposition disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	struct sctp_ulpevent *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	struct sctp_chunk *repl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	struct sctp_chunk *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	/* new_asoc is a brand-new association, so these are not yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	 * side effects--it is safe to run them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 			       GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	if (!sctp_auth_chunk_verify(net, chunk, new_asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	/* Make sure no new addresses are being added during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	 * restart.  Though this is a pretty complicated attack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	 * since you'd have to get inside the cookie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	/* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	 * the peer has restarted (Action A), it MUST NOT setup a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	 * association but instead resend the SHUTDOWN ACK and send an ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	 * chunk with a "Cookie Received while Shutting Down" error cause to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	 * its peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 		disposition = __sctp_sf_do_9_2_reshutack(net, ep, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 							 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 							 chunk, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 		if (SCTP_DISPOSITION_NOMEM == disposition)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 			goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 		err = sctp_make_op_error(asoc, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 					 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 					 NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 					SCTP_CHUNK(err));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 		return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	/* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	 * data. Consider the optional choice of resending of this data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 			SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 	/* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	 * and ASCONF-ACK cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_ASCONF_QUEUE, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	/* Update the content of current association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	if (sctp_assoc_update((struct sctp_association *)asoc, new_asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 		struct sctp_chunk *abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		abort = sctp_make_abort(asoc, NULL, sizeof(struct sctp_errhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 		if (abort) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 			sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNABORTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 		sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 				SCTP_PERR(SCTP_ERROR_RSRC_LOW));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	repl = sctp_make_cookie_ack(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	/* Report association restart to upper layer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 					     asoc->c.sinit_num_ostreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 					     asoc->c.sinit_max_instreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 					     NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	if (!ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 		goto nomem_ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	if ((sctp_state(asoc, SHUTDOWN_PENDING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	     sctp_state(asoc, SHUTDOWN_SENT)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	    (sctp_sstate(asoc->base.sk, CLOSING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	     sock_flag(asoc->base.sk, SOCK_DEAD))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 		/* If the socket has been closed by user, don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 		 * transition to ESTABLISHED. Instead trigger SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 		 * bundled with COOKIE_ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 		return sctp_sf_do_9_2_start_shutdown(net, ep, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 						     SCTP_ST_CHUNK(0), repl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 						     commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 		sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 				SCTP_STATE(SCTP_STATE_ESTABLISHED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) nomem_ev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	sctp_chunk_free(repl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)  * Section 5.2.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)  *   B) In this case, both sides may be attempting to start an association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910)  *      at about the same time but the peer endpoint started its INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)  *      after responding to the local endpoint's INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) /* This case represents an initialization collision.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) static enum sctp_disposition sctp_sf_do_dupcook_b(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 					struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 					struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 					struct sctp_association *new_asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	struct sctp_init_chunk *peer_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	struct sctp_chunk *repl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	/* new_asoc is a brand-new association, so these are not yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 	 * side effects--it is safe to run them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 			       GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 	if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 	if (!sctp_auth_chunk_verify(net, chunk, new_asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	/* Update the content of current association.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 			SCTP_STATE(SCTP_STATE_ESTABLISHED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	if (asoc->state < SCTP_STATE_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	repl = sctp_make_cookie_ack(new_asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	/* RFC 2960 5.1 Normal Establishment of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	 * D) IMPLEMENTATION NOTE: An implementation may choose to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	 * send the Communication Up notification to the SCTP user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	 * upon reception of a valid COOKIE ECHO chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	 * Sadly, this needs to be implemented as a side-effect, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 	 * we are not guaranteed to have set the association id of the real
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	 * association and so these notifications need to be delayed until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	 * the association id is allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	/* Sockets API Draft Section 5.3.1.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 	 * When a peer sends a Adaptation Layer Indication parameter , SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	 * delivers this notification to inform the application that of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	 * peers requested adaptation layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	 * This also needs to be done as a side effect for the same reason as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	 * above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 	if (asoc->peer.adaptation_ind)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 		sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	if (!asoc->peer.auth_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		sctp_add_cmd_sf(commands, SCTP_CMD_PEER_NO_AUTH, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)  * Section 5.2.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)  *  C) In this case, the local endpoint's cookie has arrived late.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991)  *     Before it arrived, the local endpoint sent an INIT and received an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)  *     INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993)  *     but a new tag of its own.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) /* This case represents an initialization collision.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) static enum sctp_disposition sctp_sf_do_dupcook_c(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 					struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 					struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 					struct sctp_association *new_asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	/* The cookie should be silently discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 	 * The endpoint SHOULD NOT change states and should leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 	 * any timers running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)  * Section 5.2.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)  * D) When both local and remote tags match the endpoint should always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016)  *    enter the ESTABLISHED state, if it has not already done so.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) /* This case represents an initialization collision.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) static enum sctp_disposition sctp_sf_do_dupcook_d(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 					struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 					struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 					struct sctp_association *new_asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	struct sctp_ulpevent *ev = NULL, *ai_ev = NULL, *auth_ev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	struct sctp_chunk *repl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 	/* Clarification from Implementor's Guide:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 	 * D) When both local and remote tags match the endpoint should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	 * It should stop any cookie timer that may be running and send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	 * a COOKIE ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	if (!sctp_auth_chunk_verify(net, chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	/* Don't accidentally move back into established state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	if (asoc->state < SCTP_STATE_ESTABLISHED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 				SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 		sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 				SCTP_STATE(SCTP_STATE_ESTABLISHED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 		SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 		/* RFC 2960 5.1 Normal Establishment of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 		 * D) IMPLEMENTATION NOTE: An implementation may choose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 		 * to send the Communication Up notification to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 		 * SCTP user upon reception of a valid COOKIE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 		 * ECHO chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		ev = sctp_ulpevent_make_assoc_change(asoc, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 					     SCTP_COMM_UP, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 					     asoc->c.sinit_num_ostreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 					     asoc->c.sinit_max_instreams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 					     NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 		if (!ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 			goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		/* Sockets API Draft Section 5.3.1.6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		 * When a peer sends a Adaptation Layer Indication parameter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 		 * SCTP delivers this notification to inform the application
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 		 * that of the peers requested adaptation layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		if (asoc->peer.adaptation_ind) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 			ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 								 GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 			if (!ai_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 				goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 		if (!asoc->peer.auth_capable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 			auth_ev = sctp_ulpevent_make_authkey(asoc, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 							     SCTP_AUTH_NO_AUTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 							     GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 			if (!auth_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 				goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 	repl = sctp_make_cookie_ack(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	if (ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 				SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	if (ai_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 					SCTP_ULPEVENT(ai_ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	if (auth_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 				SCTP_ULPEVENT(auth_ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 	if (auth_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 		sctp_ulpevent_free(auth_ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 	if (ai_ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 		sctp_ulpevent_free(ai_ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 	if (ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 		sctp_ulpevent_free(ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116)  * Handle a duplicate COOKIE-ECHO.  This usually means a cookie-carrying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)  * chunk was retransmitted and then delayed in the network.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)  * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)  * Verification Tag: None.  Do cookie validation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) enum sctp_disposition sctp_sf_do_5_2_4_dupcook(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	struct sctp_association *new_asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	enum sctp_disposition retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	struct sctp_chunk *err_chk_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	char action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	/* Make sure that the chunk has a valid length from the protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 	 * perspective.  In this case check to make sure we have at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	 * enough for the chunk header.  Cookie length verification is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 	 * done later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 			asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	/* "Decode" the chunk.  We have no optional parameters so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 	 * are in good shape.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 	if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 					sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	/* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 	 * of a duplicate COOKIE ECHO match the Verification Tags of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	 * current association, consider the State Cookie valid even if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	 * the lifespan is exceeded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 				      &err_chk_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 	/* FIXME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	 * If the re-build failed, what is the proper error path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 	 * from here?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	 * [We should abort the association. --piggy]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 	if (!new_asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 		/* FIXME: Several errors are possible.  A bad cookie should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		 * be silently discarded, but think about logging it too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 		switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		case -SCTP_IERROR_NOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 			goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 		case -SCTP_IERROR_STALE_COOKIE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 			sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 						   err_chk_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 			return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 		case -SCTP_IERROR_BAD_SIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 			return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 	/* Update socket peer label if first association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 	if (security_sctp_assoc_request((struct sctp_endpoint *)ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 					chunk->skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 		sctp_association_free(new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 	/* Set temp so that it won't be added into hashtable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 	new_asoc->temp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	/* Compare the tie_tag in cookie with the verification tag of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 	 * current association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	action = sctp_tietags_compare(new_asoc, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	case 'A': /* Association restart. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 		retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 					      new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	case 'B': /* Collision case B. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 		retval = sctp_sf_do_dupcook_b(net, ep, asoc, chunk, commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 					      new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	case 'C': /* Collision case C. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 		retval = sctp_sf_do_dupcook_c(net, ep, asoc, chunk, commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 					      new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 	case 'D': /* Collision case D. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 		retval = sctp_sf_do_dupcook_d(net, ep, asoc, chunk, commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 					      new_asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	default: /* Discard packet for all others. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		retval = sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 	/* Delete the tempory new association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC, SCTP_ASOC(new_asoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	/* Restore association pointer to provide SCTP command interpeter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	 * with a valid context in case it needs to manipulate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 	 * the queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 	sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 			 SCTP_ASOC((struct sctp_association *)asoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)  * Process an ABORT.  (SHUTDOWN-PENDING state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257)  * See sctp_sf_do_9_1_abort().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) enum sctp_disposition sctp_sf_shutdown_pending_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	if (!sctp_vtag_verify_either(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 	/* Make sure that the ABORT chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	 * Since this is an ABORT chunk, we have to discard it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 	 * because of the following text:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	 * RFC 2960, Section 3.3.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 	 *    If an endpoint receives an ABORT with a format error or for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 	 *    association that doesn't exist, it MUST silently discard it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 	 * Because the length is "invalid", we can't really discard just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	 * as we do not know its true length.  So, to be safe, discard the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 	 * packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 	/* ADD-IP: Special case for ABORT chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 	 * F4)  One special consideration is that ABORT Chunks arriving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	 * destined to the IP address being deleted MUST be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 	 * ignored (see Section 5.3.1 for further details).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 	if (SCTP_ADDR_DEL ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 		    sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 	if (!sctp_err_chunk_valid(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)  * Process an ABORT.  (SHUTDOWN-SENT state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303)  * See sctp_sf_do_9_1_abort().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) enum sctp_disposition sctp_sf_shutdown_sent_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 	if (!sctp_vtag_verify_either(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 	/* Make sure that the ABORT chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 	 * Since this is an ABORT chunk, we have to discard it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	 * because of the following text:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	 * RFC 2960, Section 3.3.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 	 *    If an endpoint receives an ABORT with a format error or for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	 *    association that doesn't exist, it MUST silently discard it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 	 * Because the length is "invalid", we can't really discard just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 	 * as we do not know its true length.  So, to be safe, discard the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 	 * packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	/* ADD-IP: Special case for ABORT chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 	 * F4)  One special consideration is that ABORT Chunks arriving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	 * destined to the IP address being deleted MUST be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	 * ignored (see Section 5.3.1 for further details).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	if (SCTP_ADDR_DEL ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 		    sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 	if (!sctp_err_chunk_valid(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 	/* Stop the T2-shutdown timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 	/* Stop the T5-shutdown guard timer.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 	return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355)  * Process an ABORT.  (SHUTDOWN-ACK-SENT state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)  * See sctp_sf_do_9_1_abort().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) enum sctp_disposition sctp_sf_shutdown_ack_sent_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 	/* The same T2 timer, so we should be able to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	 * common function with the SHUTDOWN-SENT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	return sctp_sf_shutdown_sent_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374)  * Handle an Error received in COOKIE_ECHOED state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376)  * Only handle the error type of stale COOKIE Error, the other errors will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)  * be ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) enum sctp_disposition sctp_sf_cookie_echoed_err(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 	struct sctp_errhdr *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	/* Make sure that the ERROR chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	 * The parameter walking depends on this as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 	/* Process the error here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 	/* FUTURE FIXME:  When PR-SCTP related and other optional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 	 * parms are emitted, this will have to change to handle multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 	 * errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 	sctp_walk_errors(err, chunk->chunk_hdr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 		if (SCTP_ERROR_STALE_COOKIE == err->cause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 			return sctp_sf_do_5_2_6_stale(net, ep, asoc, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 							arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 	/* It is possible to have malformed error causes, and that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 	 * will cause us to end the walk early.  However, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 	 * we are discarding the packet, there should be no adverse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 	 * affects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 	return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428)  * Handle a Stale COOKIE Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)  * Section: 5.2.6 Handle Stale COOKIE Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431)  * If the association is in the COOKIE-ECHOED state, the endpoint may elect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432)  * one of the following three alternatives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433)  * ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434)  * 3) Send a new INIT chunk to the endpoint, adding a Cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435)  *    Preservative parameter requesting an extension to the lifetime of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436)  *    the State Cookie. When calculating the time extension, an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437)  *    implementation SHOULD use the RTT information measured based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438)  *    previous COOKIE ECHO / ERROR exchange, and should add no more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439)  *    than 1 second beyond the measured RTT, due to long State Cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440)  *    lifetimes making the endpoint more subject to a replay attack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442)  * Verification Tag:  Not explicit, but safe to ignore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) static enum sctp_disposition sctp_sf_do_5_2_6_stale(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 	int attempts = asoc->init_err_counter + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	struct sctp_chunk *chunk = arg, *reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	struct sctp_cookie_preserve_param bht;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 	struct sctp_bind_addr *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 	struct sctp_errhdr *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 	u32 stale;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	if (attempts > asoc->max_init_attempts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 				SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 		sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 				SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 		return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 	err = (struct sctp_errhdr *)(chunk->skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 	/* When calculating the time extension, an implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 	 * SHOULD use the RTT information measured based on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 	 * previous COOKIE ECHO / ERROR exchange, and should add no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 	 * more than 1 second beyond the measured RTT, due to long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 	 * State Cookie lifetimes making the endpoint more subject to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 	 * a replay attack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 	 * Measure of Staleness's unit is usec. (1/1000000 sec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 	 * Suggested Cookie Life-span Increment's unit is msec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 	 * (1/1000 sec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 	 * In general, if you use the suggested cookie life, the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 	 * found in the field of measure of staleness should be doubled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 	 * to give ample time to retransmit the new cookie and thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 	 * yield a higher probability of success on the reattempt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 	stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 	stale = (stale * 2) / 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 	bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 	bht.param_hdr.length = htons(sizeof(bht));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 	bht.lifespan_increment = htonl(stale);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 	/* Build that new INIT chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 	bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 	reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 	if (!reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 	sctp_addto_chunk(reply, sizeof(bht), &bht);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 	/* Clear peer's init_tag cached in assoc as we are sending a new INIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 	sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 	/* Stop pending T3-rtx and heartbeat timers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 	sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 	sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 	/* Delete non-primary peer ip addresses since we are transitioning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 	 * back to the COOKIE-WAIT state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 	sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 	/* If we've sent any data bundled with COOKIE-ECHO we will need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 	 * resend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 			SCTP_TRANSPORT(asoc->peer.primary_path));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 	/* Cast away the const modifier, as we want to just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 	 * rerun it through as a sideffect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 	sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 			SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545)  * Process an ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547)  * Section: 9.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548)  * After checking the Verification Tag, the receiving endpoint shall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549)  * remove the association from its record, and shall report the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550)  * termination to its upper layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552)  * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553)  * B) Rules for packet carrying ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555)  *  - The endpoint shall always fill in the Verification Tag field of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556)  *    outbound packet with the destination endpoint's tag value if it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557)  *    is known.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559)  *  - If the ABORT is sent in response to an OOTB packet, the endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)  *    MUST follow the procedure described in Section 8.4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562)  *  - The receiver MUST accept the packet if the Verification Tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563)  *    matches either its own tag, OR the tag of its peer. Otherwise, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564)  *    receiver MUST silently discard the packet and take no further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565)  *    action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) enum sctp_disposition sctp_sf_do_9_1_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 	if (!sctp_vtag_verify_either(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 	/* Make sure that the ABORT chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 	 * Since this is an ABORT chunk, we have to discard it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 	 * because of the following text:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 	 * RFC 2960, Section 3.3.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 	 *    If an endpoint receives an ABORT with a format error or for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	 *    association that doesn't exist, it MUST silently discard it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 	 * Because the length is "invalid", we can't really discard just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 	 * as we do not know its true length.  So, to be safe, discard the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 	 * packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	/* ADD-IP: Special case for ABORT chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 	 * F4)  One special consideration is that ABORT Chunks arriving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 	 * destined to the IP address being deleted MUST be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 	 * ignored (see Section 5.3.1 for further details).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 	if (SCTP_ADDR_DEL ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 		    sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 	if (!sctp_err_chunk_valid(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 	return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) static enum sctp_disposition __sctp_sf_do_9_1_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 	__be16 error = SCTP_ERROR_NO_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	/* See if we have an error cause code in the chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 	len = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 	if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 		error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 	sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 	/* ASSOC_FAILED will DELETE_TCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 	sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 	SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 	SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 	return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)  * Process an ABORT.  (COOKIE-WAIT state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)  * See sctp_sf_do_9_1_abort() above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) enum sctp_disposition sctp_sf_cookie_wait_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 	__be16 error = SCTP_ERROR_NO_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	if (!sctp_vtag_verify_either(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	/* Make sure that the ABORT chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 	 * Since this is an ABORT chunk, we have to discard it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 	 * because of the following text:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 	 * RFC 2960, Section 3.3.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 	 *    If an endpoint receives an ABORT with a format error or for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 	 *    association that doesn't exist, it MUST silently discard it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 	 * Because the length is "invalid", we can't really discard just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 	 * as we do not know its true length.  So, to be safe, discard the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	 * packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 	/* See if we have an error cause code in the chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 	len = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 	if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 		error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 	return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 				      chunk->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)  * Process an incoming ICMP as an ABORT.  (COOKIE-WAIT state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) enum sctp_disposition sctp_sf_cookie_wait_icmp_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 	return sctp_stop_t1_and_abort(net, commands, SCTP_ERROR_NO_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 				      ENOPROTOOPT, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 				      (struct sctp_transport *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701)  * Process an ABORT.  (COOKIE-ECHOED state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) enum sctp_disposition sctp_sf_cookie_echoed_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 	/* There is a single T1 timer, so we should be able to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 	 * common function with the COOKIE-WAIT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 	return sctp_sf_cookie_wait_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718)  * Stop T1 timer and abort association with "INIT failed".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720)  * This is common code called by several sctp_sf_*_abort() functions above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) static enum sctp_disposition sctp_stop_t1_and_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 					struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 					__be16 error, int sk_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 					struct sctp_transport *transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 	pr_debug("%s: ABORT received (INIT)\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 			SCTP_STATE(SCTP_STATE_CLOSED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 	sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 	/* CMD_INIT_FAILED will DELETE_TCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 	sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 			SCTP_PERR(error));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 	return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745)  * sctp_sf_do_9_2_shut
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747)  * Section: 9.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748)  * Upon the reception of the SHUTDOWN, the peer endpoint shall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749)  *  - enter the SHUTDOWN-RECEIVED state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751)  *  - stop accepting new data from its SCTP user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753)  *  - verify, by checking the Cumulative TSN Ack field of the chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754)  *    that all its outstanding DATA chunks have been received by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755)  *    SHUTDOWN sender.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757)  * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)  * send a SHUTDOWN in response to a ULP request. And should discard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759)  * subsequent SHUTDOWN chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761)  * If there are still outstanding DATA chunks left, the SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)  * receiver shall continue to follow normal data transmission
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)  * procedures defined in Section 6 until all outstanding DATA chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764)  * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765)  * new data from its SCTP user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767)  * Verification Tag:  8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) enum sctp_disposition sctp_sf_do_9_2_shutdown(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 	enum sctp_disposition disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 	struct sctp_shutdownhdr *sdh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 	struct sctp_ulpevent *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 	__u32 ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 	/* Make sure that the SHUTDOWN chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 	/* Convert the elaborate header.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 	sdh = (struct sctp_shutdownhdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 	skb_pull(chunk->skb, sizeof(*sdh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 	chunk->subh.shutdown_hdr = sdh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 	ctsn = ntohl(sdh->cum_tsn_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 	if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 		pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 			 asoc->ctsn_ack_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 	/* If Cumulative TSN Ack beyond the max tsn currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 	 * send, terminating the association and respond to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 	 * sender with an ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 	if (!TSN_lt(ctsn, asoc->next_tsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 		return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 	/* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 	 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 	 * inform the application that it should cease sending data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 	ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 	if (!ev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 		disposition = SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 	sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 	/* Upon the reception of the SHUTDOWN, the peer endpoint shall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 	 *  - enter the SHUTDOWN-RECEIVED state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 	 *  - stop accepting new data from its SCTP user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 	 * [This is implicit in the new state.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 			SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 	disposition = SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 	if (sctp_outq_is_empty(&asoc->outqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 		disposition = sctp_sf_do_9_2_shutdown_ack(net, ep, asoc, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 							  arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 	if (SCTP_DISPOSITION_NOMEM == disposition)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 	/*  - verify, by checking the Cumulative TSN Ack field of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 	 *    chunk, that all its outstanding DATA chunks have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 	 *    received by the SHUTDOWN sender.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 	sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 			SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 	return disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860)  * sctp_sf_do_9_2_shut_ctsn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862)  * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863)  * it MUST NOT send a SHUTDOWN in response to a ULP request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864)  * The Cumulative TSN Ack of the received SHUTDOWN chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865)  * MUST be processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) enum sctp_disposition sctp_sf_do_9_2_shut_ctsn(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 	struct sctp_shutdownhdr *sdh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 	__u32 ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 	/* Make sure that the SHUTDOWN chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 	sdh = (struct sctp_shutdownhdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 	ctsn = ntohl(sdh->cum_tsn_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 	if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 		pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 			 asoc->ctsn_ack_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 	/* If Cumulative TSN Ack beyond the max tsn currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 	 * send, terminating the association and respond to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 	 * sender with an ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 	if (!TSN_lt(ctsn, asoc->next_tsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 		return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 	/* verify, by checking the Cumulative TSN Ack field of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 	 * chunk, that all its outstanding DATA chunks have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 	 * received by the SHUTDOWN sender.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 	sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 			SCTP_BE32(sdh->cum_tsn_ack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) /* RFC 2960 9.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915)  * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916)  * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917)  * transport addresses (either in the IP addresses or in the INIT chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918)  * that belong to this association, it should discard the INIT chunk and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919)  * retransmit the SHUTDOWN ACK chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) static enum sctp_disposition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) __sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 			   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 			   const union sctp_subtype type, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 			   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	struct sctp_chunk *reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 	/* Make sure that the chunk has a valid length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 	/* Since we are not going to really process this INIT, there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 	 * is no point in verifying chunk boundries.  Just generate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 	 * the SHUTDOWN ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 	reply = sctp_make_shutdown_ack(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 	if (NULL == reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 	/* Set the transport for the SHUTDOWN ACK chunk and the timeout for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 	 * the T2-SHUTDOWN timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 	sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 	/* and restart the T2-shutdown timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) enum sctp_disposition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 			 const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 			 const union sctp_subtype type, void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 			 struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 	if (!chunk->singleton)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 	if (chunk->sctp_hdr->vtag != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 		return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 	return __sctp_sf_do_9_2_reshutack(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980)  * sctp_sf_do_ecn_cwr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982)  * Section:  Appendix A: Explicit Congestion Notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984)  * CWR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986)  * RFC 2481 details a specific bit for a sender to send in the header of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987)  * its next outbound TCP segment to indicate to its peer that it has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988)  * reduced its congestion window.  This is termed the CWR bit.  For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989)  * SCTP the same indication is made by including the CWR chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990)  * This chunk contains one data element, i.e. the TSN number that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991)  * was sent in the ECNE chunk.  This element represents the lowest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992)  * TSN number in the datagram that was originally marked with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993)  * CE bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995)  * Verification Tag: 8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) enum sctp_disposition sctp_sf_do_ecn_cwr(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 					 const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 					 const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 					 const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 					 void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 					 struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 	struct sctp_cwrhdr *cwr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 	u32 lowest_tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 	cwr = (struct sctp_cwrhdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 	skb_pull(chunk->skb, sizeof(*cwr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 	lowest_tsn = ntohl(cwr->lowest_tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 	/* Does this CWR ack the last sent congestion notification? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 	if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 		/* Stop sending ECNE. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 		sctp_add_cmd_sf(commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 				SCTP_CMD_ECN_CWR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 				SCTP_U32(lowest_tsn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038)  * sctp_sf_do_ecne
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040)  * Section:  Appendix A: Explicit Congestion Notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042)  * ECN-Echo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044)  * RFC 2481 details a specific bit for a receiver to send back in its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045)  * TCP acknowledgements to notify the sender of the Congestion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046)  * Experienced (CE) bit having arrived from the network.  For SCTP this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047)  * same indication is made by including the ECNE chunk.  This chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048)  * contains one data element, i.e. the lowest TSN associated with the IP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)  * datagram marked with the CE bit.....
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051)  * Verification Tag: 8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) enum sctp_disposition sctp_sf_do_ecne(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 				      const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 				      const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 				      const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 				      void *arg, struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 	struct sctp_ecnehdr *ecne;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 	ecne = (struct sctp_ecnehdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 	skb_pull(chunk->skb, sizeof(*ecne));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 	/* If this is a newer ECNE than the last CWR packet we sent out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 	sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 			SCTP_U32(ntohl(ecne->lowest_tsn)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087)  * Section: 6.2  Acknowledgement on Reception of DATA Chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089)  * The SCTP endpoint MUST always acknowledge the reception of each valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090)  * DATA chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092)  * The guidelines on delayed acknowledgement algorithm specified in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093)  * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094)  * acknowledgement SHOULD be generated for at least every second packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095)  * (not every second DATA chunk) received, and SHOULD be generated within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096)  * 200 ms of the arrival of any unacknowledged DATA chunk. In some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097)  * situations it may be beneficial for an SCTP transmitter to be more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098)  * conservative than the algorithms detailed in this document allow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099)  * However, an SCTP transmitter MUST NOT be more aggressive than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100)  * following algorithms allow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102)  * A SCTP receiver MUST NOT generate more than one SACK for every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103)  * incoming packet, other than to update the offered window as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104)  * receiving application consumes new data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106)  * Verification Tag:  8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) enum sctp_disposition sctp_sf_eat_data_6_2(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 	union sctp_arg force = SCTP_NOFORCE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 	if (!sctp_vtag_verify(chunk, asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 	if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 	error = sctp_eat_data(asoc, chunk, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 	switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 	case SCTP_IERROR_NO_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 	case SCTP_IERROR_HIGH_TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 	case SCTP_IERROR_BAD_STREAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 		SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 		goto discard_noforce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 	case SCTP_IERROR_DUP_TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 	case SCTP_IERROR_IGNORE_TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 		SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 		goto discard_force;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 	case SCTP_IERROR_NO_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 		return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 	case SCTP_IERROR_PROTO_VIOLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 		return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 					       (u8 *)chunk->subh.data_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 					       sctp_datahdr_len(&asoc->stream));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 	if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 		force = SCTP_FORCE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 	if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 				SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 	/* If this is the last chunk in a packet, we need to count it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 	 * toward sack generation.  Note that we need to SACK every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 	 * OTHER packet containing data chunks, EVEN IF WE DISCARD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 	 * THEM.  We elect to NOT generate SACK's if the chunk fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 	 * the verification tag test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 	 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 	 * The SCTP endpoint MUST always acknowledge the reception of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 	 * each valid DATA chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 	 * The guidelines on delayed acknowledgement algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 	 * specified in  Section 4.2 of [RFC2581] SHOULD be followed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 	 * Specifically, an acknowledgement SHOULD be generated for at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 	 * least every second packet (not every second DATA chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 	 * received, and SHOULD be generated within 200 ms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 	 * arrival of any unacknowledged DATA chunk.  In some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 	 * situations it may be beneficial for an SCTP transmitter to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 	 * be more conservative than the algorithms detailed in this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 	 * document allow. However, an SCTP transmitter MUST NOT be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 	 * more aggressive than the following algorithms allow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 	if (chunk->end_of_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 		sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) discard_force:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 	/* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 	 * When a packet arrives with duplicate DATA chunk(s) and with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 	 * no new DATA chunk(s), the endpoint MUST immediately send a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 	 * SACK with no delay.  If a packet arrives with duplicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 	 * DATA chunk(s) bundled with new DATA chunks, the endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 	 * MAY immediately send a SACK.  Normally receipt of duplicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 	 * DATA chunks will occur when the original SACK chunk was lost
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 	 * and the peer's RTO has expired.  The duplicate TSN number(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 	 * SHOULD be reported in the SACK as duplicate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 	/* In our case, we split the MAY SACK advice up whether or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 	 * the last chunk is a duplicate.'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 	if (chunk->end_of_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 		sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) discard_noforce:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 	if (chunk->end_of_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 		sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221)  * sctp_sf_eat_data_fast_4_4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223)  * Section: 4 (4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224)  * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225)  *    DATA chunks without delay.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227)  * Verification Tag:  8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) enum sctp_disposition sctp_sf_eat_data_fast_4_4(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 	if (!sctp_vtag_verify(chunk, asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 	if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 	error = sctp_eat_data(asoc, chunk, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 	switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 	case SCTP_IERROR_NO_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 	case SCTP_IERROR_HIGH_TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 	case SCTP_IERROR_DUP_TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 	case SCTP_IERROR_IGNORE_TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 	case SCTP_IERROR_BAD_STREAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 	case SCTP_IERROR_NO_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 		return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 	case SCTP_IERROR_PROTO_VIOLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 		return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 					       (u8 *)chunk->subh.data_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 					       sctp_datahdr_len(&asoc->stream));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 	/* Go a head and force a SACK, since we are shutting down. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 	/* Implementor's Guide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 	 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 	 * respond to each received packet containing one or more DATA chunk(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 	 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 	if (chunk->end_of_packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 		/* We must delay the chunk creation since the cumulative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 		 * TSN has not been updated yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 		sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 		sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 				SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297)  * Section: 6.2  Processing a Received SACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298)  * D) Any time a SACK arrives, the endpoint performs the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300)  *     i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301)  *     then drop the SACK.   Since Cumulative TSN Ack is monotonically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302)  *     increasing, a SACK whose Cumulative TSN Ack is less than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303)  *     Cumulative TSN Ack Point indicates an out-of-order SACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305)  *     ii) Set rwnd equal to the newly received a_rwnd minus the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306)  *     of bytes still outstanding after processing the Cumulative TSN Ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307)  *     and the Gap Ack Blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309)  *     iii) If the SACK is missing a TSN that was previously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310)  *     acknowledged via a Gap Ack Block (e.g., the data receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311)  *     reneged on the data), then mark the corresponding DATA chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312)  *     as available for retransmit:  Mark it as missing for fast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313)  *     retransmit as described in Section 7.2.4 and if no retransmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314)  *     timer is running for the destination address to which the DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315)  *     chunk was originally transmitted, then T3-rtx is started for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316)  *     that destination address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318)  * Verification Tag:  8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) enum sctp_disposition sctp_sf_eat_sack_6_2(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 	struct sctp_sackhdr *sackh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 	__u32 ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 	/* Make sure that the SACK chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_sack_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 	/* Pull the SACK chunk from the data buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 	sackh = sctp_sm_pull_sack(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 	/* Was this a bogus SACK? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 	if (!sackh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 	chunk->subh.sack_hdr = sackh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 	ctsn = ntohl(sackh->cum_tsn_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 	/* If Cumulative TSN Ack beyond the max tsn currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 	 * send, terminating the association and respond to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 	 * sender with an ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 	if (TSN_lte(asoc->next_tsn, ctsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 		return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 	trace_sctp_probe(ep, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 	/* i) If Cumulative TSN Ack is less than the Cumulative TSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 	 *     Ack Point, then drop the SACK.  Since Cumulative TSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 	 *     Ack is monotonically increasing, a SACK whose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 	 *     Cumulative TSN Ack is less than the Cumulative TSN Ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 	 *     Point indicates an out-of-order SACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 	if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 		pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 			 asoc->ctsn_ack_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 	/* Return this SACK for further processing.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 	sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 	/* Note: We do the rest of the work on the PROCESS_SACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 	 * sideeffect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387)  * Generate an ABORT in response to a packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389)  * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391)  * 8) The receiver should respond to the sender of the OOTB packet with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392)  *    an ABORT.  When sending the ABORT, the receiver of the OOTB packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393)  *    MUST fill in the Verification Tag field of the outbound packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394)  *    with the value found in the Verification Tag field of the OOTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395)  *    packet and set the T-bit in the Chunk Flags to indicate that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396)  *    Verification Tag is reflected.  After sending this ABORT, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397)  *    receiver of the OOTB packet shall discard the OOTB packet and take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398)  *    no further action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400)  * Verification Tag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) static enum sctp_disposition sctp_sf_tabort_8_4_8(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 	struct sctp_packet *packet = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 	struct sctp_chunk *abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 	packet = sctp_ootb_pkt_new(net, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 	if (!packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 		return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 	/* Make an ABORT. The T bit will be set if the asoc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 	 * is NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 	abort = sctp_make_abort(asoc, chunk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 	if (!abort) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 		sctp_ootb_pkt_free(packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 		return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 	/* Reflect vtag if T-Bit is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 	if (sctp_test_T_bit(abort))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 		packet->vtag = ntohl(chunk->sctp_hdr->vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 	/* Set the skb to the belonging sock for accounting.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 	abort->skb->sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 	sctp_packet_append_chunk(packet, abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 	sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 			SCTP_PACKET(packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 	SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 	sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448)  * Received an ERROR chunk from peer.  Generate SCTP_REMOTE_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449)  * event as ULP notification for each cause included in the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451)  * API 5.3.1.3 - SCTP_REMOTE_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) enum sctp_disposition sctp_sf_operr_notify(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 	struct sctp_errhdr *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 	/* Make sure that the ERROR chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 	sctp_walk_errors(err, chunk->chunk_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 	if ((void *)err != (void *)chunk->chunk_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 		return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 						  (void *)err, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 	sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 			SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484)  * Process an inbound SHUTDOWN ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486)  * From Section 9.2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487)  * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488)  * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489)  * peer, and remove all record of the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491)  * The return value is the disposition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) enum sctp_disposition sctp_sf_do_9_2_final(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) 	struct sctp_chunk *reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 	struct sctp_ulpevent *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 	/* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 	/* 10.2 H) SHUTDOWN COMPLETE notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 	 * When SCTP completes the shutdown procedures (section 9.2) this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 	 * notification is passed to the upper layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 	ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 					     0, 0, 0, NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 	if (!ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 	/* ...send a SHUTDOWN COMPLETE chunk to its peer, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) 	reply = sctp_make_shutdown_complete(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 	if (!reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 		goto nomem_chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) 	/* Do all the commands now (after allocation), so that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) 	 * have consistent state if memory allocation failes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) 	sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 	/* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) 	 * stop the T2-shutdown timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 			SCTP_STATE(SCTP_STATE_CLOSED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 	SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 	SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 	/* ...and remove all record of the association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 	sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 	return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) nomem_chunk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 	sctp_ulpevent_free(ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557)  * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559)  * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560)  *    respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561)  *    When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562)  *    packet must fill in the Verification Tag field of the outbound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563)  *    packet with the Verification Tag received in the SHUTDOWN ACK and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564)  *    set the T-bit in the Chunk Flags to indicate that the Verification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565)  *    Tag is reflected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567)  * 8) The receiver should respond to the sender of the OOTB packet with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568)  *    an ABORT.  When sending the ABORT, the receiver of the OOTB packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569)  *    MUST fill in the Verification Tag field of the outbound packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570)  *    with the value found in the Verification Tag field of the OOTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571)  *    packet and set the T-bit in the Chunk Flags to indicate that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572)  *    Verification Tag is reflected.  After sending this ABORT, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573)  *    receiver of the OOTB packet shall discard the OOTB packet and take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574)  *    no further action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) enum sctp_disposition sctp_sf_ootb(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 				   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 				   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 				   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 				   void *arg, struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 	struct sk_buff *skb = chunk->skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 	struct sctp_chunkhdr *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 	struct sctp_errhdr *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 	int ootb_cookie_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 	int ootb_shut_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 	__u8 *ch_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 	SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 	if (asoc && !sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 		asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 	ch = (struct sctp_chunkhdr *)chunk->chunk_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 		/* Report violation if the chunk is less then minimal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 		if (ntohs(ch->length) < sizeof(*ch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 			return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 		/* Report violation if chunk len overflows */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 		ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 		if (ch_end > skb_tail_pointer(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 			return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 		/* Now that we know we at least have a chunk header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 		 * do things that are type appropriate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 		if (SCTP_CID_SHUTDOWN_ACK == ch->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 			ootb_shut_ack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 		/* RFC 2960, Section 3.3.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 		 *   Moreover, under any circumstances, an endpoint that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 		 *   receives an ABORT  MUST NOT respond to that ABORT by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 		 *   sending an ABORT of its own.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 		if (SCTP_CID_ABORT == ch->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 			return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 		/* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 		 * or a COOKIE ACK the SCTP Packet should be silently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 		 * discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 		if (SCTP_CID_COOKIE_ACK == ch->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 			ootb_cookie_ack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) 		if (SCTP_CID_ERROR == ch->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 			sctp_walk_errors(err, ch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) 				if (SCTP_ERROR_STALE_COOKIE == err->cause) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 					ootb_cookie_ack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 		ch = (struct sctp_chunkhdr *)ch_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 	} while (ch_end < skb_tail_pointer(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 	if (ootb_shut_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 		return sctp_sf_shut_8_4_5(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 	else if (ootb_cookie_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 		return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651)  * Handle an "Out of the blue" SHUTDOWN ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653)  * Section: 8.4 5, sctpimpguide 2.41.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655)  * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656)  *    respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657)  *    When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658)  *    packet must fill in the Verification Tag field of the outbound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659)  *    packet with the Verification Tag received in the SHUTDOWN ACK and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660)  *    set the T-bit in the Chunk Flags to indicate that the Verification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661)  *    Tag is reflected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664)  * (endpoint, asoc, type, arg, commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667)  * (enum sctp_disposition)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) static enum sctp_disposition sctp_sf_shut_8_4_5(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 	struct sctp_packet *packet = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 	struct sctp_chunk *shut;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 	packet = sctp_ootb_pkt_new(net, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 	if (!packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 		return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 	/* Make an SHUTDOWN_COMPLETE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 	 * The T bit will be set if the asoc is NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 	shut = sctp_make_shutdown_complete(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 	if (!shut) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 		sctp_ootb_pkt_free(packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 		return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 	/* Reflect vtag if T-Bit is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 	if (sctp_test_T_bit(shut))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 		packet->vtag = ntohl(chunk->sctp_hdr->vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 	/* Set the skb to the belonging sock for accounting.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 	shut->skb->sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 	sctp_packet_append_chunk(packet, shut);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 	sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 			SCTP_PACKET(packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 	SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 	/* We need to discard the rest of the packet to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 	 * potential bomming attacks from additional bundled chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 	 * This is documented in SCTP Threats ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 	return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718)  * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720)  * Verification Tag:  8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721)  *   If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722)  *   procedures in section 8.4 SHOULD be followed, in other words it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723)  *   should be treated as an Out Of The Blue packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724)  *   [This means that we do NOT check the Verification Tag on these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725)  *   chunks. --piggy ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) enum sctp_disposition sctp_sf_do_8_5_1_E_sa(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 					    const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 					    const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 					    const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 					    void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 					    struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) 		asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 	/* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 	/* Although we do have an association in this case, it corresponds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 	 * to a restarted association. So the packet is treated as an OOTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) 	 * packet and the state function that handles OOTB SHUTDOWN_ACK is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 	 * called with a NULL association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 	SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 	return sctp_sf_shut_8_4_5(net, ep, NULL, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) enum sctp_disposition sctp_sf_do_asconf(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 	struct sctp_paramhdr *err_param = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 	struct sctp_chunk *asconf_ack = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 	struct sctp_addiphdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 	__u32 serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 	if (!sctp_vtag_verify(chunk, asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 	/* Make sure that the ASCONF ADDIP chunk has a valid length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_addip_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 	/* ADD-IP: Section 4.1.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 	 * This chunk MUST be sent in an authenticated way by using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 	 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 	 * is received unauthenticated it MUST be silently discarded as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 	 * described in [I-D.ietf-tsvwg-sctp-auth].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 	if (!asoc->peer.asconf_capable ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 	    (!net->sctp.addip_noauth && !chunk->auth))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 	hdr = (struct sctp_addiphdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 	serial = ntohl(hdr->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 	/* Verify the ASCONF chunk before processing it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 	if (!sctp_verify_asconf(asoc, chunk, true, &err_param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 		return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 						  (void *)err_param, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 	/* ADDIP 5.2 E1) Compare the value of the serial number to the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 	 * the endpoint stored in a new association variable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 	 * 'Peer-Serial-Number'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 	if (serial == asoc->peer.addip_serial + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 		/* If this is the first instance of ASCONF in the packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 		 * we can clean our old ASCONF-ACKs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 		if (!chunk->has_asconf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 			sctp_assoc_clean_asconf_ack_cache(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 		/* ADDIP 5.2 E4) When the Sequence Number matches the next one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 		 * expected, process the ASCONF as described below and after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 		 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) 		 * the response packet and cache a copy of it (in the event it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 		 * later needs to be retransmitted).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 		 * Essentially, do V1-V5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 		asconf_ack = sctp_process_asconf((struct sctp_association *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 						 asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 		if (!asconf_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 			return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 	} else if (serial < asoc->peer.addip_serial + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) 		/* ADDIP 5.2 E2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 		 * If the value found in the Sequence Number is less than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 		 * ('Peer- Sequence-Number' + 1), simply skip to the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) 		 * ASCONF, and include in the outbound response packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) 		 * any previously cached ASCONF-ACK response that was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 		 * sent and saved that matches the Sequence Number of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 		 * ASCONF.  Note: It is possible that no cached ASCONF-ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 		 * Chunk exists.  This will occur when an older ASCONF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 		 * arrives out of order.  In such a case, the receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 		 * should skip the ASCONF Chunk and not include ASCONF-ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 		 * Chunk for that chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 		asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 		if (!asconf_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 			return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 		/* Reset the transport so that we select the correct one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 		 * this time around.  This is to make sure that we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 		 * accidentally use a stale transport that's been removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 		asconf_ack->transport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 		/* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 		 * it must be either a stale packet or from an attacker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 	/* ADDIP 5.2 E6)  The destination address of the SCTP packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) 	 * containing the ASCONF-ACK Chunks MUST be the source address of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 	 * the SCTP packet that held the ASCONF Chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 	 * To do this properly, we'll set the destination address of the chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 	 * and at the transmit time, will try look up the transport to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) 	 * Since ASCONFs may be bundled, the correct transport may not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 	 * created until we process the entire packet, thus this workaround.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 	asconf_ack->dest = chunk->source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 	if (asoc->new_transport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 		sctp_sf_heartbeat(ep, asoc, type, asoc->new_transport, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 		((struct sctp_association *)asoc)->new_transport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) static enum sctp_disposition sctp_send_next_asconf(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 					struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 	struct sctp_chunk *asconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 	struct list_head *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 	if (list_empty(&asoc->addip_chunk_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 		return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 	entry = asoc->addip_chunk_list.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 	asconf = list_entry(entry, struct sctp_chunk, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 	list_del_init(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 	sctp_chunk_hold(asconf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 	asoc->addip_last_asconf = asconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 	return sctp_sf_do_prm_asconf(net, ep, asoc, type, asconf, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893)  * ADDIP Section 4.3 General rules for address manipulation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894)  * When building TLV parameters for the ASCONF Chunk that will add or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895)  * delete IP addresses the D0 to D13 rules should be applied:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 					    const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 					    const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 					    const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) 					    void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 					    struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 	struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 	struct sctp_paramhdr *err_param = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 	struct sctp_chunk *asconf_ack = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 	struct sctp_addiphdr *addip_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 	__u32 sent_serial, rcvd_serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 	struct sctp_chunk *abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 	if (!sctp_vtag_verify(asconf_ack, asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 	/* Make sure that the ADDIP chunk has a valid length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 	if (!sctp_chunk_length_valid(asconf_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 				     sizeof(struct sctp_addip_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 	/* ADD-IP, Section 4.1.2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 	 * This chunk MUST be sent in an authenticated way by using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 	 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) 	 * is received unauthenticated it MUST be silently discarded as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 	 * described in [I-D.ietf-tsvwg-sctp-auth].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 	if (!asoc->peer.asconf_capable ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 	    (!net->sctp.addip_noauth && !asconf_ack->auth))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 	addip_hdr = (struct sctp_addiphdr *)asconf_ack->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 	rcvd_serial = ntohl(addip_hdr->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 	/* Verify the ASCONF-ACK chunk before processing it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 	if (!sctp_verify_asconf(asoc, asconf_ack, false, &err_param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 		return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 			   (void *)err_param, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 	if (last_asconf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 		addip_hdr = (struct sctp_addiphdr *)last_asconf->subh.addip_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 		sent_serial = ntohl(addip_hdr->serial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 		sent_serial = asoc->addip_serial - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 	/* D0) If an endpoint receives an ASCONF-ACK that is greater than or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 	 * equal to the next serial number to be used but no ASCONF chunk is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 	 * outstanding the endpoint MUST ABORT the association. Note that a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 	 * sequence number is greater than if it is no more than 2^^31-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 	 * larger than the current sequence number (using serial arithmetic).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 	if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 	    !(asoc->addip_last_asconf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 		abort = sctp_make_abort(asoc, asconf_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 					sizeof(struct sctp_errhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 		if (abort) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 			sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 					SCTP_CHUNK(abort));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 		/* We are going to ABORT, so we might as well stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 		 * processing the rest of the chunks in the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) 				SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 		sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 				SCTP_ERROR(ECONNABORTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 		sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 				SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) 		SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 		return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 	if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 				SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 		if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 					     asconf_ack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) 			return sctp_send_next_asconf(net, ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 					(struct sctp_association *)asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) 							type, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) 		abort = sctp_make_abort(asoc, asconf_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 					sizeof(struct sctp_errhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) 		if (abort) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 			sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) 					SCTP_CHUNK(abort));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) 		/* We are going to ABORT, so we might as well stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 		 * processing the rest of the chunks in the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 		sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 				SCTP_ERROR(ECONNABORTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 		sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) 				SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 		SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) 		return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) enum sctp_disposition sctp_sf_do_reconf(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) 	struct sctp_paramhdr *err_param = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 	struct sctp_reconf_chunk *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 	union sctp_params param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 	if (!sctp_vtag_verify(chunk, asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) 	/* Make sure that the RECONF chunk has a valid length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 	if (!sctp_chunk_length_valid(chunk, sizeof(*hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) 	if (!sctp_verify_reconf(asoc, chunk, &err_param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) 		return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) 						  (void *)err_param, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) 	hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) 	sctp_walk_params(param, hdr, params) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) 		struct sctp_chunk *reply = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 		struct sctp_ulpevent *ev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 		if (param.p->type == SCTP_PARAM_RESET_OUT_REQUEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) 			reply = sctp_process_strreset_outreq(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) 				(struct sctp_association *)asoc, param, &ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 		else if (param.p->type == SCTP_PARAM_RESET_IN_REQUEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) 			reply = sctp_process_strreset_inreq(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 				(struct sctp_association *)asoc, param, &ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 		else if (param.p->type == SCTP_PARAM_RESET_TSN_REQUEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 			reply = sctp_process_strreset_tsnreq(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) 				(struct sctp_association *)asoc, param, &ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 		else if (param.p->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 			reply = sctp_process_strreset_addstrm_out(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 				(struct sctp_association *)asoc, param, &ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) 		else if (param.p->type == SCTP_PARAM_RESET_ADD_IN_STREAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 			reply = sctp_process_strreset_addstrm_in(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) 				(struct sctp_association *)asoc, param, &ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 		else if (param.p->type == SCTP_PARAM_RESET_RESPONSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) 			reply = sctp_process_strreset_resp(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) 				(struct sctp_association *)asoc, param, &ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) 		if (ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 			sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) 					SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 		if (reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 					SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076)  * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078)  * When a FORWARD TSN chunk arrives, the data receiver MUST first update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079)  * its cumulative TSN point to the value carried in the FORWARD TSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080)  * chunk, and then MUST further advance its cumulative TSN point locally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081)  * if possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082)  * After the above processing, the data receiver MUST stop reporting any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083)  * missing TSNs earlier than or equal to the new cumulative TSN point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085)  * Verification Tag:  8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) enum sctp_disposition sctp_sf_eat_fwd_tsn(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) 					  const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) 					  const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) 					  const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) 					  void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) 					  struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) 	struct sctp_fwdtsn_hdr *fwdtsn_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) 	__u16 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 	__u32 tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) 	if (!sctp_vtag_verify(chunk, asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 	if (!asoc->peer.prsctp_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 		return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 	/* Make sure that the FORWARD_TSN chunk has valid length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) 	if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 	fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 	chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) 	len = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) 	len -= sizeof(struct sctp_chunkhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) 	skb_pull(chunk->skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) 	tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) 	pr_debug("%s: TSN 0x%x\n", __func__, tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 	/* The TSN is too high--silently discard the chunk and count on it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 	 * getting retransmitted later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 	if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) 		goto discard_noforce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) 	if (!asoc->stream.si->validate_ftsn(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 		goto discard_noforce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 	if (len > sctp_ftsnhdr_len(&asoc->stream))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 		sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 				SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 	/* Count this as receiving DATA. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 	if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 				SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 	/* FIXME: For now send a SACK, but DATA processing may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 	 * send another.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 	sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) discard_noforce:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) enum sctp_disposition sctp_sf_eat_fwd_tsn_fast(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 	struct sctp_fwdtsn_hdr *fwdtsn_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 	__u16 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 	__u32 tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 	if (!sctp_vtag_verify(chunk, asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) 	if (!asoc->peer.prsctp_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) 		return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 	/* Make sure that the FORWARD_TSN chunk has a valid length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 	if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) 	fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 	chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 	len = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 	len -= sizeof(struct sctp_chunkhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 	skb_pull(chunk->skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) 	tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 	pr_debug("%s: TSN 0x%x\n", __func__, tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 	/* The TSN is too high--silently discard the chunk and count on it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 	 * getting retransmitted later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 	if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 		goto gen_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 	if (!asoc->stream.si->validate_ftsn(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 		goto gen_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) 	if (len > sctp_ftsnhdr_len(&asoc->stream))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 		sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 				SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) 	/* Go a head and force a SACK, since we are shutting down. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) gen_shutdown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 	/* Implementor's Guide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 	 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) 	 * respond to each received packet containing one or more DATA chunk(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 	 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 	sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 	sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222)  * SCTP-AUTH Section 6.3 Receiving authenticated chukns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224)  *    The receiver MUST use the HMAC algorithm indicated in the HMAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225)  *    Identifier field.  If this algorithm was not specified by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226)  *    receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227)  *    during association setup, the AUTH chunk and all chunks after it MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228)  *    be discarded and an ERROR chunk SHOULD be sent with the error cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229)  *    defined in Section 4.1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231)  *    If an endpoint with no shared key receives a Shared Key Identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232)  *    other than 0, it MUST silently discard all authenticated chunks.  If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233)  *    the endpoint has at least one endpoint pair shared key for the peer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234)  *    it MUST use the key specified by the Shared Key Identifier if a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235)  *    key has been configured for that Shared Key Identifier.  If no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236)  *    endpoint pair shared key has been configured for that Shared Key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237)  *    Identifier, all authenticated chunks MUST be silently discarded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239)  * Verification Tag:  8.5 Verification Tag [Normal verification]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) static enum sctp_ierror sctp_sf_authenticate(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 					struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 	struct sctp_shared_key *sh_key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 	struct sctp_authhdr *auth_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 	__u8 *save_digest, *digest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) 	struct sctp_hmac *hmac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 	unsigned int sig_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 	__u16 key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 	/* Pull in the auth header, so we can do some more verification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 	auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 	chunk->subh.auth_hdr = auth_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 	skb_pull(chunk->skb, sizeof(*auth_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 	/* Make sure that we support the HMAC algorithm from the auth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) 	 * chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) 	if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 		return SCTP_IERROR_AUTH_BAD_HMAC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) 	/* Make sure that the provided shared key identifier has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 	 * configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 	key_id = ntohs(auth_hdr->shkey_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) 	if (key_id != asoc->active_key_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 		sh_key = sctp_auth_get_shkey(asoc, key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) 		if (!sh_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 			return SCTP_IERROR_AUTH_BAD_KEYID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) 	/* Make sure that the length of the signature matches what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 	 * we expect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) 	sig_len = ntohs(chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 		  sizeof(struct sctp_auth_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) 	hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 	if (sig_len != hmac->hmac_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 		return SCTP_IERROR_PROTO_VIOLATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 	/* Now that we've done validation checks, we can compute and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 	 * verify the hmac.  The steps involved are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 	 *  1. Save the digest from the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) 	 *  2. Zero out the digest in the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 	 *  3. Compute the new digest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 	 *  4. Compare saved and new digests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 	digest = auth_hdr->hmac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 	skb_pull(chunk->skb, sig_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 	save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 	if (!save_digest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 	memset(digest, 0, sig_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 	sctp_auth_calculate_hmac(asoc, chunk->skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 				 (struct sctp_auth_chunk *)chunk->chunk_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 				 sh_key, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 	/* Discard the packet if the digests do not match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 	if (memcmp(save_digest, digest, sig_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) 		kfree(save_digest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 		return SCTP_IERROR_BAD_SIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) 	kfree(save_digest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 	chunk->auth = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) 	return SCTP_IERROR_NO_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) 	return SCTP_IERROR_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) enum sctp_disposition sctp_sf_eat_auth(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 				       const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) 				       const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 				       const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) 				       void *arg, struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 	struct sctp_authhdr *auth_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) 	struct sctp_chunk *err_chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 	enum sctp_ierror error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 	/* Make sure that the peer has AUTH capable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 	if (!asoc->peer.auth_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) 		return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 	if (!sctp_vtag_verify(chunk, asoc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 				SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 	/* Make sure that the AUTH chunk has valid length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) 	auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 	error = sctp_sf_authenticate(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) 	switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) 	case SCTP_IERROR_AUTH_BAD_HMAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) 		/* Generate the ERROR chunk and discard the rest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) 		 * of the packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) 		err_chunk = sctp_make_op_error(asoc, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 					       SCTP_ERROR_UNSUP_HMAC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) 					       &auth_hdr->hmac_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 					       sizeof(__u16), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) 		if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) 					SCTP_CHUNK(err_chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 	case SCTP_IERROR_AUTH_BAD_KEYID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 	case SCTP_IERROR_BAD_SIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) 	case SCTP_IERROR_PROTO_VIOLATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) 	case SCTP_IERROR_NOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 		return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) 	default:			/* Prevent gcc warnings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 	if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 		struct sctp_ulpevent *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 		ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 				    SCTP_AUTH_NEW_KEY, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 		if (!ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 		sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 				SCTP_ULPEVENT(ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392)  * Process an unknown chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394)  * Section: 3.2. Also, 2.1 in the implementor's guide.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396)  * Chunk Types are encoded such that the highest-order two bits specify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397)  * the action that must be taken if the processing endpoint does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398)  * recognize the Chunk Type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400)  * 00 - Stop processing this SCTP packet and discard it, do not process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401)  *      any further chunks within it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403)  * 01 - Stop processing this SCTP packet and discard it, do not process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404)  *      any further chunks within it, and report the unrecognized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405)  *      chunk in an 'Unrecognized Chunk Type'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407)  * 10 - Skip this chunk and continue processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409)  * 11 - Skip this chunk and continue processing, but report in an ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410)  *      Chunk using the 'Unrecognized Chunk Type' cause of error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) enum sctp_disposition sctp_sf_unk_chunk(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) 	struct sctp_chunk *unk_chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) 	struct sctp_chunk *err_chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 	struct sctp_chunkhdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 	pr_debug("%s: processing unknown chunk id:%d\n", __func__, type.chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) 	if (!sctp_vtag_verify(unk_chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 	/* Make sure that the chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 	 * Since we don't know the chunk type, we use a general
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 	 * chunkhdr structure to make a comparison.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 	if (!sctp_chunk_length_valid(unk_chunk, sizeof(*hdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 	switch (type.chunk & SCTP_CID_ACTION_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) 	case SCTP_CID_ACTION_DISCARD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) 		/* Discard the packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 	case SCTP_CID_ACTION_DISCARD_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) 		/* Generate an ERROR chunk as response. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 		hdr = unk_chunk->chunk_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) 		err_chunk = sctp_make_op_error(asoc, unk_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) 					       SCTP_ERROR_UNKNOWN_CHUNK, hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) 					       SCTP_PAD4(ntohs(hdr->length)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) 					       0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) 		if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) 					SCTP_CHUNK(err_chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) 		/* Discard the packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) 		sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 		return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) 	case SCTP_CID_ACTION_SKIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 		/* Skip the chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) 		return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) 	case SCTP_CID_ACTION_SKIP_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) 		/* Generate an ERROR chunk as response. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) 		hdr = unk_chunk->chunk_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) 		err_chunk = sctp_make_op_error(asoc, unk_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 					       SCTP_ERROR_UNKNOWN_CHUNK, hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 					       SCTP_PAD4(ntohs(hdr->length)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 					       0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 		if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) 					SCTP_CHUNK(err_chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 		/* Skip the chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) 		return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481)  * Discard the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483)  * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484)  * [Too numerous to mention...]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485)  * Verification Tag: No verification needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) enum sctp_disposition sctp_sf_discard_chunk(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) 					    const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) 					    const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) 					    const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) 					    void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) 					    struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 	if (asoc && !sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 	/* Make sure that the chunk has a valid length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 	 * Since we don't know the chunk type, we use a general
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 	 * chunkhdr structure to make a comparison.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) 	pr_debug("%s: chunk:%d is discarded\n", __func__, type.chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520)  * Discard the whole packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522)  * Section: 8.4 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524)  * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525)  *    silently discard the OOTB packet and take no further action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527)  * Verification Tag: No verification necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) enum sctp_disposition sctp_sf_pdiscard(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) 				       const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) 				       const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) 				       const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) 				       void *arg, struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) 	SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_DISCARDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) 	sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551)  * The other end is violating protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553)  * Section: Not specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554)  * Verification Tag: Not specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559)  * (asoc, reply_msg, msg_up, timers, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561)  * We simply tag the chunk as a violation.  The state machine will log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562)  * the violation and continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) enum sctp_disposition sctp_sf_violation(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) 	if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) 	/* Make sure that the chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) 						  commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) 	return SCTP_DISPOSITION_VIOLATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585)  * Common function to handle a protocol violation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) static enum sctp_disposition sctp_sf_abort_violation(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) 					struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) 					const __u8 *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) 					const size_t paylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) 	struct sctp_packet *packet = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) 	struct sctp_chunk *chunk =  arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) 	struct sctp_chunk *abort = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) 	/* SCTP-AUTH, Section 6.3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) 	 *    It should be noted that if the receiver wants to tear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) 	 *    down an association in an authenticated way only, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) 	 *    handling of malformed packets should not result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) 	 *    tearing down the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) 	 * This means that if we only want to abort associations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) 	 * in an authenticated way (i.e AUTH+ABORT), then we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) 	 * can't destroy this association just because the packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) 	 * was malformed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) 	if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) 	/* Make the abort chunk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) 	abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) 	if (!abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) 	if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) 		/* Treat INIT-ACK as a special case during COOKIE-WAIT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) 		if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) 		    !asoc->peer.i.init_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) 			struct sctp_initack_chunk *initack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) 			initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) 			if (!sctp_chunk_length_valid(chunk, sizeof(*initack)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) 				abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) 				unsigned int inittag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) 				inittag = ntohl(initack->init_hdr.init_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) 				sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_INITTAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) 						SCTP_U32(inittag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) 		SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) 		if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) 			sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) 					SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) 			sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) 					SCTP_ERROR(ECONNREFUSED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) 			sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) 					SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) 			sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) 					SCTP_ERROR(ECONNABORTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) 			sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) 					SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) 			SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) 		packet = sctp_ootb_pkt_new(net, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) 		if (!packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) 			goto nomem_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) 		if (sctp_test_T_bit(abort))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) 			packet->vtag = ntohl(chunk->sctp_hdr->vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) 		abort->skb->sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) 		sctp_packet_append_chunk(packet, abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) 		sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) 			SCTP_PACKET(packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) 		SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) 	SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) 	sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) 	return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) nomem_pkt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) 	sctp_chunk_free(abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686)  * Handle a protocol violation when the chunk length is invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687)  * "Invalid" length is identified as smaller than the minimal length a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688)  * given chunk can be.  For example, a SACK chunk has invalid length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689)  * if its length is set to be smaller than the size of struct sctp_sack_chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691)  * We inform the other end by sending an ABORT with a Protocol Violation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692)  * error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694)  * Section: Not specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695)  * Verification Tag:  Nothing to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700)  * (reply_msg, msg_up, counters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702)  * Generate an  ABORT chunk and terminate the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) static enum sctp_disposition sctp_sf_violation_chunklen(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) 	static const char err_str[] = "The following chunk had invalid length:";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) 	return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) 				       sizeof(err_str));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719)  * Handle a protocol violation when the parameter length is invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720)  * If the length is smaller than the minimum length of a given parameter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721)  * or accumulated length in multi parameters exceeds the end of the chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722)  * the length is considered as invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) static enum sctp_disposition sctp_sf_violation_paramlen(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) 					void *arg, void *ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) 	struct sctp_paramhdr *param = ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) 	struct sctp_chunk *abort = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) 	if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) 	/* Make the abort chunk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) 	abort = sctp_make_violation_paramlen(asoc, chunk, param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) 	if (!abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) 	SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) 	sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) 			SCTP_ERROR(ECONNABORTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) 	sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) 			SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) 	SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) 	SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) 	sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) 	return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) /* Handle a protocol violation when the peer trying to advance the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762)  * cumulative tsn ack to a point beyond the max tsn currently sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764)  * We inform the other end by sending an ABORT with a Protocol Violation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765)  * error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) static enum sctp_disposition sctp_sf_violation_ctsn(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) 	static const char err_str[] = "The cumulative tsn ack beyond the max tsn currently sent:";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) 	return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) 				       sizeof(err_str));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) /* Handle protocol violation of an invalid chunk bundling.  For example,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782)  * when we have an association and we receive bundled INIT-ACK, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783)  * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784)  * statement from the specs.  Additionally, there might be an attacker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785)  * on the path and we may not want to continue this communication.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) static enum sctp_disposition sctp_sf_violation_chunk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) 	static const char err_str[] = "The following chunk violates protocol:";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) 	if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) 		return sctp_sf_violation(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) 	return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) 				       sizeof(err_str));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804)  * These are the state functions for handling primitive (Section 10) events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805)  ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807)  * sctp_sf_do_prm_asoc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809)  * Section: 10.1 ULP-to-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810)  * B) Associate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812)  * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813)  * outbound stream count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814)  * -> association id [,destination transport addr list] [,outbound stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815)  * count]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817)  * This primitive allows the upper layer to initiate an association to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818)  * specific peer endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820)  * The peer endpoint shall be specified by one of the transport addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821)  * which defines the endpoint (see Section 1.4).  If the local SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822)  * instance has not been initialized, the ASSOCIATE is considered an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823)  * error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824)  * [This is not relevant for the kernel implementation since we do all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825)  * initialization at boot time.  It we hadn't initialized we wouldn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826)  * get anywhere near this code.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828)  * An association id, which is a local handle to the SCTP association,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829)  * will be returned on successful establishment of the association. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830)  * SCTP is not able to open an SCTP association with the peer endpoint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831)  * an error is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832)  * [In the kernel implementation, the struct sctp_association needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833)  * be created BEFORE causing this primitive to run.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835)  * Other association parameters may be returned, including the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836)  * complete destination transport addresses of the peer as well as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837)  * outbound stream count of the local endpoint. One of the transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838)  * address from the returned destination addresses will be selected by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839)  * the local endpoint as default primary path for sending SCTP packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840)  * to this peer.  The returned "destination transport addr list" can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841)  * be used by the ULP to change the default primary path or to force
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842)  * sending a packet to a specific transport address.  [All of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843)  * stuff happens when the INIT ACK arrives.  This is a NON-BLOCKING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844)  * function.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846)  * Mandatory attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848)  * o local SCTP instance name - obtained from the INITIALIZE operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849)  *   [This is the argument asoc.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850)  * o destination transport addr - specified as one of the transport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851)  * addresses of the peer endpoint with which the association is to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852)  * established.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853)  *  [This is asoc->peer.active_path.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854)  * o outbound stream count - the number of outbound streams the ULP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855)  * would like to open towards this peer endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856)  * [BUG: This is not currently implemented.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857)  * Optional attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859)  * None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861)  * The return value is a disposition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) enum sctp_disposition sctp_sf_do_prm_asoc(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) 					  const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) 					  const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) 					  const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) 					  void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) 					  struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) 	struct sctp_association *my_asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) 	struct sctp_chunk *repl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) 	/* The comment below says that we enter COOKIE-WAIT AFTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) 	 * sending the INIT, but that doesn't actually work in our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) 	 * implementation...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) 			SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) 	/* RFC 2960 5.1 Normal Establishment of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) 	 * A) "A" first sends an INIT chunk to "Z".  In the INIT, "A"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) 	 * must provide its Verification Tag (Tag_A) in the Initiate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) 	 * Tag field.  Tag_A SHOULD be a random number in the range of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) 	 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) 	repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) 	if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) 	/* Choose transport for INIT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) 	sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) 			SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) 	/* Cast away the const modifier, as we want to just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) 	 * rerun it through as a sideffect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) 	my_asoc = (struct sctp_association *)asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(my_asoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) 	/* After sending the INIT, "A" starts the T1-init timer and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) 	 * enters the COOKIE-WAIT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915)  * Process the SEND primitive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917)  * Section: 10.1 ULP-to-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918)  * E) Send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920)  * Format: SEND(association id, buffer address, byte count [,context]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921)  *         [,stream id] [,life time] [,destination transport address]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922)  *         [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923)  * -> result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925)  * This is the main method to send user data via SCTP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927)  * Mandatory attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929)  *  o association id - local handle to the SCTP association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931)  *  o buffer address - the location where the user message to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932)  *    transmitted is stored;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934)  *  o byte count - The size of the user data in number of bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936)  * Optional attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938)  *  o context - an optional 32 bit integer that will be carried in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939)  *    sending failure notification to the ULP if the transportation of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940)  *    this User Message fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942)  *  o stream id - to indicate which stream to send the data on. If not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943)  *    specified, stream 0 will be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945)  *  o life time - specifies the life time of the user data. The user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946)  *    will not be sent by SCTP after the life time expires. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947)  *    parameter can be used to avoid efforts to transmit stale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948)  *    user messages. SCTP notifies the ULP if the data cannot be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949)  *    initiated to transport (i.e. sent to the destination via SCTP's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950)  *    send primitive) within the life time variable. However, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951)  *    user data will be transmitted if SCTP has attempted to transmit a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952)  *    chunk before the life time expired.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954)  *  o destination transport address - specified as one of the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955)  *    transport addresses of the peer endpoint to which this packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956)  *    should be sent. Whenever possible, SCTP should use this destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957)  *    transport address for sending the packets, instead of the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958)  *    primary path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960)  *  o unorder flag - this flag, if present, indicates that the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961)  *    would like the data delivered in an unordered fashion to the peer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962)  *    (i.e., the U flag is set to 1 on all DATA chunks carrying this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963)  *    message).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965)  *  o no-bundle flag - instructs SCTP not to bundle this user data with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966)  *    other outbound DATA chunks. SCTP MAY still bundle even when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967)  *    this flag is present, when faced with network congestion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969)  *  o payload protocol-id - A 32 bit unsigned integer that is to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970)  *    passed to the peer indicating the type of payload protocol data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971)  *    being transmitted. This value is passed as opaque data by SCTP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973)  * The return value is the disposition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) enum sctp_disposition sctp_sf_do_prm_send(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) 					  const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) 					  const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) 					  const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) 					  void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) 					  struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) 	struct sctp_datamsg *msg = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) 	sctp_add_cmd_sf(commands, SCTP_CMD_SEND_MSG, SCTP_DATAMSG(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989)  * Process the SHUTDOWN primitive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991)  * Section: 10.1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992)  * C) Shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994)  * Format: SHUTDOWN(association id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995)  * -> result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997)  * Gracefully closes an association. Any locally queued user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998)  * will be delivered to the peer. The association will be terminated only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999)  * after the peer acknowledges all the SCTP packets sent.  A success code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000)  * will be returned on successful termination of the association. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001)  * attempting to terminate the association results in a failure, an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002)  * code shall be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004)  * Mandatory attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006)  *  o association id - local handle to the SCTP association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008)  * Optional attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010)  * None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012)  * The return value is the disposition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) enum sctp_disposition sctp_sf_do_9_2_prm_shutdown(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) 	enum sctp_disposition disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) 	/* From 9.2 Shutdown of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) 	 * Upon receipt of the SHUTDOWN primitive from its upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) 	 * layer, the endpoint enters SHUTDOWN-PENDING state and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) 	 * remains there until all outstanding data has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) 	 * acknowledged by its peer. The endpoint accepts no new data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) 	 * from its upper layer, but retransmits data to the far end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) 	 * if necessary to fill gaps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) 			SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) 	disposition = SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) 	if (sctp_outq_is_empty(&asoc->outqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) 		disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) 							    arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) 	return disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045)  * Process the ABORT primitive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047)  * Section: 10.1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048)  * C) Abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050)  * Format: Abort(association id [, cause code])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051)  * -> result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053)  * Ungracefully closes an association. Any locally queued user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054)  * will be discarded and an ABORT chunk is sent to the peer.  A success code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055)  * will be returned on successful abortion of the association. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056)  * attempting to abort the association results in a failure, an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057)  * code shall be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059)  * Mandatory attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061)  *  o association id - local handle to the SCTP association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063)  * Optional attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065)  *  o cause code - reason of the abort to be passed to the peer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067)  * None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069)  * The return value is the disposition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) enum sctp_disposition sctp_sf_do_9_1_prm_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) 	/* From 9.1 Abort of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) 	 * Upon receipt of the ABORT primitive from its upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) 	 * layer, the endpoint enters CLOSED state and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) 	 * discard all outstanding data has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) 	 * acknowledged by its peer. The endpoint accepts no new data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) 	 * from its upper layer, but retransmits data to the far end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) 	 * if necessary to fill gaps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) 	struct sctp_chunk *abort = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) 	if (abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) 	/* Even if we can't send the ABORT due to low memory delete the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) 	 * TCB.  This is a departure from our typical NOMEM handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) 	sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) 			SCTP_ERROR(ECONNABORTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) 	/* Delete the established association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) 	sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) 			SCTP_PERR(SCTP_ERROR_USER_ABORT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) 	SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) 	SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) 	return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) /* We tried an illegal operation on an association which is closed.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) enum sctp_disposition sctp_sf_error_closed(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) /* We tried an illegal operation on an association which is shutting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121)  * down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) enum sctp_disposition sctp_sf_error_shutdown(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) 			SCTP_ERROR(-ESHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137)  * sctp_cookie_wait_prm_shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139)  * Section: 4 Note: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140)  * Verification Tag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144)  * The RFC does not explicitly address this issue, but is the route through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145)  * state table when someone issues a shutdown while in COOKIE_WAIT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148)  * (timers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) enum sctp_disposition sctp_sf_cookie_wait_prm_shutdown(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) 			SCTP_STATE(SCTP_STATE_CLOSED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) 	SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) 	sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) 	return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172)  * sctp_cookie_echoed_prm_shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174)  * Section: 4 Note: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175)  * Verification Tag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179)  * The RFC does not explcitly address this issue, but is the route through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180)  * state table when someone issues a shutdown while in COOKIE_ECHOED state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183)  * (timers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) enum sctp_disposition sctp_sf_cookie_echoed_prm_shutdown(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) 	/* There is a single T1 timer, so we should be able to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) 	 * common function with the COOKIE-WAIT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) 	return sctp_sf_cookie_wait_prm_shutdown(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200)  * sctp_sf_cookie_wait_prm_abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202)  * Section: 4 Note: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203)  * Verification Tag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207)  * The RFC does not explicitly address this issue, but is the route through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208)  * state table when someone issues an abort while in COOKIE_WAIT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211)  * (timers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) enum sctp_disposition sctp_sf_cookie_wait_prm_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) 	struct sctp_chunk *abort = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) 	/* Stop T1-init timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) 	if (abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) 			SCTP_STATE(SCTP_STATE_CLOSED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) 	SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) 	/* Even if we can't send the ABORT due to low memory delete the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) 	 * TCB.  This is a departure from our typical NOMEM handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) 	sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) 			SCTP_ERROR(ECONNREFUSED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) 	/* Delete the established association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) 	sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) 			SCTP_PERR(SCTP_ERROR_USER_ABORT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) 	return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249)  * sctp_sf_cookie_echoed_prm_abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251)  * Section: 4 Note: 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252)  * Verification Tag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256)  * The RFC does not explcitly address this issue, but is the route through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257)  * state table when someone issues an abort while in COOKIE_ECHOED state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260)  * (timers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) enum sctp_disposition sctp_sf_cookie_echoed_prm_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) 	/* There is a single T1 timer, so we should be able to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) 	 * common function with the COOKIE-WAIT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) 	return sctp_sf_cookie_wait_prm_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277)  * sctp_sf_shutdown_pending_prm_abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282)  * The RFC does not explicitly address this issue, but is the route through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283)  * state table when someone issues an abort while in SHUTDOWN-PENDING state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286)  * (timers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) enum sctp_disposition sctp_sf_shutdown_pending_prm_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) 	/* Stop the T5-shutdown guard timer.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) 	return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304)  * sctp_sf_shutdown_sent_prm_abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309)  * The RFC does not explicitly address this issue, but is the route through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310)  * state table when someone issues an abort while in SHUTDOWN-SENT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313)  * (timers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) enum sctp_disposition sctp_sf_shutdown_sent_prm_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) 	/* Stop the T2-shutdown timer.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) 	/* Stop the T5-shutdown guard timer.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) 	return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335)  * sctp_sf_cookie_echoed_prm_abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340)  * The RFC does not explcitly address this issue, but is the route through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341)  * state table when someone issues an abort while in COOKIE_ECHOED state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344)  * (timers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) enum sctp_disposition sctp_sf_shutdown_ack_sent_prm_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) 	/* The same T2 timer, so we should be able to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) 	 * common function with the SHUTDOWN-SENT state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) 	return sctp_sf_shutdown_sent_prm_abort(net, ep, asoc, type, arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361)  * Process the REQUESTHEARTBEAT primitive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363)  * 10.1 ULP-to-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364)  * J) Request Heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366)  * Format: REQUESTHEARTBEAT(association id, destination transport address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368)  * -> result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370)  * Instructs the local endpoint to perform a HeartBeat on the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371)  * destination transport address of the given association. The returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372)  * result should indicate whether the transmission of the HEARTBEAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373)  * chunk to the destination address is successful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375)  * Mandatory attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377)  * o association id - local handle to the SCTP association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379)  * o destination transport address - the transport address of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380)  *   association on which a heartbeat should be issued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) enum sctp_disposition sctp_sf_do_prm_requestheartbeat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) 	if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) 				      (struct sctp_transport *)arg, commands))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) 		return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) 	 * RFC 2960 (bis), section 8.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) 	 *    D) Request an on-demand HEARTBEAT on a specific destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) 	 *    transport address of a given association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) 	 *    The endpoint should increment the respective error  counter of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) 	 *    the destination transport address each time a HEARTBEAT is sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) 	 *    to that address and not acknowledged within one RTO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) 	sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) 			SCTP_TRANSPORT(arg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411)  * ADDIP Section 4.1 ASCONF Chunk Procedures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412)  * When an endpoint has an ASCONF signaled change to be sent to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413)  * remote endpoint it should do A1 to A9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) enum sctp_disposition sctp_sf_do_prm_asconf(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) 					    const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) 					    const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) 					    const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) 					    void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) 					    struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) 	sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) enum sctp_disposition sctp_sf_do_prm_reconf(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) 					    const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) 					    const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) 					    const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) 					    void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) 					    struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446)  * Ignore the primitive event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448)  * The return value is the disposition of the primitive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) enum sctp_disposition sctp_sf_ignore_primitive(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) 	pr_debug("%s: primitive type:%d is ignored\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) 		 type.primitive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465)  * These are the state functions for the OTHER events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466)  ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469)  * When the SCTP stack has no more user data to send or retransmit, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470)  * notification is given to the user. Also, at the time when a user app
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471)  * subscribes to this event, if there is no data to be sent or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472)  * retransmit, the stack will immediately send up this notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) enum sctp_disposition sctp_sf_do_no_pending_tsn(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) 	event = sctp_ulpevent_make_sender_dry_event(asoc, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) 		return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) 	sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494)  * Start the shutdown negotiation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496)  * From Section 9.2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497)  * Once all its outstanding data has been acknowledged, the endpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498)  * shall send a SHUTDOWN chunk to its peer including in the Cumulative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499)  * TSN Ack field the last sequential TSN it has received from the peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500)  * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501)  * state. If the timer expires, the endpoint must re-send the SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502)  * with the updated last sequential TSN received from its peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504)  * The return value is the disposition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) enum sctp_disposition sctp_sf_do_9_2_start_shutdown(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) 	struct sctp_chunk *reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) 	/* Once all its outstanding data has been acknowledged, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) 	 * endpoint shall send a SHUTDOWN chunk to its peer including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) 	 * in the Cumulative TSN Ack field the last sequential TSN it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) 	 * has received from the peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) 	reply = sctp_make_shutdown(asoc, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) 	if (!reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) 	/* Set the transport for the SHUTDOWN chunk and the timeout for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) 	 * T2-shutdown timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) 	sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) 	/* It shall then start the T2-shutdown timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) 	/* RFC 4960 Section 9.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) 	 * The sender of the SHUTDOWN MAY also start an overall guard timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) 	 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) 	if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) 				SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) 	/* and enter the SHUTDOWN-SENT state.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) 			SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) 	/* sctp-implguide 2.10 Issues with Heartbeating and failover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) 	 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) 	 * or SHUTDOWN-ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) 	sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565)  * Generate a SHUTDOWN ACK now that everything is SACK'd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567)  * From Section 9.2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569)  * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570)  * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571)  * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572)  * endpoint must re-send the SHUTDOWN ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574)  * The return value is the disposition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) enum sctp_disposition sctp_sf_do_9_2_shutdown_ack(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) 	struct sctp_chunk *chunk = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) 	struct sctp_chunk *reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) 	/* There are 2 ways of getting here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) 	 *    1) called in response to a SHUTDOWN chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) 	 *    2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) 	 * For the case (2), the arg parameter is set to NULL.  We need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) 	 * to check that we have a chunk before accessing it's fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) 	if (chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) 		if (!sctp_vtag_verify(chunk, asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) 			return sctp_sf_pdiscard(net, ep, asoc, type, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) 						commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) 		/* Make sure that the SHUTDOWN chunk has a valid length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) 		if (!sctp_chunk_length_valid(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) 				chunk, sizeof(struct sctp_shutdown_chunk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) 			return sctp_sf_violation_chunklen(net, ep, asoc, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603) 							  arg, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) 	/* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) 	 * shall send a SHUTDOWN ACK ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) 	reply = sctp_make_shutdown_ack(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) 	if (!reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) 	/* Set the transport for the SHUTDOWN ACK chunk and the timeout for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) 	 * the T2-shutdown timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) 	sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) 	/* and start/restart a T2-shutdown timer of its own, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) 	if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) 				SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) 	/* Enter the SHUTDOWN-ACK-SENT state.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) 			SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) 	/* sctp-implguide 2.10 Issues with Heartbeating and failover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) 	 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) 	 * or SHUTDOWN-ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) 	sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646)  * Ignore the event defined as other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648)  * The return value is the disposition of the event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) enum sctp_disposition sctp_sf_ignore_other(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) 	pr_debug("%s: the event other type:%d is ignored\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) 		 __func__, type.other);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) 	return SCTP_DISPOSITION_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) /************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664)  * These are the state functions for handling timeout events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665)  ************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668)  * RTX Timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670)  * Section: 6.3.3 Handle T3-rtx Expiration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672)  * Whenever the retransmission timer T3-rtx expires for a destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673)  * address, do the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674)  * [See below]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) enum sctp_disposition sctp_sf_do_6_3_3_rtx(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) 	struct sctp_transport *transport = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) 	SCTP_INC_STATS(net, SCTP_MIB_T3_RTX_EXPIREDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) 	if (asoc->overall_error_count >= asoc->max_retrans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) 		if (asoc->peer.zero_window_announced &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) 		    asoc->state == SCTP_STATE_SHUTDOWN_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) 			 * We are here likely because the receiver had its rwnd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) 			 * closed for a while and we have not been able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) 			 * transmit the locally queued data within the maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) 			 * retransmission attempts limit.  Start the T5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) 			 * shutdown guard timer to give the receiver one last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) 			 * chance and some additional time to recover before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) 			 * aborting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) 			sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START_ONCE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) 				SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) 			sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) 					SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) 			/* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) 			sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) 					SCTP_PERR(SCTP_ERROR_NO_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709) 			SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) 			SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) 			return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) 	/* E1) For the destination address for which the timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) 	 * expires, adjust its ssthresh with rules defined in Section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) 	 * 7.2.3 and set the cwnd <- MTU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) 	/* E2) For the destination address for which the timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) 	 * expires, set RTO <- RTO * 2 ("back off the timer").  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) 	 * maximum value discussed in rule C7 above (RTO.max) may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) 	 * used to provide an upper bound to this doubling operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) 	/* E3) Determine how many of the earliest (i.e., lowest TSN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) 	 * outstanding DATA chunks for the address for which the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) 	 * T3-rtx has expired will fit into a single packet, subject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) 	 * to the MTU constraint for the path corresponding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) 	 * destination transport address to which the retransmission
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) 	 * is being sent (this may be different from the address for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) 	 * which the timer expires [see Section 6.4]).  Call this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) 	 * value K. Bundle and retransmit those K DATA chunks in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) 	 * single packet to the destination endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) 	 * Note: Any DATA chunks that were sent to the address for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) 	 * which the T3-rtx timer expired but did not fit in one MTU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) 	 * (rule E3 above), should be marked for retransmission and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739) 	 * sent as soon as cwnd allows (normally when a SACK arrives).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) 	/* Do some failure management (Section 8.2). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) 	sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) 	/* NB: Rules E4 and F1 are implicit in R1.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) 	sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752)  * Generate delayed SACK on timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754)  * Section: 6.2  Acknowledgement on Reception of DATA Chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756)  * The guidelines on delayed acknowledgement algorithm specified in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757)  * Section 4.2 of [RFC2581] SHOULD be followed.  Specifically, an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758)  * acknowledgement SHOULD be generated for at least every second packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759)  * (not every second DATA chunk) received, and SHOULD be generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760)  * within 200 ms of the arrival of any unacknowledged DATA chunk.  In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761)  * some situations it may be beneficial for an SCTP transmitter to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762)  * more conservative than the algorithms detailed in this document
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763)  * allow. However, an SCTP transmitter MUST NOT be more aggressive than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764)  * the following algorithms allow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) enum sctp_disposition sctp_sf_do_6_2_sack(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) 					  const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) 					  const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) 					  const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) 					  void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) 					  struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) 	SCTP_INC_STATS(net, SCTP_MIB_DELAY_SACK_EXPIREDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) 	sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779)  * sctp_sf_t1_init_timer_expire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781)  * Section: 4 Note: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782)  * Verification Tag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786)  *  RFC 2960 Section 4 Notes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787)  *  2) If the T1-init timer expires, the endpoint MUST retransmit INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788)  *     and re-start the T1-init timer without changing state.  This MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789)  *     be repeated up to 'Max.Init.Retransmits' times.  After that, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790)  *     endpoint MUST abort the initialization process and report the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791)  *     error to SCTP user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794)  * (timers, events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797) enum sctp_disposition sctp_sf_t1_init_timer_expire(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) 	int attempts = asoc->init_err_counter + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) 	struct sctp_chunk *repl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) 	struct sctp_bind_addr *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) 	pr_debug("%s: timer T1 expired (INIT)\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) 	SCTP_INC_STATS(net, SCTP_MIB_T1_INIT_EXPIREDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) 	if (attempts <= asoc->max_init_attempts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) 		bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) 		repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) 		if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) 			return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) 		/* Choose transport for INIT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) 		sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) 				SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) 		/* Issue a sideeffect to do the needed accounting. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) 		sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) 				SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) 		pr_debug("%s: giving up on INIT, attempts:%d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) 			 "max_init_attempts:%d\n", __func__, attempts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) 			 asoc->max_init_attempts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) 				SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) 		sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) 				SCTP_PERR(SCTP_ERROR_NO_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) 		return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844)  * sctp_sf_t1_cookie_timer_expire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846)  * Section: 4 Note: 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847)  * Verification Tag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849)  * (endpoint, asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851)  *  RFC 2960 Section 4 Notes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852)  *  3) If the T1-cookie timer expires, the endpoint MUST retransmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853)  *     COOKIE ECHO and re-start the T1-cookie timer without changing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854)  *     state.  This MUST be repeated up to 'Max.Init.Retransmits' times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855)  *     After that, the endpoint MUST abort the initialization process and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856)  *     report the error to SCTP user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858)  * Outputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859)  * (timers, events)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) enum sctp_disposition sctp_sf_t1_cookie_timer_expire(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) 	int attempts = asoc->init_err_counter + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) 	struct sctp_chunk *repl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) 	pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) 	SCTP_INC_STATS(net, SCTP_MIB_T1_COOKIE_EXPIREDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) 	if (attempts <= asoc->max_init_attempts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) 		repl = sctp_make_cookie_echo(asoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879) 		if (!repl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) 			return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) 		sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) 				SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) 		/* Issue a sideeffect to do the needed accounting. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) 		sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) 				SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) 				SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) 		sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) 				SCTP_PERR(SCTP_ERROR_NO_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) 		return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901)  * with the updated last sequential TSN received from its peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903)  * An endpoint should limit the number of retransmissions of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904)  * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905)  * If this threshold is exceeded the endpoint should destroy the TCB and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906)  * MUST report the peer endpoint unreachable to the upper layer (and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907)  * thus the association enters the CLOSED state).  The reception of any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908)  * packet from its peer (i.e. as the peer sends all of its queued DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909)  * chunks) should clear the endpoint's retransmission count and restart
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910)  * the T2-Shutdown timer,  giving its peer ample opportunity to transmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911)  * all of its queued DATA chunks that have not yet been sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) enum sctp_disposition sctp_sf_t2_timer_expire(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) 	struct sctp_chunk *reply = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) 	pr_debug("%s: timer T2 expired\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) 	SCTP_INC_STATS(net, SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) 	((struct sctp_association *)asoc)->shutdown_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) 	if (asoc->overall_error_count >= asoc->max_retrans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931) 				SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) 		/* Note:  CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) 		sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) 				SCTP_PERR(SCTP_ERROR_NO_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) 		SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) 		return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) 	switch (asoc->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) 	case SCTP_STATE_SHUTDOWN_SENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) 		reply = sctp_make_shutdown(asoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) 	case SCTP_STATE_SHUTDOWN_ACK_SENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) 		reply = sctp_make_shutdown_ack(asoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) 	if (!reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) 	/* Do some failure management (Section 8.2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) 	 * If we remove the transport an SHUTDOWN was last sent to, don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) 	 * do failure management.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) 	if (asoc->shutdown_last_sent_to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962) 		sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) 				SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) 	/* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) 	 * the T2-shutdown timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) 	sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) 	/* Restart the T2-shutdown timer.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981)  * ADDIP Section 4.1 ASCONF CHunk Procedures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982)  * If the T4 RTO timer expires the endpoint should do B1 to B5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) enum sctp_disposition sctp_sf_t4_timer_expire(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) 	struct sctp_chunk *chunk = asoc->addip_last_asconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) 	struct sctp_transport *transport = chunk->transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) 	SCTP_INC_STATS(net, SCTP_MIB_T4_RTO_EXPIREDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) 	/* ADDIP 4.1 B1) Increment the error counters and perform path failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) 	 * detection on the appropriate destination address as defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) 	 * RFC2960 [5] section 8.1 and 8.2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) 	if (transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) 		sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) 				SCTP_TRANSPORT(transport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) 	/* Reconfig T4 timer and transport. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) 	sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) 	/* ADDIP 4.1 B2) Increment the association error counters and perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) 	 * endpoint failure detection on the association as defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010) 	 * RFC2960 [5] section 8.1 and 8.2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) 	 * association error counter is incremented in SCTP_CMD_STRIKE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) 	if (asoc->overall_error_count >= asoc->max_retrans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) 		sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) 				SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) 				SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) 		sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) 				SCTP_PERR(SCTP_ERROR_NO_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) 		SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022) 		return SCTP_DISPOSITION_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025) 	/* ADDIP 4.1 B3) Back-off the destination address RTO value to which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) 	 * the ASCONF chunk was sent by doubling the RTO timer value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027) 	 * This is done in SCTP_CMD_STRIKE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) 	/* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) 	 * choose an alternate destination address (please refer to RFC2960
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) 	 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) 	 * chunk, it MUST be the same (including its serial number) as the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) 	 * ASCONF sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) 	sctp_chunk_hold(asoc->addip_last_asconf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) 			SCTP_CHUNK(asoc->addip_last_asconf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) 	/* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) 	 * destination is selected, then the RTO used will be that of the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) 	 * destination address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) 	sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) 			SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) /* sctpimpguide-05 Section 2.12.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051)  * The sender of the SHUTDOWN MAY also start an overall guard timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052)  * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053)  * At the expiration of this timer the sender SHOULD abort the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054)  * by sending an ABORT chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) enum sctp_disposition sctp_sf_t5_timer_expire(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) 	struct sctp_chunk *reply = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) 	pr_debug("%s: timer T5 expired\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) 	SCTP_INC_STATS(net, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) 	reply = sctp_make_abort(asoc, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) 	if (!reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) 	sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) 	sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) 			SCTP_ERROR(ETIMEDOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) 	sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) 			SCTP_PERR(SCTP_ERROR_NO_ERROR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) 	SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) 	SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) 	return SCTP_DISPOSITION_DELETE_TCB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) 	return SCTP_DISPOSITION_NOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) /* Handle expiration of AUTOCLOSE timer.  When the autoclose timer expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089)  * the association is automatically closed by starting the shutdown process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090)  * The work that needs to be done is same as when SHUTDOWN is initiated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091)  * the user.  So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) enum sctp_disposition sctp_sf_autoclose_timer_expire(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) 					const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) 					void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) 					struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) 	enum sctp_disposition disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) 	SCTP_INC_STATS(net, SCTP_MIB_AUTOCLOSE_EXPIREDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105) 	/* From 9.2 Shutdown of an Association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) 	 * Upon receipt of the SHUTDOWN primitive from its upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) 	 * layer, the endpoint enters SHUTDOWN-PENDING state and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) 	 * remains there until all outstanding data has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) 	 * acknowledged by its peer. The endpoint accepts no new data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) 	 * from its upper layer, but retransmits data to the far end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) 	 * if necessary to fill gaps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) 	sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) 			SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) 	disposition = SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) 	if (sctp_outq_is_empty(&asoc->outqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) 		disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) 							    NULL, commands);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) 	return disposition;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) /*****************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126)  * These are sa state functions which could apply to all types of events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127)  ****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130)  * This table entry is not implemented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) enum sctp_disposition sctp_sf_not_impl(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) 				       const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) 				       const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) 				       const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) 				       void *arg, struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) 	return SCTP_DISPOSITION_NOT_IMPL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147)  * This table entry represents a bug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) enum sctp_disposition sctp_sf_bug(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) 				  const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) 				  const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) 				  const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) 				  void *arg, struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) 	return SCTP_DISPOSITION_BUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164)  * This table entry represents the firing of a timer in the wrong state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165)  * Since timer deletion cannot be guaranteed a timer 'may' end up firing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166)  * when the association is in the wrong state.   This event should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167)  * be ignored, so as to prevent any rearming of the timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169)  * Inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170)  * (endpoint, asoc, chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172)  * The return value is the disposition of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) enum sctp_disposition sctp_sf_timer_ignore(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) 					   const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) 					   const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) 					   const union sctp_subtype type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) 					   void *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) 					   struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) 	pr_debug("%s: timer %d ignored\n", __func__, type.chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) 	return SCTP_DISPOSITION_CONSUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) /********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187)  * 2nd Level Abstractions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188)  ********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) /* Pull the SACK chunk based on the SACK header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) 	struct sctp_sackhdr *sack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) 	__u16 num_dup_tsns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) 	__u16 num_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) 	/* Protect ourselves from reading too far into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) 	 * the skb from a bogus sender.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) 	sack = (struct sctp_sackhdr *) chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) 	num_blocks = ntohs(sack->num_gap_ack_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) 	num_dup_tsns = ntohs(sack->num_dup_tsns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) 	len = sizeof(struct sctp_sackhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) 	len += (num_blocks + num_dup_tsns) * sizeof(__u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) 	if (len > chunk->skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) 	skb_pull(chunk->skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) 	return sack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) /* Create an ABORT packet to be sent as a response, with the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216)  * error causes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) static struct sctp_packet *sctp_abort_pkt_new(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) 					const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) 					struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) 					const void *payload, size_t paylen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) 	struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) 	struct sctp_chunk *abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) 	packet = sctp_ootb_pkt_new(net, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230) 	if (packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) 		/* Make an ABORT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) 		 * The T bit will be set if the asoc is NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) 		abort = sctp_make_abort(asoc, chunk, paylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) 		if (!abort) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236) 			sctp_ootb_pkt_free(packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) 		/* Reflect vtag if T-Bit is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) 		if (sctp_test_T_bit(abort))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242) 			packet->vtag = ntohl(chunk->sctp_hdr->vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) 		/* Add specified error causes, i.e., payload, to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) 		 * end of the chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247) 		sctp_addto_chunk(abort, paylen, payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) 		/* Set the skb to the belonging sock for accounting.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250) 		abort->skb->sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) 		sctp_packet_append_chunk(packet, abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256) 	return packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) /* Allocate a packet for responding in the OOTB conditions.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) static struct sctp_packet *sctp_ootb_pkt_new(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261) 					struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) 					const struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266) 	struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267) 	__u16 sport, dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268) 	__u32 vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) 	/* Get the source and destination port from the inbound packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271) 	sport = ntohs(chunk->sctp_hdr->dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) 	dport = ntohs(chunk->sctp_hdr->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274) 	/* The V-tag is going to be the same as the inbound packet if no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) 	 * association exists, otherwise, use the peer's vtag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277) 	if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) 		/* Special case the INIT-ACK as there is no peer's vtag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) 		 * yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281) 		switch (chunk->chunk_hdr->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) 		case SCTP_CID_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) 		case SCTP_CID_INIT_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285) 			struct sctp_initack_chunk *initack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) 			initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) 			vtag = ntohl(initack->init_hdr.init_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) 			vtag = asoc->peer.i.init_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) 		/* Special case the INIT and stale COOKIE_ECHO as there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) 		 * vtag yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) 		switch (chunk->chunk_hdr->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) 		case SCTP_CID_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302) 			struct sctp_init_chunk *init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) 			init = (struct sctp_init_chunk *)chunk->chunk_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) 			vtag = ntohl(init->init_hdr.init_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) 			vtag = ntohl(chunk->sctp_hdr->vtag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) 	/* Make a transport for the bucket, Eliza... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) 	transport = sctp_transport_new(net, sctp_source(chunk), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316) 	if (!transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) 		goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) 	/* Cache a route for the transport with the chunk's destination as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) 	 * the source address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322) 	sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) 			     sctp_sk(net->sctp.ctl_sock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) 	packet = &transport->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326) 	sctp_packet_init(packet, transport, sport, dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) 	sctp_packet_config(packet, vtag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) 	return packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335) /* Free the packet allocated earlier for responding in the OOTB condition.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) void sctp_ootb_pkt_free(struct sctp_packet *packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338) 	sctp_transport_free(packet->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) static void sctp_send_stale_cookie_err(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) 				       const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) 				       const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) 				       const struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) 				       struct sctp_cmd_seq *commands,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) 				       struct sctp_chunk *err_chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349) 	struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) 	if (err_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352) 		packet = sctp_ootb_pkt_new(net, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) 		if (packet) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354) 			struct sctp_signed_cookie *cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) 			/* Override the OOTB vtag from the cookie. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357) 			cookie = chunk->subh.cookie_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) 			packet->vtag = cookie->c.peer_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360) 			/* Set the skb to the belonging sock for accounting. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) 			err_chunk->skb->sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362) 			sctp_packet_append_chunk(packet, err_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) 			sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364) 					SCTP_PACKET(packet));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) 			SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367) 			sctp_chunk_free (err_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) /* Process a data chunk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) static int sctp_eat_data(const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374) 			 struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375) 			 struct sctp_cmd_seq *commands)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) 	struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) 	struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379) 	struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) 	struct sctp_datahdr *data_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) 	struct sctp_chunk *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382) 	enum sctp_verb deliver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383) 	size_t datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) 	__u32 tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) 	int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) 	data_hdr = (struct sctp_datahdr *)chunk->skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) 	chunk->subh.data_hdr = data_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) 	skb_pull(chunk->skb, sctp_datahdr_len(&asoc->stream));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) 	tsn = ntohl(data_hdr->tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392) 	pr_debug("%s: TSN 0x%x\n", __func__, tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) 	/* ASSERT:  Now skb->data is really the user data.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) 	/* Process ECN based congestion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398) 	 * Since the chunk structure is reused for all chunks within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) 	 * a packet, we use ecn_ce_done to track if we've already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400) 	 * done CE processing for this packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) 	 * We need to do ECN processing even if we plan to discard the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) 	 * chunk later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) 	if (asoc->peer.ecn_capable && !chunk->ecn_ce_done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) 		struct sctp_af *af = SCTP_INPUT_CB(chunk->skb)->af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) 		chunk->ecn_ce_done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410) 		if (af->is_ce(sctp_gso_headskb(chunk->skb))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411) 			/* Do real work as sideffect. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412) 			sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413) 					SCTP_U32(tsn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) 	tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) 	if (tmp < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) 		/* The TSN is too high--silently discard the chunk and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) 		 * count on it getting retransmitted later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) 		if (chunk->asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) 			chunk->asoc->stats.outofseqtsns++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) 		return SCTP_IERROR_HIGH_TSN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) 	} else if (tmp > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) 		/* This is a duplicate.  Record it.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) 		return SCTP_IERROR_DUP_TSN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) 	/* This is a new TSN.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) 	/* Discard if there is no room in the receive window.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434) 	 * Actually, allow a little bit of overflow (up to a MTU).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436) 	datalen = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437) 	datalen -= sctp_datachk_len(&asoc->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439) 	deliver = SCTP_CMD_CHUNK_ULP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441) 	/* Think about partial delivery. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442) 	if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) 		/* Even if we don't accept this chunk there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) 		 * memory pressure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) 		sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450) 	/* Spill over rwnd a little bit.  Note: While allowed, this spill over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) 	 * seems a bit troublesome in that frag_point varies based on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) 	 * PMTU.  In cases, such as loopback, this might be a rather
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) 	 * large spill over.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455) 	if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) 	    (datalen > asoc->rwnd + asoc->frag_point))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458) 		/* If this is the next TSN, consider reneging to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459) 		 * room.   Note: Playing nice with a confused sender.  A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460) 		 * malicious sender can still eat up all our buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461) 		 * space and in the future we may want to detect and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462) 		 * do more drastic reneging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464) 		if (sctp_tsnmap_has_gap(map) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465) 		    (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466) 			pr_debug("%s: reneging for tsn:%u\n", __func__, tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467) 			deliver = SCTP_CMD_RENEGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469) 			pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470) 				 __func__, tsn, datalen, asoc->rwnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) 			return SCTP_IERROR_IGNORE_TSN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) 	 * Also try to renege to limit our memory usage in the event that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) 	 * we are under memory pressure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) 	 * If we can't renege, don't worry about it, the sk_rmem_schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480) 	 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) 	 * memory usage too much
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483) 	if (sk_under_memory_pressure(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) 		if (sctp_tsnmap_has_gap(map) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485) 		    (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) 			pr_debug("%s: under pressure, reneging for tsn:%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487) 				 __func__, tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488) 			deliver = SCTP_CMD_RENEGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490) 			sk_mem_reclaim(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495) 	 * Section 3.3.10.9 No User Data (9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497) 	 * Cause of error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498) 	 * ---------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499) 	 * No User Data:  This error cause is returned to the originator of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500) 	 * DATA chunk if a received DATA chunk has no user data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502) 	if (unlikely(0 == datalen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503) 		err = sctp_make_abort_no_data(asoc, chunk, tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506) 					SCTP_CHUNK(err));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) 		/* We are going to ABORT, so we might as well stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) 		 * processing the rest of the chunks in the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) 		sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) 		sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) 				SCTP_ERROR(ECONNABORTED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) 		sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515) 				SCTP_PERR(SCTP_ERROR_NO_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) 		SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) 		SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518) 		return SCTP_IERROR_NO_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) 	chunk->data_accepted = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) 	/* Note: Some chunks may get overcounted (if we drop) or overcounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) 	 * if we renege and the chunk arrives again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526) 	if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) 		SCTP_INC_STATS(net, SCTP_MIB_INUNORDERCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528) 		if (chunk->asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) 			chunk->asoc->stats.iuodchunks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531) 		SCTP_INC_STATS(net, SCTP_MIB_INORDERCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) 		if (chunk->asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) 			chunk->asoc->stats.iodchunks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536) 	/* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538) 	 * If an endpoint receive a DATA chunk with an invalid stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539) 	 * identifier, it shall acknowledge the reception of the DATA chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) 	 * following the normal procedure, immediately send an ERROR chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) 	 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) 	 * and discard the DATA chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) 	if (ntohs(data_hdr->stream) >= asoc->stream.incnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545) 		/* Mark tsn as received even though we drop it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) 		sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) 		err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) 					 &data_hdr->stream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550) 					 sizeof(data_hdr->stream),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) 					 sizeof(u16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553) 			sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554) 					SCTP_CHUNK(err));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) 		return SCTP_IERROR_BAD_STREAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) 	/* Check to see if the SSN is possible for this TSN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) 	 * The biggest gap we can record is 4K wide.  Since SSNs wrap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560) 	 * at an unsigned short, there is no way that an SSN can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561) 	 * wrap and for a valid TSN.  We can simply check if the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) 	 * SSN is smaller then the next expected one.  If it is, it wrapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563) 	 * and is invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) 	if (!asoc->stream.si->validate_data(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) 		return SCTP_IERROR_PROTO_VIOLATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568) 	/* Send the data up to the user.  Note:  Schedule  the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) 	 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) 	 * chunk needs the updated rwnd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) 	sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) 	return SCTP_IERROR_NO_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575) }