From d2eb875d80020982562344635343dd960d9b4972 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Mon, 12 Sep 2022 10:59:05 +0800 Subject: [PATCH] feat: debug option for dnsproxy --- include/dnsproxy.h | 1 + src/cleardns.c | 71 +++++++++++++++++++++++----------------------- src/dnsproxy.c | 23 ++++++++++++--- 3 files changed, 56 insertions(+), 39 deletions(-) diff --git a/include/dnsproxy.h b/include/dnsproxy.h index baa3750..99d9e37 100644 --- a/include/dnsproxy.h +++ b/include/dnsproxy.h @@ -6,6 +6,7 @@ typedef struct { int port; int cache; + int debug; // bool value int verify; // bool value int parallel; // bool value int optimistic; // bool value diff --git a/src/cleardns.c b/src/cleardns.c index 7929a3c..08ce2b1 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -35,15 +35,15 @@ int main(int argc, char *argv[]) { // ClearDNS server LOG_LEVEL = LOG_DEBUG; log_info("ClearDNS server start (%s)", VERSION); - int **temp = int_list_init(); - temp = int_list_append(temp, 1232); - temp = int_list_append(temp, 2342); - temp = int_list_append(temp, 3435); - temp = int_list_append(temp, 456); - temp = int_list_append(temp, 567); - - char *str = int_list_dump(temp); - log_info("`%s`", str); +// int **temp = int_list_init(); +// temp = int_list_append(temp, 1232); +// temp = int_list_append(temp, 2342); +// temp = int_list_append(temp, 3435); +// temp = int_list_append(temp, 456); +// temp = int_list_append(temp, 567); +// +// char *str = int_list_dump(temp); +// log_info("`%s`", str); // char **temp = string_list_init(); // temp = string_list_append(temp, "1"); @@ -53,42 +53,43 @@ int main(int argc, char *argv[]) { // ClearDNS server // char *str = string_list_dump(temp); // log_info("`%s`", str); - return 0; +// return 0; -// dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT); -// -// dnsproxy_add_bootstrap(domestic, "1.1.1.1"); -// dnsproxy_add_bootstrap(domestic, "8.8.8.8"); -// -// dnsproxy_add_primary(domestic, "223.5.5.5"); -// dnsproxy_add_primary(domestic, "tls://dns.pub"); -// -// dnsproxy_add_fallback(domestic, "tls://223.6.6.6"); -// dnsproxy_add_fallback(domestic, "tls://120.53.53.53"); + dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT); -// domestic->verify = FALSE; -// domestic->parallel = FALSE; -// domestic->optimistic = TRUE; -// domestic->cache = 0; - -// process *p = dnsproxy_load("Domestic", domestic, "domestic.json"); -// log_info("cmd -> %s", string_list_dump(p->cmd)); -// log_info("env -> %s", string_list_dump(p->env)); -// log_info("cwd -> %s", p->cwd); + dnsproxy_add_bootstrap(domestic, "1.1.1.1"); + dnsproxy_add_bootstrap(domestic, "8.8.8.8"); + dnsproxy_add_primary(domestic, "223.5.5.5"); + dnsproxy_add_primary(domestic, "tls://dns.pub"); - overture *diverter = overture_init(DIVERTER_PORT); + dnsproxy_add_fallback(domestic, "tls://223.6.6.6"); + dnsproxy_add_fallback(domestic, "tls://120.53.53.53"); - diverter->timeout = 8; - diverter->domestic_ip_file = "china-ip.txt"; - diverter->domestic_domain_file = "chinalist.txt"; - diverter->foreign_domain_file = "gfwlist.txt"; + domestic->verify = FALSE; + domestic->parallel = FALSE; + domestic->optimistic = TRUE; +// domestic->debug = TRUE; + domestic->cache = 0; - process *p = overture_load(diverter, "overture.json"); + process *p = dnsproxy_load("Domestic", domestic, "domestic.json"); log_info("cmd -> %s", string_list_dump(p->cmd)); log_info("env -> %s", string_list_dump(p->env)); log_info("cwd -> %s", p->cwd); + +// overture *diverter = overture_init(DIVERTER_PORT); +// +// diverter->timeout = 8; +// diverter->domestic_ip_file = "china-ip.txt"; +// diverter->domestic_domain_file = "chinalist.txt"; +// diverter->foreign_domain_file = "gfwlist.txt"; +// +// process *p = overture_load(diverter, "overture.json"); +// log_info("cmd -> %s", string_list_dump(p->cmd)); +// log_info("env -> %s", string_list_dump(p->env)); +// log_info("cwd -> %s", p->cwd); + // int debug_mode = 0; // fprintf(stderr, "[ClearDNS] Server start.\n"); // for (char **p = argv; p < argv + argc; ++p) { diff --git a/src/dnsproxy.c b/src/dnsproxy.c index b7110f1..436bc90 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -24,25 +24,37 @@ void dnsproxy_add_bootstrap(dnsproxy *info, const char *server) { // add bootstr dnsproxy* dnsproxy_init(int port) { // init dnsproxy options dnsproxy *info = (dnsproxy*)malloc(sizeof(dnsproxy)); info->port = port; + info->cache = 0; // disable cache in default + info->debug = FALSE; info->verify = TRUE; info->parallel = TRUE; info->optimistic = FALSE; info->bootstrap = string_list_init(); info->fallback = string_list_init(); info->primary = string_list_init(); - info->cache = 4194304; // 4MiB return info; } void dnsproxy_dump(const char *caption, dnsproxy *info) { // show dnsproxy info in debug log - log_debug("%s listen port -> %d", caption, info->port); + char *str_dump; + log_debug("%s port -> %d", caption, info->port); + log_debug("%s cache -> %d", caption, info->cache); + log_debug("%s debug -> %s", caption, show_bool(info->debug)); log_debug("%s verify -> %s", caption, show_bool(info->verify)); log_debug("%s parallel -> %s", caption, show_bool(info->parallel)); log_debug("%s optimistic -> %s", caption, show_bool(info->optimistic)); - log_debug("%s bootstrap -> %s", caption, string_list_dump(info->bootstrap)); + + str_dump = string_list_dump(info->bootstrap); + log_debug("%s bootstrap -> %s", caption, str_dump); + free(str_dump); + + str_dump = string_list_dump(info->fallback); log_debug("%s fallback -> %s", caption, string_list_dump(info->fallback)); + free(str_dump); + + str_dump = string_list_dump(info->primary); log_debug("%s primary -> %s", caption, string_list_dump(info->primary)); - log_debug("%s cache -> %d", caption, info->cache); + free(str_dump); } process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { @@ -57,6 +69,9 @@ process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { process *p = (process*)malloc(sizeof(process)); p->cmd = string_list_append(string_list_init(), DNSPROXY_BIN); p->cmd = string_list_append(p->cmd, option); + if (info->debug) { + p->cmd = string_list_append(p->cmd, "--verbose"); // dnsproxy into debug mode + } p->env = string_list_init(); p->cwd = WORK_DIR; free(option);