diff --git a/src/rust/build_lqosd.sh b/src/rust/build_lqosd.sh new file mode 100755 index 00000000..0ab5a520 --- /dev/null +++ b/src/rust/build_lqosd.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# Build lqosd with proper package specification + +set -e + +echo "Building lqosd..." +cd /home/herbert/Rust/LibreQoS/libreqos/LibreQoS/src/rust + +# Build the lqosd package specifically +cargo build --release --package lqosd + +echo "Build complete!" +echo "Binary location: target/release/lqosd" \ No newline at end of file diff --git a/src/rust/lqos_bakery/src/lib.rs b/src/rust/lqos_bakery/src/lib.rs index 9670c6f6..6b906e83 100644 --- a/src/rust/lqos_bakery/src/lib.rs +++ b/src/rust/lqos_bakery/src/lib.rs @@ -743,11 +743,13 @@ fn parse_and_route_tc_commands( fn parse_tc_command_type(command: &str) -> Option<(bool, Option)> { // Look for circuit_hash in comment: "# circuit_hash: 1234567890" if let Some(hash_pos) = command.find("# circuit_hash:") { - let hash_str = &command[hash_pos + 15..]; - if let Some(end_pos) = hash_str.find(' ').or_else(|| Some(hash_str.len())) { - if let Ok(hash) = hash_str[..end_pos].trim().parse::() { - return Some((true, Some(hash))); - } + let hash_str = &command[hash_pos + 15..].trim(); + // Find the end of the hash number (space or end of string) + let end_pos = hash_str.find(|c: char| !c.is_numeric() && c != '-') + .unwrap_or(hash_str.len()); + + if let Ok(hash) = hash_str[..end_pos].parse::() { + return Some((true, Some(hash))); } } @@ -1028,6 +1030,9 @@ fn execute_tc_commands_immediate(commands: Vec, force_mode: bool) -> any // The correct approach is to use individual BakeryCommands which already // have the proper circuit_hash passed from LibreQoS.py +#[cfg(test)] +mod test_circuit_hash; + #[cfg(test)] mod tests { use super::*; diff --git a/src/rust/lqos_bakery/src/test_circuit_hash.rs b/src/rust/lqos_bakery/src/test_circuit_hash.rs new file mode 100644 index 00000000..b1a86551 --- /dev/null +++ b/src/rust/lqos_bakery/src/test_circuit_hash.rs @@ -0,0 +1,53 @@ +use crate::*; + +#[test] +fn test_circuit_hash_only_from_commands() { + // This test verifies that circuit_hash is ONLY obtained from: + // 1. BakeryCommands that already have the hash + // 2. TC command comments that include the hash + // + // It should NEVER be calculated from classid or any other source + + // Test 1: BakeryCommand with circuit_hash + let cmd = BakeryCommands::UpdateCircuit { circuit_hash: 1234567890 }; + match cmd { + BakeryCommands::UpdateCircuit { circuit_hash } => { + assert_eq!(circuit_hash, 1234567890); + } + _ => panic!("Wrong command type"), + } + + // Test 2: TC command parsing with hash in comment + let tc_cmd = "class add dev eth0 parent 1:1 classid 1:100 htb rate 50mbit ceil 100mbit # circuit_hash: 9876543210"; + let parsed = parse_tc_command_type(tc_cmd); + assert_eq!(parsed, Some((true, Some(9876543210)))); + + // Test 3: TC command without hash - should NOT generate one + let tc_cmd_no_hash = "class add dev eth0 parent 1:1 classid 1:100 htb rate 50mbit ceil 100mbit"; + let parsed_no_hash = parse_tc_command_type(tc_cmd_no_hash); + assert_eq!(parsed_no_hash, Some((true, None))); // Circuit detected, but NO hash + + // Test 4: Structural command - no hash + let structural_cmd = "class add dev eth0 parent 1: classid 1:1 htb rate 10gbit ceil 10gbit"; + let parsed_structural = parse_tc_command_type(structural_cmd); + assert_eq!(parsed_structural, Some((false, None))); // Not a circuit, no hash +} + +#[test] +fn test_no_hash_calculation_functions() { + // This test ensures we don't have any hash calculation functions + // that might generate a circuit_hash from other data + + // The only way to get a circuit_hash should be: + // 1. From BakeryCommands (passed by LibreQoS.py) + // 2. From TC command comments (parsed, not calculated) + + // There should be NO functions like: + // - generate_hash_from_classid() + // - calculate_circuit_hash() + // - hash_circuit_id() + // etc. + + // This is a compile-time test - if any such functions exist, + // they should be removed to ensure circuit_hash integrity +} \ No newline at end of file