Lines Matching +full:x +full:- +full:ts +full:- +full:routes
1 // SPDX-License-Identifier: GPL-2.0-or-later
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Florian La Roche, <flla@stud.uni-sb.de>
25 * sk->inuse=1 and was trying to connect
51 * Alan Cox : sk->keepopen now seems to work
53 * Alan Cox : Fixed assorted sk->rqueue->next errors
63 * Alan Cox : FIN with no memory -> CRASH
113 * Alan Cox : Changed the semantics of sk->socket to
164 * Matt Day : poll()->select() match BSD precisely on error
166 * Marc Tamsky : Various sk->prot->retransmits and
167 * sk->retransmits misupdating fixed.
172 * Alan Cox : Look up device on a retransmit - routes may
214 * waiting for final ack in three-way handshake.
348 val--; in tcp_enter_memory_pressure()
363 jiffies_to_msecs(jiffies - val)); in tcp_leave_memory_pressure()
394 while (--retrans) { in retrans_to_secs()
406 u32 rate = READ_ONCE(tp->rate_delivered); in tcp_compute_delivery_rate()
407 u32 intv = READ_ONCE(tp->rate_interval_us); in tcp_compute_delivery_rate()
411 rate64 = (u64)rate * tp->mss_cache * USEC_PER_SEC; in tcp_compute_delivery_rate()
417 /* Address-family independent initialization for a tcp_sock.
428 tp->out_of_order_queue = RB_ROOT; in tcp_init_sock()
429 sk->tcp_rtx_queue = RB_ROOT; in tcp_init_sock()
431 INIT_LIST_HEAD(&tp->tsq_node); in tcp_init_sock()
432 INIT_LIST_HEAD(&tp->tsorted_sent_queue); in tcp_init_sock()
434 icsk->icsk_rto = TCP_TIMEOUT_INIT; in tcp_init_sock()
435 rto_min_us = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rto_min_us); in tcp_init_sock()
436 icsk->icsk_rto_min = usecs_to_jiffies(rto_min_us); in tcp_init_sock()
437 icsk->icsk_delack_max = TCP_DELACK_MAX; in tcp_init_sock()
438 tp->mdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT); in tcp_init_sock()
439 minmax_reset(&tp->rtt_min, tcp_jiffies32, ~0U); in tcp_init_sock()
442 * initial SYN frame in their delayed-ACK and congestion control in tcp_init_sock()
444 * efficiently to them. -DaveM in tcp_init_sock()
449 tp->app_limited = ~0U; in tcp_init_sock()
450 tp->rate_app_limited = 1; in tcp_init_sock()
452 /* See draft-stevens-tcpca-spec-01 for discussion of the in tcp_init_sock()
455 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; in tcp_init_sock()
456 tp->snd_cwnd_clamp = ~0; in tcp_init_sock()
457 tp->mss_cache = TCP_MSS_DEFAULT; in tcp_init_sock()
459 tp->reordering = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reordering); in tcp_init_sock()
462 tp->tsoffset = 0; in tcp_init_sock()
463 tp->rack.reo_wnd_steps = 1; in tcp_init_sock()
465 sk->sk_write_space = sk_stream_write_space; in tcp_init_sock()
468 icsk->icsk_sync_mss = tcp_sync_mss; in tcp_init_sock()
470 WRITE_ONCE(sk->sk_sndbuf, READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[1])); in tcp_init_sock()
471 WRITE_ONCE(sk->sk_rcvbuf, READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rmem[1])); in tcp_init_sock()
474 set_bit(SOCK_SUPPORT_ZC, &sk->sk_socket->flags); in tcp_init_sock()
476 xa_init_flags(&sk->sk_user_frags, XA_FLAGS_ALLOC1); in tcp_init_sock()
483 u32 tsflags = sockc->tsflags; in tcp_tx_timestamp()
489 sock_tx_timestamp(sk, sockc, &shinfo->tx_flags); in tcp_tx_timestamp()
491 tcb->txstamp_ack = 1; in tcp_tx_timestamp()
493 shinfo->tskey = TCP_SKB_CB(skb)->seq + skb->len - 1; in tcp_tx_timestamp()
514 struct sock *sk = sock->sk; in tcp_poll()
543 * Check-me. in tcp_poll()
548 * in state CLOSE_WAIT. One solution is evident --- to set EPOLLHUP in tcp_poll()
554 * why EPOLLHUP is incompatible with EPOLLOUT. --ANK in tcp_poll()
557 * blocking on fresh not-connected or disconnected socket. --ANK in tcp_poll()
559 shutdown = READ_ONCE(sk->sk_shutdown); in tcp_poll()
567 (state != TCP_SYN_RECV || rcu_access_pointer(tp->fastopen_rsk))) { in tcp_poll()
569 u16 urg_data = READ_ONCE(tp->urg_data); in tcp_poll()
572 READ_ONCE(tp->urg_seq) == READ_ONCE(tp->copied_seq) && in tcp_poll()
584 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); in tcp_poll()
610 if (READ_ONCE(sk->sk_err) || in tcp_poll()
611 !skb_queue_empty_lockless(&sk->sk_error_queue)) in tcp_poll()
626 if (sk->sk_state == TCP_LISTEN) in tcp_ioctl()
627 return -EINVAL; in tcp_ioctl()
634 answ = READ_ONCE(tp->urg_data) && in tcp_ioctl()
635 READ_ONCE(tp->urg_seq) == READ_ONCE(tp->copied_seq); in tcp_ioctl()
638 if (sk->sk_state == TCP_LISTEN) in tcp_ioctl()
639 return -EINVAL; in tcp_ioctl()
641 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) in tcp_ioctl()
644 answ = READ_ONCE(tp->write_seq) - tp->snd_una; in tcp_ioctl()
647 if (sk->sk_state == TCP_LISTEN) in tcp_ioctl()
648 return -EINVAL; in tcp_ioctl()
650 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) in tcp_ioctl()
653 answ = READ_ONCE(tp->write_seq) - in tcp_ioctl()
654 READ_ONCE(tp->snd_nxt); in tcp_ioctl()
657 return -ENOIOCTLCMD; in tcp_ioctl()
667 TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_PSH; in tcp_mark_push()
668 tp->pushed_seq = tp->write_seq; in tcp_mark_push()
673 return after(tp->write_seq, tp->pushed_seq + (tp->max_window >> 1)); in forced_push()
681 tcb->seq = tcb->end_seq = tp->write_seq; in tcp_skb_entail()
682 tcb->tcp_flags = TCPHDR_ACK; in tcp_skb_entail()
685 sk_wmem_queued_add(sk, skb->truesize); in tcp_skb_entail()
686 sk_mem_charge(sk, skb->truesize); in tcp_skb_entail()
687 if (tp->nonagle & TCP_NAGLE_PUSH) in tcp_skb_entail()
688 tp->nonagle &= ~TCP_NAGLE_PUSH; in tcp_skb_entail()
696 tp->snd_up = tp->write_seq; in tcp_mark_urg()
712 return skb->len < size_goal && in tcp_should_autocork()
713 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_autocorking) && in tcp_should_autocork()
715 refcount_read(&sk->sk_wmem_alloc) > skb->truesize && in tcp_should_autocork()
736 if (!test_bit(TSQ_THROTTLED, &sk->sk_tsq_flags)) { in tcp_push()
738 set_bit(TSQ_THROTTLED, &sk->sk_tsq_flags); in tcp_push()
744 if (refcount_read(&sk->sk_wmem_alloc) > skb->truesize) in tcp_push()
757 struct tcp_splice_state *tss = rd_desc->arg.data; in tcp_splice_data_recv()
760 ret = skb_splice_bits(skb, skb->sk, offset, tss->pipe, in tcp_splice_data_recv()
761 min(rd_desc->count, len), tss->flags); in tcp_splice_data_recv()
763 rd_desc->count -= ret; in tcp_splice_data_recv()
772 .count = tss->len, in __tcp_splice_read()
779 * tcp_splice_read - splice data from TCP socket to a pipe
794 struct sock *sk = sock->sk; in tcp_splice_read()
809 return -ESPIPE; in tcp_splice_read()
815 timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK); in tcp_splice_read()
825 if (sk->sk_err) { in tcp_splice_read()
829 if (sk->sk_shutdown & RCV_SHUTDOWN) in tcp_splice_read()
831 if (sk->sk_state == TCP_CLOSE) { in tcp_splice_read()
836 ret = -ENOTCONN; in tcp_splice_read()
840 ret = -EAGAIN; in tcp_splice_read()
847 if (!skb_queue_empty(&sk->sk_receive_queue)) in tcp_splice_read()
858 tss.len -= ret; in tcp_splice_read()
866 if (sk->sk_err || sk->sk_state == TCP_CLOSE || in tcp_splice_read()
867 (sk->sk_shutdown & RCV_SHUTDOWN) || in tcp_splice_read()
890 skb->truesize = SKB_TRUESIZE(skb_end_offset(skb)); in tcp_stream_alloc_skb()
893 sk_forced_mem_schedule(sk, skb->truesize); in tcp_stream_alloc_skb()
895 mem_scheduled = sk_wmem_schedule(sk, skb->truesize); in tcp_stream_alloc_skb()
899 skb->ip_summed = CHECKSUM_PARTIAL; in tcp_stream_alloc_skb()
900 INIT_LIST_HEAD(&skb->tcp_tsorted_anchor); in tcp_stream_alloc_skb()
905 sk->sk_prot->enter_memory_pressure(sk); in tcp_stream_alloc_skb()
921 new_size_goal = tcp_bound_to_half_wnd(tp, sk->sk_gso_max_size); in tcp_xmit_size_goal()
924 size_goal = tp->gso_segs * mss_now; in tcp_xmit_size_goal()
927 tp->gso_segs = min_t(u16, new_size_goal / mss_now, in tcp_xmit_size_goal()
928 sk->sk_gso_max_segs); in tcp_xmit_size_goal()
929 size_goal = tp->gso_segs * mss_now; in tcp_xmit_size_goal()
955 if (skb && TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) { in tcp_remove_empty_skb()
967 u32 extra = skb->truesize - in tcp_downgrade_zcopy_pure()
971 return -ENOMEM; in tcp_downgrade_zcopy_pure()
974 skb_shinfo(skb)->flags &= ~SKBFL_PURE_ZEROCOPY; in tcp_downgrade_zcopy_pure()
988 * Use whatever is left in sk->sk_forward_alloc and tcp_wmem[0] in tcp_wmem_schedule()
991 left = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[0]) - sk->sk_wmem_queued; in tcp_wmem_schedule()
994 return min(copy, sk->sk_forward_alloc); in tcp_wmem_schedule()
999 if (tp->fastopen_req) { in tcp_free_fastopen_req()
1000 kfree(tp->fastopen_req); in tcp_free_fastopen_req()
1001 tp->fastopen_req = NULL; in tcp_free_fastopen_req()
1010 struct sockaddr *uaddr = msg->msg_name; in tcp_sendmsg_fastopen()
1013 if (!(READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_fastopen) & in tcp_sendmsg_fastopen()
1015 (uaddr && msg->msg_namelen >= sizeof(uaddr->sa_family) && in tcp_sendmsg_fastopen()
1016 uaddr->sa_family == AF_UNSPEC)) in tcp_sendmsg_fastopen()
1017 return -EOPNOTSUPP; in tcp_sendmsg_fastopen()
1018 if (tp->fastopen_req) in tcp_sendmsg_fastopen()
1019 return -EALREADY; /* Another Fast Open is in progress */ in tcp_sendmsg_fastopen()
1021 tp->fastopen_req = kzalloc(sizeof(struct tcp_fastopen_request), in tcp_sendmsg_fastopen()
1022 sk->sk_allocation); in tcp_sendmsg_fastopen()
1023 if (unlikely(!tp->fastopen_req)) in tcp_sendmsg_fastopen()
1024 return -ENOBUFS; in tcp_sendmsg_fastopen()
1025 tp->fastopen_req->data = msg; in tcp_sendmsg_fastopen()
1026 tp->fastopen_req->size = size; in tcp_sendmsg_fastopen()
1027 tp->fastopen_req->uarg = uarg; in tcp_sendmsg_fastopen()
1034 inet->inet_dport = 0; in tcp_sendmsg_fastopen()
1035 sk->sk_route_caps = 0; in tcp_sendmsg_fastopen()
1038 flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0; in tcp_sendmsg_fastopen()
1039 err = __inet_stream_connect(sk->sk_socket, uaddr, in tcp_sendmsg_fastopen()
1040 msg->msg_namelen, flags, 1); in tcp_sendmsg_fastopen()
1044 if (tp->fastopen_req) { in tcp_sendmsg_fastopen()
1045 *copied = tp->fastopen_req->copied; in tcp_sendmsg_fastopen()
1064 flags = msg->msg_flags; in tcp_sendmsg_locked()
1067 if (msg->msg_ubuf) { in tcp_sendmsg_locked()
1068 uarg = msg->msg_ubuf; in tcp_sendmsg_locked()
1069 if (sk->sk_route_caps & NETIF_F_SG) in tcp_sendmsg_locked()
1075 err = -ENOBUFS; in tcp_sendmsg_locked()
1078 if (sk->sk_route_caps & NETIF_F_SG) in tcp_sendmsg_locked()
1081 uarg_to_msgzc(uarg)->zerocopy = 0; in tcp_sendmsg_locked()
1083 } else if (unlikely(msg->msg_flags & MSG_SPLICE_PAGES) && size) { in tcp_sendmsg_locked()
1084 if (sk->sk_route_caps & NETIF_F_SG) in tcp_sendmsg_locked()
1090 !tp->repair) { in tcp_sendmsg_locked()
1092 if (err == -EINPROGRESS && copied_syn > 0) in tcp_sendmsg_locked()
1100 tcp_rate_check_app_limited(sk); /* is sending application-limited? */ in tcp_sendmsg_locked()
1106 if (((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) && in tcp_sendmsg_locked()
1113 if (unlikely(tp->repair)) { in tcp_sendmsg_locked()
1114 if (tp->repair_queue == TCP_RECV_QUEUE) { in tcp_sendmsg_locked()
1119 err = -EINVAL; in tcp_sendmsg_locked()
1120 if (tp->repair_queue == TCP_NO_QUEUE) in tcp_sendmsg_locked()
1127 if (msg->msg_controllen) { in tcp_sendmsg_locked()
1130 err = -EINVAL; in tcp_sendmsg_locked()
1144 err = -EPIPE; in tcp_sendmsg_locked()
1145 if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) in tcp_sendmsg_locked()
1153 copy = size_goal - skb->len; in tcp_sendmsg_locked()
1168 skb = tcp_stream_alloc_skb(sk, sk->sk_allocation, in tcp_sendmsg_locked()
1176 skb->decrypted = !!(flags & MSG_SENDPAGE_DECRYPTED); in tcp_sendmsg_locked()
1185 if (tp->repair) in tcp_sendmsg_locked()
1186 TCP_SKB_CB(skb)->sacked |= TCPCB_REPAIRED; in tcp_sendmsg_locked()
1195 int i = skb_shinfo(skb)->nr_frags; in tcp_sendmsg_locked()
1201 if (!skb_can_coalesce(skb, i, pfrag->page, in tcp_sendmsg_locked()
1202 pfrag->offset)) { in tcp_sendmsg_locked()
1210 copy = min_t(int, copy, pfrag->size - pfrag->offset); in tcp_sendmsg_locked()
1222 err = skb_copy_to_page_nocache(sk, &msg->msg_iter, skb, in tcp_sendmsg_locked()
1223 pfrag->page, in tcp_sendmsg_locked()
1224 pfrag->offset, in tcp_sendmsg_locked()
1231 skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); in tcp_sendmsg_locked()
1233 skb_fill_page_desc(skb, i, pfrag->page, in tcp_sendmsg_locked()
1234 pfrag->offset, copy); in tcp_sendmsg_locked()
1235 page_ref_inc(pfrag->page); in tcp_sendmsg_locked()
1237 pfrag->offset += copy; in tcp_sendmsg_locked()
1242 if (!skb->len) in tcp_sendmsg_locked()
1243 skb_shinfo(skb)->flags |= SKBFL_PURE_ZEROCOPY; in tcp_sendmsg_locked()
1252 if (err == -EMSGSIZE || err == -EEXIST) { in tcp_sendmsg_locked()
1267 err = skb_splice_from_iter(skb, &msg->msg_iter, copy, in tcp_sendmsg_locked()
1268 sk->sk_allocation); in tcp_sendmsg_locked()
1270 if (err == -EMSGSIZE) { in tcp_sendmsg_locked()
1279 skb_shinfo(skb)->flags |= SKBFL_SHARED_FRAG; in tcp_sendmsg_locked()
1286 TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_PSH; in tcp_sendmsg_locked()
1288 WRITE_ONCE(tp->write_seq, tp->write_seq + copy); in tcp_sendmsg_locked()
1289 TCP_SKB_CB(skb)->end_seq += copy; in tcp_sendmsg_locked()
1295 TCP_SKB_CB(skb)->eor = 1; in tcp_sendmsg_locked()
1299 if (skb->len < size_goal || (flags & MSG_OOB) || unlikely(tp->repair)) in tcp_sendmsg_locked()
1310 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); in tcp_sendmsg_locked()
1326 tcp_push(sk, flags, mss_now, tp->nonagle, size_goal); in tcp_sendmsg_locked()
1329 /* msg->msg_ubuf is pinned by the caller so we don't take extra refs */ in tcp_sendmsg_locked()
1330 if (uarg && !msg->msg_ubuf) in tcp_sendmsg_locked()
1340 /* msg->msg_ubuf is pinned by the caller so we don't take extra refs */ in tcp_sendmsg_locked()
1341 if (uarg && !msg->msg_ubuf) in tcp_sendmsg_locked()
1345 if (unlikely(tcp_rtx_and_write_queues_empty(sk) && err == -EAGAIN)) { in tcp_sendmsg_locked()
1346 sk->sk_write_space(sk); in tcp_sendmsg_locked()
1367 struct sock *sk = sock->sk; in tcp_splice_eof()
1376 tcp_push(sk, 0, mss_now, tp->nonagle, size_goal); in tcp_splice_eof()
1391 if (sock_flag(sk, SOCK_URGINLINE) || !tp->urg_data || in tcp_recv_urg()
1392 tp->urg_data == TCP_URG_READ) in tcp_recv_urg()
1393 return -EINVAL; /* Yes this is right ! */ in tcp_recv_urg()
1395 if (sk->sk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DONE)) in tcp_recv_urg()
1396 return -ENOTCONN; in tcp_recv_urg()
1398 if (tp->urg_data & TCP_URG_VALID) { in tcp_recv_urg()
1400 char c = tp->urg_data; in tcp_recv_urg()
1403 WRITE_ONCE(tp->urg_data, TCP_URG_READ); in tcp_recv_urg()
1406 msg->msg_flags |= MSG_OOB; in tcp_recv_urg()
1413 msg->msg_flags |= MSG_TRUNC; in tcp_recv_urg()
1415 return err ? -EFAULT : len; in tcp_recv_urg()
1418 if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN)) in tcp_recv_urg()
1425 * Mike <pall@rz.uni-karlsruhe.de> in tcp_recv_urg()
1427 return -EAGAIN; in tcp_recv_urg()
1435 skb_rbtree_walk(skb, &sk->tcp_rtx_queue) { in tcp_peek_sndq()
1436 err = skb_copy_datagram_msg(skb, 0, msg, skb->len); in tcp_peek_sndq()
1439 copied += skb->len; in tcp_peek_sndq()
1442 skb_queue_walk(&sk->sk_write_queue, skb) { in tcp_peek_sndq()
1443 err = skb_copy_datagram_msg(skb, 0, msg, skb->len); in tcp_peek_sndq()
1447 copied += skb->len; in tcp_peek_sndq()
1467 if (/* Once-per-two-segments ACK was not sent by tcp_input.c */ in __tcp_cleanup_rbuf()
1468 tp->rcv_nxt - tp->rcv_wup > icsk->icsk_ack.rcv_mss || in __tcp_cleanup_rbuf()
1476 ((icsk->icsk_ack.pending & ICSK_ACK_PUSHED2) || in __tcp_cleanup_rbuf()
1477 ((icsk->icsk_ack.pending & ICSK_ACK_PUSHED) && in __tcp_cleanup_rbuf()
1479 !atomic_read(&sk->sk_rmem_alloc))) in __tcp_cleanup_rbuf()
1483 /* We send an ACK if we can now advertise a non-zero window in __tcp_cleanup_rbuf()
1489 if (copied > 0 && !time_to_ack && !(sk->sk_shutdown & RCV_SHUTDOWN)) { in __tcp_cleanup_rbuf()
1493 if (2*rcv_window_now <= tp->window_clamp) { in __tcp_cleanup_rbuf()
1511 struct sk_buff *skb = skb_peek(&sk->sk_receive_queue); in tcp_cleanup_rbuf()
1514 WARN(skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq), in tcp_cleanup_rbuf()
1515 "cleanup rbuf bug: copied %X seq %X rcvnxt %X\n", in tcp_cleanup_rbuf()
1516 tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt); in tcp_cleanup_rbuf()
1522 __skb_unlink(skb, &sk->sk_receive_queue); in tcp_eat_recv_skb()
1523 if (likely(skb->destructor == sock_rfree)) { in tcp_eat_recv_skb()
1525 skb->destructor = NULL; in tcp_eat_recv_skb()
1526 skb->sk = NULL; in tcp_eat_recv_skb()
1537 while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) { in tcp_recv_skb()
1538 offset = seq - TCP_SKB_CB(skb)->seq; in tcp_recv_skb()
1539 if (unlikely(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) { in tcp_recv_skb()
1541 offset--; in tcp_recv_skb()
1543 if (offset < skb->len || (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)) { in tcp_recv_skb()
1562 * - It is assumed that the socket was locked by the caller.
1563 * - The routine does not block.
1564 * - At present, there is no support for reading OOB data
1573 u32 seq = tp->copied_seq; in tcp_read_sock()
1577 if (sk->sk_state == TCP_LISTEN) in tcp_read_sock()
1578 return -ENOTCONN; in tcp_read_sock()
1580 if (offset < skb->len) { in tcp_read_sock()
1584 len = skb->len - offset; in tcp_read_sock()
1586 if (unlikely(tp->urg_data)) { in tcp_read_sock()
1587 u32 urg_offset = tp->urg_seq - seq; in tcp_read_sock()
1610 skb = tcp_recv_skb(sk, seq - 1, &offset); in tcp_read_sock()
1616 if (offset + 1 != skb->len) in tcp_read_sock()
1619 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) { in tcp_read_sock()
1625 if (!desc->count) in tcp_read_sock()
1627 WRITE_ONCE(tp->copied_seq, seq); in tcp_read_sock()
1629 WRITE_ONCE(tp->copied_seq, seq); in tcp_read_sock()
1647 if (sk->sk_state == TCP_LISTEN) in tcp_read_skb()
1648 return -ENOTCONN; in tcp_read_skb()
1650 while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) { in tcp_read_skb()
1654 __skb_unlink(skb, &sk->sk_receive_queue); in tcp_read_skb()
1656 tcp_flags = TCP_SKB_CB(skb)->tcp_flags; in tcp_read_skb()
1675 u32 seq = tp->copied_seq; in tcp_read_done()
1680 if (sk->sk_state == TCP_LISTEN) in tcp_read_done()
1687 used = min_t(size_t, skb->len - offset, left); in tcp_read_done()
1689 left -= used; in tcp_read_done()
1691 if (skb->len > offset + used) in tcp_read_done()
1694 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) { in tcp_read_done()
1701 WRITE_ONCE(tp->copied_seq, seq); in tcp_read_done()
1707 tcp_cleanup_rbuf(sk, len - left); in tcp_read_done()
1713 return tcp_inq(sock->sk); in tcp_peek_len()
1722 if (sk->sk_userlocks & SOCK_RCVBUF_LOCK) in tcp_set_rcvlowat()
1723 cap = sk->sk_rcvbuf >> 1; in tcp_set_rcvlowat()
1725 cap = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rmem[2]) >> 1; in tcp_set_rcvlowat()
1727 WRITE_ONCE(sk->sk_rcvlowat, val ? : 1); in tcp_set_rcvlowat()
1732 if (sk->sk_userlocks & SOCK_RCVBUF_LOCK) in tcp_set_rcvlowat()
1736 if (space > sk->sk_rcvbuf) { in tcp_set_rcvlowat()
1737 WRITE_ONCE(sk->sk_rcvbuf, space); in tcp_set_rcvlowat()
1738 WRITE_ONCE(tcp_sk(sk)->window_clamp, val); in tcp_set_rcvlowat()
1747 if (skb->tstamp) in tcp_update_recv_tstamps()
1748 tss->ts[0] = ktime_to_timespec64(skb->tstamp); in tcp_update_recv_tstamps()
1750 tss->ts[0] = (struct timespec64) {0}; in tcp_update_recv_tstamps()
1752 if (skb_hwtstamps(skb)->hwtstamp) in tcp_update_recv_tstamps()
1753 tss->ts[2] = ktime_to_timespec64(skb_hwtstamps(skb)->hwtstamp); in tcp_update_recv_tstamps()
1755 tss->ts[2] = (struct timespec64) {0}; in tcp_update_recv_tstamps()
1765 if (vma->vm_flags & (VM_WRITE | VM_EXEC)) in tcp_mmap()
1766 return -EPERM; in tcp_mmap()
1772 vma->vm_ops = &tcp_vm_ops; in tcp_mmap()
1782 if (unlikely(offset_skb >= skb->len)) in skb_advance_to_frag()
1785 offset_skb -= skb_headlen(skb); in skb_advance_to_frag()
1789 frag = skb_shinfo(skb)->frags; in skb_advance_to_frag()
1795 offset_skb -= skb_frag_size(frag); in skb_advance_to_frag()
1811 if (PageCompound(page) || page->mapping) in can_map_frag()
1841 zc->recv_skip_hint = skb->len - offset; in tcp_zerocopy_set_hint_for_skb()
1852 if (frag == &info->frags[info->nr_frags - 1]) in tcp_zerocopy_set_hint_for_skb()
1856 partial_frag_remainder = skb_frag_size(frag) - frag_offset; in tcp_zerocopy_set_hint_for_skb()
1857 zc->recv_skip_hint -= partial_frag_remainder; in tcp_zerocopy_set_hint_for_skb()
1865 mappable_offset = find_next_mappable_frag(frag, zc->recv_skip_hint); in tcp_zerocopy_set_hint_for_skb()
1866 zc->recv_skip_hint = mappable_offset + partial_frag_remainder; in tcp_zerocopy_set_hint_for_skb()
1876 unsigned long copy_address = (unsigned long)zc->copybuf_address; in receive_fallback_to_copy()
1880 zc->length = 0; in receive_fallback_to_copy()
1881 zc->recv_skip_hint = 0; in receive_fallback_to_copy()
1883 if (copy_address != zc->copybuf_address) in receive_fallback_to_copy()
1884 return -EINVAL; in receive_fallback_to_copy()
1892 tss, &zc->msg_flags); in receive_fallback_to_copy()
1896 zc->copybuf_len = err; in receive_fallback_to_copy()
1897 if (likely(zc->copybuf_len)) { in receive_fallback_to_copy()
1901 skb = tcp_recv_skb(sk, tcp_sk(sk)->copied_seq, &offset); in receive_fallback_to_copy()
1912 unsigned long copy_address = (unsigned long)zc->copybuf_address; in tcp_copy_straggler_data()
1916 if (copy_address != zc->copybuf_address) in tcp_copy_straggler_data()
1917 return -EINVAL; in tcp_copy_straggler_data()
1926 zc->recv_skip_hint -= copylen; in tcp_copy_straggler_data()
1939 u32 offset, copylen = min_t(u32, copybuf_len, zc->recv_skip_hint); in tcp_zc_handle_leftover()
1945 offset = *seq - TCP_SKB_CB(skb)->seq; in tcp_zc_handle_leftover()
1948 if (TCP_SKB_CB(skb)->has_rxtstamp) { in tcp_zc_handle_leftover()
1950 zc->msg_flags |= TCP_CMSG_TS; in tcp_zc_handle_leftover()
1954 zc->copybuf_len = tcp_copy_straggler_data(zc, skb, copylen, &offset, in tcp_zc_handle_leftover()
1956 return zc->copybuf_len < 0 ? 0 : copylen; in tcp_zc_handle_leftover()
1970 if (err == -EBUSY && in tcp_zerocopy_vm_insert_batch_error()
1971 zc->flags & TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT) { in tcp_zerocopy_vm_insert_batch_error()
1974 maybe_zap_len = total_bytes_to_map - /* All bytes to map */ in tcp_zerocopy_vm_insert_batch_error()
1989 bytes_mapped = PAGE_SIZE * (leftover_pages - pages_remaining); in tcp_zerocopy_vm_insert_batch_error()
2001 *length -= bytes_not_mapped; in tcp_zerocopy_vm_insert_batch_error()
2002 zc->recv_skip_hint += bytes_not_mapped; in tcp_zerocopy_vm_insert_batch_error()
2022 pages_mapped = pages_to_map - (unsigned int)pages_remaining; in tcp_zerocopy_vm_insert_batch()
2047 msg_control_addr = (unsigned long)zc->msg_control; in tcp_zc_finalize_rx_tstamp()
2050 (__kernel_size_t)zc->msg_controllen; in tcp_zc_finalize_rx_tstamp()
2054 zc->msg_flags = 0; in tcp_zc_finalize_rx_tstamp()
2055 if (zc->msg_control == msg_control_addr && in tcp_zc_finalize_rx_tstamp()
2056 zc->msg_controllen == cmsg_dummy.msg_controllen) { in tcp_zc_finalize_rx_tstamp()
2058 zc->msg_control = (__u64) in tcp_zc_finalize_rx_tstamp()
2060 zc->msg_controllen = in tcp_zc_finalize_rx_tstamp()
2062 zc->msg_flags = (__u32)cmsg_dummy.msg_flags; in tcp_zc_finalize_rx_tstamp()
2073 if (vma->vm_ops != &tcp_vm_ops) { in find_tcp_vma()
2083 if (!vma || vma->vm_ops != &tcp_vm_ops) { in find_tcp_vma()
2097 unsigned long address = (unsigned long)zc->address; in tcp_zerocopy_receive()
2099 s32 copybuf_len = zc->copybuf_len; in tcp_zerocopy_receive()
2105 u32 seq = tp->copied_seq; in tcp_zerocopy_receive()
2111 zc->copybuf_len = 0; in tcp_zerocopy_receive()
2112 zc->msg_flags = 0; in tcp_zerocopy_receive()
2114 if (address & (PAGE_SIZE - 1) || address != zc->address) in tcp_zerocopy_receive()
2115 return -EINVAL; in tcp_zerocopy_receive()
2117 if (sk->sk_state == TCP_LISTEN) in tcp_zerocopy_receive()
2118 return -ENOTCONN; in tcp_zerocopy_receive()
2126 zc->length = 0; in tcp_zerocopy_receive()
2127 zc->recv_skip_hint = inq; in tcp_zerocopy_receive()
2129 return -EIO; in tcp_zerocopy_receive()
2133 vma = find_tcp_vma(current->mm, address, &mmap_locked); in tcp_zerocopy_receive()
2135 return -EINVAL; in tcp_zerocopy_receive()
2137 vma_len = min_t(unsigned long, zc->length, vma->vm_end - address); in tcp_zerocopy_receive()
2139 total_bytes_to_map = avail_len & ~(PAGE_SIZE - 1); in tcp_zerocopy_receive()
2141 if (!(zc->flags & TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT)) in tcp_zerocopy_receive()
2144 zc->length = total_bytes_to_map; in tcp_zerocopy_receive()
2145 zc->recv_skip_hint = 0; in tcp_zerocopy_receive()
2147 zc->length = avail_len; in tcp_zerocopy_receive()
2148 zc->recv_skip_hint = avail_len; in tcp_zerocopy_receive()
2151 while (length + PAGE_SIZE <= zc->length) { in tcp_zerocopy_receive()
2155 if (zc->recv_skip_hint < PAGE_SIZE) { in tcp_zerocopy_receive()
2159 if (zc->recv_skip_hint > 0) in tcp_zerocopy_receive()
2161 skb = skb->next; in tcp_zerocopy_receive()
2162 offset = seq - TCP_SKB_CB(skb)->seq; in tcp_zerocopy_receive()
2170 if (TCP_SKB_CB(skb)->has_rxtstamp) { in tcp_zerocopy_receive()
2172 zc->msg_flags |= TCP_CMSG_TS; in tcp_zerocopy_receive()
2174 zc->recv_skip_hint = skb->len - offset; in tcp_zerocopy_receive()
2181 zc->recv_skip_hint); in tcp_zerocopy_receive()
2183 zc->recv_skip_hint = mappable_offset; in tcp_zerocopy_receive()
2193 zc->recv_skip_hint -= PAGE_SIZE; in tcp_zerocopy_receive()
2196 zc->recv_skip_hint < PAGE_SIZE) { in tcp_zerocopy_receive()
2217 mmap_read_unlock(current->mm); in tcp_zerocopy_receive()
2225 WRITE_ONCE(tp->copied_seq, seq); in tcp_zerocopy_receive()
2232 if (length == zc->length) in tcp_zerocopy_receive()
2233 zc->recv_skip_hint = 0; in tcp_zerocopy_receive()
2235 if (!zc->recv_skip_hint && sock_flag(sk, SOCK_DONE)) in tcp_zerocopy_receive()
2236 ret = -EIO; in tcp_zerocopy_receive()
2238 zc->length = length; in tcp_zerocopy_receive()
2248 u32 tsflags = READ_ONCE(sk->sk_tsflags); in tcp_recv_timestamp()
2251 if (tss->ts[0].tv_sec || tss->ts[0].tv_nsec) { in tcp_recv_timestamp()
2256 .tv_sec = tss->ts[0].tv_sec, in tcp_recv_timestamp()
2257 .tv_nsec = tss->ts[0].tv_nsec, in tcp_recv_timestamp()
2263 .tv_sec = tss->ts[0].tv_sec, in tcp_recv_timestamp()
2264 .tv_nsec = tss->ts[0].tv_nsec, in tcp_recv_timestamp()
2272 .tv_sec = tss->ts[0].tv_sec, in tcp_recv_timestamp()
2273 .tv_usec = tss->ts[0].tv_nsec / 1000, in tcp_recv_timestamp()
2279 .tv_sec = tss->ts[0].tv_sec, in tcp_recv_timestamp()
2280 .tv_usec = tss->ts[0].tv_nsec / 1000, in tcp_recv_timestamp()
2293 tss->ts[0] = (struct timespec64) {0}; in tcp_recv_timestamp()
2296 if (tss->ts[2].tv_sec || tss->ts[2].tv_nsec) { in tcp_recv_timestamp()
2302 tss->ts[2] = (struct timespec64) {0}; in tcp_recv_timestamp()
2306 tss->ts[1] = (struct timespec64) {0}; in tcp_recv_timestamp()
2317 u32 copied_seq = READ_ONCE(tp->copied_seq); in tcp_inq_hint()
2318 u32 rcv_nxt = READ_ONCE(tp->rcv_nxt); in tcp_inq_hint()
2321 inq = rcv_nxt - copied_seq; in tcp_inq_hint()
2322 if (unlikely(inq < 0 || copied_seq != READ_ONCE(tp->copied_seq))) { in tcp_inq_hint()
2324 inq = tp->rcv_nxt - tp->copied_seq; in tcp_inq_hint()
2327 /* After receiving a FIN, tell the user-space to continue reading in tcp_inq_hint()
2328 * by returning a non-zero inq. in tcp_inq_hint()
2348 for (i = 0; i < p->idx; i++) in tcp_xa_pool_commit_locked()
2349 __xa_cmpxchg(&sk->sk_user_frags, p->tokens[i], XA_ZERO_ENTRY, in tcp_xa_pool_commit_locked()
2350 (__force void *)p->netmems[i], GFP_KERNEL); in tcp_xa_pool_commit_locked()
2351 /* Rollback what has been pre-allocated and is no longer needed. */ in tcp_xa_pool_commit_locked()
2352 for (; i < p->max; i++) in tcp_xa_pool_commit_locked()
2353 __xa_erase(&sk->sk_user_frags, p->tokens[i]); in tcp_xa_pool_commit_locked()
2355 p->max = 0; in tcp_xa_pool_commit_locked()
2356 p->idx = 0; in tcp_xa_pool_commit_locked()
2361 if (!p->max) in tcp_xa_pool_commit()
2364 xa_lock_bh(&sk->sk_user_frags); in tcp_xa_pool_commit()
2368 xa_unlock_bh(&sk->sk_user_frags); in tcp_xa_pool_commit()
2376 if (p->idx < p->max) in tcp_xa_pool_refill()
2379 xa_lock_bh(&sk->sk_user_frags); in tcp_xa_pool_refill()
2384 err = __xa_alloc(&sk->sk_user_frags, &p->tokens[k], in tcp_xa_pool_refill()
2390 xa_unlock_bh(&sk->sk_user_frags); in tcp_xa_pool_refill()
2392 p->max = k; in tcp_xa_pool_refill()
2393 p->idx = 0; in tcp_xa_pool_refill()
2397 /* On error, returns the -errno. On success, returns number of bytes sent to the
2417 err = -ENODEV; in tcp_recvmsg_dmabuf()
2422 copy = start - offset; in tcp_recvmsg_dmabuf()
2426 n = copy_to_iter(skb->data + offset, copy, in tcp_recvmsg_dmabuf()
2427 &msg->msg_iter); in tcp_recvmsg_dmabuf()
2429 err = -EFAULT; in tcp_recvmsg_dmabuf()
2434 remaining_len -= copy; in tcp_recvmsg_dmabuf()
2443 if (err || msg->msg_flags & MSG_CTRUNC) { in tcp_recvmsg_dmabuf()
2444 msg->msg_flags &= ~MSG_CTRUNC; in tcp_recvmsg_dmabuf()
2446 err = -ETOOSMALL; in tcp_recvmsg_dmabuf()
2459 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in tcp_recvmsg_dmabuf()
2460 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in tcp_recvmsg_dmabuf()
2473 net_err_ratelimited("Found non-dmabuf skb with net_iov"); in tcp_recvmsg_dmabuf()
2474 err = -ENODEV; in tcp_recvmsg_dmabuf()
2480 copy = end - offset; in tcp_recvmsg_dmabuf()
2486 skb_frag_off(frag) + offset - in tcp_recvmsg_dmabuf()
2491 skb_shinfo(skb)->nr_frags - i); in tcp_recvmsg_dmabuf()
2500 remaining_len -= copy; in tcp_recvmsg_dmabuf()
2506 if (err || msg->msg_flags & MSG_CTRUNC) { in tcp_recvmsg_dmabuf()
2507 msg->msg_flags &= ~MSG_CTRUNC; in tcp_recvmsg_dmabuf()
2509 err = -ETOOSMALL; in tcp_recvmsg_dmabuf()
2513 atomic_long_inc(&niov->pp_ref_count); in tcp_recvmsg_dmabuf()
2531 skb = skb_shinfo(skb)->frag_list ?: skb->next; in tcp_recvmsg_dmabuf()
2533 offset = offset - start; in tcp_recvmsg_dmabuf()
2537 err = -EFAULT; in tcp_recvmsg_dmabuf()
2553 * tricks with *seq access order and skb->users are not required.
2562 int last_copied_dmabuf = -1; /* uninitialized */ in tcp_recvmsg_locked()
2574 err = -ENOTCONN; in tcp_recvmsg_locked()
2575 if (sk->sk_state == TCP_LISTEN) in tcp_recvmsg_locked()
2578 if (tp->recvmsg_inq) { in tcp_recvmsg_locked()
2580 msg->msg_get_inq = 1; in tcp_recvmsg_locked()
2588 if (unlikely(tp->repair)) { in tcp_recvmsg_locked()
2589 err = -EPERM; in tcp_recvmsg_locked()
2593 if (tp->repair_queue == TCP_SEND_QUEUE) in tcp_recvmsg_locked()
2596 err = -EINVAL; in tcp_recvmsg_locked()
2597 if (tp->repair_queue == TCP_NO_QUEUE) in tcp_recvmsg_locked()
2600 /* 'common' recv queue MSG_PEEK-ing */ in tcp_recvmsg_locked()
2603 seq = &tp->copied_seq; in tcp_recvmsg_locked()
2606 peek_seq = tp->copied_seq + peek_offset; in tcp_recvmsg_locked()
2616 if (unlikely(tp->urg_data) && tp->urg_seq == *seq) { in tcp_recvmsg_locked()
2620 copied = timeo ? sock_intr_errno(timeo) : -EAGAIN; in tcp_recvmsg_locked()
2627 last = skb_peek_tail(&sk->sk_receive_queue); in tcp_recvmsg_locked()
2628 skb_queue_walk(&sk->sk_receive_queue, skb) { in tcp_recvmsg_locked()
2633 if (WARN(before(*seq, TCP_SKB_CB(skb)->seq), in tcp_recvmsg_locked()
2634 "TCP recvmsg seq # bug: copied %X, seq %X, rcvnxt %X, fl %X\n", in tcp_recvmsg_locked()
2635 *seq, TCP_SKB_CB(skb)->seq, tp->rcv_nxt, in tcp_recvmsg_locked()
2639 offset = *seq - TCP_SKB_CB(skb)->seq; in tcp_recvmsg_locked()
2640 if (unlikely(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)) { in tcp_recvmsg_locked()
2642 offset--; in tcp_recvmsg_locked()
2644 if (offset < skb->len) in tcp_recvmsg_locked()
2646 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) in tcp_recvmsg_locked()
2649 "TCP recvmsg seq # bug 2: copied %X, seq %X, rcvnxt %X, fl %X\n", in tcp_recvmsg_locked()
2650 *seq, TCP_SKB_CB(skb)->seq, tp->rcv_nxt, flags); in tcp_recvmsg_locked()
2655 if (copied >= target && !READ_ONCE(sk->sk_backlog.tail)) in tcp_recvmsg_locked()
2660 sk->sk_err || in tcp_recvmsg_locked()
2661 sk->sk_state == TCP_CLOSE || in tcp_recvmsg_locked()
2662 (sk->sk_shutdown & RCV_SHUTDOWN) || in tcp_recvmsg_locked()
2669 if (sk->sk_err) { in tcp_recvmsg_locked()
2674 if (sk->sk_shutdown & RCV_SHUTDOWN) in tcp_recvmsg_locked()
2677 if (sk->sk_state == TCP_CLOSE) { in tcp_recvmsg_locked()
2681 copied = -ENOTCONN; in tcp_recvmsg_locked()
2686 copied = -EAGAIN; in tcp_recvmsg_locked()
2709 (peek_seq - peek_offset - copied - urg_hole != tp->copied_seq)) { in tcp_recvmsg_locked()
2711 current->comm, in tcp_recvmsg_locked()
2713 peek_seq = tp->copied_seq + peek_offset; in tcp_recvmsg_locked()
2719 used = skb->len - offset; in tcp_recvmsg_locked()
2724 if (unlikely(tp->urg_data)) { in tcp_recvmsg_locked()
2725 u32 urg_offset = tp->urg_seq - *seq; in tcp_recvmsg_locked()
2732 used--; in tcp_recvmsg_locked()
2742 if (last_copied_dmabuf != -1 && in tcp_recvmsg_locked()
2752 copied = -EFAULT; in tcp_recvmsg_locked()
2761 copied = -EFAULT; in tcp_recvmsg_locked()
2770 copied = -EFAULT; in tcp_recvmsg_locked()
2782 len -= used; in tcp_recvmsg_locked()
2790 if (unlikely(tp->urg_data) && after(tp->copied_seq, tp->urg_seq)) { in tcp_recvmsg_locked()
2791 WRITE_ONCE(tp->urg_data, 0); in tcp_recvmsg_locked()
2795 if (TCP_SKB_CB(skb)->has_rxtstamp) { in tcp_recvmsg_locked()
2800 if (used + offset < skb->len) in tcp_recvmsg_locked()
2803 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) in tcp_recvmsg_locked()
2818 * on connected socket. I was just happy when found this 8) --ANK in tcp_recvmsg_locked()
2847 skb_queue_empty_lockless(&sk->sk_receive_queue) && in tcp_recvmsg()
2848 sk->sk_state == TCP_ESTABLISHED) in tcp_recvmsg()
2855 if ((cmsg_flags || msg->msg_get_inq) && ret >= 0) { in tcp_recvmsg()
2858 if (msg->msg_get_inq) { in tcp_recvmsg()
2859 msg->msg_inq = tcp_inq_hint(sk); in tcp_recvmsg()
2862 sizeof(msg->msg_inq), &msg->msg_inq); in tcp_recvmsg()
2871 int oldstate = sk->sk_state; in tcp_set_state()
2901 * above-mentioned anonymous enum in the vmlinux DWARF and hence BTF in tcp_set_state()
2923 sk->sk_prot->unhash(sk); in tcp_set_state()
2924 if (inet_csk(sk)->icsk_bind_hash && in tcp_set_state()
2925 !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) in tcp_set_state()
2966 int next = (int)new_state[sk->sk_state]; in tcp_close_state()
2989 if ((1 << sk->sk_state) & in tcp_shutdown()
3027 if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && in tcp_out_of_memory()
3043 net_info_ratelimited("out of memory -- consider tuning tcp_mem\n"); in tcp_check_oom()
3053 WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK); in __tcp_close()
3055 if (sk->sk_state == TCP_LISTEN) { in __tcp_close()
3065 * descriptor close, not protocol-sourced closes, because the in __tcp_close()
3068 while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) { in __tcp_close()
3069 u32 len = TCP_SKB_CB(skb)->end_seq - TCP_SKB_CB(skb)->seq; in __tcp_close()
3071 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) in __tcp_close()
3072 len--; in __tcp_close()
3077 /* If socket has been already reset (e.g. in tcp_reset()) - kill it. */ in __tcp_close()
3078 if (sk->sk_state == TCP_CLOSE) in __tcp_close()
3083 * always doing a FIN, run an older 2.1.x kernel or 2.0.x, start a bulk in __tcp_close()
3085 * advertise a zero window, then kill -9 the FTP client, wheee... in __tcp_close()
3088 if (unlikely(tcp_sk(sk)->repair)) { in __tcp_close()
3089 sk->sk_prot->disconnect(sk, 0); in __tcp_close()
3094 tcp_send_active_reset(sk, sk->sk_allocation, in __tcp_close()
3096 } else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { in __tcp_close()
3098 sk->sk_prot->disconnect(sk, 0); in __tcp_close()
3105 /* RED-PEN. Formally speaking, we have broken TCP state in __tcp_close()
3108 * TCP_ESTABLISHED -> TCP_FIN_WAIT1 in __tcp_close()
3109 * TCP_SYN_RECV -> TCP_FIN_WAIT1 (it is difficult) in __tcp_close()
3110 * TCP_CLOSE_WAIT -> TCP_LAST_ACK in __tcp_close()
3116 * if Linux state is FIN-WAIT-1, but FIN is still not sent. in __tcp_close()
3119 * we enter time-wait state, when it is not required really in __tcp_close()
3124 * --ANK in __tcp_close()
3125 * XXX (TFO) - To start off we don't support SYN+ACK+FIN in __tcp_close()
3127 * probably need API support or TCP_CORK SYN-ACK until in __tcp_close()
3136 state = sk->sk_state; in __tcp_close()
3148 if (state != TCP_CLOSE && sk->sk_state == TCP_CLOSE) in __tcp_close()
3155 * our end. If they send after that then tough - BUT: long enough in __tcp_close()
3156 * that we won't make the old 4*rto = almost no time - whoops in __tcp_close()
3162 * linger2 option. --ANK in __tcp_close()
3165 if (sk->sk_state == TCP_FIN_WAIT2) { in __tcp_close()
3167 if (READ_ONCE(tp->linger2) < 0) { in __tcp_close()
3178 tmo - TCP_TIMEWAIT_LEN); in __tcp_close()
3185 if (sk->sk_state != TCP_CLOSE) { in __tcp_close()
3198 if (sk->sk_state == TCP_CLOSE) { in __tcp_close()
3201 req = rcu_dereference_protected(tcp_sk(sk)->fastopen_rsk, in __tcp_close()
3203 /* We could get here with a non-NULL req if the socket is in __tcp_close()
3223 if (!sk->sk_net_refcnt) in tcp_close()
3240 struct rb_node *p = rb_first(&sk->tcp_rtx_queue); in tcp_rtx_queue_purge()
3242 tcp_sk(sk)->highest_sack = NULL; in tcp_rtx_queue_purge()
3248 * list_del(&skb->tcp_tsorted_anchor) in tcp_rtx_queue_purge()
3260 while ((skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) { in tcp_write_queue_purge()
3265 INIT_LIST_HEAD(&tcp_sk(sk)->tsorted_sent_queue); in tcp_write_queue_purge()
3267 tcp_sk(sk)->packets_out = 0; in tcp_write_queue_purge()
3268 inet_csk(sk)->icsk_backoff = 0; in tcp_write_queue_purge()
3276 int old_state = sk->sk_state; in tcp_disconnect()
3285 } else if (unlikely(tp->repair)) { in tcp_disconnect()
3286 WRITE_ONCE(sk->sk_err, ECONNABORTED); in tcp_disconnect()
3289 WRITE_ONCE(sk->sk_err, ECONNRESET); in tcp_disconnect()
3290 } else if (tp->snd_nxt != tp->write_seq && in tcp_disconnect()
3297 WRITE_ONCE(sk->sk_err, ECONNRESET); in tcp_disconnect()
3299 WRITE_ONCE(sk->sk_err, ECONNRESET); in tcp_disconnect()
3302 __skb_queue_purge(&sk->sk_receive_queue); in tcp_disconnect()
3303 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); in tcp_disconnect()
3304 WRITE_ONCE(tp->urg_data, 0); in tcp_disconnect()
3305 sk_set_peek_off(sk, -1); in tcp_disconnect()
3308 skb_rbtree_purge(&tp->out_of_order_queue); in tcp_disconnect()
3310 inet->inet_dport = 0; in tcp_disconnect()
3314 WRITE_ONCE(sk->sk_shutdown, 0); in tcp_disconnect()
3316 tp->srtt_us = 0; in tcp_disconnect()
3317 tp->mdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT); in tcp_disconnect()
3318 tp->rcv_rtt_last_tsecr = 0; in tcp_disconnect()
3320 seq = tp->write_seq + tp->max_window + 2; in tcp_disconnect()
3323 WRITE_ONCE(tp->write_seq, seq); in tcp_disconnect()
3325 icsk->icsk_backoff = 0; in tcp_disconnect()
3326 icsk->icsk_probes_out = 0; in tcp_disconnect()
3327 icsk->icsk_probes_tstamp = 0; in tcp_disconnect()
3328 icsk->icsk_rto = TCP_TIMEOUT_INIT; in tcp_disconnect()
3329 icsk->icsk_rto_min = TCP_RTO_MIN; in tcp_disconnect()
3330 icsk->icsk_delack_max = TCP_DELACK_MAX; in tcp_disconnect()
3331 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; in tcp_disconnect()
3333 tp->snd_cwnd_cnt = 0; in tcp_disconnect()
3334 tp->is_cwnd_limited = 0; in tcp_disconnect()
3335 tp->max_packets_out = 0; in tcp_disconnect()
3336 tp->window_clamp = 0; in tcp_disconnect()
3337 tp->delivered = 0; in tcp_disconnect()
3338 tp->delivered_ce = 0; in tcp_disconnect()
3339 if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release) in tcp_disconnect()
3340 icsk->icsk_ca_ops->release(sk); in tcp_disconnect()
3341 memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv)); in tcp_disconnect()
3342 icsk->icsk_ca_initialized = 0; in tcp_disconnect()
3344 tp->is_sack_reneg = 0; in tcp_disconnect()
3346 tp->total_retrans = 0; in tcp_disconnect()
3351 icsk->icsk_ack.rcv_mss = TCP_MIN_MSS; in tcp_disconnect()
3352 memset(&tp->rx_opt, 0, sizeof(tp->rx_opt)); in tcp_disconnect()
3354 dst_release(unrcu_pointer(xchg(&sk->sk_rx_dst, NULL))); in tcp_disconnect()
3356 tp->compressed_ack = 0; in tcp_disconnect()
3357 tp->segs_in = 0; in tcp_disconnect()
3358 tp->segs_out = 0; in tcp_disconnect()
3359 tp->bytes_sent = 0; in tcp_disconnect()
3360 tp->bytes_acked = 0; in tcp_disconnect()
3361 tp->bytes_received = 0; in tcp_disconnect()
3362 tp->bytes_retrans = 0; in tcp_disconnect()
3363 tp->data_segs_in = 0; in tcp_disconnect()
3364 tp->data_segs_out = 0; in tcp_disconnect()
3365 tp->duplicate_sack[0].start_seq = 0; in tcp_disconnect()
3366 tp->duplicate_sack[0].end_seq = 0; in tcp_disconnect()
3367 tp->dsack_dups = 0; in tcp_disconnect()
3368 tp->reord_seen = 0; in tcp_disconnect()
3369 tp->retrans_out = 0; in tcp_disconnect()
3370 tp->sacked_out = 0; in tcp_disconnect()
3371 tp->tlp_high_seq = 0; in tcp_disconnect()
3372 tp->last_oow_ack_time = 0; in tcp_disconnect()
3373 tp->plb_rehash = 0; in tcp_disconnect()
3375 tp->app_limited = ~0U; in tcp_disconnect()
3376 tp->rate_app_limited = 1; in tcp_disconnect()
3377 tp->rack.mstamp = 0; in tcp_disconnect()
3378 tp->rack.advanced = 0; in tcp_disconnect()
3379 tp->rack.reo_wnd_steps = 1; in tcp_disconnect()
3380 tp->rack.last_delivered = 0; in tcp_disconnect()
3381 tp->rack.reo_wnd_persist = 0; in tcp_disconnect()
3382 tp->rack.dsack_seen = 0; in tcp_disconnect()
3383 tp->syn_data_acked = 0; in tcp_disconnect()
3384 tp->rx_opt.saw_tstamp = 0; in tcp_disconnect()
3385 tp->rx_opt.dsack = 0; in tcp_disconnect()
3386 tp->rx_opt.num_sacks = 0; in tcp_disconnect()
3387 tp->rcv_ooopack = 0; in tcp_disconnect()
3393 tp->fastopen_client_fail = 0; in tcp_disconnect()
3395 WARN_ON(inet->inet_num && !icsk->icsk_bind_hash); in tcp_disconnect()
3397 if (sk->sk_frag.page) { in tcp_disconnect()
3398 put_page(sk->sk_frag.page); in tcp_disconnect()
3399 sk->sk_frag.page = NULL; in tcp_disconnect()
3400 sk->sk_frag.offset = 0; in tcp_disconnect()
3409 return sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN) && in tcp_can_repair_sock()
3410 (sk->sk_state != TCP_LISTEN); in tcp_can_repair_sock()
3417 if (!tp->repair) in tcp_repair_set_window()
3418 return -EPERM; in tcp_repair_set_window()
3421 return -EINVAL; in tcp_repair_set_window()
3424 return -EFAULT; in tcp_repair_set_window()
3427 return -EINVAL; in tcp_repair_set_window()
3429 if (after(opt.snd_wl1, tp->rcv_nxt + opt.rcv_wnd)) in tcp_repair_set_window()
3430 return -EINVAL; in tcp_repair_set_window()
3432 if (after(opt.rcv_wup, tp->rcv_nxt)) in tcp_repair_set_window()
3433 return -EINVAL; in tcp_repair_set_window()
3435 tp->snd_wl1 = opt.snd_wl1; in tcp_repair_set_window()
3436 tp->snd_wnd = opt.snd_wnd; in tcp_repair_set_window()
3437 tp->max_window = opt.max_window; in tcp_repair_set_window()
3439 tp->rcv_wnd = opt.rcv_wnd; in tcp_repair_set_window()
3440 tp->rcv_wup = opt.rcv_wup; in tcp_repair_set_window()
3454 return -EFAULT; in tcp_repair_options_est()
3457 len -= sizeof(opt); in tcp_repair_options_est()
3461 tp->rx_opt.mss_clamp = opt.opt_val; in tcp_repair_options_est()
3470 return -EFBIG; in tcp_repair_options_est()
3472 tp->rx_opt.snd_wscale = snd_wscale; in tcp_repair_options_est()
3473 tp->rx_opt.rcv_wscale = rcv_wscale; in tcp_repair_options_est()
3474 tp->rx_opt.wscale_ok = 1; in tcp_repair_options_est()
3479 return -EINVAL; in tcp_repair_options_est()
3481 tp->rx_opt.sack_ok |= TCP_SACK_SEEN; in tcp_repair_options_est()
3485 return -EINVAL; in tcp_repair_options_est()
3487 tp->rx_opt.tstamp_ok = 1; in tcp_repair_options_est()
3510 /* When set indicates to always queue non-full frames. Later the user clears
3524 tp->nonagle |= TCP_NAGLE_CORK; in __tcp_sock_set_cork()
3526 tp->nonagle &= ~TCP_NAGLE_CORK; in __tcp_sock_set_cork()
3527 if (tp->nonagle & TCP_NAGLE_OFF) in __tcp_sock_set_cork()
3528 tp->nonagle |= TCP_NAGLE_PUSH; in __tcp_sock_set_cork()
3550 tcp_sk(sk)->nonagle |= TCP_NAGLE_OFF|TCP_NAGLE_PUSH; in __tcp_sock_set_nodelay()
3553 tcp_sk(sk)->nonagle &= ~TCP_NAGLE_OFF; in __tcp_sock_set_nodelay()
3573 if ((1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT) && in __tcp_sock_set_quickack()
3575 inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_PUSHED; in __tcp_sock_set_quickack()
3593 return -EINVAL; in tcp_sock_set_syncnt()
3595 WRITE_ONCE(inet_csk(sk)->icsk_syn_retries, val); in tcp_sock_set_syncnt()
3606 return -EINVAL; in tcp_sock_set_user_timeout()
3608 WRITE_ONCE(inet_csk(sk)->icsk_user_timeout, val); in tcp_sock_set_user_timeout()
3618 return -EINVAL; in tcp_sock_set_keepidle_locked()
3621 WRITE_ONCE(tp->keepalive_time, val * HZ); in tcp_sock_set_keepidle_locked()
3623 !((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) { in tcp_sock_set_keepidle_locked()
3626 if (tp->keepalive_time > elapsed) in tcp_sock_set_keepidle_locked()
3627 elapsed = tp->keepalive_time - elapsed; in tcp_sock_set_keepidle_locked()
3650 return -EINVAL; in tcp_sock_set_keepintvl()
3652 WRITE_ONCE(tcp_sk(sk)->keepalive_intvl, val * HZ); in tcp_sock_set_keepintvl()
3660 return -EINVAL; in tcp_sock_set_keepcnt()
3663 WRITE_ONCE(tcp_sk(sk)->keepalive_probes, val); in tcp_sock_set_keepcnt()
3673 if (sk->sk_state != TCP_CLOSE) in tcp_set_window_clamp()
3674 return -EINVAL; in tcp_set_window_clamp()
3675 WRITE_ONCE(tp->window_clamp, 0); in tcp_set_window_clamp()
3677 u32 new_rcv_ssthresh, old_window_clamp = tp->window_clamp; in tcp_set_window_clamp()
3684 WRITE_ONCE(tp->window_clamp, new_window_clamp); in tcp_set_window_clamp()
3689 __tcp_adjust_rcv_ssthresh(sk, tp->window_clamp); in tcp_set_window_clamp()
3692 new_rcv_ssthresh = min(tp->rcv_wnd, tp->window_clamp); in tcp_set_window_clamp()
3693 tp->rcv_ssthresh = max(new_rcv_ssthresh, in tcp_set_window_clamp()
3694 tp->rcv_ssthresh); in tcp_set_window_clamp()
3718 return -EINVAL; in do_tcp_setsockopt()
3721 min_t(long, TCP_CA_NAME_MAX-1, optlen)); in do_tcp_setsockopt()
3723 return -EFAULT; in do_tcp_setsockopt()
3728 sockopt_ns_capable(sock_net(sk)->user_ns, in do_tcp_setsockopt()
3737 return -EINVAL; in do_tcp_setsockopt()
3740 min_t(long, TCP_ULP_NAME_MAX - 1, in do_tcp_setsockopt()
3743 return -EFAULT; in do_tcp_setsockopt()
3760 return -EINVAL; in do_tcp_setsockopt()
3763 return -EFAULT; in do_tcp_setsockopt()
3776 return -EINVAL; in do_tcp_setsockopt()
3779 return -EFAULT; in do_tcp_setsockopt()
3793 WRITE_ONCE(tp->linger2, -1); in do_tcp_setsockopt()
3795 WRITE_ONCE(tp->linger2, TCP_FIN_TIMEOUT_MAX); in do_tcp_setsockopt()
3797 WRITE_ONCE(tp->linger2, val * HZ); in do_tcp_setsockopt()
3801 WRITE_ONCE(icsk->icsk_accept_queue.rskq_defer_accept, in do_tcp_setsockopt()
3816 err = -EINVAL; in do_tcp_setsockopt()
3819 tp->rx_opt.user_mss = val; in do_tcp_setsockopt()
3828 err = -EINVAL; in do_tcp_setsockopt()
3830 tp->thin_lto = val; in do_tcp_setsockopt()
3835 err = -EINVAL; in do_tcp_setsockopt()
3840 err = -EPERM; in do_tcp_setsockopt()
3842 tp->repair = 1; in do_tcp_setsockopt()
3843 sk->sk_reuse = SK_FORCE_REUSE; in do_tcp_setsockopt()
3844 tp->repair_queue = TCP_NO_QUEUE; in do_tcp_setsockopt()
3846 tp->repair = 0; in do_tcp_setsockopt()
3847 sk->sk_reuse = SK_NO_REUSE; in do_tcp_setsockopt()
3850 tp->repair = 0; in do_tcp_setsockopt()
3851 sk->sk_reuse = SK_NO_REUSE; in do_tcp_setsockopt()
3853 err = -EINVAL; in do_tcp_setsockopt()
3858 if (!tp->repair) in do_tcp_setsockopt()
3859 err = -EPERM; in do_tcp_setsockopt()
3861 tp->repair_queue = val; in do_tcp_setsockopt()
3863 err = -EINVAL; in do_tcp_setsockopt()
3867 if (sk->sk_state != TCP_CLOSE) { in do_tcp_setsockopt()
3868 err = -EPERM; in do_tcp_setsockopt()
3869 } else if (tp->repair_queue == TCP_SEND_QUEUE) { in do_tcp_setsockopt()
3871 err = -EPERM; in do_tcp_setsockopt()
3873 WRITE_ONCE(tp->write_seq, val); in do_tcp_setsockopt()
3874 } else if (tp->repair_queue == TCP_RECV_QUEUE) { in do_tcp_setsockopt()
3875 if (tp->rcv_nxt != tp->copied_seq) { in do_tcp_setsockopt()
3876 err = -EPERM; in do_tcp_setsockopt()
3878 WRITE_ONCE(tp->rcv_nxt, val); in do_tcp_setsockopt()
3879 WRITE_ONCE(tp->copied_seq, val); in do_tcp_setsockopt()
3882 err = -EINVAL; in do_tcp_setsockopt()
3887 if (!tp->repair) in do_tcp_setsockopt()
3888 err = -EINVAL; in do_tcp_setsockopt()
3889 else if (sk->sk_state == TCP_ESTABLISHED && !tp->bytes_sent) in do_tcp_setsockopt()
3892 err = -EPERM; in do_tcp_setsockopt()
3905 err = -EINVAL; in do_tcp_setsockopt()
3907 tp->save_syn = val; in do_tcp_setsockopt()
3920 err = -EPERM; in do_tcp_setsockopt()
3929 /* If this is the first TCP-AO setsockopt() on the socket, in do_tcp_setsockopt()
3933 if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) in do_tcp_setsockopt()
3935 if (rcu_dereference_protected(tcp_sk(sk)->ao_info, in do_tcp_setsockopt()
3938 if (tp->repair) in do_tcp_setsockopt()
3940 err = -EISCONN; in do_tcp_setsockopt()
3943 err = tp->af_specific->ao_parse(sk, optname, optval, optlen); in do_tcp_setsockopt()
3950 err = tp->af_specific->md5_parse(sk, optname, optval, optlen); in do_tcp_setsockopt()
3954 if (val >= 0 && ((1 << sk->sk_state) & (TCPF_CLOSE | in do_tcp_setsockopt()
3960 err = -EINVAL; in do_tcp_setsockopt()
3965 err = -EINVAL; in do_tcp_setsockopt()
3966 } else if (READ_ONCE(net->ipv4.sysctl_tcp_fastopen) & in do_tcp_setsockopt()
3968 if (sk->sk_state == TCP_CLOSE) in do_tcp_setsockopt()
3969 tp->fastopen_connect = val; in do_tcp_setsockopt()
3971 err = -EINVAL; in do_tcp_setsockopt()
3973 err = -EOPNOTSUPP; in do_tcp_setsockopt()
3978 err = -EINVAL; in do_tcp_setsockopt()
3979 else if (!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) in do_tcp_setsockopt()
3980 err = -EINVAL; in do_tcp_setsockopt()
3982 tp->fastopen_no_cookie = val; in do_tcp_setsockopt()
3985 if (!tp->repair) { in do_tcp_setsockopt()
3986 err = -EPERM; in do_tcp_setsockopt()
3993 tp->tcp_usec_ts = val & 1; in do_tcp_setsockopt()
3994 WRITE_ONCE(tp->tsoffset, val - tcp_clock_ts(tp->tcp_usec_ts)); in do_tcp_setsockopt()
4000 WRITE_ONCE(tp->notsent_lowat, val); in do_tcp_setsockopt()
4001 sk->sk_write_space(sk); in do_tcp_setsockopt()
4005 err = -EINVAL; in do_tcp_setsockopt()
4007 tp->recvmsg_inq = val; in do_tcp_setsockopt()
4012 WRITE_ONCE(tp->tcp_tx_delay, val); in do_tcp_setsockopt()
4015 err = -ENOPROTOOPT; in do_tcp_setsockopt()
4030 return READ_ONCE(icsk->icsk_af_ops)->setsockopt(sk, level, optname, in tcp_setsockopt()
4043 stats[i] = tp->chrono_stat[i - 1]; in tcp_get_info_chrono_stats()
4044 if (i == tp->chrono_type) in tcp_get_info_chrono_stats()
4045 stats[i] += tcp_jiffies32 - tp->chrono_start; in tcp_get_info_chrono_stats()
4050 info->tcpi_busy_time = total; in tcp_get_info_chrono_stats()
4051 info->tcpi_rwnd_limited = stats[TCP_CHRONO_RWND_LIMITED]; in tcp_get_info_chrono_stats()
4052 info->tcpi_sndbuf_limited = stats[TCP_CHRONO_SNDBUF_LIMITED]; in tcp_get_info_chrono_stats()
4066 if (sk->sk_type != SOCK_STREAM) in tcp_get_info()
4069 info->tcpi_state = inet_sk_state_load(sk); in tcp_get_info()
4072 rate = READ_ONCE(sk->sk_pacing_rate); in tcp_get_info()
4074 info->tcpi_pacing_rate = rate64; in tcp_get_info()
4076 rate = READ_ONCE(sk->sk_max_pacing_rate); in tcp_get_info()
4078 info->tcpi_max_pacing_rate = rate64; in tcp_get_info()
4080 info->tcpi_reordering = tp->reordering; in tcp_get_info()
4081 info->tcpi_snd_cwnd = tcp_snd_cwnd(tp); in tcp_get_info()
4083 if (info->tcpi_state == TCP_LISTEN) { in tcp_get_info()
4085 * tcpi_unacked -> Number of children ready for accept() in tcp_get_info()
4086 * tcpi_sacked -> max backlog in tcp_get_info()
4088 info->tcpi_unacked = READ_ONCE(sk->sk_ack_backlog); in tcp_get_info()
4089 info->tcpi_sacked = READ_ONCE(sk->sk_max_ack_backlog); in tcp_get_info()
4095 info->tcpi_ca_state = icsk->icsk_ca_state; in tcp_get_info()
4096 info->tcpi_retransmits = icsk->icsk_retransmits; in tcp_get_info()
4097 info->tcpi_probes = icsk->icsk_probes_out; in tcp_get_info()
4098 info->tcpi_backoff = icsk->icsk_backoff; in tcp_get_info()
4100 if (tp->rx_opt.tstamp_ok) in tcp_get_info()
4101 info->tcpi_options |= TCPI_OPT_TIMESTAMPS; in tcp_get_info()
4103 info->tcpi_options |= TCPI_OPT_SACK; in tcp_get_info()
4104 if (tp->rx_opt.wscale_ok) { in tcp_get_info()
4105 info->tcpi_options |= TCPI_OPT_WSCALE; in tcp_get_info()
4106 info->tcpi_snd_wscale = tp->rx_opt.snd_wscale; in tcp_get_info()
4107 info->tcpi_rcv_wscale = tp->rx_opt.rcv_wscale; in tcp_get_info()
4110 if (tp->ecn_flags & TCP_ECN_OK) in tcp_get_info()
4111 info->tcpi_options |= TCPI_OPT_ECN; in tcp_get_info()
4112 if (tp->ecn_flags & TCP_ECN_SEEN) in tcp_get_info()
4113 info->tcpi_options |= TCPI_OPT_ECN_SEEN; in tcp_get_info()
4114 if (tp->syn_data_acked) in tcp_get_info()
4115 info->tcpi_options |= TCPI_OPT_SYN_DATA; in tcp_get_info()
4116 if (tp->tcp_usec_ts) in tcp_get_info()
4117 info->tcpi_options |= TCPI_OPT_USEC_TS; in tcp_get_info()
4119 info->tcpi_rto = jiffies_to_usecs(icsk->icsk_rto); in tcp_get_info()
4120 info->tcpi_ato = jiffies_to_usecs(min_t(u32, icsk->icsk_ack.ato, in tcp_get_info()
4122 info->tcpi_snd_mss = tp->mss_cache; in tcp_get_info()
4123 info->tcpi_rcv_mss = icsk->icsk_ack.rcv_mss; in tcp_get_info()
4125 info->tcpi_unacked = tp->packets_out; in tcp_get_info()
4126 info->tcpi_sacked = tp->sacked_out; in tcp_get_info()
4128 info->tcpi_lost = tp->lost_out; in tcp_get_info()
4129 info->tcpi_retrans = tp->retrans_out; in tcp_get_info()
4132 info->tcpi_last_data_sent = jiffies_to_msecs(now - tp->lsndtime); in tcp_get_info()
4133 info->tcpi_last_data_recv = jiffies_to_msecs(now - icsk->icsk_ack.lrcvtime); in tcp_get_info()
4134 info->tcpi_last_ack_recv = jiffies_to_msecs(now - tp->rcv_tstamp); in tcp_get_info()
4136 info->tcpi_pmtu = icsk->icsk_pmtu_cookie; in tcp_get_info()
4137 info->tcpi_rcv_ssthresh = tp->rcv_ssthresh; in tcp_get_info()
4138 info->tcpi_rtt = tp->srtt_us >> 3; in tcp_get_info()
4139 info->tcpi_rttvar = tp->mdev_us >> 2; in tcp_get_info()
4140 info->tcpi_snd_ssthresh = tp->snd_ssthresh; in tcp_get_info()
4141 info->tcpi_advmss = tp->advmss; in tcp_get_info()
4143 info->tcpi_rcv_rtt = tp->rcv_rtt_est.rtt_us >> 3; in tcp_get_info()
4144 info->tcpi_rcv_space = tp->rcvq_space.space; in tcp_get_info()
4146 info->tcpi_total_retrans = tp->total_retrans; in tcp_get_info()
4148 info->tcpi_bytes_acked = tp->bytes_acked; in tcp_get_info()
4149 info->tcpi_bytes_received = tp->bytes_received; in tcp_get_info()
4150 info->tcpi_notsent_bytes = max_t(int, 0, tp->write_seq - tp->snd_nxt); in tcp_get_info()
4153 info->tcpi_segs_out = tp->segs_out; in tcp_get_info()
4156 info->tcpi_segs_in = READ_ONCE(tp->segs_in); in tcp_get_info()
4157 info->tcpi_data_segs_in = READ_ONCE(tp->data_segs_in); in tcp_get_info()
4159 info->tcpi_min_rtt = tcp_min_rtt(tp); in tcp_get_info()
4160 info->tcpi_data_segs_out = tp->data_segs_out; in tcp_get_info()
4162 info->tcpi_delivery_rate_app_limited = tp->rate_app_limited ? 1 : 0; in tcp_get_info()
4165 info->tcpi_delivery_rate = rate64; in tcp_get_info()
4166 info->tcpi_delivered = tp->delivered; in tcp_get_info()
4167 info->tcpi_delivered_ce = tp->delivered_ce; in tcp_get_info()
4168 info->tcpi_bytes_sent = tp->bytes_sent; in tcp_get_info()
4169 info->tcpi_bytes_retrans = tp->bytes_retrans; in tcp_get_info()
4170 info->tcpi_dsack_dups = tp->dsack_dups; in tcp_get_info()
4171 info->tcpi_reord_seen = tp->reord_seen; in tcp_get_info()
4172 info->tcpi_rcv_ooopack = tp->rcv_ooopack; in tcp_get_info()
4173 info->tcpi_snd_wnd = tp->snd_wnd; in tcp_get_info()
4174 info->tcpi_rcv_wnd = tp->rcv_wnd; in tcp_get_info()
4175 info->tcpi_rehash = tp->plb_rehash + tp->timeout_rehash; in tcp_get_info()
4176 info->tcpi_fastopen_client_fail = tp->fastopen_client_fail; in tcp_get_info()
4178 info->tcpi_total_rto = tp->total_rto; in tcp_get_info()
4179 info->tcpi_total_rto_recoveries = tp->total_rto_recoveries; in tcp_get_info()
4180 info->tcpi_total_rto_time = tp->total_rto_time; in tcp_get_info()
4181 if (tp->rto_stamp) in tcp_get_info()
4182 info->tcpi_total_rto_time += tcp_clock_ms() - tp->rto_stamp; in tcp_get_info()
4224 if (skb->protocol == htons(ETH_P_IP)) in tcp_skb_ttl_or_hop_limit()
4225 return ip_hdr(skb)->ttl; in tcp_skb_ttl_or_hop_limit()
4226 else if (skb->protocol == htons(ETH_P_IPV6)) in tcp_skb_ttl_or_hop_limit()
4227 return ipv6_hdr(skb)->hop_limit; in tcp_skb_ttl_or_hop_limit()
4254 tp->data_segs_out, TCP_NLA_PAD); in tcp_get_timestamping_opt_stats()
4256 tp->total_retrans, TCP_NLA_PAD); in tcp_get_timestamping_opt_stats()
4258 rate = READ_ONCE(sk->sk_pacing_rate); in tcp_get_timestamping_opt_stats()
4266 nla_put_u32(stats, TCP_NLA_REORDERING, tp->reordering); in tcp_get_timestamping_opt_stats()
4269 nla_put_u8(stats, TCP_NLA_RECUR_RETRANS, inet_csk(sk)->icsk_retransmits); in tcp_get_timestamping_opt_stats()
4270 nla_put_u8(stats, TCP_NLA_DELIVERY_RATE_APP_LMT, !!tp->rate_app_limited); in tcp_get_timestamping_opt_stats()
4271 nla_put_u32(stats, TCP_NLA_SND_SSTHRESH, tp->snd_ssthresh); in tcp_get_timestamping_opt_stats()
4272 nla_put_u32(stats, TCP_NLA_DELIVERED, tp->delivered); in tcp_get_timestamping_opt_stats()
4273 nla_put_u32(stats, TCP_NLA_DELIVERED_CE, tp->delivered_ce); in tcp_get_timestamping_opt_stats()
4275 nla_put_u32(stats, TCP_NLA_SNDQ_SIZE, tp->write_seq - tp->snd_una); in tcp_get_timestamping_opt_stats()
4276 nla_put_u8(stats, TCP_NLA_CA_STATE, inet_csk(sk)->icsk_ca_state); in tcp_get_timestamping_opt_stats()
4278 nla_put_u64_64bit(stats, TCP_NLA_BYTES_SENT, tp->bytes_sent, in tcp_get_timestamping_opt_stats()
4280 nla_put_u64_64bit(stats, TCP_NLA_BYTES_RETRANS, tp->bytes_retrans, in tcp_get_timestamping_opt_stats()
4282 nla_put_u32(stats, TCP_NLA_DSACK_DUPS, tp->dsack_dups); in tcp_get_timestamping_opt_stats()
4283 nla_put_u32(stats, TCP_NLA_REORD_SEEN, tp->reord_seen); in tcp_get_timestamping_opt_stats()
4284 nla_put_u32(stats, TCP_NLA_SRTT, tp->srtt_us >> 3); in tcp_get_timestamping_opt_stats()
4285 nla_put_u16(stats, TCP_NLA_TIMEOUT_REHASH, tp->timeout_rehash); in tcp_get_timestamping_opt_stats()
4287 max_t(int, 0, tp->write_seq - tp->snd_nxt)); in tcp_get_timestamping_opt_stats()
4288 nla_put_u64_64bit(stats, TCP_NLA_EDT, orig_skb->skb_mstamp_ns, in tcp_get_timestamping_opt_stats()
4294 nla_put_u32(stats, TCP_NLA_REHASH, tp->plb_rehash + tp->timeout_rehash); in tcp_get_timestamping_opt_stats()
4307 return -EFAULT; in do_tcp_getsockopt()
4310 return -EINVAL; in do_tcp_getsockopt()
4316 val = tp->mss_cache; in do_tcp_getsockopt()
4317 if (tp->rx_opt.user_mss && in do_tcp_getsockopt()
4318 ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) in do_tcp_getsockopt()
4319 val = tp->rx_opt.user_mss; in do_tcp_getsockopt()
4320 if (tp->repair) in do_tcp_getsockopt()
4321 val = tp->rx_opt.mss_clamp; in do_tcp_getsockopt()
4324 val = !!(tp->nonagle&TCP_NAGLE_OFF); in do_tcp_getsockopt()
4327 val = !!(tp->nonagle&TCP_NAGLE_CORK); in do_tcp_getsockopt()
4339 val = READ_ONCE(icsk->icsk_syn_retries) ? : in do_tcp_getsockopt()
4340 READ_ONCE(net->ipv4.sysctl_tcp_syn_retries); in do_tcp_getsockopt()
4343 val = READ_ONCE(tp->linger2); in do_tcp_getsockopt()
4345 val = (val ? : READ_ONCE(net->ipv4.sysctl_tcp_fin_timeout)) / HZ; in do_tcp_getsockopt()
4348 val = READ_ONCE(icsk->icsk_accept_queue.rskq_defer_accept); in do_tcp_getsockopt()
4353 val = READ_ONCE(tp->window_clamp); in do_tcp_getsockopt()
4359 return -EFAULT; in do_tcp_getsockopt()
4365 return -EFAULT; in do_tcp_getsockopt()
4367 return -EFAULT; in do_tcp_getsockopt()
4377 return -EFAULT; in do_tcp_getsockopt()
4379 ca_ops = icsk->icsk_ca_ops; in do_tcp_getsockopt()
4380 if (ca_ops && ca_ops->get_info) in do_tcp_getsockopt()
4381 sz = ca_ops->get_info(sk, ~0U, &attr, &info); in do_tcp_getsockopt()
4385 return -EFAULT; in do_tcp_getsockopt()
4387 return -EFAULT; in do_tcp_getsockopt()
4396 return -EFAULT; in do_tcp_getsockopt()
4399 return -EFAULT; in do_tcp_getsockopt()
4400 if (copy_to_sockptr(optval, icsk->icsk_ca_ops->name, len)) in do_tcp_getsockopt()
4401 return -EFAULT; in do_tcp_getsockopt()
4406 return -EFAULT; in do_tcp_getsockopt()
4408 if (!icsk->icsk_ulp_ops) { in do_tcp_getsockopt()
4411 return -EFAULT; in do_tcp_getsockopt()
4415 return -EFAULT; in do_tcp_getsockopt()
4416 if (copy_to_sockptr(optval, icsk->icsk_ulp_ops->name, len)) in do_tcp_getsockopt()
4417 return -EFAULT; in do_tcp_getsockopt()
4425 return -EFAULT; in do_tcp_getsockopt()
4431 return -EFAULT; in do_tcp_getsockopt()
4433 return -EFAULT; in do_tcp_getsockopt()
4437 val = tp->thin_lto; in do_tcp_getsockopt()
4445 val = tp->repair; in do_tcp_getsockopt()
4449 if (tp->repair) in do_tcp_getsockopt()
4450 val = tp->repair_queue; in do_tcp_getsockopt()
4452 return -EINVAL; in do_tcp_getsockopt()
4459 return -EFAULT; in do_tcp_getsockopt()
4462 return -EINVAL; in do_tcp_getsockopt()
4464 if (!tp->repair) in do_tcp_getsockopt()
4465 return -EPERM; in do_tcp_getsockopt()
4467 opt.snd_wl1 = tp->snd_wl1; in do_tcp_getsockopt()
4468 opt.snd_wnd = tp->snd_wnd; in do_tcp_getsockopt()
4469 opt.max_window = tp->max_window; in do_tcp_getsockopt()
4470 opt.rcv_wnd = tp->rcv_wnd; in do_tcp_getsockopt()
4471 opt.rcv_wup = tp->rcv_wup; in do_tcp_getsockopt()
4474 return -EFAULT; in do_tcp_getsockopt()
4478 if (tp->repair_queue == TCP_SEND_QUEUE) in do_tcp_getsockopt()
4479 val = tp->write_seq; in do_tcp_getsockopt()
4480 else if (tp->repair_queue == TCP_RECV_QUEUE) in do_tcp_getsockopt()
4481 val = tp->rcv_nxt; in do_tcp_getsockopt()
4483 return -EINVAL; in do_tcp_getsockopt()
4487 val = READ_ONCE(icsk->icsk_user_timeout); in do_tcp_getsockopt()
4491 val = READ_ONCE(icsk->icsk_accept_queue.fastopenq.max_qlen); in do_tcp_getsockopt()
4495 val = tp->fastopen_connect; in do_tcp_getsockopt()
4499 val = tp->fastopen_no_cookie; in do_tcp_getsockopt()
4503 val = READ_ONCE(tp->tcp_tx_delay); in do_tcp_getsockopt()
4507 val = tcp_clock_ts(tp->tcp_usec_ts) + READ_ONCE(tp->tsoffset); in do_tcp_getsockopt()
4508 if (tp->tcp_usec_ts) in do_tcp_getsockopt()
4514 val = READ_ONCE(tp->notsent_lowat); in do_tcp_getsockopt()
4517 val = tp->recvmsg_inq; in do_tcp_getsockopt()
4520 val = tp->save_syn; in do_tcp_getsockopt()
4524 return -EFAULT; in do_tcp_getsockopt()
4527 if (tp->saved_syn) { in do_tcp_getsockopt()
4528 if (len < tcp_saved_syn_len(tp->saved_syn)) { in do_tcp_getsockopt()
4529 len = tcp_saved_syn_len(tp->saved_syn); in do_tcp_getsockopt()
4532 return -EFAULT; in do_tcp_getsockopt()
4535 return -EINVAL; in do_tcp_getsockopt()
4537 len = tcp_saved_syn_len(tp->saved_syn); in do_tcp_getsockopt()
4540 return -EFAULT; in do_tcp_getsockopt()
4542 if (copy_to_sockptr(optval, tp->saved_syn->data, len)) { in do_tcp_getsockopt()
4544 return -EFAULT; in do_tcp_getsockopt()
4552 return -EFAULT; in do_tcp_getsockopt()
4563 return -EFAULT; in do_tcp_getsockopt()
4566 return -EINVAL; in do_tcp_getsockopt()
4569 len - sizeof(zc)); in do_tcp_getsockopt()
4571 return err == 0 ? -EINVAL : err; in do_tcp_getsockopt()
4574 return -EFAULT; in do_tcp_getsockopt()
4577 return -EFAULT; in do_tcp_getsockopt()
4579 return -EINVAL; in do_tcp_getsockopt()
4581 return -EINVAL; in do_tcp_getsockopt()
4617 err = -EFAULT; in do_tcp_getsockopt()
4623 return -EPERM; in do_tcp_getsockopt()
4642 return -ENOPROTOOPT; in do_tcp_getsockopt()
4646 return -EFAULT; in do_tcp_getsockopt()
4648 return -EFAULT; in do_tcp_getsockopt()
4671 return READ_ONCE(icsk->icsk_af_ops)->getsockopt(sk, level, optname, in tcp_getsockopt()
4679 int tcp_md5_sigpool_id = -1;
4691 * id would stay the same. Re-write the id only for the case in tcp_md5_alloc_sigpool()
4715 u8 keylen = READ_ONCE(key->keylen); /* paired with WRITE_ONCE() in tcp_md5_do_add */ in tcp_md5_hash_key()
4718 sg_init_one(&sg, key->key, keylen); in tcp_md5_hash_key()
4719 ahash_request_set_crypt(hp->req, &sg, NULL, keylen); in tcp_md5_hash_key()
4722 * key->key under us in tcp_md5_hash_key()
4724 return data_race(crypto_ahash_update(hp->req)); in tcp_md5_hash_key()
4734 /* This gets called for each TCP segment that has TCP-MD5 option. in tcp_inbound_md5_hash()
4755 * IPv4-mapped case. in tcp_inbound_md5_hash()
4760 genhash = tp->af_specific->calc_md5_hash(newhash, key, in tcp_inbound_md5_hash()
4803 keyid = aoh->keyid; in tcp_inbound_hash()
4804 rnext = aoh->rnext_keyid; in tcp_inbound_hash()
4823 /* Drop if there's TCP-MD5 or TCP-AO key with any rcvid/sndid in tcp_inbound_hash()
4824 * for the remote peer. On TCP-AO established connection in tcp_inbound_hash()
4856 req = rcu_dereference_protected(tcp_sk(sk)->fastopen_rsk, 1); in tcp_done()
4858 if (sk->sk_state == TCP_SYN_SENT || sk->sk_state == TCP_SYN_RECV) in tcp_done()
4866 WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK); in tcp_done()
4869 sk->sk_state_change(sk); in tcp_done()
4883 inet_csk_reqsk_queue_drop(req->rsk_listener, req); in tcp_abort()
4890 refcount_inc(&tw->tw_refcnt); in tcp_abort()
4903 if (sk->sk_state == TCP_CLOSE) { in tcp_abort()
4906 return -ENOENT; in tcp_abort()
4909 if (sk->sk_state == TCP_LISTEN) { in tcp_abort()
4918 if (tcp_need_reset(sk->sk_state)) in tcp_abort()
4961 /* TX read-mostly hotpath cache lines */ in tcp_struct_check()
4971 /* TXRX read-mostly hotpath cache lines */ in tcp_struct_check()
4982 /* RX read-mostly hotpath cache lines */ in tcp_struct_check()
4997 /* TX read-write hotpath cache lines */ in tcp_struct_check()
5015 /* TXRX read-write hotpath cache lines */ in tcp_struct_check()
5037 /* RX read-write hotpath cache lines */ in tcp_struct_check()
5133 /* Set per-socket limits to no more than 1/128 the pressure threshold */ in tcp_init()
5134 limit = nr_free_buffer_pages() << (PAGE_SHIFT - 7); in tcp_init()