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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  net/dccp/input.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  An implementation of the DCCP protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Arnaldo Carvalho de Melo <acme@conectiva.com.br>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/dccp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "ackvec.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "ccid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "dccp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /* rate-limit for syncs in reply to sequence-invalid packets; RFC 4340, 7.5.4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) int sysctl_dccp_sync_ratelimit	__read_mostly = HZ / 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static void dccp_enqueue_skb(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	__skb_pull(skb, dccp_hdr(skb)->dccph_doff * 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	__skb_queue_tail(&sk->sk_receive_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	skb_set_owner_r(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	sk->sk_data_ready(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static void dccp_fin(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	 * On receiving Close/CloseReq, both RD/WR shutdown are performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	 * RFC 4340, 8.3 says that we MAY send further Data/DataAcks after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	 * receiving the closing segment, but there is no guarantee that such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	 * data will be processed at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	sk->sk_shutdown = SHUTDOWN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	sock_set_flag(sk, SOCK_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	dccp_enqueue_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int dccp_rcv_close(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	switch (sk->sk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	 * We ignore Close when received in one of the following states:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 *  - CLOSED		(may be a late or duplicate packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 *  - PASSIVE_CLOSEREQ	(the peer has sent a CloseReq earlier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 *  - RESPOND		(already handled by dccp_check_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	case DCCP_CLOSING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		 * Simultaneous-close: receiving a Close after sending one. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		 * can happen if both client and server perform active-close and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		 * will result in an endless ping-pong of crossing and retrans-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		 * mitted Close packets, which only terminates when one of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		 * nodes times out (min. 64 seconds). Quicker convergence can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		 * achieved when one of the nodes acts as tie-breaker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		 * This is ok as both ends are done with data transfer and each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		 * end is just waiting for the other to acknowledge termination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		if (dccp_sk(sk)->dccps_role != DCCP_ROLE_CLIENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	case DCCP_REQUESTING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	case DCCP_ACTIVE_CLOSEREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		dccp_send_reset(sk, DCCP_RESET_CODE_CLOSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		dccp_done(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	case DCCP_OPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	case DCCP_PARTOPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		/* Give waiting application a chance to read pending data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		dccp_fin(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		dccp_set_state(sk, DCCP_PASSIVE_CLOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	case DCCP_PASSIVE_CLOSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		 * Retransmitted Close: we have already enqueued the first one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int dccp_rcv_closereq(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 *   Step 7: Check for unexpected packet types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 *      If (S.is_server and P.type == CloseReq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	 *	  Send Sync packet acknowledging P.seqno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 *	  Drop packet and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (dccp_sk(sk)->dccps_role != DCCP_ROLE_CLIENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq, DCCP_PKT_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	/* Step 13: process relevant Client states < CLOSEREQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	switch (sk->sk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	case DCCP_REQUESTING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		dccp_send_close(sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		dccp_set_state(sk, DCCP_CLOSING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	case DCCP_OPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	case DCCP_PARTOPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		/* Give waiting application a chance to read pending data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		dccp_fin(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		dccp_set_state(sk, DCCP_PASSIVE_CLOSEREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case DCCP_PASSIVE_CLOSEREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static u16 dccp_reset_code_convert(const u8 code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	static const u16 error_code[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	[DCCP_RESET_CODE_CLOSED]	     = 0,	/* normal termination */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	[DCCP_RESET_CODE_UNSPECIFIED]	     = 0,	/* nothing known */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	[DCCP_RESET_CODE_ABORTED]	     = ECONNRESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	[DCCP_RESET_CODE_NO_CONNECTION]	     = ECONNREFUSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	[DCCP_RESET_CODE_CONNECTION_REFUSED] = ECONNREFUSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	[DCCP_RESET_CODE_TOO_BUSY]	     = EUSERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	[DCCP_RESET_CODE_AGGRESSION_PENALTY] = EDQUOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	[DCCP_RESET_CODE_PACKET_ERROR]	     = ENOMSG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	[DCCP_RESET_CODE_BAD_INIT_COOKIE]    = EBADR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	[DCCP_RESET_CODE_BAD_SERVICE_CODE]   = EBADRQC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	[DCCP_RESET_CODE_OPTION_ERROR]	     = EILSEQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	[DCCP_RESET_CODE_MANDATORY_ERROR]    = EOPNOTSUPP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	return code >= DCCP_MAX_RESET_CODES ? 0 : error_code[code];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static void dccp_rcv_reset(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	u16 err = dccp_reset_code_convert(dccp_hdr_reset(skb)->dccph_reset_code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	sk->sk_err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* Queue the equivalent of TCP fin so that dccp_recvmsg exits the loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	dccp_fin(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (err && !sock_flag(sk, SOCK_DEAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		sk_wake_async(sk, SOCK_WAKE_IO, POLL_ERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	dccp_time_wait(sk, DCCP_TIME_WAIT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static void dccp_handle_ackvec_processing(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct dccp_ackvec *av = dccp_sk(sk)->dccps_hc_rx_ackvec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (av == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		dccp_ackvec_clear_state(av, DCCP_SKB_CB(skb)->dccpd_ack_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	dccp_ackvec_input(av, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static void dccp_deliver_input_to_ccids(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	const struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* Don't deliver to RX CCID when node has shut down read end. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (!(sk->sk_shutdown & RCV_SHUTDOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	 * Until the TX queue has been drained, we can not honour SHUT_WR, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	 * we need received feedback as input to adjust congestion control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (sk->sk_write_queue.qlen > 0 || !(sk->sk_shutdown & SEND_SHUTDOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	const struct dccp_hdr *dh = dccp_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	u64 lswl, lawl, seqno = DCCP_SKB_CB(skb)->dccpd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
^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) 	 *   Step 5: Prepare sequence numbers for Sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 *     If P.type == Sync or P.type == SyncAck,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	 *	  If S.AWL <= P.ackno <= S.AWH and P.seqno >= S.SWL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	 *	     / * P is valid, so update sequence number variables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 *		 accordingly.  After this update, P will pass the tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 *		 in Step 6.  A SyncAck is generated if necessary in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 *		 Step 15 * /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 *	     Update S.GSR, S.SWL, S.SWH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 *	  Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 *	     Drop packet and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (dh->dccph_type == DCCP_PKT_SYNC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	    dh->dccph_type == DCCP_PKT_SYNCACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (between48(ackno, dp->dccps_awl, dp->dccps_awh) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		    dccp_delta_seqno(dp->dccps_swl, seqno) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			dccp_update_gsr(sk, seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	 *   Step 6: Check sequence numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	 *      Let LSWL = S.SWL and LAWL = S.AWL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	 *      If P.type == CloseReq or P.type == Close or P.type == Reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	 *	  LSWL := S.GSR + 1, LAWL := S.GAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	 *      If LSWL <= P.seqno <= S.SWH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	 *	     and (P.ackno does not exist or LAWL <= P.ackno <= S.AWH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 *	  Update S.GSR, S.SWL, S.SWH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 *	  If P.type != Sync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 *	     Update S.GAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	lswl = dp->dccps_swl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	lawl = dp->dccps_awl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (dh->dccph_type == DCCP_PKT_CLOSEREQ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	    dh->dccph_type == DCCP_PKT_CLOSE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	    dh->dccph_type == DCCP_PKT_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		lswl = ADD48(dp->dccps_gsr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		lawl = dp->dccps_gar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (between48(seqno, lswl, dp->dccps_swh) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	    (ackno == DCCP_PKT_WITHOUT_ACK_SEQ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	     between48(ackno, lawl, dp->dccps_awh))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		dccp_update_gsr(sk, seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		if (dh->dccph_type != DCCP_PKT_SYNC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		    ackno != DCCP_PKT_WITHOUT_ACK_SEQ &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		    after48(ackno, dp->dccps_gar))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			dp->dccps_gar = ackno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		 *   Step 6: Check sequence numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		 *      Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		 *         If P.type == Reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		 *            Send Sync packet acknowledging S.GSR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		 *         Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		 *            Send Sync packet acknowledging P.seqno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		 *      Drop packet and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		 *   These Syncs are rate-limited as per RFC 4340, 7.5.4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		 *   at most 1 / (dccp_sync_rate_limit * HZ) Syncs per second.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		if (time_before(now, (dp->dccps_rate_last +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				      sysctl_dccp_sync_ratelimit)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		DCCP_WARN("Step 6 failed for %s packet, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			  "(LSWL(%llu) <= P.seqno(%llu) <= S.SWH(%llu)) and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			  "(P.ackno %s or LAWL(%llu) <= P.ackno(%llu) <= S.AWH(%llu), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			  "sending SYNC...\n",  dccp_packet_name(dh->dccph_type),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			  (unsigned long long) lswl, (unsigned long long) seqno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			  (unsigned long long) dp->dccps_swh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			  (ackno == DCCP_PKT_WITHOUT_ACK_SEQ) ? "doesn't exist"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 							      : "exists",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			  (unsigned long long) lawl, (unsigned long long) ackno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			  (unsigned long long) dp->dccps_awh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		dp->dccps_rate_last = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		if (dh->dccph_type == DCCP_PKT_RESET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			seqno = dp->dccps_gsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		dccp_send_sync(sk, seqno, DCCP_PKT_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 				  const struct dccp_hdr *dh, const unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	switch (dccp_hdr(skb)->dccph_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	case DCCP_PKT_DATAACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	case DCCP_PKT_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		 * FIXME: schedule DATA_DROPPED (RFC 4340, 11.7.2) if and when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		 * - sk_shutdown == RCV_SHUTDOWN, use Code 1, "Not Listening"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		 * - sk_receive_queue is full, use Code 2, "Receive Buffer"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		dccp_enqueue_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	case DCCP_PKT_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	case DCCP_PKT_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		 *  Step 9: Process Reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		 *	If P.type == Reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		 *		Tear down connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		 *		S.state := TIMEWAIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		 *		Set TIMEWAIT timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		 *		Drop packet and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		dccp_rcv_reset(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	case DCCP_PKT_CLOSEREQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		if (dccp_rcv_closereq(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	case DCCP_PKT_CLOSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		if (dccp_rcv_close(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	case DCCP_PKT_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		/* Step 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		 *   or (S.is_server and P.type == Response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		 *   or (S.is_client and P.type == Request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		 *   or (S.state >= OPEN and P.type == Request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		 *	and P.seqno >= S.OSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		 *    or (S.state >= OPEN and P.type == Response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		 *	and P.seqno >= S.OSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		 *    or (S.state == RESPOND and P.type == Data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		 *  Send Sync packet acknowledging P.seqno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		 *  Drop packet and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		if (dp->dccps_role != DCCP_ROLE_LISTEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			goto send_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto check_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	case DCCP_PKT_RESPONSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (dp->dccps_role != DCCP_ROLE_CLIENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			goto send_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) check_seq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		if (dccp_delta_seqno(dp->dccps_osr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 				     DCCP_SKB_CB(skb)->dccpd_seq) >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) send_sync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				       DCCP_PKT_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	case DCCP_PKT_SYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		dccp_send_sync(sk, DCCP_SKB_CB(skb)->dccpd_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			       DCCP_PKT_SYNCACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		 * From RFC 4340, sec. 5.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		 * As with DCCP-Ack packets, DCCP-Sync and DCCP-SyncAck packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		 * MAY have non-zero-length application data areas, whose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		 * contents receivers MUST ignore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	DCCP_INC_STATS(DCCP_MIB_INERRS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	__kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			 const struct dccp_hdr *dh, const unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (dccp_check_seqno(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (dccp_parse_options(sk, NULL, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	dccp_handle_ackvec_processing(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	dccp_deliver_input_to_ccids(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	return __dccp_rcv_established(sk, skb, dh, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	__kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) EXPORT_SYMBOL_GPL(dccp_rcv_established);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int dccp_rcv_request_sent_state_process(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 					       struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 					       const struct dccp_hdr *dh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 					       const unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	 *  Step 4: Prepare sequence numbers in REQUEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	 *     If S.state == REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	 *	  If (P.type == Response or P.type == Reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	 *		and S.AWL <= P.ackno <= S.AWH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	 *	     / * Set sequence number variables corresponding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	 *		other endpoint, so P will pass the tests in Step 6 * /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	 *	     Set S.GSR, S.ISR, S.SWL, S.SWH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	 *	     / * Response processing continues in Step 10; Reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	 *		processing continues in Step 9 * /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	if (dh->dccph_type == DCCP_PKT_RESPONSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		const struct inet_connection_sock *icsk = inet_csk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		long tstamp = dccp_timestamp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		if (!between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			       dp->dccps_awl, dp->dccps_awh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			dccp_pr_debug("invalid ackno: S.AWL=%llu, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 				      "P.ackno=%llu, S.AWH=%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 				      (unsigned long long)dp->dccps_awl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 			   (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 				      (unsigned long long)dp->dccps_awh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			goto out_invalid_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		 * If option processing (Step 8) failed, return 1 here so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		 * dccp_v4_do_rcv() sends a Reset. The Reset code depends on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		 * the option type and is set in dccp_parse_options().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		if (dccp_parse_options(sk, NULL, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		/* Obtain usec RTT sample from SYN exchange (used by TFRC). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (likely(dp->dccps_options_received.dccpor_timestamp_echo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			dp->dccps_syn_rtt = dccp_sample_rtt(sk, 10 * (tstamp -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			    dp->dccps_options_received.dccpor_timestamp_echo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		/* Stop the REQUEST timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		WARN_ON(sk->sk_send_head == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		kfree_skb(sk->sk_send_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		sk->sk_send_head = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		 * Set ISR, GSR from packet. ISS was set in dccp_v{4,6}_connect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		 * and GSS in dccp_transmit_skb(). Setting AWL/AWH and SWL/SWH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		 * is done as part of activating the feature values below, since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		 * these settings depend on the local/remote Sequence Window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		 * features, which were undefined or not confirmed until now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		dp->dccps_gsr = dp->dccps_isr = DCCP_SKB_CB(skb)->dccpd_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		dccp_sync_mss(sk, icsk->icsk_pmtu_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		 *    Step 10: Process REQUEST state (second part)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		 *       If S.state == REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		 *	  / * If we get here, P is a valid Response from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		 *	      server (see Step 4), and we should move to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		 *	      PARTOPEN state. PARTOPEN means send an Ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		 *	      don't send Data packets, retransmit Acks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		 *	      periodically, and always include any Init Cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		 *	      from the Response * /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		 *	  S.state := PARTOPEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		 *	  Set PARTOPEN timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		 *	  Continue with S.state == PARTOPEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		 *	  / * Step 12 will send the Ack completing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		 *	      three-way handshake * /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		dccp_set_state(sk, DCCP_PARTOPEN);
^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) 		 * If feature negotiation was successful, activate features now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		 * an activation failure means that this host could not activate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		 * one ore more features (e.g. insufficient memory), which would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		 * leave at least one feature in an undefined state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		if (dccp_feat_activate_values(sk, &dp->dccps_featneg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 			goto unable_to_proceed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		/* Make sure socket is routed, for correct metrics. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		icsk->icsk_af_ops->rebuild_header(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		if (!sock_flag(sk, SOCK_DEAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		if (sk->sk_write_pending || inet_csk_in_pingpong_mode(sk) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		    icsk->icsk_accept_queue.rskq_defer_accept) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			/* Save one ACK. Data will be ready after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			 * several ticks, if write_pending is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			 * It may be deleted, but with this feature tcpdumps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			 * look so _wonderfully_ clever, that I was not able
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			 * to stand against the temptation 8)     --ANK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			 * OK, in DCCP we can as well do a similar trick, its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 			 * even in the draft, but there is no need for us to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 			 * schedule an ack here, as dccp_sendmsg does this for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			 * us, also stated in the draft. -acme
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			__kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		dccp_send_ack(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) out_invalid_packet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	/* dccp_v4_do_rcv will send a reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) unable_to_proceed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_ABORTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	 * We mark this socket as no longer usable, so that the loop in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	 * dccp_sendmsg() terminates and the application gets notified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	dccp_set_state(sk, DCCP_CLOSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	sk->sk_err = ECOMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static int dccp_rcv_respond_partopen_state_process(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 						   struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 						   const struct dccp_hdr *dh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 						   const unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	u32 sample = dp->dccps_options_received.dccpor_timestamp_echo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	switch (dh->dccph_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	case DCCP_PKT_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	case DCCP_PKT_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		if (sk->sk_state == DCCP_RESPOND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	case DCCP_PKT_DATAACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	case DCCP_PKT_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		 * FIXME: we should be resetting the PARTOPEN (DELACK) timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		 * here but only if we haven't used the DELACK timer for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		 * something else, like sending a delayed ack for a TIMESTAMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		 * echo, etc, for now were not clearing it, sending an extra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		 * ACK when there is nothing else to do in DELACK is not a big
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		 * deal after all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		/* Stop the PARTOPEN timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		if (sk->sk_state == DCCP_PARTOPEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		/* Obtain usec RTT sample from SYN exchange (used by TFRC). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		if (likely(sample)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 			long delta = dccp_timestamp() - sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 			dp->dccps_syn_rtt = dccp_sample_rtt(sk, 10 * delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		dp->dccps_osr = DCCP_SKB_CB(skb)->dccpd_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		dccp_set_state(sk, DCCP_OPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		if (dh->dccph_type == DCCP_PKT_DATAACK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		    dh->dccph_type == DCCP_PKT_DATA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 			__dccp_rcv_established(sk, skb, dh, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 			queued = 1; /* packet was queued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 				       (by __dccp_rcv_established) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 			   struct dccp_hdr *dh, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	const int old_state = sk->sk_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	bool acceptable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	int queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	 *  Step 3: Process LISTEN state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	 *     If S.state == LISTEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	 *	 If P.type == Request or P contains a valid Init Cookie option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	 *	      (* Must scan the packet's options to check for Init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	 *		 Cookies.  Only Init Cookies are processed here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	 *		 however; other options are processed in Step 8.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	 *		 scan need only be performed if the endpoint uses Init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	 *		 Cookies *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	 *	      (* Generate a new socket and switch to that socket *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	 *	      Set S := new socket for this port pair
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	 *	      S.state = RESPOND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	 *	      Choose S.ISS (initial seqno) or set from Init Cookies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	 *	      Initialize S.GAR := S.ISS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	 *	      Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	 *	      Cookies Continue with S.state == RESPOND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	 *	      (* A Response packet will be generated in Step 11 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	 *	 Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	 *	      Generate Reset(No Connection) unless P.type == Reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	 *	      Drop packet and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	if (sk->sk_state == DCCP_LISTEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		if (dh->dccph_type == DCCP_PKT_REQUEST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 			/* It is possible that we process SYN packets from backlog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 			 * so we need to make sure to disable BH and RCU right there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 			local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 			acceptable = inet_csk(sk)->icsk_af_ops->conn_request(sk, skb) >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 			local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 			if (!acceptable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 				return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 			consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		if (dh->dccph_type == DCCP_PKT_RESET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 			goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		/* Caller (dccp_v4_do_rcv) will send Reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	} else if (sk->sk_state == DCCP_CLOSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	/* Step 6: Check sequence numbers (omitted in LISTEN/REQUEST state) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	if (sk->sk_state != DCCP_REQUESTING && dccp_check_seqno(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	 *   Step 7: Check for unexpected packet types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	 *      If (S.is_server and P.type == Response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	 *	    or (S.is_client and P.type == Request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	 *	    or (S.state == RESPOND and P.type == Data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	 *	  Send Sync packet acknowledging P.seqno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	 *	  Drop packet and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	if ((dp->dccps_role != DCCP_ROLE_CLIENT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	     dh->dccph_type == DCCP_PKT_RESPONSE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	    (dp->dccps_role == DCCP_ROLE_CLIENT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	     dh->dccph_type == DCCP_PKT_REQUEST) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	    (sk->sk_state == DCCP_RESPOND && dh->dccph_type == DCCP_PKT_DATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	/*  Step 8: Process options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	if (dccp_parse_options(sk, NULL, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	 *  Step 9: Process Reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	 *	If P.type == Reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	 *		Tear down connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	 *		S.state := TIMEWAIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	 *		Set TIMEWAIT timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	 *		Drop packet and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	if (dh->dccph_type == DCCP_PKT_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		dccp_rcv_reset(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	} else if (dh->dccph_type == DCCP_PKT_CLOSEREQ) {	/* Step 13 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		if (dccp_rcv_closereq(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	} else if (dh->dccph_type == DCCP_PKT_CLOSE) {		/* Step 14 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		if (dccp_rcv_close(sk, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	switch (sk->sk_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	case DCCP_REQUESTING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		queued = dccp_rcv_request_sent_state_process(sk, skb, dh, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		if (queued >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 			return queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		__kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	case DCCP_PARTOPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		/* Step 8: if using Ack Vectors, mark packet acknowledgeable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		dccp_handle_ackvec_processing(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		dccp_deliver_input_to_ccids(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	case DCCP_RESPOND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		queued = dccp_rcv_respond_partopen_state_process(sk, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 								 dh, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	if (dh->dccph_type == DCCP_PKT_ACK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	    dh->dccph_type == DCCP_PKT_DATAACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		switch (old_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		case DCCP_PARTOPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 			sk->sk_state_change(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 			sk_wake_async(sk, SOCK_WAKE_IO, POLL_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	} else if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNCACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 		goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	if (!queued) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 		__kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) EXPORT_SYMBOL_GPL(dccp_rcv_state_process);
^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)  *  dccp_sample_rtt  -  Validate and finalise computation of RTT sample
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)  *  @sk:	socket structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)  *  @delta:	number of microseconds between packet and acknowledgment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)  *  The routine is kept generic to work in different contexts. It should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)  *  called immediately when the ACK used for the RTT sample arrives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) u32 dccp_sample_rtt(struct sock *sk, long delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	/* dccpor_elapsed_time is either zeroed out or set and > 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	delta -= dccp_sk(sk)->dccps_options_received.dccpor_elapsed_time * 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	if (unlikely(delta <= 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		DCCP_WARN("unusable RTT sample %ld, using min\n", delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		return DCCP_SANE_RTT_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	if (unlikely(delta > DCCP_SANE_RTT_MAX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		DCCP_WARN("RTT sample %ld too large, using max\n", delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 		return DCCP_SANE_RTT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	return delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }