Basic vsock proxying implementation
Currently just connecting to the host's session bus
This commit is contained in:
parent
11a682e19f
commit
14ce212e81
12 changed files with 1807 additions and 34 deletions
46
sidebus-agent/src/main.rs
Normal file
46
sidebus-agent/src/main.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use clap::Parser;
|
||||
use tokio::net::UnixListener;
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct AgentCli {
|
||||
listen_path: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let cli = AgentCli::parse();
|
||||
|
||||
let unix_addr = cli.listen_path;
|
||||
let unix_listener = UnixListener::bind(unix_addr.clone())?;
|
||||
info!(%unix_addr, "listening for unix clients");
|
||||
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(
|
||||
zbus::address::transport::Vsock::new(2, 4269),
|
||||
));
|
||||
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(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue