diff options
-rwxr-xr-x | .gitignore | 2 | ||||
-rw-r--r-- | make-linux.mk | 18 | ||||
-rw-r--r-- | netcon/Intercept.c | 47 | ||||
-rw-r--r-- | netcon/Intercept.h | 1 |
4 files changed, 30 insertions, 38 deletions
@@ -33,8 +33,6 @@ Thumbs.db /examples/docker/test-*.env /world/mkworld /world/*.c25519 -/tiny-httpd -/netcon/tiny-httpd # Miscellaneous temporaries, build files, etc. *.log diff --git a/make-linux.mk b/make-linux.mk index 5e3658a0..1e6d0270 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -105,15 +105,15 @@ netcon: $(OBJS) ln -sf zerotier-netcon-service zerotier-cli ln -sf zerotier-netcon-service zerotier-idtool -install-intercept: - cp libzerotierintercept.so /lib/libzerotierintercept.so - ln -sf /lib/libzerotierintercept.so /lib/libzerotierintercept - /usr/bin/install -c netcon/zerotier-intercept /usr/bin - -uninstall-intercept: - rm -r /lib/libzerotierintercept.so - rm -r /lib/libzerotierintercept - rm -r /usr/bin/zerotier-intercept +#install-intercept: +# cp libzerotierintercept.so /lib/libzerotierintercept.so +# ln -sf /lib/libzerotierintercept.so /lib/libzerotierintercept +# /usr/bin/install -c netcon/zerotier-intercept /usr/bin + +#uninstall-intercept: +# rm -r /lib/libzerotierintercept.so +# rm -r /lib/libzerotierintercept +# rm -r /usr/bin/zerotier-intercept selftest: $(OBJS) selftest.o $(CXX) $(CXXFLAGS) $(LDFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LDLIBS) diff --git a/netcon/Intercept.c b/netcon/Intercept.c index 3890c08b..30d57901 100644 --- a/netcon/Intercept.c +++ b/netcon/Intercept.c @@ -75,6 +75,7 @@ static int (*realclose)(CLOSE_SIG); static int (*realclone)(CLONE_SIG); static int (*realdup2)(DUP2_SIG); static int (*realdup3)(DUP3_SIG); +static int (*realgetsockname)(GETSOCKNAME_SIG); /* Exported Function Prototypes */ void my_init(void); @@ -92,6 +93,7 @@ int close(CLOSE_SIG); int clone(CLONE_SIG); int dup2(DUP2_SIG); int dup3(DUP3_SIG); +int getsockname(GETSOCKNAME_SIG); int connect_to_service(void); int init_service_connection(); @@ -309,16 +311,11 @@ void my_dest(void) { void load_symbols(void) { -#ifdef USE_OLD_DLSYM - void *lib; -#endif - /* possibly add check to beginning of each method to avoid needing to cll the constructor */ if(thispid == getpid()) { - dwr(MSG_DEBUG,"detected duplicate call to global ctor (pid=%d).\n", thispid); + dwr(MSG_DEBUG,"detected duplicate call to global constructor (pid=%d).\n", thispid); } thispid = getpid(); -#ifndef USE_OLD_DLSYM realconnect = dlsym(RTLD_NEXT, "connect"); realbind = dlsym(RTLD_NEXT, "bind"); realaccept = dlsym(RTLD_NEXT, "accept"); @@ -334,26 +331,7 @@ void load_symbols(void) realsyscall = dlsym(RTLD_NEXT, "syscall"); realdup2 = dlsym(RTLD_NEXT, "dup2"); realdup3 = dlsym(RTLD_NEXT, "dup3"); -#else - lib = dlopen(LIBCONNECT, RTLD_LAZY); - realconnect = dlsym(lib, "connect"); - realbind = dlsym(lib, "bind"); - realaccept = dlsym(lib, "accept"); - reallisten = dlsym(lib, "listen"); - realsocket = dlsym(lib, "socket"); - realselect = dlsym(lib, "select"); - realsetsockopt = dlsym(lib, "setsockopt"); - realgetsockopt = dlsym(lib, "getsockopt"); - realaccept4 = dlsym(lib), "accept4"); - realclone = dlsym(lib, "clone"); - realclose = dlsym(lib, "close"); - realsyscall = dlsym(lib, "syscall"); - realdup2 = dlsym(RTLD_NEXT, "dup2"); - realdup3 = dlsym(RTLD_NEXT, "dup3"); - dlclose(lib); - lib = dlopen(LIBC, RTLD_LAZY); - dlclose(lib); -#endif + realgetsockname = dlsym(RTLD_NEXT, "getsockname"); } /* Private Function Prototypes */ @@ -825,7 +803,7 @@ int accept(ACCEPT_SIG) } /* The following line is required for libuv/nodejs to accept connections properly, - however, this has the side effect of causing certain webservers to max out the CPU + however, this has the side effect of causing certain webservers to max out the CPU in an accept loop */ //fcntl(sockfd, F_SETFL, O_NONBLOCK); @@ -1040,6 +1018,21 @@ int dup3(DUP3_SIG) return realdup3(oldfd, newfd, flags); } +/*------------------------------------------------------------------------------ +-------------------------------------- getsockname()---------------------------- +------------------------------------------------------------------------------*/ + +int getsockname(GETSOCKNAME_SIG) +{ + if (realgetsockname == NULL) { + dwr(MSG_ERROR, "getsockname(): SYMBOL NOT FOUND.\n"); + return -1; + } + + // TODO + + return realgetsockname(sockfd,addr,addrlen); +} /*------------------------------------------------------------------------------ ------------------------------------ syscall()---------------------------------- diff --git a/netcon/Intercept.h b/netcon/Intercept.h index ef10dc64..0a9103ad 100644 --- a/netcon/Intercept.h +++ b/netcon/Intercept.h @@ -185,6 +185,7 @@ struct shutdown_st #define SYSCALL_SIG long number, ... #define CLONE_SIG int (*fn)(void *), void *child_stack, int flags, void *arg, ... #define POLL_SIG struct pollfd *fds, nfds_t nfds, int timeout +#define GETSOCKNAME_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen #define DUP2_SIG int oldfd, int newfd #define DUP3_SIG int oldfd, int newfd, int flags |