mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 13:05:36 +03:00
fix client IP address
This commit is contained in:
parent
8227970d39
commit
62606db1af
2 changed files with 15 additions and 2 deletions
|
@ -252,7 +252,7 @@ func (s *Server) handleDNSRequest(p *proxy.Proxy, d *proxy.DNSContext) error {
|
|||
if d.Upstream != nil {
|
||||
upstreamAddr = d.Upstream.Address()
|
||||
}
|
||||
logRequest(msg, d.Res, res, elapsed, d.Addr.String(), upstreamAddr)
|
||||
logRequest(msg, d.Res, res, elapsed, d.Addr, upstreamAddr)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -3,6 +3,7 @@ package dnsforward
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -41,10 +42,11 @@ type logEntry struct {
|
|||
Upstream string `json:",omitempty"` // if empty, means it was cached
|
||||
}
|
||||
|
||||
func logRequest(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, ip string, upstream string) {
|
||||
func logRequest(question *dns.Msg, answer *dns.Msg, result *dnsfilter.Result, elapsed time.Duration, addr net.Addr, upstream string) {
|
||||
var q []byte
|
||||
var a []byte
|
||||
var err error
|
||||
ip := getIPString(addr)
|
||||
|
||||
if question != nil {
|
||||
q, err = question.Pack()
|
||||
|
@ -227,3 +229,14 @@ func HandleQueryLog(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, errorText, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// getIPString is a helper function that extracts IP address from net.Addr
|
||||
func getIPString(addr net.Addr) string {
|
||||
switch addr := addr.(type) {
|
||||
case *net.UDPAddr:
|
||||
return addr.IP.String()
|
||||
case *net.TCPAddr:
|
||||
return addr.IP.String()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue