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") getsockname_v4_prog(struct bpf_sock_addr * ctx)16int 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"; 25