Improve ifname configuration handling

This commit is contained in:
Matthias Schiffer 2015-03-23 05:20:03 +01:00
parent 2c6147d4d4
commit b2e576bb17
4 changed files with 24 additions and 10 deletions

View file

@ -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");

View file

@ -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);

View file

@ -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;
}
}
;

View file

@ -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 */