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