From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christoph Paasch Subject: [PATCH net-next 4/5] tcp: Allow getsockopt of listener's keypool Date: Fri, 14 Dec 2018 14:40:06 -0800 Message-ID: <20181214224007.54813-5-cpaasch@apple.com> References: <20181214224007.54813-1-cpaasch@apple.com> Content-Transfer-Encoding: 7BIT Cc: Eric Dumazet , Yuchung Cheng , David Miller To: netdev@vger.kernel.org Return-path: Received: from ma1-aaemail-dr-lapp03.apple.com ([17.171.2.72]:48240 "EHLO ma1-aaemail-dr-lapp03.apple.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729691AbeLNWkg (ORCPT ); Fri, 14 Dec 2018 17:40:36 -0500 In-reply-to: <20181214224007.54813-1-cpaasch@apple.com> Sender: netdev-owner@vger.kernel.org List-ID: Allow to get the full list of the listener's keypool through a getsockopt. Signed-off-by: Christoph Paasch --- net/ipv4/tcp.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 27e2f6837062..cdb317392138 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3420,21 +3420,24 @@ static int do_tcp_getsockopt(struct sock *sk, int level, return 0; case TCP_FASTOPEN_KEY: { - __u8 key[TCP_FASTOPEN_KEY_LENGTH]; + __u8 key[TCP_FASTOPEN_KEY_LENGTH * TCP_FASTOPEN_CTXT_LEN]; struct tcp_fastopen_context *ctx; + unsigned int key_len = 0; if (get_user(len, optlen)) return -EFAULT; rcu_read_lock(); ctx = rcu_dereference(icsk->icsk_accept_queue.fastopenq.ctx); - if (ctx) - memcpy(key, ctx->key, sizeof(key)); - else - len = 0; + while (ctx) { + memcpy(&key[key_len], ctx->key, TCP_FASTOPEN_KEY_LENGTH); + + key_len += TCP_FASTOPEN_KEY_LENGTH; + ctx = rcu_dereference(ctx->next); + } rcu_read_unlock(); - len = min_t(unsigned int, len, sizeof(key)); + len = min_t(unsigned int, len, key_len); if (put_user(len, optlen)) return -EFAULT; if (copy_to_user(optval, key, len)) -- 2.16.2