From 9e434460030cc7a9919671ca3843ff4c0a8ea17e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 11 Jan 2015 10:56:11 +0100 Subject: config: allow ipv4/ipv6 keywords before static addresses --- src/config.y | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/config.y b/src/config.y index 35b8901..bd106e7 100644 --- a/src/config.y +++ b/src/config.y @@ -458,41 +458,41 @@ peer_statement: TOK_REMOTE peer_remote ';' | TOK_INCLUDE peer_include ';' ; -peer_remote: TOK_ADDR4 port { +peer_remote: maybe_ipv4 TOK_ADDR4 port { fastd_remote_t remote = {}; remote.address.in.sin_family = AF_INET; - remote.address.in.sin_addr = $1; - remote.address.in.sin_port = htons($2); + remote.address.in.sin_addr = $2; + remote.address.in.sin_port = htons($3); fastd_peer_address_simplify(&remote.address); VECTOR_ADD(state->peer->remotes, remote); } - | TOK_ADDR6 port { + | maybe_ipv6 TOK_ADDR6 port { fastd_remote_t remote = {}; remote.address.in6.sin6_family = AF_INET6; - remote.address.in6.sin6_addr = $1; - remote.address.in6.sin6_port = htons($2); + remote.address.in6.sin6_addr = $2; + remote.address.in6.sin6_port = htons($3); fastd_peer_address_simplify(&remote.address); VECTOR_ADD(state->peer->remotes, remote); } - | TOK_ADDR6_SCOPED port { + | maybe_ipv6 TOK_ADDR6_SCOPED port { char addrbuf[INET6_ADDRSTRLEN]; size_t addrlen; - inet_ntop(AF_INET6, &$1.addr, addrbuf, sizeof(addrbuf)); + inet_ntop(AF_INET6, &$2.addr, addrbuf, sizeof(addrbuf)); addrlen = strlen(addrbuf); fastd_remote_t remote = {}; - remote.hostname = fastd_alloc(addrlen + strlen($1.ifname) + 2); + remote.hostname = fastd_alloc(addrlen + strlen($2.ifname) + 2); memcpy(remote.hostname, addrbuf, addrlen); remote.hostname[addrlen] = '%'; - strcpy(remote.hostname+addrlen+1, $1.ifname); + strcpy(remote.hostname+addrlen+1, $2.ifname); remote.address.sa.sa_family = AF_INET6; - remote.address.in.sin_port = htons($2); + remote.address.in.sin_port = htons($3); VECTOR_ADD(state->peer->remotes, remote); } @@ -587,6 +587,14 @@ maybe_af: TOK_IPV4 { $$ = AF_INET; } | { $$ = AF_UNSPEC; } ; +maybe_ipv4: TOK_IPV4 + | + ; + +maybe_ipv6: TOK_IPV6 + | + ; + sync_def_sync: sync { $$ = $1; } | { $$ = true; } ; -- cgit v1.2.3