From: Mat Martineau <mathew.j.martineau@linux.intel.com>
To: netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: Nicolas Rybowski <nicolas.rybowski@tessares.net>,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
mptcp@lists.linux.dev,
Matthieu Baerts <matthieu.baerts@tessares.net>,
Mat Martineau <mathew.j.martineau@linux.intel.com>
Subject: [PATCH bpf-next 1/7] bpf: expose is_mptcp flag to bpf_tcp_sock
Date: Wed, 20 Apr 2022 15:24:53 -0700 [thread overview]
Message-ID: <20220420222459.307649-2-mathew.j.martineau@linux.intel.com> (raw)
In-Reply-To: <20220420222459.307649-1-mathew.j.martineau@linux.intel.com>
From: Nicolas Rybowski <nicolas.rybowski@tessares.net>
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 <matthieu.baerts@tessares.net>
Acked-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Nicolas Rybowski <nicolas.rybowski@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
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 d14b10b85e51..9ef1f3e1c22f 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -5694,6 +5694,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 143f442a9505..7b1867f1f422 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -6754,7 +6754,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)
@@ -6888,6 +6888,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 d14b10b85e51..9ef1f3e1c22f 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -5694,6 +5694,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.36.0
next prev parent reply other threads:[~2022-04-20 22:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-20 22:24 [PATCH bpf-next 0/7] bpf: mptcp: Support for mptcp_sock and is_mptcp Mat Martineau
2022-04-20 22:24 ` Mat Martineau [this message]
2022-04-20 22:24 ` [PATCH bpf-next 2/7] bpf: add bpf_skc_to_mptcp_sock_proto Mat Martineau
2022-04-25 14:26 ` Daniel Borkmann
2022-04-25 14:29 ` Daniel Borkmann
2022-04-26 6:36 ` Andrii Nakryiko
2022-04-25 18:35 ` Mat Martineau
2022-04-25 14:33 ` Daniel Borkmann
2022-04-25 18:11 ` Mat Martineau
2022-04-20 22:24 ` [PATCH bpf-next 3/7] selftests: bpf: add MPTCP test base Mat Martineau
2022-04-20 22:24 ` [PATCH bpf-next 4/7] selftests: bpf: test bpf_skc_to_mptcp_sock Mat Martineau
2022-04-20 22:24 ` [PATCH bpf-next 5/7] selftests: bpf: verify token of struct mptcp_sock Mat Martineau
2022-04-20 22:24 ` [PATCH bpf-next 6/7] selftests: bpf: verify ca_name " Mat Martineau
2022-04-20 22:24 ` [PATCH bpf-next 7/7] selftests: bpf: verify first " Mat Martineau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220420222459.307649-2-mathew.j.martineau@linux.intel.com \
--to=mathew.j.martineau@linux.intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=matthieu.baerts@tessares.net \
--cc=mptcp@lists.linux.dev \
--cc=netdev@vger.kernel.org \
--cc=nicolas.rybowski@tessares.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox