Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1148455pxk; Fri, 18 Sep 2020 05:14:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF9RlSxjoonswNPbA5hY7s7NUoIEPmCb9ItSsh/Qo9cqMTv05VGsJ41WW29++TmBTwlb5n X-Received: by 2002:aa7:d88a:: with SMTP id u10mr38546793edq.217.1600431240720; Fri, 18 Sep 2020 05:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600431240; cv=none; d=google.com; s=arc-20160816; b=eS2NaSF8RYx3ARWMVRGbt2LFQzD4HKnppc6svxgpVABH12DqmzulI8t0d+wID2UcKh YAkV/IS2W/HJk7OWpVbEj3o/bdJvxZfqrF9ygI3tQAmFjF+9N3u3nUwNag1MFSM8BDIx DtTcYIC9wTKGlPCeTcOHyWcrlzqSX5AkZYBD64No8nRSIzRWkawRevnVZOYqnX6f9ExJ Fyg6uwiRwcV8+Pxc0ULWK6PNEoNmtYJ6tVsZjlAsJXSYce753td3zIb6VWGHqYT7psPc fLNRVRFfNBNNwktD5cZn1SEtEdrszOgvO3LeKUMuHPOaN0gy9v2Mdm7sNbor8mUltpLd vKEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CbLoMvbCVZR7v2qr1uLu68maulfUQM+3TJzgKeP8L7U=; b=G/ueedtVe/SqBScsqogx6bMEXrAIfeKEKdW6DHJMB7zq16xMWKnq7zJcL9gtThFI0r vNFFddQ7/ufn1tQHDYQlLxJJNkgFfQvg98uiD+zCnAxhCyFWUOMZ1C0rBIqD5FT00KP9 pXJUayGg5LmQlnGFimgjzGOx061by737rZVmQ3Qv9hnr+cANy58333c2UEZ8yOUbpT1f ZlhhYd66MzA4fYSHW/ONB+N0N29ruwSBRG6G/CnjepQkDqjynkd04EfusVrgX44zSzno iTMTaWOpiA2fHUjpwVrUeWdLfKesx4zQdJq405jI/uRAtY23WDkCSx+zbXxSNWv68Ehn 1DPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b="ARLlP/MI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x1si2070307edq.177.2020.09.18.05.13.36; Fri, 18 Sep 2020 05:14:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b="ARLlP/MI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726588AbgIRMMf (ORCPT + 99 others); Fri, 18 Sep 2020 08:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgIRMMd (ORCPT ); Fri, 18 Sep 2020 08:12:33 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 561BCC06174A for ; Fri, 18 Sep 2020 05:12:33 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id ay8so5828866edb.8 for ; Fri, 18 Sep 2020 05:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CbLoMvbCVZR7v2qr1uLu68maulfUQM+3TJzgKeP8L7U=; b=ARLlP/MI0ddfuPiVcUweomzB1eTSRRV+yworw6SVPrtnqjFn6hOLe3fLWaLcaMkXwe enMhMKYrQQr5fEc0mb+IwCxK8QepcWsINr9KN8R1XNYOm841LzFb6GDySIeZRQNz6X11 ObJbBnLjmkABvmgRrdLKXSodve6GlaxbVn61a4QhINKVKHCS+R+Hn5LvEzy4TafoK5OI oYS8Ph48ZVpAd9DdKOLU8Sa/5e5Vt3cjTmZ73j2pWpe3ZHg/XqQtvPyMYnYjz6lMdLNC RtM+C+cDCJWWuHRb+e/4a35WlkbWRvJEPLEJsUs1+yXnZl4v2PRwEbvoG1jw9Aj07QaQ tAfw== 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:mime-version :content-transfer-encoding; bh=CbLoMvbCVZR7v2qr1uLu68maulfUQM+3TJzgKeP8L7U=; b=T0d3QbXjQFelTJ21CexDs1Tn8IHHU5YhYreNrhf4oAdQx5LEO0sBol068AMKjqr9Bo /CZ2ZWYLdslo86R4d+i0FneMYDxJBW4Kn5v0+obIbwMxPCnKMElgryCvlilPprqtqzOR ThvJo2Wc/eUCkKE2sH7u+9RXYdMh5sTzPuDtBTfCZfYJSmkVBqHPZwryzJonMGS90XRS 68gW8Vq5R71oM/q1kQg8mJZpK+xiAX/TbttPpHWR2gqVMTL3MlWYFkVBdRCv5Gw0tNf3 quSATX3Gc9pr0XPS+8XJBIW8uktBLTkCN1vs0o9hJrztmAX52aIMhDyTypPWEmaDoSI3 3Kmw== X-Gm-Message-State: AOAM531BsXVirJCyx2FdLpMmMlOblMSlSDnCHRpEBQ1aWzM59TaOUOOu XVSOmc4eZ1VUN3z2JPfZcFghXw== X-Received: by 2002:a50:f687:: with SMTP id d7mr39717142edn.353.1600431152011; Fri, 18 Sep 2020 05:12:32 -0700 (PDT) Received: from localhost.localdomain ([87.66.33.240]) by smtp.gmail.com with ESMTPSA id h64sm2084555edd.50.2020.09.18.05.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 05:12:31 -0700 (PDT) From: Nicolas Rybowski To: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , "David S. Miller" , Jakub Kicinski Cc: Nicolas Rybowski , Matthieu Baerts , Mat Martineau , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v3 1/5] bpf: expose is_mptcp flag to bpf_tcp_sock Date: Fri, 18 Sep 2020 14:10:40 +0200 Message-Id: <20200918121046.190240-1-nicolas.rybowski@tessares.net> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org is_mptcp is a field from struct tcp_sock used to indicate that the current tcp_sock is part of the MPTCP protocol. In this protocol, a first socket (mptcp_sock) is created with sk_protocol set to IPPROTO_MPTCP (=262) for control purpose but it isn't directly on the wire. This is the role of the subflow (kernel) sockets which are classical tcp_sock with sk_protocol set to IPPROTO_TCP. The only way to differentiate such sockets from plain TCP sockets is the is_mptcp field from tcp_sock. Such an exposure in BPF is thus required to be able to differentiate plain TCP sockets from MPTCP subflow sockets in BPF_PROG_TYPE_SOCK_OPS programs. The choice has been made to silently pass the case when CONFIG_MPTCP is unset by defaulting is_mptcp to 0 in order to make BPF independent of the MPTCP configuration. Another solution is to make the verifier fail in 'bpf_tcp_sock_is_valid_ctx_access' but this will add an additional '#ifdef CONFIG_MPTCP' in the BPF code and a same injected BPF program will not run if MPTCP is not set. An example use-case is provided in https://github.com/multipath-tcp/mptcp_net-next/tree/scripts/bpf/examples Suggested-by: Matthieu Baerts Acked-by: Matthieu Baerts Acked-by: Mat Martineau Signed-off-by: Nicolas Rybowski --- include/uapi/linux/bpf.h | 1 + net/core/filter.c | 9 ++++++++- tools/include/uapi/linux/bpf.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index a22812561064..351b3d0a6ca8 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -4067,6 +4067,7 @@ struct bpf_tcp_sock { __u32 delivered; /* Total data packets delivered incl. rexmits */ __u32 delivered_ce; /* Like the above but only ECE marked packets */ __u32 icsk_retransmits; /* Number of unrecovered [RTO] timeouts */ + __u32 is_mptcp; /* Is MPTCP subflow? */ }; struct bpf_sock_tuple { diff --git a/net/core/filter.c b/net/core/filter.c index d266c6941967..dab48528dceb 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5837,7 +5837,7 @@ bool bpf_tcp_sock_is_valid_access(int off, int size, enum bpf_access_type type, struct bpf_insn_access_aux *info) { if (off < 0 || off >= offsetofend(struct bpf_tcp_sock, - icsk_retransmits)) + is_mptcp)) return false; if (off % size != 0) @@ -5971,6 +5971,13 @@ u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type, case offsetof(struct bpf_tcp_sock, icsk_retransmits): BPF_INET_SOCK_GET_COMMON(icsk_retransmits); break; + case offsetof(struct bpf_tcp_sock, is_mptcp): +#ifdef CONFIG_MPTCP + BPF_TCP_SOCK_GET_COMMON(is_mptcp); +#else + *insn++ = BPF_MOV32_IMM(si->dst_reg, 0); +#endif + break; } return insn - insn_buf; diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index a22812561064..351b3d0a6ca8 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -4067,6 +4067,7 @@ struct bpf_tcp_sock { __u32 delivered; /* Total data packets delivered incl. rexmits */ __u32 delivered_ce; /* Like the above but only ECE marked packets */ __u32 icsk_retransmits; /* Number of unrecovered [RTO] timeouts */ + __u32 is_mptcp; /* Is MPTCP subflow? */ }; struct bpf_sock_tuple { -- 2.28.0