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