18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * NET		Generic infrastructure for INET connection oriented protocols.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *		Definitions for inet_connection_sock
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Authors:	Many people, see the TCP sources
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * 		From code originally in TCP
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#ifndef _INET_CONNECTION_SOCK_H
128c2ecf20Sopenharmony_ci#define _INET_CONNECTION_SOCK_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/compiler.h>
158c2ecf20Sopenharmony_ci#include <linux/string.h>
168c2ecf20Sopenharmony_ci#include <linux/timer.h>
178c2ecf20Sopenharmony_ci#include <linux/poll.h>
188c2ecf20Sopenharmony_ci#include <linux/kernel.h>
198c2ecf20Sopenharmony_ci#include <linux/sockptr.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <net/inet_sock.h>
228c2ecf20Sopenharmony_ci#include <net/request_sock.h>
238c2ecf20Sopenharmony_ci#if defined(CONFIG_TCP_NATA_URC) || defined(CONFIG_TCP_NATA_STL)
248c2ecf20Sopenharmony_ci#include <net/nata.h>
258c2ecf20Sopenharmony_ci#include <net/inet_connection_nata.h>
268c2ecf20Sopenharmony_ci#endif
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* Cancel timers, when they are not required. */
298c2ecf20Sopenharmony_ci#undef INET_CSK_CLEAR_TIMERS
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistruct inet_bind_bucket;
328c2ecf20Sopenharmony_cistruct tcp_congestion_ops;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/*
358c2ecf20Sopenharmony_ci * Pointers to address related TCP functions
368c2ecf20Sopenharmony_ci * (i.e. things that depend on the address family)
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_cistruct inet_connection_sock_af_ops {
398c2ecf20Sopenharmony_ci	int	    (*queue_xmit)(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
408c2ecf20Sopenharmony_ci	void	    (*send_check)(struct sock *sk, struct sk_buff *skb);
418c2ecf20Sopenharmony_ci	int	    (*rebuild_header)(struct sock *sk);
428c2ecf20Sopenharmony_ci	void	    (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb);
438c2ecf20Sopenharmony_ci	int	    (*conn_request)(struct sock *sk, struct sk_buff *skb);
448c2ecf20Sopenharmony_ci	struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb,
458c2ecf20Sopenharmony_ci				      struct request_sock *req,
468c2ecf20Sopenharmony_ci				      struct dst_entry *dst,
478c2ecf20Sopenharmony_ci				      struct request_sock *req_unhash,
488c2ecf20Sopenharmony_ci				      bool *own_req);
498c2ecf20Sopenharmony_ci	u16	    net_header_len;
508c2ecf20Sopenharmony_ci	u16	    net_frag_header_len;
518c2ecf20Sopenharmony_ci	u16	    sockaddr_len;
528c2ecf20Sopenharmony_ci	int	    (*setsockopt)(struct sock *sk, int level, int optname,
538c2ecf20Sopenharmony_ci				  sockptr_t optval, unsigned int optlen);
548c2ecf20Sopenharmony_ci	int	    (*getsockopt)(struct sock *sk, int level, int optname,
558c2ecf20Sopenharmony_ci				  char __user *optval, int __user *optlen);
568c2ecf20Sopenharmony_ci	void	    (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
578c2ecf20Sopenharmony_ci	void	    (*mtu_reduced)(struct sock *sk);
588c2ecf20Sopenharmony_ci};
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/** inet_connection_sock - INET connection oriented sock
618c2ecf20Sopenharmony_ci *
628c2ecf20Sopenharmony_ci * @icsk_accept_queue:	   FIFO of established children
638c2ecf20Sopenharmony_ci * @icsk_bind_hash:	   Bind node
648c2ecf20Sopenharmony_ci * @icsk_timeout:	   Timeout
658c2ecf20Sopenharmony_ci * @icsk_retransmit_timer: Resend (no ack)
668c2ecf20Sopenharmony_ci * @icsk_rto:		   Retransmit timeout
678c2ecf20Sopenharmony_ci * @icsk_pmtu_cookie	   Last pmtu seen by socket
688c2ecf20Sopenharmony_ci * @icsk_ca_ops		   Pluggable congestion control hook
698c2ecf20Sopenharmony_ci * @icsk_af_ops		   Operations which are AF_INET{4,6} specific
708c2ecf20Sopenharmony_ci * @icsk_ulp_ops	   Pluggable ULP control hook
718c2ecf20Sopenharmony_ci * @icsk_ulp_data	   ULP private data
728c2ecf20Sopenharmony_ci * @icsk_clean_acked	   Clean acked data hook
738c2ecf20Sopenharmony_ci * @icsk_listen_portaddr_node	hash to the portaddr listener hashtable
748c2ecf20Sopenharmony_ci * @icsk_ca_state:	   Congestion control state
758c2ecf20Sopenharmony_ci * @icsk_retransmits:	   Number of unrecovered [RTO] timeouts
768c2ecf20Sopenharmony_ci * @icsk_pending:	   Scheduled timer event
778c2ecf20Sopenharmony_ci * @icsk_backoff:	   Backoff
788c2ecf20Sopenharmony_ci * @icsk_syn_retries:      Number of allowed SYN (or equivalent) retries
798c2ecf20Sopenharmony_ci * @icsk_probes_out:	   unanswered 0 window probes
808c2ecf20Sopenharmony_ci * @icsk_ext_hdr_len:	   Network protocol overhead (IP/IPv6 options)
818c2ecf20Sopenharmony_ci * @icsk_ack:		   Delayed ACK control data
828c2ecf20Sopenharmony_ci * @icsk_mtup;		   MTU probing control data
838c2ecf20Sopenharmony_ci * @icsk_probes_tstamp:    Probe timestamp (cleared by non-zero window ack)
848c2ecf20Sopenharmony_ci * @icsk_user_timeout:	   TCP_USER_TIMEOUT value
858c2ecf20Sopenharmony_ci */
868c2ecf20Sopenharmony_cistruct inet_connection_sock {
878c2ecf20Sopenharmony_ci	/* inet_sock has to be the first member! */
888c2ecf20Sopenharmony_ci	struct inet_sock	  icsk_inet;
898c2ecf20Sopenharmony_ci	struct request_sock_queue icsk_accept_queue;
908c2ecf20Sopenharmony_ci	struct inet_bind_bucket	  *icsk_bind_hash;
918c2ecf20Sopenharmony_ci	unsigned long		  icsk_timeout;
928c2ecf20Sopenharmony_ci 	struct timer_list	  icsk_retransmit_timer;
938c2ecf20Sopenharmony_ci 	struct timer_list	  icsk_delack_timer;
948c2ecf20Sopenharmony_ci	__u32			  icsk_rto;
958c2ecf20Sopenharmony_ci	__u32                     icsk_rto_min;
968c2ecf20Sopenharmony_ci	__u32                     icsk_delack_max;
978c2ecf20Sopenharmony_ci	__u32			  icsk_pmtu_cookie;
988c2ecf20Sopenharmony_ci	const struct tcp_congestion_ops *icsk_ca_ops;
998c2ecf20Sopenharmony_ci	const struct inet_connection_sock_af_ops *icsk_af_ops;
1008c2ecf20Sopenharmony_ci	const struct tcp_ulp_ops  *icsk_ulp_ops;
1018c2ecf20Sopenharmony_ci	void __rcu		  *icsk_ulp_data;
1028c2ecf20Sopenharmony_ci	void (*icsk_clean_acked)(struct sock *sk, u32 acked_seq);
1038c2ecf20Sopenharmony_ci	struct hlist_node         icsk_listen_portaddr_node;
1048c2ecf20Sopenharmony_ci	unsigned int		  (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
1058c2ecf20Sopenharmony_ci	__u8			  icsk_ca_state:5,
1068c2ecf20Sopenharmony_ci				  icsk_ca_initialized:1,
1078c2ecf20Sopenharmony_ci				  icsk_ca_setsockopt:1,
1088c2ecf20Sopenharmony_ci				  icsk_ca_dst_locked:1;
1098c2ecf20Sopenharmony_ci	__u8			  icsk_retransmits;
1108c2ecf20Sopenharmony_ci	__u8			  icsk_pending;
1118c2ecf20Sopenharmony_ci	__u8			  icsk_backoff;
1128c2ecf20Sopenharmony_ci	__u8			  icsk_syn_retries;
1138c2ecf20Sopenharmony_ci	__u8			  icsk_probes_out;
1148c2ecf20Sopenharmony_ci	__u16			  icsk_ext_hdr_len;
1158c2ecf20Sopenharmony_ci#if defined(CONFIG_TCP_NATA_URC) || defined(CONFIG_TCP_NATA_STL)
1168c2ecf20Sopenharmony_ci	__u8			  nata_retries_enabled:1,
1178c2ecf20Sopenharmony_ci				  nata_reserved:7;
1188c2ecf20Sopenharmony_ci	__u8			  nata_data_retries;
1198c2ecf20Sopenharmony_ci	__u8			  nata_retries_type;
1208c2ecf20Sopenharmony_ci	__u32			  nata_syn_rto;
1218c2ecf20Sopenharmony_ci	__u32			  nata_data_rto;
1228c2ecf20Sopenharmony_ci#endif
1238c2ecf20Sopenharmony_ci	struct {
1248c2ecf20Sopenharmony_ci		__u8		  pending;	 /* ACK is pending			   */
1258c2ecf20Sopenharmony_ci		__u8		  quick;	 /* Scheduled number of quick acks	   */
1268c2ecf20Sopenharmony_ci		__u8		  pingpong;	 /* The session is interactive		   */
1278c2ecf20Sopenharmony_ci		__u8		  retry;	 /* Number of attempts			   */
1288c2ecf20Sopenharmony_ci		__u32		  ato;		 /* Predicted tick of soft clock	   */
1298c2ecf20Sopenharmony_ci		unsigned long	  timeout;	 /* Currently scheduled timeout		   */
1308c2ecf20Sopenharmony_ci		__u32		  lrcvtime;	 /* timestamp of last received data packet */
1318c2ecf20Sopenharmony_ci		__u16		  last_seg_size; /* Size of last incoming segment	   */
1328c2ecf20Sopenharmony_ci		__u16		  rcv_mss;	 /* MSS used for delayed ACK decisions	   */
1338c2ecf20Sopenharmony_ci	} icsk_ack;
1348c2ecf20Sopenharmony_ci	struct {
1358c2ecf20Sopenharmony_ci		int		  enabled;
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci		/* Range of MTUs to search */
1388c2ecf20Sopenharmony_ci		int		  search_high;
1398c2ecf20Sopenharmony_ci		int		  search_low;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci		/* Information on the current probe. */
1428c2ecf20Sopenharmony_ci		int		  probe_size;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci		u32		  probe_timestamp;
1458c2ecf20Sopenharmony_ci	} icsk_mtup;
1468c2ecf20Sopenharmony_ci	u32			  icsk_probes_tstamp;
1478c2ecf20Sopenharmony_ci	u32			  icsk_user_timeout;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	u64			  icsk_ca_priv[104 / sizeof(u64)];
1508c2ecf20Sopenharmony_ci#define ICSK_CA_PRIV_SIZE      (13 * sizeof(u64))
1518c2ecf20Sopenharmony_ci};
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#define ICSK_TIME_RETRANS	1	/* Retransmit timer */
1548c2ecf20Sopenharmony_ci#define ICSK_TIME_DACK		2	/* Delayed ack timer */
1558c2ecf20Sopenharmony_ci#define ICSK_TIME_PROBE0	3	/* Zero window probe timer */
1568c2ecf20Sopenharmony_ci#define ICSK_TIME_EARLY_RETRANS 4	/* Early retransmit timer */
1578c2ecf20Sopenharmony_ci#define ICSK_TIME_LOSS_PROBE	5	/* Tail loss probe timer */
1588c2ecf20Sopenharmony_ci#define ICSK_TIME_REO_TIMEOUT	6	/* Reordering timer */
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistatic inline struct inet_connection_sock *inet_csk(const struct sock *sk)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	return (struct inet_connection_sock *)sk;
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic inline void *inet_csk_ca(const struct sock *sk)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	return (void *)inet_csk(sk)->icsk_ca_priv;
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistruct sock *inet_csk_clone_lock(const struct sock *sk,
1718c2ecf20Sopenharmony_ci				 const struct request_sock *req,
1728c2ecf20Sopenharmony_ci				 const gfp_t priority);
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_cienum inet_csk_ack_state_t {
1758c2ecf20Sopenharmony_ci	ICSK_ACK_SCHED	= 1,
1768c2ecf20Sopenharmony_ci	ICSK_ACK_TIMER  = 2,
1778c2ecf20Sopenharmony_ci	ICSK_ACK_PUSHED = 4,
1788c2ecf20Sopenharmony_ci	ICSK_ACK_PUSHED2 = 8,
1798c2ecf20Sopenharmony_ci	ICSK_ACK_NOW = 16	/* Send the next ACK immediately (once) */
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_civoid inet_csk_init_xmit_timers(struct sock *sk,
1838c2ecf20Sopenharmony_ci			       void (*retransmit_handler)(struct timer_list *),
1848c2ecf20Sopenharmony_ci			       void (*delack_handler)(struct timer_list *),
1858c2ecf20Sopenharmony_ci			       void (*keepalive_handler)(struct timer_list *));
1868c2ecf20Sopenharmony_civoid inet_csk_clear_xmit_timers(struct sock *sk);
1878c2ecf20Sopenharmony_civoid inet_csk_clear_xmit_timers_sync(struct sock *sk);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistatic inline void inet_csk_schedule_ack(struct sock *sk)
1908c2ecf20Sopenharmony_ci{
1918c2ecf20Sopenharmony_ci	inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistatic inline int inet_csk_ack_scheduled(const struct sock *sk)
1958c2ecf20Sopenharmony_ci{
1968c2ecf20Sopenharmony_ci	return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;
1978c2ecf20Sopenharmony_ci}
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistatic inline void inet_csk_delack_init(struct sock *sk)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_civoid inet_csk_delete_keepalive_timer(struct sock *sk);
2058c2ecf20Sopenharmony_civoid inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
2088c2ecf20Sopenharmony_ci{
2098c2ecf20Sopenharmony_ci	struct inet_connection_sock *icsk = inet_csk(sk);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci	if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
2128c2ecf20Sopenharmony_ci		icsk->icsk_pending = 0;
2138c2ecf20Sopenharmony_ci#ifdef INET_CSK_CLEAR_TIMERS
2148c2ecf20Sopenharmony_ci		sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
2158c2ecf20Sopenharmony_ci#endif
2168c2ecf20Sopenharmony_ci	} else if (what == ICSK_TIME_DACK) {
2178c2ecf20Sopenharmony_ci		icsk->icsk_ack.pending = 0;
2188c2ecf20Sopenharmony_ci		icsk->icsk_ack.retry = 0;
2198c2ecf20Sopenharmony_ci#ifdef INET_CSK_CLEAR_TIMERS
2208c2ecf20Sopenharmony_ci		sk_stop_timer(sk, &icsk->icsk_delack_timer);
2218c2ecf20Sopenharmony_ci#endif
2228c2ecf20Sopenharmony_ci	} else {
2238c2ecf20Sopenharmony_ci		pr_debug("inet_csk BUG: unknown timer value\n");
2248c2ecf20Sopenharmony_ci	}
2258c2ecf20Sopenharmony_ci}
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci#if defined(CONFIG_TCP_NATA_URC) || defined(CONFIG_TCP_NATA_STL)
2288c2ecf20Sopenharmony_cistatic inline unsigned long get_nata_rto(struct sock *sk,
2298c2ecf20Sopenharmony_ci					 struct inet_connection_sock *icsk,
2308c2ecf20Sopenharmony_ci					 unsigned long when, const int what)
2318c2ecf20Sopenharmony_ci{
2328c2ecf20Sopenharmony_ci	unsigned long when_nata;
2338c2ecf20Sopenharmony_ci	unsigned long shift;
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	if (!icsk->nata_retries_enabled)
2368c2ecf20Sopenharmony_ci		return when;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	switch (what) {
2398c2ecf20Sopenharmony_ci	case ICSK_TIME_RETRANS:
2408c2ecf20Sopenharmony_ci	case ICSK_TIME_EARLY_RETRANS:
2418c2ecf20Sopenharmony_ci	case ICSK_TIME_LOSS_PROBE:
2428c2ecf20Sopenharmony_ci	case ICSK_TIME_REO_TIMEOUT:
2438c2ecf20Sopenharmony_ci		break;
2448c2ecf20Sopenharmony_ci	default:
2458c2ecf20Sopenharmony_ci		return when;
2468c2ecf20Sopenharmony_ci	}
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	if (icsk->nata_retries_type == NATA_STL)
2498c2ecf20Sopenharmony_ci		return sk->sk_state == TCP_SYN_SENT ?
2508c2ecf20Sopenharmony_ci			icsk->nata_syn_rto : icsk->nata_data_rto;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	if (!nata_thin_stream_check(sk))
2538c2ecf20Sopenharmony_ci		return when;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	when_nata = icsk->nata_data_rto;
2568c2ecf20Sopenharmony_ci	if (icsk->icsk_retransmits > icsk->nata_data_retries) {
2578c2ecf20Sopenharmony_ci		shift = icsk->icsk_retransmits - icsk->nata_data_retries;
2588c2ecf20Sopenharmony_ci		if (shift > MAX_SHIFT) {
2598c2ecf20Sopenharmony_ci			when_nata = NATA_RTO_MAX;
2608c2ecf20Sopenharmony_ci		} else {
2618c2ecf20Sopenharmony_ci			when_nata <<= shift;
2628c2ecf20Sopenharmony_ci		}
2638c2ecf20Sopenharmony_ci	}
2648c2ecf20Sopenharmony_ci	return min(when, when_nata);
2658c2ecf20Sopenharmony_ci}
2668c2ecf20Sopenharmony_ci#endif
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci/*
2698c2ecf20Sopenharmony_ci *	Reset the retransmission timer
2708c2ecf20Sopenharmony_ci */
2718c2ecf20Sopenharmony_cistatic inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
2728c2ecf20Sopenharmony_ci					     unsigned long when,
2738c2ecf20Sopenharmony_ci					     const unsigned long max_when)
2748c2ecf20Sopenharmony_ci{
2758c2ecf20Sopenharmony_ci	struct inet_connection_sock *icsk = inet_csk(sk);
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci#if defined(CONFIG_TCP_NATA_URC) || defined(CONFIG_TCP_NATA_STL)
2788c2ecf20Sopenharmony_ci	when = get_nata_rto(sk, icsk, when, what);
2798c2ecf20Sopenharmony_ci#endif
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	if (when > max_when) {
2828c2ecf20Sopenharmony_ci		pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
2838c2ecf20Sopenharmony_ci			 sk, what, when, (void *)_THIS_IP_);
2848c2ecf20Sopenharmony_ci		when = max_when;
2858c2ecf20Sopenharmony_ci	}
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
2888c2ecf20Sopenharmony_ci	    what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE ||
2898c2ecf20Sopenharmony_ci	    what == ICSK_TIME_REO_TIMEOUT) {
2908c2ecf20Sopenharmony_ci		icsk->icsk_pending = what;
2918c2ecf20Sopenharmony_ci		icsk->icsk_timeout = jiffies + when;
2928c2ecf20Sopenharmony_ci		sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
2938c2ecf20Sopenharmony_ci	} else if (what == ICSK_TIME_DACK) {
2948c2ecf20Sopenharmony_ci		icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
2958c2ecf20Sopenharmony_ci		icsk->icsk_ack.timeout = jiffies + when;
2968c2ecf20Sopenharmony_ci		sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
2978c2ecf20Sopenharmony_ci	} else {
2988c2ecf20Sopenharmony_ci		pr_debug("inet_csk BUG: unknown timer value\n");
2998c2ecf20Sopenharmony_ci	}
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_cistatic inline unsigned long
3038c2ecf20Sopenharmony_ciinet_csk_rto_backoff(const struct inet_connection_sock *icsk,
3048c2ecf20Sopenharmony_ci		     unsigned long max_when)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci        u64 when = (u64)icsk->icsk_rto << icsk->icsk_backoff;
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci        return (unsigned long)min_t(u64, when, max_when);
3098c2ecf20Sopenharmony_ci}
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_cistruct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern);
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ciint inet_csk_get_port(struct sock *sk, unsigned short snum);
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cistruct dst_entry *inet_csk_route_req(const struct sock *sk, struct flowi4 *fl4,
3168c2ecf20Sopenharmony_ci				     const struct request_sock *req);
3178c2ecf20Sopenharmony_cistruct dst_entry *inet_csk_route_child_sock(const struct sock *sk,
3188c2ecf20Sopenharmony_ci					    struct sock *newsk,
3198c2ecf20Sopenharmony_ci					    const struct request_sock *req);
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cistruct sock *inet_csk_reqsk_queue_add(struct sock *sk,
3228c2ecf20Sopenharmony_ci				      struct request_sock *req,
3238c2ecf20Sopenharmony_ci				      struct sock *child);
3248c2ecf20Sopenharmony_civoid inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
3258c2ecf20Sopenharmony_ci				   unsigned long timeout);
3268c2ecf20Sopenharmony_cistruct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child,
3278c2ecf20Sopenharmony_ci					 struct request_sock *req,
3288c2ecf20Sopenharmony_ci					 bool own_req);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_cistatic inline void inet_csk_reqsk_queue_added(struct sock *sk)
3318c2ecf20Sopenharmony_ci{
3328c2ecf20Sopenharmony_ci	reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue);
3338c2ecf20Sopenharmony_ci}
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_cistatic inline int inet_csk_reqsk_queue_len(const struct sock *sk)
3368c2ecf20Sopenharmony_ci{
3378c2ecf20Sopenharmony_ci	return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_cistatic inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
3418c2ecf20Sopenharmony_ci{
3428c2ecf20Sopenharmony_ci	return inet_csk_reqsk_queue_len(sk) >= sk->sk_max_ack_backlog;
3438c2ecf20Sopenharmony_ci}
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_cibool inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
3468c2ecf20Sopenharmony_civoid inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req);
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_cistatic inline void inet_csk_prepare_for_destroy_sock(struct sock *sk)
3498c2ecf20Sopenharmony_ci{
3508c2ecf20Sopenharmony_ci	/* The below has to be done to allow calling inet_csk_destroy_sock */
3518c2ecf20Sopenharmony_ci	sock_set_flag(sk, SOCK_DEAD);
3528c2ecf20Sopenharmony_ci	this_cpu_inc(*sk->sk_prot->orphan_count);
3538c2ecf20Sopenharmony_ci}
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_civoid inet_csk_destroy_sock(struct sock *sk);
3568c2ecf20Sopenharmony_civoid inet_csk_prepare_forced_close(struct sock *sk);
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci/*
3598c2ecf20Sopenharmony_ci * LISTEN is a special case for poll..
3608c2ecf20Sopenharmony_ci */
3618c2ecf20Sopenharmony_cistatic inline __poll_t inet_csk_listen_poll(const struct sock *sk)
3628c2ecf20Sopenharmony_ci{
3638c2ecf20Sopenharmony_ci	return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ?
3648c2ecf20Sopenharmony_ci			(EPOLLIN | EPOLLRDNORM) : 0;
3658c2ecf20Sopenharmony_ci}
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ciint inet_csk_listen_start(struct sock *sk, int backlog);
3688c2ecf20Sopenharmony_civoid inet_csk_listen_stop(struct sock *sk);
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_civoid inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci/* update the fast reuse flag when adding a socket */
3738c2ecf20Sopenharmony_civoid inet_csk_update_fastreuse(struct inet_bind_bucket *tb,
3748c2ecf20Sopenharmony_ci			       struct sock *sk);
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cistruct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu);
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci#define TCP_PINGPONG_THRESH	1
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_cistatic inline void inet_csk_enter_pingpong_mode(struct sock *sk)
3818c2ecf20Sopenharmony_ci{
3828c2ecf20Sopenharmony_ci	inet_csk(sk)->icsk_ack.pingpong = TCP_PINGPONG_THRESH;
3838c2ecf20Sopenharmony_ci}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic inline void inet_csk_exit_pingpong_mode(struct sock *sk)
3868c2ecf20Sopenharmony_ci{
3878c2ecf20Sopenharmony_ci	inet_csk(sk)->icsk_ack.pingpong = 0;
3888c2ecf20Sopenharmony_ci}
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_cistatic inline bool inet_csk_in_pingpong_mode(struct sock *sk)
3918c2ecf20Sopenharmony_ci{
3928c2ecf20Sopenharmony_ci	return inet_csk(sk)->icsk_ack.pingpong >= TCP_PINGPONG_THRESH;
3938c2ecf20Sopenharmony_ci}
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_cistatic inline bool inet_csk_has_ulp(struct sock *sk)
3968c2ecf20Sopenharmony_ci{
3978c2ecf20Sopenharmony_ci	return inet_sk(sk)->is_icsk && !!inet_csk(sk)->icsk_ulp_ops;
3988c2ecf20Sopenharmony_ci}
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_cistatic inline void inet_init_csk_locks(struct sock *sk)
4018c2ecf20Sopenharmony_ci{
4028c2ecf20Sopenharmony_ci	struct inet_connection_sock *icsk = inet_csk(sk);
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	spin_lock_init(&icsk->icsk_accept_queue.rskq_lock);
4058c2ecf20Sopenharmony_ci	spin_lock_init(&icsk->icsk_accept_queue.fastopenq.lock);
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci#endif /* _INET_CONNECTION_SOCK_H */
409