0001
0002
0003 #include <linux/stddef.h>
0004 #include <linux/bpf.h>
0005 #include <linux/in.h>
0006 #include <sys/socket.h>
0007
0008 #include <bpf/bpf_helpers.h>
0009 #include <bpf/bpf_endian.h>
0010
0011 #include <bpf_sockopt_helpers.h>
0012
0013 #define SERV4_IP 0xc0a801feU
0014 #define SERV4_PORT 4040
0015
0016 SEC("cgroup/recvmsg4")
0017 int recvmsg4_prog(struct bpf_sock_addr *ctx)
0018 {
0019 struct bpf_sock *sk;
0020 __u32 user_ip4;
0021 __u16 user_port;
0022
0023 sk = ctx->sk;
0024 if (!sk)
0025 return 1;
0026
0027 if (sk->family != AF_INET)
0028 return 1;
0029
0030 if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
0031 return 1;
0032
0033 if (!get_set_sk_priority(ctx))
0034 return 1;
0035
0036 ctx->user_ip4 = bpf_htonl(SERV4_IP);
0037 ctx->user_port = bpf_htons(SERV4_PORT);
0038
0039 return 1;
0040 }
0041
0042 char _license[] SEC("license") = "GPL";