Skip to content

Commit 8ac7c2a

Browse files
ffmanceracathay4t
authored andcommitted
attribute: fix decoding error on empty IFLA_VFINFO_LIST payload
Using netdevsim driver, it sends empty IFLA_VFINFO_LIST if not configured. When this happens, the payload length is 0. As we are using new_checked() function for NlaBuffer creation, we check that the payload size can allocate the NLA size for that type. The kernel shouldn't send an empty IFLA_VFINFO_LIST on netdevsim driver when not configured but until that is fixed, this is a proper solution. It fixes the following error: ``` thread 'main' panicked at links_dump.rs:62:52: called `Result::unwrap()` on an `Err` value: DecodeError { inner: Failed to parse message with type 16 Caused by: Decode error occurred: invalid link message } ``` Signed-off-by: Fernando Fernandez Mancera <[email protected]>
1 parent 201d99b commit 8ac7c2a

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/link/attribute.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,20 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
376376
IFLA_VFINFO_LIST => {
377377
let err =
378378
|payload| format!("invalid IFLA_VFINFO_LIST {payload:?}");
379-
Self::VfInfoList(
380-
VecLinkVfInfo::parse(
381-
&NlaBuffer::new_checked(payload)
382-
.context(err(payload))?,
379+
if !payload.is_empty() {
380+
Self::VfInfoList(
381+
VecLinkVfInfo::parse(
382+
&NlaBuffer::new_checked(payload)
383+
.context(err(payload))?,
384+
)
385+
.context(err(payload))?
386+
.0,
383387
)
384-
.context(err(payload))?
385-
.0,
386-
)
388+
} else {
389+
// Empty IFLA_VFINFO_LIST, this is likely a netdevsim device
390+
// no need to parse it, it is empty
391+
Self::VfInfoList(vec![])
392+
}
387393
}
388394
IFLA_VF_PORTS => {
389395
let err =

src/link/tests/sriov.rs

+17
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,20 @@ fn test_parsing_link_sriov() {
183183

184184
assert_eq!(buf, raw);
185185
}
186+
187+
// tcpdump capture of nlmon on a netdevsim device without VF info configure.
188+
// Only IFLA_VFINFO_LIST was included.
189+
#[test]
190+
fn test_parsing_empty_link_sriov_vf_info() {
191+
let raw = vec![0x04, 0x00, 0x16, 0x00];
192+
let expected = LinkAttribute::VfInfoList(vec![]);
193+
194+
assert_eq!(
195+
expected,
196+
LinkAttribute::parse_with_param(
197+
&NlaBuffer::new_checked(&raw).unwrap(),
198+
AddressFamily::Unspec
199+
)
200+
.unwrap(),
201+
);
202+
}

0 commit comments

Comments
 (0)