Add file descriptor support

This commit is contained in:
B. Blechschmidt 2023-04-10 23:24:53 +02:00
parent 9437308283
commit 500f6ef21f
5 changed files with 31 additions and 10 deletions

View file

@ -18,6 +18,11 @@ pub struct Proxy {
pub credentials: Option<Credentials>,
}
pub enum NetworkInterface {
Named(String),
Fd(std::os::fd::RawFd),
}
impl Proxy {
pub fn from_url(s: &str) -> Result<Proxy, Error> {
let e = format!("`{s}` is not a valid proxy URL");
@ -83,6 +88,7 @@ impl std::fmt::Display for ProxyType {
#[derive(Default)]
pub struct Options {
virtdns: Option<virtdns::VirtualDns>,
mtu: Option<usize>,
}
impl Options {
@ -94,6 +100,11 @@ impl Options {
self.virtdns = Some(virtdns::VirtualDns::new());
self
}
pub fn with_mtu(mut self, mtu: usize) -> Self {
self.mtu = Some(mtu);
self
}
}
#[derive(Default, Clone, Debug)]
@ -111,8 +122,12 @@ impl Credentials {
}
}
pub fn main_entry(tun: &str, proxy: &Proxy, options: Options) -> Result<(), Error> {
let mut ttp = TunToProxy::new(tun, options)?;
pub fn main_entry(
interface: &NetworkInterface,
proxy: &Proxy,
options: Options,
) -> Result<(), Error> {
let mut ttp = TunToProxy::new(interface, options)?;
match proxy.proxy_type {
ProxyType::Socks4 => {
ttp.add_connection_manager(SocksManager::new(