1 | // SPDX-License-Identifier: GPL-2.0 |
---|---|
2 | |
3 | #include <linux/stddef.h> |
4 | #include <linux/bpf.h> |
5 | #include <linux/in.h> |
6 | #include <sys/socket.h> |
7 | |
8 | #include <bpf/bpf_helpers.h> |
9 | #include <bpf/bpf_endian.h> |
10 | |
11 | #include <bpf_sockopt_helpers.h> |
12 | |
13 | #define SERV4_IP 0xc0a801feU /* 192.168.1.254 */ |
14 | #define SERV4_PORT 4040 |
15 | |
16 | SEC("cgroup/recvmsg4") |
17 | int recvmsg4_prog(struct bpf_sock_addr *ctx) |
18 | { |
19 | struct bpf_sock *sk; |
20 | |
21 | sk = ctx->sk; |
22 | if (!sk) |
23 | return 1; |
24 | |
25 | if (sk->family != AF_INET) |
26 | return 1; |
27 | |
28 | if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM) |
29 | return 1; |
30 | |
31 | if (!get_set_sk_priority(ctx)) |
32 | return 1; |
33 | |
34 | ctx->user_ip4 = bpf_htonl(SERV4_IP); |
35 | ctx->user_port = bpf_htons(SERV4_PORT); |
36 | |
37 | return 1; |
38 | } |
39 | |
40 | char _license[] SEC("license") = "GPL"; |
41 |