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/output.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/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <net/inet_sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "ackvec.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "ccid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "dccp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static inline void dccp_event_ack_sent(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* enqueue @skb on sk_send_head for retransmission, return clone to send now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct sk_buff *dccp_skb_entail(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	skb_set_owner_w(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	WARN_ON(sk->sk_send_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	sk->sk_send_head = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	return skb_clone(sk->sk_send_head, gfp_any());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * All SKB's seen here are completely headerless. It is our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * job to build the DCCP header, and pass the packet down to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * IP so it can do the same plus pass the packet off to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (likely(skb != NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		const struct inet_connection_sock *icsk = inet_csk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		struct dccp_hdr *dh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		/* XXX For now we're using only 48 bits sequence numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		const u32 dccp_header_size = sizeof(*dh) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 					     sizeof(struct dccp_hdr_ext) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 					  dccp_packet_hdr_len(dcb->dccpd_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		int err, set_ack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		u64 ackno = dp->dccps_gsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		 * Increment GSS here already in case the option code needs it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		 * Update GSS for real only if option processing below succeeds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		dcb->dccpd_seq = ADD48(dp->dccps_gss, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		switch (dcb->dccpd_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		case DCCP_PKT_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			set_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		case DCCP_PKT_DATAACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		case DCCP_PKT_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		case DCCP_PKT_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			set_ack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			/* Use ISS on the first (non-retransmitted) Request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			if (icsk->icsk_retransmits == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				dcb->dccpd_seq = dp->dccps_iss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		case DCCP_PKT_SYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		case DCCP_PKT_SYNCACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			ackno = dcb->dccpd_ack_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			 * Set owner/destructor: some skbs are allocated via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			 * alloc_skb (e.g. when retransmission may happen).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			 * Only Data, DataAck, and Reset packets should come
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			 * through here with skb->sk set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			WARN_ON(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			skb_set_owner_w(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		if (dccp_insert_options(sk, skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		/* Build DCCP header and checksum it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		dh = dccp_zeroed_hdr(skb, dccp_header_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		dh->dccph_type	= dcb->dccpd_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		dh->dccph_sport	= inet->inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		dh->dccph_dport	= inet->inet_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		dh->dccph_doff	= (dccp_header_size + dcb->dccpd_opt_len) / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		dh->dccph_ccval	= dcb->dccpd_ccval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		dh->dccph_cscov = dp->dccps_pcslen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		/* XXX For now we're using only 48 bits sequence numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		dh->dccph_x	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		dccp_update_gss(sk, dcb->dccpd_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		dccp_hdr_set_seq(dh, dp->dccps_gss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		if (set_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), ackno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		switch (dcb->dccpd_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		case DCCP_PKT_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			dccp_hdr_request(skb)->dccph_req_service =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 							dp->dccps_service;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			 * Limit Ack window to ISS <= P.ackno <= GSS, so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			 * only Responses to Requests we sent are considered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			dp->dccps_awl = dp->dccps_iss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		case DCCP_PKT_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			dccp_hdr_reset(skb)->dccph_reset_code =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 							dcb->dccpd_reset_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		icsk->icsk_af_ops->send_check(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (set_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			dccp_event_ack_sent(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		err = icsk->icsk_af_ops->queue_xmit(sk, skb, &inet->cork.fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return net_xmit_eval(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^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)  * dccp_determine_ccmps  -  Find out about CCID-specific packet-size limits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * We only consider the HC-sender CCID for setting the CCMPS (RFC 4340, 14.),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * since the RX CCID is restricted to feedback packets (Acks), which are small
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * in comparison with the data traffic. A value of 0 means "no current CCMPS".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static u32 dccp_determine_ccmps(const struct dccp_sock *dp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	const struct ccid *tx_ccid = dp->dccps_hc_tx_ccid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (tx_ccid == NULL || tx_ccid->ccid_ops == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return tx_ccid->ccid_ops->ccid_ccmps;
^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) unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct inet_connection_sock *icsk = inet_csk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	u32 ccmps = dccp_determine_ccmps(dp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	u32 cur_mps = ccmps ? min(pmtu, ccmps) : pmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* Account for header lengths and IPv4/v6 option overhead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	cur_mps -= (icsk->icsk_af_ops->net_header_len + icsk->icsk_ext_hdr_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		    sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	 * Leave enough headroom for common DCCP header options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	 * This only considers options which may appear on DCCP-Data packets, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 * per table 3 in RFC 4340, 5.8. When running out of space for other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * options (eg. Ack Vector which can take up to 255 bytes), it is better
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * to schedule a separate Ack. Thus we leave headroom for the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 *  - 1 byte for Slow Receiver (11.6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	 *  - 6 bytes for Timestamp (13.1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	 *  - 10 bytes for Timestamp Echo (13.3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	 *  - 8 bytes for NDP count (7.7, when activated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 *  - 6 bytes for Data Checksum (9.3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 *  - %DCCPAV_MIN_OPTLEN bytes for Ack Vector size (11.4, when enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	cur_mps -= roundup(1 + 6 + 10 + dp->dccps_send_ndp_count * 8 + 6 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			   (dp->dccps_hc_rx_ackvec ? DCCPAV_MIN_OPTLEN : 0), 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	/* And store cached results */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	icsk->icsk_pmtu_cookie = pmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	dp->dccps_mss_cache = cur_mps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return cur_mps;
^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) EXPORT_SYMBOL_GPL(dccp_sync_mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) void dccp_write_space(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct socket_wq *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	wq = rcu_dereference(sk->sk_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (skwq_has_sleeper(wq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		wake_up_interruptible(&wq->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/* Should agree with poll, otherwise some programs break */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (sock_writeable(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * dccp_wait_for_ccid  -  Await CCID send permission
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * @sk:    socket to wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * @delay: timeout in jiffies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * This is used by CCIDs which need to delay the send time in process context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int dccp_wait_for_ccid(struct sock *sk, unsigned long delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	long remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	sk->sk_write_pending++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	remaining = schedule_timeout(delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	sk->sk_write_pending--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (signal_pending(current) || sk->sk_err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return remaining;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * dccp_xmit_packet  -  Send data packet under control of CCID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * Transmits next-queued payload and informs CCID to account for the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static void dccp_xmit_packet(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	int err, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	struct sk_buff *skb = dccp_qpolicy_pop(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (unlikely(skb == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (sk->sk_state == DCCP_PARTOPEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		const u32 cur_mps = dp->dccps_mss_cache - DCCP_FEATNEG_OVERHEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		 * See 8.1.5 - Handshake Completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		 * For robustness we resend Confirm options until the client has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		 * entered OPEN. During the initial feature negotiation, the MPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		 * is smaller than usual, reduced by the Change/Confirm options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (!list_empty(&dp->dccps_featneg) && len > cur_mps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			DCCP_WARN("Payload too large (%d) for featneg.\n", len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			dccp_send_ack(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			dccp_feat_list_purge(&dp->dccps_featneg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		inet_csk_schedule_ack(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 					      inet_csk(sk)->icsk_rto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 					      DCCP_RTO_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_DATAACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	} else if (dccp_ack_pending(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_DATAACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	err = dccp_transmit_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		dccp_pr_debug("transmit_skb() returned err=%d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	 * Register this one as sent even if an error occurred. To the remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	 * end a local packet drop is indistinguishable from network loss, i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	 * any local drop will eventually be reported via receiver feedback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	ccid_hc_tx_packet_sent(dp->dccps_hc_tx_ccid, sk, len);
^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) 	 * If the CCID needs to transfer additional header options out-of-band
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	 * (e.g. Ack Vectors or feature-negotiation options), it activates this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * flag to schedule a Sync. The Sync will automatically incorporate all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 * currently pending header options, thus clearing the backlog.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (dp->dccps_sync_scheduled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		dccp_send_sync(sk, dp->dccps_gsr, DCCP_PKT_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * dccp_flush_write_queue  -  Drain queue at end of connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * Since dccp_sendmsg queues packets without waiting for them to be sent, it may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * happen that the TX queue is not empty at the end of a connection. We give the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * HC-sender CCID a grace period of up to @time_budget jiffies. If this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * returns with a non-empty write queue, it will be purged later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) void dccp_flush_write_queue(struct sock *sk, long *time_budget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	long delay, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	while (*time_budget > 0 && (skb = skb_peek(&sk->sk_write_queue))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		rc = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		switch (ccid_packet_dequeue_eval(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		case CCID_PACKET_WILL_DEQUEUE_LATER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			 * If the CCID determines when to send, the next sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			 * time is unknown or the CCID may not even send again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			 * (e.g. remote host crashes or lost Ack packets).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			DCCP_WARN("CCID did not manage to send all packets\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		case CCID_PACKET_DELAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			delay = msecs_to_jiffies(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			if (delay > *time_budget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			rc = dccp_wait_for_ccid(sk, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			*time_budget -= (delay - rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			/* check again if we can send now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		case CCID_PACKET_SEND_AT_ONCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			dccp_xmit_packet(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		case CCID_PACKET_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			skb_dequeue(&sk->sk_write_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			dccp_pr_debug("packet discarded due to err=%ld\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) void dccp_write_xmit(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	while ((skb = dccp_qpolicy_top(sk))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		int rc = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		switch (ccid_packet_dequeue_eval(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		case CCID_PACKET_WILL_DEQUEUE_LATER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		case CCID_PACKET_DELAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			sk_reset_timer(sk, &dp->dccps_xmit_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 				       jiffies + msecs_to_jiffies(rc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		case CCID_PACKET_SEND_AT_ONCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			dccp_xmit_packet(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		case CCID_PACKET_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			dccp_qpolicy_drop(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			dccp_pr_debug("packet discarded due to err=%d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  * dccp_retransmit_skb  -  Retransmit Request, Close, or CloseReq packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  * There are only four retransmittable packet types in DCCP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * - Request  in client-REQUEST  state (sec. 8.1.1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * - CloseReq in server-CLOSEREQ state (sec. 8.3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * - Close    in   node-CLOSING  state (sec. 8.3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * - Acks in client-PARTOPEN state (sec. 8.1.5, handled by dccp_delack_timer()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * This function expects sk->sk_send_head to contain the original skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) int dccp_retransmit_skb(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	WARN_ON(sk->sk_send_head == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (inet_csk(sk)->icsk_af_ops->rebuild_header(sk) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		return -EHOSTUNREACH; /* Routing failure or similar. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	/* this count is used to distinguish original and retransmitted skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	inet_csk(sk)->icsk_retransmits++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	return dccp_transmit_skb(sk, skb_clone(sk->sk_send_head, GFP_ATOMIC));
^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) struct sk_buff *dccp_make_response(const struct sock *sk, struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 				   struct request_sock *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	struct dccp_hdr *dh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct dccp_request_sock *dreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	const u32 dccp_header_size = sizeof(struct dccp_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 				     sizeof(struct dccp_hdr_ext) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 				     sizeof(struct dccp_hdr_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	/* sk is marked const to clearly express we dont hold socket lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	 * sock_wmalloc() will atomically change sk->sk_wmem_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	 * it is safe to promote sk to non const.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	skb = sock_wmalloc((struct sock *)sk, MAX_DCCP_HEADER, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			   GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	skb_reserve(skb, MAX_DCCP_HEADER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	skb_dst_set(skb, dst_clone(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	dreq = dccp_rsk(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (inet_rsk(req)->acked)	/* increase GSS upon retransmission */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		dccp_inc_seqno(&dreq->dreq_gss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESPONSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	DCCP_SKB_CB(skb)->dccpd_seq  = dreq->dreq_gss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	/* Resolve feature dependencies resulting from choice of CCID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	if (dccp_feat_server_ccid_dependencies(dreq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		goto response_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (dccp_insert_options_rsk(dreq, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		goto response_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	/* Build and checksum header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	dh = dccp_zeroed_hdr(skb, dccp_header_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	dh->dccph_sport	= htons(inet_rsk(req)->ir_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	dh->dccph_dport	= inet_rsk(req)->ir_rmt_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	dh->dccph_doff	= (dccp_header_size +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			   DCCP_SKB_CB(skb)->dccpd_opt_len) / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	dh->dccph_type	= DCCP_PKT_RESPONSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	dh->dccph_x	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	dccp_hdr_set_seq(dh, dreq->dreq_gss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dreq->dreq_gsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	dccp_hdr_response(skb)->dccph_resp_service = dreq->dreq_service;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	dccp_csum_outgoing(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	/* We use `acked' to remember that a Response was already sent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	inet_rsk(req)->acked = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	DCCP_INC_STATS(DCCP_MIB_OUTSEGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) response_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) EXPORT_SYMBOL_GPL(dccp_make_response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* answer offending packet in @rcv_skb with Reset from control socket @ctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) struct sk_buff *dccp_ctl_make_reset(struct sock *sk, struct sk_buff *rcv_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	struct dccp_hdr *rxdh = dccp_hdr(rcv_skb), *dh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	struct dccp_skb_cb *dcb = DCCP_SKB_CB(rcv_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	const u32 dccp_hdr_reset_len = sizeof(struct dccp_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 				       sizeof(struct dccp_hdr_ext) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 				       sizeof(struct dccp_hdr_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	struct dccp_hdr_reset *dhr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	skb = alloc_skb(sk->sk_prot->max_header, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	skb_reserve(skb, sk->sk_prot->max_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	/* Swap the send and the receive. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	dh = dccp_zeroed_hdr(skb, dccp_hdr_reset_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	dh->dccph_type	= DCCP_PKT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	dh->dccph_sport	= rxdh->dccph_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	dh->dccph_dport	= rxdh->dccph_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	dh->dccph_doff	= dccp_hdr_reset_len / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	dh->dccph_x	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	dhr = dccp_hdr_reset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	dhr->dccph_reset_code = dcb->dccpd_reset_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	switch (dcb->dccpd_reset_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	case DCCP_RESET_CODE_PACKET_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		dhr->dccph_reset_data[0] = rxdh->dccph_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	case DCCP_RESET_CODE_OPTION_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	case DCCP_RESET_CODE_MANDATORY_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		memcpy(dhr->dccph_reset_data, dcb->dccpd_reset_data, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	 * From RFC 4340, 8.3.1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	 *   If P.ackno exists, set R.seqno := P.ackno + 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	 *   Else set R.seqno := 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		dccp_hdr_set_seq(dh, ADD48(dcb->dccpd_ack_seq, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dcb->dccpd_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	dccp_csum_outgoing(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) EXPORT_SYMBOL_GPL(dccp_ctl_make_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /* send Reset on established socket, to close or abort the connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	 * FIXME: what if rebuild_header fails?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	 * Should we be doing a rebuild_header here?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	int err = inet_csk(sk)->icsk_af_ops->rebuild_header(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	skb = sock_wmalloc(sk, sk->sk_prot->max_header, 1, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	/* Reserve space for headers and prepare control bits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	skb_reserve(skb, sk->sk_prot->max_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	DCCP_SKB_CB(skb)->dccpd_type	   = DCCP_PKT_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	DCCP_SKB_CB(skb)->dccpd_reset_code = code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	return dccp_transmit_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  * Do all connect socket setups that can be done AF independent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) int dccp_connect(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	struct dst_entry *dst = __sk_dst_get(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	struct inet_connection_sock *icsk = inet_csk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	sk->sk_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	sock_reset_flag(sk, SOCK_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	dccp_sync_mss(sk, dst_mtu(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	/* do not connect if feature negotiation setup fails */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	if (dccp_feat_finalise_settings(dccp_sk(sk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	/* Initialise GAR as per 8.5; AWL/AWH are set in dccp_transmit_skb() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	dp->dccps_gar = dp->dccps_iss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	skb = alloc_skb(sk->sk_prot->max_header, sk->sk_allocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	if (unlikely(skb == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	/* Reserve space for headers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	skb_reserve(skb, sk->sk_prot->max_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	dccp_transmit_skb(sk, dccp_skb_entail(sk, skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	DCCP_INC_STATS(DCCP_MIB_ACTIVEOPENS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	/* Timer for repeating the REQUEST until an answer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	icsk->icsk_retransmits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 				  icsk->icsk_rto, DCCP_RTO_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) EXPORT_SYMBOL_GPL(dccp_connect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) void dccp_send_ack(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	/* If we have been reset, we may not send again. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	if (sk->sk_state != DCCP_CLOSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		struct sk_buff *skb = alloc_skb(sk->sk_prot->max_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 						GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		if (skb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 			inet_csk_schedule_ack(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 			inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 			inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 						  TCP_DELACK_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 						  DCCP_RTO_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		/* Reserve space for headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		skb_reserve(skb, sk->sk_prot->max_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		dccp_transmit_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) EXPORT_SYMBOL_GPL(dccp_send_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* FIXME: Is this still necessary (11.3) - currently nowhere used by DCCP. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) void dccp_send_delayed_ack(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	struct inet_connection_sock *icsk = inet_csk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	 * FIXME: tune this timer. elapsed time fixes the skew, so no problem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	 * with using 2s, and active senders also piggyback the ACK into a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	 * DATAACK packet, so this is really for quiescent senders.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	unsigned long timeout = jiffies + 2 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	/* Use new timeout only if there wasn't a older one earlier. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	if (icsk->icsk_ack.pending & ICSK_ACK_TIMER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		/* If delack timer was blocked or is about to expire,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		 * send ACK now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		 * FIXME: check the "about to expire" part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		if (icsk->icsk_ack.blocked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 			dccp_send_ack(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		if (!time_before(timeout, icsk->icsk_ack.timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 			timeout = icsk->icsk_ack.timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	icsk->icsk_ack.pending |= ICSK_ACK_SCHED | ICSK_ACK_TIMER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	icsk->icsk_ack.timeout = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	sk_reset_timer(sk, &icsk->icsk_delack_timer, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) void dccp_send_sync(struct sock *sk, const u64 ackno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		    const enum dccp_pkt_type pkt_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	 * We are not putting this on the write queue, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	 * dccp_transmit_skb() will set the ownership to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	 * sock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	struct sk_buff *skb = alloc_skb(sk->sk_prot->max_header, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	if (skb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		/* FIXME: how to make sure the sync is sent? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		DCCP_CRIT("could not send %s", dccp_packet_name(pkt_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	/* Reserve space for headers and prepare control bits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	skb_reserve(skb, sk->sk_prot->max_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	DCCP_SKB_CB(skb)->dccpd_type = pkt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	DCCP_SKB_CB(skb)->dccpd_ack_seq = ackno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	 * Clear the flag in case the Sync was scheduled for out-of-band data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	 * such as carrying a long Ack Vector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	dccp_sk(sk)->dccps_sync_scheduled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	dccp_transmit_skb(sk, skb);
^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) EXPORT_SYMBOL_GPL(dccp_send_sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)  * Send a DCCP_PKT_CLOSE/CLOSEREQ. The caller locks the socket for us. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)  * cannot be allowed to fail queueing a DCCP_PKT_CLOSE/CLOSEREQ frame under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)  * any circumstances.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) void dccp_send_close(struct sock *sk, const int active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	struct dccp_sock *dp = dccp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	const gfp_t prio = active ? GFP_KERNEL : GFP_ATOMIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	skb = alloc_skb(sk->sk_prot->max_header, prio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	/* Reserve space for headers and prepare control bits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	skb_reserve(skb, sk->sk_prot->max_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	if (dp->dccps_role == DCCP_ROLE_SERVER && !dp->dccps_server_timewait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_CLOSEREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_CLOSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	if (active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		skb = dccp_skb_entail(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		 * Retransmission timer for active-close: RFC 4340, 8.3 requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		 * to retransmit the Close/CloseReq until the CLOSING/CLOSEREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		 * state can be left. The initial timeout is 2 RTTs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		 * Since RTT measurement is done by the CCIDs, there is no easy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		 * way to get an RTT sample. The fallback RTT from RFC 4340, 3.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		 * is too low (200ms); we use a high value to avoid unnecessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 		 * retransmissions when the link RTT is > 0.2 seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 		 * FIXME: Let main module sample RTTs and use that instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 					  DCCP_TIMEOUT_INIT, DCCP_RTO_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	dccp_transmit_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }