From 3a4056058bc85c4124e40d5cf7f8e09c90eea8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 21 Nov 2021 20:16:17 +0100 Subject: [PATCH] udp: statistics: properly handle ipv4-mapped ipv6 addresses --- aquatic_udp/src/lib/workers/socket.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/aquatic_udp/src/lib/workers/socket.rs b/aquatic_udp/src/lib/workers/socket.rs index db359d6..53b214c 100644 --- a/aquatic_udp/src/lib/workers/socket.rs +++ b/aquatic_udp/src/lib/workers/socket.rs @@ -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,