1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 #include <linux/stddef.h> 3 #include <linux/stddef.h> 4 #include <linux/bpf.h> 4 #include <linux/bpf.h> 5 #include <linux/in6.h> 5 #include <linux/in6.h> 6 #include <sys/socket.h> 6 #include <sys/socket.h> 7 7 8 #include <bpf/bpf_helpers.h> 8 #include <bpf/bpf_helpers.h> 9 #include <bpf/bpf_endian.h> 9 #include <bpf/bpf_endian.h> 10 10 11 #include <bpf_sockopt_helpers.h> 11 #include <bpf_sockopt_helpers.h> 12 12 13 #define SERV6_IP_0 0xfaceb00c /* 13 #define SERV6_IP_0 0xfaceb00c /* face:b00c:1234:5678::abcd */ 14 #define SERV6_IP_1 0x12345678 14 #define SERV6_IP_1 0x12345678 15 #define SERV6_IP_2 0x00000000 15 #define SERV6_IP_2 0x00000000 16 #define SERV6_IP_3 0x0000abcd 16 #define SERV6_IP_3 0x0000abcd 17 #define SERV6_PORT 6060 17 #define SERV6_PORT 6060 18 18 19 SEC("cgroup/recvmsg6") 19 SEC("cgroup/recvmsg6") 20 int recvmsg6_prog(struct bpf_sock_addr *ctx) 20 int recvmsg6_prog(struct bpf_sock_addr *ctx) 21 { 21 { 22 struct bpf_sock *sk; 22 struct bpf_sock *sk; 23 23 24 sk = ctx->sk; 24 sk = ctx->sk; 25 if (!sk) 25 if (!sk) 26 return 1; 26 return 1; 27 27 28 if (sk->family != AF_INET6) 28 if (sk->family != AF_INET6) 29 return 1; 29 return 1; 30 30 31 if (ctx->type != SOCK_STREAM && ctx->t 31 if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM) 32 return 1; 32 return 1; 33 33 34 if (!get_set_sk_priority(ctx)) 34 if (!get_set_sk_priority(ctx)) 35 return 1; 35 return 1; 36 36 37 ctx->user_ip6[0] = bpf_htonl(SERV6_IP_ 37 ctx->user_ip6[0] = bpf_htonl(SERV6_IP_0); 38 ctx->user_ip6[1] = bpf_htonl(SERV6_IP_ 38 ctx->user_ip6[1] = bpf_htonl(SERV6_IP_1); 39 ctx->user_ip6[2] = bpf_htonl(SERV6_IP_ 39 ctx->user_ip6[2] = bpf_htonl(SERV6_IP_2); 40 ctx->user_ip6[3] = bpf_htonl(SERV6_IP_ 40 ctx->user_ip6[3] = bpf_htonl(SERV6_IP_3); 41 ctx->user_port = bpf_htons(SERV6_PORT) 41 ctx->user_port = bpf_htons(SERV6_PORT); 42 42 43 return 1; 43 return 1; 44 } 44 } 45 45 46 char _license[] SEC("license") = "GPL"; 46 char _license[] SEC("license") = "GPL"; 47 47
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.