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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use futures::{
future::{self, Either},
stream::{StreamExt, TryStream},
FutureExt,
};
use crate::{
packet::{constants::*, nlas::link::Nla, LinkMessage, NetlinkMessage, RtnlMessage},
try_rtnl,
Error,
Handle,
};
pub struct LinkGetRequest {
handle: Handle,
message: LinkMessage,
dump: bool,
}
impl LinkGetRequest {
pub(crate) fn new(handle: Handle) -> Self {
LinkGetRequest {
handle,
message: LinkMessage::default(),
dump: true,
}
}
pub fn set_filter_mask(mut self, family: u8, filter_mask: u32) -> Self {
self.message.header.interface_family = family;
self.message.nlas.push(Nla::ExtMask(filter_mask));
self
}
pub fn execute(self) -> impl TryStream<Ok = LinkMessage, Error = Error> {
let LinkGetRequest {
mut handle,
message,
dump,
} = self;
let mut req = NetlinkMessage::from(RtnlMessage::GetLink(message));
if dump {
req.header.flags = NLM_F_REQUEST | NLM_F_DUMP;
} else {
req.header.flags = NLM_F_REQUEST;
}
match handle.request(req) {
Ok(response) => {
Either::Left(response.map(move |msg| Ok(try_rtnl!(msg, RtnlMessage::NewLink))))
}
Err(e) => Either::Right(future::err::<LinkMessage, Error>(e).into_stream()),
}
}
pub fn message_mut(&mut self) -> &mut LinkMessage {
&mut self.message
}
pub fn match_index(mut self, index: u32) -> Self {
self.dump = false;
self.message.header.index = index;
self
}
pub fn match_name(mut self, name: String) -> Self {
self.dump = false;
self.message.nlas.push(Nla::IfName(name));
self
}
}