@@ -163,7 +163,8 @@ impl DoH {
163163 async fn serve_doh_query (
164164 & self ,
165165 query : Vec < u8 > ,
166- client_ip : Option < IpAddr > ,
166+ ecs_client_ip : Option < IpAddr > ,
167+ log_client_ip : Option < IpAddr > ,
167168 headers : & HeaderMap ,
168169 ) -> Result < Response < Body > , http:: Error > {
169170 // Log the request if logging is enabled
@@ -188,7 +189,7 @@ impl DoH {
188189 self . globals . runtime_handle . spawn ( async move {
189190 let _ = logger_clone
190191 . log_request (
191- client_ip ,
192+ log_client_ip ,
192193 & query_name_clone,
193194 query_type,
194195 user_agent. as_deref ( ) ,
@@ -197,7 +198,7 @@ impl DoH {
197198 } ) ;
198199 }
199200
200- let resp = match self . proxy ( query, client_ip ) . await {
201+ let resp = match self . proxy ( query, ecs_client_ip ) . await {
201202 Ok ( resp) => {
202203 self . build_response ( resp. packet , resp. ttl , DoHType :: Standard . as_str ( ) , true )
203204 }
@@ -235,37 +236,45 @@ impl DoH {
235236 }
236237
237238 async fn serve_doh_get ( & self , req : Request < Body > ) -> Result < Response < Body > , http:: Error > {
238- let client_ip = if self . globals . enable_ecs {
239+ // Extract client IP for ECS (if enabled)
240+ let ecs_client_ip = if self . globals . enable_ecs {
239241 edns_ecs:: extract_client_ip ( req. headers ( ) , None )
240242 } else {
241243 None
242244 } ;
245+
246+ // Always extract client IP for logging
247+ let log_client_ip = edns_ecs:: extract_client_ip ( req. headers ( ) , None ) ;
243248
244249 let headers = req. headers ( ) . clone ( ) ;
245250 let query = match self . query_from_query_string ( req) {
246251 Some ( query) => query,
247252 _ => return http_error_with_cache ( StatusCode :: BAD_REQUEST ) ,
248253 } ;
249- self . serve_doh_query ( query, client_ip , & headers) . await
254+ self . serve_doh_query ( query, ecs_client_ip , log_client_ip , & headers) . await
250255 }
251256
252257 async fn serve_doh_post ( & self , req : Request < Body > ) -> Result < Response < Body > , http:: Error > {
253258 if self . globals . disable_post {
254259 return http_error ( StatusCode :: METHOD_NOT_ALLOWED ) ;
255260 }
256261
257- let client_ip = if self . globals . enable_ecs {
262+ // Extract client IP for ECS (if enabled)
263+ let ecs_client_ip = if self . globals . enable_ecs {
258264 edns_ecs:: extract_client_ip ( req. headers ( ) , None )
259265 } else {
260266 None
261267 } ;
268+
269+ // Always extract client IP for logging
270+ let log_client_ip = edns_ecs:: extract_client_ip ( req. headers ( ) , None ) ;
262271
263272 let headers = req. headers ( ) . clone ( ) ;
264273 let query = match self . read_body ( req. into_body ( ) ) . await {
265274 Ok ( q) => q,
266275 Err ( e) => return http_error ( StatusCode :: from ( e) ) ,
267276 } ;
268- self . serve_doh_query ( query, client_ip , & headers) . await
277+ self . serve_doh_query ( query, ecs_client_ip , log_client_ip , & headers) . await
269278 }
270279
271280 async fn serve_odoh ( & self , encrypted_query : Vec < u8 > ) -> Result < Response < Body > , http:: Error > {
@@ -383,12 +392,15 @@ impl DoH {
383392 }
384393 } ;
385394
386- // Extract client IP if ECS is enabled
387- let client_ip = if self . globals . enable_ecs {
395+ // Extract client IP for ECS (if enabled)
396+ let ecs_client_ip = if self . globals . enable_ecs {
388397 edns_ecs:: extract_client_ip ( req. headers ( ) , None )
389398 } else {
390399 None
391400 } ;
401+
402+ // Always extract client IP for logging
403+ let log_client_ip = edns_ecs:: extract_client_ip ( req. headers ( ) , None ) ;
392404
393405 // Log the request if logging is enabled
394406 if let Some ( ref logger) = self . globals . logger {
@@ -403,13 +415,13 @@ impl DoH {
403415 let query_type = json_query. qtype . unwrap_or ( 1 ) ; // Default to A record
404416 self . globals . runtime_handle . spawn ( async move {
405417 let _ = logger_clone
406- . log_request ( client_ip , & query_name, query_type, user_agent. as_deref ( ) )
418+ . log_request ( log_client_ip , & query_name, query_type, user_agent. as_deref ( ) )
407419 . await ;
408420 } ) ;
409421 }
410422
411423 // Send query and get response
412- let dns_response = match self . proxy ( query_packet, client_ip ) . await {
424+ let dns_response = match self . proxy ( query_packet, ecs_client_ip ) . await {
413425 Ok ( resp) => resp,
414426 Err ( e) => return http_error ( StatusCode :: from ( e) ) ,
415427 } ;
0 commit comments