summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c20
-rw-r--r--src/config.l8
-rw-r--r--src/config.y22
-rw-r--r--src/fastd.h2
4 files changed, 49 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index 8534fe2..358a785 100644
--- a/src/config.c
+++ b/src/config.c
@@ -49,7 +49,7 @@ extern fastd_protocol fastd_protocol_ec25519_fhmqvc_xsalsa20_poly1305;
static void default_config(fastd_config *conf) {
- conf->loglevel = LOG_DEBUG;
+ conf->loglevel = LOG_INFO;
conf->peer_stale_time = 300;
conf->peer_stale_time_temp = 30;
@@ -223,6 +223,24 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
while (i < argc) {
+ IF_OPTION_ARG("--log-level") {
+ if (!strcmp(arg, "fatal"))
+ conf->loglevel = LOG_FATAL;
+ else if (!strcmp(arg, "error"))
+ conf->loglevel = LOG_ERROR;
+ else if (!strcmp(arg, "warn"))
+ conf->loglevel = LOG_WARN;
+ else if (!strcmp(arg, "info"))
+ conf->loglevel = LOG_INFO;
+ else if (!strcmp(arg, "verbose"))
+ conf->loglevel = LOG_VERBOSE;
+ else if (!strcmp(arg, "debug"))
+ conf->loglevel = LOG_DEBUG;
+ else
+ exit_error(ctx, "invalid mode `%s'", arg);
+ continue;
+ }
+
IF_OPTION_ARG("-c", "--config") {
fastd_read_config(ctx, conf, arg, false, 0);
continue;
diff --git a/src/config.l b/src/config.l
index 447daed..7901faa 100644
--- a/src/config.l
+++ b/src/config.l
@@ -72,6 +72,14 @@ on { UPDATE_LOCATION; return TOK_ON; }
up { UPDATE_LOCATION; return TOK_UP; }
peers { UPDATE_LOCATION; return TOK_PEERS; }
from { UPDATE_LOCATION; return TOK_FROM; }
+log { UPDATE_LOCATION; return TOK_LOG; }
+level { UPDATE_LOCATION; return TOK_LEVEL; }
+fatal { UPDATE_LOCATION; return TOK_FATAL; }
+error { UPDATE_LOCATION; return TOK_ERROR; }
+warn { UPDATE_LOCATION; return TOK_WARN; }
+info { UPDATE_LOCATION; return TOK_INFO; }
+verbose { UPDATE_LOCATION; return TOK_VERBOSE; }
+debug { UPDATE_LOCATION; return TOK_DEBUG; }
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} {
UPDATE_LOCATION;
diff --git a/src/config.y b/src/config.y
index d4b9af6..37a4ea9 100644
--- a/src/config.y
+++ b/src/config.y
@@ -72,6 +72,14 @@
%token TOK_UP
%token TOK_PEERS
%token TOK_FROM
+%token TOK_LOG
+%token TOK_LEVEL
+%token TOK_FATAL
+%token TOK_ERROR
+%token TOK_WARN
+%token TOK_INFO
+%token TOK_VERBOSE
+%token TOK_DEBUG
%token <addr> TOK_ADDR
%token <addr6> TOK_ADDR6
@@ -107,7 +115,8 @@ config: config statement
|
;
-statement: TOK_INTERFACE interface ';'
+statement: TOK_LOG log ';'
+ | TOK_INTERFACE interface ';'
| TOK_BIND bind ';'
| TOK_MTU mtu ';'
| TOK_MODE mode ';'
@@ -118,6 +127,17 @@ statement: TOK_INTERFACE interface ';'
| TOK_INCLUDE include ';'
;
+log: TOK_LEVEL log_level
+ ;
+
+log_level: TOK_FATAL { conf->loglevel = LOG_FATAL; }
+ | TOK_ERROR { conf->loglevel = LOG_ERROR; }
+ | TOK_WARN { conf->loglevel = LOG_WARN; }
+ | TOK_INFO { conf->loglevel = LOG_INFO; }
+ | TOK_VERBOSE { conf->loglevel = LOG_VERBOSE; }
+ | TOK_DEBUG { conf->loglevel = LOG_DEBUG; }
+ ;
+
interface: TOK_STRING { free(conf->ifname); conf->ifname = $1; }
;
diff --git a/src/fastd.h b/src/fastd.h
index 8e63884..e48929d 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -158,7 +158,7 @@ static inline int fastd_rand(fastd_context *ctx, int min, int max) {
#define pr_error(ctx, args...) pr_log(ctx, LOG_ERROR, "Error: ", args)
#define pr_warn(ctx, args...) pr_log(ctx, LOG_WARN, "Warning: ", args)
#define pr_info(ctx, args...) pr_log(ctx, LOG_INFO, "Info: ", args)
-#define pr_verbose(ctx, args...) pr_log(ctx, LOG_INFO, "Verbose: ", args)
+#define pr_verbose(ctx, args...) pr_log(ctx, LOG_VERBOSE, "Verbose: ", args)
#define pr_debug(ctx, args...) pr_log(ctx, LOG_DEBUG, "DEBUG: ", args)
#define warn_errno(ctx, message) pr_warn(ctx, "%s: %s", message, strerror(errno))