From 6984d3709ef09da8d605d2c8f0a9da877c9cca35 Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 9 Apr 2013 11:47:32 +0100 Subject: [PATCH] flexnbd: Don't bind() unless a bind address is specified --- src/proxy.c | 8 +++++++- src/proxy.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/proxy.c b/src/proxy.c index 0c0ccc7..1afed87 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -53,6 +53,7 @@ struct proxier* proxy_create( "Couldn't parse bind address '%s'", s_upstream_bind ); + out->bind = 1; } out->listen_fd = -1; @@ -78,7 +79,12 @@ void proxy_destroy( struct proxier* proxy ) */ int proxy_connect_to_upstream( struct proxier* proxy ) { - int fd = socket_connect( &proxy->connect_to.generic, &proxy->connect_from.generic ); + struct sockaddr* connect_from = NULL; + if ( proxy->bind ) { + connect_from = &proxy->connect_from.generic; + } + + int fd = socket_connect( &proxy->connect_to.generic, connect_from ); off64_t size = 0; if ( -1 == fd ) { diff --git a/src/proxy.h b/src/proxy.h index bbe797c..1475e77 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -21,6 +21,7 @@ struct proxier { /** address to bind to when making outgoing connections */ union mysockaddr connect_from; + int bind; /* Set to true if we should use it */ /* The socket we listen() on and accept() against */ int listen_fd;