diff --git a/common.c b/common.c index 9274d19..131a10b 100644 --- a/common.c +++ b/common.c @@ -427,11 +427,11 @@ void init_cnx(struct connection *cnx) void dump_connection(struct connection *cnx) { - printf("state: %d\n", cnx->state); - printf("0: fd %d, %d deferred\n", cnx->q[0].fd, cnx->q[0].deferred_data_size); - hexdump(cnx->q[0].deferred_data, cnx->q[0].deferred_data_size); - printf("1: fd %d, %d deferred\n", cnx->q[1].fd, cnx->q[1].deferred_data_size); - hexdump(cnx->q[1].deferred_data, cnx->q[1].deferred_data_size); + print_message(msg_int_error, "state: %d\n", cnx->state); + print_message(msg_int_error, "0: fd %d, %d deferred\n", cnx->q[0].fd, cnx->q[0].deferred_data_size); + hexdump(msg_int_error, cnx->q[0].deferred_data, cnx->q[0].deferred_data_size); + print_message(msg_int_error, "1: fd %d, %d deferred\n", cnx->q[1].fd, cnx->q[1].deferred_data_size); + hexdump(msg_int_error, cnx->q[1].deferred_data, cnx->q[1].deferred_data_size); } diff --git a/echosrv-conf.c b/echosrv-conf.c index a5d1a71..581c61e 100644 --- a/echosrv-conf.c +++ b/echosrv-conf.c @@ -1,5 +1,5 @@ /* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README) - * on Sat Sep 18 17:28:37 2021. + * on Sun Sep 19 21:54:08 2021. # conf2struct: generate libconf parsers that read to structs # Copyright (C) 2018-2021 Yves Rutschle diff --git a/echosrv-conf.h b/echosrv-conf.h index 0218d99..cfc9cc8 100644 --- a/echosrv-conf.h +++ b/echosrv-conf.h @@ -1,5 +1,5 @@ /* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README) - * on Sat Sep 18 17:28:37 2021. + * on Sun Sep 19 21:54:08 2021. # conf2struct: generate libconf parsers that read to structs # Copyright (C) 2018-2021 Yves Rutschle diff --git a/log.c b/log.c index 4c01fcb..eb89515 100644 --- a/log.c +++ b/log.c @@ -57,6 +57,13 @@ msg_info msg_system_error = { }; +msg_info msg_packets = { + LOG_INFO, + &cfg.verbose_packets +}; + + + /* Bitmasks in verbose-* values */ #define MSG_STDOUT 1 diff --git a/log.h b/log.h index e99b77b..563d217 100644 --- a/log.h +++ b/log.h @@ -17,6 +17,7 @@ extern msg_info msg_config; extern msg_info msg_config_error; extern msg_info msg_fd; +extern msg_info msg_packets; extern msg_info msg_int_error; extern msg_info msg_system_error; diff --git a/probe.c b/probe.c index f3d4529..657842e 100644 --- a/probe.c +++ b/probe.c @@ -1,7 +1,7 @@ /* # probe.c: Code for probing protocols # -# Copyright (C) 2007-2019 Yves Rutschle +# Copyright (C) 2007-2021 Yves Rutschle # # This program is free software; you can redistribute it # and/or modify it under the terms of the GNU General Public @@ -27,6 +27,7 @@ #endif #include #include "probe.h" +#include "log.h" @@ -81,33 +82,38 @@ struct sslhcfg_protocols_item* timeout_protocol(void) /* From http://grapsus.net/blog/post/Hexadecimal-dump-in-C */ #define HEXDUMP_COLS 16 -void hexdump(const char *mem, unsigned int len) +void hexdump(msg_info msg_info, const char *mem, unsigned int len) { unsigned int i, j; + char str[10 + HEXDUMP_COLS * 4 + 2]; + int c = 0; /* index in str */ for(i = 0; i < len + ((len % HEXDUMP_COLS) ? (HEXDUMP_COLS - len % HEXDUMP_COLS) : 0); i++) { /* print offset */ if(i % HEXDUMP_COLS == 0) - fprintf(stderr, "0x%06x: ", i); + c += sprintf(&str[c], "0x%06x: ", i); /* print hex data */ if(i < len) - fprintf(stderr, "%02x ", 0xFF & mem[i]); + c += sprintf(&str[c], "%02x ", 0xFF & mem[i]); else /* end of block, just aligning for ASCII dump */ - fprintf(stderr, " "); + c+= sprintf(&str[c], " "); /* print ASCII dump */ if(i % HEXDUMP_COLS == (HEXDUMP_COLS - 1)) { for(j = i - (HEXDUMP_COLS - 1); j <= i; j++) { if(j >= len) /* end of block, not really printing */ - fputc(' ', stderr); + str[c++] = ' '; else if(isprint(mem[j])) /* printable char */ - fputc(0xFF & mem[j], stderr); + str[c++] = 0xFF & mem[j]; else /* other char */ - fputc('.', stderr); + str[c++] = '.'; } - fputc('\n', stderr); + str[c++] = '\n'; + str[c++] = 0; + print_message(msg_info, str); + c = 0; } } } @@ -345,8 +351,8 @@ int probe_buffer(char* buf, int len, struct sslhcfg_protocols_item** proto) int i, res, again = 0; if (cfg.verbose > 1) { - fprintf(stderr, "hexdump of incoming packet:\n"); - hexdump(buf, len); + print_message(msg_packets, "hexdump of incoming packet:\n"); + hexdump(msg_packets, buf, len); } *proto = NULL; diff --git a/probe.h b/probe.h index ecc972f..01248fc 100644 --- a/probe.h +++ b/probe.h @@ -5,6 +5,7 @@ #include "common.h" #include "tls.h" +#include "log.h" typedef enum { PROBE_NEXT, /* Enough data, probe failed -- it's some other protocol */ @@ -59,6 +60,6 @@ void set_ontimeout(const char* name); */ struct sslhcfg_protocols_item* timeout_protocol(void); -void hexdump(const char*, unsigned int); +void hexdump(msg_info, const char*, unsigned int); #endif diff --git a/sslh-conf.c b/sslh-conf.c index 6d8eb46..1abebb6 100644 --- a/sslh-conf.c +++ b/sslh-conf.c @@ -1,5 +1,5 @@ /* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README) - * on Sun Sep 19 20:20:24 2021. + * on Sun Sep 19 21:54:06 2021. # conf2struct: generate libconf parsers that read to structs # Copyright (C) 2018-2021 Yves Rutschle @@ -446,7 +446,9 @@ struct arg_file* sslhcfg_conffile; struct arg_int* sslhcfg_verbose_config; struct arg_int* sslhcfg_verbose_config_error; struct arg_int* sslhcfg_verbose_connections; + struct arg_int* sslhcfg_verbose_connections_error; struct arg_int* sslhcfg_verbose_fd; + struct arg_int* sslhcfg_verbose_packets; struct arg_int* sslhcfg_verbose_system_error; struct arg_int* sslhcfg_verbose_int_error; struct arg_int* sslhcfg_verbose; @@ -789,7 +791,7 @@ static struct config_desc table_sslhcfg_listen[] = { }, { 0 } }; - + static struct config_desc table_sslhcfg[] = { @@ -838,7 +840,23 @@ static struct config_desc table_sslhcfg[] = { /* array_type */ -1, /* mandatory */ 0, /* optional */ 0, - /* default_val*/ .default_val.def_int = 0 + /* default_val*/ .default_val.def_int = 3 + }, + + { + /* name */ "verbose_connections_error", + /* type */ CFG_INT, + /* sub_group*/ NULL, + /* arg_cl */ & sslhcfg_verbose_connections_error, + /* base_addr */ NULL, + /* offset */ offsetof(struct sslhcfg_item, verbose_connections_error), + /* offset_len */ 0, + /* offset_present */ 0, + /* size */ sizeof(int), + /* array_type */ -1, + /* mandatory */ 0, + /* optional */ 0, + /* default_val*/ .default_val.def_int = 3 }, { @@ -857,6 +875,22 @@ static struct config_desc table_sslhcfg[] = { /* default_val*/ .default_val.def_int = 0 }, + { + /* name */ "verbose_packets", + /* type */ CFG_INT, + /* sub_group*/ NULL, + /* arg_cl */ & sslhcfg_verbose_packets, + /* base_addr */ NULL, + /* offset */ offsetof(struct sslhcfg_item, verbose_packets), + /* offset_len */ 0, + /* offset_present */ 0, + /* size */ sizeof(int), + /* array_type */ -1, + /* mandatory */ 0, + /* optional */ 0, + /* default_val*/ .default_val.def_int = 0 + }, + { /* name */ "verbose_system_error", /* type */ CFG_INT, @@ -1225,7 +1259,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: listen */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_listen, - .base_entry = & table_sslhcfg [19], + .base_entry = & table_sslhcfg [21], .targets = sslhcfg_listen_targets, @@ -1237,7 +1271,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: ssh */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_ssh, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_ssh_targets, @@ -1249,7 +1283,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: tls */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_tls, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_tls_targets, @@ -1261,7 +1295,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: openvpn */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_openvpn, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_openvpn_targets, @@ -1273,7 +1307,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: tinc */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_tinc, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_tinc_targets, @@ -1285,7 +1319,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: xmpp */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_xmpp, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_xmpp_targets, @@ -1297,7 +1331,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: http */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_http, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_http_targets, @@ -1309,7 +1343,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: adb */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_adb, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_adb_targets, @@ -1321,7 +1355,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: socks5 */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_socks5, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_socks5_targets, @@ -1333,7 +1367,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: syslog */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_syslog, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_syslog_targets, @@ -1345,7 +1379,7 @@ static struct compound_cl_arg compound_cl_args[] = { { /* arg: anyprot */ .regex = "(.+):(\\w+)", .arg_cl = & sslhcfg_anyprot, - .base_entry = & table_sslhcfg [20], + .base_entry = & table_sslhcfg [22], .targets = sslhcfg_anyprot_targets, @@ -2013,7 +2047,9 @@ int sslhcfg_cl_parse(int argc, char* argv[], struct sslhcfg_item* cfg) sslhcfg_verbose_config = arg_intn(NULL, "verbose-config", "", 0, 1, ""), sslhcfg_verbose_config_error = arg_intn(NULL, "verbose-config-error", "", 0, 1, ""), sslhcfg_verbose_connections = arg_intn(NULL, "verbose-connections", "", 0, 1, ""), + sslhcfg_verbose_connections_error = arg_intn(NULL, "verbose-connections-error", "", 0, 1, ""), sslhcfg_verbose_fd = arg_intn(NULL, "verbose-fd", "", 0, 1, ""), + sslhcfg_verbose_packets = arg_intn(NULL, "verbose-packets", "", 0, 1, ""), sslhcfg_verbose_system_error = arg_intn(NULL, "verbose-system-error", "", 0, 1, ""), sslhcfg_verbose_int_error = arg_intn(NULL, "verbose-int-error", "", 0, 1, ""), sslhcfg_verbose = arg_intn("v", "verbose", "", 0, 1, ""), @@ -2194,9 +2230,15 @@ void sslhcfg_fprint( fprintf(out, "verbose_connections: %d", sslhcfg->verbose_connections); fprintf(out, "\n"); indent(out, depth); + fprintf(out, "verbose_connections_error: %d", sslhcfg->verbose_connections_error); + fprintf(out, "\n"); + indent(out, depth); fprintf(out, "verbose_fd: %d", sslhcfg->verbose_fd); fprintf(out, "\n"); indent(out, depth); + fprintf(out, "verbose_packets: %d", sslhcfg->verbose_packets); + fprintf(out, "\n"); + indent(out, depth); fprintf(out, "verbose_system_error: %d", sslhcfg->verbose_system_error); fprintf(out, "\n"); indent(out, depth); diff --git a/sslh-conf.h b/sslh-conf.h index 81ef678..f51ae62 100644 --- a/sslh-conf.h +++ b/sslh-conf.h @@ -1,5 +1,5 @@ /* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README) - * on Sun Sep 19 20:20:24 2021. + * on Sun Sep 19 21:54:06 2021. # conf2struct: generate libconf parsers that read to structs # Copyright (C) 2018-2021 Yves Rutschle @@ -77,7 +77,9 @@ struct sslhcfg_item { int verbose_config; int verbose_config_error; int verbose_connections; + int verbose_connections_error; int verbose_fd; + int verbose_packets; int verbose_system_error; int verbose_int_error; int verbose; diff --git a/sslhconf.cfg b/sslhconf.cfg index 6a9a0fa..8e89324 100644 --- a/sslhconf.cfg +++ b/sslhconf.cfg @@ -27,8 +27,10 @@ config: { items: ( { name: "verbose-config"; type: "int"; default: 0; }, { name: "verbose-config-error"; type: "int"; default: 3; }, - { name: "verbose-connections"; type: "int"; default: 0; }, + { name: "verbose-connections"; type: "int"; default: 3; }, + { name: "verbose-connections-error"; type: "int"; default: 3; }, { name: "verbose-fd"; type: "int"; default: 0; }, + { name: "verbose-packets"; type: "int"; default: 0; }, { name: "verbose-system-error"; type: "int"; default: 3; }, { name: "verbose-int-error"; type: "int"; default: 3; }, diff --git a/test.cfg b/test.cfg index 5f31027..8a83312 100644 --- a/test.cfg +++ b/test.cfg @@ -19,6 +19,7 @@ syslog_facility: "auth"; #verbose-config-error: 3; #config-error: print configuration errors #verbose-connections: 3; #config-connections: track connections #verbose-fd: 3; # file descriptor activity, open/close/whatnot +verbose-packets: 3; # hexdump packets on which probing is done #verbose-system-error: 3; # system call problem, i.e. malloc, fork, failing #verbose-int-error: 3; # internal errors, the kind that should never happen