summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-03-31 18:04:02 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-03-31 18:04:02 +0200
commit0c82651c30bf543903ca05df4e5b179201353ee1 (patch)
tree8c7d7eb1e2f41b500433b14213dc1532d4a79b0f /src
parent342d63a45a8918e45ddcf6a0b82b2f593f4bde12 (diff)
downloadfastd-0c82651c30bf543903ca05df4e5b179201353ee1.tar
fastd-0c82651c30bf543903ca05df4e5b179201353ee1.zip
Change how handshakes are triggered
Diffstat (limited to 'src')
-rw-r--r--src/config.c2
-rw-r--r--src/fastd.c3
-rw-r--r--src/fastd.h2
-rw-r--r--src/peer.c18
-rw-r--r--src/peer.h15
-rw-r--r--src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c2
-rw-r--r--src/task.c19
-rw-r--r--src/task.h1
8 files changed, 41 insertions, 21 deletions
diff --git a/src/config.c b/src/config.c
index 1eda277..61cd42f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -65,7 +65,7 @@ static void default_config(fastd_config *conf) {
conf->protocol = &fastd_protocol_null;
conf->secret = NULL;
- conf->rekey = 3600;
+ conf->key_valid = 3600;
conf->peers = NULL;
diff --git a/src/fastd.c b/src/fastd.c
index 535c772..a651946 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -213,8 +213,7 @@ static void handle_tasks(fastd_context *ctx) {
pr_debug(ctx, "Sending handshake to %P...", task->peer);
ctx->conf->protocol->handshake_init(ctx, task->peer);
- if (task->peer->state == STATE_WAIT)
- fastd_task_schedule_handshake(ctx, task->peer, 20000);
+ fastd_task_schedule_handshake(ctx, task->peer, 20000);
break;
default:
diff --git a/src/fastd.h b/src/fastd.h
index cceaaf3..dc425ba 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -92,7 +92,7 @@ struct _fastd_config {
fastd_protocol *protocol;
char *secret;
- unsigned rekey;
+ unsigned key_valid;
fastd_peer_config *peers;
diff --git a/src/peer.c b/src/peer.c
index ff72c8e..653a62f 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -192,6 +192,24 @@ const fastd_eth_addr* fastd_get_dest_address(const fastd_context *ctx, fastd_buf
}
}
+void fastd_peer_set_established(fastd_context *ctx, fastd_peer *peer) {
+ fastd_task_delete_peer_handshakes(ctx, peer);
+
+ switch(peer->state) {
+ case STATE_WAIT:
+ pr_info(ctx, "Connection with %P established.", peer);
+ peer->state = STATE_ESTABLISHED;
+ break;
+
+ case STATE_TEMP:
+ exit_bug(ctx, "tried to set a temporary connection to established");
+
+ default:
+ return;
+ }
+}
+
+
static inline int fastd_eth_addr_cmp(const fastd_eth_addr *addr1, const fastd_eth_addr *addr2) {
return memcmp(addr1->data, addr2->data, ETH_ALEN);
}
diff --git a/src/peer.h b/src/peer.h
index b100739..9df018e 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -96,20 +96,7 @@ static inline bool fastd_peer_is_established(const fastd_peer *peer) {
return (peer->state == STATE_ESTABLISHED);
}
-static inline void fastd_peer_set_established(fastd_context *ctx, fastd_peer *peer) {
- switch(peer->state) {
- case STATE_WAIT:
- pr_info(ctx, "Connection with %P established.", peer);
- peer->state = STATE_ESTABLISHED;
- break;
-
- case STATE_TEMP:
- exit_bug(ctx, "tried to set a temporary connection to established");
-
- default:
- return;
- }
-}
+void fastd_peer_set_established(fastd_context *ctx, fastd_peer *peer);
static inline void fastd_peer_seen(fastd_context *ctx, fastd_peer *peer) {
peer->seen = ctx->now;
diff --git a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
index df551fb..11edfa2 100644
--- a/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
+++ b/src/protocol_ec25519_fhmqvc_xsalsa20_poly1305.c
@@ -352,7 +352,7 @@ static void establish(fastd_context *ctx, fastd_peer *peer, const fastd_peer_con
crypto_hash_sha256(peer->protocol_state->session.key, hashinput, 5*PUBLICKEYBYTES);
peer->protocol_state->session.valid_till = ctx->now;
- peer->protocol_state->session.valid_till.tv_sec += ctx->conf->rekey;
+ peer->protocol_state->session.valid_till.tv_sec += ctx->conf->key_valid;
peer->protocol_state->session.send_nonce[0] = initiator ? 3 : 2;
peer->protocol_state->session.receive_nonce[0] = initiator ? 0 : 1;
diff --git a/src/task.c b/src/task.c
index 62afd4f..b4004ef 100644
--- a/src/task.c
+++ b/src/task.c
@@ -69,13 +69,22 @@ void fastd_task_schedule_handshake(fastd_context *ctx, fastd_peer *peer, int tim
fastd_queue_put(ctx, &ctx->task_queue, &task->entry, timeout);
}
+typedef struct _delete_task_extra {
+ fastd_peer *peer;
+ bool handshake_only;
+} delete_task_extra;
+
static bool delete_task(fastd_queue_entry *data, void *extra) {
+ delete_task_extra *e = extra;
fastd_task *task = container_of(data, fastd_task, entry);
- fastd_peer *peer = extra;
+ fastd_peer *peer = e->peer;
if (task->peer != peer)
return true;
+ if (e->handshake_only && task->type != TASK_HANDSHAKE)
+ return true;
+
switch (task->type) {
case TASK_SEND:
fastd_buffer_free(task->send.buffer);
@@ -95,5 +104,11 @@ static bool delete_task(fastd_queue_entry *data, void *extra) {
}
void fastd_task_delete_peer(fastd_context *ctx, fastd_peer *peer) {
- fastd_queue_filter(ctx, &ctx->task_queue, delete_task, peer);
+ delete_task_extra extra = {peer, false};
+ fastd_queue_filter(ctx, &ctx->task_queue, delete_task, &extra);
+}
+
+void fastd_task_delete_peer_handshakes(fastd_context *ctx, fastd_peer *peer) {
+ delete_task_extra extra = {peer, true};
+ fastd_queue_filter(ctx, &ctx->task_queue, delete_task, &extra);
}
diff --git a/src/task.h b/src/task.h
index 23400d3..f5634d9 100644
--- a/src/task.h
+++ b/src/task.h
@@ -79,5 +79,6 @@ void fastd_task_put_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buff
void fastd_task_schedule_handshake(fastd_context *ctx, fastd_peer *peer, int timeout);
void fastd_task_delete_peer(fastd_context *ctx, fastd_peer *peer);
+void fastd_task_delete_peer_handshakes(fastd_context *ctx, fastd_peer *peer);
#endif /* _FASTD_TASK_H_ */