1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/tools/testing/selftests/bpf/progs/recvmsg4_prog.c
Andrii Nakryiko c8ed668593 selftests/bpf: fix lots of silly mistakes pointed out by compiler
Once we enable -Wall for BPF sources, compiler will complain about lots
of unused variables, variables that are set but never read, etc.

Fix all these issues first before enabling -Wall in Makefile.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20230309054015.4068562-4-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-03-10 08:14:08 -08:00

40 lines
723 B
C

// SPDX-License-Identifier: GPL-2.0
#include <linux/stddef.h>
#include <linux/bpf.h>
#include <linux/in.h>
#include <sys/socket.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>
#include <bpf_sockopt_helpers.h>
#define SERV4_IP 0xc0a801feU /* 192.168.1.254 */
#define SERV4_PORT 4040
SEC("cgroup/recvmsg4")
int recvmsg4_prog(struct bpf_sock_addr *ctx)
{
struct bpf_sock *sk;
sk = ctx->sk;
if (!sk)
return 1;
if (sk->family != AF_INET)
return 1;
if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
return 1;
if (!get_set_sk_priority(ctx))
return 1;
ctx->user_ip4 = bpf_htonl(SERV4_IP);
ctx->user_port = bpf_htons(SERV4_PORT);
return 1;
}
char _license[] SEC("license") = "GPL";