hexdump writes to parametrable msg_info

This commit is contained in:
yrutschle 2021-09-19 21:54:47 +02:00
parent 673c40954e
commit e5f16b93ce
11 changed files with 97 additions and 35 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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

7
log.c
View File

@ -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

1
log.h
View File

@ -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;

28
probe.c
View File

@ -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 <ctype.h>
#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;

View File

@ -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

View File

@ -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", "<n>", 0, 1, ""),
sslhcfg_verbose_config_error = arg_intn(NULL, "verbose-config-error", "<n>", 0, 1, ""),
sslhcfg_verbose_connections = arg_intn(NULL, "verbose-connections", "<n>", 0, 1, ""),
sslhcfg_verbose_connections_error = arg_intn(NULL, "verbose-connections-error", "<n>", 0, 1, ""),
sslhcfg_verbose_fd = arg_intn(NULL, "verbose-fd", "<n>", 0, 1, ""),
sslhcfg_verbose_packets = arg_intn(NULL, "verbose-packets", "<n>", 0, 1, ""),
sslhcfg_verbose_system_error = arg_intn(NULL, "verbose-system-error", "<n>", 0, 1, ""),
sslhcfg_verbose_int_error = arg_intn(NULL, "verbose-int-error", "<n>", 0, 1, ""),
sslhcfg_verbose = arg_intn("v", "verbose", "<n>", 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);

View File

@ -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;

View File

@ -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; },

View File

@ -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