Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 167BCC433EF for ; Tue, 11 Jan 2022 19:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235945AbiAKT36 (ORCPT ); Tue, 11 Jan 2022 14:29:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235839AbiAKT3z (ORCPT ); Tue, 11 Jan 2022 14:29:55 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07129C06173F for ; Tue, 11 Jan 2022 11:29:55 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id l15so308029pls.7 for ; Tue, 11 Jan 2022 11:29:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xzVuATJi0a8u1tXW7Evjch4xTueZKS94YDE36TE9HHo=; b=OxayUWxYOARiQlDidsYe1/FVFLBC7u7reVNeilSP1QhK7zZDv4/rX2rCOKdPWJUFKW KNmI0ToQeAZay960YHed+dTXgIcw/xhAFP0beVo5OQ55IdhQXGGNDyBcbvQSrJKjUSUu Df46CgsM0X7wnKS096QWeVpCyc7E9fWsiGhPs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xzVuATJi0a8u1tXW7Evjch4xTueZKS94YDE36TE9HHo=; b=GJWkuQyUZxq3DHcjNrri4To7BEB8sPfhuwjFdcBDBL3gG8jgBumYYMuznGxe8DiLxU OGr6WYFCkn6EgfL7trHJG0oZVtJwG+8IHSC8M/CAoLEdU1Y38d0bRrfyA/IgcU4BA5Jl MzVy6WZxQPbkLL3QyjYJnwrsmgOi6iREY1m6t9IwAd0uLYRa6noyW2Sz45w35YuIO2nk aD8ej4oDLwz5KS4kQ5dEeQ8pH2+j+ILcOKPdwbaf4MovE0wmj9YPg/QnDnTvCeecq30K nM6qztSC7ijPCMkSi2GPoZ00X0vjwWiXLJl5Q/t70UEN7pjPlTjz4Y9gNGdO1RrhuCzH W4JQ== X-Gm-Message-State: AOAM533JZnyn+L+FG0lMh7xvubtxw+V4TKldm4Va4Zp6AP5q49xK6FVu 5kZ/IRU605MUZhOBDVSi8dDdMQ== X-Google-Smtp-Source: ABdhPJx8UoJ4wIeExZ0+899Y+0oGQn2SzH4M3hBPj7bBdLfUHpD24v9QuJInPBBYgyvLkNWdoc/0jg== X-Received: by 2002:a63:7257:: with SMTP id c23mr5405701pgn.573.1641929394529; Tue, 11 Jan 2022 11:29:54 -0800 (PST) Received: from localhost ([2600:1700:2434:285f:b8b9:866f:ece3:8a5b]) by smtp.gmail.com with ESMTPSA id p1sm128333pgj.46.2022.01.11.11.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 11:29:54 -0800 (PST) From: Ivan Babrou To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@cloudflare.com, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eric Dumazet , Ivan Babrou Subject: [PATCH bpf-next] tcp: bpf: Add TCP_BPF_RCV_SSTHRESH for bpf_setsockopt Date: Tue, 11 Jan 2022 11:29:52 -0800 Message-Id: <20220111192952.49040-1-ivan@cloudflare.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds bpf_setsockopt(TCP_BPF_RCV_SSTHRESH) to allow setting rcv_ssthresh value for TCP connections. Combined with increased window_clamp via tcp_rmem[1], it allows to advertise initial scaled TCP window larger than 64k. This is useful for high BDP connections, where it allows to push data with fewer roundtrips, reducing latency. For active connections the larger window is advertised in the first non-SYN ACK packet as the part of the 3 way handshake. For passive connections the larger window is advertised whenever there's any packet to send after the 3 way handshake. See: https://lkml.org/lkml/2021/12/22/652 Signed-off-by: Ivan Babrou --- include/uapi/linux/bpf.h | 1 + net/core/filter.c | 6 ++++++ tools/include/uapi/linux/bpf.h | 1 + 3 files changed, 8 insertions(+) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 791f31dd0abe..36ebf87278bd 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5978,6 +5978,7 @@ enum { TCP_BPF_SYN = 1005, /* Copy the TCP header */ TCP_BPF_SYN_IP = 1006, /* Copy the IP[46] and TCP header */ TCP_BPF_SYN_MAC = 1007, /* Copy the MAC, IP[46], and TCP header */ + TCP_BPF_RCV_SSTHRESH = 1008, /* Set rcv_ssthresh */ }; enum { diff --git a/net/core/filter.c b/net/core/filter.c index 2e32cee2c469..aafb6066b1a6 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4904,6 +4904,12 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname, return -EINVAL; inet_csk(sk)->icsk_rto_min = timeout; break; + case TCP_BPF_RCV_SSTHRESH: + if (val <= 0) + ret = -EINVAL; + else + tp->rcv_ssthresh = min_t(u32, val, tp->window_clamp); + break; case TCP_SAVE_SYN: if (val < 0 || val > 1) ret = -EINVAL; diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 791f31dd0abe..36ebf87278bd 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5978,6 +5978,7 @@ enum { TCP_BPF_SYN = 1005, /* Copy the TCP header */ TCP_BPF_SYN_IP = 1006, /* Copy the IP[46] and TCP header */ TCP_BPF_SYN_MAC = 1007, /* Copy the MAC, IP[46], and TCP header */ + TCP_BPF_RCV_SSTHRESH = 1008, /* Set rcv_ssthresh */ }; enum { -- 2.34.1