Files
ddidderr 4d5881d6b0 fix(mdns): retain origin and bound daemon state
Vendor the pinned mdns-sd 0.21.1 source so response records retain their observed source IP. Bound unauthenticated cache records to 1024 globally and 128 per source, deduplicate and cap timers at 4096, and poll at least once per second for expiry cleanup.

Expose packet provenance through lanspread-mdns, drop originless resolutions, and add a dedicated vendor test recipe while keeping third-party sources outside workspace formatting and Clippy.

Test Plan:
- just mdns-vendor-test (106 tests passed with socket access)
- just test
- just fmt
- just clippy
- cache/per-source, exact-refresh, timer-cap, and serde tests
- git diff --check
2026-09-12 13:08:26 +02:00

149 lines
3.3 KiB
Rust

use std::{
collections::HashSet,
net::{IpAddr, Ipv4Addr, Ipv6Addr},
};
use mdns_sd::AsIpAddrs;
#[test]
fn test_addr_str() {
assert_eq!(
"127.0.0.1".as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set
})
);
let addr = "127.0.0.1".to_string();
assert_eq!(
addr.as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set
})
);
// verify that `&String` also works.
assert_eq!(
addr.as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set
})
);
assert_eq!(
"127.0.0.1,127.0.0.2".as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set.insert(Ipv4Addr::new(127, 0, 0, 2).into());
set
})
);
let addr = "2001:db8::1".to_string();
assert_eq!(
addr.as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).into());
set
})
);
assert_eq!(
"2001:db8::1,2001:db8::2".as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).into());
set.insert(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 2).into());
set
})
);
// verify that an empty string parsed into an empty set.
assert_eq!("".as_ip_addrs(), Ok(HashSet::new()));
}
#[test]
fn test_addr_slice() {
assert_eq!(
(&["127.0.0.1"][..]).as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set
})
);
assert_eq!(
(&["127.0.0.1", "127.0.0.2"][..]).as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set.insert(Ipv4Addr::new(127, 0, 0, 2).into());
set
})
);
assert_eq!(
(&vec!["127.0.0.1", "127.0.0.2"][..]).as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set.insert(Ipv4Addr::new(127, 0, 0, 2).into());
set
})
);
assert_eq!(
(&vec!["2001:db8::1", "2001:db8::2"][..]).as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).into());
set.insert(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 2).into());
set
})
);
}
#[test]
fn test_addr_ip() {
let ip: IpAddr = Ipv4Addr::new(127, 0, 0, 1).into();
assert_eq!(
ip.as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set
})
);
assert_eq!(
ip.as_ip_addrs(),
Ok({
let mut set = HashSet::new();
set.insert(Ipv4Addr::new(127, 0, 0, 1).into());
set
})
);
}