0
0
mirror of https://github.com/bol-van/zapret.git synced 2025-06-30 18:43:05 +00:00

nfqws,tpws: --debug=android for NDK builds

This commit is contained in:
bol-van 2025-05-31 10:34:03 +03:00
parent 893a133f86
commit 87a0cf0797
9 changed files with 143 additions and 26 deletions

View File

@ -507,5 +507,6 @@ v71.1
nfqws,tpws: much faster ipset implementation. move from hash to avl tree nfqws,tpws: much faster ipset implementation. move from hash to avl tree
nfqws,tpws: check list files accessibility with dropped privs in --dry-run mode nfqws,tpws: check list files accessibility with dropped privs in --dry-run mode
nfqws,tpws: --debug=android for NDK builds
install_easy: stop if running embedded release on traditional linux system (some files missing) install_easy: stop if running embedded release on traditional linux system (some files missing)
install_bin: add "read elf" arch detection method install_bin: add "read elf" arch detection method

View File

@ -3,6 +3,7 @@ CFLAGS += -std=gnu99 -Os -flto=auto
CFLAGS_SYSTEMD = -DUSE_SYSTEMD CFLAGS_SYSTEMD = -DUSE_SYSTEMD
CFLAGS_BSD = -Wno-address-of-packed-member CFLAGS_BSD = -Wno-address-of-packed-member
CFLAGS_CYGWIN = -Wno-address-of-packed-member -static CFLAGS_CYGWIN = -Wno-address-of-packed-member -static
LDFLAGS_ANDROID = -llog
LIBS_LINUX = -lnetfilter_queue -lnfnetlink -lz LIBS_LINUX = -lnetfilter_queue -lnfnetlink -lz
LIBS_SYSTEMD = -lsystemd LIBS_SYSTEMD = -lsystemd
LIBS_BSD = -lz LIBS_BSD = -lz
@ -21,7 +22,8 @@ nfqws: $(SRC_FILES)
systemd: $(SRC_FILES) systemd: $(SRC_FILES)
$(CC) -s $(CFLAGS) $(CFLAGS_SYSTEMD) -o nfqws $(SRC_FILES) $(LIBS_LINUX) $(LIBS_SYSTEMD) $(LDFLAGS) $(CC) -s $(CFLAGS) $(CFLAGS_SYSTEMD) -o nfqws $(SRC_FILES) $(LIBS_LINUX) $(LIBS_SYSTEMD) $(LDFLAGS)
android: nfqws android: $(SRC_FILES)
$(CC) -s $(CFLAGS) -o nfqws $(SRC_FILES) $(LIBS_LINUX) $(LDFLAGS) $(LDFLAGS_ANDROID)
bsd: $(SRC_FILES) bsd: $(SRC_FILES)
$(CC) -s $(CFLAGS) $(CFLAGS_BSD) -o dvtws $(SRC_FILES) $(LIBS_BSD) $(LDFLAGS) $(CC) -s $(CFLAGS) $(CFLAGS_BSD) -o dvtws $(SRC_FILES) $(LIBS_BSD) $(LDFLAGS)

View File

@ -1485,7 +1485,11 @@ static void exithelp(void)
#if !defined( __OpenBSD__) && !defined(__ANDROID__) #if !defined( __OpenBSD__) && !defined(__ANDROID__)
" @<config_file>|$<config_file>\t\t\t; read file for options. must be the only argument. other options are ignored.\n\n" " @<config_file>|$<config_file>\t\t\t; read file for options. must be the only argument. other options are ignored.\n\n"
#endif #endif
#ifdef __ANDROID__
" --debug=0|1|syslog|android|@<filename>\n"
#else
" --debug=0|1|syslog|@<filename>\n" " --debug=0|1|syslog|@<filename>\n"
#endif
" --version\t\t\t\t\t; print version and exit\n" " --version\t\t\t\t\t; print version and exit\n"
" --dry-run\t\t\t\t\t; verify parameters and exit with code 0 if successful\n" " --dry-run\t\t\t\t\t; verify parameters and exit with code 0 if successful\n"
" --comment=any_text\n" " --comment=any_text\n"
@ -2057,10 +2061,22 @@ int main(int argc, char **argv)
params.debug_target = LOG_TARGET_SYSLOG; params.debug_target = LOG_TARGET_SYSLOG;
openlog(progname,LOG_PID,LOG_USER); openlog(progname,LOG_PID,LOG_USER);
} }
#ifdef __ANDROID__
else if (!strcmp(optarg,"android"))
{
if (!params.debug) params.debug = 1;
params.debug_target = LOG_TARGET_ANDROID;
}
#endif
else if (optarg[0]>='0' && optarg[0]<='1')
{
params.debug = atoi(optarg);
params.debug_target = LOG_TARGET_CONSOLE;
}
else else
{ {
params.debug = !!atoi(optarg); fprintf(stderr, "invalid debug mode : %s\n", optarg);
params.debug_target = LOG_TARGET_CONSOLE; exit_clean(1);
} }
} }
else else

