diff --git a/leaf/src/app/outbound/manager.rs b/leaf/src/app/outbound/manager.rs index 96485832d..e1427ffb3 100644 --- a/leaf/src/app/outbound/manager.rs +++ b/leaf/src/app/outbound/manager.rs @@ -151,13 +151,15 @@ impl OutboundManager { .map_err(|e| anyhow!("invalid [{}] outbound settings: {}", &tag, e))?; let stream = Box::new(socks::outbound::StreamHandler { address: settings.address.clone(), - port: settings.port as u16, + port: settings.port.clone() as u16, username: settings.username.clone(), password: settings.password.clone(), }); let datagram = Box::new(socks::outbound::DatagramHandler { address: settings.address.clone(), port: settings.port as u16, + username: settings.username.clone(), + password: settings.password.clone(), dns_client: dns_client.clone(), }); HandlerBuilder::default() diff --git a/leaf/src/proxy/socks/outbound/datagram.rs b/leaf/src/proxy/socks/outbound/datagram.rs index 9345e695d..7ceb63659 100644 --- a/leaf/src/proxy/socks/outbound/datagram.rs +++ b/leaf/src/proxy/socks/outbound/datagram.rs @@ -13,6 +13,8 @@ use crate::{app::SyncDnsClient, proxy::*, session::*}; pub struct Handler { pub address: String, pub port: u16, + pub username: String, + pub password: String, pub dns_client: SyncDnsClient, } @@ -39,7 +41,14 @@ impl OutboundDatagramHandler for Handler { .new_tcp_stream(self.dns_client.clone(), &self.address, &self.port) .await?; let socket = self.new_udp_socket(&sess.source).await?; - let socket = SocksDatagram::associate(stream, socket, None::, None::) + let auth = match (&self.username, &self.password) { + (auth_username, _) if auth_username.is_empty() => None, + (auth_username, auth_password) => Some(Auth { + username: auth_username.to_owned(), + password: auth_password.to_owned(), + }), + }; + let socket = SocksDatagram::associate(stream, socket, auth, None::) .map_err(|x| Error::new(ErrorKind::Other, x)) .await?; Ok(Box::new(Datagram { socket }))