]> Git Repo - linux.git/blob - tools/testing/selftests/bpf/progs/getsockname4_prog.c
Linux 6.14-rc3
[linux.git] / tools / testing / selftests / bpf / progs / getsockname4_prog.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Google LLC */
3
4 #include "vmlinux.h"
5
6 #include <string.h>
7 #include <bpf/bpf_helpers.h>
8 #include <bpf/bpf_endian.h>
9 #include <bpf/bpf_core_read.h>
10 #include "bpf_kfuncs.h"
11
12 #define REWRITE_ADDRESS_IP4   0xc0a801fe // 192.168.1.254
13 #define REWRITE_ADDRESS_PORT4 4040
14
15 SEC("cgroup/getsockname4")
16 int getsockname_v4_prog(struct bpf_sock_addr *ctx)
17 {
18         ctx->user_ip4 = bpf_htonl(REWRITE_ADDRESS_IP4);
19         ctx->user_port = bpf_htons(REWRITE_ADDRESS_PORT4);
20
21         return 1;
22 }
23
24 char _license[] SEC("license") = "GPL";
This page took 0.033322 seconds and 4 git commands to generate.