From 921485a5bc0c8448bcc23ae5587777e762473dd2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 29 Oct 2012 23:06:24 +0100 Subject: Allow setting IPv[46] default bind addresses --- src/config.l | 1 + src/config.y | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/config.l b/src/config.l index 1ee4b28..404384e 100644 --- a/src/config.l +++ b/src/config.l @@ -99,6 +99,7 @@ port { TOKEN(TOK_PORT); } float { TOKEN(TOK_FLOAT); } crypto { TOKEN(TOK_CRYPTO); } use { TOKEN(TOK_USE); } +default { TOKEN(TOK_DEFAULT); } [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} { UPDATE_LOCATION; diff --git a/src/config.y b/src/config.y index 0693294..59fc296 100644 --- a/src/config.y +++ b/src/config.y @@ -97,6 +97,7 @@ %token TOK_FLOAT %token TOK_CRYPTO %token TOK_USE +%token TOK_DEFAULT %token TOK_ADDR %token TOK_ADDR6 @@ -194,21 +195,21 @@ bind_new: { } ; -bind: bind_new TOK_ADDR maybe_port maybe_bind_to_device { +bind: bind_new TOK_ADDR maybe_port maybe_bind_to_device maybe_bind_default { conf->bind_addrs->addr.in.sin_family = AF_INET; conf->bind_addrs->addr.in.sin_addr = $2; conf->bind_addrs->addr.in.sin_port = htons($3); if (!conf->bind_addr_default_v4) conf->bind_addr_default_v4 = conf->bind_addrs; } - | bind_new TOK_ADDR6 maybe_port maybe_bind_to_device { + | bind_new TOK_ADDR6 maybe_port maybe_bind_to_device maybe_bind_default { conf->bind_addrs->addr.in6.sin6_family = AF_INET6; conf->bind_addrs->addr.in6.sin6_addr = $2; conf->bind_addrs->addr.in6.sin6_port = htons($3); if (!conf->bind_addr_default_v6) conf->bind_addr_default_v6 = conf->bind_addrs; } - | bind_new TOK_ANY maybe_port maybe_bind_to_device { + | bind_new TOK_ANY maybe_port maybe_bind_to_device maybe_bind_default { conf->bind_addrs->addr.in.sin_port = htons($3); if (!conf->bind_addr_default_v4) conf->bind_addr_default_v4 = conf->bind_addrs; @@ -221,7 +222,37 @@ maybe_bind_to_device: TOK_INTERFACE TOK_STRING { conf->bind_addrs->bindtodev = strdup($2->str); } - | {} + | + ; + +maybe_bind_default: + TOK_DEFAULT bind_default + | + ; + +bind_default: + TOK_IPV4 { + if (conf->bind_addrs->addr.sa.sa_family == AF_INET6) { + fastd_config_error(&@$, ctx, conf, filename, depth, "tried to set IPv6 bind as IPv4 default"); + YYERROR; + } + + conf->bind_addr_default_v4 = conf->bind_addrs; + } + | TOK_IPV6 { + if (conf->bind_addrs->addr.sa.sa_family == AF_INET) { + fastd_config_error(&@$, ctx, conf, filename, depth, "tried to set IPv4 bind as IPv6 default"); + YYERROR; + } + + conf->bind_addr_default_v6 = conf->bind_addrs; + } + | { + if (conf->bind_addrs->addr.sa.sa_family != AF_INET6) + conf->bind_addr_default_v4 = conf->bind_addrs; + if (conf->bind_addrs->addr.sa.sa_family != AF_INET) + conf->bind_addr_default_v6 = conf->bind_addrs; + } ; mtu: TOK_INTEGER { conf->mtu = $1; } -- cgit v1.2.3