From 5f66dbf5d1c26851e0a47269abbc44fe3524e4e2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 23 Mar 2015 07:20:02 +0100 Subject: peer: create interface when the connection has been established and no interface exists yet Allows using dynamic interfaces with dynamic peers. --- src/peer.c | 19 +++++++++++++++++-- src/peer.h | 2 +- src/protocols/ec25519_fhmqvc/handshake.c | 6 +++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/peer.c b/src/peer.c index 9f6c228..8a95398 100644 --- a/src/peer.c +++ b/src/peer.c @@ -871,14 +871,29 @@ void fastd_peer_handle_handshake_queue(void) { } /** Marks a peer as established */ -void fastd_peer_set_established(fastd_peer_t *peer) { +bool fastd_peer_set_established(fastd_peer_t *peer) { if (fastd_peer_is_established(peer)) - return; + return true; + + if (!peer->iface) { + const char *ifname = peer->ifname; + + if (!ifname && fastd_config_single_iface()) + ifname = conf.ifname; + + peer->iface = fastd_iface_open(ifname, peer); + if (peer->iface) + on_up(peer, false); + else + return false; + } peer->state = STATE_ESTABLISHED; peer->established = ctx.now; on_establish(peer); pr_info("connection with %P established.", peer); + + return true; } /** Compares two MAC addresses */ diff --git a/src/peer.h b/src/peer.h index 1dcc43b..e77462c 100644 --- a/src/peer.h +++ b/src/peer.h @@ -169,7 +169,7 @@ bool fastd_peer_add(fastd_peer_t *peer); void fastd_peer_reset(fastd_peer_t *peer); void fastd_peer_delete(fastd_peer_t *peer); void fastd_peer_free(fastd_peer_t *peer); -void fastd_peer_set_established(fastd_peer_t *peer); +bool fastd_peer_set_established(fastd_peer_t *peer); bool fastd_peer_may_connect(fastd_peer_t *peer); void fastd_peer_handle_resolve(fastd_peer_t *peer, fastd_remote_t *remote, size_t n_addresses, const fastd_peer_address_t *addresses); bool fastd_peer_owns_address(const fastd_peer_t *peer, const fastd_peer_address_t *addr); diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c index 7dda0a1..bbe572d 100644 --- a/src/protocols/ec25519_fhmqvc/handshake.c +++ b/src/protocols/ec25519_fhmqvc/handshake.c @@ -156,9 +156,13 @@ static bool establish(fastd_peer_t *peer, const fastd_method_info_t *method, fas return false; } + if (!fastd_peer_set_established(peer)) { + fastd_peer_reset(peer); + return false; + } + peer->establish_handshake_timeout = ctx.now + MIN_HANDSHAKE_INTERVAL; fastd_peer_seen(peer); - fastd_peer_set_established(peer); pr_verbose("new session with %P established using method `%s'%s.", peer, method->name, salt ? "" : " (compat mode)"); -- cgit v1.2.3