From patchwork Tue May 17 08:10:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852074 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEDBCC433EF for ; Tue, 17 May 2022 08:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242564AbiEQIMC (ORCPT ); Tue, 17 May 2022 04:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242527AbiEQILy (ORCPT ); Tue, 17 May 2022 04:11:54 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71DC33CA57; Tue, 17 May 2022 01:11:52 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id 137so16301845pgb.5; Tue, 17 May 2022 01:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qSi6S3M6hUob0GWOOxB6gDONEJlCHyD3XkZQid/wuws=; b=PMnJNleIpy37YTNvv5ff7xIrlmIxC3I4r5UL0n9mbXd2I1iIDfvpW5Ie7iHnK9crXW 6dx+nzX1t1uau5q5Zz7+Q4BM6r9xItM1ZaPocRDr8HNrWDN297aa/D/5HEqTcwQmU8aX 9qcYd7zfsEkog2ex4UPchekWPL6cz66vF6xHkLe0Gl9uLer/WtqJFlG3884WtUX6Hd6h d8F1hTVcoCIG6wJNVKCWVa85GN5lLcr3y6T2kHLWJcy4qO49HMR5uXHk8Hc5wOaz8gh9 1L05h9wgz1sYZ3iqdz5oLacwvnHBNdVMTZXrcal8OTOR8vFnv/6EgTlhb+3s6hZ4cVFS ykbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qSi6S3M6hUob0GWOOxB6gDONEJlCHyD3XkZQid/wuws=; b=VX9AgDuaoN153LKjEqd0obz4AnVZZebShnYErqOeH3Lf4AJppIDkkhg6dCSfFaxIwz EhF4FE2nCiZIio7c7ZLdpLt6CRQyT274DwdkLg1NZ708MsIPsdcfyQCzsZxj/bt6k5zN Ks2JNTUlLACcgbz56x65SXIVF6WNJ6VoPjb/Dt+aRXtk9RZ/j4BdNGVAiVZRw0MYjzdS Sirhe2OXY56L+Ja20aKGhoTSqyIjWeyd81N6r6M8bKhVp7wBAjXrHg7WChW5ma4MGZqd leFb0yJ5JYP+xxKOrXbL0AMkidqfcUTOYr5ObtCx58SF9tkLTzrbRir1mlTE9Dxp/IDt GDrA== X-Gm-Message-State: AOAM5327MlX5oTpuJplFHbfXFYd4XsR/3innzAJApPPhnyKr4Yl8aTxC jJWS+qXsxCqQVQQW1xx9T/A= X-Google-Smtp-Source: ABdhPJzEo8O0t9RSZnIyikzKdNI7TQcKYq6sorCBI1gr2QXrUxMZZx/KomUpwIv62aJhKLSjnPRu+g== X-Received: by 2002:a63:d145:0:b0:3c1:4ba0:d890 with SMTP id c5-20020a63d145000000b003c14ba0d890mr18495572pgj.607.1652775111671; Tue, 17 May 2022 01:11:51 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:11:51 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 1/9] net: skb: introduce __DEFINE_SKB_DROP_REASON() to simply the code Date: Tue, 17 May 2022 16:10:00 +0800 Message-Id: <20220517081008.294325-2-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong It is annoying to add new skb drop reasons to 'enum skb_drop_reason' and TRACE_SKB_DROP_REASON in trace/event/skb.h, and it's easy to forget to add the new reasons we added to TRACE_SKB_DROP_REASON. TRACE_SKB_DROP_REASON is used to convert drop reason of type number to string. For now, the string we passed to user space is exactly the same as the name in 'enum skb_drop_reason' with a 'SKB_DROP_REASON_' prefix. So why not make them togather by define a macro? Therefore, introduce __DEFINE_SKB_DROP_REASON() and use it for 'enum skb_drop_reason' definition and string converting. Now, what should we with the document for the reasons? How about follow __BPF_FUNC_MAPPER() and make these document togather? Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 444 ++++++++++++++++++++++++------------- include/trace/events/skb.h | 89 +------- net/core/drop_monitor.c | 13 -- net/core/skbuff.c | 10 + 4 files changed, 297 insertions(+), 259 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 4db3f4a33580..dfc568844df2 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -337,169 +337,295 @@ struct sk_buff_head { struct sk_buff; +/* + * SKB_DROP_REASON_NOT_SPECIFIED + * drop reason is not specified + * + * SKB_DROP_REASON_NO_SOCKET + * socket not found + * + * SKB_DROP_REASON_PKT_TOO_SMALL + * packet size is too small + * + * SKB_DROP_REASON_TCP_CSUM + * TCP checksum error + * + * SKB_DROP_REASON_SOCKET_FILTER + * dropped by socket filter + * + * SKB_DROP_REASON_UDP_CSUM + * UDP checksum error + * + * SKB_DROP_REASON_NETFILTER_DROP + * dropped by netfilter + * + * SKB_DROP_REASON_OTHERHOST + * packet don't belong to current host (interface is in promisc + * mode) + * + * SKB_DROP_REASON_IP_CSUM + * IP checksum error + * + * SKB_DROP_REASON_IP_INHDR + * there is something wrong with IP header (see + * IPSTATS_MIB_INHDRERRORS) + * + * SKB_DROP_REASON_IP_RPFILTER + * IP rpfilter validate failed. see the document for rp_filter + * in ip-sysctl.rst for more information + * + * SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST + * destination address of L2 is multicast, but L3 is unicast. + * + * SKB_DROP_REASON_XFRM_POLICY + * xfrm policy check failed + * + * SKB_DROP_REASON_IP_NOPROTO + * no support for IP protocol + * + * SKB_DROP_REASON_SOCKET_RCVBUFF + * socket receive buff is full + * + * SKB_DROP_REASON_PROTO_MEM + * proto memory limition, such as udp packet drop out of + * udp_memory_allocated. + * + * SKB_DROP_REASON_TCP_MD5NOTFOUND + * no MD5 hash and one expected, corresponding to + * LINUX_MIB_TCPMD5NOTFOUND + * + * SKB_DROP_REASON_TCP_MD5UNEXPECTED + * MD5 hash and we're not expecting one, corresponding to + * LINUX_MIB_TCPMD5UNEXPECTED + * + * SKB_DROP_REASON_TCP_MD5FAILURE + * MD5 hash and its wrong, corresponding to LINUX_MIB_TCPMD5FAILURE + * + * SKB_DROP_REASON_SOCKET_BACKLOG + * failed to add skb to socket backlog (see LINUX_MIB_TCPBACKLOGDROP) + * + * SKB_DROP_REASON_TCP_FLAGS + * TCP flags invalid + * + * SKB_DROP_REASON_TCP_ZEROWINDOW + * TCP receive window size is zero, see LINUX_MIB_TCPZEROWINDOWDROP + * + * SKB_DROP_REASON_TCP_OLD_DATA + * the TCP data reveived is already received before (spurious + * retrans may happened), see LINUX_MIB_DELAYEDACKLOST + * + * SKB_DROP_REASON_TCP_OVERWINDOW + * the TCP data is out of window, the seq of the first byte exceed + * the right edges of receive window + * + * SKB_DROP_REASON_TCP_OFOMERGE + * the data of skb is already in the ofo queue, corresponding to + * LINUX_MIB_TCPOFOMERGE + * + * SKB_DROP_REASON_TCP_RFC7323_PAWS + * PAWS check, corresponding to LINUX_MIB_PAWSESTABREJECTED + * + * SKB_DROP_REASON_TCP_INVALID_SEQUENCE + * Not acceptable SEQ field + * + * SKB_DROP_REASON_TCP_RESET + * Invalid RST packet + * + * SKB_DROP_REASON_TCP_INVALID_SYN + * Incoming packet has unexpected SYN flag + * + * SKB_DROP_REASON_TCP_CLOSE + * TCP socket in CLOSE state + * + * SKB_DROP_REASON_TCP_FASTOPEN + * dropped by FASTOPEN request socket + * + * SKB_DROP_REASON_TCP_OLD_ACK + * TCP ACK is old, but in window + * + * SKB_DROP_REASON_TCP_TOO_OLD_ACK + * TCP ACK is too old + * + * SKB_DROP_REASON_TCP_ACK_UNSENT_DATA + * TCP ACK for data we haven't sent yet + * + * SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE + * pruned from TCP OFO queue + * + * SKB_DROP_REASON_TCP_OFO_DROP + * data already in receive queue + * + * SKB_DROP_REASON_IP_OUTNOROUTES + * route lookup failed + * + * SKB_DROP_REASON_BPF_CGROUP_EGRESS + * dropped by BPF_PROG_TYPE_CGROUP_SKB eBPF program + * + * SKB_DROP_REASON_IPV6DISABLED + * IPv6 is disabled on the device + * + * SKB_DROP_REASON_NEIGH_CREATEFAIL + * failed to create neigh entry + * + * SKB_DROP_REASON_NEIGH_FAILED + * neigh entry in failed state + * + * SKB_DROP_REASON_NEIGH_QUEUEFULL + * arp_queue for neigh entry is full + * + * SKB_DROP_REASON_NEIGH_DEAD + * neigh entry is dead + * + * SKB_DROP_REASON_TC_EGRESS + * dropped in TC egress HOOK + * + * SKB_DROP_REASON_QDISC_DROP + * dropped by qdisc when packet outputting (failed to enqueue to + * current qdisc) + * + * SKB_DROP_REASON_CPU_BACKLOG + * failed to enqueue the skb to the per CPU backlog queue. This + * can be caused by backlog queue full (see netdev_max_backlog in + * net.rst) or RPS flow limit + * + * SKB_DROP_REASON_XDP + * dropped by XDP in input path + * + * SKB_DROP_REASON_TC_INGRESS + * dropped in TC ingress HOOK + * + * SKB_DROP_REASON_UNHANDLED_PROTO + * protocol not implemented or not supported + * + * SKB_DROP_REASON_SKB_CSUM + * sk_buff checksum computation error + * + * SKB_DROP_REASON_SKB_GSO_SEG + * gso segmentation error + * + * SKB_DROP_REASON_SKB_UCOPY_FAULT + * failed to copy data from user space, e.g., via + * zerocopy_sg_from_iter() or skb_orphan_frags_rx() + * + * SKB_DROP_REASON_DEV_HDR + * device driver specific header/metadata is invalid + * + * SKB_DROP_REASON_DEV_READY + * the device is not ready to xmit/recv due to any of its data + * structure that is not up/ready/initialized, e.g., the IFF_UP is + * not set, or driver specific tun->tfiles[txq] is not initialized + * + * SKB_DROP_REASON_FULL_RING + * ring buffer is full + * + * SKB_DROP_REASON_NOMEM + * error due to OOM + * + * SKB_DROP_REASON_HDR_TRUNC + * failed to trunc/extract the header from networking data, e.g., + * failed to pull the protocol header from frags via + * pskb_may_pull() + * + * SKB_DROP_REASON_TAP_FILTER + * dropped by (ebpf) filter directly attached to tun/tap, e.g., via + * TUNSETFILTEREBPF + * + * SKB_DROP_REASON_TAP_TXFILTER + * dropped by tx filter implemented at tun/tap, e.g., check_filter() + * + * SKB_DROP_REASON_ICMP_CSUM + * ICMP checksum error + * + * SKB_DROP_REASON_INVALID_PROTO + * the packet doesn't follow RFC 2211, such as a broadcasts + * ICMP_TIMESTAMP + * + * SKB_DROP_REASON_IP_INADDRERRORS + * host unreachable, corresponding to IPSTATS_MIB_INADDRERRORS + * + * SKB_DROP_REASON_IP_INNOROUTES + * network unreachable, corresponding to IPSTATS_MIB_INADDRERRORS + * + * SKB_DROP_REASON_PKT_TOO_BIG + * packet size is too big (maybe exceed the MTU) + */ +#define __DEFINE_SKB_DROP_REASON(FN) \ + FN(NOT_SPECIFIED) \ + FN(NO_SOCKET) \ + FN(PKT_TOO_SMALL) \ + FN(TCP_CSUM) \ + FN(SOCKET_FILTER) \ + FN(UDP_CSUM) \ + FN(NETFILTER_DROP) \ + FN(OTHERHOST) \ + FN(IP_CSUM) \ + FN(IP_INHDR) \ + FN(IP_RPFILTER) \ + FN(UNICAST_IN_L2_MULTICAST) \ + FN(XFRM_POLICY) \ + FN(IP_NOPROTO) \ + FN(SOCKET_RCVBUFF) \ + FN(PROTO_MEM) \ + FN(TCP_MD5NOTFOUND) \ + FN(TCP_MD5UNEXPECTED) \ + FN(TCP_MD5FAILURE) \ + FN(SOCKET_BACKLOG) \ + FN(TCP_FLAGS) \ + FN(TCP_ZEROWINDOW) \ + FN(TCP_OLD_DATA) \ + FN(TCP_OVERWINDOW) \ + FN(TCP_OFOMERGE) \ + FN(TCP_RFC7323_PAWS) \ + FN(TCP_INVALID_SEQUENCE) \ + FN(TCP_RESET) \ + FN(TCP_INVALID_SYN) \ + FN(TCP_CLOSE) \ + FN(TCP_FASTOPEN) \ + FN(TCP_OLD_ACK) \ + FN(TCP_TOO_OLD_ACK) \ + FN(TCP_ACK_UNSENT_DATA) \ + FN(TCP_OFO_QUEUE_PRUNE) \ + FN(TCP_OFO_DROP) \ + FN(IP_OUTNOROUTES) \ + FN(BPF_CGROUP_EGRESS) \ + FN(IPV6DISABLED) \ + FN(NEIGH_CREATEFAIL) \ + FN(NEIGH_FAILED) \ + FN(NEIGH_QUEUEFULL) \ + FN(NEIGH_DEAD) \ + FN(TC_EGRESS) \ + FN(QDISC_DROP) \ + FN(CPU_BACKLOG) \ + FN(XDP) \ + FN(TC_INGRESS) \ + FN(UNHANDLED_PROTO) \ + FN(SKB_CSUM) \ + FN(SKB_GSO_SEG) \ + FN(SKB_UCOPY_FAULT) \ + FN(DEV_HDR) \ + FN(DEV_READY) \ + FN(FULL_RING) \ + FN(NOMEM) \ + FN(HDR_TRUNC) \ + FN(TAP_FILTER) \ + FN(TAP_TXFILTER) \ + FN(ICMP_CSUM) \ + FN(INVALID_PROTO) \ + FN(IP_INADDRERRORS) \ + FN(IP_INNOROUTES) \ + FN(PKT_TOO_BIG) \ + FN(MAX) + /* The reason of skb drop, which is used in kfree_skb_reason(). * en...maybe they should be splited by group? - * - * Each item here should also be in 'TRACE_SKB_DROP_REASON', which is - * used to translate the reason to string. */ enum skb_drop_reason { SKB_NOT_DROPPED_YET = 0, - SKB_DROP_REASON_NOT_SPECIFIED, /* drop reason is not specified */ - SKB_DROP_REASON_NO_SOCKET, /* socket not found */ - SKB_DROP_REASON_PKT_TOO_SMALL, /* packet size is too small */ - SKB_DROP_REASON_TCP_CSUM, /* TCP checksum error */ - SKB_DROP_REASON_SOCKET_FILTER, /* dropped by socket filter */ - SKB_DROP_REASON_UDP_CSUM, /* UDP checksum error */ - SKB_DROP_REASON_NETFILTER_DROP, /* dropped by netfilter */ - SKB_DROP_REASON_OTHERHOST, /* packet don't belong to current - * host (interface is in promisc - * mode) - */ - SKB_DROP_REASON_IP_CSUM, /* IP checksum error */ - SKB_DROP_REASON_IP_INHDR, /* there is something wrong with - * IP header (see - * IPSTATS_MIB_INHDRERRORS) - */ - SKB_DROP_REASON_IP_RPFILTER, /* IP rpfilter validate failed. - * see the document for rp_filter - * in ip-sysctl.rst for more - * information - */ - SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, /* destination address of L2 - * is multicast, but L3 is - * unicast. - */ - SKB_DROP_REASON_XFRM_POLICY, /* xfrm policy check failed */ - SKB_DROP_REASON_IP_NOPROTO, /* no support for IP protocol */ - SKB_DROP_REASON_SOCKET_RCVBUFF, /* socket receive buff is full */ - SKB_DROP_REASON_PROTO_MEM, /* proto memory limition, such as - * udp packet drop out of - * udp_memory_allocated. - */ - SKB_DROP_REASON_TCP_MD5NOTFOUND, /* no MD5 hash and one - * expected, corresponding - * to LINUX_MIB_TCPMD5NOTFOUND - */ - SKB_DROP_REASON_TCP_MD5UNEXPECTED, /* MD5 hash and we're not - * expecting one, corresponding - * to LINUX_MIB_TCPMD5UNEXPECTED - */ - SKB_DROP_REASON_TCP_MD5FAILURE, /* MD5 hash and its wrong, - * corresponding to - * LINUX_MIB_TCPMD5FAILURE - */ - SKB_DROP_REASON_SOCKET_BACKLOG, /* failed to add skb to socket - * backlog (see - * LINUX_MIB_TCPBACKLOGDROP) - */ - SKB_DROP_REASON_TCP_FLAGS, /* TCP flags invalid */ - SKB_DROP_REASON_TCP_ZEROWINDOW, /* TCP receive window size is zero, - * see LINUX_MIB_TCPZEROWINDOWDROP - */ - SKB_DROP_REASON_TCP_OLD_DATA, /* the TCP data reveived is already - * received before (spurious retrans - * may happened), see - * LINUX_MIB_DELAYEDACKLOST - */ - SKB_DROP_REASON_TCP_OVERWINDOW, /* the TCP data is out of window, - * the seq of the first byte exceed - * the right edges of receive - * window - */ - SKB_DROP_REASON_TCP_OFOMERGE, /* the data of skb is already in - * the ofo queue, corresponding to - * LINUX_MIB_TCPOFOMERGE - */ - SKB_DROP_REASON_TCP_RFC7323_PAWS, /* PAWS check, corresponding to - * LINUX_MIB_PAWSESTABREJECTED - */ - SKB_DROP_REASON_TCP_INVALID_SEQUENCE, /* Not acceptable SEQ field */ - SKB_DROP_REASON_TCP_RESET, /* Invalid RST packet */ - SKB_DROP_REASON_TCP_INVALID_SYN, /* Incoming packet has unexpected SYN flag */ - SKB_DROP_REASON_TCP_CLOSE, /* TCP socket in CLOSE state */ - SKB_DROP_REASON_TCP_FASTOPEN, /* dropped by FASTOPEN request socket */ - SKB_DROP_REASON_TCP_OLD_ACK, /* TCP ACK is old, but in window */ - SKB_DROP_REASON_TCP_TOO_OLD_ACK, /* TCP ACK is too old */ - SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, /* TCP ACK for data we haven't sent yet */ - SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE, /* pruned from TCP OFO queue */ - SKB_DROP_REASON_TCP_OFO_DROP, /* data already in receive queue */ - SKB_DROP_REASON_IP_OUTNOROUTES, /* route lookup failed */ - SKB_DROP_REASON_BPF_CGROUP_EGRESS, /* dropped by - * BPF_PROG_TYPE_CGROUP_SKB - * eBPF program - */ - SKB_DROP_REASON_IPV6DISABLED, /* IPv6 is disabled on the device */ - SKB_DROP_REASON_NEIGH_CREATEFAIL, /* failed to create neigh - * entry - */ - SKB_DROP_REASON_NEIGH_FAILED, /* neigh entry in failed state */ - SKB_DROP_REASON_NEIGH_QUEUEFULL, /* arp_queue for neigh - * entry is full - */ - SKB_DROP_REASON_NEIGH_DEAD, /* neigh entry is dead */ - SKB_DROP_REASON_TC_EGRESS, /* dropped in TC egress HOOK */ - SKB_DROP_REASON_QDISC_DROP, /* dropped by qdisc when packet - * outputting (failed to enqueue to - * current qdisc) - */ - SKB_DROP_REASON_CPU_BACKLOG, /* failed to enqueue the skb to - * the per CPU backlog queue. This - * can be caused by backlog queue - * full (see netdev_max_backlog in - * net.rst) or RPS flow limit - */ - SKB_DROP_REASON_XDP, /* dropped by XDP in input path */ - SKB_DROP_REASON_TC_INGRESS, /* dropped in TC ingress HOOK */ - SKB_DROP_REASON_UNHANDLED_PROTO, /* protocol not implemented - * or not supported - */ - SKB_DROP_REASON_SKB_CSUM, /* sk_buff checksum computation - * error - */ - SKB_DROP_REASON_SKB_GSO_SEG, /* gso segmentation error */ - SKB_DROP_REASON_SKB_UCOPY_FAULT, /* failed to copy data from - * user space, e.g., via - * zerocopy_sg_from_iter() - * or skb_orphan_frags_rx() - */ - SKB_DROP_REASON_DEV_HDR, /* device driver specific - * header/metadata is invalid - */ - /* the device is not ready to xmit/recv due to any of its data - * structure that is not up/ready/initialized, e.g., the IFF_UP is - * not set, or driver specific tun->tfiles[txq] is not initialized - */ - SKB_DROP_REASON_DEV_READY, - SKB_DROP_REASON_FULL_RING, /* ring buffer is full */ - SKB_DROP_REASON_NOMEM, /* error due to OOM */ - SKB_DROP_REASON_HDR_TRUNC, /* failed to trunc/extract the header - * from networking data, e.g., failed - * to pull the protocol header from - * frags via pskb_may_pull() - */ - SKB_DROP_REASON_TAP_FILTER, /* dropped by (ebpf) filter directly - * attached to tun/tap, e.g., via - * TUNSETFILTEREBPF - */ - SKB_DROP_REASON_TAP_TXFILTER, /* dropped by tx filter implemented - * at tun/tap, e.g., check_filter() - */ - SKB_DROP_REASON_ICMP_CSUM, /* ICMP checksum error */ - SKB_DROP_REASON_INVALID_PROTO, /* the packet doesn't follow RFC - * 2211, such as a broadcasts - * ICMP_TIMESTAMP - */ - SKB_DROP_REASON_IP_INADDRERRORS, /* host unreachable, corresponding - * to IPSTATS_MIB_INADDRERRORS - */ - SKB_DROP_REASON_IP_INNOROUTES, /* network unreachable, corresponding - * to IPSTATS_MIB_INADDRERRORS - */ - SKB_DROP_REASON_PKT_TOO_BIG, /* packet size is too big (maybe exceed - * the MTU) - */ - SKB_DROP_REASON_MAX, + +#undef FN +#define FN(name) SKB_DROP_REASON_##name, + __DEFINE_SKB_DROP_REASON(FN) +#undef FN }; #define SKB_DR_INIT(name, reason) \ @@ -515,6 +641,8 @@ enum skb_drop_reason { SKB_DR_SET(name, reason); \ } while (0) +extern const char * const drop_reasons[]; + /* To allow 64K frame to be packed as single skb without frag_list we * require 64K/PAGE_SIZE pages plus 1 additional page to allow for * buffers which do not start on a page boundary. diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index a477bf907498..45264e4bb254 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -9,92 +9,6 @@ #include #include -#define TRACE_SKB_DROP_REASON \ - EM(SKB_DROP_REASON_NOT_SPECIFIED, NOT_SPECIFIED) \ - EM(SKB_DROP_REASON_NO_SOCKET, NO_SOCKET) \ - EM(SKB_DROP_REASON_PKT_TOO_SMALL, PKT_TOO_SMALL) \ - EM(SKB_DROP_REASON_TCP_CSUM, TCP_CSUM) \ - EM(SKB_DROP_REASON_SOCKET_FILTER, SOCKET_FILTER) \ - EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ - EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP) \ - EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \ - EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \ - EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \ - EM(SKB_DROP_REASON_IP_RPFILTER, IP_RPFILTER) \ - EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, \ - UNICAST_IN_L2_MULTICAST) \ - EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY) \ - EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO) \ - EM(SKB_DROP_REASON_SOCKET_RCVBUFF, SOCKET_RCVBUFF) \ - EM(SKB_DROP_REASON_PROTO_MEM, PROTO_MEM) \ - EM(SKB_DROP_REASON_TCP_MD5NOTFOUND, TCP_MD5NOTFOUND) \ - EM(SKB_DROP_REASON_TCP_MD5UNEXPECTED, \ - TCP_MD5UNEXPECTED) \ - EM(SKB_DROP_REASON_TCP_MD5FAILURE, TCP_MD5FAILURE) \ - EM(SKB_DROP_REASON_SOCKET_BACKLOG, SOCKET_BACKLOG) \ - EM(SKB_DROP_REASON_TCP_FLAGS, TCP_FLAGS) \ - EM(SKB_DROP_REASON_TCP_ZEROWINDOW, TCP_ZEROWINDOW) \ - EM(SKB_DROP_REASON_TCP_OLD_DATA, TCP_OLD_DATA) \ - EM(SKB_DROP_REASON_TCP_OVERWINDOW, TCP_OVERWINDOW) \ - EM(SKB_DROP_REASON_TCP_OFOMERGE, TCP_OFOMERGE) \ - EM(SKB_DROP_REASON_TCP_OFO_DROP, TCP_OFO_DROP) \ - EM(SKB_DROP_REASON_TCP_RFC7323_PAWS, TCP_RFC7323_PAWS) \ - EM(SKB_DROP_REASON_TCP_INVALID_SEQUENCE, \ - TCP_INVALID_SEQUENCE) \ - EM(SKB_DROP_REASON_TCP_RESET, TCP_RESET) \ - EM(SKB_DROP_REASON_TCP_INVALID_SYN, TCP_INVALID_SYN) \ - EM(SKB_DROP_REASON_TCP_CLOSE, TCP_CLOSE) \ - EM(SKB_DROP_REASON_TCP_FASTOPEN, TCP_FASTOPEN) \ - EM(SKB_DROP_REASON_TCP_OLD_ACK, TCP_OLD_ACK) \ - EM(SKB_DROP_REASON_TCP_TOO_OLD_ACK, TCP_TOO_OLD_ACK) \ - EM(SKB_DROP_REASON_TCP_ACK_UNSENT_DATA, \ - TCP_ACK_UNSENT_DATA) \ - EM(SKB_DROP_REASON_TCP_OFO_QUEUE_PRUNE, \ - TCP_OFO_QUEUE_PRUNE) \ - EM(SKB_DROP_REASON_IP_OUTNOROUTES, IP_OUTNOROUTES) \ - EM(SKB_DROP_REASON_BPF_CGROUP_EGRESS, \ - BPF_CGROUP_EGRESS) \ - EM(SKB_DROP_REASON_IPV6DISABLED, IPV6DISABLED) \ - EM(SKB_DROP_REASON_NEIGH_CREATEFAIL, NEIGH_CREATEFAIL) \ - EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \ - EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \ - EM(SKB_DROP_REASON_NEIGH_DEAD, NEIGH_DEAD) \ - EM(SKB_DROP_REASON_TC_EGRESS, TC_EGRESS) \ - EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \ - EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \ - EM(SKB_DROP_REASON_XDP, XDP) \ - EM(SKB_DROP_REASON_TC_INGRESS, TC_INGRESS) \ - EM(SKB_DROP_REASON_UNHANDLED_PROTO, UNHANDLED_PROTO) \ - EM(SKB_DROP_REASON_SKB_CSUM, SKB_CSUM) \ - EM(SKB_DROP_REASON_SKB_GSO_SEG, SKB_GSO_SEG) \ - EM(SKB_DROP_REASON_SKB_UCOPY_FAULT, SKB_UCOPY_FAULT) \ - EM(SKB_DROP_REASON_DEV_HDR, DEV_HDR) \ - EM(SKB_DROP_REASON_DEV_READY, DEV_READY) \ - EM(SKB_DROP_REASON_FULL_RING, FULL_RING) \ - EM(SKB_DROP_REASON_NOMEM, NOMEM) \ - EM(SKB_DROP_REASON_HDR_TRUNC, HDR_TRUNC) \ - EM(SKB_DROP_REASON_TAP_FILTER, TAP_FILTER) \ - EM(SKB_DROP_REASON_TAP_TXFILTER, TAP_TXFILTER) \ - EM(SKB_DROP_REASON_ICMP_CSUM, ICMP_CSUM) \ - EM(SKB_DROP_REASON_INVALID_PROTO, INVALID_PROTO) \ - EM(SKB_DROP_REASON_IP_INADDRERRORS, IP_INADDRERRORS) \ - EM(SKB_DROP_REASON_IP_INNOROUTES, IP_INNOROUTES) \ - EM(SKB_DROP_REASON_PKT_TOO_BIG, PKT_TOO_BIG) \ - EMe(SKB_DROP_REASON_MAX, MAX) - -#undef EM -#undef EMe - -#define EM(a, b) TRACE_DEFINE_ENUM(a); -#define EMe(a, b) TRACE_DEFINE_ENUM(a); - -TRACE_SKB_DROP_REASON - -#undef EM -#undef EMe -#define EM(a, b) { a, #b }, -#define EMe(a, b) { a, #b } - /* * Tracepoint for free an sk_buff: */ @@ -121,8 +35,7 @@ TRACE_EVENT(kfree_skb, TP_printk("skbaddr=%p protocol=%u location=%p reason: %s", __entry->skbaddr, __entry->protocol, __entry->location, - __print_symbolic(__entry->reason, - TRACE_SKB_DROP_REASON)) + drop_reasons[__entry->reason]) ); TRACE_EVENT(consume_skb, diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index 41cac0e4834e..4ad1decce724 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c @@ -48,19 +48,6 @@ static int trace_state = TRACE_OFF; static bool monitor_hw; -#undef EM -#undef EMe - -#define EM(a, b) [a] = #b, -#define EMe(a, b) [a] = #b - -/* drop_reasons is used to translate 'enum skb_drop_reason' to string, - * which is reported to user space. - */ -static const char * const drop_reasons[] = { - TRACE_SKB_DROP_REASON -}; - /* net_dm_mutex * * An overall lock guarding every operation coming from userspace. diff --git a/net/core/skbuff.c b/net/core/skbuff.c index fab791b0c59e..e677c052b459 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -90,6 +90,16 @@ static struct kmem_cache *skbuff_ext_cache __ro_after_init; int sysctl_max_skb_frags __read_mostly = MAX_SKB_FRAGS; EXPORT_SYMBOL(sysctl_max_skb_frags); +/* drop_reasons is used to translate 'enum skb_drop_reason' to string, + * which is reported to user space. + */ +const char * const drop_reasons[] = { +#undef FN +#define FN(name) [SKB_DROP_REASON_##name] = #name, + __DEFINE_SKB_DROP_REASON(FN) +#undef FN +}; + /** * skb_panic - private function for out-of-line support * @skb: buffer From patchwork Tue May 17 08:10:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852073 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D3B8C4332F for ; Tue, 17 May 2022 08:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242542AbiEQIL7 (ORCPT ); Tue, 17 May 2022 04:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242895AbiEQIL5 (ORCPT ); Tue, 17 May 2022 04:11:57 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83D603CA57; Tue, 17 May 2022 01:11:56 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id w200so337252pfc.10; Tue, 17 May 2022 01:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PFUmdFHadjVSWKgDGHvFdEqXwH0fA/y0X+v/6NyB02o=; b=SC/hukbpWW+a5yMv8Ch5Ltq/54B7Mk7Iu1ukbh1d7rHYnYYhrB6da5wxfRnd2pPA4g z4tFRZp99sljMCjD3eEIwdnFo34IriXuZ7hDrmIePOlhabDDw2e6QacyA5IMdiq7LlLO LFFhsaQh3mSZ3Vq+IIP17m9m+M8JOPaBFx0GdXC3lgzoSbjzgQuXT/OI8hSy6XRz8Pmp nqu29qV61LkwpbeUHCs2ygbuRPuLfz2n/0o5lefGEW8Yl6c4vRYsyYKgbAwL1xzdlrKT CwP6DIjokwTmmhsZpLx2Vv0f2miFFutRTVtWI46daf2MA+bzBI2ITdJP0vLopRos2yBX I92A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PFUmdFHadjVSWKgDGHvFdEqXwH0fA/y0X+v/6NyB02o=; b=3G/+GhEoB/5csZ+VHJF7GuaCocNPctJnN3mn3FxgSr6le/Qp3hx6Gy8sEYoUvj7R7x 92tOkzG892cwo4bb9pMrXMp2aCmXlZn3TAjvtOljQD1Q8vGi8TVq+lTc3Sql5ixdkbYk e9TBxDTC9WSBpcMV2EkGKmgHA7WDe5GTXOZ80IA9OXEeR5FgNVzGz0uQUQ4TL1UY22Uh sbabHBw/jXzUnUazlMrR6wj5Uku4GSnLFZMrj0BrIKkQklm1glcz17w1+RNvayIdVmyy uh0dV1peF5mSphpBGxWW6JmXMSO+WL2KAEBaxA88v8Ww8cACE9aDCyHL2C+BX3rpibGF HSKg== X-Gm-Message-State: AOAM530M8kK8JyeFwKnqrgb0ApZ3cEzCOBquEfVxkalGCOAszLXtIMuT yQPBAOyoupYg9wTD/5EPj68= X-Google-Smtp-Source: ABdhPJyjWuQLM53tDQ80cZZXhrYJPrAkc/zBQyq0h4cTnU147xlc7UBjKuawyMF2GNTSOBSc1HbyVA== X-Received: by 2002:a63:2b0b:0:b0:39d:890a:ab68 with SMTP id r11-20020a632b0b000000b0039d890aab68mr18266378pgr.247.1652775116105; Tue, 17 May 2022 01:11:56 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:11:55 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 2/9] net: skb: introduce __skb_queue_purge_reason() Date: Tue, 17 May 2022 16:10:01 +0800 Message-Id: <20220517081008.294325-3-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Introduce __skb_queue_purge_reason() to empty a skb list with drop reason and make __skb_queue_purge() an inline call to it. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index dfc568844df2..e9659a63961a 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3323,18 +3323,24 @@ static inline int skb_orphan_frags_rx(struct sk_buff *skb, gfp_t gfp_mask) } /** - * __skb_queue_purge - empty a list + * __skb_queue_purge_reason - empty a list with specific drop reason * @list: list to empty + * @reason: drop reason * * Delete all buffers on an &sk_buff list. Each buffer is removed from * the list and one reference dropped. This function does not take the * list lock and the caller must hold the relevant locks to use it. */ -static inline void __skb_queue_purge(struct sk_buff_head *list) +static inline void __skb_queue_purge_reason(struct sk_buff_head *list, + enum skb_drop_reason reason) { struct sk_buff *skb; while ((skb = __skb_dequeue(list)) != NULL) - kfree_skb(skb); + kfree_skb_reason(skb, reason); +} +static inline void __skb_queue_purge(struct sk_buff_head *list) +{ + __skb_queue_purge_reason(list, SKB_DROP_REASON_NOT_SPECIFIED); } void skb_queue_purge(struct sk_buff_head *list); From patchwork Tue May 17 08:10:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852076 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4187CC433F5 for ; Tue, 17 May 2022 08:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238956AbiEQIMI (ORCPT ); Tue, 17 May 2022 04:12:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242560AbiEQIMC (ORCPT ); Tue, 17 May 2022 04:12:02 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D88A93CA63; Tue, 17 May 2022 01:12:00 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id l11so16284541pgt.13; Tue, 17 May 2022 01:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g1ch9JUquSiEZY3rT3hSUX6ygAPZRU7aK66mWZEBfMc=; b=l677yDNNh9wM4HRRDrc8fmNazcJaTtnExXMIiStTblbYqswMP/1Yb4icbI8+x6S15N 8i5htd0voQ8OGBSg6AMUd22fcJPWmLrl2z4/pMWE6eadWgvUVoto7ispzDPdwEEmwp9L YwrscQlwAPckHiJJD/iV1Ri17RUSmarPkYhWzUceEZlvJ//h/uzoEPIBCSo73v3b0I8F hmX1mtUkLnMK9Pzf+9jq6wrBb06BqBJfYiW9GVbc8lBZVC2AHkrH3PXMKSQ3Y4erDCiJ Trt5W6P5AT84DMeSRdS0BWFM20ol1VnXOOMNacOTjBaO8bGFNkEgx6yABSljQ55sTXbl wS8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g1ch9JUquSiEZY3rT3hSUX6ygAPZRU7aK66mWZEBfMc=; b=MNPfE2Lifm/J1ocRPiYEZ5Ti5B/DoavjzALGoliK5R4oibrKUGm5ZkbzclmepiNxVN ky7yT3Rv88sT6OxOAa9InFD7bZigKUCc/8M7699D6JzT4NbIz519cZgrsg6UpYIQDZ2S XxgWEvRCY4O8M5cf87QUOSXPJ73Zg53lGa9CHAcj1VJEKrqBUdGvxusb8krPBmz6iRUt zj9huwyN3wDXq2oZP7xXkF/4Qu93TCXzI1MnD8ogXO2fsacIA1Utk2h3P+Ymy6nVWHNk 4W1U0uA8HJAlqkibCuhEWhKzUrWGSuAFwjgRgiALltTLGFpxPpdlFfT9xcOm1nVkmmeN RyUg== X-Gm-Message-State: AOAM533i/2kdeGCqosaS59uD8Q6vum7hphLzvn4Q7cdu1uoAEUgEeXOa n3OzFU3YOheW+1IT5+lXwSE= X-Google-Smtp-Source: ABdhPJz2PsC+b5mYRzZkRLbT7AMmFLF8v2YXPSNob5tFcH88kb+tlwa9H+e9nMX8+cwevoL0ITO5yw== X-Received: by 2002:a65:6b8a:0:b0:3db:7dc5:fec2 with SMTP id d10-20020a656b8a000000b003db7dc5fec2mr17831059pgw.223.1652775120427; Tue, 17 May 2022 01:12:00 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:11:59 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 3/9] net: sock: introduce sk_stream_kill_queues_reason() Date: Tue, 17 May 2022 16:10:02 +0800 Message-Id: <20220517081008.294325-4-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Introduce the function sk_stream_kill_queues_reason() and make the origin sk_stream_kill_queues() an inline call to it. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/net/sock.h | 8 +++++++- net/core/stream.c | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 73063c88a249..085838ce70d5 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1128,12 +1128,18 @@ int sk_stream_wait_connect(struct sock *sk, long *timeo_p); int sk_stream_wait_memory(struct sock *sk, long *timeo_p); void sk_stream_wait_close(struct sock *sk, long timeo_p); int sk_stream_error(struct sock *sk, int flags, int err); -void sk_stream_kill_queues(struct sock *sk); +void sk_stream_kill_queues_reason(struct sock *sk, + enum skb_drop_reason reason); void sk_set_memalloc(struct sock *sk); void sk_clear_memalloc(struct sock *sk); void __sk_flush_backlog(struct sock *sk); +static inline void sk_stream_kill_queues(struct sock *sk) +{ + sk_stream_kill_queues_reason(sk, SKB_DROP_REASON_NOT_SPECIFIED); +} + static inline bool sk_flush_backlog(struct sock *sk) { if (unlikely(READ_ONCE(sk->sk_backlog.tail))) { diff --git a/net/core/stream.c b/net/core/stream.c index 06b36c730ce8..a562b23a1a6e 100644 --- a/net/core/stream.c +++ b/net/core/stream.c @@ -190,10 +190,11 @@ int sk_stream_error(struct sock *sk, int flags, int err) } EXPORT_SYMBOL(sk_stream_error); -void sk_stream_kill_queues(struct sock *sk) +void sk_stream_kill_queues_reason(struct sock *sk, + enum skb_drop_reason reason) { /* First the read buffer. */ - __skb_queue_purge(&sk->sk_receive_queue); + __skb_queue_purge_reason(&sk->sk_receive_queue, reason); /* Next, the write queue. */ WARN_ON(!skb_queue_empty(&sk->sk_write_queue)); @@ -209,4 +210,4 @@ void sk_stream_kill_queues(struct sock *sk) * have gone away, only the net layer knows can touch it. */ } -EXPORT_SYMBOL(sk_stream_kill_queues); +EXPORT_SYMBOL(sk_stream_kill_queues_reason); From patchwork Tue May 17 08:10:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852080 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44548C433F5 for ; Tue, 17 May 2022 08:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242675AbiEQIMk (ORCPT ); Tue, 17 May 2022 04:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235674AbiEQIML (ORCPT ); Tue, 17 May 2022 04:12:11 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0F383CA68; Tue, 17 May 2022 01:12:05 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id x12so16295438pgj.7; Tue, 17 May 2022 01:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cAONMTMOUj5WPs7ieoNpxag94xyVtxhJLyFyNTFOxKY=; b=M/BrsATgBTdCYpAy7daDdTXN49Q/sx1f6R0MGwiPohmKTnhJQwXSXyMsHmai36EqgV whR70D5vwMgziEAeldS/gFy2FkXJpq3lGAk7vGE21LsRxvynsTT5VO/EJS8HAU2v0+W0 CuDiMLQmaPBzmoX/epWeonDo3FOk0oIRuSsdPBbsKJMR5w6QvNL+wnW1UHV1AL1hRUZ+ klmRsf77JLf72YaOoecE8A4Pk9DNErTwXVGC6ZFKe0uNhM3uGoeq4AcBf5xqoMS92XTq yqt+XryMMwbm+LqcGHFvW/ORj+stJiRPYJuajcrVsBM+dRFAlXXnn9lUYqZH3eQZeZcv UU+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cAONMTMOUj5WPs7ieoNpxag94xyVtxhJLyFyNTFOxKY=; b=T5Kp26U0HopHSD9u6m7iNrbquhgvlQTrkDP0/JembETUIa6kZuw4yfc0MAPjPruIFw tlxMdwHNZjxByiGSn0yA0lq+X9V96pLia2i4O55RYX8HvzH8q/wy5gDj042ayqRHo7Nw hoUbi75+kQrtCJk8q1qaAbXXQSetxIhoERLBkn+/PMypfQLxP9y3B6GjloUnKYO5kEfv HLFHseOSv71hxd1igC/ZPwgnrZivLsHQCip967wB3cNXUmmk+kwiPn+WP9tOQLD+u612 /1wVfb9jt+r2zl1zmrv9i4Eh4ngQqzAaoiFwutwztRQlw30PzzoIkdU9O//f7RC4kiuL O7cw== X-Gm-Message-State: AOAM532GQ+iM+tLXUPcos7n7RslHcjRWL6ZpGVwLS4lTJkP0oDMfz+Xr a8CquvGp52Q9r68QHO8zNvc= X-Google-Smtp-Source: ABdhPJy9iOhN19TCrxP5LWKoA45SRGJdKYwhu7lIl1WZJb3UWPILCGwLAYzmgg4k95fDIZq33NX9qg== X-Received: by 2002:a63:ee50:0:b0:3f4:e63c:3f08 with SMTP id n16-20020a63ee50000000b003f4e63c3f08mr1492938pgk.271.1652775124796; Tue, 17 May 2022 01:12:04 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:12:04 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 4/9] net: inet: add skb drop reason to inet_csk_destroy_sock() Date: Tue, 17 May 2022 16:10:03 +0800 Message-Id: <20220517081008.294325-5-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong skb dropping in inet_csk_destroy_sock() seems to be a common case. Add the new drop reason 'SKB_DROP_REASON_SOCKET_DESTROIED' and apply it to inet_csk_destroy_sock() to stop confusing users with 'NOT_SPECIFIED'. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 5 +++++ net/ipv4/inet_connection_sock.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index e9659a63961a..3c7b1e9aabbb 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -548,6 +548,10 @@ struct sk_buff; * * SKB_DROP_REASON_PKT_TOO_BIG * packet size is too big (maybe exceed the MTU) + * + * SKB_DROP_REASON_SOCKET_DESTROYED + * socket is destroyed and the skb in its receive or send queue + * are all dropped */ #define __DEFINE_SKB_DROP_REASON(FN) \ FN(NOT_SPECIFIED) \ @@ -614,6 +618,7 @@ struct sk_buff; FN(IP_INADDRERRORS) \ FN(IP_INNOROUTES) \ FN(PKT_TOO_BIG) \ + FN(SOCKET_DESTROYED) \ FN(MAX) /* The reason of skb drop, which is used in kfree_skb_reason(). diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 1e5b53c2bb26..6775cc8c42e1 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1006,7 +1006,7 @@ void inet_csk_destroy_sock(struct sock *sk) sk->sk_prot->destroy(sk); - sk_stream_kill_queues(sk); + sk_stream_kill_queues_reason(sk, SKB_DROP_REASON_SOCKET_DESTROYED); xfrm_sk_free_policy(sk); From patchwork Tue May 17 08:10:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852081 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4636C433FE for ; Tue, 17 May 2022 08:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242677AbiEQINO (ORCPT ); Tue, 17 May 2022 04:13:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242664AbiEQIMi (ORCPT ); Tue, 17 May 2022 04:12:38 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E62913EB8D; Tue, 17 May 2022 01:12:09 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id m12so16694536plb.4; Tue, 17 May 2022 01:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DJeIXN/OmSuazHjh5yZaGLXJ2vumkN5BeouJnoUdK54=; b=E1u6mLaXt7yirm/Pa4BNRXXeqEQ+kTpEzhxju4U1WANBDwQfSOv9XtN5r9qg5fozcw +hLztqhaQcgTqxUVaMujMGvFR118bKGG3sYYb6GACkUWUwE92ZgnWH+uTgPGF7LakwCf MJfbPHuA2F3HTw0hkkoqGebfiLfrZV9YUAsqGIJ5Wpx983zzDZX5X2LQgm2jkNq5klJA 8HhwJMtet6WfMzhAb7NMCL4/LwVpvVyWegfVVrTq2ofKZICh8s2pisBl2Sv1JJ+B8ToQ MySoq6iHss0HliOoVeRiPX3vg6P7jt5zOYlJITg6TlelDsKXsoKlgurqCgaZWVsbYs2C SrxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DJeIXN/OmSuazHjh5yZaGLXJ2vumkN5BeouJnoUdK54=; b=KO3AhXixqE0Xi/vgo520GPn5AjYp/kBwlwS2lIH2pD0aVrmyHjr1qWAwIZZnsTLcHA qnggr4b1s+CVD1ALoN1DqnOS9r8KB57w26GViMIynMGbM/WmdsYxgg2+2fUOAvaweqw2 TJW4E3DqzPXo07tbysKCthwO83tzkLMlAdFGgIvT6Kr10kxlrN1C8iLLsHBkxbwrF3LN c4+6KmLZwqMuNy3EHFhmzC4Mn6udSKKqWDsNHw9O5Gg3dE7Qb0K7PSw+FMht/oIkHMPo CR99UQ79p0JyjFOyoWxYK9PlntKefkbBjQshf+gZqgqaG0Cy9YUnzQS2L2oX5+MhCM4H 5JNg== X-Gm-Message-State: AOAM531MD1gvFgq9KZI7bq0nJdEsfMuSEi90vYW7a4IM76CJomcdQs3a P3XXWHqNnZ0PqjDdf9kF6tk= X-Google-Smtp-Source: ABdhPJzv/CGo0C0NQKrOa3ABeuJCxhjWLTJ2BFztKcVi0eHBrp3g7KYPb/PTtY6ea0yZvE55i6KImg== X-Received: by 2002:a17:90a:764b:b0:1df:58f2:784c with SMTP id s11-20020a17090a764b00b001df58f2784cmr8944224pjl.122.1652775129184; Tue, 17 May 2022 01:12:09 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:12:08 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 5/9] net: tcp: make tcp_rcv_synsent_state_process() return drop reasons Date: Tue, 17 May 2022 16:10:04 +0800 Message-Id: <20220517081008.294325-6-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong The return value of tcp_rcv_synsent_state_process() can be -1, 0 or 1: - -1: free skb silently - 0: success and skb is already freed - 1: drop packet and send a RST Therefore, we can make it return skb drop reasons on 'reset_and_undo' path, which will not impact the caller. The new reason 'TCP_PAWSACTIVEREJECTED' is added, which is corresponding to LINUX_MIB_PAWSACTIVEREJECTED. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 1 + net/ipv4/tcp_input.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 3c7b1e9aabbb..36e0971f4cc9 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -619,6 +619,7 @@ struct sk_buff; FN(IP_INNOROUTES) \ FN(PKT_TOO_BIG) \ FN(SOCKET_DESTROYED) \ + FN(TCP_PAWSACTIVEREJECTED) \ FN(MAX) /* The reason of skb drop, which is used in kfree_skb_reason(). diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 97cfcd85f84e..e8d26a68bc45 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6174,6 +6174,10 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, TCP_TIMEOUT_MIN, TCP_RTO_MAX); + if (after(TCP_SKB_CB(skb)->ack_seq, tp->snd_nxt)) + SKB_DR_SET(reason, TCP_ACK_UNSENT_DATA); + else + SKB_DR_SET(reason, TCP_TOO_OLD_ACK); goto reset_and_undo; } @@ -6182,6 +6186,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, tcp_time_stamp(tp))) { NET_INC_STATS(sock_net(sk), LINUX_MIB_PAWSACTIVEREJECTED); + SKB_DR_SET(reason, TCP_PAWSACTIVEREJECTED); goto reset_and_undo; } @@ -6375,7 +6380,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb, reset_and_undo: tcp_clear_options(&tp->rx_opt); tp->rx_opt.mss_clamp = saved_clamp; - return 1; + return reason; } static void tcp_rcv_synrecv_state_fastopen(struct sock *sk) From patchwork Tue May 17 08:10:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852082 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAFB5C433EF for ; Tue, 17 May 2022 08:13:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242560AbiEQIN0 (ORCPT ); Tue, 17 May 2022 04:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242616AbiEQINM (ORCPT ); Tue, 17 May 2022 04:13:12 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55B2D45051; Tue, 17 May 2022 01:12:14 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id nr2-20020a17090b240200b001df2b1bfc40so1699415pjb.5; Tue, 17 May 2022 01:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rBPzBYMrWsFKbZByuHnQrLDMtrzPNzPI3nX7MvL+UmA=; b=Sli0Pc2oXjsj4zfQ0xsmoNUgH8yHp1UQzAy+bRy7MVM2k6R0HYJDheixZm4P9qoxPW rJtuc3CG8PETWqpE3AREb6C/DOW64n0taJEcJnA5kAHEy00OGRTgina0NamU3ry1Et0u qWOah4KacW+4QUb1c4Iu0uZFYrW+txSix/OUVClyjBKbseOG77Z8a9fswY1T8mFZ24am Ef9myRLwjEUzrqoVYWsNuRNWnsYRXbxcmHRqrNvHi7FpNaJWxoY5Ntdmo8uFdSWoo0Y/ s63DxOeYFdbu4PHjl8ZggxvaFH5ZF6wxIjC/KAWxDBvgu9tprJoUuIVQMpFI9ejfDvMu 3t3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rBPzBYMrWsFKbZByuHnQrLDMtrzPNzPI3nX7MvL+UmA=; b=lHrR5vuEdv4wzPUXsqpOp9J2uHWOfaty8ec72F+aoDbNALiH6DJoSmaL85MocYUHiA WK0gm1awHajZOgZzRGRjgZh+Tc7/7ukuKYt+OM+fKpgxAxfCFSMXakm9wx2UGXzLjJF9 UjKpkYyq6yF+/omGbthjUiVexWsSYfOQqyh08FdMqVDEdbbLhg++sB7CBPGuMtXtHzj5 bvy3sJe9j2TabjPmO4tNurPXDKlMv0rGPMVsO6hf+DdCtslevt1yPl7+hPJdXJJlbe3k zm1DyStLGNBWQrJxLajcTufuNhQoj0dwhhMg6+K9iKg+mKOHGHkf7K23Tom0HO2SYXwv J6Tg== X-Gm-Message-State: AOAM533Dwe7wDeC6uwLMhQlbOqpxSuca05MV50waqSNh0wyv825GnLGg tVEtUMg4KvtWFbtGeF0xCEo= X-Google-Smtp-Source: ABdhPJxvv8vKZPlVirSw5NowsPTUwdlt8HNK4TE370QM74w8I9Gljp29gX9NfLRht0y1fvntYsCeMw== X-Received: by 2002:a17:90a:778c:b0:1df:56a5:8474 with SMTP id v12-20020a17090a778c00b001df56a58474mr9546929pjk.63.1652775133589; Tue, 17 May 2022 01:12:13 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:12:13 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 6/9] net: tcp: make tcp_rcv_state_process() return drop reason Date: Tue, 17 May 2022 16:10:05 +0800 Message-Id: <20220517081008.294325-7-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong For now, the return value of tcp_rcv_state_process() is treated as bool. Therefore, we can make it return the reasons of the skb drops. Meanwhile, the return value of tcp_child_process() comes from tcp_rcv_state_process(), make it drop reasons by the way. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 1 + include/net/tcp.h | 8 +++++--- net/ipv4/tcp_input.c | 22 +++++++++++----------- net/ipv4/tcp_ipv4.c | 20 +++++++++++++------- net/ipv4/tcp_minisocks.c | 11 ++++++----- net/ipv6/tcp_ipv6.c | 19 ++++++++++++------- 6 files changed, 48 insertions(+), 33 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 36e0971f4cc9..736899cc6a13 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -620,6 +620,7 @@ struct sk_buff; FN(PKT_TOO_BIG) \ FN(SOCKET_DESTROYED) \ FN(TCP_PAWSACTIVEREJECTED) \ + FN(TCP_ABORTONDATA) \ FN(MAX) /* The reason of skb drop, which is used in kfree_skb_reason(). diff --git a/include/net/tcp.h b/include/net/tcp.h index 1e99f5c61f84..ea0eb2d4a743 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -339,7 +339,8 @@ void tcp_wfree(struct sk_buff *skb); void tcp_write_timer_handler(struct sock *sk); void tcp_delack_timer_handler(struct sock *sk); int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg); -int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb); +enum skb_drop_reason tcp_rcv_state_process(struct sock *sk, + struct sk_buff *skb); void tcp_rcv_established(struct sock *sk, struct sk_buff *skb); void tcp_rcv_space_adjust(struct sock *sk); int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp); @@ -385,8 +386,9 @@ enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, struct request_sock *req, bool fastopen, bool *lost_race); -int tcp_child_process(struct sock *parent, struct sock *child, - struct sk_buff *skb); +enum skb_drop_reason tcp_child_process(struct sock *parent, + struct sock *child, + struct sk_buff *skb); void tcp_enter_loss(struct sock *sk); void tcp_cwnd_reduction(struct sock *sk, int newly_acked_sacked, int newly_lost, int flag); void tcp_clear_retrans(struct tcp_sock *tp); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index e8d26a68bc45..4717af0eaea7 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6422,7 +6422,7 @@ static void tcp_rcv_synrecv_state_fastopen(struct sock *sk) * address independent. */ -int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) +enum skb_drop_reason tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) { struct tcp_sock *tp = tcp_sk(sk); struct inet_connection_sock *icsk = inet_csk(sk); @@ -6439,7 +6439,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) case TCP_LISTEN: if (th->ack) - return 1; + return SKB_DROP_REASON_TCP_FLAGS; if (th->rst) { SKB_DR_SET(reason, TCP_RESET); @@ -6460,9 +6460,9 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) rcu_read_unlock(); if (!acceptable) - return 1; + return SKB_DROP_REASON_NOT_SPECIFIED; consume_skb(skb); - return 0; + return SKB_NOT_DROPPED_YET; } SKB_DR_SET(reason, TCP_FLAGS); goto discard; @@ -6472,13 +6472,13 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) tcp_mstamp_refresh(tp); queued = tcp_rcv_synsent_state_process(sk, skb, th); if (queued >= 0) - return queued; + return (enum skb_drop_reason)queued; /* Do step6 onward by hand. */ tcp_urg(sk, skb, th); __kfree_skb(skb); tcp_data_snd_check(sk); - return 0; + return SKB_NOT_DROPPED_YET; } tcp_mstamp_refresh(tp); @@ -6582,7 +6582,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) if (tp->linger2 < 0) { tcp_done(sk); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); - return 1; + return SKB_DROP_REASON_TCP_ABORTONDATA; } if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq && after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { @@ -6591,7 +6591,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) tcp_fastopen_active_disable(sk); tcp_done(sk); NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); - return 1; + return SKB_DROP_REASON_TCP_ABORTONDATA; } tmo = tcp_fin_time(sk); @@ -6656,7 +6656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONDATA); tcp_reset(sk, skb); - return 1; + return SKB_DROP_REASON_TCP_ABORTONDATA; } } fallthrough; @@ -6676,11 +6676,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) discard: tcp_drop_reason(sk, skb, reason); } - return 0; + return SKB_NOT_DROPPED_YET; consume: __kfree_skb(skb); - return 0; + return SKB_NOT_DROPPED_YET; } EXPORT_SYMBOL(tcp_rcv_state_process); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 24eb42497a71..12a18c5035f4 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1670,7 +1670,8 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) if (!nsk) goto discard; if (nsk != sk) { - if (tcp_child_process(sk, nsk, skb)) { + reason = tcp_child_process(sk, nsk, skb); + if (reason) { rsk = nsk; goto reset; } @@ -1679,7 +1680,8 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) } else sock_rps_save_rxhash(sk, skb); - if (tcp_rcv_state_process(sk, skb)) { + reason = tcp_rcv_state_process(sk, skb); + if (reason) { rsk = sk; goto reset; } @@ -1688,6 +1690,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) reset: tcp_v4_send_reset(rsk, skb); discard: + SKB_DR_OR(reason, NOT_SPECIFIED); kfree_skb_reason(skb, reason); /* Be careful here. If this function gets more complicated and * gcc suffers from register pressure on the x86, sk (in %ebx) @@ -2019,12 +2022,15 @@ int tcp_v4_rcv(struct sk_buff *skb) if (nsk == sk) { reqsk_put(req); tcp_v4_restore_cb(skb); - } else if (tcp_child_process(sk, nsk, skb)) { - tcp_v4_send_reset(nsk, skb); - goto discard_and_relse; } else { - sock_put(sk); - return 0; + drop_reason = tcp_child_process(sk, nsk, skb); + if (drop_reason) { + tcp_v4_send_reset(nsk, skb); + goto discard_and_relse; + } else { + sock_put(sk); + return 0; + } } } diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 6854bb1fb32b..1a21018f6f64 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -821,11 +821,12 @@ EXPORT_SYMBOL(tcp_check_req); * be created. */ -int tcp_child_process(struct sock *parent, struct sock *child, - struct sk_buff *skb) +enum skb_drop_reason tcp_child_process(struct sock *parent, + struct sock *child, + struct sk_buff *skb) __releases(&((child)->sk_lock.slock)) { - int ret = 0; + enum skb_drop_reason reason = SKB_NOT_DROPPED_YET; int state = child->sk_state; /* record sk_napi_id and sk_rx_queue_mapping of child. */ @@ -833,7 +834,7 @@ int tcp_child_process(struct sock *parent, struct sock *child, tcp_segs_in(tcp_sk(child), skb); if (!sock_owned_by_user(child)) { - ret = tcp_rcv_state_process(child, skb); + reason = tcp_rcv_state_process(child, skb); /* Wakeup parent, send SIGIO */ if (state == TCP_SYN_RECV && child->sk_state != state) parent->sk_data_ready(parent); @@ -847,6 +848,6 @@ int tcp_child_process(struct sock *parent, struct sock *child, bh_unlock_sock(child); sock_put(child); - return ret; + return reason; } EXPORT_SYMBOL(tcp_child_process); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 636ed23d9af0..d8236d51dd47 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1489,7 +1489,8 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) goto discard; if (nsk != sk) { - if (tcp_child_process(sk, nsk, skb)) + reason = tcp_child_process(sk, nsk, skb); + if (reason) goto reset; if (opt_skb) __kfree_skb(opt_skb); @@ -1498,7 +1499,8 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) } else sock_rps_save_rxhash(sk, skb); - if (tcp_rcv_state_process(sk, skb)) + reason = tcp_rcv_state_process(sk, skb); + if (reason) goto reset; if (opt_skb) goto ipv6_pktoptions; @@ -1685,12 +1687,15 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) if (nsk == sk) { reqsk_put(req); tcp_v6_restore_cb(skb); - } else if (tcp_child_process(sk, nsk, skb)) { - tcp_v6_send_reset(nsk, skb); - goto discard_and_relse; } else { - sock_put(sk); - return 0; + drop_reason = tcp_child_process(sk, nsk, skb); + if (drop_reason) { + tcp_v6_send_reset(nsk, skb); + goto discard_and_relse; + } else { + sock_put(sk); + return 0; + } } } From patchwork Tue May 17 08:10:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852083 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75D71C433F5 for ; Tue, 17 May 2022 08:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242682AbiEQINl (ORCPT ); Tue, 17 May 2022 04:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242638AbiEQINX (ORCPT ); Tue, 17 May 2022 04:13:23 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0A847388; Tue, 17 May 2022 01:12:18 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id nr2-20020a17090b240200b001df2b1bfc40so1699358pjb.5; Tue, 17 May 2022 01:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yrWgjLmB2iiLiA7VGVIElFdh/U/JN3XyMku/hPoh75g=; b=F8nWqU6wBagVndxWEMZOW9+XWf3p+WASC4vIulv5sc9MqMwfIq4X7ojrJqqv8g6DhP iz+KFYHBbX0w1xrBRxMAgvdLUJv2QmejU2EBN0e4Jc3n3HBNodXN3sPLO0rhxQHD2ujI E86kChI6JEFkovNNfps75DpUjqNLimlDCiv7OTDRk+31nQ7glQ4FtT8TCtV17SsJBl7w CTCkAj67BxXkGsp9t2bP5PWWhoqc/ihsqCMJ+NDZAu03Efsv6waZqWPfm2f8HHooNIy7 bYPaAkaXuObc46NpNX8GDJpBbMpjr75iaDyPh44Ma6enSuOWHhTorkG/Fbf7B2o1EHSN +K9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yrWgjLmB2iiLiA7VGVIElFdh/U/JN3XyMku/hPoh75g=; b=E3N9V1KeGYQm3yk+lz6tlv1Ut2M+LgKBAHVEqqDBcQaauoKQoMmC3T2aNhHV3mbg5F ymQKBL9btT1ovZwb42HpQkNCskBEtrZFvaidwj6Y8hc3SzsMJmgVkn9V71P+i6OOn9eL rz4dU45bEzxYqEcJxw5gyRdltQpBBS6PiSNG4yhtZu5tzpg62oeRae5anKOz0ZkKtSQ/ eb6/oTB+wfp3vdc8LKYiGosRNZJg8uByKPEytfYIYm4BYE5R0HLMARx4Eh06e7etJIV7 YcuKw85946sSHAGU7luTnOmN/WowZ7bYv8uxgeWXimTjuSrFKP6asSowtwrHc9fooAT9 n2VA== X-Gm-Message-State: AOAM531hFP3u+tOd8day7FxDXz2d3swlCaDbhyVhEF0he2C1VdXwo7XF amE0JzlYZVUI2iKn41ljH70= X-Google-Smtp-Source: ABdhPJxaZNlXl44yTcz+JZuwhnHZB2oWRnrTHW2zdV05/u3sf9qptAZiW0J7V2EUb05G76iH9pGujg== X-Received: by 2002:a17:90b:4f91:b0:1cd:3a73:3a5d with SMTP id qe17-20020a17090b4f9100b001cd3a733a5dmr23586988pjb.98.1652775138075; Tue, 17 May 2022 01:12:18 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:12:17 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 7/9] net: tcp: add skb drop reasons to tcp connect requesting Date: Tue, 17 May 2022 16:10:06 +0800 Message-Id: <20220517081008.294325-8-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong In order to get skb drop reasons during tcp connect requesting code path, we have to pass the pointer of the 'reason' as a new function argument of conn_request() in 'struct inet_connection_sock_af_ops'. As the return value of conn_request() can be positive or negative or 0, it's not flexible to make it return drop reasons. As the return value of tcp_conn_request() is 0, so we can treat it as bool and make it return the skb drop reasons. The new drop reasons 'LISTENOVERFLOWS' and 'TCP_REQQFULLDROP' are added, which are used for 'accept queue' and 'request queue' full. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 10 ++++++++++ include/net/inet_connection_sock.h | 3 ++- include/net/tcp.h | 9 +++++---- net/dccp/dccp.h | 3 ++- net/dccp/input.c | 3 ++- net/dccp/ipv4.c | 3 ++- net/dccp/ipv6.c | 5 +++-- net/ipv4/tcp_input.c | 27 ++++++++++++++++++--------- net/ipv4/tcp_ipv4.c | 9 ++++++--- net/ipv6/tcp_ipv6.c | 12 ++++++++---- net/mptcp/subflow.c | 8 +++++--- 11 files changed, 63 insertions(+), 29 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 736899cc6a13..4578bbab5a3e 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -552,6 +552,14 @@ struct sk_buff; * SKB_DROP_REASON_SOCKET_DESTROYED * socket is destroyed and the skb in its receive or send queue * are all dropped + * + * SKB_DROP_REASON_LISTENOVERFLOWS + * accept queue of the listen socket is full, corresponding to + * LINUX_MIB_LISTENOVERFLOWS + * + * SKB_DROP_REASON_TCP_REQQFULLDROP + * request queue of the listen socket is full, corresponding to + * LINUX_MIB_TCPREQQFULLDROP */ #define __DEFINE_SKB_DROP_REASON(FN) \ FN(NOT_SPECIFIED) \ @@ -621,6 +629,8 @@ struct sk_buff; FN(SOCKET_DESTROYED) \ FN(TCP_PAWSACTIVEREJECTED) \ FN(TCP_ABORTONDATA) \ + FN(LISTENOVERFLOWS) \ + FN(TCP_REQQFULLDROP) \ FN(MAX) /* The reason of skb drop, which is used in kfree_skb_reason(). diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h index 3908296d103f..0600280f308e 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -36,7 +36,8 @@ struct inet_connection_sock_af_ops { void (*send_check)(struct sock *sk, struct sk_buff *skb); int (*rebuild_header)(struct sock *sk); void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb); - int (*conn_request)(struct sock *sk, struct sk_buff *skb); + int (*conn_request)(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason); struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb, struct request_sock *req, struct dst_entry *dst, diff --git a/include/net/tcp.h b/include/net/tcp.h index ea0eb2d4a743..082dd0627e2e 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -445,7 +445,8 @@ void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb); void tcp_v4_mtu_reduced(struct sock *sk); void tcp_req_err(struct sock *sk, u32 seq, bool abort); void tcp_ld_RTO_revert(struct sock *sk, u32 seq); -int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb); +int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason); struct sock *tcp_create_openreq_child(const struct sock *sk, struct request_sock *req, struct sk_buff *skb); @@ -2036,9 +2037,9 @@ void tcp4_proc_exit(void); #endif int tcp_rtx_synack(const struct sock *sk, struct request_sock *req); -int tcp_conn_request(struct request_sock_ops *rsk_ops, - const struct tcp_request_sock_ops *af_ops, - struct sock *sk, struct sk_buff *skb); +enum skb_drop_reason tcp_conn_request(struct request_sock_ops *rsk_ops, + const struct tcp_request_sock_ops *af_ops, + struct sock *sk, struct sk_buff *skb); /* TCP af-specific functions */ struct tcp_sock_af_ops { diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h index 7dfc00c9fb32..8c1241ae8449 100644 --- a/net/dccp/dccp.h +++ b/net/dccp/dccp.h @@ -255,7 +255,8 @@ void dccp_done(struct sock *sk); int dccp_reqsk_init(struct request_sock *rq, struct dccp_sock const *dp, struct sk_buff const *skb); -int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb); +int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason); struct sock *dccp_create_openreq_child(const struct sock *sk, const struct request_sock *req, diff --git a/net/dccp/input.c b/net/dccp/input.c index 2cbb757a894f..e12baa56ca59 100644 --- a/net/dccp/input.c +++ b/net/dccp/input.c @@ -576,6 +576,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb, const int old_state = sk->sk_state; bool acceptable; int queued = 0; + SKB_DR(reason); /* * Step 3: Process LISTEN state @@ -606,7 +607,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb, */ rcu_read_lock(); local_bh_disable(); - acceptable = inet_csk(sk)->icsk_af_ops->conn_request(sk, skb) >= 0; + acceptable = inet_csk(sk)->icsk_af_ops->conn_request(sk, skb, &reason) >= 0; local_bh_enable(); rcu_read_unlock(); if (!acceptable) diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c index 82696ab86f74..c689385229f0 100644 --- a/net/dccp/ipv4.c +++ b/net/dccp/ipv4.c @@ -581,7 +581,8 @@ static struct request_sock_ops dccp_request_sock_ops __read_mostly = { .syn_ack_timeout = dccp_syn_ack_timeout, }; -int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb) +int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { struct inet_request_sock *ireq; struct request_sock *req; diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c index 4d95b6400915..d32fbdf45012 100644 --- a/net/dccp/ipv6.c +++ b/net/dccp/ipv6.c @@ -314,7 +314,8 @@ static struct request_sock_ops dccp6_request_sock_ops = { .syn_ack_timeout = dccp_syn_ack_timeout, }; -static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb) +static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { struct request_sock *req; struct dccp_request_sock *dreq; @@ -324,7 +325,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb) struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); if (skb->protocol == htons(ETH_P_IP)) - return dccp_v4_conn_request(sk, skb); + return dccp_v4_conn_request(sk, skb, reason); if (!ipv6_unicast_destination(skb)) return 0; /* discard, don't send a reset here */ diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 4717af0eaea7..be6275c56b59 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6455,13 +6455,17 @@ enum skb_drop_reason tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) */ rcu_read_lock(); local_bh_disable(); - acceptable = icsk->icsk_af_ops->conn_request(sk, skb) >= 0; + reason = SKB_NOT_DROPPED_YET; + acceptable = icsk->icsk_af_ops->conn_request(sk, skb, &reason) >= 0; local_bh_enable(); rcu_read_unlock(); if (!acceptable) - return SKB_DROP_REASON_NOT_SPECIFIED; - consume_skb(skb); + return reason ?: SKB_DROP_REASON_NOT_SPECIFIED; + if (reason) + kfree_skb_reason(skb, reason); + else + consume_skb(skb); return SKB_NOT_DROPPED_YET; } SKB_DR_SET(reason, TCP_FLAGS); @@ -6881,9 +6885,9 @@ u16 tcp_get_syncookie_mss(struct request_sock_ops *rsk_ops, } EXPORT_SYMBOL_GPL(tcp_get_syncookie_mss); -int tcp_conn_request(struct request_sock_ops *rsk_ops, - const struct tcp_request_sock_ops *af_ops, - struct sock *sk, struct sk_buff *skb) +enum skb_drop_reason tcp_conn_request(struct request_sock_ops *rsk_ops, + const struct tcp_request_sock_ops *af_ops, + struct sock *sk, struct sk_buff *skb) { struct tcp_fastopen_cookie foc = { .len = -1 }; __u32 isn = TCP_SKB_CB(skb)->tcp_tw_isn; @@ -6895,6 +6899,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, bool want_cookie = false; struct dst_entry *dst; struct flowi fl; + SKB_DR(reason); /* TW buckets are converted to open requests without * limitations, they conserve resources and peer is @@ -6903,12 +6908,15 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, if ((net->ipv4.sysctl_tcp_syncookies == 2 || inet_csk_reqsk_queue_is_full(sk)) && !isn) { want_cookie = tcp_syn_flood_action(sk, rsk_ops->slab_name); - if (!want_cookie) + if (!want_cookie) { + SKB_DR_SET(reason, TCP_REQQFULLDROP); goto drop; + } } if (sk_acceptq_is_full(sk)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS); + SKB_DR_SET(reason, LISTENOVERFLOWS); goto drop; } @@ -6964,6 +6972,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, */ pr_drop_req(req, ntohs(tcp_hdr(skb)->source), rsk_ops->family); + SKB_DR_SET(reason, TCP_REQQFULLDROP); goto drop_and_release; } @@ -7016,7 +7025,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, } } reqsk_put(req); - return 0; + return SKB_NOT_DROPPED_YET; drop_and_release: dst_release(dst); @@ -7024,6 +7033,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, __reqsk_free(req); drop: tcp_listendrop(sk); - return 0; + return reason; } EXPORT_SYMBOL(tcp_conn_request); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 12a18c5035f4..708f92b03f42 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1458,17 +1458,20 @@ const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = { .send_synack = tcp_v4_send_synack, }; -int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb) +int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { /* Never answer to SYNs send to broadcast or multicast */ if (skb_rtable(skb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) goto drop; - return tcp_conn_request(&tcp_request_sock_ops, - &tcp_request_sock_ipv4_ops, sk, skb); + *reason = tcp_conn_request(&tcp_request_sock_ops, + &tcp_request_sock_ipv4_ops, sk, skb); + return *reason; drop: tcp_listendrop(sk); + *reason = SKB_DROP_REASON_IP_INADDRERRORS; return 0; } EXPORT_SYMBOL(tcp_v4_conn_request); diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index d8236d51dd47..27c51991bd54 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1148,24 +1148,28 @@ u16 tcp_v6_get_syncookie(struct sock *sk, struct ipv6hdr *iph, return mss; } -static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) +static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { if (skb->protocol == htons(ETH_P_IP)) - return tcp_v4_conn_request(sk, skb); + return tcp_v4_conn_request(sk, skb, reason); if (!ipv6_unicast_destination(skb)) goto drop; if (ipv6_addr_v4mapped(&ipv6_hdr(skb)->saddr)) { __IP6_INC_STATS(sock_net(sk), NULL, IPSTATS_MIB_INHDRERRORS); + *reason = SKB_DROP_REASON_IP_INADDRERRORS; return 0; } - return tcp_conn_request(&tcp6_request_sock_ops, - &tcp_request_sock_ipv6_ops, sk, skb); + *reason = tcp_conn_request(&tcp6_request_sock_ops, + &tcp_request_sock_ipv6_ops, sk, skb); + return *reason; drop: tcp_listendrop(sk); + *reason = SKB_DROP_REASON_IP_INADDRERRORS; return 0; /* don't send reset */ } diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 6d59336a8e1e..58c1f056213b 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -532,7 +532,8 @@ static int subflow_v6_rebuild_header(struct sock *sk) struct request_sock_ops mptcp_subflow_request_sock_ops; static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops __ro_after_init; -static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb) +static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); @@ -556,14 +557,15 @@ static struct inet_connection_sock_af_ops subflow_v6_specific __ro_after_init; static struct inet_connection_sock_af_ops subflow_v6m_specific __ro_after_init; static struct proto tcpv6_prot_override; -static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb) +static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason *reason) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); pr_debug("subflow=%p", subflow); if (skb->protocol == htons(ETH_P_IP)) - return subflow_v4_conn_request(sk, skb); + return subflow_v4_conn_request(sk, skb, reason); if (!ipv6_unicast_destination(skb)) goto drop; From patchwork Tue May 17 08:10:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852084 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B645DC433F5 for ; Tue, 17 May 2022 08:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242761AbiEQIOi (ORCPT ); Tue, 17 May 2022 04:14:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242895AbiEQINZ (ORCPT ); Tue, 17 May 2022 04:13:25 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEA2549686; Tue, 17 May 2022 01:12:22 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id 202so16285060pgc.9; Tue, 17 May 2022 01:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LIJvlfwH+A7ChhNAlcL3A1DkFGuk0HKdruIRD+tpTeA=; b=Cilti3rM3XWSD0VRpAH3Ic2xIszEp7yxpy4jd42+PPoI7rnR3zlMwLcioOGgMjuxdJ v8BfyIiKgZTPXOx2uEUkQ+X0OtViCtkGEdnnc4XuUDEkqlKvRMyj8PD1caOSSHnYZLrz zgWUz8rupW4j2G0hrpl9IWAm2u2100R8g31X5MH/G5sr40qKT+xHK+TteALHG0Knio5K bzmxIKLhQDX1x2o118SHCtjZkJvfIPVUyGCS4MwplJSK46qc1PCjSUgzJJOTDyLTxala 6YFx9JWR3JLYwLL3/kMjNgyT6A8gLu874Pu0tQ/X2BDl4eUe7uVHvCMgjgPJxpHvQHzY NeWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LIJvlfwH+A7ChhNAlcL3A1DkFGuk0HKdruIRD+tpTeA=; b=K27klrKtUgW+c4XSR6QfXrkqTol8MDeZVX8TyNLU9J2AZ9f/Aig9mN3j6y7Ax+V/EU /+pmTjqJOZ1Xl0PWDVytg124e/lTUNsnjk/H89qpdQ5FoOH3DVZRmGBAMLfq5cWR+F9m MJPtcjhwLXdvOWX54Os2TBXnfB4xrKneskaY9uGqengq2IsIXwZ+Et3YT00V7kEqXRLu eepNOVrztBjCu8GBqzNpBFuRmTZkyXST8cs2OB2KhcqycfVUP5uvexX+7l4VFvbeWNhm 9c40BO/TF9LY1Gu5WYK1gYO57AggkZ2IEzcFzLUMtQxR2O/RlUXbHBPC3c7o8xMsgqj/ Boxg== X-Gm-Message-State: AOAM530V7+X9rCc2plbdw6sd/NTaE5ib14aNFESuF6Qe7P4rcWmG1cR6 gJQNMQMtiLuGT3MRtB9mRHo= X-Google-Smtp-Source: ABdhPJzt10xjhAZfHagR+V5BR5RL1J9sld/c/IRH9aARHqtTjXTNFcV8uuFigM/5rS5VgKMWt5T8EA== X-Received: by 2002:a05:6a00:e8e:b0:4fa:a52f:59cf with SMTP id bo14-20020a056a000e8e00b004faa52f59cfmr21306473pfb.84.1652775142413; Tue, 17 May 2022 01:12:22 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:12:21 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 8/9] net: tcp: add skb drop reasons to tcp tw code path Date: Tue, 17 May 2022 16:10:07 +0800 Message-Id: <20220517081008.294325-9-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong In order to get the reasons of skb drops, add a function argument of type 'enum skb_drop_reason *reason' to tcp_timewait_state_process(). In the origin code, all packets to time-wait socket are treated as dropping with kfree_skb(), which can make users confused. Therefore, we use consume_skb() for the skbs that are 'good'. We can check the value of 'reason' to decide use kfree_skb() or consume_skb(). The new reason 'TIMEWAIT' is added for the case that the skb is dropped as the socket in time-wait state. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- v2: - skb is not freed on TCP_TW_ACK and 'ret' is not initizalized, fix it (Eric Dumazet) --- include/linux/skbuff.h | 5 +++++ include/net/tcp.h | 7 ++++--- net/ipv4/tcp_ipv4.c | 9 ++++++++- net/ipv4/tcp_minisocks.c | 24 ++++++++++++++++++++---- net/ipv6/tcp_ipv6.c | 9 ++++++++- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 4578bbab5a3e..8d18fc5a5af6 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -560,6 +560,10 @@ struct sk_buff; * SKB_DROP_REASON_TCP_REQQFULLDROP * request queue of the listen socket is full, corresponding to * LINUX_MIB_TCPREQQFULLDROP + * + * SKB_DROP_REASON_TIMEWAIT + * socket is in time-wait state and all packet that received will + * be treated as 'drop', except a good 'SYN' packet */ #define __DEFINE_SKB_DROP_REASON(FN) \ FN(NOT_SPECIFIED) \ @@ -631,6 +635,7 @@ struct sk_buff; FN(TCP_ABORTONDATA) \ FN(LISTENOVERFLOWS) \ FN(TCP_REQQFULLDROP) \ + FN(TIMEWAIT) \ FN(MAX) /* The reason of skb drop, which is used in kfree_skb_reason(). diff --git a/include/net/tcp.h b/include/net/tcp.h index 082dd0627e2e..88217b8d95ac 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -380,9 +380,10 @@ enum tcp_tw_status { }; -enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, - struct sk_buff *skb, - const struct tcphdr *th); +enum tcp_tw_status +tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, + const struct tcphdr *th, + enum skb_drop_reason *reason); struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, struct request_sock *req, bool fastopen, bool *lost_race); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 708f92b03f42..3c163b54b0f8 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2134,7 +2134,8 @@ int tcp_v4_rcv(struct sk_buff *skb) inet_twsk_put(inet_twsk(sk)); goto csum_error; } - switch (tcp_timewait_state_process(inet_twsk(sk), skb, th)) { + switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, + &drop_reason)) { case TCP_TW_SYN: { struct sock *sk2 = inet_lookup_listener(dev_net(skb->dev), &tcp_hashinfo, skb, @@ -2150,11 +2151,17 @@ int tcp_v4_rcv(struct sk_buff *skb) refcounted = false; goto process; } + /* TCP_FLAGS or NO_SOCKET? */ + SKB_DR_SET(drop_reason, TCP_FLAGS); } /* to ACK */ fallthrough; case TCP_TW_ACK: tcp_v4_timewait_ack(sk, skb); + if (!drop_reason) { + consume_skb(skb); + return 0; + } break; case TCP_TW_RST: tcp_v4_send_reset(sk, skb); diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 1a21018f6f64..329724118b7f 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -83,13 +83,15 @@ tcp_timewait_check_oow_rate_limit(struct inet_timewait_sock *tw, */ enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, - const struct tcphdr *th) + const struct tcphdr *th, + enum skb_drop_reason *reason) { struct tcp_options_received tmp_opt; struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw); bool paws_reject = false; tmp_opt.saw_tstamp = 0; + *reason = SKB_DROP_REASON_NOT_SPECIFIED; if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) { tcp_parse_options(twsk_net(tw), skb, &tmp_opt, 0, NULL); @@ -113,11 +115,16 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, return tcp_timewait_check_oow_rate_limit( tw, skb, LINUX_MIB_TCPACKSKIPPEDFINWAIT2); - if (th->rst) + if (th->rst) { + SKB_DR_SET(*reason, TCP_RESET); goto kill; + } - if (th->syn && !before(TCP_SKB_CB(skb)->seq, tcptw->tw_rcv_nxt)) + if (th->syn && !before(TCP_SKB_CB(skb)->seq, + tcptw->tw_rcv_nxt)) { + SKB_DR_SET(*reason, TCP_FLAGS); return TCP_TW_RST; + } /* Dup ACK? */ if (!th->ack || @@ -143,6 +150,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, } inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN); + + /* skb should be free normally on this case. */ + *reason = SKB_NOT_DROPPED_YET; return TCP_TW_ACK; } @@ -174,6 +184,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, * protocol bug yet. */ if (twsk_net(tw)->ipv4.sysctl_tcp_rfc1337 == 0) { + SKB_DR_SET(*reason, TCP_RESET); kill: inet_twsk_deschedule_put(tw); return TCP_TW_SUCCESS; @@ -216,11 +227,14 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, if (isn == 0) isn++; TCP_SKB_CB(skb)->tcp_tw_isn = isn; + *reason = SKB_NOT_DROPPED_YET; return TCP_TW_SYN; } - if (paws_reject) + if (paws_reject) { + SKB_DR_SET(*reason, TCP_RFC7323_PAWS); __NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWSESTABREJECTED); + } if (!th->rst) { /* In this case we must reset the TIMEWAIT timer. @@ -232,9 +246,11 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, if (paws_reject || th->ack) inet_twsk_reschedule(tw, TCP_TIMEWAIT_LEN); + SKB_DR_OR(*reason, TIMEWAIT); return tcp_timewait_check_oow_rate_limit( tw, skb, LINUX_MIB_TCPACKSKIPPEDTIMEWAIT); } + SKB_DR_SET(*reason, TCP_RESET); inet_twsk_put(tw); return TCP_TW_SUCCESS; } diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 27c51991bd54..132b27763229 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1772,6 +1772,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) } discard_it: + SKB_DR_OR(drop_reason, NOT_SPECIFIED); kfree_skb_reason(skb, drop_reason); return 0; @@ -1795,7 +1796,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) goto csum_error; } - switch (tcp_timewait_state_process(inet_twsk(sk), skb, th)) { + switch (tcp_timewait_state_process(inet_twsk(sk), skb, th, + &drop_reason)) { case TCP_TW_SYN: { struct sock *sk2; @@ -1815,11 +1817,16 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) refcounted = false; goto process; } + SKB_DR_SET(drop_reason, TCP_FLAGS); } /* to ACK */ fallthrough; case TCP_TW_ACK: tcp_v6_timewait_ack(sk, skb); + if (!drop_reason) { + consume_skb(skb); + return 0; + } break; case TCP_TW_RST: tcp_v6_send_reset(sk, skb); From patchwork Tue May 17 08:10:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12852085 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 325E1C433F5 for ; Tue, 17 May 2022 08:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242801AbiEQIOq (ORCPT ); Tue, 17 May 2022 04:14:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242921AbiEQIN0 (ORCPT ); Tue, 17 May 2022 04:13:26 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BF9F496A7; Tue, 17 May 2022 01:12:27 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ev18so6059869pjb.4; Tue, 17 May 2022 01:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tsqLBQjRtgnyo1sQei1gpb0K6REi5TaI3JgfHkJY/jQ=; b=jhHbxV5PpwiIzUsl2mEJKAtp4rc/vpdVks3HnKGxskvQ81EvZZY9jc2isPtK9Ih8Kk YZy+55f6/VcQ7fEyOmjQBRlhPTr14K6auWTS/pBnarwEDMTgfSv4Iii5L4UDs1JOa5bq LUT6h05vSlMuupWQY/9Zi950i/pUqxREDexrUALt7KWbCGMmA8it7uJgO+Y2nfxFEmkd BJxiINsvNODG072jTl9xZYUVHOseXmKrVlTW+G3Uo18yWdKqRRmBtrINAZqyMZIjZfou NPrBqvIMpD3OiGzO7id/0YwU6CuWpeZhTO8wUgl7Fc8vwPaJapQJBck7L+XOM5zbZcAe uwqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tsqLBQjRtgnyo1sQei1gpb0K6REi5TaI3JgfHkJY/jQ=; b=NCLNLU1ssrptsJCrGyhCEw7cq41f+eciM8GMW9AdSD6mA7whWlLXuK+hpFF7e7pL08 VpmH+Ns/ysNhMP+fNiK1yIJnQ5WHeb8WoqhBGCMWAwZBqxpJ02hf8GomLM9seuEAUDEr rh+1OXozTIADKpzTt7Pcs7mfm04dIsSULJhldG2tSLEczm++5WwcZ0liXOwlScnTcyNJ aItHSBw8neCYq3x8SbAcwzvDeUT9U3a/dAV/MT3aYWWJTyLkk8LH8XD2TjJJTY+pHfQM gWPe2q6qgAV45ExCLgATapTim/8WPXWI65TT7e26KmJODTUtHmDyCvvll9U4kN8fsVVq JT0w== X-Gm-Message-State: AOAM531ml0n80RzVFsroHmbbHEsYB3ZvQfUa6KoVtX+shinHdqX09urZ lnTVNnV4VnYN8uL7wircURw= X-Google-Smtp-Source: ABdhPJwSXMOAdvAnBLa3qRqOZ9uiNSUIzx/t6id6EaaxALCZtKiNRYwDDxXAdmU7keITpCEDDawmNQ== X-Received: by 2002:a17:90b:1c87:b0:1ca:f4e:4fbe with SMTP id oo7-20020a17090b1c8700b001ca0f4e4fbemr35065639pjb.159.1652775146828; Tue, 17 May 2022 01:12:26 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.20]) by smtp.gmail.com with ESMTPSA id c14-20020a170902c2ce00b0015e8d4eb2easm8336306pla.308.2022.05.17.01.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:12:26 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: edumazet@google.com Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, dongli.zhang@oracle.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jiang Biao , Hao Peng Subject: [PATCH net-next v2 9/9] net: tcp: add skb drop reasons to route_req() Date: Tue, 17 May 2022 16:10:08 +0800 Message-Id: <20220517081008.294325-10-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220517081008.294325-1-imagedong@tencent.com> References: <20220517081008.294325-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Add skb drop reasons to the route_req() in struct tcp_request_sock_ops. Following functions are involved: tcp_v4_route_req() tcp_v6_route_req() subflow_v4_route_req() subflow_v6_route_req() And the new reason SKB_DROP_REASON_LSM is added, which is used when skb is dropped by LSM. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 4 ++++ include/net/tcp.h | 3 ++- net/ipv4/tcp_input.c | 2 +- net/ipv4/tcp_ipv4.c | 14 +++++++++++--- net/ipv6/tcp_ipv6.c | 14 +++++++++++--- net/mptcp/subflow.c | 10 ++++++---- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8d18fc5a5af6..fdfe54dc5ae4 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -564,6 +564,9 @@ struct sk_buff; * SKB_DROP_REASON_TIMEWAIT * socket is in time-wait state and all packet that received will * be treated as 'drop', except a good 'SYN' packet + * + * SKB_DROP_REASON_LSM + * dropped by LSM */ #define __DEFINE_SKB_DROP_REASON(FN) \ FN(NOT_SPECIFIED) \ @@ -636,6 +639,7 @@ struct sk_buff; FN(LISTENOVERFLOWS) \ FN(TCP_REQQFULLDROP) \ FN(TIMEWAIT) \ + FN(LSM) \ FN(MAX) /* The reason of skb drop, which is used in kfree_skb_reason(). diff --git a/include/net/tcp.h b/include/net/tcp.h index 88217b8d95ac..ed57c331fdeb 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2075,7 +2075,8 @@ struct tcp_request_sock_ops { struct dst_entry *(*route_req)(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req); + struct request_sock *req, + enum skb_drop_reason *reason); u32 (*init_seq)(const struct sk_buff *skb); u32 (*init_ts_off)(const struct net *net, const struct sk_buff *skb); int (*send_synack)(const struct sock *sk, struct dst_entry *dst, diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index be6275c56b59..146d22b05186 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6950,7 +6950,7 @@ enum skb_drop_reason tcp_conn_request(struct request_sock_ops *rsk_ops, /* Note: tcp_v6_init_req() might override ir_iif for link locals */ inet_rsk(req)->ir_iif = inet_request_bound_dev_if(sk, skb); - dst = af_ops->route_req(sk, skb, &fl, req); + dst = af_ops->route_req(sk, skb, &fl, req, &reason); if (!dst) goto drop_and_free; diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 3c163b54b0f8..026a36f1598b 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1423,14 +1423,22 @@ static void tcp_v4_init_req(struct request_sock *req, static struct dst_entry *tcp_v4_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req) + struct request_sock *req, + enum skb_drop_reason *reason) { + struct dst_entry *dst; + tcp_v4_init_req(req, sk, skb); - if (security_inet_conn_request(sk, skb, req)) + if (security_inet_conn_request(sk, skb, req)) { + SKB_DR_SET(*reason, LSM); return NULL; + } - return inet_csk_route_req(sk, &fl->u.ip4, req); + dst = inet_csk_route_req(sk, &fl->u.ip4, req); + if (!dst) + SKB_DR_SET(*reason, IP_OUTNOROUTES); + return dst; } struct request_sock_ops tcp_request_sock_ops __read_mostly = { diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 132b27763229..b859adcde756 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -802,14 +802,22 @@ static void tcp_v6_init_req(struct request_sock *req, static struct dst_entry *tcp_v6_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req) + struct request_sock *req, + enum skb_drop_reason *reason) { + struct dst_entry *dst; + tcp_v6_init_req(req, sk, skb); - if (security_inet_conn_request(sk, skb, req)) + if (security_inet_conn_request(sk, skb, req)) { + SKB_DR_SET(*reason, LSM); return NULL; + } - return inet6_csk_route_req(sk, &fl->u.ip6, req, IPPROTO_TCP); + dst = inet6_csk_route_req(sk, &fl->u.ip6, req, IPPROTO_TCP); + if (!dst) + SKB_DR_SET(*reason, IP_OUTNOROUTES); + return dst; } struct request_sock_ops tcp6_request_sock_ops __read_mostly = { diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 58c1f056213b..db7e6cd96d44 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -285,7 +285,8 @@ EXPORT_SYMBOL_GPL(mptcp_subflow_init_cookie_req); static struct dst_entry *subflow_v4_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req) + struct request_sock *req, + enum skb_drop_reason *reason) { struct dst_entry *dst; int err; @@ -293,7 +294,7 @@ static struct dst_entry *subflow_v4_route_req(const struct sock *sk, tcp_rsk(req)->is_mptcp = 1; subflow_init_req(req, sk); - dst = tcp_request_sock_ipv4_ops.route_req(sk, skb, fl, req); + dst = tcp_request_sock_ipv4_ops.route_req(sk, skb, fl, req, reason); if (!dst) return NULL; @@ -311,7 +312,8 @@ static struct dst_entry *subflow_v4_route_req(const struct sock *sk, static struct dst_entry *subflow_v6_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, - struct request_sock *req) + struct request_sock *req, + enum skb_drop_reason *reason) { struct dst_entry *dst; int err; @@ -319,7 +321,7 @@ static struct dst_entry *subflow_v6_route_req(const struct sock *sk, tcp_rsk(req)->is_mptcp = 1; subflow_init_req(req, sk); - dst = tcp_request_sock_ipv6_ops.route_req(sk, skb, fl, req); + dst = tcp_request_sock_ipv6_ops.route_req(sk, skb, fl, req, reason); if (!dst) return NULL;