1 // SPDX-License-Identifier: GPL-2.0
2 #include "vmlinux.h"
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
5 #include <bpf/bpf_core_read.h>
6 #include "bpf_misc.h"
7 
8 static struct sockaddr_in old;
9 
10 static int handle_sys_connect_common(struct sockaddr_in *uservaddr)
11 {
12 	struct sockaddr_in new;
13 
14 	bpf_probe_read_user(&old, sizeof(old), uservaddr);
15 	__builtin_memset(&new, 0xab, sizeof(new));
16 	bpf_probe_write_user(uservaddr, &new, sizeof(new));
17 
18 	return 0;
19 }
20 
21 SEC("ksyscall/connect")
22 int BPF_KSYSCALL(handle_sys_connect, int fd, struct sockaddr_in *uservaddr,
23 		 int addrlen)
24 {
25 	return handle_sys_connect_common(uservaddr);
26 }
27 
28 #if defined(bpf_target_s390)
29 #ifndef SYS_CONNECT
30 #define SYS_CONNECT 3
31 #endif
32 
33 SEC("ksyscall/socketcall")
34 int BPF_KSYSCALL(handle_sys_socketcall, int call, unsigned long *args)
35 {
36 	if (call == SYS_CONNECT) {
37 		struct sockaddr_in *uservaddr;
38 
39 		bpf_probe_read_user(&uservaddr, sizeof(uservaddr), &args[1]);
40 		return handle_sys_connect_common(uservaddr);
41 	}
42 
43 	return 0;
44 }
45 #endif
46 
47 char _license[] SEC("license") = "GPL";
48