Lines Matching +full:ideal +full:- +full:factor +full:- +full:value
1 // SPDX-License-Identifier: GPL-2.0-only
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Florian La Roche, <flla@stud.uni-sb.de>
33 * Cacophonix Gaul : draft-minshall-nagle-01
59 tp->tcp_clock_cache = val; in tcp_mstamp_refresh()
60 tp->tcp_mstamp = div_u64(val, NSEC_PER_USEC); in tcp_mstamp_refresh()
71 unsigned int prior_packets = tp->packets_out; in tcp_event_new_data_sent()
73 WRITE_ONCE(tp->snd_nxt, TCP_SKB_CB(skb)->end_seq); in tcp_event_new_data_sent()
75 __skb_unlink(skb, &sk->sk_write_queue); in tcp_event_new_data_sent()
76 tcp_rbtree_insert(&sk->tcp_rtx_queue, skb); in tcp_event_new_data_sent()
78 if (tp->highest_sack == NULL) in tcp_event_new_data_sent()
79 tp->highest_sack = skb; in tcp_event_new_data_sent()
81 tp->packets_out += tcp_skb_pcount(skb); in tcp_event_new_data_sent()
82 if (!prior_packets || icsk->icsk_pending == ICSK_TIME_LOSS_PROBE) in tcp_event_new_data_sent()
91 * window scaling factor due to loss of precision.
93 * Using SND.UNA we will fail to open window, SND.NXT is out of window. :-(
101 if (!before(tcp_wnd_end(tp), tp->snd_nxt) || in tcp_acceptable_seq()
102 (tp->rx_opt.wscale_ok && in tcp_acceptable_seq()
103 ((tp->snd_nxt - tcp_wnd_end(tp)) < (1 << tp->rx_opt.rcv_wscale)))) in tcp_acceptable_seq()
104 return tp->snd_nxt; in tcp_acceptable_seq()
110 * RFC1122, RFC1063, draft-ietf-tcpimpl-pmtud-01 state that:
113 * 2. Ideally, it is maximal possible segment size i.e. 65535-40.
120 * 5. Value 65535 for MSS is valid in IPv6 and means "as large as possible,
127 int mss = tp->advmss; in tcp_advertise_mss()
134 tp->advmss = mss; in tcp_advertise_mss()
152 tp->snd_ssthresh = tcp_current_ssthresh(sk); in tcp_cwnd_restart()
155 while ((delta -= inet_csk(sk)->icsk_rto) > 0 && cwnd > restart_cwnd) in tcp_cwnd_restart()
158 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_cwnd_restart()
159 tp->snd_cwnd_used = 0; in tcp_cwnd_restart()
172 tp->lsndtime = now; in tcp_event_data_sent()
177 if ((u32)(now - icsk->icsk_ack.lrcvtime) < icsk->icsk_ack.ato) in tcp_event_data_sent()
186 if (unlikely(tp->compressed_ack)) { in tcp_event_ack_sent()
188 tp->compressed_ack); in tcp_event_ack_sent()
189 tp->compressed_ack = 0; in tcp_event_ack_sent()
190 if (hrtimer_try_to_cancel(&tp->compressed_ack_timer) == 1) in tcp_event_ack_sent()
194 if (unlikely(rcv_nxt != tp->rcv_nxt)) in tcp_event_ack_sent()
227 * we will truncate our initial window offering to 32K-1 in tcp_select_initial_window()
232 if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_workaround_signed_windows)) in tcp_select_initial_window()
243 space = max_t(u32, space, READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rmem[2])); in tcp_select_initial_window()
246 *rcv_wscale = clamp_t(int, ilog2(space) - 15, in tcp_select_initial_window()
249 /* Set the clamp no higher than max representable value */ in tcp_select_initial_window()
257 * value can be stuffed directly into th->window for an outgoing
264 u32 old_win = tp->rcv_wnd; in tcp_select_window()
271 if (unlikely(inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOMEM)) in tcp_select_window()
280 * window in time. --DaveM in tcp_select_window()
284 if (!READ_ONCE(net->ipv4.sysctl_tcp_shrink_window) || !tp->rx_opt.rcv_wscale) { in tcp_select_window()
288 new_win = ALIGN(cur_win, 1 << tp->rx_opt.rcv_wscale); in tcp_select_window()
292 tp->rcv_wnd = new_win; in tcp_select_window()
293 tp->rcv_wup = tp->rcv_nxt; in tcp_select_window()
298 if (!tp->rx_opt.rcv_wscale && in tcp_select_window()
299 READ_ONCE(net->ipv4.sysctl_tcp_workaround_signed_windows)) in tcp_select_window()
302 new_win = min(new_win, (65535U << tp->rx_opt.rcv_wscale)); in tcp_select_window()
305 new_win >>= tp->rx_opt.rcv_wscale; in tcp_select_window()
309 tp->pred_flags = 0; in tcp_select_window()
319 /* Packet ECN state for a SYN-ACK */
324 TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_CWR; in tcp_ecn_send_synack()
325 if (!(tp->ecn_flags & TCP_ECN_OK)) in tcp_ecn_send_synack()
326 TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_ECE; in tcp_ecn_send_synack()
337 bool use_ecn = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn) == 1 || in tcp_ecn_send_syn()
347 tp->ecn_flags = 0; in tcp_ecn_send_syn()
350 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_ECE | TCPHDR_CWR; in tcp_ecn_send_syn()
351 tp->ecn_flags = TCP_ECN_OK; in tcp_ecn_send_syn()
359 if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_ecn_fallback)) in tcp_ecn_clear_syn()
360 /* tp->ecn_flags are cleared at a later point in time when in tcp_ecn_clear_syn()
363 TCP_SKB_CB(skb)->tcp_flags &= ~(TCPHDR_ECE | TCPHDR_CWR); in tcp_ecn_clear_syn()
369 if (inet_rsk(req)->ecn_ok) in tcp_ecn_make_synack()
370 th->ece = 1; in tcp_ecn_make_synack()
381 if (tp->ecn_flags & TCP_ECN_OK) { in tcp_ecn_send()
382 /* Not-retransmitted data segment: set ECT and inject CWR. */ in tcp_ecn_send()
383 if (skb->len != tcp_header_len && in tcp_ecn_send()
384 !before(TCP_SKB_CB(skb)->seq, tp->snd_nxt)) { in tcp_ecn_send()
386 if (tp->ecn_flags & TCP_ECN_QUEUE_CWR) { in tcp_ecn_send()
387 tp->ecn_flags &= ~TCP_ECN_QUEUE_CWR; in tcp_ecn_send()
388 th->cwr = 1; in tcp_ecn_send()
389 skb_shinfo(skb)->gso_type |= SKB_GSO_TCP_ECN; in tcp_ecn_send()
395 if (tp->ecn_flags & TCP_ECN_DEMAND_CWR) in tcp_ecn_send()
396 th->ece = 1; in tcp_ecn_send()
400 /* Constructs common control bits of non-data skb. If SYN/FIN is present,
405 skb->ip_summed = CHECKSUM_PARTIAL; in tcp_init_nondata_skb()
407 TCP_SKB_CB(skb)->tcp_flags = flags; in tcp_init_nondata_skb()
411 TCP_SKB_CB(skb)->seq = seq; in tcp_init_nondata_skb()
414 TCP_SKB_CB(skb)->end_seq = seq; in tcp_init_nondata_skb()
419 return tp->snd_una != tp->snd_up; in tcp_urg_mode()
464 if (unlikely(OPTION_MPTCP & opts->options)) in mptcp_options_write()
465 mptcp_write_options(th, ptr, tp, &opts->mptcp); in mptcp_options_write()
511 * Thus, "req" is passed here and the cgroup-bpf-progs in bpf_skops_hdr_opt_len()
516 * consistent between fastopen and non-fastopen on in bpf_skops_hdr_opt_len()
539 opts->bpf_opt_len = *remaining - sock_ops.remaining_opt_len; in bpf_skops_hdr_opt_len()
541 opts->bpf_opt_len = (opts->bpf_opt_len + 3) & ~3; in bpf_skops_hdr_opt_len()
543 *remaining -= opts->bpf_opt_len; in bpf_skops_hdr_opt_len()
552 u8 first_opt_off, nr_written, max_opt_len = opts->bpf_opt_len; in bpf_skops_write_hdr_opt()
575 first_opt_off = tcp_hdrlen(skb) - max_opt_len; in bpf_skops_write_hdr_opt()
583 nr_written = max_opt_len - sock_ops.remaining_opt_len; in bpf_skops_write_hdr_opt()
586 memset(skb->data + first_opt_off + nr_written, TCPOPT_NOP, in bpf_skops_write_hdr_opt()
587 max_opt_len - nr_written); in bpf_skops_write_hdr_opt()
614 u8 maclen = tcp_ao_maclen(key->ao_key); in process_tcp_ao_options()
620 (tcprsk->ao_keyid << 8) | in process_tcp_ao_options()
621 (tcprsk->ao_rcv_next)); in process_tcp_ao_options()
626 ao_info = rcu_dereference_check(tp->ao_info, in process_tcp_ao_options()
627 lockdep_sock_is_held(&tp->inet_conn.icsk_inet.sk)); in process_tcp_ao_options()
628 rnext_key = READ_ONCE(ao_info->rnext_key); in process_tcp_ao_options()
632 (tcp_ao_len(key->ao_key) << 16) | in process_tcp_ao_options()
633 (key->ao_key->sndid << 8) | in process_tcp_ao_options()
634 (rnext_key->rcvid)); in process_tcp_ao_options()
636 opts->hash_location = (__u8 *)ptr; in process_tcp_ao_options()
650 * Luckily we can at least blame others for their non-compliance but from
651 * inter-operability perspective it seems that we're somewhat stuck with
665 u16 options = opts->options; /* mungable copy */ in tcp_options_write()
671 opts->hash_location = (__u8 *)ptr; in tcp_options_write()
676 if (unlikely(opts->mss)) { in tcp_options_write()
679 opts->mss); in tcp_options_write()
695 *ptr++ = htonl(opts->tsval); in tcp_options_write()
696 *ptr++ = htonl(opts->tsecr); in tcp_options_write()
710 opts->ws); in tcp_options_write()
713 if (unlikely(opts->num_sack_blocks)) { in tcp_options_write()
714 struct tcp_sack_block *sp = tp->rx_opt.dsack ? in tcp_options_write()
715 tp->duplicate_sack : tp->selective_acks; in tcp_options_write()
721 (TCPOLEN_SACK_BASE + (opts->num_sack_blocks * in tcp_options_write()
724 for (this_sack = 0; this_sack < opts->num_sack_blocks; in tcp_options_write()
730 tp->rx_opt.dsack = 0; in tcp_options_write()
734 struct tcp_fastopen_cookie *foc = opts->fastopen_cookie; in tcp_options_write()
738 if (foc->exp) { in tcp_options_write()
739 len = TCPOLEN_EXP_FASTOPEN_BASE + foc->len; in tcp_options_write()
744 len = TCPOLEN_FASTOPEN_BASE + foc->len; in tcp_options_write()
749 memcpy(p, foc->val, foc->len); in tcp_options_write()
751 p[foc->len] = TCPOPT_NOP; in tcp_options_write()
752 p[foc->len + 1] = TCPOPT_NOP; in tcp_options_write()
768 if (tp->syn_smc) { in smc_set_option()
770 opts->options |= OPTION_SMC; in smc_set_option()
771 *remaining -= TCPOLEN_EXP_SMC_BASE_ALIGNED; in smc_set_option()
785 if (tp->syn_smc && ireq->smc_ok) { in smc_set_option_cond()
787 opts->options |= OPTION_SMC; in smc_set_option_cond()
788 *remaining -= TCPOLEN_EXP_SMC_BASE_ALIGNED; in smc_set_option_cond()
802 if (mptcp_synack_options(req, &size, &opts->mptcp)) { in mptcp_set_option_cond()
804 opts->options |= OPTION_MPTCP; in mptcp_set_option_cond()
805 *remaining -= size; in mptcp_set_option_cond()
820 struct tcp_fastopen_request *fastopen = tp->fastopen_req; in tcp_syn_options()
826 opts->options |= OPTION_MD5; in tcp_syn_options()
827 remaining -= TCPOLEN_MD5SIG_ALIGNED; in tcp_syn_options()
829 timestamps = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps); in tcp_syn_options()
831 opts->options |= OPTION_AO; in tcp_syn_options()
832 remaining -= tcp_ao_len_aligned(key->ao_key); in tcp_syn_options()
838 * advertised. But we subtract them from tp->mss_cache so that in tcp_syn_options()
845 opts->mss = tcp_advertise_mss(sk); in tcp_syn_options()
846 remaining -= TCPOLEN_MSS_ALIGNED; in tcp_syn_options()
849 opts->options |= OPTION_TS; in tcp_syn_options()
850 opts->tsval = tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb) + tp->tsoffset; in tcp_syn_options()
851 opts->tsecr = tp->rx_opt.ts_recent; in tcp_syn_options()
852 remaining -= TCPOLEN_TSTAMP_ALIGNED; in tcp_syn_options()
854 if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling))) { in tcp_syn_options()
855 opts->ws = tp->rx_opt.rcv_wscale; in tcp_syn_options()
856 opts->options |= OPTION_WSCALE; in tcp_syn_options()
857 remaining -= TCPOLEN_WSCALE_ALIGNED; in tcp_syn_options()
859 if (likely(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_sack))) { in tcp_syn_options()
860 opts->options |= OPTION_SACK_ADVERTISE; in tcp_syn_options()
861 if (unlikely(!(OPTION_TS & opts->options))) in tcp_syn_options()
862 remaining -= TCPOLEN_SACKPERM_ALIGNED; in tcp_syn_options()
865 if (fastopen && fastopen->cookie.len >= 0) { in tcp_syn_options()
866 u32 need = fastopen->cookie.len; in tcp_syn_options()
868 need += fastopen->cookie.exp ? TCPOLEN_EXP_FASTOPEN_BASE : in tcp_syn_options()
872 opts->options |= OPTION_FAST_OPEN_COOKIE; in tcp_syn_options()
873 opts->fastopen_cookie = &fastopen->cookie; in tcp_syn_options()
874 remaining -= need; in tcp_syn_options()
875 tp->syn_fastopen = 1; in tcp_syn_options()
876 tp->syn_fastopen_exp = fastopen->cookie.exp ? 1 : 0; in tcp_syn_options()
885 if (mptcp_syn_options(sk, skb, &size, &opts->mptcp)) { in tcp_syn_options()
886 opts->options |= OPTION_MPTCP; in tcp_syn_options()
887 remaining -= size; in tcp_syn_options()
893 return MAX_TCP_OPTION_SPACE - remaining; in tcp_syn_options()
896 /* Set up TCP options for SYN-ACKs. */
910 opts->options |= OPTION_MD5; in tcp_synack_options()
911 remaining -= TCPOLEN_MD5SIG_ALIGNED; in tcp_synack_options()
919 ireq->tstamp_ok &= !ireq->sack_ok; in tcp_synack_options()
921 opts->options |= OPTION_AO; in tcp_synack_options()
922 remaining -= tcp_ao_len_aligned(key->ao_key); in tcp_synack_options()
923 ireq->tstamp_ok &= !ireq->sack_ok; in tcp_synack_options()
927 opts->mss = mss; in tcp_synack_options()
928 remaining -= TCPOLEN_MSS_ALIGNED; in tcp_synack_options()
930 if (likely(ireq->wscale_ok)) { in tcp_synack_options()
931 opts->ws = ireq->rcv_wscale; in tcp_synack_options()
932 opts->options |= OPTION_WSCALE; in tcp_synack_options()
933 remaining -= TCPOLEN_WSCALE_ALIGNED; in tcp_synack_options()
935 if (likely(ireq->tstamp_ok)) { in tcp_synack_options()
936 opts->options |= OPTION_TS; in tcp_synack_options()
937 opts->tsval = tcp_skb_timestamp_ts(tcp_rsk(req)->req_usec_ts, skb) + in tcp_synack_options()
938 tcp_rsk(req)->ts_off; in tcp_synack_options()
939 opts->tsecr = READ_ONCE(req->ts_recent); in tcp_synack_options()
940 remaining -= TCPOLEN_TSTAMP_ALIGNED; in tcp_synack_options()
942 if (likely(ireq->sack_ok)) { in tcp_synack_options()
943 opts->options |= OPTION_SACK_ADVERTISE; in tcp_synack_options()
944 if (unlikely(!ireq->tstamp_ok)) in tcp_synack_options()
945 remaining -= TCPOLEN_SACKPERM_ALIGNED; in tcp_synack_options()
947 if (foc != NULL && foc->len >= 0) { in tcp_synack_options()
948 u32 need = foc->len; in tcp_synack_options()
950 need += foc->exp ? TCPOLEN_EXP_FASTOPEN_BASE : in tcp_synack_options()
954 opts->options |= OPTION_FAST_OPEN_COOKIE; in tcp_synack_options()
955 opts->fastopen_cookie = foc; in tcp_synack_options()
956 remaining -= need; in tcp_synack_options()
967 return MAX_TCP_OPTION_SPACE - remaining; in tcp_synack_options()
981 opts->options = 0; in tcp_established_options()
985 opts->options |= OPTION_MD5; in tcp_established_options()
988 opts->options |= OPTION_AO; in tcp_established_options()
989 size += tcp_ao_len_aligned(key->ao_key); in tcp_established_options()
992 if (likely(tp->rx_opt.tstamp_ok)) { in tcp_established_options()
993 opts->options |= OPTION_TS; in tcp_established_options()
994 opts->tsval = skb ? tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb) + in tcp_established_options()
995 tp->tsoffset : 0; in tcp_established_options()
996 opts->tsecr = tp->rx_opt.ts_recent; in tcp_established_options()
1007 unsigned int remaining = MAX_TCP_OPTION_SPACE - size; in tcp_established_options()
1011 &opts->mptcp)) { in tcp_established_options()
1012 opts->options |= OPTION_MPTCP; in tcp_established_options()
1017 eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack; in tcp_established_options()
1019 const unsigned int remaining = MAX_TCP_OPTION_SPACE - size; in tcp_established_options()
1024 opts->num_sack_blocks = in tcp_established_options()
1026 (remaining - TCPOLEN_SACK_BASE_ALIGNED) / in tcp_established_options()
1030 opts->num_sack_blocks * TCPOLEN_SACK_PERBLOCK; in tcp_established_options()
1035 unsigned int remaining = MAX_TCP_OPTION_SPACE - size; in tcp_established_options()
1039 size = MAX_TCP_OPTION_SPACE - remaining; in tcp_established_options()
1054 * The invariant being skb->truesize subtracted from sk->sk_wmem_alloc
1068 if ((1 << sk->sk_state) & in tcp_tsq_write()
1073 if (tp->lost_out > tp->retrans_out && in tcp_tsq_write()
1079 tcp_write_xmit(sk, tcp_current_mss(sk), tp->nonagle, in tcp_tsq_write()
1089 else if (!test_and_set_bit(TCP_TSQ_DEFERRED, &sk->sk_tsq_flags)) in tcp_tsq_handler()
1096 * transferring tsq->head because tcp_wfree() might
1109 list_splice_init(&tsq->head, &list); in tcp_tasklet_func()
1114 list_del(&tp->tsq_node); in tcp_tasklet_func()
1118 clear_bit(TSQ_QUEUED, &sk->sk_tsq_flags); in tcp_tasklet_func()
1131 * tcp_release_cb - tcp release_sock() callback
1139 unsigned long flags = smp_load_acquire(&sk->sk_tsq_flags); in tcp_release_cb()
1147 } while (!try_cmpxchg(&sk->sk_tsq_flags, &flags, nflags)); in tcp_release_cb()
1163 inet_csk(sk)->icsk_af_ops->mtu_reduced(sk); in tcp_release_cb()
1178 INIT_LIST_HEAD(&tsq->head); in tcp_tasklet_init()
1179 tasklet_setup(&tsq->tasklet, tcp_tasklet_func); in tcp_tasklet_init()
1190 struct sock *sk = skb->sk; in tcp_wfree()
1199 WARN_ON(refcount_sub_and_test(skb->truesize - 1, &sk->sk_wmem_alloc)); in tcp_wfree()
1204 * - less callbacks to tcp_write_xmit(), reducing stress (batches) in tcp_wfree()
1205 * - chance for incoming ACK (processed by another cpu maybe) in tcp_wfree()
1206 * to migrate this flow (skb->ooo_okay will be eventually set) in tcp_wfree()
1208 if (refcount_read(&sk->sk_wmem_alloc) >= SKB_TRUESIZE(1) && this_cpu_ksoftirqd() == current) in tcp_wfree()
1211 oval = smp_load_acquire(&sk->sk_tsq_flags); in tcp_wfree()
1217 } while (!try_cmpxchg(&sk->sk_tsq_flags, &oval, nval)); in tcp_wfree()
1222 empty = list_empty(&tsq->head); in tcp_wfree()
1223 list_add(&tp->tsq_node, &tsq->head); in tcp_wfree()
1225 tasklet_schedule(&tsq->tasklet); in tcp_wfree()
1251 if (sk->sk_pacing_status != SK_PACING_NONE) { in tcp_update_skb_after_send()
1252 unsigned long rate = READ_ONCE(sk->sk_pacing_rate); in tcp_update_skb_after_send()
1255 * Note that tp->data_segs_out overflows after 2^32 packets, in tcp_update_skb_after_send()
1258 if (rate != ~0UL && rate && tp->data_segs_out >= 10) { in tcp_update_skb_after_send()
1259 u64 len_ns = div64_ul((u64)skb->len * NSEC_PER_SEC, rate); in tcp_update_skb_after_send()
1260 u64 credit = tp->tcp_wstamp_ns - prior_wstamp; in tcp_update_skb_after_send()
1263 len_ns -= min_t(u64, len_ns / 2, credit); in tcp_update_skb_after_send()
1264 tp->tcp_wstamp_ns += len_ns; in tcp_update_skb_after_send()
1267 list_move_tail(&skb->tcp_tsorted_anchor, &tp->tsorted_sent_queue); in tcp_update_skb_after_send()
1302 prior_wstamp = tp->tcp_wstamp_ns; in __tcp_transmit_skb()
1303 tp->tcp_wstamp_ns = max(tp->tcp_wstamp_ns, tp->tcp_clock_cache); in __tcp_transmit_skb()
1304 skb_set_delivery_time(skb, tp->tcp_wstamp_ns, SKB_CLOCK_MONOTONIC); in __tcp_transmit_skb()
1316 return -ENOBUFS; in __tcp_transmit_skb()
1317 /* retransmit skbs might have a non zero value in skb->dev in __tcp_transmit_skb()
1318 * because skb->dev is aliased with skb->rbnode.rb_left in __tcp_transmit_skb()
1320 skb->dev = NULL; in __tcp_transmit_skb()
1328 if (unlikely(tcb->tcp_flags & TCPHDR_SYN)) { in __tcp_transmit_skb()
1336 * and in this case it is better to delay the delivery of 1-MSS in __tcp_transmit_skb()
1341 tcb->tcp_flags |= TCPHDR_PSH; in __tcp_transmit_skb()
1345 /* We set skb->ooo_okay to one if this packet can select in __tcp_transmit_skb()
1349 * if XPS is enabled, or sk->sk_txhash otherwise. in __tcp_transmit_skb()
1358 skb->ooo_okay = sk_wmem_alloc_get(sk) < SKB_TRUESIZE(1) || in __tcp_transmit_skb()
1366 skb->pfmemalloc = 0; in __tcp_transmit_skb()
1372 skb->sk = sk; in __tcp_transmit_skb()
1373 skb->destructor = skb_is_tcp_pure_ack(skb) ? __sock_wfree : tcp_wfree; in __tcp_transmit_skb()
1374 refcount_add(skb->truesize, &sk->sk_wmem_alloc); in __tcp_transmit_skb()
1376 skb_set_dst_pending_confirm(skb, READ_ONCE(sk->sk_dst_pending_confirm)); in __tcp_transmit_skb()
1379 th = (struct tcphdr *)skb->data; in __tcp_transmit_skb()
1380 th->source = inet->inet_sport; in __tcp_transmit_skb()
1381 th->dest = inet->inet_dport; in __tcp_transmit_skb()
1382 th->seq = htonl(tcb->seq); in __tcp_transmit_skb()
1383 th->ack_seq = htonl(rcv_nxt); in __tcp_transmit_skb()
1385 tcb->tcp_flags); in __tcp_transmit_skb()
1387 th->check = 0; in __tcp_transmit_skb()
1388 th->urg_ptr = 0; in __tcp_transmit_skb()
1391 if (unlikely(tcp_urg_mode(tp) && before(tcb->seq, tp->snd_up))) { in __tcp_transmit_skb()
1392 if (before(tp->snd_up, tcb->seq + 0x10000)) { in __tcp_transmit_skb()
1393 th->urg_ptr = htons(tp->snd_up - tcb->seq); in __tcp_transmit_skb()
1394 th->urg = 1; in __tcp_transmit_skb()
1395 } else if (after(tcb->seq + 0xFFFF, tp->snd_nxt)) { in __tcp_transmit_skb()
1396 th->urg_ptr = htons(0xFFFF); in __tcp_transmit_skb()
1397 th->urg = 1; in __tcp_transmit_skb()
1401 skb_shinfo(skb)->gso_type = sk->sk_gso_type; in __tcp_transmit_skb()
1402 if (likely(!(tcb->tcp_flags & TCPHDR_SYN))) { in __tcp_transmit_skb()
1403 th->window = htons(tcp_select_window(sk)); in __tcp_transmit_skb()
1409 th->window = htons(min(tp->rcv_wnd, 65535U)); in __tcp_transmit_skb()
1418 tp->af_specific->calc_md5_hash(opts.hash_location, in __tcp_transmit_skb()
1428 return -ENOMEM; in __tcp_transmit_skb()
1435 INDIRECT_CALL_INET(icsk->icsk_af_ops->send_check, in __tcp_transmit_skb()
1439 if (likely(tcb->tcp_flags & TCPHDR_ACK)) in __tcp_transmit_skb()
1442 if (skb->len != tcp_header_size) { in __tcp_transmit_skb()
1444 tp->data_segs_out += tcp_skb_pcount(skb); in __tcp_transmit_skb()
1445 tp->bytes_sent += skb->len - tcp_header_size; in __tcp_transmit_skb()
1448 if (after(tcb->end_seq, tp->snd_nxt) || tcb->seq == tcb->end_seq) in __tcp_transmit_skb()
1452 tp->segs_out += tcp_skb_pcount(skb); in __tcp_transmit_skb()
1454 /* OK, its time to fill skb_shinfo(skb)->gso_{segs|size} */ in __tcp_transmit_skb()
1455 skb_shinfo(skb)->gso_segs = tcp_skb_pcount(skb); in __tcp_transmit_skb()
1456 skb_shinfo(skb)->gso_size = tcp_skb_mss(skb); in __tcp_transmit_skb()
1458 /* Leave earliest departure time in skb->tstamp (skb->skb_mstamp_ns) */ in __tcp_transmit_skb()
1461 memset(skb->cb, 0, max(sizeof(struct inet_skb_parm), in __tcp_transmit_skb()
1466 err = INDIRECT_CALL_INET(icsk->icsk_af_ops->queue_xmit, in __tcp_transmit_skb()
1468 sk, skb, &inet->cork.fl); in __tcp_transmit_skb()
1485 tcp_sk(sk)->rcv_nxt); in tcp_transmit_skb()
1498 WRITE_ONCE(tp->write_seq, TCP_SKB_CB(skb)->end_seq); in tcp_queue_skb()
1501 sk_wmem_queued_add(sk, skb->truesize); in tcp_queue_skb()
1502 sk_mem_charge(sk, skb->truesize); in tcp_queue_skb()
1510 if (skb->len <= mss_now) { in tcp_set_skb_tso_segs()
1512 * non-TSO case. in tcp_set_skb_tso_segs()
1514 TCP_SKB_CB(skb)->tcp_gso_size = 0; in tcp_set_skb_tso_segs()
1518 TCP_SKB_CB(skb)->tcp_gso_size = mss_now; in tcp_set_skb_tso_segs()
1519 tso_segs = DIV_ROUND_UP(skb->len, mss_now); in tcp_set_skb_tso_segs()
1531 tp->packets_out -= decr; in tcp_adjust_pcount()
1533 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED) in tcp_adjust_pcount()
1534 tp->sacked_out -= decr; in tcp_adjust_pcount()
1535 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS) in tcp_adjust_pcount()
1536 tp->retrans_out -= decr; in tcp_adjust_pcount()
1537 if (TCP_SKB_CB(skb)->sacked & TCPCB_LOST) in tcp_adjust_pcount()
1538 tp->lost_out -= decr; in tcp_adjust_pcount()
1542 tp->sacked_out -= min_t(u32, tp->sacked_out, decr); in tcp_adjust_pcount()
1544 if (tp->lost_skb_hint && in tcp_adjust_pcount()
1545 before(TCP_SKB_CB(skb)->seq, TCP_SKB_CB(tp->lost_skb_hint)->seq) && in tcp_adjust_pcount()
1546 (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED)) in tcp_adjust_pcount()
1547 tp->lost_cnt_hint -= decr; in tcp_adjust_pcount()
1554 return TCP_SKB_CB(skb)->txstamp_ack || in tcp_has_tx_tstamp()
1555 (skb_shinfo(skb)->tx_flags & SKBTX_ANY_TSTAMP); in tcp_has_tx_tstamp()
1563 !before(shinfo->tskey, TCP_SKB_CB(skb2)->seq)) { in tcp_fragment_tstamp()
1565 u8 tsflags = shinfo->tx_flags & SKBTX_ANY_TSTAMP; in tcp_fragment_tstamp()
1567 shinfo->tx_flags &= ~tsflags; in tcp_fragment_tstamp()
1568 shinfo2->tx_flags |= tsflags; in tcp_fragment_tstamp()
1569 swap(shinfo->tskey, shinfo2->tskey); in tcp_fragment_tstamp()
1570 TCP_SKB_CB(skb2)->txstamp_ack = TCP_SKB_CB(skb)->txstamp_ack; in tcp_fragment_tstamp()
1571 TCP_SKB_CB(skb)->txstamp_ack = 0; in tcp_fragment_tstamp()
1577 TCP_SKB_CB(skb2)->eor = TCP_SKB_CB(skb)->eor; in tcp_skb_fragment_eor()
1578 TCP_SKB_CB(skb)->eor = 0; in tcp_skb_fragment_eor()
1588 __skb_queue_after(&sk->sk_write_queue, skb, buff); in tcp_insert_write_queue_after()
1590 tcp_rbtree_insert(&sk->tcp_rtx_queue, buff); in tcp_insert_write_queue_after()
1609 if (WARN_ON(len > skb->len)) in tcp_fragment()
1610 return -EINVAL; in tcp_fragment()
1619 limit = sk->sk_sndbuf + 2 * SKB_TRUESIZE(GSO_LEGACY_MAX_SIZE); in tcp_fragment()
1620 if (unlikely((sk->sk_wmem_queued >> 1) > limit && in tcp_fragment()
1625 return -ENOMEM; in tcp_fragment()
1629 return -ENOMEM; in tcp_fragment()
1634 return -ENOMEM; /* We'll just try again later. */ in tcp_fragment()
1638 sk_wmem_queued_add(sk, buff->truesize); in tcp_fragment()
1639 sk_mem_charge(sk, buff->truesize); in tcp_fragment()
1640 nlen = skb->len - len; in tcp_fragment()
1641 buff->truesize += nlen; in tcp_fragment()
1642 skb->truesize -= nlen; in tcp_fragment()
1645 TCP_SKB_CB(buff)->seq = TCP_SKB_CB(skb)->seq + len; in tcp_fragment()
1646 TCP_SKB_CB(buff)->end_seq = TCP_SKB_CB(skb)->end_seq; in tcp_fragment()
1647 TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(buff)->seq; in tcp_fragment()
1650 flags = TCP_SKB_CB(skb)->tcp_flags; in tcp_fragment()
1651 TCP_SKB_CB(skb)->tcp_flags = flags & ~(TCPHDR_FIN | TCPHDR_PSH); in tcp_fragment()
1652 TCP_SKB_CB(buff)->tcp_flags = flags; in tcp_fragment()
1653 TCP_SKB_CB(buff)->sacked = TCP_SKB_CB(skb)->sacked; in tcp_fragment()
1658 skb_set_delivery_time(buff, skb->tstamp, SKB_CLOCK_MONOTONIC); in tcp_fragment()
1668 TCP_SKB_CB(buff)->tx = TCP_SKB_CB(skb)->tx; in tcp_fragment()
1673 if (!before(tp->snd_nxt, TCP_SKB_CB(buff)->end_seq)) { in tcp_fragment()
1674 int diff = old_factor - tcp_skb_pcount(skb) - in tcp_fragment()
1685 list_add(&buff->tcp_tsorted_anchor, &skb->tcp_tsorted_anchor); in tcp_fragment()
1702 for (i = 0; i < shinfo->nr_frags; i++) { in __pskb_trim_head()
1703 int size = skb_frag_size(&shinfo->frags[i]); in __pskb_trim_head()
1707 eat -= size; in __pskb_trim_head()
1709 shinfo->frags[k] = shinfo->frags[i]; in __pskb_trim_head()
1711 skb_frag_off_add(&shinfo->frags[k], eat); in __pskb_trim_head()
1712 skb_frag_size_sub(&shinfo->frags[k], eat); in __pskb_trim_head()
1718 shinfo->nr_frags = k; in __pskb_trim_head()
1720 skb->data_len -= len; in __pskb_trim_head()
1721 skb->len = skb->data_len; in __pskb_trim_head()
1731 return -ENOMEM; in tcp_trim_head()
1735 TCP_SKB_CB(skb)->seq += len; in tcp_trim_head()
1737 skb->truesize -= delta_truesize; in tcp_trim_head()
1738 sk_wmem_queued_add(sk, -delta_truesize); in tcp_trim_head()
1742 /* Any change of skb->len requires recalculation of tso factor. */ in tcp_trim_head()
1757 It is MMS_S - sizeof(tcphdr) of rfc1122 in __tcp_mtu_to_mss()
1759 mss_now = pmtu - icsk->icsk_af_ops->net_header_len - sizeof(struct tcphdr); in __tcp_mtu_to_mss()
1762 if (mss_now > tp->rx_opt.mss_clamp) in __tcp_mtu_to_mss()
1763 mss_now = tp->rx_opt.mss_clamp; in __tcp_mtu_to_mss()
1766 mss_now -= icsk->icsk_ext_hdr_len; in __tcp_mtu_to_mss()
1770 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_snd_mss)); in __tcp_mtu_to_mss()
1778 return __tcp_mtu_to_mss(sk, pmtu) - in tcp_mtu_to_mss()
1779 (tcp_sk(sk)->tcp_header_len - sizeof(struct tcphdr)); in tcp_mtu_to_mss()
1790 tp->tcp_header_len + in tcp_mss_to_mtu()
1791 icsk->icsk_ext_hdr_len + in tcp_mss_to_mtu()
1792 icsk->icsk_af_ops->net_header_len; in tcp_mss_to_mtu()
1803 icsk->icsk_mtup.enabled = READ_ONCE(net->ipv4.sysctl_tcp_mtu_probing) > 1; in tcp_mtup_init()
1804 icsk->icsk_mtup.search_high = tp->rx_opt.mss_clamp + sizeof(struct tcphdr) + in tcp_mtup_init()
1805 icsk->icsk_af_ops->net_header_len; in tcp_mtup_init()
1806 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, READ_ONCE(net->ipv4.sysctl_tcp_base_mss)); in tcp_mtup_init()
1807 icsk->icsk_mtup.probe_size = 0; in tcp_mtup_init()
1808 if (icsk->icsk_mtup.enabled) in tcp_mtup_init()
1809 icsk->icsk_mtup.probe_timestamp = tcp_jiffies32; in tcp_mtup_init()
1815 tp->rx_opt.user_mss is mss set by user by TCP_MAXSEG. It does NOT counts
1818 tp->rx_opt.mss_clamp is mss negotiated at connection setup.
1822 inet_csk(sk)->icsk_pmtu_cookie is last pmtu, seen by this function.
1824 tp->mss_cache is current effective sending mss, including
1827 tp->rx_opt.mss_clamp.
1832 NOTE2. inet_csk(sk)->icsk_pmtu_cookie and tp->mss_cache
1833 are READ ONLY outside this function. --ANK (980731)
1841 if (icsk->icsk_mtup.search_high > pmtu) in tcp_sync_mss()
1842 icsk->icsk_mtup.search_high = pmtu; in tcp_sync_mss()
1848 icsk->icsk_pmtu_cookie = pmtu; in tcp_sync_mss()
1849 if (icsk->icsk_mtup.enabled) in tcp_sync_mss()
1850 mss_now = min(mss_now, tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low)); in tcp_sync_mss()
1851 tp->mss_cache = mss_now; in tcp_sync_mss()
1869 mss_now = tp->mss_cache; in tcp_current_mss()
1873 if (mtu != inet_csk(sk)->icsk_pmtu_cookie) in tcp_current_mss()
1879 /* The mss_cache is sized based on tp->tcp_header_len, which assumes in tcp_current_mss()
1883 if (header_len != tp->tcp_header_len) { in tcp_current_mss()
1884 int delta = (int) header_len - tp->tcp_header_len; in tcp_current_mss()
1885 mss_now -= delta; in tcp_current_mss()
1899 if (inet_csk(sk)->icsk_ca_state == TCP_CA_Open && in tcp_cwnd_application_limited()
1900 sk->sk_socket && !test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { in tcp_cwnd_application_limited()
1903 u32 win_used = max(tp->snd_cwnd_used, init_win); in tcp_cwnd_application_limited()
1905 tp->snd_ssthresh = tcp_current_ssthresh(sk); in tcp_cwnd_application_limited()
1908 tp->snd_cwnd_used = 0; in tcp_cwnd_application_limited()
1910 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_cwnd_application_limited()
1915 const struct tcp_congestion_ops *ca_ops = inet_csk(sk)->icsk_ca_ops; in tcp_cwnd_validate()
1919 * is fully utilized. If cwnd-limited then remember that fact for the in tcp_cwnd_validate()
1920 * current window. If not cwnd-limited then track the maximum number of in tcp_cwnd_validate()
1921 * outstanding packets in the current window. (If cwnd-limited then we in tcp_cwnd_validate()
1922 * chose to not update tp->max_packets_out to avoid an extra else in tcp_cwnd_validate()
1925 if (!before(tp->snd_una, tp->cwnd_usage_seq) || in tcp_cwnd_validate()
1927 (!tp->is_cwnd_limited && in tcp_cwnd_validate()
1928 tp->packets_out > tp->max_packets_out)) { in tcp_cwnd_validate()
1929 tp->is_cwnd_limited = is_cwnd_limited; in tcp_cwnd_validate()
1930 tp->max_packets_out = tp->packets_out; in tcp_cwnd_validate()
1931 tp->cwnd_usage_seq = tp->snd_nxt; in tcp_cwnd_validate()
1936 tp->snd_cwnd_used = 0; in tcp_cwnd_validate()
1937 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_cwnd_validate()
1940 if (tp->packets_out > tp->snd_cwnd_used) in tcp_cwnd_validate()
1941 tp->snd_cwnd_used = tp->packets_out; in tcp_cwnd_validate()
1943 if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle) && in tcp_cwnd_validate()
1944 (s32)(tcp_jiffies32 - tp->snd_cwnd_stamp) >= inet_csk(sk)->icsk_rto && in tcp_cwnd_validate()
1945 !ca_ops->cong_control) in tcp_cwnd_validate()
1955 if (tcp_write_queue_empty(sk) && sk->sk_socket && in tcp_cwnd_validate()
1956 test_bit(SOCK_NOSPACE, &sk->sk_socket->flags) && in tcp_cwnd_validate()
1957 (1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) in tcp_cwnd_validate()
1965 return after(tp->snd_sml, tp->snd_una) && in tcp_minshall_check()
1966 !after(tp->snd_sml, tp->snd_nxt); in tcp_minshall_check()
1970 * Note that a TSO packet might end with a sub-mss segment
1972 * if ((skb->len % mss) != 0)
1973 * tp->snd_sml = TCP_SKB_CB(skb)->end_seq;
1975 * skb_pcount = skb->len / mss_now
1980 if (skb->len < tcp_skb_pcount(skb) * mss_now) in tcp_minshall_update()
1981 tp->snd_sml = TCP_SKB_CB(skb)->end_seq; in tcp_minshall_update()
1996 (!nonagle && tp->packets_out && tcp_minshall_check(tp))); in tcp_nagle_check()
2003 * - For close peers, we rather send bigger packets to reduce
2005 * - For long distance/rtt flows, we would like to get ACK clocking
2009 * in bigger TSO bursts. We we cut the RTT-based allowance in half
2010 * for every 2^9 usec (aka 512 us) of RTT, so that the RTT-based allowance
2019 bytes = READ_ONCE(sk->sk_pacing_rate) >> READ_ONCE(sk->sk_pacing_shift); in tcp_tso_autosize()
2021 r = tcp_min_rtt(tcp_sk(sk)) >> READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_tso_rtt_log); in tcp_tso_autosize()
2022 if (r < BITS_PER_TYPE(sk->sk_gso_max_size)) in tcp_tso_autosize()
2023 bytes += sk->sk_gso_max_size >> r; in tcp_tso_autosize()
2025 bytes = min_t(unsigned long, bytes, sk->sk_gso_max_size); in tcp_tso_autosize()
2035 const struct tcp_congestion_ops *ca_ops = inet_csk(sk)->icsk_ca_ops; in tcp_tso_segs()
2038 min_tso = ca_ops->min_tso_segs ? in tcp_tso_segs()
2039 ca_ops->min_tso_segs(sk) : in tcp_tso_segs()
2040 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_tso_segs); in tcp_tso_segs()
2043 return min_t(u32, tso_segs, sk->sk_gso_max_segs); in tcp_tso_segs()
2056 window = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq; in tcp_mss_split_point()
2062 needed = min(skb->len, window); in tcp_mss_split_point()
2073 return needed - partial; in tcp_mss_split_point()
2094 return min(halfcwnd, cwnd - in_flight); in tcp_cwnd_test()
2128 if (tcp_urg_mode(tp) || (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)) in tcp_nagle_test()
2131 if (!tcp_nagle_check(skb->len < cur_mss, tp, nonagle)) in tcp_nagle_test()
2142 u32 end_seq = TCP_SKB_CB(skb)->end_seq; in tcp_snd_wnd_test()
2144 if (skb->len > cur_mss) in tcp_snd_wnd_test()
2145 end_seq = TCP_SKB_CB(skb)->seq + cur_mss; in tcp_snd_wnd_test()
2154 * know that all the data is in scatter-gather pages, and that the
2160 int nlen = skb->len - len; in tso_fragment()
2165 DEBUG_NET_WARN_ON_ONCE(skb->len != skb->data_len); in tso_fragment()
2169 return -ENOMEM; in tso_fragment()
2173 sk_wmem_queued_add(sk, buff->truesize); in tso_fragment()
2174 sk_mem_charge(sk, buff->truesize); in tso_fragment()
2175 buff->truesize += nlen; in tso_fragment()
2176 skb->truesize -= nlen; in tso_fragment()
2179 TCP_SKB_CB(buff)->seq = TCP_SKB_CB(skb)->seq + len; in tso_fragment()
2180 TCP_SKB_CB(buff)->end_seq = TCP_SKB_CB(skb)->end_seq; in tso_fragment()
2181 TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(buff)->seq; in tso_fragment()
2184 flags = TCP_SKB_CB(skb)->tcp_flags; in tso_fragment()
2185 TCP_SKB_CB(skb)->tcp_flags = flags & ~(TCPHDR_FIN | TCPHDR_PSH); in tso_fragment()
2186 TCP_SKB_CB(buff)->tcp_flags = flags; in tso_fragment()
2221 if (icsk->icsk_ca_state >= TCP_CA_Recovery) in tcp_tso_should_defer()
2226 * Note that tp->tcp_wstamp_ns can be in the future if we have in tcp_tso_should_defer()
2229 delta = tp->tcp_clock_cache - tp->tcp_wstamp_ns - NSEC_PER_MSEC; in tcp_tso_should_defer()
2238 send_win = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq; in tcp_tso_should_defer()
2241 cong_win = (tcp_snd_cwnd(tp) - in_flight) * tp->mss_cache; in tcp_tso_should_defer()
2245 /* If a full-sized TSO skb can be sent, do it. */ in tcp_tso_should_defer()
2246 if (limit >= max_segs * tp->mss_cache) in tcp_tso_should_defer()
2250 if ((skb != tcp_write_queue_tail(sk)) && (limit >= skb->len)) in tcp_tso_should_defer()
2253 win_divisor = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_tso_win_divisor); in tcp_tso_should_defer()
2255 u32 chunk = min(tp->snd_wnd, tcp_snd_cwnd(tp) * tp->mss_cache); in tcp_tso_should_defer()
2269 if (limit > tcp_max_tso_deferred_mss(tp) * tp->mss_cache) in tcp_tso_should_defer()
2277 delta = tp->tcp_clock_cache - head->tstamp; in tcp_tso_should_defer()
2279 if ((s64)(delta - (u64)NSEC_PER_USEC * (tp->srtt_us >> 4)) < 0) in tcp_tso_should_defer()
2284 * 1) We are cwnd-limited in tcp_tso_should_defer()
2285 * 2) We are rwnd-limited in tcp_tso_should_defer()
2289 if (cong_win <= skb->len) { in tcp_tso_should_defer()
2294 if (send_win <= skb->len) { in tcp_tso_should_defer()
2301 if ((TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) || in tcp_tso_should_defer()
2302 TCP_SKB_CB(skb)->eor) in tcp_tso_should_defer()
2319 interval = READ_ONCE(net->ipv4.sysctl_tcp_probe_interval); in tcp_mtu_check_reprobe()
2320 delta = tcp_jiffies32 - icsk->icsk_mtup.probe_timestamp; in tcp_mtu_check_reprobe()
2325 icsk->icsk_mtup.probe_size = 0; in tcp_mtu_check_reprobe()
2326 icsk->icsk_mtup.search_high = tp->rx_opt.mss_clamp + in tcp_mtu_check_reprobe()
2328 icsk->icsk_af_ops->net_header_len; in tcp_mtu_check_reprobe()
2329 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss); in tcp_mtu_check_reprobe()
2332 icsk->icsk_mtup.probe_timestamp = tcp_jiffies32; in tcp_mtu_check_reprobe()
2342 if (len <= skb->len) in tcp_can_coalesce_send_queue_head()
2348 len -= skb->len; in tcp_can_coalesce_send_queue_head()
2357 skb_frag_t *lastfrag = NULL, *fragto = skb_shinfo(to)->frags; in tcp_clone_payload()
2361 if (!sk_wmem_schedule(sk, to->truesize + probe_size)) in tcp_clone_payload()
2362 return -ENOMEM; in tcp_clone_payload()
2364 skb_queue_walk(&sk->sk_write_queue, skb) { in tcp_clone_payload()
2365 const skb_frag_t *fragfrom = skb_shinfo(skb)->frags; in tcp_clone_payload()
2368 return -EINVAL; in tcp_clone_payload()
2370 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++, fragfrom++) { in tcp_clone_payload()
2374 probe_size - len); in tcp_clone_payload()
2384 return -E2BIG; in tcp_clone_payload()
2397 skb_shinfo(to)->nr_frags = nr_frags; in tcp_clone_payload()
2398 to->truesize += probe_size; in tcp_clone_payload()
2399 to->len += probe_size; in tcp_clone_payload()
2400 to->data_len += probe_size; in tcp_clone_payload()
2413 TCP_SKB_CB(dst)->tcp_flags |= TCP_SKB_CB(src)->tcp_flags; in tcp_eat_one_skb()
2414 TCP_SKB_CB(dst)->eor = TCP_SKB_CB(src)->eor; in tcp_eat_one_skb()
2427 * -1 otherwise
2446 if (likely(!icsk->icsk_mtup.enabled || in tcp_mtu_probe()
2447 icsk->icsk_mtup.probe_size || in tcp_mtu_probe()
2448 inet_csk(sk)->icsk_ca_state != TCP_CA_Open || in tcp_mtu_probe()
2450 tp->rx_opt.num_sacks || tp->rx_opt.dsack)) in tcp_mtu_probe()
2451 return -1; in tcp_mtu_probe()
2454 * and current mss_clamp. if (search_high - search_low) in tcp_mtu_probe()
2458 probe_size = tcp_mtu_to_mss(sk, (icsk->icsk_mtup.search_high + in tcp_mtu_probe()
2459 icsk->icsk_mtup.search_low) >> 1); in tcp_mtu_probe()
2460 size_needed = probe_size + (tp->reordering + 1) * tp->mss_cache; in tcp_mtu_probe()
2461 interval = icsk->icsk_mtup.search_high - icsk->icsk_mtup.search_low; in tcp_mtu_probe()
2466 if (probe_size > tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_high) || in tcp_mtu_probe()
2467 interval < READ_ONCE(net->ipv4.sysctl_tcp_probe_threshold)) { in tcp_mtu_probe()
2472 return -1; in tcp_mtu_probe()
2476 if (tp->write_seq - tp->snd_nxt < size_needed) in tcp_mtu_probe()
2477 return -1; in tcp_mtu_probe()
2479 if (tp->snd_wnd < size_needed) in tcp_mtu_probe()
2480 return -1; in tcp_mtu_probe()
2481 if (after(tp->snd_nxt + size_needed, tcp_wnd_end(tp))) in tcp_mtu_probe()
2487 return -1; in tcp_mtu_probe()
2493 return -1; in tcp_mtu_probe()
2498 return -1; in tcp_mtu_probe()
2504 return -1; in tcp_mtu_probe()
2506 sk_wmem_queued_add(sk, nskb->truesize); in tcp_mtu_probe()
2507 sk_mem_charge(sk, nskb->truesize); in tcp_mtu_probe()
2513 TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(skb)->seq; in tcp_mtu_probe()
2514 TCP_SKB_CB(nskb)->end_seq = TCP_SKB_CB(skb)->seq + probe_size; in tcp_mtu_probe()
2515 TCP_SKB_CB(nskb)->tcp_flags = TCPHDR_ACK; in tcp_mtu_probe()
2522 copy = min_t(int, skb->len, probe_size - len); in tcp_mtu_probe()
2524 if (skb->len <= copy) { in tcp_mtu_probe()
2527 TCP_SKB_CB(nskb)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags & in tcp_mtu_probe()
2531 TCP_SKB_CB(skb)->seq += copy; in tcp_mtu_probe()
2539 tcp_init_tso_segs(nskb, nskb->len); in tcp_mtu_probe()
2542 * be resegmented into mss-sized pieces by tcp_write_xmit(). in tcp_mtu_probe()
2547 tcp_snd_cwnd_set(tp, tcp_snd_cwnd(tp) - 1); in tcp_mtu_probe()
2550 icsk->icsk_mtup.probe_size = tcp_mss_to_mtu(sk, nskb->len); in tcp_mtu_probe()
2551 tp->mtu_probe.probe_seq_start = TCP_SKB_CB(nskb)->seq; in tcp_mtu_probe()
2552 tp->mtu_probe.probe_seq_end = TCP_SKB_CB(nskb)->end_seq; in tcp_mtu_probe()
2557 return -1; in tcp_mtu_probe()
2567 if (tp->tcp_wstamp_ns <= tp->tcp_clock_cache) in tcp_pacing_check()
2570 if (!hrtimer_is_queued(&tp->pacing_timer)) { in tcp_pacing_check()
2571 hrtimer_start(&tp->pacing_timer, in tcp_pacing_check()
2572 ns_to_ktime(tp->tcp_wstamp_ns), in tcp_pacing_check()
2581 const struct rb_node *node = sk->tcp_rtx_queue.rb_node; in tcp_rtx_queue_empty_or_single_skb()
2588 return !node->rb_left && !node->rb_right; in tcp_rtx_queue_empty_or_single_skb()
2595 * - better RTT estimation and ACK scheduling
2596 * - faster recovery
2597 * - high rates
2603 unsigned int factor) in tcp_small_queue_check() argument
2608 2 * skb->truesize, in tcp_small_queue_check()
2609 READ_ONCE(sk->sk_pacing_rate) >> READ_ONCE(sk->sk_pacing_shift)); in tcp_small_queue_check()
2610 if (sk->sk_pacing_status == SK_PACING_NONE) in tcp_small_queue_check()
2612 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_limit_output_bytes)); in tcp_small_queue_check()
2613 limit <<= factor; in tcp_small_queue_check()
2616 tcp_sk(sk)->tcp_tx_delay) { in tcp_small_queue_check()
2617 u64 extra_bytes = (u64)READ_ONCE(sk->sk_pacing_rate) * in tcp_small_queue_check()
2618 tcp_sk(sk)->tcp_tx_delay; in tcp_small_queue_check()
2621 * approximate our needs assuming an ~100% skb->truesize overhead. in tcp_small_queue_check()
2625 extra_bytes >>= (20 - 1); in tcp_small_queue_check()
2628 if (refcount_read(&sk->sk_wmem_alloc) > limit) { in tcp_small_queue_check()
2637 set_bit(TSQ_THROTTLED, &sk->sk_tsq_flags); in tcp_small_queue_check()
2643 if (refcount_read(&sk->sk_wmem_alloc) > limit) in tcp_small_queue_check()
2652 enum tcp_chrono old = tp->chrono_type; in tcp_chrono_set()
2655 tp->chrono_stat[old - 1] += now - tp->chrono_start; in tcp_chrono_set()
2656 tp->chrono_start = now; in tcp_chrono_set()
2657 tp->chrono_type = new; in tcp_chrono_set()
2669 if (type > tp->chrono_type) in tcp_chrono_start()
2687 else if (type == tp->chrono_type) in tcp_chrono_stop()
2691 /* First skb in the write queue is smaller than ideal packet size.
2696 struct sk_buff *next_skb = skb->next; in tcp_grow_skb()
2705 nlen = min_t(u32, amount, next_skb->len); in tcp_grow_skb()
2709 TCP_SKB_CB(skb)->end_seq += nlen; in tcp_grow_skb()
2710 TCP_SKB_CB(next_skb)->seq += nlen; in tcp_grow_skb()
2712 if (!next_skb->len) { in tcp_grow_skb()
2714 TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(next_skb)->end_seq; in tcp_grow_skb()
2725 * snd_up-64k-mss .. snd_up cannot be large. However, taking into
2762 if (unlikely(tp->repair) && tp->repair_queue == TCP_SEND_QUEUE) { in tcp_write_xmit()
2764 tp->tcp_wstamp_ns = tp->tcp_clock_cache; in tcp_write_xmit()
2765 skb_set_delivery_time(skb, tp->tcp_wstamp_ns, SKB_CLOCK_MONOTONIC); in tcp_write_xmit()
2766 list_move_tail(&skb->tcp_tsorted_anchor, &tp->tsorted_sent_queue); in tcp_write_xmit()
2783 missing_bytes = cwnd_quota * mss_now - skb->len; in tcp_write_xmit()
2812 if (skb->len > limit && in tcp_write_xmit()
2821 * We do not want to send a pure-ack packet and have in tcp_write_xmit()
2824 if (TCP_SKB_CB(skb)->end_seq == TCP_SKB_CB(skb)->seq) in tcp_write_xmit()
2854 tp->prr_out += sent_pkts; in tcp_write_xmit()
2861 return !tp->packets_out && !tcp_write_queue_empty(sk); in tcp_write_xmit()
2874 if (rcu_access_pointer(tp->fastopen_rsk)) in tcp_schedule_loss_probe()
2877 early_retrans = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_early_retrans); in tcp_schedule_loss_probe()
2882 !tp->packets_out || !tcp_is_sack(tp) || in tcp_schedule_loss_probe()
2883 (icsk->icsk_ca_state != TCP_CA_Open && in tcp_schedule_loss_probe()
2884 icsk->icsk_ca_state != TCP_CA_CWR)) in tcp_schedule_loss_probe()
2891 if (tp->srtt_us) { in tcp_schedule_loss_probe()
2892 timeout_us = tp->srtt_us >> 2; in tcp_schedule_loss_probe()
2893 if (tp->packets_out == 1) in tcp_schedule_loss_probe()
2904 jiffies_to_usecs(inet_csk(sk)->icsk_rto) : in tcp_schedule_loss_probe()
2921 set_bit(TSQ_THROTTLED, &sk->sk_tsq_flags); in skb_still_in_host_queue()
2943 if (tp->tlp_high_seq) in tcp_send_loss_probe()
2946 tp->tlp_retrans = 0; in tcp_send_loss_probe()
2949 pcount = tp->packets_out; in tcp_send_loss_probe()
2951 if (tp->packets_out > pcount) in tcp_send_loss_probe()
2955 skb = skb_rb_last(&sk->tcp_rtx_queue); in tcp_send_loss_probe()
2957 WARN_ONCE(tp->packets_out, in tcp_send_loss_probe()
2959 tp->packets_out, sk->sk_state, tcp_snd_cwnd(tp), mss); in tcp_send_loss_probe()
2960 inet_csk(sk)->icsk_pending = 0; in tcp_send_loss_probe()
2971 if ((pcount > 1) && (skb->len > (pcount - 1) * mss)) { in tcp_send_loss_probe()
2973 (pcount - 1) * mss, mss, in tcp_send_loss_probe()
2985 tp->tlp_retrans = 1; in tcp_send_loss_probe()
2989 tp->tlp_high_seq = tp->snd_nxt; in tcp_send_loss_probe()
2993 inet_csk(sk)->icsk_pending = 0; in tcp_send_loss_probe()
3009 if (unlikely(sk->sk_state == TCP_CLOSE)) in __tcp_push_pending_frames()
3024 BUG_ON(!skb || skb->len < mss_now); in tcp_push_one()
3026 tcp_write_xmit(sk, mss_now, TCP_NAGLE_PUSH, 1, sk->sk_allocation); in tcp_push_one()
3038 * RCV.BUFF - RCV.USER - RCV.WINDOW >= min(1/2 RCV.BUFF, MSS)"
3044 * since header prediction assumes th->window stays fixed.
3046 * Strictly speaking, keeping th->window fixed violates the receiver
3061 * and from being larger than the largest representable value.
3087 * here. I don't know if the value based on our guesses in __tcp_select_window()
3090 * fluctuations. --SAW 1998/11/1 in __tcp_select_window()
3092 int mss = icsk->icsk_ack.rcv_mss; in __tcp_select_window()
3100 full_space = min_t(int, tp->window_clamp, allowed_space); in __tcp_select_window()
3109 * a non-zero scaling factor in effect. in __tcp_select_window()
3111 if (READ_ONCE(net->ipv4.sysctl_tcp_shrink_window) && tp->rx_opt.rcv_wscale) in __tcp_select_window()
3117 icsk->icsk_ack.quick = 0; in __tcp_select_window()
3125 free_space = round_down(free_space, 1 << tp->rx_opt.rcv_wscale); in __tcp_select_window()
3128 * of the maximum allowed, try to move to zero-window, else in __tcp_select_window()
3138 if (free_space > tp->rcv_ssthresh) in __tcp_select_window()
3139 free_space = tp->rcv_ssthresh; in __tcp_select_window()
3144 if (tp->rx_opt.rcv_wscale) { in __tcp_select_window()
3151 window = ALIGN(window, (1 << tp->rx_opt.rcv_wscale)); in __tcp_select_window()
3153 window = tp->rcv_wnd; in __tcp_select_window()
3162 if (window <= free_space - mss || window > free_space) in __tcp_select_window()
3172 /* new window should always be an exact multiple of scaling factor */ in __tcp_select_window()
3173 free_space = round_down(free_space, 1 << tp->rx_opt.rcv_wscale); in __tcp_select_window()
3176 icsk->icsk_ack.quick = 0; in __tcp_select_window()
3183 free_space < (1 << tp->rx_opt.rcv_wscale)) in __tcp_select_window()
3187 if (free_space > tp->rcv_ssthresh) { in __tcp_select_window()
3188 free_space = tp->rcv_ssthresh; in __tcp_select_window()
3189 /* new window should always be an exact multiple of scaling factor in __tcp_select_window()
3193 * the memory-based limit, and rcv_ssthresh is not a hard limit in __tcp_select_window()
3196 free_space = ALIGN(free_space, (1 << tp->rx_opt.rcv_wscale)); in __tcp_select_window()
3210 shinfo->tx_flags |= next_shinfo->tx_flags & SKBTX_ANY_TSTAMP; in tcp_skb_collapse_tstamp()
3211 shinfo->tskey = next_shinfo->tskey; in tcp_skb_collapse_tstamp()
3212 TCP_SKB_CB(skb)->txstamp_ack |= in tcp_skb_collapse_tstamp()
3213 TCP_SKB_CB(next_skb)->txstamp_ack; in tcp_skb_collapse_tstamp()
3224 next_skb_size = next_skb->len; in tcp_collapse_retrans()
3234 TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(next_skb)->end_seq; in tcp_collapse_retrans()
3237 TCP_SKB_CB(skb)->tcp_flags |= TCP_SKB_CB(next_skb)->tcp_flags; in tcp_collapse_retrans()
3242 TCP_SKB_CB(skb)->sacked |= TCP_SKB_CB(next_skb)->sacked & TCPCB_EVER_RETRANS; in tcp_collapse_retrans()
3243 TCP_SKB_CB(skb)->eor = TCP_SKB_CB(next_skb)->eor; in tcp_collapse_retrans()
3247 if (next_skb == tp->retransmit_skb_hint) in tcp_collapse_retrans()
3248 tp->retransmit_skb_hint = skb; in tcp_collapse_retrans()
3268 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED) in tcp_can_collapse()
3284 if (!READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_retrans_collapse)) in tcp_retrans_try_collapse()
3286 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN) in tcp_retrans_try_collapse()
3296 space -= skb->len; in tcp_retrans_try_collapse()
3306 if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp))) in tcp_retrans_try_collapse()
3315 * state updates are done by the caller. Returns non-zero if an
3327 if (icsk->icsk_mtup.probe_size) in __tcp_retransmit_skb()
3328 icsk->icsk_mtup.probe_size = 0; in __tcp_retransmit_skb()
3331 return -EBUSY; in __tcp_retransmit_skb()
3334 if (before(TCP_SKB_CB(skb)->seq, tp->snd_una)) { in __tcp_retransmit_skb()
3335 if (unlikely(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) { in __tcp_retransmit_skb()
3336 TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_SYN; in __tcp_retransmit_skb()
3337 TCP_SKB_CB(skb)->seq++; in __tcp_retransmit_skb()
3340 if (unlikely(before(TCP_SKB_CB(skb)->end_seq, tp->snd_una))) { in __tcp_retransmit_skb()
3342 return -EINVAL; in __tcp_retransmit_skb()
3344 if (tcp_trim_head(sk, skb, tp->snd_una - TCP_SKB_CB(skb)->seq)) in __tcp_retransmit_skb()
3345 return -ENOMEM; in __tcp_retransmit_skb()
3348 if (inet_csk(sk)->icsk_af_ops->rebuild_header(sk)) in __tcp_retransmit_skb()
3349 return -EHOSTUNREACH; /* Routing failure or similar. */ in __tcp_retransmit_skb()
3352 avail_wnd = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq; in __tcp_retransmit_skb()
3360 if (TCP_SKB_CB(skb)->seq != tp->snd_una) in __tcp_retransmit_skb()
3361 return -EAGAIN; in __tcp_retransmit_skb()
3371 if (skb->len > len) { in __tcp_retransmit_skb()
3374 return -ENOMEM; /* We'll try again later. */ in __tcp_retransmit_skb()
3377 return -ENOMEM; in __tcp_retransmit_skb()
3381 diff -= tcp_skb_pcount(skb); in __tcp_retransmit_skb()
3385 if (skb->len < avail_wnd) in __tcp_retransmit_skb()
3390 if ((TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN_ECN) == TCPHDR_SYN_ECN) in __tcp_retransmit_skb()
3396 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN) in __tcp_retransmit_skb()
3398 tp->total_retrans += segs; in __tcp_retransmit_skb()
3399 tp->bytes_retrans += skb->len; in __tcp_retransmit_skb()
3401 /* make sure skb->data is aligned on arches that require it in __tcp_retransmit_skb()
3402 * and check if ack-trimming & collapsing extended the headroom in __tcp_retransmit_skb()
3405 if (unlikely((NET_IP_ALIGN && ((unsigned long)skb->data & 3)) || in __tcp_retransmit_skb()
3412 nskb->dev = NULL; in __tcp_retransmit_skb()
3415 err = -ENOBUFS; in __tcp_retransmit_skb()
3420 tcp_update_skb_after_send(sk, skb, tp->tcp_wstamp_ns); in __tcp_retransmit_skb()
3429 TCP_SKB_CB(skb)->seq, segs, err); in __tcp_retransmit_skb()
3433 } else if (err != -EBUSY) { in __tcp_retransmit_skb()
3440 TCP_SKB_CB(skb)->sacked |= TCPCB_EVER_RETRANS; in __tcp_retransmit_skb()
3452 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS) { in tcp_retransmit_skb()
3456 TCP_SKB_CB(skb)->sacked |= TCPCB_RETRANS; in tcp_retransmit_skb()
3457 tp->retrans_out += tcp_skb_pcount(skb); in tcp_retransmit_skb()
3461 if (!tp->retrans_stamp) in tcp_retransmit_skb()
3462 tp->retrans_stamp = tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb); in tcp_retransmit_skb()
3464 if (tp->undo_retrans < 0) in tcp_retransmit_skb()
3465 tp->undo_retrans = 0; in tcp_retransmit_skb()
3466 tp->undo_retrans += tcp_skb_pcount(skb); in tcp_retransmit_skb()
3484 if (!tp->packets_out) in tcp_xmit_retransmit_queue()
3488 skb = tp->retransmit_skb_hint ?: rtx_head; in tcp_xmit_retransmit_queue()
3499 tp->retransmit_skb_hint = skb; in tcp_xmit_retransmit_queue()
3501 segs = tcp_snd_cwnd(tp) - tcp_packets_in_flight(tp); in tcp_xmit_retransmit_queue()
3504 sacked = TCP_SKB_CB(skb)->sacked; in tcp_xmit_retransmit_queue()
3510 if (tp->retrans_out >= tp->lost_out) { in tcp_xmit_retransmit_queue()
3518 if (icsk->icsk_ca_state != TCP_CA_Loss) in tcp_xmit_retransmit_queue()
3536 tp->prr_out += tcp_skb_pcount(skb); in tcp_xmit_retransmit_queue()
3539 icsk->icsk_pending != ICSK_TIME_REO_TIMEOUT) in tcp_xmit_retransmit_queue()
3545 inet_csk(sk)->icsk_rto, in tcp_xmit_retransmit_queue()
3560 delta = size - sk->sk_forward_alloc; in sk_forced_mem_schedule()
3567 if (mem_cgroup_sockets_enabled && sk->sk_memcg) in sk_forced_mem_schedule()
3568 mem_cgroup_charge_skmem(sk->sk_memcg, amt, in sk_forced_mem_schedule()
3587 tskb = skb_rb_last(&sk->tcp_rtx_queue); in tcp_send_fin()
3590 TCP_SKB_CB(tskb)->tcp_flags |= TCPHDR_FIN; in tcp_send_fin()
3591 TCP_SKB_CB(tskb)->end_seq++; in tcp_send_fin()
3592 tp->write_seq++; in tcp_send_fin()
3596 * We need to set tp->snd_nxt to the value it would have in tcp_send_fin()
3598 * does not change tp->snd_nxt. in tcp_send_fin()
3600 WRITE_ONCE(tp->snd_nxt, tp->snd_nxt + 1); in tcp_send_fin()
3610 INIT_LIST_HEAD(&skb->tcp_tsorted_anchor); in tcp_send_fin()
3612 sk_forced_mem_schedule(sk, skb->truesize); in tcp_send_fin()
3614 tcp_init_nondata_skb(skb, tp->write_seq, in tcp_send_fin()
3624 * by RFC 2525, section 2.17. -DaveM
3655 /* Send a crossed SYN-ACK during socket establishment.
3666 if (!skb || !(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) { in tcp_send_synack()
3668 return -EFAULT; in tcp_send_synack()
3670 if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_ACK)) { in tcp_send_synack()
3678 return -ENOMEM; in tcp_send_synack()
3679 INIT_LIST_HEAD(&nskb->tcp_tsorted_anchor); in tcp_send_synack()
3683 tcp_rbtree_insert(&sk->tcp_rtx_queue, nskb); in tcp_send_synack()
3684 sk_wmem_queued_add(sk, nskb->truesize); in tcp_send_synack()
3685 sk_mem_charge(sk, nskb->truesize); in tcp_send_synack()
3689 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_ACK; in tcp_send_synack()
3696 * tcp_make_synack - Allocate one skb and build a SYNACK packet.
3741 * sk->sk_wmem_alloc in an atomic, we can promote to rw. in tcp_make_synack()
3753 if (unlikely(synack_type == TCP_SYNACK_COOKIE && ireq->tstamp_ok)) in tcp_make_synack()
3760 if (!tcp_rsk(req)->snt_synack) /* Timestamp first SYNACK */ in tcp_make_synack()
3761 tcp_rsk(req)->snt_synack = tcp_skb_timestamp_us(skb); in tcp_make_synack()
3770 u8 keyid = tcp_rsk(req)->ao_keyid; in tcp_make_synack()
3771 u8 rnext = tcp_rsk(req)->ao_rcv_next; in tcp_make_synack()
3773 ao_key = tcp_sk(sk)->af_specific->ao_lookup(sk, req_to_sk(req), in tcp_make_synack()
3774 keyid, -1); in tcp_make_synack()
3775 /* If there is no matching key - avoid sending anything, in tcp_make_synack()
3777 * for another peer-matching key, but the peer has requested in tcp_make_synack()
3784 … net_warn_ratelimited("TCP-AO: the keyid %u from SYN packet is not present - not sending SYNACK\n", in tcp_make_synack()
3793 key.md5_key = tcp_rsk(req)->af_specific->req_md5_lookup(sk, in tcp_make_synack()
3799 skb_set_hash(skb, READ_ONCE(tcp_rsk(req)->txhash), PKT_HASH_TYPE_L4); in tcp_make_synack()
3801 TCP_SKB_CB(skb)->tcp_flags = TCPHDR_SYN | TCPHDR_ACK; in tcp_make_synack()
3809 th = (struct tcphdr *)skb->data; in tcp_make_synack()
3811 th->syn = 1; in tcp_make_synack()
3812 th->ack = 1; in tcp_make_synack()
3814 th->source = htons(ireq->ir_num); in tcp_make_synack()
3815 th->dest = ireq->ir_rmt_port; in tcp_make_synack()
3816 skb->mark = ireq->ir_mark; in tcp_make_synack()
3817 skb->ip_summed = CHECKSUM_PARTIAL; in tcp_make_synack()
3818 th->seq = htonl(tcp_rsk(req)->snt_isn); in tcp_make_synack()
3820 th->ack_seq = htonl(tcp_rsk(req)->rcv_nxt); in tcp_make_synack()
3823 th->window = htons(min(req->rsk_rcv_wnd, 65535U)); in tcp_make_synack()
3825 th->doff = (tcp_header_size >> 2); in tcp_make_synack()
3828 /* Okay, we have all we need - do the md5 hash if needed */ in tcp_make_synack()
3831 tcp_rsk(req)->af_specific->calc_md5_hash(opts.hash_location, in tcp_make_synack()
3836 tcp_rsk(req)->af_specific->ao_synack_hash(opts.hash_location, in tcp_make_synack()
3838 opts.hash_location - (u8 *)th, 0); in tcp_make_synack()
3866 if (likely(ca && bpf_try_module_get(ca, ca->owner))) { in tcp_ca_dst_init()
3867 bpf_module_put(icsk->icsk_ca_ops, icsk->icsk_ca_ops->owner); in tcp_ca_dst_init()
3868 icsk->icsk_ca_dst_locked = tcp_ca_dst_locked(dst); in tcp_ca_dst_init()
3869 icsk->icsk_ca_ops = ca; in tcp_ca_dst_init()
3885 tp->tcp_header_len = sizeof(struct tcphdr); in tcp_connect_init()
3886 if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_timestamps)) in tcp_connect_init()
3887 tp->tcp_header_len += TCPOLEN_TSTAMP_ALIGNED; in tcp_connect_init()
3892 if (tp->rx_opt.user_mss) in tcp_connect_init()
3893 tp->rx_opt.mss_clamp = tp->rx_opt.user_mss; in tcp_connect_init()
3894 tp->max_window = 0; in tcp_connect_init()
3900 if (!tp->window_clamp) in tcp_connect_init()
3901 WRITE_ONCE(tp->window_clamp, dst_metric(dst, RTAX_WINDOW)); in tcp_connect_init()
3902 tp->advmss = tcp_mss_clamp(tp, dst_metric_advmss(dst)); in tcp_connect_init()
3907 if (sk->sk_userlocks & SOCK_RCVBUF_LOCK && in tcp_connect_init()
3908 (tp->window_clamp > tcp_full_space(sk) || tp->window_clamp == 0)) in tcp_connect_init()
3909 WRITE_ONCE(tp->window_clamp, tcp_full_space(sk)); in tcp_connect_init()
3916 tp->advmss - (tp->rx_opt.ts_recent_stamp ? tp->tcp_header_len - sizeof(struct tcphdr) : 0), in tcp_connect_init()
3917 &tp->rcv_wnd, in tcp_connect_init()
3918 &tp->window_clamp, in tcp_connect_init()
3919 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_window_scaling), in tcp_connect_init()
3923 tp->rx_opt.rcv_wscale = rcv_wscale; in tcp_connect_init()
3924 tp->rcv_ssthresh = tp->rcv_wnd; in tcp_connect_init()
3926 WRITE_ONCE(sk->sk_err, 0); in tcp_connect_init()
3928 tp->snd_wnd = 0; in tcp_connect_init()
3931 tp->snd_una = tp->write_seq; in tcp_connect_init()
3932 tp->snd_sml = tp->write_seq; in tcp_connect_init()
3933 tp->snd_up = tp->write_seq; in tcp_connect_init()
3934 WRITE_ONCE(tp->snd_nxt, tp->write_seq); in tcp_connect_init()
3936 if (likely(!tp->repair)) in tcp_connect_init()
3937 tp->rcv_nxt = 0; in tcp_connect_init()
3939 tp->rcv_tstamp = tcp_jiffies32; in tcp_connect_init()
3940 tp->rcv_wup = tp->rcv_nxt; in tcp_connect_init()
3941 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); in tcp_connect_init()
3943 inet_csk(sk)->icsk_rto = tcp_timeout_init(sk); in tcp_connect_init()
3944 inet_csk(sk)->icsk_retransmits = 0; in tcp_connect_init()
3953 tcb->end_seq += skb->len; in tcp_connect_queue_skb()
3955 sk_wmem_queued_add(sk, skb->truesize); in tcp_connect_queue_skb()
3956 sk_mem_charge(sk, skb->truesize); in tcp_connect_queue_skb()
3957 WRITE_ONCE(tp->write_seq, tcb->end_seq); in tcp_connect_queue_skb()
3958 tp->packets_out += tcp_skb_pcount(skb); in tcp_connect_queue_skb()
3962 * queue a data-only packet after the regular SYN, such that regular SYNs
3963 * are retransmitted on timeouts. Also if the remote SYN-ACK acknowledges
3972 struct tcp_fastopen_request *fo = tp->fastopen_req; in tcp_send_syn_data()
3977 tp->rx_opt.mss_clamp = tp->advmss; /* If MSS is not cached */ in tcp_send_syn_data()
3978 if (!tcp_fastopen_cookie_check(sk, &tp->rx_opt.mss_clamp, &fo->cookie)) in tcp_send_syn_data()
3981 /* MSS for SYN-data is based on cached MSS and bounded by PMTU and in tcp_send_syn_data()
3982 * user-MSS. Reserve maximum option space for middleboxes that add in tcp_send_syn_data()
3985 tp->rx_opt.mss_clamp = tcp_mss_clamp(tp, tp->rx_opt.mss_clamp); in tcp_send_syn_data()
3987 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); in tcp_send_syn_data()
3989 space = __tcp_mtu_to_mss(sk, icsk->icsk_pmtu_cookie) - in tcp_send_syn_data()
3992 space = min_t(size_t, space, fo->size); in tcp_send_syn_data()
3996 pfrag, sk->sk_allocation)) in tcp_send_syn_data()
3998 syn_data = tcp_stream_alloc_skb(sk, sk->sk_allocation, false); in tcp_send_syn_data()
4001 memcpy(syn_data->cb, syn->cb, sizeof(syn->cb)); in tcp_send_syn_data()
4003 space = min_t(size_t, space, pfrag->size - pfrag->offset); in tcp_send_syn_data()
4007 space = copy_page_from_iter(pfrag->page, pfrag->offset, in tcp_send_syn_data()
4008 space, &fo->data->msg_iter); in tcp_send_syn_data()
4014 skb_fill_page_desc(syn_data, 0, pfrag->page, in tcp_send_syn_data()
4015 pfrag->offset, space); in tcp_send_syn_data()
4016 page_ref_inc(pfrag->page); in tcp_send_syn_data()
4017 pfrag->offset += space; in tcp_send_syn_data()
4019 skb_zcopy_set(syn_data, fo->uarg, NULL); in tcp_send_syn_data()
4022 if (space == fo->size) in tcp_send_syn_data()
4023 fo->data = NULL; in tcp_send_syn_data()
4024 fo->copied = space; in tcp_send_syn_data()
4027 if (syn_data->len) in tcp_send_syn_data()
4030 err = tcp_transmit_skb(sk, syn_data, 1, sk->sk_allocation); in tcp_send_syn_data()
4032 skb_set_delivery_time(syn, syn_data->skb_mstamp_ns, SKB_CLOCK_MONOTONIC); in tcp_send_syn_data()
4039 TCP_SKB_CB(syn_data)->seq++; in tcp_send_syn_data()
4040 TCP_SKB_CB(syn_data)->tcp_flags = TCPHDR_ACK | TCPHDR_PSH; in tcp_send_syn_data()
4042 tp->syn_data = (fo->copied > 0); in tcp_send_syn_data()
4043 tcp_rbtree_insert(&sk->tcp_rtx_queue, syn_data); in tcp_send_syn_data()
4049 __skb_queue_tail(&sk->sk_write_queue, syn_data); in tcp_send_syn_data()
4050 tp->packets_out -= tcp_skb_pcount(syn_data); in tcp_send_syn_data()
4054 if (fo->cookie.len > 0) in tcp_send_syn_data()
4055 fo->cookie.len = 0; in tcp_send_syn_data()
4056 err = tcp_transmit_skb(sk, syn, 1, sk->sk_allocation); in tcp_send_syn_data()
4058 tp->syn_fastopen = 0; in tcp_send_syn_data()
4060 fo->cookie.len = -1; /* Exclude Fast Open option for SYN retries */ in tcp_send_syn_data()
4075 * Return error if the peer has both a md5 and a tcp-ao key in tcp_connect()
4078 if (unlikely(rcu_dereference_protected(tp->md5sig_info, in tcp_connect()
4080 bool needs_ao = !!tp->af_specific->ao_lookup(sk, sk, -1, -1); in tcp_connect()
4081 bool needs_md5 = !!tp->af_specific->md5_lookup(sk, sk); in tcp_connect()
4084 ao_info = rcu_dereference_check(tp->ao_info, in tcp_connect()
4091 needs_ao |= ao_info->ao_required; in tcp_connect()
4092 WARN_ON_ONCE(ao_info->ao_required && needs_md5); in tcp_connect()
4095 return -EKEYREJECTED; in tcp_connect()
4097 /* If we have a matching md5 key and no matching tcp-ao key in tcp_connect()
4104 kfree(rcu_replace_pointer(tp->md5sig_info, NULL, in tcp_connect()
4110 if (unlikely(rcu_dereference_protected(tp->ao_info, in tcp_connect()
4115 if (!tp->af_specific->ao_lookup(sk, sk, -1, -1)) in tcp_connect()
4116 return -EKEYREJECTED; in tcp_connect()
4120 if (inet_csk(sk)->icsk_af_ops->rebuild_header(sk)) in tcp_connect()
4121 return -EHOSTUNREACH; /* Routing failure or similar. */ in tcp_connect()
4125 if (unlikely(tp->repair)) { in tcp_connect()
4130 buff = tcp_stream_alloc_skb(sk, sk->sk_allocation, true); in tcp_connect()
4132 return -ENOBUFS; in tcp_connect()
4134 tcp_init_nondata_skb(buff, tp->write_seq++, TCPHDR_SYN); in tcp_connect()
4136 tp->retrans_stamp = tcp_time_stamp_ts(tp); in tcp_connect()
4139 tcp_rbtree_insert(&sk->tcp_rtx_queue, buff); in tcp_connect()
4142 err = tp->fastopen_req ? tcp_send_syn_data(sk, buff) : in tcp_connect()
4143 tcp_transmit_skb(sk, buff, 1, sk->sk_allocation); in tcp_connect()
4144 if (err == -ECONNREFUSED) in tcp_connect()
4147 /* We change tp->snd_nxt after the tcp_transmit_skb() call in tcp_connect()
4150 WRITE_ONCE(tp->snd_nxt, tp->write_seq); in tcp_connect()
4151 tp->pushed_seq = tp->write_seq; in tcp_connect()
4154 WRITE_ONCE(tp->snd_nxt, TCP_SKB_CB(buff)->seq); in tcp_connect()
4155 tp->pushed_seq = TCP_SKB_CB(buff)->seq; in tcp_connect()
4161 inet_csk(sk)->icsk_rto, TCP_RTO_MAX); in tcp_connect()
4168 u32 delack_from_rto_min = max(tcp_rto_min(sk), 2) - 1; in tcp_delack_max()
4170 return min(inet_csk(sk)->icsk_delack_max, delack_from_rto_min); in tcp_delack_max()
4180 int ato = icsk->icsk_ack.ato; in tcp_send_delayed_ack()
4188 (icsk->icsk_ack.pending & ICSK_ACK_PUSHED)) in tcp_send_delayed_ack()
4194 * Do not use inet_csk(sk)->icsk_rto here, use results of rtt measurements in tcp_send_delayed_ack()
4197 if (tp->srtt_us) { in tcp_send_delayed_ack()
4198 int rtt = max_t(int, usecs_to_jiffies(tp->srtt_us >> 3), in tcp_send_delayed_ack()
4214 if (icsk->icsk_ack.pending & ICSK_ACK_TIMER) { in tcp_send_delayed_ack()
4216 if (time_before_eq(icsk->icsk_ack.timeout, jiffies + (ato >> 2))) { in tcp_send_delayed_ack()
4221 if (!time_before(timeout, icsk->icsk_ack.timeout)) in tcp_send_delayed_ack()
4222 timeout = icsk->icsk_ack.timeout; in tcp_send_delayed_ack()
4224 icsk->icsk_ack.pending |= ICSK_ACK_SCHED | ICSK_ACK_TIMER; in tcp_send_delayed_ack()
4225 icsk->icsk_ack.timeout = timeout; in tcp_send_delayed_ack()
4226 sk_reset_timer(sk, &icsk->icsk_delack_timer, timeout); in tcp_send_delayed_ack()
4235 if (sk->sk_state == TCP_CLOSE) in __tcp_send_ack()
4248 delay = TCP_DELACK_MAX << icsk->icsk_ack.retry; in __tcp_send_ack()
4250 icsk->icsk_ack.retry++; in __tcp_send_ack()
4252 icsk->icsk_ack.ato = TCP_ATO_MIN; in __tcp_send_ack()
4274 __tcp_send_ack(sk, tcp_sk(sk)->rcv_nxt); in tcp_send_ack()
4284 * Current solution: to send TWO zero-length segments in urgent mode:
4286 * out-of-date with SND.UNA-1 to probe window.
4297 return -1; in tcp_xmit_probe_skb()
4305 tcp_init_nondata_skb(skb, tp->snd_una - !urgent, TCPHDR_ACK); in tcp_xmit_probe_skb()
4313 if (sk->sk_state == TCP_ESTABLISHED) { in tcp_send_window_probe()
4314 tcp_sk(sk)->snd_wl1 = tcp_sk(sk)->rcv_nxt - 1; in tcp_send_window_probe()
4326 if (sk->sk_state == TCP_CLOSE) in tcp_write_wakeup()
4327 return -1; in tcp_write_wakeup()
4330 if (skb && before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp))) { in tcp_write_wakeup()
4333 unsigned int seg_size = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq; in tcp_write_wakeup()
4335 if (before(tp->pushed_seq, TCP_SKB_CB(skb)->end_seq)) in tcp_write_wakeup()
4336 tp->pushed_seq = TCP_SKB_CB(skb)->end_seq; in tcp_write_wakeup()
4342 if (seg_size < TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq || in tcp_write_wakeup()
4343 skb->len > mss) { in tcp_write_wakeup()
4345 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_PSH; in tcp_write_wakeup()
4348 return -1; in tcp_write_wakeup()
4352 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_PSH; in tcp_write_wakeup()
4358 if (between(tp->snd_up, tp->snd_una + 1, tp->snd_una + 0xFFFF)) in tcp_write_wakeup()
4377 if (tp->packets_out || tcp_write_queue_empty(sk)) { in tcp_send_probe0()
4379 icsk->icsk_probes_out = 0; in tcp_send_probe0()
4380 icsk->icsk_backoff = 0; in tcp_send_probe0()
4381 icsk->icsk_probes_tstamp = 0; in tcp_send_probe0()
4385 icsk->icsk_probes_out++; in tcp_send_probe0()
4387 if (icsk->icsk_backoff < READ_ONCE(net->ipv4.sysctl_tcp_retries2)) in tcp_send_probe0()
4388 icsk->icsk_backoff++; in tcp_send_probe0()
4403 const struct tcp_request_sock_ops *af_ops = tcp_rsk(req)->af_specific; in tcp_rtx_synack()
4408 if (READ_ONCE(sk->sk_txrehash) == SOCK_TXREHASH_ENABLED) in tcp_rtx_synack()
4409 WRITE_ONCE(tcp_rsk(req)->txhash, net_tx_rndhash()); in tcp_rtx_synack()
4410 res = af_ops->send_synack(sk, NULL, &fl, req, NULL, TCP_SYNACK_NORMAL, in tcp_rtx_synack()
4418 * socket thus we can change total_retrans value. in tcp_rtx_synack()
4420 tcp_sk_rw(sk)->total_retrans++; in tcp_rtx_synack()