From patchwork Fri Aug 21 15:15:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Rybowski X-Patchwork-Id: 262112 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF450C433E1 for ; Fri, 21 Aug 2020 15:19:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C27A207BB for ; Fri, 21 Aug 2020 15:19:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=tessares-net.20150623.gappssmtp.com header.i=@tessares-net.20150623.gappssmtp.com header.b="1yxK8FrA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728355AbgHUPTL (ORCPT ); Fri, 21 Aug 2020 11:19:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728153AbgHUPSP (ORCPT ); Fri, 21 Aug 2020 11:18:15 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B29F6C061573 for ; Fri, 21 Aug 2020 08:18:13 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id df16so1715974edb.9 for ; Fri, 21 Aug 2020 08:18:13 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=rQR67AqDgTFceM1GcH2o1VP0eXhNCBh9bwg17gfoTgU=; b=1yxK8FrAf4JsUoVuTMaIeajsDp7BkyBW/nIt5zPEpq0A5jbvKscdEPur41ES+s4LjB YzceM+KnfPfM0ob8s3SLA4DJz5LU2oDIc6HO0bh5W5xf1Gw9UeC7/XaFhXGaq4OLW2+n 4IDSN/klhWSlzfzWyN2TeMrYu+EUk5dtYqlkp4tZI4UFmSMJEgTMR/1J4iR/4A1Gv8ox 8G3+ez8CiW0u2ok6Ib3LW/QAfL6m9uguROWnrZuIUjMhqb9BrvHQO/CgTa7PY81DOBCh 9H7PoNj7mTzRcz4nHkV26CikoPkkdUFhFD2v7vX/dXYE8M/sBlKgane36KSzePtex7x0 3IAA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=rQR67AqDgTFceM1GcH2o1VP0eXhNCBh9bwg17gfoTgU=; b=HHDVJvdxCuYqOwFL4xRu8U1kHI78lyUFlecy2REaMbN9gBYMt63omKRDl3hGxYGgWP g8XLSLRDOVF36/rG3W2Gsne3+Po6SvRYKJM0RlpVdSPqwZC6I4RaN5CngjQ2dgKOC1Q3 mjDyOhw0TQjgFcSjAbAUyM96n043QG82YsvDpelsaCOEmXYyClzj6cOnX/flAPK+MMU3 e5UXY5UhzZd5ff03/wmbShbB4k5ytPBsyTbtEZmrRmm0ot4mmeHI81P3+0iz3PZH68xP 6BUy26QjzO851ltdsuOwn09Cb8p2oHCMBEmIf3JPSoR7l9TWRj4B2AgiFAcC3qS1HT1D TFpw== X-Gm-Message-State: AOAM5325O1d3HJGaizmv8pibA1Tv3ns2mzsUSZaMzJKF3P+DIBT9Kdpa COVO/gfuSqIPJ/Z6ZFWWTPUQTQ== X-Google-Smtp-Source: ABdhPJyi0tkiH5q/ltl//GjdPiGKtU+rjkFW0l048hREebCe9VF5uhvGKNPNQnNuLlWSRFI9KMG57g== X-Received: by 2002:a50:93a2:: with SMTP id o31mr3343896eda.203.1598023092403; Fri, 21 Aug 2020 08:18:12 -0700 (PDT) Received: from localhost.localdomain (223.60-242-81.adsl-dyn.isp.belgacom.be. [81.242.60.223]) by smtp.gmail.com with ESMTPSA id qp16sm1482709ejb.89.2020.08.21.08.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 08:18:11 -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 1/3] bpf: expose is_mptcp flag to bpf_tcp_sock Date: Fri, 21 Aug 2020 17:15:39 +0200 Message-Id: <20200821151544.1211989-2-nicolas.rybowski@tessares.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200821151544.1211989-1-nicolas.rybowski@tessares.net> References: <20200821151544.1211989-1-nicolas.rybowski@tessares.net> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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 0480f893facd..a9fccfdb3a62 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -3865,6 +3865,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 b2df52086445..eb400aeea282 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5742,7 +5742,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) @@ -5876,6 +5876,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 0480f893facd..a9fccfdb3a62 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -3865,6 +3865,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 {