Add udp reverse tunneling
This commit is contained in:
parent
b352d5717d
commit
f48b156542
5 changed files with 70 additions and 20 deletions
31
src/main.rs
31
src/main.rs
|
@ -62,7 +62,8 @@ struct Client {
|
|||
/// Listen on remote and forwards traffic from local. Can be specified multiple times. Only tcp is supported
|
||||
/// examples:
|
||||
/// 'tcp://1212:google.com:443' => listen on server for incoming tcp cnx on port 1212 and forward to google.com on port 443 from local machine
|
||||
#[arg(short='R', long, value_name = "{tcp}://[BIND:]PORT:HOST:PORT", value_parser = parse_tunnel_arg, verbatim_doc_comment)]
|
||||
/// 'udp://1212:1.1.1.1:53' => listen on server for incoming udp on port 1212 and forward to cloudflare dns 1.1.1.1 on port 53 from local machine
|
||||
#[arg(short='R', long, value_name = "{tcp,udp}://[BIND:]PORT:HOST:PORT", value_parser = parse_tunnel_arg, verbatim_doc_comment)]
|
||||
remote_to_local: Vec<LocalToRemote>,
|
||||
|
||||
/// (linux only) Mark network packet with SO_MARK sockoption with the specified value.
|
||||
|
@ -172,6 +173,7 @@ enum LocalProtocol {
|
|||
Stdio,
|
||||
Socks5,
|
||||
ReverseTcp,
|
||||
ReverseUdp { timeout: Option<Duration> },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -551,7 +553,31 @@ async fn main() {
|
|||
LocalProtocol::Tcp => {
|
||||
tunnel.local_protocol = ReverseTcp;
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) = tunnel::client::run_reverse_tunnel(client_config, tunnel).await {
|
||||
let remote = tunnel.remote.clone();
|
||||
let cfg = client_config.clone();
|
||||
let connect_to_dest = || async {
|
||||
tcp::connect(&remote.0, remote.1, cfg.socket_so_mark, cfg.timeout_connect).await
|
||||
};
|
||||
|
||||
if let Err(err) =
|
||||
tunnel::client::run_reverse_tunnel(client_config, tunnel, connect_to_dest).await
|
||||
{
|
||||
error!("{:?}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
LocalProtocol::Udp { timeout } => {
|
||||
tunnel.local_protocol = LocalProtocol::ReverseUdp { timeout: *timeout };
|
||||
|
||||
tokio::spawn(async move {
|
||||
let cfg = client_config.clone();
|
||||
let remote = tunnel.remote.clone();
|
||||
let connect_to_dest =
|
||||
|| async { udp::connect(&remote.0, remote.1, cfg.timeout_connect).await };
|
||||
|
||||
if let Err(err) =
|
||||
tunnel::client::run_reverse_tunnel(client_config, tunnel, connect_to_dest).await
|
||||
{
|
||||
error!("{:?}", err);
|
||||
}
|
||||
});
|
||||
|
@ -628,6 +654,7 @@ async fn main() {
|
|||
}
|
||||
}
|
||||
LocalProtocol::ReverseTcp => {}
|
||||
LocalProtocol::ReverseUdp { .. } => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue