Skip to content

Commit 9de99ce

Browse files
committed
New function to forward ACK/DONE/NOOP message to handler
Introducing these public functions to allow forwarding ACK/DONE/NOOP message to handler: * `Connection::set_forward_noop()` * `Connection::set_forward_done()` * `Connection::set_forward_ack()` By default, we still drop these messages, so rtnetlink/ethtool crates will not be impacted. If any protocol require the handle of ACK/DONE/NOOP in handler, please invoke these functions during connection setup( e.g. rtnetlink has function `new_connection()`). Signed-off-by: Gris Ge <[email protected]>
1 parent 95d6009 commit 9de99ce

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

src/connection.rs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ where
5050
Option<UnboundedSender<(NetlinkMessage<T>, SocketAddr)>>,
5151

5252
socket_closed: bool,
53+
54+
forward_noop: bool,
55+
forward_done: bool,
56+
forward_ack: bool,
5357
}
5458

5559
impl<T, S, C> Connection<T, S, C>
@@ -73,9 +77,27 @@ where
7377
requests_rx: Some(requests_rx),
7478
unsolicited_messages_tx: Some(unsolicited_messages_tx),
7579
socket_closed: false,
80+
forward_noop: false,
81+
forward_done: false,
82+
forward_ack: false,
7683
})
7784
}
7885

86+
/// Whether [NetlinkPayload::Noop] should forwared to handler
87+
pub fn set_forward_noop(&mut self, value: bool) {
88+
self.forward_noop = value;
89+
}
90+
91+
/// Whether [NetlinkPayload::Done] should forwared to handler
92+
pub fn set_forward_done(&mut self, value: bool) {
93+
self.forward_done = value;
94+
}
95+
96+
/// Whether [NetlinkPayload::Ack] should forwared to handler
97+
pub fn set_forward_ack(&mut self, value: bool) {
98+
self.forward_ack = value;
99+
}
100+
79101
pub fn socket_mut(&mut self) -> &mut S {
80102
self.socket.get_mut()
81103
}
@@ -218,7 +240,7 @@ where
218240
|| self
219241
.unsolicited_messages_tx
220242
.as_ref()
221-
.map_or(true, |x| x.is_closed())
243+
.is_none_or(|x| x.is_closed())
222244
{
223245
// The channel is closed so we can drop the sender.
224246
let _ = self.unsolicited_messages_tx.take();
@@ -242,6 +264,12 @@ where
242264
if done {
243265
use NetlinkPayload::*;
244266
match &message.payload {
267+
Noop => {
268+
if !self.forward_noop {
269+
trace!("Not forwarding Noop message to the handle");
270+
continue;
271+
}
272+
}
245273
// Since `self.protocol` set the `done` flag here,
246274
// we know it has already dropped the request and
247275
// its associated metadata, ie the UnboundedSender
@@ -250,12 +278,11 @@ where
250278
// dropping the last instance of that sender,
251279
// hence closing the channel and signaling the
252280
// handle that no more messages are expected.
253-
Noop | Done(_) => {
254-
trace!(
255-
"not forwarding Noop/Ack/Done message to \
256-
the handle"
257-
);
258-
continue;
281+
Done(_) => {
282+
if !self.forward_done {
283+
trace!("Not forwarding Done message to the handle");
284+
continue;
285+
}
259286
}
260287
// I'm not sure how we should handle overrun messages
261288
Overrun(_) => unimplemented!("overrun is not handled yet"),
@@ -264,11 +291,8 @@ where
264291
// because only the user knows how they want to
265292
// handle them.
266293
Error(err_msg) => {
267-
if err_msg.code.is_none() {
268-
trace!(
269-
"not forwarding Noop/Ack/Done message to \
270-
the handle"
271-
);
294+
if err_msg.code.is_none() && !self.forward_ack {
295+
trace!("Not forwarding Ack message to the handle");
272296
continue;
273297
}
274298
}
@@ -314,6 +338,9 @@ where
314338
requests_rx: Some(requests_rx),
315339
unsolicited_messages_tx: Some(unsolicited_messages_tx),
316340
socket_closed: false,
341+
forward_noop: false,
342+
forward_done: false,
343+
forward_ack: false,
317344
}
318345
}
319346
}

src/handle.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ where
3232
/// - **acknowledgements**: when an acknowledgement is received, the stream
3333
/// is closed
3434
/// - **end of dump messages**: similarly, upon receiving an "end of dump"
35-
/// message, the stream is
36-
/// closed
35+
/// message, the stream is closed
3736
pub fn request(
3837
&self,
3938
message: NetlinkMessage<T>,

0 commit comments

Comments
 (0)