diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-04-01 22:28:31 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-04-01 22:28:31 +0200 |
commit | bd781685508ae5096f864ba969824e299c7f327c (patch) | |
tree | 574d91e2dcbc61a7bb9096d6a46dd3b6f70825c5 | |
parent | 14d6915f098c6d51a6e879b81f70d9b9dba0b867 (diff) | |
download | fastd-bd781685508ae5096f864ba969824e299c7f327c.tar fastd-bd781685508ae5096f864ba969824e299c7f327c.zip |
Require port with peer specfication, remove default port
-rw-r--r-- | src/config.c | 27 | ||||
-rw-r--r-- | src/config.y | 13 | ||||
-rw-r--r-- | src/peer.c | 2 |
3 files changed, 14 insertions, 28 deletions
diff --git a/src/config.c b/src/config.c index 5acdc21..8534fe2 100644 --- a/src/config.c +++ b/src/config.c @@ -340,33 +340,24 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con if (arg[0] == '[') { charptr = strchr(arg, ']'); - if (!charptr || (charptr[1] != ':' && charptr[1] != '\0')) + if (!charptr || (charptr[1] != ':')) exit_error(ctx, "invalid peer address `%s'", arg); addrstr = strndup(arg+1, charptr-arg-1); - - if (charptr[1] == ':') - charptr++; - else - charptr = NULL; + charptr++; } else { charptr = strchr(arg, ':'); - if (charptr) - addrstr = strndup(arg, charptr-arg); - else - addrstr = strdup(arg); - } + if (!charptr) + exit_error(ctx, "invalid peer address `%s'", arg); - if (charptr) { - l = strtol(charptr+1, &endptr, 10); - if (*endptr || l < 0 || l > 65535) - exit_error(ctx, "invalid peer port `%s'", charptr+1); - } - else { - l = 1337; /* default port */ + addrstr = strndup(arg, charptr-arg); } + l = strtol(charptr+1, &endptr, 10); + if (*endptr || l < 0 || l > 65535) + exit_error(ctx, "invalid peer port `%s'", charptr+1); + if (arg[0] == '[') { peer->address.in6.sin6_family = AF_INET6; if (inet_pton(AF_INET6, addrstr, &peer->address.in6.sin6_addr) != 1) diff --git a/src/config.y b/src/config.y index fd60d0d..d4b9af6 100644 --- a/src/config.y +++ b/src/config.y @@ -96,7 +96,6 @@ %type <num> port %type <num> maybe_port -%type <num> maybe_port_default %type <str> maybe_as %% @@ -188,15 +187,15 @@ peer_statement: TOK_ADDRESS peer_address ';' | TOK_INCLUDE peer_include ';' ; -peer_address: TOK_ADDR maybe_port_default { +peer_address: TOK_ADDR ':' port { conf->peers->address.in.sin_family = AF_INET; conf->peers->address.in.sin_addr = $1; - conf->peers->address.in.sin_port = $2; + conf->peers->address.in.sin_port = $3; } - | TOK_ADDR6 maybe_port_default { + | TOK_ADDR6 ':' port { conf->peers->address.in6.sin6_family = AF_INET6; conf->peers->address.in6.sin6_addr = $1; - conf->peers->address.in6.sin6_port = $2; + conf->peers->address.in6.sin6_port = $3; } ; @@ -230,10 +229,6 @@ maybe_port: ':' port { $$ = $2; } | { $$ = 0; } ; -maybe_port_default: ':' port { $$ = $2; } - | { $$ = htons(1337); } - ; - maybe_as: TOK_AS TOK_STRING { $$ = $2; } | { $$ = NULL; } ; @@ -143,7 +143,7 @@ fastd_peer* fastd_peer_add_temp(fastd_context *ctx, const fastd_peer_address *ad peer->state = STATE_TEMP; peer->seen = ctx->now; - pr_debug(ctx, "adding peer %P", peer); + pr_debug(ctx, "added peer %P", peer); return peer; } |