summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c17
-rw-r--r--src/config.h1
-rw-r--r--src/config.y13
-rw-r--r--src/options.c3
4 files changed, 24 insertions, 10 deletions
diff --git a/src/config.c b/src/config.c
index 725c4e4..511d4e7 100644
--- a/src/config.c
+++ b/src/config.c
@@ -98,6 +98,18 @@ void fastd_config_method(fastd_peer_group_t *group, const char *name) {
*method = fastd_string_stack_dup(name);
}
+bool fastd_config_ifname(fastd_peer_t *peer, const char *ifname) {
+ if (strchr(ifname, '/'))
+ return false;
+
+ char **name = peer ? &peer->ifname : &conf.ifname;
+
+ free(*name);
+ *name = fastd_strdup(ifname);
+
+ return true;
+}
+
/** Handles the configuration of a cipher implementation */
void fastd_config_cipher(const char *name, const char *impl) {
if (!fastd_cipher_config(name, impl))
@@ -533,11 +545,6 @@ void fastd_configure(int argc, char *const argv[]) {
/** Performs some basic checks on the configuration */
static void config_check_base(void) {
- if (conf.ifname) {
- if (strchr(conf.ifname, '/'))
- exit_error("config error: invalid interface name");
- }
-
#ifndef USE_PACKET_MARK
if (conf.packet_mark)
exit_error("config error: setting a packet mark is not supported on this system");
diff --git a/src/config.h b/src/config.h
index b96247f..0d1bffc 100644
--- a/src/config.h
+++ b/src/config.h
@@ -47,6 +47,7 @@ struct fastd_parser_state {
void fastd_config_protocol(const char *name);
void fastd_config_method(fastd_peer_group_t *group, const char *name);
+bool fastd_config_ifname(fastd_peer_t *peer, const char *ifname);
void fastd_config_cipher(const char *name, const char *impl);
void fastd_config_mac(const char *name, const char *impl);
void fastd_config_bind_address(const fastd_peer_address_t *address, const char *bindtodev, bool default_v4, bool default_v6);
diff --git a/src/config.y b/src/config.y
index 36b7368..fb2ceee 100644
--- a/src/config.y
+++ b/src/config.y
@@ -302,7 +302,12 @@ log_level: TOK_FATAL { $$ = LL_FATAL; }
| TOK_DEBUG2 { $$ = LL_DEBUG2; }
;
-interface: TOK_STRING { free(conf.ifname); conf.ifname = fastd_strdup($1->str); }
+interface: TOK_STRING {
+ if (!fastd_config_ifname(NULL, $1->str)) {
+ fastd_config_error(&@$, state, "invalid interface name");
+ YYERROR;
+ }
+ }
;
bind: bind_address maybe_bind_interface maybe_bind_default {
@@ -528,8 +533,10 @@ peer_key: TOK_STRING {
;
peer_interface: TOK_STRING {
- free(state->peer->ifname);
- state->peer->ifname = fastd_strdup($1->str);
+ if (!fastd_config_ifname(state->peer, $1->str)) {
+ fastd_config_error(&@$, state, "invalid interface name");
+ YYERROR;
+ }
}
;
diff --git a/src/options.c b/src/options.c
index 44b097b..a84830b 100644
--- a/src/options.c
+++ b/src/options.c
@@ -228,8 +228,7 @@ static void option_mode(const char *arg) {
/** Handles the --interface option */
static void option_interface(const char *arg) {
- free(conf.ifname);
- conf.ifname = fastd_strdup(arg);
+ fastd_config_ifname(NULL, arg);
}
/** Handles the --mtu option */