1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <string.h>
4 
5 #include <linux/stddef.h>
6 #include <linux/bpf.h>
7 
8 #include <sys/socket.h>
9 
10 #include <bpf/bpf_helpers.h>
11 #include <bpf/bpf_endian.h>
12 
13 #define VERDICT_REJECT	0
14 #define VERDICT_PROCEED	1
15 
16 int port;
17 
18 SEC("cgroup/connect4")
connect_v4_dropper(struct bpf_sock_addr * ctx)19 int connect_v4_dropper(struct bpf_sock_addr *ctx)
20 {
21 	if (ctx->type != SOCK_STREAM)
22 		return VERDICT_PROCEED;
23 	if (ctx->user_port == bpf_htons(port))
24 		return VERDICT_REJECT;
25 	return VERDICT_PROCEED;
26 }
27 
28 char _license[] SEC("license") = "GPL";
29