From e930fc0f769adacd6674546c07c2d5221bed95cd Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 15 Jun 2012 04:13:49 +0200 Subject: Allow setting dynamic peers to flaoting --- src/config.l | 1 + src/config.y | 9 ++++++++- src/peer.c | 6 +++++- src/peer.h | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/config.l b/src/config.l index 4f7dd7f..c4b20ab 100644 --- a/src/config.l +++ b/src/config.l @@ -93,6 +93,7 @@ forward { UPDATE_LOCATION; return TOK_FORWARD; } yes { UPDATE_LOCATION; return TOK_YES; } no { UPDATE_LOCATION; return TOK_NO; } port { UPDATE_LOCATION; return TOK_PORT; } +float { UPDATE_LOCATION; return TOK_FLOAT; } [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 ec2aabe..07774d1 100644 --- a/src/config.y +++ b/src/config.y @@ -94,6 +94,7 @@ %token TOK_YES %token TOK_NO %token TOK_PORT +%token TOK_FLOAT %token TOK_ADDR %token TOK_ADDR6 @@ -117,6 +118,7 @@ %type maybe_port %type maybe_as %type maybe_af +%type maybe_float %% start: START_CONFIG config @@ -294,12 +296,13 @@ peer_remote: TOK_ADDR port { conf->peers->address.in6.sin6_addr = $1; conf->peers->address.in6.sin6_port = htons($2); } - | maybe_af TOK_STRING port { + | maybe_af TOK_STRING port maybe_float { free(conf->peers->hostname); conf->peers->hostname = strdup($2->str); conf->peers->address.sa.sa_family = $1; conf->peers->address.in.sin_port = htons($3); + conf->peers->dynamic_float = $4; } ; @@ -351,6 +354,10 @@ maybe_af: TOK_IPV4 { $$ = AF_INET; } | { $$ = AF_UNSPEC; } ; +maybe_float: TOK_FLOAT { $$ = true; } + | { $$ = false; } + ; + boolean: TOK_YES { $$ = true; } | TOK_NO { $$ = false; } ; diff --git a/src/peer.c b/src/peer.c index a2b6c1a..54db531 100644 --- a/src/peer.c +++ b/src/peer.c @@ -189,7 +189,7 @@ static inline void setup_peer(fastd_context *ctx, fastd_peer *peer) { if (!peer->protocol_state) ctx->conf->protocol->init_peer_state(ctx, peer); - if (!fastd_peer_is_floating(peer)) + if (!fastd_peer_is_floating(peer) || fastd_peer_is_dynamic(peer)) fastd_task_schedule_handshake(ctx, peer, 0); } @@ -215,6 +215,7 @@ fastd_peer_config* fastd_peer_config_new(fastd_context *ctx, fastd_config *conf) peer->hostname = NULL; memset(&peer->address, 0, sizeof(fastd_peer_address)); + peer->dynamic_float = false; peer->config_source_dir = NULL; @@ -310,6 +311,9 @@ bool fastd_peer_config_equal(const fastd_peer_config *peer1, const fastd_peer_co if (!strequal(peer1->hostname, peer2->hostname)) return false; + if(peer1->dynamic_float != peer2->dynamic_float) + return false; + if (!fastd_peer_address_equal(&peer1->address, &peer2->address)) return false; diff --git a/src/peer.h b/src/peer.h index 007eefd..b326ad1 100644 --- a/src/peer.h +++ b/src/peer.h @@ -62,6 +62,7 @@ struct _fastd_peer_config { char *hostname; fastd_peer_address address; + bool dynamic_float; char *key; fastd_protocol_peer_config *protocol_config; @@ -92,7 +93,7 @@ const fastd_eth_addr* fastd_get_source_address(const fastd_context *ctx, fastd_b const fastd_eth_addr* fastd_get_dest_address(const fastd_context *ctx, fastd_buffer buffer); static inline bool fastd_peer_config_is_floating(const fastd_peer_config *config) { - return (config->hostname == NULL && config->address.sa.sa_family == AF_UNSPEC); + return ((config->hostname == NULL && config->address.sa.sa_family == AF_UNSPEC) || config->dynamic_float); } static inline bool fastd_peer_config_is_dynamic(const fastd_peer_config *config) { -- cgit v1.2.3