staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / sendmsg6_prog.c
bloba680628204108b41d0c046a5371cec9f2cfedc0b
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018 Facebook
4 #include <linux/stddef.h>
5 #include <linux/bpf.h>
6 #include <sys/socket.h>
8 #include "bpf_helpers.h"
9 #include "bpf_endian.h"
11 #define SRC_REWRITE_IP6_0 0
12 #define SRC_REWRITE_IP6_1 0
13 #define SRC_REWRITE_IP6_2 0
14 #define SRC_REWRITE_IP6_3 6
16 #define DST_REWRITE_IP6_0 0
17 #define DST_REWRITE_IP6_1 0
18 #define DST_REWRITE_IP6_2 0
19 #define DST_REWRITE_IP6_3 1
21 #define DST_REWRITE_PORT6 6666
23 int _version SEC("version") = 1;
25 SEC("cgroup/sendmsg6")
26 int sendmsg_v6_prog(struct bpf_sock_addr *ctx)
28 if (ctx->type != SOCK_DGRAM)
29 return 0;
31 /* Rewrite source. */
32 if (ctx->msg_src_ip6[3] == bpf_htonl(1) ||
33 ctx->msg_src_ip6[3] == bpf_htonl(0)) {
34 ctx->msg_src_ip6[0] = bpf_htonl(SRC_REWRITE_IP6_0);
35 ctx->msg_src_ip6[1] = bpf_htonl(SRC_REWRITE_IP6_1);
36 ctx->msg_src_ip6[2] = bpf_htonl(SRC_REWRITE_IP6_2);
37 ctx->msg_src_ip6[3] = bpf_htonl(SRC_REWRITE_IP6_3);
38 } else {
39 /* Unexpected source. Reject sendmsg. */
40 return 0;
43 /* Rewrite destination. */
44 if (ctx->user_ip6[0] == bpf_htonl(0xFACEB00C)) {
45 ctx->user_ip6[0] = bpf_htonl(DST_REWRITE_IP6_0);
46 ctx->user_ip6[1] = bpf_htonl(DST_REWRITE_IP6_1);
47 ctx->user_ip6[2] = bpf_htonl(DST_REWRITE_IP6_2);
48 ctx->user_ip6[3] = bpf_htonl(DST_REWRITE_IP6_3);
50 ctx->user_port = bpf_htons(DST_REWRITE_PORT6);
51 } else {
52 /* Unexpected destination. Reject sendmsg. */
53 return 0;
56 return 1;
59 char _license[] SEC("license") = "GPL";