Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 2 | /* |
| 3 | * NET Generic infrastructure for INET connection oriented protocols. |
| 4 | * |
| 5 | * Definitions for inet_connection_sock |
| 6 | * |
| 7 | * Authors: Many people, see the TCP sources |
| 8 | * |
| 9 | * From code originally in TCP |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 10 | */ |
| 11 | #ifndef _INET_CONNECTION_SOCK_H |
| 12 | #define _INET_CONNECTION_SOCK_H |
| 13 | |
Arnaldo Carvalho de Melo | 8292a17 | 2005-12-13 23:15:52 -0800 | [diff] [blame] | 14 | #include <linux/compiler.h> |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 15 | #include <linux/string.h> |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 16 | #include <linux/timer.h> |
Al Viro | bd01f84 | 2006-10-19 17:23:57 -0400 | [diff] [blame] | 17 | #include <linux/poll.h> |
Nick Desaulniers | 96d18d8 | 2018-08-01 14:57:59 -0700 | [diff] [blame] | 18 | #include <linux/kernel.h> |
Christoph Hellwig | a7b75c5 | 2020-07-23 08:09:07 +0200 | [diff] [blame] | 19 | #include <linux/sockptr.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 20 | |
| 21 | #include <net/inet_sock.h> |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 22 | #include <net/request_sock.h> |
| 23 | |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 24 | /* Cancel timers, when they are not required. */ |
| 25 | #undef INET_CSK_CLEAR_TIMERS |
| 26 | |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 27 | struct inet_bind_bucket; |
Arnaldo Carvalho de Melo | 6687e98 | 2005-08-10 04:03:31 -0300 | [diff] [blame] | 28 | struct tcp_congestion_ops; |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 29 | |
Arnaldo Carvalho de Melo | 8292a17 | 2005-12-13 23:15:52 -0800 | [diff] [blame] | 30 | /* |
| 31 | * Pointers to address related TCP functions |
| 32 | * (i.e. things that depend on the address family) |
| 33 | */ |
| 34 | struct inet_connection_sock_af_ops { |
Eric Dumazet | b0270e9 | 2014-04-15 12:58:34 -0400 | [diff] [blame] | 35 | int (*queue_xmit)(struct sock *sk, struct sk_buff *skb, struct flowi *fl); |
Herbert Xu | bb29624 | 2010-04-11 02:15:55 +0000 | [diff] [blame] | 36 | void (*send_check)(struct sock *sk, struct sk_buff *skb); |
Arnaldo Carvalho de Melo | 8292a17 | 2005-12-13 23:15:52 -0800 | [diff] [blame] | 37 | int (*rebuild_header)(struct sock *sk); |
Eric Dumazet | 5d299f3 | 2012-08-06 05:09:33 +0000 | [diff] [blame] | 38 | void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb); |
Arnaldo Carvalho de Melo | 8292a17 | 2005-12-13 23:15:52 -0800 | [diff] [blame] | 39 | int (*conn_request)(struct sock *sk, struct sk_buff *skb); |
Eric Dumazet | 0c27171 | 2015-09-29 07:42:48 -0700 | [diff] [blame] | 40 | struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb, |
Arnaldo Carvalho de Melo | 8292a17 | 2005-12-13 23:15:52 -0800 | [diff] [blame] | 41 | struct request_sock *req, |
Eric Dumazet | 5e0724d | 2015-10-22 08:20:46 -0700 | [diff] [blame] | 42 | struct dst_entry *dst, |
| 43 | struct request_sock *req_unhash, |
| 44 | bool *own_req); |
Arnaldo Carvalho de Melo | 850db6b | 2006-11-27 17:56:43 -0200 | [diff] [blame] | 45 | u16 net_header_len; |
Eric Dumazet | 6746960 | 2012-04-24 07:37:38 +0000 | [diff] [blame] | 46 | u16 net_frag_header_len; |
Arnaldo Carvalho de Melo | 850db6b | 2006-11-27 17:56:43 -0200 | [diff] [blame] | 47 | u16 sockaddr_len; |
Stephen Hemminger | 82695b3 | 2018-02-27 15:48:21 -0800 | [diff] [blame] | 48 | int (*setsockopt)(struct sock *sk, int level, int optname, |
Christoph Hellwig | a7b75c5 | 2020-07-23 08:09:07 +0200 | [diff] [blame] | 49 | sockptr_t optval, unsigned int optlen); |
Stephen Hemminger | 82695b3 | 2018-02-27 15:48:21 -0800 | [diff] [blame] | 50 | int (*getsockopt)(struct sock *sk, int level, int optname, |
Arnaldo Carvalho de Melo | 8292a17 | 2005-12-13 23:15:52 -0800 | [diff] [blame] | 51 | char __user *optval, int __user *optlen); |
| 52 | void (*addr2sockaddr)(struct sock *sk, struct sockaddr *); |
Neal Cardwell | 4fab907 | 2014-08-14 12:40:05 -0400 | [diff] [blame] | 53 | void (*mtu_reduced)(struct sock *sk); |
Arnaldo Carvalho de Melo | 8292a17 | 2005-12-13 23:15:52 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 56 | /** inet_connection_sock - INET connection oriented sock |
| 57 | * |
Stephen Hemminger | 82695b3 | 2018-02-27 15:48:21 -0800 | [diff] [blame] | 58 | * @icsk_accept_queue: FIFO of established children |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 59 | * @icsk_bind_hash: Bind node |
| 60 | * @icsk_timeout: Timeout |
| 61 | * @icsk_retransmit_timer: Resend (no ack) |
| 62 | * @icsk_rto: Retransmit timeout |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 63 | * @icsk_pmtu_cookie Last pmtu seen by socket |
Arnaldo Carvalho de Melo | 6687e98 | 2005-08-10 04:03:31 -0300 | [diff] [blame] | 64 | * @icsk_ca_ops Pluggable congestion control hook |
Arnaldo Carvalho de Melo | 8292a17 | 2005-12-13 23:15:52 -0800 | [diff] [blame] | 65 | * @icsk_af_ops Operations which are AF_INET{4,6} specific |
Dave Watson | 734942c | 2017-06-14 11:37:14 -0700 | [diff] [blame] | 66 | * @icsk_ulp_ops Pluggable ULP control hook |
| 67 | * @icsk_ulp_data ULP private data |
Ilya Lesokhin | 6dac152 | 2018-04-30 10:16:10 +0300 | [diff] [blame] | 68 | * @icsk_clean_acked Clean acked data hook |
Martin KaFai Lau | 61b7c69 | 2017-12-01 12:52:31 -0800 | [diff] [blame] | 69 | * @icsk_listen_portaddr_node hash to the portaddr listener hashtable |
Arnaldo Carvalho de Melo | 6687e98 | 2005-08-10 04:03:31 -0300 | [diff] [blame] | 70 | * @icsk_ca_state: Congestion control state |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 71 | * @icsk_retransmits: Number of unrecovered [RTO] timeouts |
| 72 | * @icsk_pending: Scheduled timer event |
| 73 | * @icsk_backoff: Backoff |
| 74 | * @icsk_syn_retries: Number of allowed SYN (or equivalent) retries |
Arnaldo Carvalho de Melo | 6687e98 | 2005-08-10 04:03:31 -0300 | [diff] [blame] | 75 | * @icsk_probes_out: unanswered 0 window probes |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 76 | * @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options) |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 77 | * @icsk_ack: Delayed ACK control data |
John Heffner | 5d424d5 | 2006-03-20 17:53:41 -0800 | [diff] [blame] | 78 | * @icsk_mtup; MTU probing control data |
Enke Chen | 9d9b1ee | 2021-01-15 14:30:58 -0800 | [diff] [blame] | 79 | * @icsk_probes_tstamp: Probe timestamp (cleared by non-zero window ack) |
| 80 | * @icsk_user_timeout: TCP_USER_TIMEOUT value |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 81 | */ |
| 82 | struct inet_connection_sock { |
| 83 | /* inet_sock has to be the first member! */ |
| 84 | struct inet_sock icsk_inet; |
| 85 | struct request_sock_queue icsk_accept_queue; |
| 86 | struct inet_bind_bucket *icsk_bind_hash; |
| 87 | unsigned long icsk_timeout; |
| 88 | struct timer_list icsk_retransmit_timer; |
| 89 | struct timer_list icsk_delack_timer; |
| 90 | __u32 icsk_rto; |
Martin KaFai Lau | ca584ba | 2020-08-20 12:00:27 -0700 | [diff] [blame] | 91 | __u32 icsk_rto_min; |
Martin KaFai Lau | 2b8ee4f | 2020-08-20 12:00:21 -0700 | [diff] [blame] | 92 | __u32 icsk_delack_max; |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 93 | __u32 icsk_pmtu_cookie; |
Stephen Hemminger | 770cfbc | 2006-01-09 15:56:09 -0800 | [diff] [blame] | 94 | const struct tcp_congestion_ops *icsk_ca_ops; |
| 95 | const struct inet_connection_sock_af_ops *icsk_af_ops; |
Dave Watson | 734942c | 2017-06-14 11:37:14 -0700 | [diff] [blame] | 96 | const struct tcp_ulp_ops *icsk_ulp_ops; |
Jakub Kicinski | 15a7dea | 2019-08-30 12:25:47 +0200 | [diff] [blame] | 97 | void __rcu *icsk_ulp_data; |
Ilya Lesokhin | 6dac152 | 2018-04-30 10:16:10 +0300 | [diff] [blame] | 98 | void (*icsk_clean_acked)(struct sock *sk, u32 acked_seq); |
Martin KaFai Lau | 61b7c69 | 2017-12-01 12:52:31 -0800 | [diff] [blame] | 99 | struct hlist_node icsk_listen_portaddr_node; |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 100 | unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu); |
Neal Cardwell | 8919a9b | 2020-09-10 15:35:32 -0400 | [diff] [blame] | 101 | __u8 icsk_ca_state:5, |
| 102 | icsk_ca_initialized:1, |
Neal Cardwell | 9f95041 | 2015-05-29 13:47:07 -0400 | [diff] [blame] | 103 | icsk_ca_setsockopt:1, |
Daniel Borkmann | c5c6a8a | 2015-01-05 23:57:46 +0100 | [diff] [blame] | 104 | icsk_ca_dst_locked:1; |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 105 | __u8 icsk_retransmits; |
| 106 | __u8 icsk_pending; |
| 107 | __u8 icsk_backoff; |
| 108 | __u8 icsk_syn_retries; |
Arnaldo Carvalho de Melo | 6687e98 | 2005-08-10 04:03:31 -0300 | [diff] [blame] | 109 | __u8 icsk_probes_out; |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 110 | __u16 icsk_ext_hdr_len; |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 111 | struct { |
| 112 | __u8 pending; /* ACK is pending */ |
| 113 | __u8 quick; /* Scheduled number of quick acks */ |
| 114 | __u8 pingpong; /* The session is interactive */ |
Eric Dumazet | a37c213 | 2020-09-30 05:54:57 -0700 | [diff] [blame] | 115 | __u8 retry; /* Number of attempts */ |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 116 | __u32 ato; /* Predicted tick of soft clock */ |
| 117 | unsigned long timeout; /* Currently scheduled timeout */ |
| 118 | __u32 lrcvtime; /* timestamp of last received data packet */ |
| 119 | __u16 last_seg_size; /* Size of last incoming segment */ |
Stephen Hemminger | 82695b3 | 2018-02-27 15:48:21 -0800 | [diff] [blame] | 120 | __u16 rcv_mss; /* MSS used for delayed ACK decisions */ |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 121 | } icsk_ack; |
John Heffner | 5d424d5 | 2006-03-20 17:53:41 -0800 | [diff] [blame] | 122 | struct { |
John Heffner | 5d424d5 | 2006-03-20 17:53:41 -0800 | [diff] [blame] | 123 | /* Range of MTUs to search */ |
| 124 | int search_high; |
| 125 | int search_low; |
| 126 | |
| 127 | /* Information on the current probe. */ |
Neal Cardwell | 14e8e0f | 2021-01-29 13:54:38 -0500 | [diff] [blame] | 128 | u32 probe_size:31, |
| 129 | /* Is the MTUP feature enabled for this connection? */ |
| 130 | enabled:1; |
Fan Du | 05cbc0d | 2015-03-06 11:18:24 +0800 | [diff] [blame] | 131 | |
| 132 | u32 probe_timestamp; |
John Heffner | 5d424d5 | 2006-03-20 17:53:41 -0800 | [diff] [blame] | 133 | } icsk_mtup; |
Enke Chen | 9d9b1ee | 2021-01-15 14:30:58 -0800 | [diff] [blame] | 134 | u32 icsk_probes_tstamp; |
Jerry Chu | dca43c7 | 2010-08-27 19:13:28 +0000 | [diff] [blame] | 135 | u32 icsk_user_timeout; |
Eric Dumazet | b5d721d | 2015-05-18 17:06:14 -0700 | [diff] [blame] | 136 | |
Priyaranjan Jha | 78dc70e | 2019-01-23 12:04:54 -0800 | [diff] [blame] | 137 | u64 icsk_ca_priv[104 / sizeof(u64)]; |
Eric Dumazet | 3f8ad50 | 2021-06-29 06:53:14 -0700 | [diff] [blame] | 138 | #define ICSK_CA_PRIV_SIZE sizeof_field(struct inet_connection_sock, icsk_ca_priv) |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 141 | #define ICSK_TIME_RETRANS 1 /* Retransmit timer */ |
| 142 | #define ICSK_TIME_DACK 2 /* Delayed ack timer */ |
| 143 | #define ICSK_TIME_PROBE0 3 /* Zero window probe timer */ |
Nandita Dukkipati | 6ba8a3b | 2013-03-11 10:00:43 +0000 | [diff] [blame] | 144 | #define ICSK_TIME_LOSS_PROBE 5 /* Tail loss probe timer */ |
Yuchung Cheng | 57dde7f | 2017-01-12 22:11:33 -0800 | [diff] [blame] | 145 | #define ICSK_TIME_REO_TIMEOUT 6 /* Reordering timer */ |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 146 | |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 147 | static inline struct inet_connection_sock *inet_csk(const struct sock *sk) |
| 148 | { |
| 149 | return (struct inet_connection_sock *)sk; |
| 150 | } |
| 151 | |
Arnaldo Carvalho de Melo | 6687e98 | 2005-08-10 04:03:31 -0300 | [diff] [blame] | 152 | static inline void *inet_csk_ca(const struct sock *sk) |
| 153 | { |
| 154 | return (void *)inet_csk(sk)->icsk_ca_priv; |
| 155 | } |
| 156 | |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 157 | struct sock *inet_csk_clone_lock(const struct sock *sk, |
| 158 | const struct request_sock *req, |
| 159 | const gfp_t priority); |
Arnaldo Carvalho de Melo | 9f1d260 | 2005-08-09 20:11:24 -0700 | [diff] [blame] | 160 | |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 161 | enum inet_csk_ack_state_t { |
| 162 | ICSK_ACK_SCHED = 1, |
| 163 | ICSK_ACK_TIMER = 2, |
Alexey Kuznetsov | 1ef9696 | 2006-09-19 12:52:50 -0700 | [diff] [blame] | 164 | ICSK_ACK_PUSHED = 4, |
Yuchung Cheng | 466466d | 2018-08-09 09:38:09 -0700 | [diff] [blame] | 165 | ICSK_ACK_PUSHED2 = 8, |
| 166 | ICSK_ACK_NOW = 16 /* Send the next ACK immediately (once) */ |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 169 | void inet_csk_init_xmit_timers(struct sock *sk, |
Kees Cook | 59f379f | 2017-10-16 17:29:19 -0700 | [diff] [blame] | 170 | void (*retransmit_handler)(struct timer_list *), |
| 171 | void (*delack_handler)(struct timer_list *), |
| 172 | void (*keepalive_handler)(struct timer_list *)); |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 173 | void inet_csk_clear_xmit_timers(struct sock *sk); |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 174 | |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 175 | static inline void inet_csk_schedule_ack(struct sock *sk) |
| 176 | { |
| 177 | inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED; |
| 178 | } |
| 179 | |
| 180 | static inline int inet_csk_ack_scheduled(const struct sock *sk) |
| 181 | { |
| 182 | return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED; |
| 183 | } |
| 184 | |
| 185 | static inline void inet_csk_delack_init(struct sock *sk) |
| 186 | { |
| 187 | memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack)); |
| 188 | } |
| 189 | |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 190 | void inet_csk_delete_keepalive_timer(struct sock *sk); |
| 191 | void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout); |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 192 | |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 193 | static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what) |
| 194 | { |
| 195 | struct inet_connection_sock *icsk = inet_csk(sk); |
Stephen Hemminger | 82695b3 | 2018-02-27 15:48:21 -0800 | [diff] [blame] | 196 | |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 197 | if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) { |
| 198 | icsk->icsk_pending = 0; |
| 199 | #ifdef INET_CSK_CLEAR_TIMERS |
| 200 | sk_stop_timer(sk, &icsk->icsk_retransmit_timer); |
| 201 | #endif |
| 202 | } else if (what == ICSK_TIME_DACK) { |
Eric Dumazet | b6b6d65 | 2020-09-30 05:54:56 -0700 | [diff] [blame] | 203 | icsk->icsk_ack.pending = 0; |
Eric Dumazet | a37c213 | 2020-09-30 05:54:57 -0700 | [diff] [blame] | 204 | icsk->icsk_ack.retry = 0; |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 205 | #ifdef INET_CSK_CLEAR_TIMERS |
| 206 | sk_stop_timer(sk, &icsk->icsk_delack_timer); |
| 207 | #endif |
Joe Perches | 03bdfc0 | 2018-05-09 23:24:07 -0700 | [diff] [blame] | 208 | } else { |
| 209 | pr_debug("inet_csk BUG: unknown timer value\n"); |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 210 | } |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Reset the retransmission timer |
| 215 | */ |
| 216 | static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what, |
| 217 | unsigned long when, |
| 218 | const unsigned long max_when) |
| 219 | { |
| 220 | struct inet_connection_sock *icsk = inet_csk(sk); |
| 221 | |
| 222 | if (when > max_when) { |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 223 | pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n", |
Nick Desaulniers | 96d18d8 | 2018-08-01 14:57:59 -0700 | [diff] [blame] | 224 | sk, what, when, (void *)_THIS_IP_); |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 225 | when = max_when; |
| 226 | } |
| 227 | |
Nandita Dukkipati | 6ba8a3b | 2013-03-11 10:00:43 +0000 | [diff] [blame] | 228 | if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 || |
Pengcheng Yang | a05a728 | 2021-01-21 22:31:13 +0800 | [diff] [blame] | 229 | what == ICSK_TIME_LOSS_PROBE || what == ICSK_TIME_REO_TIMEOUT) { |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 230 | icsk->icsk_pending = what; |
| 231 | icsk->icsk_timeout = jiffies + when; |
| 232 | sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout); |
| 233 | } else if (what == ICSK_TIME_DACK) { |
| 234 | icsk->icsk_ack.pending |= ICSK_ACK_TIMER; |
| 235 | icsk->icsk_ack.timeout = jiffies + when; |
| 236 | sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout); |
Joe Perches | 03bdfc0 | 2018-05-09 23:24:07 -0700 | [diff] [blame] | 237 | } else { |
| 238 | pr_debug("inet_csk BUG: unknown timer value\n"); |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 239 | } |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Eric Dumazet | fcdd1cf | 2014-09-22 13:19:44 -0700 | [diff] [blame] | 242 | static inline unsigned long |
| 243 | inet_csk_rto_backoff(const struct inet_connection_sock *icsk, |
| 244 | unsigned long max_when) |
| 245 | { |
| 246 | u64 when = (u64)icsk->icsk_rto << icsk->icsk_backoff; |
| 247 | |
| 248 | return (unsigned long)min_t(u64, when, max_when); |
| 249 | } |
| 250 | |
David Howells | cdfbabf | 2017-03-09 08:09:05 +0000 | [diff] [blame] | 251 | struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern); |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 252 | |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 253 | int inet_csk_get_port(struct sock *sk, unsigned short snum); |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 254 | |
Eric Dumazet | e5895bc | 2015-09-25 07:39:11 -0700 | [diff] [blame] | 255 | struct dst_entry *inet_csk_route_req(const struct sock *sk, struct flowi4 *fl4, |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 256 | const struct request_sock *req); |
Eric Dumazet | a2432c4 | 2015-09-29 07:42:43 -0700 | [diff] [blame] | 257 | struct dst_entry *inet_csk_route_child_sock(const struct sock *sk, |
| 258 | struct sock *newsk, |
David S. Miller | ba3f7f0 | 2012-07-17 14:02:46 -0700 | [diff] [blame] | 259 | const struct request_sock *req); |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 260 | |
Eric Dumazet | 7716682 | 2016-02-18 05:39:18 -0800 | [diff] [blame] | 261 | struct sock *inet_csk_reqsk_queue_add(struct sock *sk, |
| 262 | struct request_sock *req, |
| 263 | struct sock *child); |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 264 | void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, |
| 265 | unsigned long timeout); |
Eric Dumazet | 5e0724d | 2015-10-22 08:20:46 -0700 | [diff] [blame] | 266 | struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child, |
| 267 | struct request_sock *req, |
| 268 | bool own_req); |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 269 | |
Eric Dumazet | 2feda34 | 2015-10-02 11:43:31 -0700 | [diff] [blame] | 270 | static inline void inet_csk_reqsk_queue_added(struct sock *sk) |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 271 | { |
Eric Dumazet | fa76ce73 | 2015-03-19 19:04:20 -0700 | [diff] [blame] | 272 | reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue); |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static inline int inet_csk_reqsk_queue_len(const struct sock *sk) |
| 276 | { |
| 277 | return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue); |
| 278 | } |
| 279 | |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 280 | static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk) |
| 281 | { |
Eric Dumazet | ef547f2 | 2015-10-02 11:43:37 -0700 | [diff] [blame] | 282 | return inet_csk_reqsk_queue_len(sk) >= sk->sk_max_ack_backlog; |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Alexander Ovechkin | 7233da8 | 2021-03-15 14:05:45 +0300 | [diff] [blame] | 285 | bool inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req); |
Eric Dumazet | f03f2e1 | 2015-10-14 11:16:27 -0700 | [diff] [blame] | 286 | void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req); |
Arnaldo Carvalho de Melo | 3f421ba | 2005-08-09 20:11:08 -0700 | [diff] [blame] | 287 | |
Paolo Abeni | 2f8a397 | 2020-05-15 19:22:16 +0200 | [diff] [blame] | 288 | static inline void inet_csk_prepare_for_destroy_sock(struct sock *sk) |
| 289 | { |
| 290 | /* The below has to be done to allow calling inet_csk_destroy_sock */ |
| 291 | sock_set_flag(sk, SOCK_DEAD); |
Eric Dumazet | 19757ce | 2021-10-14 06:41:26 -0700 | [diff] [blame] | 292 | this_cpu_inc(*sk->sk_prot->orphan_count); |
Paolo Abeni | 2f8a397 | 2020-05-15 19:22:16 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 295 | void inet_csk_destroy_sock(struct sock *sk); |
| 296 | void inet_csk_prepare_forced_close(struct sock *sk); |
Arnaldo Carvalho de Melo | dc40c7b | 2005-08-23 21:52:58 -0700 | [diff] [blame] | 297 | |
| 298 | /* |
| 299 | * LISTEN is a special case for poll.. |
| 300 | */ |
Al Viro | ade994f | 2017-07-03 00:01:49 -0400 | [diff] [blame] | 301 | static inline __poll_t inet_csk_listen_poll(const struct sock *sk) |
Arnaldo Carvalho de Melo | dc40c7b | 2005-08-23 21:52:58 -0700 | [diff] [blame] | 302 | { |
| 303 | return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ? |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 304 | (EPOLLIN | EPOLLRDNORM) : 0; |
Arnaldo Carvalho de Melo | dc40c7b | 2005-08-23 21:52:58 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Kuniyuki Iwashima | e704939 | 2021-11-22 19:16:21 +0900 | [diff] [blame] | 307 | int inet_csk_listen_start(struct sock *sk); |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 308 | void inet_csk_listen_stop(struct sock *sk); |
Arnaldo Carvalho de Melo | 295f732 | 2005-08-09 20:11:56 -0700 | [diff] [blame] | 309 | |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 310 | void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr); |
Arnaldo Carvalho de Melo | af05dc9 | 2005-12-13 23:16:04 -0800 | [diff] [blame] | 311 | |
Tim Froidcoeur | 62ffc58 | 2020-08-11 20:33:23 +0200 | [diff] [blame] | 312 | /* update the fast reuse flag when adding a socket */ |
| 313 | void inet_csk_update_fastreuse(struct inet_bind_bucket *tb, |
| 314 | struct sock *sk); |
| 315 | |
Joe Perches | 1fd5115 | 2013-09-21 10:22:41 -0700 | [diff] [blame] | 316 | struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu); |
Wei Wang | 31954cd | 2019-01-25 10:53:19 -0800 | [diff] [blame] | 317 | |
Wei Wang | 4a41f45 | 2019-01-25 10:53:20 -0800 | [diff] [blame] | 318 | #define TCP_PINGPONG_THRESH 3 |
Wei Wang | 31954cd | 2019-01-25 10:53:19 -0800 | [diff] [blame] | 319 | |
| 320 | static inline void inet_csk_enter_pingpong_mode(struct sock *sk) |
| 321 | { |
| 322 | inet_csk(sk)->icsk_ack.pingpong = TCP_PINGPONG_THRESH; |
| 323 | } |
| 324 | |
| 325 | static inline void inet_csk_exit_pingpong_mode(struct sock *sk) |
| 326 | { |
| 327 | inet_csk(sk)->icsk_ack.pingpong = 0; |
| 328 | } |
| 329 | |
| 330 | static inline bool inet_csk_in_pingpong_mode(struct sock *sk) |
| 331 | { |
| 332 | return inet_csk(sk)->icsk_ack.pingpong >= TCP_PINGPONG_THRESH; |
| 333 | } |
Wei Wang | 4a41f45 | 2019-01-25 10:53:20 -0800 | [diff] [blame] | 334 | |
| 335 | static inline void inet_csk_inc_pingpong_cnt(struct sock *sk) |
| 336 | { |
| 337 | struct inet_connection_sock *icsk = inet_csk(sk); |
| 338 | |
| 339 | if (icsk->icsk_ack.pingpong < U8_MAX) |
| 340 | icsk->icsk_ack.pingpong++; |
| 341 | } |
Lorenz Bauer | 7b70973 | 2020-03-09 11:12:32 +0000 | [diff] [blame] | 342 | |
| 343 | static inline bool inet_csk_has_ulp(struct sock *sk) |
| 344 | { |
| 345 | return inet_sk(sk)->is_icsk && !!inet_csk(sk)->icsk_ulp_ops; |
| 346 | } |
| 347 | |
Arnaldo Carvalho de Melo | 463c84b | 2005-08-09 20:10:42 -0700 | [diff] [blame] | 348 | #endif /* _INET_CONNECTION_SOCK_H */ |