mirror of
https://github.com/aramperes/onetun.git
synced 2025-09-09 23:18:31 -04:00
Index ports with protocol in WG. Start writing UDP tunnel code with plans.
This commit is contained in:
parent
703f261344
commit
5cec6d4943
10 changed files with 156 additions and 91 deletions
|
@ -1,6 +1,8 @@
|
|||
pub mod tcp;
|
||||
|
||||
use crate::config::PortProtocol;
|
||||
use async_trait::async_trait;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[async_trait]
|
||||
pub trait VirtualInterfacePoll {
|
||||
|
@ -8,3 +10,13 @@ pub trait VirtualInterfacePoll {
|
|||
/// to the WireGuard tunnel and to the real client.
|
||||
async fn poll_loop(mut self) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
/// Virtual port.
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub struct VirtualPort(pub u16, pub PortProtocol);
|
||||
|
||||
impl Display for VirtualPort {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "[{}:{}]", self.0, self.1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::config::PortForwardConfig;
|
||||
use crate::config::{PortForwardConfig, PortProtocol};
|
||||
use crate::virtual_device::VirtualIpDevice;
|
||||
use crate::virtual_iface::VirtualInterfacePoll;
|
||||
use crate::virtual_iface::{VirtualInterfacePoll, VirtualPort};
|
||||
use crate::wg::WireGuardTunnel;
|
||||
use anyhow::Context;
|
||||
use async_trait::async_trait;
|
||||
|
@ -74,8 +74,9 @@ impl VirtualInterfacePoll for TcpVirtualInterface {
|
|||
|
||||
// Consumer for IP packets to send through the virtual interface
|
||||
// Initialize the interface
|
||||
let device = VirtualIpDevice::new(self.virtual_port, self.wg)
|
||||
.with_context(|| "Failed to initialize TCP VirtualIpDevice")?;
|
||||
let device =
|
||||
VirtualIpDevice::new(VirtualPort(self.virtual_port, PortProtocol::Tcp), self.wg)
|
||||
.with_context(|| "Failed to initialize TCP VirtualIpDevice")?;
|
||||
let mut virtual_interface = InterfaceBuilder::new(device)
|
||||
.ip_addrs([
|
||||
// Interface handles IP packets for the sender and recipient
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue