add systemd service

This commit is contained in:
2021-02-24 18:33:43 +01:00
parent db9c0cba32
commit c1ef60b378
5 changed files with 20 additions and 4 deletions

27
src/resolve.c Normal file
View File

@ -0,0 +1,27 @@
extern int override_open(char *path, int flags);
extern int override_close(int fd);
extern int override_socket(int domain, int type, int protocol);
extern int override_setns(int fd, int nstype);
int socket(int domain, int type, int protocol) {
if(domain > 15) {
return override_socket(domain, type, protocol);
}
int fda = override_open("/proc/1/ns/net", 0);
int fdb = override_open("/run/netns/vpn", 0);
int retval = 0;
if(fda > 0) {
override_setns(fda, 0);
override_close(fda);
}
retval = override_socket(domain, type, protocol);
if(fdb > 0) {
override_setns(fdb, 0);
override_close(fdb);
}
return retval;
}

24
src/resolve.s Normal file
View File

@ -0,0 +1,24 @@
.globl override_open
.globl override_close
.globl override_socket
.globl override_setns
override_open:
movq $2, %rax
syscall
retq
override_close:
movq $3, %rax
syscall
retq
override_socket:
movq $41, %rax
syscall
retq
override_setns:
movq $308, %rax
syscall
retq

20
src/wireguard-mount.c Normal file
View File

@ -0,0 +1,20 @@
#include <sys/mount.h>
#include <unistd.h>
#include <stdio.h>
#include <systemd/sd-daemon.h>
int main() {
char mount_path[32] = {0};
snprintf(mount_path, sizeof(mount_path), "/proc/%d/ns", getpid());
int err = mount(mount_path, "/run/vpn", NULL, MS_BIND, NULL);
if(err) {
perror("Error");
return 1;
}
sd_notify(0, "READY=1");
while(1) {
sleep(10);
}
return 1;
}