summaryrefslogtreecommitdiffstats
path: root/src/config.y
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-03-24 22:32:24 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-03-24 22:32:24 +0100
commit359e9b6c2b0cc4817b55338f0b89638945d98c50 (patch)
tree731b1b59a96f9ff84a6a5b531964418bee634815 /src/config.y
parent4ffc28ecd6d914f9c1e5aaf5d5921ee4827bb289 (diff)
downloadfastd-359e9b6c2b0cc4817b55338f0b89638945d98c50.tar
fastd-359e9b6c2b0cc4817b55338f0b89638945d98c50.zip
Rename methods to protocols; fix some command line parse bugs; implement most of the config file parser
Diffstat (limited to 'src/config.y')
-rw-r--r--src/config.y119
1 files changed, 91 insertions, 28 deletions
diff --git a/src/config.y b/src/config.y
index 08c5050..a949860 100644
--- a/src/config.y
+++ b/src/config.y
@@ -3,7 +3,7 @@
%lex-param {fastd_context *ctx}
%lex-param {yyscan_t scanner}
%parse-param {fastd_context *ctx}
-%parse-param {fastd_config *config}
+%parse-param {fastd_config *conf}
%parse-param {yyscan_t scanner}
%code requires {
@@ -27,32 +27,41 @@
%token <str> TOK_MODE
%token <str> TOK_PROTOCOL
%token <str> TOK_PEER
+%token <str> TOK_ADDRESS
%token <addr> TOK_ADDR
%token <addr6> TOK_ADDR6
%token <str> TOK_ANY
-%token <str> TOK_FLOAT
%token <str> TOK_TAP
%token <str> TOK_TUN
-/* %code top {
- #define YY_DECL int fastd_config_lex(YYSTYPE *yylval_param, fastd_context *ctx, yyscan_t yyscanner)
-}*/
-
-
%code {
+ #include <config.h>
#include <config.ll.h>
- YY_DECL;
+ #include <stdint.h>
+ #include <peer.h>
+
+ void fastd_config_error(fastd_context *ctx, fastd_config *conf, yyscan_t scanner, char *s);
- void fastd_config_error(fastd_context *ctx, fastd_config *config, void *scanner, char *s);
+ extern fastd_protocol fastd_protocol_null;
+
+ #ifdef WITH_PROTOCOL_ECFXP
+ extern fastd_protocol fastd_protocol_ec25519_fhmqvc_xsalsa20_poly1305;
+ #endif
}
%code provides {
#include <fastd.h>
- int fastd_config_parse (fastd_context *ctx, fastd_config *config, void *scanner);
+ int fastd_config_parse (fastd_context *ctx, fastd_config *conf, void *scanner);
}
+%type <str> maybe_string
+
+%type <num> port
+%type <num> maybe_port
+%type <num> maybe_port_default
+
%%
config: config statement
|
@@ -63,44 +72,98 @@ statement: TOK_INTERFACE interface ';'
| TOK_MTU mtu ';'
| TOK_MODE mode ';'
| TOK_PROTOCOL protocol ';'
- | TOK_PEER peer '{' peer_config '}'
+ | TOK_PEER peer '{' peer_conf '}'
;
-interface: TOK_STRING { config->ifname = strdup($1); }
+interface: TOK_STRING { conf->ifname = strdup($1); }
;
-bind: TOK_ADDR
- | TOK_ADDR ':' port
- | TOK_ADDR6
- | TOK_ADDR6 ':' port
- | TOK_ANY
- | TOK_ANY ':' port
+bind: TOK_ADDR maybe_port {
+ conf->bind_addr_in.sin_family = AF_INET;
+ conf->bind_addr_in.sin_addr = $1;
+ conf->bind_addr_in.sin_port = $2;
+ }
+ | TOK_ADDR6 maybe_port {
+ conf->bind_addr_in6.sin6_family = AF_INET6;
+ conf->bind_addr_in6.sin6_addr = $1;
+ conf->bind_addr_in6.sin6_port = $2;
+ }
+ | TOK_ANY maybe_port {
+ conf->bind_addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
+ conf->bind_addr_in.sin_port = $2;
+ conf->bind_addr_in6.sin6_addr = in6addr_any;
+ conf->bind_addr_in6.sin6_port = $2;
+ }
;
-mtu: TOK_INTEGER { config->mtu = $1; }
+mtu: TOK_INTEGER { conf->mtu = $1; }
;
-mode: TOK_TAP { config->mode = MODE_TAP; }
- | TOK_TUN { config->mode = MODE_TUN; }
+mode: TOK_TAP { conf->mode = MODE_TAP; }
+ | TOK_TUN { conf->mode = MODE_TUN; }
;
-protocol: TOK_STRING
+protocol: maybe_string {
+ if (!strcmp($1, "null"))
+ conf->protocol = &fastd_protocol_null;
+#ifdef WITH_PROTOCOL_ECFXP
+ if (!strcmp($1, "ecfxp"))
+ conf->protocol = &fastd_protocol_ec25519_fhmqvc_xsalsa20_poly1305;
+#endif
+ else
+ exit_error(ctx, "config error: invalid protocol `%s'", $1);
+}
;
-peer: TOK_STRING
- |
+peer: maybe_string {
+ fastd_peer_config *current_peer = malloc(sizeof(fastd_peer_config));
+ current_peer->next = conf->peers;
+ conf->peers = current_peer;
+
+ memset(&current_peer->address, 0, sizeof(fastd_peer_address));
+
+ current_peer->address.sa.sa_family = AF_UNSPEC;
+ }
;
-peer_config: peer_config peer_statement
+peer_conf: peer_conf peer_statement
|
;
-peer_statement: ':'
+peer_statement: TOK_ADDRESS peer_address
+ ;
+
+peer_address: TOK_ADDR maybe_port_default {
+ conf->peers->address.in.sin_family = AF_INET;
+ conf->peers->address.in.sin_addr = $1;
+ conf->peers->address.in.sin_port = $2;
+ }
+ | TOK_ADDR6 maybe_port_default {
+ conf->peers->address.in6.sin6_family = AF_INET6;
+ conf->peers->address.in6.sin6_addr = $1;
+ conf->peers->address.in6.sin6_port = $2;
+ }
+ ;
+
+maybe_string: TOK_STRING
+ | { $$[0] = '\0'; }
+ ;
+
+maybe_port: ':' port { $$ = $2; }
+ | { $$ = 0; }
+ ;
+
+maybe_port_default: ':' port { $$ = $2; }
+ | { $$ = htons(1337); }
;
-port: TOK_INTEGER
+port: TOK_INTEGER {
+ if ($1 < 0 || $1 > 65635)
+ exit_error(ctx, "invalid port %i", $1);
+ $$ = htons($1);
+ }
;
%%
-void fastd_config_error(fastd_context *ctx, fastd_config *config, yyscan_t scanner, char *s) {
+void fastd_config_error(fastd_context *ctx, fastd_config *conf, yyscan_t scanner, char *s) {
exit_error(ctx, "config error: %s", s);
}