Files
linux/tools/testing/selftests/bpf/progs/mptcp_sockmap.c
Jiayuan Chen cb730e4ac1 selftests/bpf: Add mptcp test with sockmap
Add test cases to verify that when MPTCP falls back to plain TCP sockets,
they can properly work with sockmap.

Additionally, add test cases to ensure that sockmap correctly rejects
MPTCP sockets as expected.

Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20251111060307.194196-4-jiayuan.chen@linux.dev
2025-11-13 13:18:25 -08:00

44 lines
943 B
C

// SPDX-License-Identifier: GPL-2.0
#include "bpf_tracing_net.h"
char _license[] SEC("license") = "GPL";
int sk_index;
int redirect_idx;
int trace_port;
int helper_ret;
struct {
__uint(type, BPF_MAP_TYPE_SOCKMAP);
__uint(key_size, sizeof(__u32));
__uint(value_size, sizeof(__u32));
__uint(max_entries, 100);
} sock_map SEC(".maps");
SEC("sockops")
int mptcp_sockmap_inject(struct bpf_sock_ops *skops)
{
struct bpf_sock *sk;
/* only accept specified connection */
if (skops->local_port != trace_port ||
skops->op != BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB)
return 1;
sk = skops->sk;
if (!sk)
return 1;
/* update sk handler */
helper_ret = bpf_sock_map_update(skops, &sock_map, &sk_index, BPF_NOEXIST);
return 1;
}
SEC("sk_skb/stream_verdict")
int mptcp_sockmap_redirect(struct __sk_buff *skb)
{
/* redirect skb to the sk under sock_map[redirect_idx] */
return bpf_sk_redirect_map(skb, &sock_map, redirect_idx, 0);
}