From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B646315A5 for ; Wed, 11 May 2022 06:10:45 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id m12so913545plb.4 for ; Tue, 10 May 2022 23:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Rxwmw7F4yraTtQttPtF/0wZ/ikGq2Rscn+f5iMrT7V8=; b=hk5nmcxWqr1+4XZIG4Y2EoHdn4MFyQuBSg3wMbJB03xCN3J0/fGQJI9kJKzQLLlWfP ZDVe37fm/UkBmm/PkjCtG1P4jelVut0rqGMNUuM6eaNwDqMDWJXOAVNl43inn/9fzuiX 08PIOuW+zLnKULD33PrfJiIhTaBGApajk5KJgbDuUBGdDqvD325R1qkKy6xn2plIZWb6 q0aQvfYNQ6zMw9ug/iMN/mRFoKLZLTd/4HF2ZzjOoZxf4gLk0u7t38GhennBESJ0W/R3 gpWBhIKHac6jv9zJ8sSWOg69s2c3x674NJk5GSfVmEAeoaiakgRb0u/l55Wh9RH3czUw sUqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Rxwmw7F4yraTtQttPtF/0wZ/ikGq2Rscn+f5iMrT7V8=; b=p77daCVbpcDmZ2hWDT6v2HfV5MmE7yaXBsQpQxIpBA3lGmpj7VTxp/WyVbAwF/P441 +PinExegaP9IhQCC+yPaq/1nJaIoVBKNyhnOGziGtcT0RKxHIv8YOZKK5y0fFHcCLuUv S46vQRLNUiedbJ1LbEL96WkVZOWk1yMOoUcDFjvvXVyZlLFmxgYE5wDBqhOrRJ+xFXbm NCgNWeL0yStsdHmpHr6LxJwTzo2VuIGrH10gL2cCS8KlAAs8lOGif3sGxLsjV04rQvje hxs8DGcj2NFjHIiR6UHgylhrvjtD7Z75IZtG3mCVmbEIGvA1sccbNIwNB48GOCaw7KFA 0BXQ== X-Gm-Message-State: AOAM5315ib8DUOlqYAnM20FISd8AXPEm+PYtRwB3hmPOo8HG0FnPm2Sr tGibA2qr2se2Bnp8mqbARMP8bY7yx/nnxAM4p70= X-Google-Smtp-Source: ABdhPJyvXv/OGzpotKsy1AIe0kD136J2PA88iaQfJStWhn17wXqCV6y8+g7+UBAut26mWSxafLKVkQRZipa4VxIIYG4= X-Received: by 2002:a17:902:8f8d:b0:15b:7b98:22e6 with SMTP id z13-20020a1709028f8d00b0015b7b9822e6mr23907991plo.102.1652249445174; Tue, 10 May 2022 23:10:45 -0700 (PDT) Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20220502211235.142250-1-mathew.j.martineau@linux.intel.com> <20220502211235.142250-2-mathew.j.martineau@linux.intel.com> <20220511004818.qnfpzgepmg7xufwd@kafai-mbp.dhcp.thefacebook.com> In-Reply-To: From: Geliang Tang Date: Wed, 11 May 2022 14:10:42 +0800 Message-ID: Subject: Re: [PATCH bpf-next v3 1/8] bpf: expose is_mptcp flag to bpf_tcp_sock To: Andrii Nakryiko Cc: Martin KaFai Lau , Mat Martineau , Andrii Nakryiko , Networking , bpf , Nicolas Rybowski , Alexei Starovoitov , Daniel Borkmann , MPTCP Upstream , Matthieu Baerts Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Andrii Nakryiko =E4=BA=8E2022=E5=B9=B45=E6=9C= =8811=E6=97=A5=E5=91=A8=E4=B8=89 13:02=E5=86=99=E9=81=93=EF=BC=9A > > On Tue, May 10, 2022 at 5:48 PM Martin KaFai Lau wrote: > > > > On Mon, May 02, 2022 at 02:12:27PM -0700, Mat Martineau wrote: > > > From: Nicolas Rybowski > > > > > > 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 (=3D262) 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 TC= P > > > 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_OP= S > > > 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 fai= l > > > 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. > > There is already bpf_skc_to_tcp_sock() and its returned tcp_sock pointe= r > > can access all fields of the "struct tcp_sock" without extending > > the bpf_tcp_sock. > > > > iiuc, I believe the needs to extend bpf_tcp_sock here is to make the > > same bpf sockops prog works for kernel with and without CONFIG_MPTCP > > because tp->is_mptcp is not always available: > > > > struct tcp_sock { > > /* ... */ > > > > #if IS_ENABLED(CONFIG_MPTCP) > > bool is_mptcp; > > #endif > > }; > > > > Andrii, do you think bpf_core_field_exists() can be used in > > the bpf prog to test if is_mptcp is available in the running kernel > > such that the same bpf prog can be used in kernel with and without > > CONFIG_MPTCP? > > yep, absolutely: > > bool is_mptcp =3D bpf_core_field_exists(struct tcp_sock, is_mptcp) ? > sock->is_mptcp : false; > > One can also directly check if CONFIG_MPTCP is set with the following > in BPF-side code: > > extern bool CONFIG_MPTCP __kconfig; Thanks Martin & Andrii, will update this in v4. -Geliang SUSE >