Skip to content

Commit

Permalink
New function to forward ACK/DONE/NOOP message to handler
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cathay4t committed Apr 9, 2024
1 parent 8b90890 commit 644b2fc
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ where
Option<UnboundedSender<(NetlinkMessage<T>, SocketAddr)>>,

socket_closed: bool,

forward_noop: bool,
forward_done: bool,
forward_ack: bool,
}

impl<T, S, C> Connection<T, S, C>
Expand All @@ -73,9 +77,27 @@ where
requests_rx: Some(requests_rx),
unsolicited_messages_tx: Some(unsolicited_messages_tx),
socket_closed: false,
forward_noop: false,
forward_done: false,
forward_ack: false,
})
}

/// Whether [NetlinkPayload::Noop] should forwared to handler
pub fn set_forward_noop(&mut self, value: bool) {
self.forward_noop = value;
}

/// Whether [NetlinkPayload::Done] should forwared to handler
pub fn set_forward_done(&mut self, value: bool) {
self.forward_done = value;
}

/// Whether [NetlinkPayload::Ack] should forwared to handler
pub fn set_forward_ack(&mut self, value: bool) {
self.forward_ack = value;
}

pub fn socket_mut(&mut self) -> &mut S {
self.socket.get_mut()
}
Expand Down Expand Up @@ -242,6 +264,12 @@ where
if done {
use NetlinkPayload::*;
match &message.payload {
Noop => {
if !self.forward_noop {
trace!("Not forwarding Noop message to the handle");
continue;
}
}
// Since `self.protocol` set the `done` flag here,
// we know it has already dropped the request and
// its associated metadata, ie the UnboundedSender
Expand All @@ -250,12 +278,11 @@ where
// dropping the last instance of that sender,
// hence closing the channel and signaling the
// handle that no more messages are expected.
Noop | Done(_) => {
trace!(
"not forwarding Noop/Ack/Done message to \
the handle"
);
continue;
Done(_) => {
if !self.forward_done {
trace!("Not forwarding Done message to the handle");
continue;
}
}
// I'm not sure how we should handle overrun messages
Overrun(_) => unimplemented!("overrun is not handled yet"),
Expand All @@ -264,11 +291,8 @@ where
// because only the user knows how they want to
// handle them.
Error(err_msg) => {
if err_msg.code.is_none() {
trace!(
"not forwarding Noop/Ack/Done message to \
the handle"
);
if err_msg.code.is_none() && !self.forward_ack {
trace!("Not forwarding Ack message to the handle");
continue;
}
}
Expand Down

0 comments on commit 644b2fc

Please sign in to comment.