0001
0002
0003 #include <linux/stddef.h>
0004 #include <linux/bpf.h>
0005 #include <linux/in6.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 SERV6_IP_0 0xfaceb00c
0014 #define SERV6_IP_1 0x12345678
0015 #define SERV6_IP_2 0x00000000
0016 #define SERV6_IP_3 0x0000abcd
0017 #define SERV6_PORT 6060
0018
0019 SEC("cgroup/recvmsg6")
0020 int recvmsg6_prog(struct bpf_sock_addr *ctx)
0021 {
0022 struct bpf_sock *sk;
0023 __u32 user_ip4;
0024 __u16 user_port;
0025
0026 sk = ctx->sk;
0027 if (!sk)
0028 return 1;
0029
0030 if (sk->family != AF_INET6)
0031 return 1;
0032
0033 if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
0034 return 1;
0035
0036 if (!get_set_sk_priority(ctx))
0037 return 1;
0038
0039 ctx->user_ip6[0] = bpf_htonl(SERV6_IP_0);
0040 ctx->user_ip6[1] = bpf_htonl(SERV6_IP_1);
0041 ctx->user_ip6[2] = bpf_htonl(SERV6_IP_2);
0042 ctx->user_ip6[3] = bpf_htonl(SERV6_IP_3);
0043 ctx->user_port = bpf_htons(SERV6_PORT);
0044
0045 return 1;
0046 }
0047
0048 char _license[] SEC("license") = "GPL";