Сборка: добавить production packaging flow через .deb
Добавлен package-режим в tools/build.sh: --package, --dist-dir, --version. Реализована сборка Debian-пакета, metadata/control, postinst/postrm и SHA256SUMS. Установочные пути унифицированы под /usr/sbin и /lib/systemd/system для production-модели.
This commit is contained in:
@@ -290,11 +290,12 @@ fn parse_tc_filter_hits(raw: &str) -> BTreeMap<String, u64> {
|
||||
current_ip = extract_tc_match_ip(t);
|
||||
} else if t.starts_with("Sent ") {
|
||||
if let Some(ip) = current_ip.clone() {
|
||||
let hits = t
|
||||
.split_whitespace()
|
||||
.nth(4)
|
||||
.and_then(|s| s.parse::<u64>().ok())
|
||||
.unwrap_or(0);
|
||||
let hits = parse_sent_packets(t).unwrap_or(0);
|
||||
out.insert(ip, hits);
|
||||
}
|
||||
} else if t.contains(" success ") || t.starts_with("success ") {
|
||||
if let Some(ip) = current_ip.clone() {
|
||||
let hits = parse_success_packets(t).unwrap_or(0);
|
||||
out.insert(ip, hits);
|
||||
}
|
||||
}
|
||||
@@ -302,6 +303,20 @@ fn parse_tc_filter_hits(raw: &str) -> BTreeMap<String, u64> {
|
||||
out
|
||||
}
|
||||
|
||||
fn parse_sent_packets(line: &str) -> Option<u64> {
|
||||
let toks: Vec<&str> = line.split_whitespace().collect();
|
||||
if toks.len() >= 5 && toks[0] == "Sent" && toks[2] == "bytes" && toks[4] == "pkt" {
|
||||
return toks[3].parse::<u64>().ok();
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn parse_success_packets(line: &str) -> Option<u64> {
|
||||
let toks: Vec<&str> = line.split_whitespace().collect();
|
||||
let pos = toks.iter().position(|v| *v == "success")?;
|
||||
toks.get(pos + 1)?.parse::<u64>().ok()
|
||||
}
|
||||
|
||||
fn extract_tc_match_ip(line: &str) -> Option<String> {
|
||||
let toks: Vec<&str> = line.split_whitespace().collect();
|
||||
let pos = toks.iter().position(|v| *v == "match")?;
|
||||
@@ -316,3 +331,37 @@ fn extract_tc_match_ip(line: &str) -> Option<String> {
|
||||
let b4 = u8::from_str_radix(&hex[6..8], 16).ok()?;
|
||||
Some(format!("{b1}.{b2}.{b3}.{b4}"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{parse_sent_packets, parse_success_packets, parse_tc_filter_hits};
|
||||
|
||||
#[test]
|
||||
fn parse_sent_pkt_counter() {
|
||||
let line = "Sent 12345 bytes 67 pkt (dropped 0, overlimits 0 requeues 0)";
|
||||
assert_eq!(parse_sent_packets(line), Some(67));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_success_counter() {
|
||||
let line = "match 0a080102/ffffffff at 16 success 42";
|
||||
assert_eq!(parse_success_packets(line), Some(42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_tc_filter_hits_supports_sent_and_success() {
|
||||
let raw = r#"
|
||||
filter parent 1: protocol ip pref 1 u32 chain 0
|
||||
filter parent 1: protocol ip pref 1 u32 chain 0 fh 800: ht divisor 1
|
||||
filter parent 1: protocol ip pref 1 u32 chain 0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:10 not_in_hw
|
||||
match 0a080102/ffffffff at 16
|
||||
Sent 100 bytes 7 pkt (dropped 0, overlimits 0 requeues 0)
|
||||
filter parent 1: protocol ip pref 1 u32 chain 0 fh 800::801 order 2049 key ht 800 bkt 0 flowid 1:11 not_in_hw
|
||||
match 0a080103/ffffffff at 16 success 9
|
||||
"#;
|
||||
|
||||
let map = parse_tc_filter_hits(raw);
|
||||
assert_eq!(map.get("10.8.1.2"), Some(&7));
|
||||
assert_eq!(map.get("10.8.1.3"), Some(&9));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user