View File

@ -3,6 +3,9 @@
#include <stdarg.h> #include <stdarg.h>
#include <syslog.h> #include <syslog.h>
#include <errno.h> #include <errno.h>
#ifdef __ANDROID__
#include <android/log.h>
#endif
#include "pools.h" #include "pools.h"
#include "desync.h" #include "desync.h"
@ -39,19 +42,47 @@ int DLOG_FILENAME(const char *filename, const char *format, va_list args)
r=-1; r=-1;
return r; return r;
} }
typedef void (*f_log_function)(int priority, const char *line);
static char syslog_buf[1024]; static char log_buf[1024];
static size_t syslog_buf_sz=0; static size_t log_buf_sz=0;
static void syslog_buffered(int priority, const char *format, va_list args) static void syslog_log_function(int priority, const char *line)
{ {
if (vsnprintf(syslog_buf+syslog_buf_sz,sizeof(syslog_buf)-syslog_buf_sz,format,args)>0) syslog(priority,"%s",log_buf);
}
#ifdef __ANDROID__
enum android_LogPriority syslog_priority_to_android(int priority)
{
enum android_LogPriority ap;
switch(priority)
{ {
syslog_buf_sz=strlen(syslog_buf); case LOG_INFO:
case LOG_NOTICE: ap=ANDROID_LOG_INFO; break;
case LOG_ERR: ap=ANDROID_LOG_ERROR; break;
case LOG_WARNING: ap=ANDROID_LOG_WARN; break;
case LOG_EMERG:
case LOG_ALERT:
case LOG_CRIT: ap=ANDROID_LOG_FATAL; break;
case LOG_DEBUG: ap=ANDROID_LOG_DEBUG; break;
default: ap=ANDROID_LOG_UNKNOWN;
}
return ap;
}
static void android_log_function(int priority, const char *line)
{
__android_log_print(syslog_priority_to_android(priority), progname, "%s", line);
}
#endif
static void log_buffered(f_log_function log_function, int syslog_priority, const char *format, va_list args)
{
if (vsnprintf(log_buf+log_buf_sz,sizeof(log_buf)-log_buf_sz,format,args)>0)
{
log_buf_sz=strlen(log_buf);
// log when buffer is full or buffer ends with \n // log when buffer is full or buffer ends with \n
if (syslog_buf_sz>=(sizeof(syslog_buf)-1) || (syslog_buf_sz && syslog_buf[syslog_buf_sz-1]=='\n')) if (log_buf_sz>=(sizeof(log_buf)-1) || (log_buf_sz && log_buf[log_buf_sz-1]=='\n'))
{ {
syslog(priority,"%s",syslog_buf); log_function(syslog_priority,log_buf);
syslog_buf_sz = 0; log_buf_sz = 0;
} }
} }
} }
@ -79,9 +110,16 @@ static int DLOG_VA(const char *format, int syslog_priority, bool condup, va_list
break; break;
case LOG_TARGET_SYSLOG: case LOG_TARGET_SYSLOG:
// skip newlines // skip newlines
syslog_buffered(syslog_priority,format,args); log_buffered(syslog_log_function,syslog_priority,format,args);
r = 1; r = 1;
break; break;
#ifdef __ANDROID__
case LOG_TARGET_ANDROID:
// skip newlines
log_buffered(android_log_function,syslog_priority,format,args);
r = 1;
break;
#endif
default: default:
break; break;
} }

View File

