Received: by 10.223.164.202 with SMTP id h10csp2359680wrb; Sat, 18 Nov 2017 20:12:38 -0800 (PST) X-Google-Smtp-Source: AGs4zMaKlGewu6yT/1F/uODmV+wYnbCwJNZipJg4AxFjDQKqp+hSzigGgdZKv1HkOmG4SjIOL/1l X-Received: by 10.84.251.146 with SMTP id w18mr6147524pll.324.1511064758112; Sat, 18 Nov 2017 20:12:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511064758; cv=none; d=google.com; s=arc-20160816; b=lkyLqbmXrBt/ajGGKPzVqmFeKthNRH93WMg0vBeprKjXhN7zMGbi4+w6zQbKtcjqRG igRgCWavZBuWlqNo6PzwDfG7wVfiF5hGexu2tFckAzeppRksnKxaIh5NGUmCSi3QpSzu 5PBH3ath7vziL3j+ujHMcedtNnnySaIoW9wBgfHHe0kkBo2Tjas9p6uiO3CT+pZ04hvo wtxF5GbJLcixAKkq08k4qGLX1bWu742IZjzIZGY4sTdRxYKTfLXpmxGf76XC8silyneM IhHOP+dKys81f106SOiFw510+dGVl581Ydrr778Iq3XrWiCkj2cJc8cf/93iqyqRvKG/ v6YA== 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=c2p0aFLyFnGjT6LKz+pv4j079w8QWJodAL8NA1TzLlA=; b=E8wrvEWYC/OQw6sGaTUOAMXWSvkLc/K21Pv+Ex+aGNXxlTdPrmckVRSgMnvfxzn8oq pctHTvsXt7kUmr0zPGSqcA0V15Y6KyKD2cqFK2BjJ86Bbp+tOlZDc/ppT9vcBz9zSCzz mI+RIR0+KLTNzYUZYgu+PyC4NVX1zr77/qDt+xupV6EJsDyQg/oHZuSOV4TM+73qIa0g Ybdlz9nc1CQ8DKJk80dsNKA170I2o/bwegNBlb9trkYGS97CXL9iWuG99ohUFhq/RsRx JgYOmzLE8uKHtzgJ8BH1kkYBpV5LZ0kd1y9saK0VsppDoLG/vakJafOikGWlCMkvSn3R VkRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=s9bxLhl4; 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 c41si5551680plj.293.2017.11.18.20.12.25; Sat, 18 Nov 2017 20:12:38 -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=s9bxLhl4; 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 S966511AbdKRPdB (ORCPT + 93 others); Sat, 18 Nov 2017 10:33:01 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45944 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934777AbdKRPcu (ORCPT ); Sat, 18 Nov 2017 10:32:50 -0500 Received: by mail-pg0-f66.google.com with SMTP id 207so4109630pgc.12; Sat, 18 Nov 2017 07:32:50 -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=c2p0aFLyFnGjT6LKz+pv4j079w8QWJodAL8NA1TzLlA=; b=s9bxLhl4wl6hpAIO578v1pmCNefy2QcLQW5zr20KCwYlPXA4sTNGoSORz3VLWAURyG ylGmoVsv8SmXbFQUYjEENLLpmLTh+pP6v3LU5XjmZ9JadiKzvQQLSyLT4fEdzNIlWkOv UA4a4CKKbmWsMouId5D7wM7r0JrETYjMPxRvojTXHoKSs2z04jDQkHYKpZ0kBT3SpXIb 3SEPnIrO/VdR319D3Rm/JP8Nn/CeFGjgxfL72XAwgvU975qY4zLewN9foX+wyTwapcKO 1AVDEZMjaapo/yQittUx/8pzhfaKbmm/SC5poW3Exm7WbahBZuNz9NmdL0uJjg+ryrIH ozzw== 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=c2p0aFLyFnGjT6LKz+pv4j079w8QWJodAL8NA1TzLlA=; b=nXQHA4QoZJUsi9annIfhkP5JQgokvvxm3LY/3HUIREd+WDEvUlHBV480IYwrHb56Lm 8QDRGA3nNxzf3fXaS2RyZ7JkOTG4Xjow9458i3DqaOTOn4Ci+kq+18YR0fHltZiNgLVR zGzG14Zku0Pqvu5ZdS2pR+KBcPvTIdHmF+79rOLoO1UuGxcxwqhkzWr1Hw7SDvuxh6TH IFVjbO127w30a+g1E2fMbutfEn5WJsKP/B0ouy31tlyiHyr+/sxwxghyrLVazoWx8gXD qXDikTkB/NSrG0NuV3bgHmG+ebvANb0YzPrzidps8XnKYQ6i2U7+mgygDrE5443j2rg8 t2tA== X-Gm-Message-State: AJaThX4recgfqz4d603aPlyItQ1Io/jVXtvv9ybBQcCpeLtem/cwr0Od Jkao54CNf3wdrMzYUOPzT4c= X-Received: by 10.99.119.79 with SMTP id s76mr8388046pgc.192.1511019170262; Sat, 18 Nov 2017 07:32:50 -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 n10sm13184269pfk.174.2017.11.18.07.32.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Nov 2017 07:32:49 -0800 (PST) From: Yafang Shao To: davem@davemloft.net Cc: kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, rostedt@goodmis.org, songliubraving@fb.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH v2 net-next] net/tcp: trace all TCP/IP state transition with tcp_set_state tracepoint Date: Sat, 18 Nov 2017 15:32:36 +0000 Message-Id: <1511019156-22039-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 and some other transitions are not traced with tcp_set_state tracepoint. In order to trace the whole tcp lifespans, two helpers are introduced, void __tcp_set_state(struct sock *sk, int state) 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 | 2 ++ net/ipv4/inet_connection_sock.c | 6 +++--- net/ipv4/inet_hashtables.c | 2 +- net/ipv4/tcp.c | 12 ++++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 85ea578..4f2d015 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1247,6 +1247,8 @@ static inline bool tcp_checksum_complete(struct sk_buff *skb) "Close Wait","Last ACK","Listen","Closing" }; #endif +void __sk_state_store(struct sock *sk, int newstate); +void __tcp_set_state(struct sock *sk, int state); void tcp_set_state(struct sock *sk, int state); void tcp_done(struct sock *sk); 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); } diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index bf97317..2bc7e04 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2036,6 +2036,18 @@ int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, } EXPORT_SYMBOL(tcp_recvmsg); +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_set_state(struct sock *sk, int state) +{ + trace_tcp_set_state(sk, sk->sk_state, state); + sk->sk_state = state; +} + void tcp_set_state(struct sock *sk, int state) { int oldstate = sk->sk_state; -- 1.8.3.1 From 1584508216851636417@xxx Sun Nov 19 15:19:50 +0000 2017 X-GM-THRID: 1584505495914205118 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread