From patchwork Fri Dec 14 22:40:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Paasch X-Patchwork-Id: 1013751 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=apple.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=apple.com header.i=@apple.com header.b="ZfwnF18E"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43Glr90Mqnz9s1c for ; Sat, 15 Dec 2018 09:40:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730264AbeLNWkk (ORCPT ); Fri, 14 Dec 2018 17:40:40 -0500 Received: from nwk-aaemail-lapp03.apple.com ([17.151.62.68]:35314 "EHLO nwk-aaemail-lapp03.apple.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729803AbeLNWkh (ORCPT ); Fri, 14 Dec 2018 17:40:37 -0500 Received: from pps.filterd (nwk-aaemail-lapp03.apple.com [127.0.0.1]) by nwk-aaemail-lapp03.apple.com (8.16.0.22/8.16.0.22) with SMTP id wBEMW0uN054363; Fri, 14 Dec 2018 14:40:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=content-transfer-encoding : sender : from : to : cc : subject : date : message-id : in-reply-to : references; s=20180706; bh=YRphguDudp1jzYQr2JrSAW6CKzJj8j3o5WWf6y2ek8w=; b=ZfwnF18EtZZeKlD74DuMYZ7I8boxBqg1/PNDIJOUWpFNy97uSj/Aa71oqqiA9tEZzV1Y juPHIYZUKz6gGZj0x7aHCWxShUlCfSJwr6c9o+iDydyb4cJatFS/KF4Hy+DNCB7LCDqt 82Ah+mgCwNUMZRkc9n58KdxTbMKa0P3Z2wM319BJ5r1XmcDnevpdqRV2l3APkxRlG0jk f+3EWokQnHz/VqMEKd3SN14F7MhKfUOyozzUY5gL3+JReweZjLo2cGMjF3ovsBvvzzxv O0ZkPDow6ZhmeWZUtdD4BVNFGCHr78w6Kc6r8IFEIVT3RS/FeD9IYhy82Daao0uJDp7S Dg== Received: from mr2-mtap-s02.rno.apple.com (mr2-mtap-s02.rno.apple.com [17.179.226.134]) by nwk-aaemail-lapp03.apple.com with ESMTP id 2p8bcd4jbv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Fri, 14 Dec 2018 14:40:33 -0800 Content-transfer-encoding: 7BIT Received: from nwk-mmpp-sz09.apple.com (nwk-mmpp-sz09.apple.com [17.128.115.80]) by mr2-mtap-s02.rno.apple.com (Oracle Communications Messaging Server 8.0.2.3.20181024 64bit (built Oct 24 2018)) with ESMTPS id <0PJR00LM70BLWQE0@mr2-mtap-s02.rno.apple.com>; Fri, 14 Dec 2018 14:40:33 -0800 (PST) Received: from process_viserion-daemon.nwk-mmpp-sz09.apple.com by nwk-mmpp-sz09.apple.com (Oracle Communications Messaging Server 8.0.2.3.20181024 64bit (built Oct 24 2018)) id <0PJQ00B00Z1EGU00@nwk-mmpp-sz09.apple.com>; Fri, 14 Dec 2018 14:40:33 -0800 (PST) X-Va-A: X-Va-T-CD: 4b1e0bf36502e052fc75ad21b706ed24 X-Va-E-CD: 7c3ee86764b9b9f2218ea4c1bf5f34a6 X-Va-R-CD: 3ab423187ce70efc0116c2277bac3176 X-Va-CD: 0 X-Va-ID: 21677b8b-fb39-4e4e-9c0a-7f575bc9165c X-V-A: X-V-T-CD: 5c1d590bbb3e9640019563b4ec412a7e X-V-E-CD: 7c3ee86764b9b9f2218ea4c1bf5f34a6 X-V-R-CD: 3ab423187ce70efc0116c2277bac3176 X-V-CD: 0 X-V-ID: f31c0b37-ad59-413a-ae3a-b11d766f3b33 Received: from process_milters-daemon.nwk-mmpp-sz09.apple.com by nwk-mmpp-sz09.apple.com (Oracle Communications Messaging Server 8.0.2.3.20181024 64bit (built Oct 24 2018)) id <0PJR00F0009AI500@nwk-mmpp-sz09.apple.com>; Fri, 14 Dec 2018 14:40:31 -0800 (PST) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-14_13:,, signatures=0 Received: from localhost ([17.192.155.217]) by nwk-mmpp-sz09.apple.com (Oracle Communications Messaging Server 8.0.2.3.20181024 64bit (built Oct 24 2018)) with ESMTPSA id <0PJR00GBC0BJSV00@nwk-mmpp-sz09.apple.com>; Fri, 14 Dec 2018 14:40:31 -0800 (PST) From: Christoph Paasch To: netdev@vger.kernel.org Cc: Eric Dumazet , Yuchung Cheng , David Miller Subject: [PATCH net-next 5/5] tcp: TFO - cleanup code duplication Date: Fri, 14 Dec 2018 14:40:07 -0800 Message-id: <20181214224007.54813-6-cpaasch@apple.com> X-Mailer: git-send-email 2.16.2 In-reply-to: <20181214224007.54813-1-cpaasch@apple.com> References: <20181214224007.54813-1-cpaasch@apple.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-12-14_13:, , signatures=0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We can actually easily reuse __tcp_fastopen_cookie_gen_with_ctx to generate the cookie based on a give TFO-context. This cleans up some of the code. Signed-off-by: Christoph Paasch --- net/ipv4/tcp_fastopen.c | 51 +++++++++++-------------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index e856262ef4c2..81e8b3ae9ecd 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -155,27 +155,6 @@ error: kfree(ctx); return err; } -static bool __tcp_fastopen_cookie_gen(struct sock *sk, const void *path, - struct tcp_fastopen_cookie *foc) -{ - struct tcp_fastopen_context *ctx; - bool ok = false; - - rcu_read_lock(); - - ctx = rcu_dereference(inet_csk(sk)->icsk_accept_queue.fastopenq.ctx); - if (!ctx) - ctx = rcu_dereference(sock_net(sk)->ipv4.tcp_fastopen_ctx); - - if (ctx) { - crypto_cipher_encrypt_one(ctx->tfm, foc->val, path); - foc->len = TCP_FASTOPEN_COOKIE_SIZE; - ok = true; - } - rcu_read_unlock(); - return ok; -} - static void __tcp_fastopen_cookie_gen_with_ctx(struct request_sock *req, struct sk_buff *syn, struct tcp_fastopen_cookie *foc, @@ -222,29 +201,21 @@ static bool tcp_fastopen_cookie_gen(struct sock *sk, struct sk_buff *syn, struct tcp_fastopen_cookie *foc) { - if (req->rsk_ops->family == AF_INET) { - const struct iphdr *iph = ip_hdr(syn); - - __be32 path[4] = { iph->saddr, iph->daddr, 0, 0 }; - return __tcp_fastopen_cookie_gen(sk, path, foc); - } + struct tcp_fastopen_context *ctx; + bool ok = false; -#if IS_ENABLED(CONFIG_IPV6) - if (req->rsk_ops->family == AF_INET6) { - const struct ipv6hdr *ip6h = ipv6_hdr(syn); - struct tcp_fastopen_cookie tmp; + rcu_read_lock(); - if (__tcp_fastopen_cookie_gen(sk, &ip6h->saddr, &tmp)) { - struct in6_addr *buf = &tmp.addr; - int i; + ctx = rcu_dereference(inet_csk(sk)->icsk_accept_queue.fastopenq.ctx); + if (!ctx) + ctx = rcu_dereference(sock_net(sk)->ipv4.tcp_fastopen_ctx); - for (i = 0; i < 4; i++) - buf->s6_addr32[i] ^= ip6h->daddr.s6_addr32[i]; - return __tcp_fastopen_cookie_gen(sk, buf, foc); - } + if (ctx) { + __tcp_fastopen_cookie_gen_with_ctx(req, syn, foc, ctx); + ok = true; } -#endif - return false; + rcu_read_unlock(); + return ok; }