syscall symbol loading fixes, makefile SDK_DEBUG tweak
This commit is contained in:
@@ -64,7 +64,7 @@ endif
|
||||
# Debug output for Network Containers
|
||||
# Specific levels can be controlled in netcon/common.inc.c
|
||||
ifeq ($(SDK_DEBUG),1)
|
||||
DEFS+=-DSDK_DEBUG
|
||||
DEFS+=-DSDK_DEBUG -g
|
||||
endif
|
||||
|
||||
# Uncomment for gprof profile build
|
||||
@@ -84,7 +84,7 @@ linux_shared_lib: remove_only_intermediates $(OBJS)
|
||||
# Build liblwip.so which must be placed in ZT home for zerotier-netcon-service to work
|
||||
make -f make-liblwip.mk
|
||||
# Use gcc not clang to build standalone intercept library since gcc is typically used for libc and we want to ensure maximal ABI compatibility
|
||||
cd src ; gcc $(DEFS) -g -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -I. -I../zerotierone/node -nostdlib -shared -o libztintercept.so SDK_Sockets.c SDK_Intercept.c SDK_Debug.c SDK_RPC.c -ldl
|
||||
cd src ; gcc $(DEFS) -O2 -Wall -std=c99 -fPIC -DVERBOSE -D_GNU_SOURCE -DSDK_INTERCEPT -I. -I../zerotierone/node -nostdlib -shared -o libztintercept.so SDK_Sockets.c SDK_Intercept.c SDK_Debug.c SDK_RPC.c -ldl
|
||||
cp src/libztintercept.so build/linux_shared_lib/libztintercept.so
|
||||
ln -sf zerotier-sdk-service zerotier-cli
|
||||
ln -sf zerotier-sdk-service zerotier-idtool
|
||||
|
||||
@@ -45,7 +45,7 @@ endif
|
||||
# Debug output for SDK
|
||||
# Specific levels can be controlled in src/debug.h
|
||||
ifeq ($(SDK_DEBUG),1)
|
||||
DEFS+=-DSDK_DEBUG
|
||||
DEFS+=-DSDK_DEBUG -g
|
||||
endif
|
||||
|
||||
CXXFLAGS=$(CFLAGS) -fno-rtti
|
||||
|
||||
30
src/SDK.h
30
src/SDK.h
@@ -43,28 +43,28 @@ void zt_init_rpc(char *path, char *nwid);
|
||||
extern char *api_netpath;
|
||||
|
||||
#if defined(__linux__)
|
||||
static int (*realaccept4)(ACCEPT4_SIG) = 0;
|
||||
extern int (*realaccept4)(ACCEPT4_SIG);
|
||||
#if !defined(__ANDROID__)
|
||||
static int (*realsyscall)(SYSCALL_SIG) = 0;
|
||||
extern int (*realsyscall)(SYSCALL_SIG);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(__ANDROID__)
|
||||
bool check_intercept_enabled_for_thread();
|
||||
static int (*realbind)(BIND_SIG) = 0;
|
||||
static int (*realsendmsg)(SENDMSG_SIG) = 0;
|
||||
static ssize_t (*realsendto)(SENDTO_SIG) = 0;
|
||||
static int (*realrecvmsg)(RECVMSG_SIG) = 0;
|
||||
static int (*realrecvfrom)(RECVFROM_SIG) = 0;
|
||||
extern int (*realbind)(BIND_SIG);
|
||||
extern int (*realsendmsg)(SENDMSG_SIG);
|
||||
extern ssize_t (*realsendto)(SENDTO_SIG);
|
||||
extern int (*realrecvmsg)(RECVMSG_SIG);
|
||||
extern int (*realrecvfrom)(RECVFROM_SIG);
|
||||
#endif
|
||||
static int (*realconnect)(CONNECT_SIG) = 0;
|
||||
static int (*realaccept)(ACCEPT_SIG) = 0;
|
||||
static int (*reallisten)(LISTEN_SIG) = 0;
|
||||
static int (*realsocket)(SOCKET_SIG) = 0;
|
||||
static int (*realsetsockopt)(SETSOCKOPT_SIG) = 0;
|
||||
static int (*realgetsockopt)(GETSOCKOPT_SIG) = 0;
|
||||
static int (*realclose)(CLOSE_SIG) = 0;
|
||||
static int (*realgetsockname)(GETSOCKNAME_SIG) = 0;
|
||||
extern int (*realconnect)(CONNECT_SIG);
|
||||
extern int (*realaccept)(ACCEPT_SIG);
|
||||
extern int (*reallisten)(LISTEN_SIG);
|
||||
extern int (*realsocket)(SOCKET_SIG);
|
||||
extern int (*realsetsockopt)(SETSOCKOPT_SIG);
|
||||
extern int (*realgetsockopt)(GETSOCKOPT_SIG);
|
||||
extern int (*realclose)(CLOSE_SIG);
|
||||
extern int (*realgetsockname)(GETSOCKNAME_SIG);
|
||||
|
||||
ssize_t zt_sendto(SENDTO_SIG);
|
||||
ssize_t zt_sendmsg(SENDMSG_SIG);
|
||||
|
||||
@@ -63,6 +63,30 @@ void dwr(int level, const char *fmt, ... );
|
||||
pthread_key_t thr_id_key;
|
||||
char *api_netpath;
|
||||
|
||||
// externs common between SDK_Intercept and SDK_Socket from SDK.h
|
||||
#if defined(__linux__)
|
||||
int (*realaccept4)(ACCEPT4_SIG) = 0;
|
||||
#if !defined(__ANDROID__)
|
||||
int (*realsyscall)(SYSCALL_SIG) = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(__ANDROID__)
|
||||
int (*realbind)(BIND_SIG) = 0;
|
||||
int (*realsendmsg)(SENDMSG_SIG) = 0;
|
||||
ssize_t (*realsendto)(SENDTO_SIG) = 0;
|
||||
int (*realrecvmsg)(RECVMSG_SIG) = 0;
|
||||
int (*realrecvfrom)(RECVFROM_SIG) = 0;
|
||||
#endif
|
||||
int (*realconnect)(CONNECT_SIG) = 0;
|
||||
int (*realaccept)(ACCEPT_SIG) = 0;
|
||||
int (*reallisten)(LISTEN_SIG) = 0;
|
||||
int (*realsocket)(SOCKET_SIG) = 0;
|
||||
int (*realsetsockopt)(SETSOCKOPT_SIG) = 0;
|
||||
int (*realgetsockopt)(GETSOCKOPT_SIG) = 0;
|
||||
int (*realclose)(CLOSE_SIG);
|
||||
int (*realgetsockname)(GETSOCKNAME_SIG) = 0;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// --------------------- Get Original socket API pointers -----------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
@@ -503,9 +527,11 @@ char *api_netpath;
|
||||
|
||||
int close(CLOSE_SIG) {
|
||||
dwr(MSG_DEBUG, " close(%d)\n", fd);
|
||||
check_intercept_enabled_for_thread();
|
||||
if(!check_intercept_enabled_for_thread()) {
|
||||
return realclose(fd);
|
||||
}
|
||||
zt_close(fd);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// -------------------------------- getsockname() -------------------------------
|
||||
|
||||
@@ -47,6 +47,10 @@
|
||||
#include "SDK.h"
|
||||
#include "SDK_RPC.h"
|
||||
|
||||
// externs common between SDK_Intercept and SDK_Socket from SDK.h
|
||||
int (*realsocket)(SOCKET_SIG);
|
||||
int (*realconnect)(CONNECT_SIG);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -74,16 +74,21 @@
|
||||
|
||||
void print_addr(struct sockaddr *addr);
|
||||
void dwr(int level, const char *fmt, ... );
|
||||
|
||||
char *api_netpath = (char *)0;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// ---------------------------------- zt_init_rpc -------------------------------
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
// Assembles (and/or) sets the RPC path for communication with the ZeroTier service
|
||||
void zt_init_rpc(char *path, char *nwid)
|
||||
{
|
||||
dwr(MSG_DEBUG, "zt_init_rpc\n");
|
||||
// Just double check we have
|
||||
if(!realconnect) {
|
||||
load_symbols();
|
||||
}
|
||||
|
||||
if(!api_netpath) {
|
||||
#if defined(SDK_BUNDLED)
|
||||
// Get the path/nwid from the user application
|
||||
@@ -373,9 +378,9 @@ char *api_netpath = (char *)0;
|
||||
struct connect_st rpc_st;
|
||||
#if defined(__linux__)
|
||||
#if !defined(__ANDROID__)
|
||||
rpc_st.__tid = syscall(SYS_gettid);
|
||||
//rpc_st.__tid = syscall(SYS_gettid);
|
||||
#else
|
||||
rpc_st.__tid = gettid(); // dummy value
|
||||
//rpc_st.__tid = gettid(); // dummy value
|
||||
#endif
|
||||
#endif
|
||||
rpc_st.__fd = __fd;
|
||||
@@ -482,8 +487,9 @@ char *api_netpath = (char *)0;
|
||||
// int fd
|
||||
|
||||
int zt_close(CLOSE_SIG) {
|
||||
dwr(MSG_DEBUG, "zt_close(%d)", fd);
|
||||
return close(fd);
|
||||
get_api_netpath();
|
||||
dwr(MSG_DEBUG, "zt_close(%d)\n", fd);
|
||||
return realclose(fd);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
if(argc < 2) {
|
||||
printf("usage: udp_client <port>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int port = atoi(argv[1]);
|
||||
|
||||
printf("cpp_udp_socket_client_test():\n");
|
||||
|
||||
Reference in New Issue
Block a user