pub struct SharedState {
pub tx_ring: ArrayQueue<Vec<u8>>,
pub rx_ring: ArrayQueue<Vec<u8>>,
pub rx_wake: WakePipe,
pub tx_wake: WakePipe,
pub proxy_wake: WakePipe,
/* private fields */
}Expand description
All shared state between the three threads:
- NetWorker (libkrun) — pushes guest frames to
tx_ring, pops response frames fromrx_ring. - smoltcp poll thread — pops from
tx_ring, processes through smoltcp, pushes responses torx_ring. - tokio proxy tasks — relay data between smoltcp sockets and real network connections.
Queue naming follows the guest’s perspective (matching libkrun’s
convention): tx_ring = “transmit from guest”, rx_ring = “receive at
guest”.
Fields§
§tx_ring: ArrayQueue<Vec<u8>>Frames from guest → smoltcp (NetWorker writes, smoltcp reads).
rx_ring: ArrayQueue<Vec<u8>>Frames from smoltcp → guest (smoltcp writes, NetWorker reads).
rx_wake: WakePipeWakes NetWorker: “rx_ring has frames for the guest.”
Written by SmoltcpDevice::transmit(). Read end polled by NetWorker’s
epoll loop.
tx_wake: WakePipeWakes smoltcp poll thread: “tx_ring has frames from the guest.”
Written by SmoltcpBackend::write_frame(). Read end polled by the
poll loop.
proxy_wake: WakePipeWakes smoltcp poll thread: “proxy task has data to write to a smoltcp socket.” Written by proxy tasks via channels. Read end polled by the poll loop.
Implementations§
Sourcepub fn set_gateway_ips(&self, ipv4: Option<Ipv4Addr>, ipv6: Option<Ipv6Addr>)
pub fn set_gateway_ips(&self, ipv4: Option<Ipv4Addr>, ipv6: Option<Ipv6Addr>)
Set the per-sandbox gateway IPs. Called once at boot. Each family is only published when active for this sandbox.
Sourcepub fn gateway_ipv4(&self) -> Option<Ipv4Addr>
pub fn gateway_ipv4(&self) -> Option<Ipv4Addr>
Gateway IPv4 address, if set.
Sourcepub fn gateway_ipv6(&self) -> Option<Ipv6Addr>
pub fn gateway_ipv6(&self) -> Option<Ipv6Addr>
Gateway IPv6 address, if set.
Sourcepub fn set_termination_hook(&self, hook: Arc<dyn Fn() + Send + Sync>)
pub fn set_termination_hook(&self, hook: Arc<dyn Fn() + Send + Sync>)
Install a host-side termination hook.
Sourcepub fn trigger_termination(&self)
pub fn trigger_termination(&self)
Trigger host-side termination if a hook is installed.
Sourcepub fn cache_resolved_hostname(
&self,
domain: &str,
family: ResolvedHostnameFamily,
addrs: impl IntoIterator<Item = IpAddr>,
ttl: Duration,
)
pub fn cache_resolved_hostname( &self, domain: &str, family: ResolvedHostnameFamily, addrs: impl IntoIterator<Item = IpAddr>, ttl: Duration, )
Replace the resolved addresses for a hostname within the given address family.
Sourcepub fn clear_resolved_hostname(
&self,
domain: &str,
family: ResolvedHostnameFamily,
)
pub fn clear_resolved_hostname( &self, domain: &str, family: ResolvedHostnameFamily, )
Clear the resolved addresses for a hostname within the given address family.
Sourcepub fn any_resolved_hostname(
&self,
addr: IpAddr,
predicate: impl FnMut(&str) -> bool,
) -> bool
pub fn any_resolved_hostname( &self, addr: IpAddr, predicate: impl FnMut(&str) -> bool, ) -> bool
Returns true when any resolved hostname for addr satisfies predicate.
Sourcepub fn cleanup_resolved_hostnames(&self)
pub fn cleanup_resolved_hostnames(&self)
Best-effort expiry maintenance for resolved hostnames.
This runs outside the hot egress read path. If the index is currently busy, cleanup is skipped and retried on the next maintenance pass.
Sourcepub fn add_tx_bytes(&self, bytes: usize)
pub fn add_tx_bytes(&self, bytes: usize)
Increment the guest -> runtime byte counter.
Sourcepub fn add_rx_bytes(&self, bytes: usize)
pub fn add_rx_bytes(&self, bytes: usize)
Increment the runtime -> guest byte counter.