1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: MIT
use crate::{
packet_route::link::{InfoData, InfoDsa, InfoKind},
LinkMessageBuilder,
};
/// Represent DSA interface.
/// Example code on creating a DSA interface
/// ```no_run
/// use rtnetlink::{new_connection, LinkDsa};
/// #[tokio::main]
/// async fn main() -> Result<(), String> {
/// let (connection, handle, _) = new_connection().unwrap();
/// tokio::spawn(connection);
///
/// handle
/// .link()
/// .add(
/// LinkDsa::new("swp0")
/// .conduit(3)
/// .build(),
/// )
/// .execute()
/// .await
/// .map_err(|e| format!("{e}"))
/// }
/// ```
///
/// Please check LinkMessageBuilder::<LinkDsa> for more detail.
#[derive(Default, Debug)]
pub struct LinkDsa;
impl LinkDsa {
/// Equal to `LinkMessageBuilder::<LinkDsa>::new()`
pub fn new(name: &str) -> LinkMessageBuilder<Self> {
LinkMessageBuilder::<LinkDsa>::new(name)
}
}
impl LinkMessageBuilder<LinkDsa> {
/// Create [LinkMessageBuilder] for DSA interface type
pub fn new(name: &str) -> Self {
LinkMessageBuilder::<LinkDsa>::new_with_info_kind(InfoKind::Dsa)
.name(name.to_string())
}
fn append_info_data(self, info: InfoDsa) -> Self {
let mut ret = self;
if let InfoData::Dsa(infos) = ret
.info_data
.get_or_insert_with(|| InfoData::Dsa(Vec::new()))
{
infos.push(info);
}
ret
}
/// This is equivalent to `conduit IFINDEX` in command
/// `ip link set dev DEV type dsa conduit DEVICE`.
pub fn conduit(self, ifindex: u32) -> Self {
self.append_info_data(InfoDsa::Conduit(ifindex))
}
}