mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Allow auto port binding for cgroup connect test to avoid binding conflict. Result: ./test_progs -a cgroup_v1v2 59 cgroup_v1v2:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Link: https://lore.kernel.org/r/20250227142646.59711-2-jiayuan.chen@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
28 lines
519 B
C
28 lines
519 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <string.h>
|
|
|
|
#include <linux/stddef.h>
|
|
#include <linux/bpf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_endian.h>
|
|
|
|
#define VERDICT_REJECT 0
|
|
#define VERDICT_PROCEED 1
|
|
|
|
int port;
|
|
|
|
SEC("cgroup/connect4")
|
|
int connect_v4_dropper(struct bpf_sock_addr *ctx)
|
|
{
|
|
if (ctx->type != SOCK_STREAM)
|
|
return VERDICT_PROCEED;
|
|
if (ctx->user_port == bpf_htons(port))
|
|
return VERDICT_REJECT;
|
|
return VERDICT_PROCEED;
|
|
}
|
|
|
|
char _license[] SEC("license") = "GPL";
|