summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-08-27 17:57:06 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-08-27 17:57:06 +0200
commit81bff2df037a218cb973559a2bfbfbd259b1cbad (patch)
treebaeeeb599991e6de736e91f3b9e80f8603fd7bb0
parente91f17de87175d822ae7e3d3238e7a0021a645ad (diff)
downloadfastd-81bff2df037a218cb973559a2bfbfbd259b1cbad.tar
fastd-81bff2df037a218cb973559a2bfbfbd259b1cbad.zip
Introduce new log level debug2 for potentially very frequent messages
-rw-r--r--src/config.c6
-rw-r--r--src/config.y14
-rw-r--r--src/fastd.c5
-rw-r--r--src/fastd.h27
-rw-r--r--src/lex.c1
-rw-r--r--src/method_aes128_gcm.c2
-rw-r--r--src/method_xsalsa20_poly1305.c2
-rw-r--r--src/options.c14
-rw-r--r--src/printf.c38
-rw-r--r--src/protocol_ec25519_fhmqvc.c2
-rw-r--r--src/types.h11
11 files changed, 79 insertions, 43 deletions
diff --git a/src/config.c b/src/config.c
index 7dd3e7f..d5165dd 100644
--- a/src/config.c
+++ b/src/config.c
@@ -87,8 +87,6 @@ static const fastd_crypto_ghash_t *fastd_crypto_ghash_default = &fastd_crypto_gh
static void default_config(fastd_config_t *conf) {
memset(conf, 0, sizeof(fastd_config_t));
- conf->log_stderr_level = -1;
- conf->log_syslog_level = -1;
conf->log_syslog_ident = strdup("fastd");
conf->keepalive_interval = 20;
@@ -294,7 +292,7 @@ static bool has_peer_group_peer_dirs(const fastd_peer_group_config_t *group) {
return false;
}
-bool fastd_config_add_log_file(fastd_context_t *ctx, fastd_config_t *conf, const char *name, int level) {
+bool fastd_config_add_log_file(fastd_context_t *ctx, fastd_config_t *conf, const char *name, fastd_loglevel_t level) {
char *name2 = strdup(name);
char *name3 = strdup(name);
@@ -612,7 +610,7 @@ void fastd_configure(fastd_context_t *ctx, fastd_config_t *conf, int argc, char
fastd_config_handle_options(ctx, conf, argc, argv);
- if (conf->log_stderr_level < 0 && conf->log_syslog_level < 0 && !conf->log_files)
+ if (!conf->log_stderr_level && !conf->log_syslog_level && !conf->log_files)
conf->log_stderr_level = FASTD_DEFAULT_LOG_LEVEL;
if (!conf->methods[0])
diff --git a/src/config.y b/src/config.y
index 774d0db..e9ab3af 100644
--- a/src/config.y
+++ b/src/config.y
@@ -97,6 +97,7 @@
%token TOK_INFO
%token TOK_VERBOSE
%token TOK_DEBUG
+%token TOK_DEBUG2
%token TOK_FORWARD
%token TOK_YES
%token TOK_NO
@@ -253,12 +254,13 @@ maybe_log_level:
| { $$ = FASTD_DEFAULT_LOG_LEVEL; }
;
-log_level: TOK_FATAL { $$ = LOG_CRIT; }
- | TOK_ERROR { $$ = LOG_ERR; }
- | TOK_WARN { $$ = LOG_WARNING; }
- | TOK_INFO { $$ = LOG_NOTICE; }
- | TOK_VERBOSE { $$ = LOG_INFO; }
- | TOK_DEBUG { $$ = LOG_DEBUG; }
+log_level: TOK_FATAL { $$ = LL_FATAL; }
+ | TOK_ERROR { $$ = LL_ERROR; }
+ | TOK_WARN { $$ = LL_WARN; }
+ | TOK_INFO { $$ = LL_INFO; }
+ | TOK_VERBOSE { $$ = LL_VERBOSE; }
+ | TOK_DEBUG { $$ = LL_DEBUG; }
+ | TOK_DEBUG2 { $$ = LL_DEBUG2; }
;
interface: TOK_STRING { free(conf->ifname); conf->ifname = strdup($1->str); }
diff --git a/src/fastd.c b/src/fastd.c
index 0da1c08..65fc59f 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -36,6 +36,7 @@
#include <pthread.h>
#include <signal.h>
#include <string.h>
+#include <syslog.h>
#include <sys/resource.h>
@@ -107,7 +108,7 @@ static void init_log(fastd_context_t *ctx) {
pr_debug_errno(ctx, "seteuid");
}
- if (ctx->conf->log_syslog_level >= 0)
+ if (ctx->conf->log_syslog_level > LL_UNSPEC)
openlog(ctx->conf->log_syslog_ident, LOG_PID, LOG_DAEMON);
fastd_log_file_t *config;
@@ -452,7 +453,7 @@ static void handle_tasks(fastd_context_t *ctx) {
break;
case TASK_KEEPALIVE:
- pr_debug(ctx, "sending keepalive to %P", task->peer);
+ pr_debug2(ctx, "sending keepalive to %P", task->peer);
ctx->conf->protocol->send(ctx, task->peer, fastd_buffer_alloc(ctx, 0, ctx->conf->min_encrypt_head_space, ctx->conf->min_encrypt_tail_space));
break;
diff --git a/src/fastd.h b/src/fastd.h
index efd785a..f74cb9d 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -37,7 +37,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <time.h>
#include <sys/uio.h>
@@ -115,7 +114,7 @@ struct fastd_resolve_return {
struct fastd_log_file {
fastd_log_file_t *next;
- int level;
+ fastd_loglevel_t level;
char *filename;
};
@@ -162,8 +161,8 @@ struct fastd_peer_group {
};
struct fastd_config {
- int log_stderr_level;
- int log_syslog_level;
+ fastd_loglevel_t log_stderr_level;
+ fastd_loglevel_t log_syslog_level;
char *log_syslog_ident;
fastd_log_file_t *log_files;
@@ -328,7 +327,7 @@ void fastd_setfl(const fastd_context_t *ctx, int fd, int set, int unset);
void fastd_resolve_peer(fastd_context_t *ctx, fastd_peer_t *peer, fastd_remote_t *remote);
int fastd_vsnprintf(const fastd_context_t *ctx, char *buffer, size_t size, const char *format, va_list ap);
-void fastd_logf(const fastd_context_t *ctx, int level, const char *format, ...);
+void fastd_logf(const fastd_context_t *ctx, fastd_loglevel_t level, const char *format, ...);
void fastd_add_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char *dir);
bool fastd_read_config(fastd_context_t *ctx, fastd_config_t *conf, const char *filename, bool peer_config, int depth);
@@ -336,7 +335,7 @@ bool fastd_read_config(fastd_context_t *ctx, fastd_config_t *conf, const char *f
bool fastd_config_protocol(fastd_context_t *ctx, fastd_config_t *conf, const char *name);
bool fastd_config_method(fastd_context_t *ctx, fastd_config_t *conf, const char *name);
bool fastd_config_crypto(fastd_context_t *ctx, fastd_config_t *conf, const char *alg, const char *impl);
-bool fastd_config_add_log_file(fastd_context_t *ctx, fastd_config_t *conf, const char *name, int level);
+bool fastd_config_add_log_file(fastd_context_t *ctx, fastd_config_t *conf, const char *name, fastd_loglevel_t level);
bool fastd_config_bind_address(fastd_context_t *ctx, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6);
void fastd_config_peer_group_push(fastd_context_t *ctx, fastd_config_t *conf, const char *name);
void fastd_config_peer_group_pop(fastd_context_t *ctx, fastd_config_t *conf);
@@ -363,19 +362,21 @@ static inline int fastd_rand(fastd_context_t *ctx, int min, int max) {
}
-#define FASTD_DEFAULT_LOG_LEVEL LOG_INFO
+#define FASTD_DEFAULT_LOG_LEVEL LL_VERBOSE
-#define pr_fatal(ctx, args...) fastd_logf(ctx, LOG_CRIT, args)
-#define pr_error(ctx, args...) fastd_logf(ctx, LOG_ERR, args)
-#define pr_warn(ctx, args...) fastd_logf(ctx, LOG_WARNING, args)
-#define pr_info(ctx, args...) fastd_logf(ctx, LOG_NOTICE, args)
-#define pr_verbose(ctx, args...) fastd_logf(ctx, LOG_INFO, args)
-#define pr_debug(ctx, args...) fastd_logf(ctx, LOG_DEBUG, args)
+#define pr_fatal(ctx, args...) fastd_logf(ctx, LL_FATAL, args)
+#define pr_error(ctx, args...) fastd_logf(ctx, LL_ERROR, args)
+#define pr_warn(ctx, args...) fastd_logf(ctx, LL_WARN, args)
+#define pr_info(ctx, args...) fastd_logf(ctx, LL_INFO, args)
+#define pr_verbose(ctx, args...) fastd_logf(ctx, LL_VERBOSE, args)
+#define pr_debug(ctx, args...) fastd_logf(ctx, LL_DEBUG, args)
+#define pr_debug2(ctx, args...) fastd_logf(ctx, LL_DEBUG2, args)
#define pr_error_errno(ctx, message) pr_error(ctx, "%s: %s", message, strerror(errno))
#define pr_warn_errno(ctx, message) pr_warn(ctx, "%s: %s", message, strerror(errno))
#define pr_debug_errno(ctx, message) pr_debug(ctx, "%s: %s", message, strerror(errno))
+#define pr_debug2_errno(ctx, message) pr_debug2(ctx, "%s: %s", message, strerror(errno))
#define exit_fatal(ctx, args...) do { pr_fatal(ctx, args); abort(); } while(0)
#define exit_bug(ctx, message) exit_fatal(ctx, "BUG: %s", message)
diff --git a/src/lex.c b/src/lex.c
index 9e68bc2..b8f6496 100644
--- a/src/lex.c
+++ b/src/lex.c
@@ -56,6 +56,7 @@ static const keyword_t keywords[] = {
{ "capabilities", TOK_CAPABILITIES },
{ "crypto", TOK_CRYPTO },
{ "debug", TOK_DEBUG },
+ { "debug2", TOK_DEBUG2 },
{ "default", TOK_DEFAULT },
{ "disestablish", TOK_DISESTABLISH },
{ "down", TOK_DOWN },
diff --git a/src/method_aes128_gcm.c b/src/method_aes128_gcm.c
index 3670225..4e51ecf 100644
--- a/src/method_aes128_gcm.c
+++ b/src/method_aes128_gcm.c
@@ -281,7 +281,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
*out = fastd_buffer_alloc(ctx, 0, 0, 0);
}
else {
- pr_debug(ctx, "accepting reordered packet from %P (age %u)", peer, (unsigned)age);
+ pr_debug2(ctx, "accepting reordered packet from %P (age %u)", peer, (unsigned)age);
session->receive_reorder_seen |= (1 << (age-1));
}
diff --git a/src/method_xsalsa20_poly1305.c b/src/method_xsalsa20_poly1305.c
index 9bcf5ed..d0d31f4 100644
--- a/src/method_xsalsa20_poly1305.c
+++ b/src/method_xsalsa20_poly1305.c
@@ -209,7 +209,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
*out = fastd_buffer_alloc(ctx, crypto_secretbox_xsalsa20poly1305_ZEROBYTES, 0, 0);
}
else {
- pr_debug(ctx, "accepting reordered packet from %P (age %u)", peer, (unsigned)age);
+ pr_debug2(ctx, "accepting reordered packet from %P (age %u)", peer, (unsigned)age);
session->receive_reorder_seen |= (1 << (age-1));
}
diff --git a/src/options.c b/src/options.c
index 2641b1b..1462b9f 100644
--- a/src/options.c
+++ b/src/options.c
@@ -115,17 +115,19 @@ static void option_group(fastd_context_t *ctx UNUSED, fastd_config_t *conf, cons
static int parse_log_level(fastd_context_t *ctx, const char *arg) {
if (!strcmp(arg, "fatal"))
- return LOG_CRIT;
+ return LL_FATAL;
else if (!strcmp(arg, "error"))
- return LOG_ERR;
+ return LL_ERROR;
else if (!strcmp(arg, "warn"))
- return LOG_WARNING;
+ return LL_WARN;
else if (!strcmp(arg, "info"))
- return LOG_NOTICE;
+ return LL_INFO;
else if (!strcmp(arg, "verbose"))
- return LOG_INFO;
+ return LL_VERBOSE;
else if (!strcmp(arg, "debug"))
- return LOG_DEBUG;
+ return LL_DEBUG;
+ else if (!strcmp(arg, "debug2"))
+ return LL_DEBUG2;
else
exit_error(ctx, "invalid log level `%s'", arg);
}
diff --git a/src/printf.c b/src/printf.c
index db111a0..deb48c0 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -27,6 +27,7 @@
#include "fastd.h"
#include "peer.h"
+#include <syslog.h>
#include <arpa/inet.h>
#include <net/if.h>
@@ -180,26 +181,45 @@ int fastd_vsnprintf(const fastd_context_t *ctx, char *buffer, size_t size, const
return buffer-buffer_start;
}
-static inline const char* get_log_prefix(int log_level) {
+static inline const char* get_log_prefix(fastd_loglevel_t log_level) {
switch(log_level) {
- case LOG_CRIT:
+ case LL_FATAL:
return "Fatal: ";
- case LOG_ERR:
+ case LL_ERROR:
return "Error: ";
- case LOG_WARNING:
+ case LL_WARN:
return "Warning: ";
- case LOG_NOTICE:
+ case LL_INFO:
return "Info: ";
- case LOG_INFO:
+ case LL_VERBOSE:
return "Verbose: ";
- case LOG_DEBUG:
+ case LL_DEBUG:
return "DEBUG: ";
+ case LL_DEBUG2:
+ return "DEBUG2: ";
default:
return "";
}
}
-void fastd_logf(const fastd_context_t *ctx, int level, const char *format, ...) {
+static inline int get_syslog_level(fastd_loglevel_t log_level) {
+ switch(log_level) {
+ case LL_FATAL:
+ return LOG_CRIT;
+ case LL_ERROR:
+ return LOG_ERR;
+ case LL_WARN:
+ return LOG_WARNING;
+ case LL_INFO:
+ return LOG_NOTICE;
+ case LL_VERBOSE:
+ return LOG_INFO;
+ default:
+ return LOG_DEBUG;
+ }
+}
+
+void fastd_logf(const fastd_context_t *ctx, fastd_loglevel_t level, const char *format, ...) {
char buffer[1024];
char timestr[100] = "";
va_list ap;
@@ -225,7 +245,7 @@ void fastd_logf(const fastd_context_t *ctx, int level, const char *format, ...)
fprintf(stderr, "%s%s%s\n", timestr, get_log_prefix(level), buffer);
if (ctx->conf != NULL && level <= ctx->conf->log_syslog_level)
- syslog(level, "%s", buffer);
+ syslog(get_syslog_level(level), "%s", buffer);
fastd_log_fd_t *file;
for (file = ctx->log_files; file; file = file->next) {
diff --git a/src/protocol_ec25519_fhmqvc.c b/src/protocol_ec25519_fhmqvc.c
index b020530..711fdee 100644
--- a/src/protocol_ec25519_fhmqvc.c
+++ b/src/protocol_ec25519_fhmqvc.c
@@ -830,7 +830,7 @@ static void protocol_send(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer
check_session_refresh(ctx, peer);
if (peer->protocol_state->session.method->session_is_initiator(ctx, peer->protocol_state->session.method_state) && is_session_valid(ctx, &peer->protocol_state->old_session)) {
- pr_debug(ctx, "sending packet for old session to %P", peer);
+ pr_debug2(ctx, "sending packet for old session to %P", peer);
session_send(ctx, peer, buffer, &peer->protocol_state->old_session);
}
else {
diff --git a/src/types.h b/src/types.h
index bb7663e..2dcfa58 100644
--- a/src/types.h
+++ b/src/types.h
@@ -65,6 +65,17 @@ typedef enum fastd_peer_state {
STATE_ESTABLISHED,
} fastd_peer_state_t;
+typedef enum fastd_loglevel {
+ LL_UNSPEC = 0,
+ LL_FATAL,
+ LL_ERROR,
+ LL_WARN,
+ LL_INFO,
+ LL_VERBOSE,
+ LL_DEBUG,
+ LL_DEBUG2,
+} fastd_loglevel_t;
+
typedef struct fastd_buffer fastd_buffer_t;
typedef union fastd_peer_address fastd_peer_address_t;