Skip to content

Commit 6475831

Browse files
nrybowskikernel-patches-bot
authored andcommitted
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> Acked-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: Nicolas Rybowski <nicolas.rybowski@tessares.net> --- 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(-)
1 parent 34221e8 commit 6475831

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,6 +4060,7 @@ struct bpf_tcp_sock {
40604060
__u32 delivered;/* Total data packets delivered incl. rexmits */
40614061
__u32 delivered_ce;/* Like the above but only ECE marked packets */
40624062
__u32 icsk_retransmits;/* Number of unrecovered [RTO] timeouts */
4063+
__u32 is_mptcp;/* Is MPTCP subflow? */
40634064
};
40644065

40654066
struct bpf_sock_tuple {

net/core/filter.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5837,7 +5837,7 @@ bool bpf_tcp_sock_is_valid_access(int off, int size, enum bpf_access_type type,
58375837
struct bpf_insn_access_aux *info)
58385838
{
58395839
if (off < 0 || off >= offsetofend(struct bpf_tcp_sock,
5840-
icsk_retransmits))
5840+
is_mptcp))
58415841
return false;
58425842

58435843
if (off % size != 0)
@@ -5971,6 +5971,13 @@ u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type,
59715971
case offsetof(struct bpf_tcp_sock, icsk_retransmits):
59725972
BPF_INET_SOCK_GET_COMMON(icsk_retransmits);
59735973
break;
5974+
case offsetof(struct bpf_tcp_sock, is_mptcp):
5975+
#ifdef CONFIG_MPTCP
5976+
BPF_TCP_SOCK_GET_COMMON(is_mptcp);
5977+
#else
5978+
*insn++ = BPF_MOV32_IMM(si->dst_reg, 0);
5979+
#endif
5980+
break;
59745981
}
59755982

59765983
return insn - insn_buf;

tools/include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,6 +4060,7 @@ struct bpf_tcp_sock {
40604060
__u32 delivered;/* Total data packets delivered incl. rexmits */
40614061
__u32 delivered_ce;/* Like the above but only ECE marked packets */
40624062
__u32 icsk_retransmits;/* Number of unrecovered [RTO] timeouts */
4063+
__u32 is_mptcp;/* Is MPTCP subflow? */
40634064
};
40644065

40654066
struct bpf_sock_tuple {

0 commit comments

Comments
 (0)