@ -65,7 +65,7 @@
#define MAX_GIDS 64 #define MAX_GIDS 64
enum log_target { LOG_TARGET_CONSOLE=0, LOG_TARGET_FILE, LOG_TARGET_SYSLOG }; enum log_target { LOG_TARGET_CONSOLE=0, LOG_TARGET_FILE, LOG_TARGET_SYSLOG, LOG_TARGET_ANDROID };
struct fake_tls_mod_cache struct fake_tls_mod_cache
{ {

View File

@ -2,6 +2,7 @@ CC ?= gcc
CFLAGS += -std=gnu99 -Os -flto=auto CFLAGS += -std=gnu99 -Os -flto=auto
CFLAGS_SYSTEMD = -DUSE_SYSTEMD CFLAGS_SYSTEMD = -DUSE_SYSTEMD
CFLAGS_BSD = -Wno-address-of-packed-member CFLAGS_BSD = -Wno-address-of-packed-member
LDFLAGS_ANDROID = -llog
LIBS = -lz -lpthread LIBS = -lz -lpthread
LIBS_SYSTEMD = -lsystemd LIBS_SYSTEMD = -lsystemd
LIBS_ANDROID = -lz LIBS_ANDROID = -lz
@ -17,7 +18,7 @@ systemd: $(SRC_FILES)
$(CC) -s $(CFLAGS) $(CFLAGS_SYSTEMD) -o tpws $(SRC_FILES) $(LIBS) $(LIBS_SYSTEMD) $(LDFLAGS) $(CC) -s $(CFLAGS) $(CFLAGS_SYSTEMD) -o tpws $(SRC_FILES) $(LIBS) $(LIBS_SYSTEMD) $(LDFLAGS)
android: $(SRC_FILES) android: $(SRC_FILES)
$(CC) -s $(CFLAGS) -o tpws $(SRC_FILES_ANDROID) $(LIBS_ANDROID) $(LDFLAGS) $(CC) -s $(CFLAGS) -o tpws $(SRC_FILES_ANDROID) $(LIBS_ANDROID) $(LDFLAGS) $(LDFLAGS_ANDROID)
bsd: $(SRC_FILES) bsd: $(SRC_FILES)
$(CC) -s $(CFLAGS) $(CFLAGS_BSD) -Iepoll-shim/include -o tpws $(SRC_FILES) epoll-shim/src/*.c $(LIBS) $(LDFLAGS) $(CC) -s $(CFLAGS) $(CFLAGS_BSD) -Iepoll-shim/include -o tpws $(SRC_FILES) epoll-shim/src/*.c $(LIBS) $(LDFLAGS)

View File

@ -2,6 +2,11 @@
#include <stdarg.h> #include <stdarg.h>
#include <syslog.h> #include <syslog.h>
#include <errno.h> #include <errno.h>
#ifdef __ANDROID__
#include <android/log.h>
#endif
const char *progname = "tpws";
int DLOG_FILE(FILE *F, const char *format, va_list args) int DLOG_FILE(FILE *F, const char *format, va_list args)
{ {
@ -25,18 +30,47 @@ int DLOG_FILENAME(const char *filename, const char *format, va_list args)
return r; return r;
} }
static char syslog_buf[1024]; typedef void (*f_log_function)(int priority, const char *line);
static size_t syslog_buf_sz=0;
static void syslog_buffered(int priority, const char *format, va_list args) static char log_buf[1024];
static size_t log_buf_sz=0;
static void syslog_log_function(int priority, const char *line)
{ {
if (vsnprintf(syslog_buf+syslog_buf_sz,sizeof(syslog_buf)-syslog_buf_sz,format,args)>0) syslog(priority,"%s",log_buf);
}
#ifdef __ANDROID__
enum android_LogPriority syslog_priority_to_android(int priority)
{
enum android_LogPriority ap;
switch(priority)
{ {
syslog_buf_sz=strlen(syslog_buf); case LOG_INFO:
case LOG_NOTICE: ap=ANDROID_LOG_INFO; break;
case LOG_ERR: ap=ANDROID_LOG_ERROR; break;
case LOG_WARNING: ap=ANDROID_LOG_WARN; break;
case LOG_EMERG:
case LOG_ALERT:
case LOG_CRIT: ap=ANDROID_LOG_FATAL; break;
case LOG_DEBUG: ap=ANDROID_LOG_DEBUG; break;
default: ap=ANDROID_LOG_UNKNOWN;
}
return ap;
}
static void android_log_function(int priority, const char *line)
{
__android_log_print(syslog_priority_to_android(priority), progname, "%s", line);
}
#endif
static void log_buffered(f_log_function log_function, int syslog_priority, const char *format, va_list args)
{
if (vsnprintf(log_buf+log_buf_sz,sizeof(log_buf)-log_buf_sz,format,args)>0)
{
log_buf_sz=strlen(log_buf);
// log when buffer is full or buffer ends with \n // log when buffer is full or buffer ends with \n
if (syslog_buf_sz>=(sizeof(syslog_buf)-1) || (syslog_buf_sz && syslog_buf[syslog_buf_sz-1]=='\n')) if (log_buf_sz>=(sizeof(log_buf)-1) || (log_buf_sz && log_buf[log_buf_sz-1]=='\n'))
{ {
syslog(priority,"%s",syslog_buf); log_function(syslog_priority,log_buf);
syslog_buf_sz = 0; log_buf_sz = 0;
} }
} }
} }
@ -64,9 +98,16 @@ static int DLOG_VA(const char *format, int syslog_priority, bool condup, int lev
break; break;
case LOG_TARGET_SYSLOG: case LOG_TARGET_SYSLOG:
// skip newlines // skip newlines
syslog_buffered(syslog_priority,format,args); log_buffered(syslog_log_function,syslog_priority,format,args);
r = 1; r = 1;
break; break;
#ifdef __ANDROID__
case LOG_TARGET_ANDROID:
// skip newlines
log_buffered(android_log_function,syslog_priority,format,args);
r = 1;
break;
#endif
default: default:
break; break;
} }

View File

@ -11,6 +11,7 @@
#include <wordexp.h> #include <wordexp.h>
#endif #endif
#include "tpws.h" #include "tpws.h"
#include "pools.h" #include "pools.h"
#include "helpers.h" #include "helpers.h"
@ -38,7 +39,7 @@ struct bind_s
#define MAX_SPLITS 16 #define MAX_SPLITS 16
enum log_target { LOG_TARGET_CONSOLE=0, LOG_TARGET_FILE, LOG_TARGET_SYSLOG }; enum log_target { LOG_TARGET_CONSOLE=0, LOG_TARGET_FILE, LOG_TARGET_SYSLOG, LOG_TARGET_ANDROID };
struct desync_profile struct desync_profile
{ {
@ -153,6 +154,7 @@ struct params_s
}; };
extern struct params_s params; extern struct params_s params;
extern const char *progname;
int DLOG(const char *format, int level, ...); int DLOG(const char *format, int level, ...);
int DLOG_CONDUP(const char *format, ...); int DLOG_CONDUP(const char *format, ...);

View File

@ -224,7 +224,11 @@ static void exithelp(void)
#endif #endif
" --ipcache-lifetime=<int>\t\t; time in seconds to keep cached domain name (default %u). 0 = no expiration\n" " --ipcache-lifetime=<int>\t\t; time in seconds to keep cached domain name (default %u). 0 = no expiration\n"
" --ipcache-hostname=[0|1]\t\t; 1 or no argument enables ip->hostname caching\n" " --ipcache-hostname=[0|1]\t\t; 1 or no argument enables ip->hostname caching\n"
#ifdef __ANDROID__
" --debug=0|1|2|syslog|android|@<filename> ; 1 and 2 means log to console and set debug level. for other targets use --debug-level.\n"
#else
" --debug=0|1|2|syslog|@<filename>\t; 1 and 2 means log to console and set debug level. for other targets use --debug-level.\n" " --debug=0|1|2|syslog|@<filename>\t; 1 and 2 means log to console and set debug level. for other targets use --debug-level.\n"
#endif
" --debug-level=0|1|2\t\t\t; specify debug level\n" " --debug-level=0|1|2\t\t\t; specify debug level\n"
" --dry-run\t\t\t\t; verify parameters and exit with code 0 if successful\n" " --dry-run\t\t\t\t; verify parameters and exit with code 0 if successful\n"
" --version\t\t\t\t; print version and exit\n" " --version\t\t\t\t; print version and exit\n"
@ -1345,13 +1349,25 @@ void parse_params(int argc, char *argv[])
{ {
if (!params.debug) params.debug = 1; if (!params.debug) params.debug = 1;
params.debug_target = LOG_TARGET_SYSLOG; params.debug_target = LOG_TARGET_SYSLOG;
openlog("tpws",LOG_PID,LOG_USER); openlog(progname,LOG_PID,LOG_USER);
} }
else #ifdef __ANDROID__
else if (!strcmp(optarg,"android"))
{
if (!params.debug) params.debug = 1;
params.debug_target = LOG_TARGET_ANDROID;
}
#endif
else if (optarg[0]>='0' && optarg[0]<='2')
{ {
params.debug = atoi(optarg); params.debug = atoi(optarg);
params.debug_target = LOG_TARGET_CONSOLE; params.debug_target = LOG_TARGET_CONSOLE;
} }
else
{
fprintf(stderr, "invalid debug mode : %s\n", optarg);
exit_clean(1);
}
} }
else else
{ {