1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 #include <string.h> 3 #include <string.h> 4 4 5 #include <linux/stddef.h> 5 #include <linux/stddef.h> 6 #include <linux/bpf.h> 6 #include <linux/bpf.h> 7 7 8 #include <sys/socket.h> 8 #include <sys/socket.h> 9 9 10 #include <bpf/bpf_helpers.h> 10 #include <bpf/bpf_helpers.h> 11 #include <bpf/bpf_endian.h> 11 #include <bpf/bpf_endian.h> 12 12 13 #define VERDICT_REJECT 0 13 #define VERDICT_REJECT 0 14 #define VERDICT_PROCEED 1 14 #define VERDICT_PROCEED 1 15 15 16 SEC("cgroup/connect4") 16 SEC("cgroup/connect4") 17 int connect_v4_dropper(struct bpf_sock_addr *c 17 int connect_v4_dropper(struct bpf_sock_addr *ctx) 18 { 18 { 19 if (ctx->type != SOCK_STREAM) 19 if (ctx->type != SOCK_STREAM) 20 return VERDICT_PROCEED; 20 return VERDICT_PROCEED; 21 if (ctx->user_port == bpf_htons(60120) 21 if (ctx->user_port == bpf_htons(60120)) 22 return VERDICT_REJECT; 22 return VERDICT_REJECT; 23 return VERDICT_PROCEED; 23 return VERDICT_PROCEED; 24 } 24 } 25 25 26 char _license[] SEC("license") = "GPL"; 26 char _license[] SEC("license") = "GPL"; 27 27
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.