mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-10-14 02:22:03 +08:00
Simplified debugging by allowing multiple levels.
'ocserv -d' now accepts a numeric option from 0 (no debugging) to 9 (maximum verbosity).
This commit is contained in:
+1
-7
@@ -551,14 +551,8 @@ int cmd_parser (int argc, char **argv, struct cfg_st* config)
|
||||
if (HAVE_OPT(PID_FILE))
|
||||
pid_file = OPT_ARG(PID_FILE);
|
||||
|
||||
if (HAVE_OPT(TLS_DEBUG))
|
||||
config->tls_debug = 1;
|
||||
|
||||
if (HAVE_OPT(HTTP_DEBUG))
|
||||
config->http_debug = 1;
|
||||
|
||||
if (HAVE_OPT(DEBUG))
|
||||
config->debug = 1;
|
||||
config->debug = OPT_VALUE_DEBUG;
|
||||
|
||||
if (HAVE_OPT(CONFIG)) {
|
||||
cfg_file = OPT_ARG(CONFIG);
|
||||
|
||||
@@ -91,10 +91,15 @@ void __attribute__ ((format(printf, 3, 4)))
|
||||
return;
|
||||
|
||||
if (priority == LOG_HTTP_DEBUG) {
|
||||
if (ws->config->http_debug == 0)
|
||||
if (ws->config->debug < DEBUG_HTTP)
|
||||
return;
|
||||
else
|
||||
priority = LOG_INFO;
|
||||
} else if (priority == LOG_TRANSFER_DEBUG) {
|
||||
if (ws->config->debug < DEBUG_TRANSFERRED)
|
||||
return;
|
||||
else
|
||||
priority = LOG_DEBUG;
|
||||
}
|
||||
|
||||
ip = human_addr((void*)&ws->remote_addr, ws->remote_addr_len,
|
||||
@@ -127,7 +132,12 @@ void __attribute__ ((format(printf, 4, 5)))
|
||||
return;
|
||||
|
||||
if (priority == LOG_HTTP_DEBUG) {
|
||||
if (s->config->http_debug == 0)
|
||||
if (s->config->debug < DEBUG_HTTP)
|
||||
return;
|
||||
else
|
||||
priority = LOG_DEBUG;
|
||||
} else if (priority == LOG_TRANSFER_DEBUG) {
|
||||
if (s->config->debug < DEBUG_TRANSFERRED)
|
||||
return;
|
||||
else
|
||||
priority = LOG_DEBUG;
|
||||
|
||||
+1
-1
@@ -855,7 +855,7 @@ int main(int argc, char** argv)
|
||||
|
||||
flags = LOG_PID|LOG_NDELAY;
|
||||
#ifdef LOG_PERROR
|
||||
if (config.debug != 0 || config.http_debug != 0 || config.tls_debug != 0)
|
||||
if (config.debug != 0)
|
||||
flags |= LOG_PERROR;
|
||||
#endif
|
||||
openlog("ocserv", flags, LOG_DAEMON);
|
||||
|
||||
+2
-12
@@ -32,21 +32,11 @@ flag = {
|
||||
doc = "";
|
||||
};
|
||||
|
||||
flag = {
|
||||
name = tls-debug;
|
||||
descrip = "Enable verbose TLS debugging information";
|
||||
doc = "";
|
||||
};
|
||||
|
||||
flag = {
|
||||
name = http-debug;
|
||||
descrip = "Enable verbose HTTP debugging information";
|
||||
doc = "";
|
||||
};
|
||||
|
||||
flag = {
|
||||
name = debug;
|
||||
value = d;
|
||||
arg-type = number;
|
||||
arg-range = "0 -> 9999";
|
||||
descrip = "Enable verbose network debugging information";
|
||||
doc = "";
|
||||
};
|
||||
|
||||
+1
-1
@@ -557,7 +557,7 @@ const char* perr;
|
||||
char *tmp;
|
||||
unsigned len;
|
||||
|
||||
if (s->config->tls_debug) {
|
||||
if (s->config->debug >= DEBUG_TLS) {
|
||||
gnutls_global_set_log_function(tls_log_func);
|
||||
gnutls_global_set_log_level(9);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@
|
||||
# define _ATTR_PACKED
|
||||
#endif
|
||||
|
||||
#define DEBUG_BASIC 1
|
||||
#define DEBUG_HTTP 2
|
||||
#define DEBUG_TRANSFERRED 3
|
||||
#define DEBUG_TLS 4
|
||||
|
||||
#define AC_PKT_DATA 0 /* Uncompressed data */
|
||||
#define AC_PKT_DPD_OUT 3 /* Dead Peer Detection */
|
||||
@@ -75,6 +79,7 @@ extern int syslog_open;
|
||||
#define ERR_CTL -12
|
||||
|
||||
#define LOG_HTTP_DEBUG 2048
|
||||
#define LOG_TRANSFER_DEBUG 2049
|
||||
|
||||
#define MAX_CIPHERSUITE_NAME 64
|
||||
#define MAX_DTLS_CIPHERSUITE_NAME 24
|
||||
@@ -198,8 +203,6 @@ struct cfg_st {
|
||||
unsigned keepalive;
|
||||
unsigned dpd;
|
||||
unsigned foreground;
|
||||
unsigned tls_debug;
|
||||
unsigned http_debug;
|
||||
unsigned debug;
|
||||
unsigned max_clients;
|
||||
unsigned max_same_clients;
|
||||
|
||||
+11
-11
@@ -1484,7 +1484,7 @@ static int connect_handler(worker_st * ws)
|
||||
ws->buffer[6] = AC_PKT_TERM_SERVER;
|
||||
ws->buffer[7] = 0;
|
||||
|
||||
oclog(ws, LOG_DEBUG,
|
||||
oclog(ws, LOG_TRANSFER_DEBUG,
|
||||
"sending disconnect message in TLS channel");
|
||||
ret = tls_send(ws->session, ws->buffer, 8);
|
||||
GNUTLS_FATAL_ERR(ret);
|
||||
@@ -1543,7 +1543,7 @@ static int connect_handler(worker_st * ws)
|
||||
if (bandwidth_update(&b_tx, l - 1, ws->conn_mtu, &tnow)
|
||||
!= 0) {
|
||||
tls_retry = 0;
|
||||
oclog(ws, LOG_DEBUG, "sending %d byte(s)\n", l);
|
||||
oclog(ws, LOG_TRANSFER_DEBUG, "sending %d byte(s)\n", l);
|
||||
if (ws->udp_state == UP_ACTIVE) {
|
||||
ws->buffer[7] = AC_PKT_DATA;
|
||||
|
||||
@@ -1556,7 +1556,7 @@ static int connect_handler(worker_st * ws)
|
||||
if (ret == GNUTLS_E_LARGE_PACKET) {
|
||||
mtu_not_ok(ws);
|
||||
|
||||
oclog(ws, LOG_DEBUG,
|
||||
oclog(ws, LOG_TRANSFER_DEBUG,
|
||||
"retrying (TLS) %d\n", l);
|
||||
tls_retry = 1;
|
||||
} else if (ret >= ws->conn_mtu
|
||||
@@ -1589,7 +1589,7 @@ static int connect_handler(worker_st * ws)
|
||||
ret =
|
||||
tls_recv(ws->session, ws->buffer,
|
||||
ws->buffer_size);
|
||||
oclog(ws, LOG_DEBUG, "received %d byte(s) (TLS)", ret);
|
||||
oclog(ws, LOG_TRANSFER_DEBUG, "received %d byte(s) (TLS)", ret);
|
||||
|
||||
GNUTLS_FATAL_ERR(ret);
|
||||
|
||||
@@ -1652,7 +1652,7 @@ static int connect_handler(worker_st * ws)
|
||||
tls_recv(ws->dtls_session,
|
||||
ws->buffer,
|
||||
ws->buffer_size);
|
||||
oclog(ws, LOG_DEBUG,
|
||||
oclog(ws, LOG_TRANSFER_DEBUG,
|
||||
"received %d byte(s) (DTLS)", ret);
|
||||
|
||||
GNUTLS_FATAL_ERR(ret);
|
||||
@@ -1697,7 +1697,7 @@ static int connect_handler(worker_st * ws)
|
||||
}
|
||||
|
||||
} else
|
||||
oclog(ws, LOG_DEBUG,
|
||||
oclog(ws, LOG_TRANSFER_DEBUG,
|
||||
"no data received (%d)", ret);
|
||||
|
||||
udp_recv_time = now;
|
||||
@@ -1799,16 +1799,16 @@ static int parse_data(struct worker_st *ws, gnutls_session_t ts, /* the interfac
|
||||
|
||||
switch (head) {
|
||||
case AC_PKT_DPD_RESP:
|
||||
oclog(ws, LOG_DEBUG, "received DPD response");
|
||||
oclog(ws, LOG_TRANSFER_DEBUG, "received DPD response");
|
||||
break;
|
||||
case AC_PKT_KEEPALIVE:
|
||||
oclog(ws, LOG_DEBUG, "received keepalive");
|
||||
oclog(ws, LOG_TRANSFER_DEBUG, "received keepalive");
|
||||
break;
|
||||
case AC_PKT_DPD_OUT:
|
||||
if (ws->session == ts) {
|
||||
ret = tls_send(ts, "STF\x01\x00\x00\x04\x00", 8);
|
||||
|
||||
oclog(ws, LOG_DEBUG,
|
||||
oclog(ws, LOG_TRANSFER_DEBUG,
|
||||
"received TLS DPD; sent response (%d bytes)",
|
||||
ret);
|
||||
} else {
|
||||
@@ -1821,7 +1821,7 @@ static int parse_data(struct worker_st *ws, gnutls_session_t ts, /* the interfac
|
||||
ret = tls_send(ts, ws->buffer, 1);
|
||||
}
|
||||
|
||||
oclog(ws, LOG_DEBUG,
|
||||
oclog(ws, LOG_TRANSFER_DEBUG,
|
||||
"received DTLS DPD; sent response (%d bytes)",
|
||||
ret);
|
||||
}
|
||||
@@ -1837,7 +1837,7 @@ static int parse_data(struct worker_st *ws, gnutls_session_t ts, /* the interfac
|
||||
exit_worker(ws);
|
||||
break;
|
||||
case AC_PKT_DATA:
|
||||
oclog(ws, LOG_DEBUG, "writing %d byte(s) to TUN",
|
||||
oclog(ws, LOG_TRANSFER_DEBUG, "writing %d byte(s) to TUN",
|
||||
(int)buf_size);
|
||||
ret = force_write(ws->tun_fd, buf, buf_size);
|
||||
if (ret == -1) {
|
||||
|
||||
Reference in New Issue
Block a user