2025-07-17 23:16:39 -03:00
|
|
|
use eyre::OptionExt;
|
2025-07-04 21:52:14 -03:00
|
|
|
use tokio::net::UnixListener;
|
|
|
|
|
use tracing::info;
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() -> eyre::Result<()> {
|
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
2025-07-17 23:16:39 -03:00
|
|
|
let creds_dir = std::path::PathBuf::try_from(std::env::var("CREDENTIALS_DIRECTORY")?)?;
|
|
|
|
|
let vsock_port = std::fs::read_to_string(creds_dir.join("sidebus.port"))?
|
|
|
|
|
.trim()
|
|
|
|
|
.parse::<u32>()?;
|
|
|
|
|
|
|
|
|
|
let unix_listener = UnixListener::from_std(
|
|
|
|
|
listenfd::ListenFd::from_env()
|
|
|
|
|
.take_unix_listener(0)?
|
|
|
|
|
.ok_or_eyre("no unix listener provided")?,
|
|
|
|
|
)?;
|
|
|
|
|
info!("listening for unix clients");
|
2025-07-04 21:52:14 -03:00
|
|
|
|
|
|
|
|
while let Ok((unix_client, client_addr)) = unix_listener.accept().await {
|
|
|
|
|
info!(?client_addr, "new unix client");
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
let vsock_addr = zbus::Address::from(zbus::address::Transport::Vsock(
|
2025-07-17 23:16:39 -03:00
|
|
|
zbus::address::transport::Vsock::new(2, vsock_port),
|
2025-07-04 21:52:14 -03:00
|
|
|
));
|
|
|
|
|
let vsock_conn = zbus::connection::Builder::address(vsock_addr)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.p2p()
|
|
|
|
|
.auth_mechanism(zbus::AuthMechanism::Anonymous)
|
|
|
|
|
.build()
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
info!(guid = %vsock_conn.server_guid(), "connected to vsock bus");
|
|
|
|
|
let client_conn = zbus::connection::Builder::unix_stream(unix_client)
|
|
|
|
|
.server(vsock_conn.server_guid())
|
|
|
|
|
.unwrap()
|
|
|
|
|
.p2p()
|
|
|
|
|
.auth_mechanism(zbus::AuthMechanism::External)
|
|
|
|
|
.build()
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
sidebus_common::raw::splice_conns(client_conn, vsock_conn).await;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|