udp: statistics: properly handle ipv4-mapped ipv6 addresses

This commit is contained in:
Joakim Frostegård 2021-11-21 20:16:17 +01:00
parent f001c69dc7
commit 3a4056058b

View file

@ -240,20 +240,8 @@ fn read_requests(
Request::from_bytes(&buffer[..amt], config.protocol.max_scrape_torrents);
let src = match src {
src @ SocketAddr::V4(_) => {
if res_request.is_ok() {
requests_received_ipv4 += 1;
}
bytes_received_ipv4 += amt;
src
}
src @ SocketAddr::V4(_) => src,
SocketAddr::V6(src) => {
if res_request.is_ok() {
requests_received_ipv6 += 1;
}
bytes_received_ipv6 += amt;
match src.ip().octets() {
// Convert IPv4-mapped address (available in std but nightly-only)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, a, b, c, d] => {
@ -267,6 +255,19 @@ fn read_requests(
}
};
// Update statistics for converted address
if src.is_ipv4() {
if res_request.is_ok() {
requests_received_ipv4 += 1;
}
bytes_received_ipv4 += amt;
} else {
if res_request.is_ok() {
requests_received_ipv6 += 1;
}
bytes_received_ipv6 += amt;
}
handle_request(
config,
connections,