diff --git a/src/main.rs b/src/main.rs index 9d7b81f..56f9e1c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,10 @@ enum Command { /// IP address for the control server. Bore clients must reach this address. #[clap(long, default_value = "0.0.0.0")] control_addr: String, + + /// IP address where tunnels will listen on. + #[clap(long, default_value = "0.0.0.0")] + tunnels_addr: String, }, } @@ -72,6 +76,7 @@ async fn run(command: Command) -> Result<()> { max_port, secret, control_addr, + tunnels_addr, } => { let port_range = min_port..=max_port; if port_range.is_empty() { @@ -79,7 +84,7 @@ async fn run(command: Command) -> Result<()> { .error(ErrorKind::InvalidValue, "port range is empty") .exit(); } - Server::new(port_range, secret.as_deref(), control_addr).listen().await?; + Server::new(port_range, secret.as_deref(), control_addr, tunnels_addr).listen().await?; } } diff --git a/src/server.rs b/src/server.rs index 6240323..1c46d8f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -26,17 +26,21 @@ pub struct Server { /// IP address for the control server. Bore clients must reach this address. control_addr: String, + + /// IP address where tunnels will listen on. + tunnels_addr: String, } impl Server { /// Create a new server with a specified minimum port number. - pub fn new(port_range: RangeInclusive, secret: Option<&str>, control_addr: String) -> Self { + pub fn new(port_range: RangeInclusive, secret: Option<&str>, control_addr: String, tunnels_addr: String) -> Self { assert!(!port_range.is_empty(), "must provide at least one port"); Server { port_range, conns: Arc::new(DashMap::new()), auth: secret.map(Authenticator::new), - control_addr: control_addr, + control_addr, + tunnels_addr, } } @@ -65,7 +69,7 @@ impl Server { async fn create_listener(&self, port: u16) -> Result { let try_bind = |port: u16| async move { - TcpListener::bind(("0.0.0.0", port)) + TcpListener::bind((self.tunnels_addr.as_ref(), port)) .await .map_err(|err| match err.kind() { io::ErrorKind::AddrInUse => "port already in use",