summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-03-25 00:16:20 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-03-25 00:16:20 +0100
commit6ce20e2bb6660694e995d890f2846fc26c96c8f7 (patch)
tree5cbe80433351372237843f11951518e16e9a32b8 /src
parent0b61ebf351a69a3451727254eec2c7e1cc024b4c (diff)
downloadfastd-6ce20e2bb6660694e995d890f2846fc26c96c8f7.tar
fastd-6ce20e2bb6660694e995d890f2846fc26c96c8f7.zip
Add keypair config
Diffstat (limited to 'src')
-rw-r--r--src/config.c20
-rw-r--r--src/config.l2
-rw-r--r--src/config.y13
-rw-r--r--src/fastd.h3
-rw-r--r--src/peer.h1
5 files changed, 31 insertions, 8 deletions
diff --git a/src/config.c b/src/config.c
index 13fb8b5..12b92b3 100644
--- a/src/config.c
+++ b/src/config.c
@@ -65,6 +65,7 @@ static void default_config(fastd_config *conf) {
conf->mtu = 1500;
conf->mode = MODE_TAP;
conf->protocol = &fastd_protocol_null;
+ conf->secret = NULL;
conf->peers = NULL;
}
@@ -90,16 +91,22 @@ static bool config_match(const char *opt, ...) {
static void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filename) {
yyscan_t scanner;
FILE *file;
+ bool use_stdin = !strcmp(filename, "-");
- file = fopen(filename, "r");
- fastd_config_lex_init(&scanner);
+ if (use_stdin)
+ file = stdin;
+ else
+ file = fopen(filename, "r");
+ fastd_config_lex_init(&scanner);
fastd_config_set_in(file, scanner);
fastd_config_parse(ctx, conf, scanner);
fastd_config_lex_destroy(scanner);
- fclose(file);
+
+ if (!use_stdin)
+ fclose(file);
}
#define IF_OPTION(args...) if(config_match(argv[i], args, NULL) && (++i))
@@ -131,7 +138,8 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
}
IF_OPTION_ARG("-i", "--interface") {
- conf->ifname = arg;
+ free(conf->ifname);
+ conf->ifname = strdup(arg);
continue;
}
@@ -160,7 +168,7 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
if (charptr) {
l = strtol(charptr+1, &endptr, 10);
- if (*endptr || l > 65535)
+ if (*endptr || l < 0 || l > 65535)
exit_error(ctx, "invalid bind port `%s'", charptr+1);
}
else {
@@ -255,7 +263,7 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con
if (charptr) {
l = strtol(charptr+1, &endptr, 10);
- if (*endptr || l > 65535)
+ if (*endptr || l < 0 || l > 65535)
exit_error(ctx, "invalid peer port `%s'", charptr+1);
}
else {
diff --git a/src/config.l b/src/config.l
index 5e5e666..1173d44 100644
--- a/src/config.l
+++ b/src/config.l
@@ -20,6 +20,8 @@ mode { yylval->str = yytext; return TOK_MODE; }
protocol { yylval->str = yytext; return TOK_PROTOCOL; }
peer { yylval->str = yytext; return TOK_PEER; }
address { yylval->str = yytext; return TOK_ADDRESS; }
+secret { yylval->str = yytext; return TOK_SECRET; }
+key { yylval->str = yytext; return TOK_KEY; }
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} {
if (!inet_pton(AF_INET, yytext, &yylval->addr)) {
diff --git a/src/config.y b/src/config.y
index 9a0d333..02a9529 100644
--- a/src/config.y
+++ b/src/config.y
@@ -29,6 +29,8 @@
%token <str> TOK_PROTOCOL
%token <str> TOK_PEER
%token <str> TOK_ADDRESS
+%token <str> TOK_SECRET
+%token <str> TOK_KEY
%token <addr> TOK_ADDR
%token <addr6> TOK_ADDR6
@@ -73,10 +75,11 @@ statement: TOK_INTERFACE interface ';'
| TOK_MTU mtu ';'
| TOK_MODE mode ';'
| TOK_PROTOCOL protocol ';'
+ | TOK_SECRET secret ';'
| TOK_PEER peer '{' peer_conf '}'
;
-interface: TOK_STRING { conf->ifname = strdup($1); }
+interface: TOK_STRING { free(conf->ifname); conf->ifname = strdup($1); }
;
bind: TOK_ADDR maybe_port {
@@ -116,6 +119,9 @@ protocol: maybe_string {
}
;
+secret: TOK_STRING { free(conf->secret); conf->secret = strdup($1); }
+ ;
+
peer: maybe_string {
fastd_peer_config *current_peer = malloc(sizeof(fastd_peer_config));
current_peer->next = conf->peers;
@@ -132,6 +138,7 @@ peer_conf: peer_conf peer_statement
;
peer_statement: TOK_ADDRESS peer_address ';'
+ | TOK_KEY peer_key ';'
;
peer_address: TOK_ADDR maybe_port_default {
@@ -146,6 +153,10 @@ peer_address: TOK_ADDR maybe_port_default {
}
;
+peer_key: TOK_STRING { free(conf->peers->key); conf->peers->key = strdup($1); }
+ ;
+
+
maybe_string: TOK_STRING
| { $$[0] = '\0'; }
;
diff --git a/src/fastd.h b/src/fastd.h
index d911a71..c453790 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -81,7 +81,7 @@ struct _fastd_config {
unsigned peer_stale_time_temp;
unsigned eth_addr_stale_time;
- const char *ifname;
+ char *ifname;
struct sockaddr_in bind_addr_in;
struct sockaddr_in6 bind_addr_in6;
@@ -90,6 +90,7 @@ struct _fastd_config {
fastd_mode mode;
fastd_protocol *protocol;
+ char *secret;
fastd_peer_config *peers;
diff --git a/src/peer.h b/src/peer.h
index 39fcc02..8b3b3ac 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -56,6 +56,7 @@ struct _fastd_peer_config {
fastd_peer_config *next;
fastd_peer_address address;
+ char *key;
};
struct _fastd_peer_eth_addr {