From d9db22093b2bc9857f54502b435dd6cd1c798de8 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Tue, 15 Dec 2020 16:59:23 +0800 Subject: [PATCH] Fix: write to log without clientIP (#517) --- app/dns/dohdns.go | 8 ++++++-- app/dns/udpns.go | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/dns/dohdns.go b/app/dns/dohdns.go index 104e705d4..33123ec73 100644 --- a/app/dns/dohdns.go +++ b/app/dns/dohdns.go @@ -44,7 +44,9 @@ type DoHNameServer struct { // NewDoHNameServer creates DOH client object for remote resolving func NewDoHNameServer(url *url.URL, dispatcher routing.Dispatcher, clientIP net.IP) (*DoHNameServer, error) { newError("DNS: created Remote DOH client for ", url.String()).AtInfo().WriteToLog() - newError("DNS: Remote DOH client ", url.String(), " use clientip ", clientIP.String()).AtInfo().WriteToLog() + if clientIP != nil { + newError("DNS: Remote DOH client ", url.String(), " uses clientip ", clientIP.String()).AtInfo().WriteToLog() + } s := baseDOHNameServer(url, "DOH", clientIP) // Dispatched connection will be closed (interrupted) after each request @@ -108,7 +110,9 @@ func NewDoHLocalNameServer(url *url.URL, clientIP net.IP) *DoHNameServer { Transport: tr, } newError("DNS: created Local DOH client for ", url.String()).AtInfo().WriteToLog() - newError("DNS: Local DOH client ", url.String(), " use clientip ", clientIP.String()).AtInfo().WriteToLog() + if clientIP != nil { + newError("DNS: Local DOH client ", url.String(), " uses clientip ", clientIP.String()).AtInfo().WriteToLog() + } return s } diff --git a/app/dns/udpns.go b/app/dns/udpns.go index b4bbeeffa..9cf3a8e9d 100644 --- a/app/dns/udpns.go +++ b/app/dns/udpns.go @@ -55,7 +55,9 @@ func NewClassicNameServer(address net.Destination, dispatcher routing.Dispatcher } s.udpServer = udp.NewDispatcher(dispatcher, s.HandleResponse) newError("DNS: created UDP client inited for ", address.NetAddr()).AtInfo().WriteToLog() - newError("DNS: UDP client ", address.NetAddr(), " use clientip ", clientIP.String()).AtInfo().WriteToLog() + if clientIP != nil { + newError("DNS: UDP client ", address.NetAddr(), " uses clientip ", clientIP.String()).AtInfo().WriteToLog() + } return s }