Skip to content

Commit aa6ab82

Browse files
author
Hang SU
committed
console: check parameter mutual exclusivity
- Introduce `InvalidCmdlineOption` error type to handle conflicting parameters - Implement backend-specific parameter checks: * Nested backend: - Require single socket (socket_count=1) - Disallow TCP port/UDS path * Network backend: Disallow UDS path * UDS backend: Disallow TCP port - Remove default TCP port value to enforce explicit configuration Signed-off-by: Hang SU <[email protected]>
1 parent d910fe6 commit aa6ab82

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

vhost-device-console/src/backend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub enum Error {
4242
ThreadPanic(String, Box<dyn Any + Send>),
4343
#[error("Error using multiple sockets with Nested backend")]
4444
WrongBackendSocket,
45+
#[error("Invalid cmdline option")]
46+
InvalidCmdlineOption,
4547
#[error("Invalid uds file")]
4648
InvalidUdsFile,
4749
}

vhost-device-console/src/main.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct ConsoleArgs {
7070
/// Initial tcp port to be used with `network` backend. If socket_count is
7171
/// `N` then the following tcp ports will be created: `tcp_port`,
7272
/// `tcp_port + 1`, ... , `tcp_port + (N - 1)`.
73-
#[clap(short = 'p', long, value_name = "PORT", default_value = "12345")]
73+
#[clap(short = 'p', long, value_name = "PORT")]
7474
tcp_port: String,
7575

7676
/// Specify the maximum size of virtqueue, the default is 128.
@@ -86,8 +86,22 @@ impl TryFrom<ConsoleArgs> for VuConsoleConfig {
8686
return Err(Error::SocketCountInvalid(0));
8787
}
8888

89-
if (args.backend == BackendType::Nested) && (args.socket_count != 1) {
90-
return Err(Error::WrongBackendSocket);
89+
if args.backend == BackendType::Nested {
90+
if args.socket_count != 1 {
91+
return Err(Error::WrongBackendSocket);
92+
}
93+
94+
if (!args.tcp_port.is_empty()) || (args.uds_path.is_some()) {
95+
return Err(Error::InvalidCmdlineOption);
96+
}
97+
}
98+
99+
if args.backend == BackendType::Network && args.uds_path.is_some() {
100+
return Err(Error::InvalidCmdlineOption);
101+
}
102+
103+
if args.backend == BackendType::Uds && !args.tcp_port.is_empty() {
104+
return Err(Error::InvalidCmdlineOption);
91105
}
92106

93107
let ConsoleArgs {

0 commit comments

Comments
 (0)