Parse fwmark in Cake stats as a TcHandle (#294)

FIXES #289

Extend TC parser to handle cases that don't have a colon at all.
Use this to parse the `fwmark` field in the Cake stats, which
is probably a TC handle - but since the cake source doesn't
document it, it might be a random number for all we know.

The `fwmark` field isn't actually referenced anywhere in the
program.
This commit is contained in:
Herbert "TheBracket 2023-03-23 13:50:01 -05:00 committed by GitHub
parent 25801b6445
commit b8436ca734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -34,8 +34,13 @@ impl TcHandle {
"none" => Ok(Self(TC_H_UNSPEC)),
_ => {
if !handle.contains(':') {
error!("Unable to parse TC handle {handle}. Must contain a colon.");
return Err(TcHandleParseError::InvalidInput(handle.to_string()));
if let Ok(major) = read_hex_string(handle) {
let minor = 0;
return Ok(Self((major << 16) | minor));
} else {
error!("Unable to parse TC handle {handle}. Must contain a colon.");
return Err(TcHandleParseError::InvalidInput(handle.to_string()));
}
}
let parts: Vec<&str> = handle.split(':').collect();
let major = read_hex_string(parts[0]).map_err(|_| TcHandleParseError::InvalidInput(handle.to_string()))?;

View File

@ -59,7 +59,7 @@ struct TcCakeOptions {
split_gso: bool,
raw: bool,
overhead: u16,
fwmark: String,
fwmark: TcHandle,
}
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
@ -179,7 +179,7 @@ impl TcCakeOptions {
"raw" => result.raw = value.as_bool().unwrap_or(false),
"overhead" => result.overhead = value.as_u64().unwrap_or(0) as u16,
"fwmark" => {
result.fwmark = value.as_str().unwrap_or("").to_string()
parse_tc_handle!(result.fwmark, value);
}
_ => {
info_once!(