diff options
-rw-r--r-- | src/config.c | 26 | ||||
-rw-r--r-- | src/config.h | 6 | ||||
-rw-r--r-- | src/config.y | 23 | ||||
-rw-r--r-- | src/options.c | 3 |
4 files changed, 21 insertions, 37 deletions
diff --git a/src/config.c b/src/config.c index b6ea94f..bfdfd2e 100644 --- a/src/config.c +++ b/src/config.c @@ -79,13 +79,11 @@ static void default_config(fastd_config_t *conf) { conf->macs = fastd_mac_config_alloc(); } -bool fastd_config_protocol(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *name) { +void fastd_config_protocol(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *name) { if (!strcmp(name, "ec25519-fhmqvc")) conf->protocol = &fastd_protocol_ec25519_fhmqvc; else - return false; - - return true; + exit_error(ctx, "protocol `%s' not supported", name); } void fastd_config_method(fastd_context_t *ctx, fastd_config_t *conf, const char *name) { @@ -101,10 +99,10 @@ void fastd_config_method(fastd_context_t *ctx, fastd_config_t *conf, const char *method = fastd_string_stack_dup(name); } -bool fastd_config_bind_address(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6) { +void fastd_config_bind_address(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6) { #ifndef USE_BINDTODEVICE if (bindtodev) - return false; + exit_error(ctx, "device bind configuration not supported on this system"); #endif #ifndef USE_MULTIAF_BIND @@ -112,13 +110,9 @@ bool fastd_config_bind_address(fastd_context_t *ctx UNUSED, fastd_config_t *conf fastd_peer_address_t addr4 = { .in = { .sin_family = AF_INET, .sin_port = address->in.sin_port } }; fastd_peer_address_t addr6 = { .in6 = { .sin6_family = AF_INET6, .sin6_port = address->in.sin_port } }; - if (!fastd_config_bind_address(ctx, conf, &addr4, bindtodev, default_v4, default_v6)) - return false; - - if (!fastd_config_bind_address(ctx, conf, &addr6, bindtodev, default_v4, default_v6)) - return false; - - return true; + fastd_config_bind_address(ctx, conf, &addr4, bindtodev, default_v4, default_v6); + fastd_config_bind_address(ctx, conf, &addr6, bindtodev, default_v4, default_v6); + return; } #endif @@ -137,8 +131,6 @@ bool fastd_config_bind_address(fastd_context_t *ctx UNUSED, fastd_config_t *conf if (addr->addr.sa.sa_family != AF_INET && (default_v6 || !conf->bind_addr_default_v6)) conf->bind_addr_default_v6 = addr; - - return true; } void fastd_config_peer_group_push(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *name) { @@ -183,7 +175,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, fastd_loglevel_t level) { +void 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); @@ -219,8 +211,6 @@ bool fastd_config_add_log_file(fastd_context_t *ctx, fastd_config_t *conf, const free(oldcwd); free(name2); free(name3); - - return true; } static void read_peer_dir(fastd_context_t *ctx, fastd_config_t *conf, const char *dir) { diff --git a/src/config.h b/src/config.h index ad3d6b1..2b43968 100644 --- a/src/config.h +++ b/src/config.h @@ -30,10 +30,10 @@ #include "fastd.h" -bool fastd_config_protocol(fastd_context_t *ctx, fastd_config_t *conf, const char *name); +void fastd_config_protocol(fastd_context_t *ctx, fastd_config_t *conf, const char *name); void fastd_config_method(fastd_context_t *ctx, fastd_config_t *conf, const char *name); -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_add_log_file(fastd_context_t *ctx, fastd_config_t *conf, const char *name, fastd_loglevel_t level); +void 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); void fastd_config_release(fastd_context_t *ctx, fastd_config_t *conf); diff --git a/src/config.y b/src/config.y index 68d41a4..dfa8a18 100644 --- a/src/config.y +++ b/src/config.y @@ -242,10 +242,7 @@ log: TOK_LEVEL log_level { conf->log_syslog_level = $5; } | TOK_TO TOK_STRING maybe_log_level { - if (!fastd_config_add_log_file(ctx, conf, $2->str, $3)) { - fastd_config_error(&@$, ctx, conf, filename, depth, "unable to set log file"); - YYERROR; - } + fastd_config_add_log_file(ctx, conf, $2->str, $3); } ; @@ -275,10 +272,7 @@ interface: TOK_STRING { free(conf->ifname); conf->ifname = strdup($1->str); } ; bind: bind_address maybe_bind_interface maybe_bind_default { - if (!fastd_config_bind_address(ctx, conf, &$1, $2 ? $2->str : NULL, $3 == AF_UNSPEC || $3 == AF_INET, $3 == AF_UNSPEC || $3 == AF_INET6)) { - fastd_config_error(&@$, ctx, conf, filename, depth, "invalid bind directive"); - YYERROR; - } + fastd_config_bind_address(ctx, conf, &$1, $2 ? $2->str : NULL, $3 == AF_UNSPEC || $3 == AF_INET, $3 == AF_UNSPEC || $3 == AF_INET6); } ; @@ -325,7 +319,7 @@ bind_default: ; mtu: TOK_UINT { - if (conf->mtu < 576 || $1 > 65535) { + if ($1 < 576 || $1 > 65535) { fastd_config_error(&@$, ctx, conf, filename, depth, "invalid MTU"); YYERROR; } @@ -342,10 +336,7 @@ mode: TOK_TAP { conf->mode = MODE_TAP; } ; protocol: TOK_STRING { - if (!fastd_config_protocol(ctx, conf, $1->str)) { - fastd_config_error(&@$, ctx, conf, filename, depth, "unsupported protocol"); - YYERROR; - } + fastd_config_protocol(ctx, conf, $1->str); } ; @@ -470,7 +461,11 @@ peer_remote: TOK_ADDR4 port { (*remote)->hostname = strdup($2->str); (*remote)->address.sa.sa_family = $1; (*remote)->address.in.sin_port = htons($3); - conf->peers->floating = conf->peers->dynamic_float_deprecated = $4; + + if ($4) { + conf->peers->floating = true; + conf->peers->dynamic_float_deprecated = true; + } } ; diff --git a/src/options.c b/src/options.c index c86717b..f9a147a 100644 --- a/src/options.c +++ b/src/options.c @@ -246,8 +246,7 @@ static void option_bind(fastd_context_t *ctx, fastd_config_t *conf, const char * } static void option_protocol(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { - if (!fastd_config_protocol(ctx, conf, arg)) - exit_error(ctx, "unsupported protocol `%s'", arg); + fastd_config_protocol(ctx, conf, arg); } static void option_method(fastd_context_t *ctx, fastd_config_t *conf, const char *arg) { |