Received: by 10.223.164.202 with SMTP id h10csp291011wrb; Thu, 9 Nov 2017 06:27:34 -0800 (PST) X-Google-Smtp-Source: ABhQp+TCRwRCN/hZc7VzdkRT0kGMLdq9je0eyCWuH570v0AELqbRsIzGnppNiTtaYjGz9eV97BVS X-Received: by 10.98.198.28 with SMTP id m28mr654927pfg.217.1510237653921; Thu, 09 Nov 2017 06:27:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510237653; cv=none; d=google.com; s=arc-20160816; b=0rcqNwMybmzPX2Ba5d/5BE5UBwGEMm0QVP352V9+138gNbyLAWh/Iu5mCG5GKlJVPI baMbMQ4drG2mE6ekZWlYZfSh5gI4vvbcu4MFCq/R73dARpbV/vg8fiv88+ZzdV1m6a98 kThOHoyTT6P+GM052z0AonukbjKheyFcr4JqZEy8GDMOVTisiufZfhc6sokUd9b0re7P dWGCAlnXu03wus0dt1BdbgDYBAipiZOMHjncmFeeLe2Nc0lzH+zLc9QGSRrNxA5mmnXZ Rvp2Y83If3GmEn/yn+7PM41T9RBAjzYqEfLnlLPGLYveQ1f8Bbv/pHukKza87k+KoKHq YFRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=XGBH52Y4Pd7796gXNIeAGbdA8hAo+BrzXmPh61PIGaA=; b=c3DUNV3SD56e348qnRB/C3i9+B2NGSUsBl+jdL8kP2a/0Jt36hobbFyOp/oj+A7lwk 2AMUWGTjoYOqvPH1P3bt6OStEMWTz2K2rK0BBkaJr5Y5YtYp8XQo1WmV2bkcIL3scZ/P brtuzLTkxWSA0azCBMO+IEA/9PBfYTIMcwYCFaiuUdXdBhDc4XF6XkRFHO0ynHgIOfAe E1MRlKyW7gieKbZFo06KIkNs//cYZVlMGj+nLhvB018OO2JjyuV8rILRjZrBadV8JcWy HeX04OWDTfwYOPJpRK7/HxEkNl2cgpcbWfvQiGv0vCRq6V5KUL6x5to5mW0WG2ZasCB7 81dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q8OS10Ve; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h71si6207692pgc.321.2017.11.09.06.27.22; Thu, 09 Nov 2017 06:27:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q8OS10Ve; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755056AbdKIO0a (ORCPT + 80 others); Thu, 9 Nov 2017 09:26:30 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45797 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754983AbdKIO02 (ORCPT ); Thu, 9 Nov 2017 09:26:28 -0500 Received: by mail-pf0-f193.google.com with SMTP id d28so4380581pfe.2; Thu, 09 Nov 2017 06:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=XGBH52Y4Pd7796gXNIeAGbdA8hAo+BrzXmPh61PIGaA=; b=Q8OS10VeMM0Zh56m7nwnQ9v0agmv2HViT4KFvQXDM8+D6J0/NI5QlL7hvY3WizJzAp wEKjAkmZD0gAJPODRvrtknDcnaJSdzBXgzrYYTXHMOYtg9UtGL8uGotH0X9WzzNQQLBd i8vFfkYAHZlrCx2B8XbtmCbQauxfbgn0LyFi0XWA9ecAlhlWZO6ENi6IHPdyHRwp11dL /99MAuzo+slpPryo5o0STWFM17fCu1wkfCHYPk6nsULbrTw2b+HFE7ZL+zimwVKpHkoa z47r/L1YFloRExXucNqgWsGb7OXQoqxs0ULJlu2rXpj+UN1yM8gAQCC1zeqkCdT5aaqT ItTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=XGBH52Y4Pd7796gXNIeAGbdA8hAo+BrzXmPh61PIGaA=; b=btbOavPbiwQai2sTwhJ3Ic2wqSEao1KRt9wn1XuLfk0Blp0kt3bqD48+PTdHFvuz6X WQEMayA7jgX7kHiMQ0JdVqhQAn+fx6/Q8RwFeOAChPc2MHq5QdSSEfHT46dLRvomAVAi 6jFu950TM/C0KczjqlQJkQM0lFfNJiFTBrXZBmfo87vL3k81dY/nbd4ZjF2CaD988pQK /Jc8gyZ+qQq5uM9D0KyDOGwshLIvxJoeiZ6jzP1KNtwj0+tFmUzi43JC2TAGykZYoj+h jmvmEn9YAqSGR/zYhj10g8FUy19BYgDddEN+YdjWtWdoecOQvdy278qS4RwZtuwdsHIW uChw== X-Gm-Message-State: AJaThX47glJR73ADGJ5oZfYXH5tpxw8at+MTTXFNwlfeM0F2Wj1jc1JH Eo0eN2T+yIKjt6fwrDKCKgg= X-Received: by 10.98.10.21 with SMTP id s21mr669863pfi.119.1510237588046; Thu, 09 Nov 2017 06:26:28 -0800 (PST) Received: from li1588-6.members.linode.com (li1588-6.members.linode.com. [139.162.104.6]) by smtp.gmail.com with ESMTPSA id p12sm9073146pgn.60.2017.11.09.06.26.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 06:26:27 -0800 (PST) From: Yafang Shao To: davem@davemloft.net Cc: kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, rostedt@goodmis.org, mingo@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH net-next 1/2] net/tcp: track all TCP/IP state transition in tcp_set_state Date: Thu, 9 Nov 2017 14:26:03 +0000 Message-Id: <1510237564-6013-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The TCP/IP transition from TCP_LISTEN to TCP_SYN_RECV isn't traced in the tcp_set_state tracepoint. In order to trace the whole tcp lifespans, two helpers are introduced, static inline void __tcp_set_state(struct sock *sk, int state) static inline void __sk_state_store(struct sock *sk, int newstate) When do TCP/IP state transition, we should use these two helpers or use tcp_set_state() other than assigning a value to sk_state directly. Signed-off-by: Yafang Shao --- include/net/tcp.h | 16 ++++++++++++++++ net/ipv4/inet_connection_sock.c | 6 +++--- net/ipv4/inet_hashtables.c | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index babfd4d..c1d57d0 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -46,6 +46,7 @@ #include #include #include +#include extern struct inet_hashinfo tcp_hashinfo; @@ -1263,6 +1264,21 @@ static inline bool tcp_checksum_complete(struct sk_buff *skb) #endif void tcp_set_state(struct sock *sk, int state); +/* + * To trace TCP/IP state transition. + */ +static inline void __tcp_set_state(struct sock *sk, int state) +{ + trace_tcp_set_state(sk, sk->sk_state, state); + sk->sk_state = state; +} + +static inline void __sk_state_store(struct sock *sk, int newstate) +{ + trace_tcp_set_state(sk, sk->sk_state, newstate); + sk_state_store(sk, newstate); +} + void tcp_done(struct sock *sk); int tcp_abort(struct sock *sk, int err); diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 4ca46dc..f3967f1 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -783,7 +783,7 @@ struct sock *inet_csk_clone_lock(const struct sock *sk, if (newsk) { struct inet_connection_sock *newicsk = inet_csk(newsk); - newsk->sk_state = TCP_SYN_RECV; + __tcp_set_state(newsk, TCP_SYN_RECV); newicsk->icsk_bind_hash = NULL; inet_sk(newsk)->inet_dport = inet_rsk(req)->ir_rmt_port; @@ -877,7 +877,7 @@ int inet_csk_listen_start(struct sock *sk, int backlog) * It is OK, because this socket enters to hash table only * after validation is complete. */ - sk_state_store(sk, TCP_LISTEN); + __sk_state_store(sk, TCP_LISTEN); if (!sk->sk_prot->get_port(sk, inet->inet_num)) { inet->inet_sport = htons(inet->inet_num); @@ -888,7 +888,7 @@ int inet_csk_listen_start(struct sock *sk, int backlog) return 0; } - sk->sk_state = TCP_CLOSE; + __tcp_set_state(sk, TCP_CLOSE); return err; } EXPORT_SYMBOL_GPL(inet_csk_listen_start); diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index e7d15fb..72c15b6 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -430,7 +430,7 @@ bool inet_ehash_nolisten(struct sock *sk, struct sock *osk) sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1); } else { percpu_counter_inc(sk->sk_prot->orphan_count); - sk->sk_state = TCP_CLOSE; + __tcp_set_state(sk, TCP_CLOSE); sock_set_flag(sk, SOCK_DEAD); inet_csk_destroy_sock(sk); } -- 1.8.3.1 From 1583622187308794649@xxx Thu Nov 09 20:36:46 +0000 2017 X-GM-THRID: 1583622187308794649 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread