brintos

brintos / linux-shallow public Read only

0
0
Text · 965 B · d9a4016 Raw
47 lines · c
1// SPDX-License-Identifier: GPL-2.02 3#include <linux/stddef.h>4#include <linux/bpf.h>5#include <linux/in6.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 SERV6_IP_0		0xfaceb00c /* face:b00c:1234:5678::abcd */14#define SERV6_IP_1		0x1234567815#define SERV6_IP_2		0x0000000016#define SERV6_IP_3		0x0000abcd17#define SERV6_PORT		606018 19SEC("cgroup/recvmsg6")20int recvmsg6_prog(struct bpf_sock_addr *ctx)21{22	struct bpf_sock *sk;23 24	sk = ctx->sk;25	if (!sk)26		return 1;27 28	if (sk->family != AF_INET6)29		return 1;30 31	if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)32		return 1;33 34	if (!get_set_sk_priority(ctx))35		return 1;36 37	ctx->user_ip6[0] = bpf_htonl(SERV6_IP_0);38	ctx->user_ip6[1] = bpf_htonl(SERV6_IP_1);39	ctx->user_ip6[2] = bpf_htonl(SERV6_IP_2);40	ctx->user_ip6[3] = bpf_htonl(SERV6_IP_3);41	ctx->user_port = bpf_htons(SERV6_PORT);42 43	return 1;44}45 46char _license[] SEC("license") = "GPL";47