Skip to content

Commit

Permalink
Fix bug with deserializing FqCodelXStats
Browse files Browse the repository at this point in the history
`deserialize` was called on entire `bytes` array when it was supposed to be offset by 4 bytes.
  • Loading branch information
mmynk committed Oct 20, 2023
1 parent 09d9a62 commit b06668d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/qdiscs/fq_codel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn unmarshal_fq_codel_xstats(bytes: &[u8]) -> Result<FqCodelXStats, TcError> {
.map_err(|_| TcError::Decode("Failed to extract FqCodel XStats kind".to_string()))?;
let kind = u32::from_ne_bytes(buf);
if kind == 0 {
bincode::deserialize(bytes).map_err(|e| TcError::UnmarshalStruct(e))
bincode::deserialize(&bytes[4..]).map_err(|e| TcError::UnmarshalStruct(e))
} else {
Err(TcError::InvalidAttribute(format!(
"FqCodel XStats has unidentified kind: {kind}"
Expand Down
2 changes: 1 addition & 1 deletion src/tc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub fn qdiscs<T: netlink::NetlinkConnection>() -> Result<Vec<Tc>, TcError> {
let mut tcs = Vec::new();

let messages = T::new()?.qdiscs()?;
// println!("messages: {:?}", messages);
for message in &messages {
let tc = TcMessage {
index: message.header.index as u32,
Expand Down Expand Up @@ -143,7 +144,6 @@ pub fn qdiscs<T: netlink::NetlinkConnection>() -> Result<Vec<Tc>, TcError> {
}
}
}
// netlink_tc::Nla::QDisc(q_disc) => parse_qdisc(&mut tc, q_disc),
netlink_tc::Nla::XStats(bytes) => xstats = bytes.clone(),
_ => (),
}
Expand Down

0 comments on commit b06668d

Please sign in to comment.