diff --git a/Cargo.lock b/Cargo.lock index 8ead6c2..6e39e35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -929,6 +929,15 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + [[package]] name = "memoffset" version = "0.9.1" @@ -985,6 +994,7 @@ dependencies = [ "bitflags 1.3.2", "cfg-if", "libc", + "memoffset 0.7.1", ] [[package]] @@ -996,7 +1006,7 @@ dependencies = [ "bitflags 2.5.0", "cfg-if", "libc", - "memoffset", + "memoffset 0.9.1", ] [[package]] @@ -1708,8 +1718,6 @@ dependencies = [ [[package]] name = "tokio-listener" version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914a439d123292125bc806649c396d23e1aac5da4052f0d97b23137b38782f46" dependencies = [ "document-features", "futures-core", @@ -1719,6 +1727,7 @@ dependencies = [ "socket2", "tokio", "tokio-util", + "tokio-vsock", "tonic", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index af733dd..a896753 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ serde = { version = "1.0.202", features = ["derive"]} serde_json = "1.0.120" x509-parser = { version = "0.16" } -tokio-listener = {version = "0.4.3", features = ["multi-listener", "tonic012"]} +tokio-listener = {version = "0.4.3", features = ["multi-listener", "tonic012", "vsock"], path="/home/avn/work/unikie/tokio-listener"} # GIVC subparts givc-common = { path="common" } diff --git a/src/bin/givc-admin.rs b/src/bin/givc-admin.rs index 0b58bb3..7feb4cc 100644 --- a/src/bin/givc-admin.rs +++ b/src/bin/givc-admin.rs @@ -2,6 +2,7 @@ use clap::Parser; use givc::admin; use givc::endpoint::TlsConfig; use givc_common::pb::reflection::ADMIN_DESCRIPTOR; +use givc::utils::vsock::parse_vsock_addr; use std::net::SocketAddr; use std::path::PathBuf; use tonic::transport::Server; @@ -16,9 +17,12 @@ struct Cli { #[arg(long, env = "PORT", default_missing_value = "9000", value_parser = clap::value_parser!(u16).range(1..))] port: u16, - #[arg(long, help = "Additionally listen UNIX socket")] + #[arg(long, help = "Additionally listen UNIX socket (path)")] unix: Option, + #[arg(long, help = "Additionally listen Vsock socket (cid:port format)")] + vsock: Option, + #[arg(long, env = "TLS", default_missing_value = "false")] use_tls: bool, @@ -84,6 +88,11 @@ async fn main() -> std::result::Result<(), Box> { addrs.push(unix_sock_addr) } + if let Some(vsock) = cli.vsock { + let vsock_addr = tokio_listener::ListenerAddress::Vsock(parse_vsock_addr(&vsock)?); + addrs.push(vsock_addr) + } + let listener = tokio_listener::Listener::bind_multiple(&addrs, &sys_opts, &user_opts).await?; builder diff --git a/src/bin/givc-cli.rs b/src/bin/givc-cli.rs index f9e41ac..6c7a985 100644 --- a/src/bin/givc-cli.rs +++ b/src/bin/givc-cli.rs @@ -2,6 +2,8 @@ use clap::{Parser, Subcommand}; use givc::endpoint::TlsConfig; use givc::types::*; use givc_client::AdminClient; +use givc_common::address::EndpointAddress; +use givc::utils::vsock::parse_vsock_addr; use serde::ser::Serialize; use std::path::PathBuf; use std::time; @@ -23,6 +25,9 @@ struct Cli { #[arg(long, env = "NAME", default_missing_value = "admin.ghaf")] name: String, // for TLS service name + #[arg(long)] + vsock: Option, + #[arg(long, env = "CA_CERT")] cacert: Option, @@ -128,7 +133,14 @@ async fn main() -> std::result::Result<(), Box> { }, )) }; - let admin = AdminClient::new(cli.addr, cli.port, tls); + + // FIXME; big kludge, but allow to test vsock connection + let admin = if let Some(vsock) = cli.vsock { + info!("Connection diverted to VSock"); + AdminClient::from_endpoint_address(EndpointAddress::Vsock(parse_vsock_addr(&vsock)?), tls) + } else { + AdminClient::new(cli.addr, cli.port, tls) + }; match cli.command { Commands::Test { test } => test_subcommands(test, admin).await?, diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 02918bc..26e9481 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,4 +1,5 @@ pub mod auth; pub mod naming; pub mod tonic; +pub mod vsock; pub mod x509;