Received: by 10.192.165.148 with SMTP id m20csp2422302imm; Sun, 22 Apr 2018 06:51:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx49XEaUZQe6n0S7FhGD5JZaZeaew1okZ9Uyd1AIkWKhPtDNzmJR9jYTtueKJOkge8AEqC7lU X-Received: by 2002:a17:902:781:: with SMTP id 1-v6mr11207753plj.150.1524405102689; Sun, 22 Apr 2018 06:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524405102; cv=none; d=google.com; s=arc-20160816; b=tsYQMwYjUkdrSz9DAYx0wG/FUzsEbNvhCWcTXHwlJIyEP/0x/S+9rMgnB2ItVPBFQv ybe+SGLSV4fiPJVRt27M2V5rBiBFJBlR2h0Fu8yMoBhTrvewi1297waBFBglcsh6DK49 KdxDcG+0S2f3FDrsQ5PkJxQGz1R1uMp6wZezXUPQcgvupkkfDEIlcS8HQ1rS/AHx/LoY E6UNHSUZHm5HDzsf1kOE17KS1GQNPmyrsJiPwnPWJMSvzN6THnVxcZ+oi3A4RO0qNghl cXxhWb+9hD9AmSTyVv9WRiUka7p4YDbWbqLnUTyMCxfOz0GNB7JTUlVxf2hC+109/NrP xnKg== 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=3wZ4cUf6HB3wMN7aiZGBtBPKHkkZuogQYrULPDpWyYs=; b=lS95KNMeJY7NGRIeGidjwfdv/o+sc2ReY9JFyhcgU/XTu2qk/vQFXIxbqp+Qq+XfmC UBJPpfAEWwaItPHpLmH6mEUoPpR0f4dxZj/+m3eHwBPxwUgvGnd/XVIUv0IvZXyymNAX N2KZQGEGtDdAsWwFusqBQ8gLWXxnCPF/cXQWYMqB2rXYbxvX2QSjfYAGACgqVR139/6I n8uKZwAwtbmFmrK9jLPOKD5vdHrqeEziAgDLUexTOapnWLV0iple+EMM4V1NIQrgOqkC zckrRTvZYfP4VEzBhSSnPdV4MzfyX959JSjvGq4P96ZXSaxJhROJViaJ6hBstbK9zbGc j88A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fkm2U/wc; 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=QUARANTINE 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 b61-v6si9871015plc.500.2018.04.22.06.51.27; Sun, 22 Apr 2018 06:51:42 -0700 (PDT) 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=fkm2U/wc; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751710AbeDVNuZ (ORCPT + 99 others); Sun, 22 Apr 2018 09:50:25 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34047 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751053AbeDVNuX (ORCPT ); Sun, 22 Apr 2018 09:50:23 -0400 Received: by mail-pf0-f195.google.com with SMTP id q9so7089947pff.1; Sun, 22 Apr 2018 06:50:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=3wZ4cUf6HB3wMN7aiZGBtBPKHkkZuogQYrULPDpWyYs=; b=fkm2U/wcyQhnplvqi9br9D19x6fACqQBHf8NwZHr5ov6U5ineU5vpXCpxoW7M9QZ7d cP9lj6MmQg5zYXoBLcCSZyD/L0wT4WsVE6j7OkjGwl3OKeDr6v0Ek3gzWg9DaBdMALJz OqSeu/bqIrKv8NsbNeYELvCKX7gLVId8GS6Wol2slMCJmpvPuTJDqyMOb/4qWak+YaH/ RBFDK5dey5u7R+zwEU6cFszMLqHoOHxlng4uskNdISffg4l1e7PLr9qfj5Sa5j+TQvnD 629V/CTqtW+kTKBVbEPDiJ8TdT+rBIx42lC4gdA+zk8l07uz/C+4HUcwggSsmbi8SvuG KFVA== 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=3wZ4cUf6HB3wMN7aiZGBtBPKHkkZuogQYrULPDpWyYs=; b=qOmfmt4FinFjumhymvFodd2DIi4GC/ECAu3Skm67zX1ItfJwEpc3YUU8mAtVSnOIEZ 1cIy39wxQuE+oOHOoH2fg530qlNEVQ/8HpUd+4HpEhLomQttz04/1fk8ubrPuuHeQwib 8jeH52Ja8WIKycZvvGxsx1t8RqSqfq9qaFznA/l73kW4hOWET/7Ynau+CyxdETyQCD3i EV8ZPrNpr3tEC9Jv/RF+OC7yqUsAK5Qk26kDQEW4GXodciTs8wf5MKF3la61IMrapaZo wW5/KAAcq6BVvIT7B5Lilz4Bcb6hcCGJroev5S94/zwsF6q0pwS966zjuoAkQCe89NDo Ub6A== X-Gm-Message-State: ALQs6tAqCNKWWe3NjejF2t5CciVRpsXV6Safj8bwqwtWZMgjpU2g+/4Z GHOrloaZXR4kXlFubJtd+fA= X-Received: by 10.99.131.72 with SMTP id h69mr13963307pge.378.1524405023169; Sun, 22 Apr 2018 06:50:23 -0700 (PDT) Received: from li1588-6.members.linode.com (li1588-6.members.linode.com. [139.162.104.6]) by smtp.gmail.com with ESMTPSA id k24sm14825415pff.147.2018.04.22.06.50.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Apr 2018 06:50:22 -0700 (PDT) From: Yafang Shao To: eric.dumazet@gmail.com, alexei.starovoitov@gmail.com, davem@davemloft.net Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH net-next] net: init sk_cookie for inet socket Date: Sun, 22 Apr 2018 21:50:04 +0800 Message-Id: <1524405004-10960-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 With sk_cookie we can identify a socket, that is very helpful for traceing and statistic, i.e. tcp tracepiont and ebpf. So we'd better init it by default for inet socket. When using it, we just need call atomic64_read(&sk->sk_cookie). Signed-off-by: Yafang Shao --- include/linux/sock_diag.h | 9 +++++++++ net/ipv4/tcp_input.c | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h index 15fe980..5c916e6 100644 --- a/include/linux/sock_diag.h +++ b/include/linux/sock_diag.h @@ -25,6 +25,15 @@ struct sock_diag_handler { void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh)); void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh)); +static inline +void sock_init_cookie(struct sock *sk) +{ + u64 res; + + res = atomic64_inc_return(&sock_net(sk)->cookie_gen); + atomic64_set(&sk->sk_cookie, res); +} + u64 sock_gen_cookie(struct sock *sk); int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie); void sock_diag_save_cookie(struct sock *sk, __u32 *cookie); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 0396fb9..e6a64a3 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -78,6 +78,7 @@ #include #include #include +#include int sysctl_tcp_max_orphans __read_mostly = NR_FILE; @@ -6188,10 +6189,15 @@ struct request_sock *inet_reqsk_alloc(const struct request_sock_ops *ops, #if IS_ENABLED(CONFIG_IPV6) ireq->pktopts = NULL; #endif - atomic64_set(&ireq->ir_cookie, 0); ireq->ireq_state = TCP_NEW_SYN_RECV; write_pnet(&ireq->ireq_net, sock_net(sk_listener)); ireq->ireq_family = sk_listener->sk_family; + + BUILD_BUG_ON(offsetof(struct inet_request_sock, ir_cookie) != + offsetof(struct sock, sk_cookie)); + BUILD_BUG_ON(offsetof(struct inet_request_sock, ireq_net) != + offsetof(struct sock, sk_net)); + sock_init_cookie((struct sock *)ireq); } return req; -- 1.8.3.1