Received: by 10.223.164.202 with SMTP id h10csp159259wrb; Tue, 7 Nov 2017 04:33:01 -0800 (PST) X-Google-Smtp-Source: ABhQp+RgmudpL/o1MmU6hhJKdnKmqsAKRRHGquWYw6D4DA8nGZ4xdy+2Rp9nIjTCnoc9njYRYMML X-Received: by 10.98.242.15 with SMTP id m15mr20655173pfh.176.1510057981461; Tue, 07 Nov 2017 04:33:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510057981; cv=none; d=google.com; s=arc-20160816; b=cVty4StzJKyi1ff1ZzWR1ZTkN+60YC5BlZRCBp1APA2Lo7z2MVJXfTfScWMjuDsJwm uP1xgZqjbmb9lTRtwcGxEgbpynC1NVphJmT53GMiCZ5eWX4Nuea+qkmOZLygkOoNN5up 7MgmDJtSQogduOh0BenITQ7xR7iLdsI1L18kbsA03tPbX4ML07i5sn7uieR7niuCW2hq 1urG08cJgOhWURTDqaAF0x0Td2ztn1L6pGIRDdDi8JYg8avRJvC91UJRqmHrHavF4D2e XpQJip4A0QilZBMNJFO7Tpr4eNdFNk9eTEkaIbtsFsE/0AuDimE7oiFbtx3YWORXFzbD l0Nw== 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=Ic6+XG1/Vprg27t/+kPrYX0Nrtm/ldGZlTeby+g8+8k=; b=oUMvMZsqdIzjfYyn9FgN2yrwTTCSwMNHQt2NHAMriQNBAar64I3Eiix5HIx+aFgUJQ j6ZDBe4jfXpIhbFLwkyDo8EBAfAoAg/c6hxRM43zOHoYsN4TN0Gc/K6WQpvIYqmfKs+q A+1FyJZQhy1VBRfxIr3KPrIsGm2ri6ohf6pSuvsktRRUqW9OhF0woMGOm08bhCrYEyAn YqbTSjbh7Ie7orRTHT7J11IhSgy3cC3wq36Pz585Fss1yBAJ53oezuDTw5MkPMRDiqoB Vq5bYr4cZIyjjapldjQlYPAtEKlCg65pHCjiHrEDkXmcHEFMJlpSjz9g4NcOskjFrVJQ hmyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uZuBs1ps; 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 g33si1123765plb.153.2017.11.07.04.32.48; Tue, 07 Nov 2017 04:33:01 -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=uZuBs1ps; 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 S1756888AbdKGKgj (ORCPT + 91 others); Tue, 7 Nov 2017 05:36:39 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:51847 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751801AbdKGKgf (ORCPT ); Tue, 7 Nov 2017 05:36:35 -0500 Received: by mail-pg0-f65.google.com with SMTP id p9so10675468pgc.8; Tue, 07 Nov 2017 02:36:35 -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=Ic6+XG1/Vprg27t/+kPrYX0Nrtm/ldGZlTeby+g8+8k=; b=uZuBs1psL1RkQS/8i+wl3SiYmbIhbiSASjrkwICPt4VP0U+3YIYRHdSpv+WNjSnER4 Fs1N30mKTLxjGpdXHdBe6g0DRuJ0/8IjNFmjdxhUVOm5NTRkIluNJN5RteMiROywPj90 3lbIm/PE1lsgaDeSvja0EnfjnTAlFamMCCUU8m5GZR9/b0fmo7wQN1nwch0cGjNlQP8C DvMeTJW9+i0UnX6XKcOBCci4sXZOQW1MI1oyYsqrWmWKZqNABcU4nGclFjCl9SAG/zaI +zn7HdKHK5mgeag9nwMs5IrI+O9cQ8IidYsP/CmoFI6PN9UvC7RpRfQAam2SjUKjoOI8 eHIA== 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=Ic6+XG1/Vprg27t/+kPrYX0Nrtm/ldGZlTeby+g8+8k=; b=ZfpUCsbFvzZ4Spj43myfKrM/3CyDNCWZn0QB9aWBcns9vp/fnfYSH9JI+5JyvFMM4b WOAHw2b0fc/fPMLsFvSp+LM9cDFUTIJdJHwq//YqdU3RWiyuT8bJZ0TrnpiNwfvbKpWK 3X6+ju8Uy0Won1ms8lxXOHpPFY3XqSl8kyDKju5o3eSs7NqbpWV85NLWY+FTRM9c/VGE 0oPAyXfnw/6E0rljgT2vDXAfj/Zx+jdCI4UczvMe9UXQwDpj9JuWf4Kq44F6dQ+9qO7d jd6UMYmvzQdfT+hEyL9s3W4xENCWJ0BP8gJCsRhTLSzfbqK7ODLknBx770UxTPi8TtJ1 mowg== X-Gm-Message-State: AMCzsaW292f3K49k1U5zuTbR233fJIYViQT4TSBbyYmgjFx+y0W2Dj/y GyMQzlCCc7H5YTiniFuWXjw= X-Received: by 10.99.160.25 with SMTP id r25mr18018249pge.67.1510050995249; Tue, 07 Nov 2017 02:36:35 -0800 (PST) Received: from localhost.localdomain.localdomain ([122.224.77.194]) by smtp.gmail.com with ESMTPSA id f10sm2128982pgr.8.2017.11.07.02.36.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Nov 2017 02:36:34 -0800 (PST) From: Yafang Shao To: davem@davemloft.net, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH] net/tcp: track all ipv4/tcp state transition in tcp_set_state Date: Tue, 7 Nov 2017 18:36:28 +0800 Message-Id: <1510050988-17688-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 When I hooked the function tcp_set_state with kprobe to track the ipv4/tcp state transistion, I found state transition from TCP_LISTEN to TCP_SYN_RECV is missed. I think it is better to use the helper to do state transition instead of assigning the state to sk_state directly. Then we can monitor the whole tcp lifespans with kprobe or ftrace easily. Signed-off-by: Yafang Shao --- net/ipv4/inet_connection_sock.c | 6 +++--- net/ipv4/inet_hashtables.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index c039c93..7c987c5 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -786,7 +786,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; @@ -880,7 +880,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); + tcp_set_state(sk, TCP_LISTEN); if (!sk->sk_prot->get_port(sk, inet->inet_num)) { inet->inet_sport = htons(inet->inet_num); @@ -891,7 +891,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 597bb4c..bea8318 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 1583461690183133245@xxx Wed Nov 08 02:05:44 +0000 2017 X-GM-THRID: 1583461690183133245 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread