pub struct PortPublisher { /* private fields */ }Expand description
Manages published port listeners and inbound connections.
Spawns tokio listeners for each published port. When connections arrive, they are queued for the poll loop to create smoltcp sockets and initiate connections to the guest.
Implementations§
Source§impl PortPublisher
impl PortPublisher
Sourcepub fn new(
ports: &[PublishedPort],
guest_ipv4: Option<Ipv4Addr>,
guest_ipv6: Option<Ipv6Addr>,
gateway_ipv4: Option<Ipv4Addr>,
gateway_ipv6: Option<Ipv6Addr>,
gateway_mac: [u8; 6],
guest_mac: [u8; 6],
policy: Arc<NetworkPolicy>,
shared: Arc<SharedState>,
tokio_handle: &Handle,
) -> Self
pub fn new( ports: &[PublishedPort], guest_ipv4: Option<Ipv4Addr>, guest_ipv6: Option<Ipv6Addr>, gateway_ipv4: Option<Ipv4Addr>, gateway_ipv6: Option<Ipv6Addr>, gateway_mac: [u8; 6], guest_mac: [u8; 6], policy: Arc<NetworkPolicy>, shared: Arc<SharedState>, tokio_handle: &Handle, ) -> Self
Create a new publisher and spawn listeners for all published ports.
Listeners are only spawned when at least one of guest_ipv4 /
guest_ipv6 is Some; published ports need a smoltcp dial target.
Each TCP listener task gates accepted connections through the
supplied NetworkPolicy’s evaluate_ingress before queuing
them; rejected connections drop with TCP RST (zero-linger) so
the peer observes ECONNRESET.
Sourcepub fn accept_inbound(
&mut self,
iface: &mut Interface,
sockets: &mut SocketSet<'_>,
shared: &Arc<SharedState>,
tokio_handle: &Handle,
)
pub fn accept_inbound( &mut self, iface: &mut Interface, sockets: &mut SocketSet<'_>, shared: &Arc<SharedState>, tokio_handle: &Handle, )
Accept queued inbound connections: create smoltcp sockets and initiate connections to the guest.
Must be called each poll iteration.
Sourcepub fn relay_data(&mut self, sockets: &mut SocketSet<'_>)
pub fn relay_data(&mut self, sockets: &mut SocketSet<'_>)
Relay data between smoltcp sockets and host relay tasks.
Sourcepub fn relay_udp_outbound(
&self,
frame: &[u8],
src: SocketAddr,
dst: SocketAddr,
) -> bool
pub fn relay_udp_outbound( &self, frame: &[u8], src: SocketAddr, dst: SocketAddr, ) -> bool
Relay a guest UDP datagram to a host peer that recently sent traffic to a UDP published port.
Returns true when the frame belongs to a published-port flow and
should be consumed by the caller.
Sourcepub fn cleanup_closed(&mut self, sockets: &mut SocketSet<'_>)
pub fn cleanup_closed(&mut self, sockets: &mut SocketSet<'_>)
Remove closed inbound connections.
Only removes sockets in Closed state. Sockets in TimeWait are
left for smoltcp’s 2*MSL timer to handle naturally.