From bd781685508ae5096f864ba969824e299c7f327c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 1 Apr 2012 22:28:31 +0200 Subject: Require port with peer specfication, remove default port --- src/config.c | 27 +++++++++------------------ src/config.y | 13 ++++--------- src/peer.c | 2 +- 3 files changed, 14 insertions(+), 28 deletions(-) (limited to 'src') 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 port %type maybe_port -%type maybe_port_default %type 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; } ; diff --git a/src/peer.c b/src/peer.c index 9e3e501..a86a0d2 100644 --- a/src/peer.c +++ b/src/peer.c @@ -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; } -- cgit v1.2.3