From 46e337a1fd34a3c0555f286b6bc46b9ba058c17c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 20 May 2013 10:41:20 +0200 Subject: Optimize send_all() to allow zero-copy TUN mode --- src/fastd.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/fastd.c') diff --git a/src/fastd.c b/src/fastd.c index bbf1e03..63c5750 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -611,6 +611,12 @@ static inline void send_all(fastd_context_t *ctx, fastd_peer_t *source_peer, fas if (dest_peer == source_peer || !fastd_peer_is_established(dest_peer)) continue; + /* optimization, primarily for TUN mode: don't duplicate the buffer for the last (or only) peer */ + if (!dest_peer->next) { + ctx->conf->protocol->send(ctx, dest_peer, buffer); + return; + } + ctx->conf->protocol->send(ctx, dest_peer, fastd_buffer_dup(ctx, buffer, methods_min_encrypt_head_space(ctx), methods_min_encrypt_tail_space(ctx))); } -- cgit v1.2.3