Skip to content

Commit bbfb0f3

Browse files
committed
Fix done message parse
Though the document of kernel (https://kernel.org/doc/html/next/userspace-api/netlink/intro.html#netlink-message-types) specify the format of netlink message with NLMSG_DONE, it also says that "Note that some implementations may issue custom NLMSG_DONE messages in reply to do action requests. In that case the payload is implementation-specific and may also be absent.". when use NLMSG_DONE as an end of multi messages, there will always be a NLM_F_MULTIPART in the flag and only in this case should we parse it as a DoneMessage, in other occassion like connector netlink (https://elixir.bootlin.com/linux/v6.15/source/drivers/connector/connector.c#L101), we should parse it as a common message. Signed-off-by: feng zhao <[email protected]>
1 parent b40f3d6 commit bbfb0f3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/message.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
payload::{NLMSG_DONE, NLMSG_ERROR, NLMSG_NOOP, NLMSG_OVERRUN},
88
DecodeError, DoneBuffer, DoneMessage, Emitable, ErrorBuffer, ErrorContext,
99
ErrorMessage, NetlinkBuffer, NetlinkDeserializable, NetlinkHeader,
10-
NetlinkPayload, NetlinkSerializable, Parseable,
10+
NetlinkPayload, NetlinkSerializable, Parseable, NLM_F_MULTIPART,
1111
};
1212

1313
/// Represent a netlink message.
@@ -103,7 +103,8 @@ where
103103
Error(msg)
104104
}
105105
NLMSG_NOOP => Noop,
106-
NLMSG_DONE => {
106+
// message without NLM_F_MULTIPART shouldn't be parsed to DoneMessage
107+
NLMSG_DONE if header.flags & NLM_F_MULTIPART != 0 => {
107108
// Linux kernel allows zero sized of NLMSG_DONE
108109
let msg = if bytes.is_empty() {
109110
DoneBuffer::new_checked(&[0u8; DONE_HEADER_LEN])
@@ -214,7 +215,8 @@ mod tests {
214215

215216
#[test]
216217
fn test_done() {
217-
let header = NetlinkHeader::default();
218+
let mut header = NetlinkHeader::default();
219+
header.flags |= NLM_F_MULTIPART;
218220
let done_msg = DoneMessage {
219221
code: 0,
220222
extended_ack: vec![6, 7, 8, 9],

0 commit comments

Comments
 (0)