qemu_command_builder/
incoming.rs1use crate::common::OnOff;
2use crate::to_command::{ToArg, ToCommand};
3use bon::Builder;
4use std::path::PathBuf;
5
6#[derive(Builder)]
7pub struct Tcp {
8 host: Option<String>,
9 port: u16,
10 to: Option<u16>,
11 ipv4: Option<OnOff>,
12 ipv6: Option<OnOff>,
13}
14
15#[derive(Builder)]
16pub struct Rdma {
17 host: String,
18 port: u16,
19 ipv4: Option<OnOff>,
20 ipv6: Option<OnOff>,
21}
22
23#[derive(Builder)]
24pub struct File {
25 filename: PathBuf,
26 offset: Option<String>,
27}
28
29pub enum Incoming {
30 Tcp(Tcp),
31 Rdma(Rdma),
32 Unix(PathBuf),
33 Fd(String),
34 File(File),
35 Exec(String),
36 Channel(String),
37 Defer,
38}
39
40impl ToCommand for Incoming {
41 fn to_command(&self) -> Vec<String> {
42 let mut cmd = vec![];
43
44 cmd.push("-incoming".to_string());
45
46 match self {
47 Incoming::Tcp(tcp) => {
48 let mut args = vec![];
49 if let Some(host) = &tcp.host {
50 args.push(format!("tcp:{}:{}", host, tcp.port));
51 } else {
52 args.push(format!("tcp::{}", tcp.port));
53 }
54 if let Some(to) = &tcp.to {
55 args.push(format!("to={}", to));
56 }
57 if let Some(ipv4) = &tcp.ipv4 {
58 args.push(format!("ipv4={}", ipv4.to_arg()));
59 }
60 if let Some(ipv6) = &tcp.ipv6 {
61 args.push(format!("ipv6={}", ipv6.to_arg()));
62 }
63 cmd.push(args.join(","));
64 }
65 Incoming::Rdma(rdma) => {
66 let mut args = vec![];
67 args.push(format!("rdma:{}:{}", rdma.host, rdma.port));
68 if let Some(ipv4) = &rdma.ipv4 {
69 args.push(format!("ipv4={}", ipv4.to_arg()));
70 }
71 if let Some(ipv6) = &rdma.ipv6 {
72 args.push(format!("ipv6={}", ipv6.to_arg()));
73 }
74 cmd.push(args.join(","));
75 }
76 Incoming::Unix(unix) => {
77 cmd.push(format!("unix:{}", unix.display()));
78 }
79 Incoming::Fd(fd) => {
80 cmd.push(format!("fd:{}", fd));
81 }
82 Incoming::File(file) => {
83 let mut args = vec![format!("file:{}", file.filename.display())];
84 if let Some(offset) = &file.offset {
85 args.push(format!("offset={}", offset));
86 }
87 cmd.push(args.join(","));
88 }
89 Incoming::Exec(exec) => {
90 cmd.push(format!("exec:{}", exec));
91 }
92 Incoming::Channel(chrono) => {
93 cmd.push(format!("channel:{}", chrono));
94 }
95 Incoming::Defer => {
96 cmd.push("defer".to_string());
97 }
98 }
99
100 cmd
101 }
102}