mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-24 22:15:45 +03:00
c1ee2c7e5e
Updates #6312. Squashed commit of the following: commit bd9146ee161a67fa41763070f985e1e73b85823b Merge: 58d2fd98d856cc40cf
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 24 18:09:19 2024 +0300 Merge branch 'master' into 6312-client-ipv6-zone commit 58d2fd98d3e82c84638d58dd4d74d13a9a8fbca6 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 24 18:00:56 2024 +0300 client: imp naming commit 922a14b036d829c2775feb7bb3e6beb6aa49692e Merge: 6f4d58fe160f48e2d0
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 24 14:29:00 2024 +0300 Merge branch 'master' into 6312-client-ipv6-zone commit 6f4d58fe1c42504e8345bff24dbb3f523e8c5f85 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 24 14:27:55 2024 +0300 client: imp docs commit fa292eee828cd6f27f62b782675aa1f998e44518 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Apr 22 19:20:28 2024 +0300 client: fix typo commit 599414be0ccd3f9deb044e022a8ac0006c96b467 Merge: 502571756762ef4a6d
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Apr 22 18:42:06 2024 +0300 Merge branch 'master' into 6312-client-ipv6-zone commit 502571756400a00445086b5ba412e03fca65e39f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Apr 22 18:39:22 2024 +0300 all: imp code; add tests commit 155b2fef500a0d835f49957d9f30b0870712f6f2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Apr 16 19:56:00 2024 +0300 all: upd chlog; imp code commit 7a4426c5d0a511cd3865884c00328b8c130746bf Merge: e9c1cbb8548c6242a7
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Apr 16 19:52:00 2024 +0300 Merge branch 'master' into 6312-client-ipv6-zone commit e9c1cbb85e4afa173969d5bedfaaaf92716b7fad Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 10 16:23:07 2024 +0300 client: client ipv6 zone
87 lines
2 KiB
Go
87 lines
2 KiB
Go
package querylog
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
|
"github.com/AdguardTeam/golibs/errors"
|
|
"github.com/AdguardTeam/golibs/log"
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
// logEntry represents a single entry in the file.
|
|
type logEntry struct {
|
|
// client is the found client information, if any.
|
|
client *Client
|
|
|
|
Time time.Time `json:"T"`
|
|
|
|
QHost string `json:"QH"`
|
|
QType string `json:"QT"`
|
|
QClass string `json:"QC"`
|
|
|
|
ReqECS string `json:"ECS,omitempty"`
|
|
|
|
ClientID string `json:"CID,omitempty"`
|
|
ClientProto ClientProto `json:"CP"`
|
|
|
|
Upstream string `json:",omitempty"`
|
|
|
|
Answer []byte `json:",omitempty"`
|
|
OrigAnswer []byte `json:",omitempty"`
|
|
|
|
// TODO(s.chzhen): Use netip.Addr.
|
|
IP net.IP `json:"IP"`
|
|
|
|
Result filtering.Result
|
|
|
|
Elapsed time.Duration
|
|
|
|
Cached bool `json:",omitempty"`
|
|
AuthenticatedData bool `json:"AD,omitempty"`
|
|
}
|
|
|
|
// shallowClone returns a shallow clone of e.
|
|
func (e *logEntry) shallowClone() (clone *logEntry) {
|
|
cloneVal := *e
|
|
|
|
return &cloneVal
|
|
}
|
|
|
|
// addResponse adds data from resp to e.Answer if resp is not nil. If isOrig is
|
|
// true, addResponse sets the e.OrigAnswer field instead of e.Answer. Any
|
|
// errors are logged.
|
|
func (e *logEntry) addResponse(resp *dns.Msg, isOrig bool) {
|
|
if resp == nil {
|
|
return
|
|
}
|
|
|
|
var err error
|
|
if isOrig {
|
|
e.OrigAnswer, err = resp.Pack()
|
|
err = errors.Annotate(err, "packing orig answer: %w")
|
|
} else {
|
|
e.Answer, err = resp.Pack()
|
|
err = errors.Annotate(err, "packing answer: %w")
|
|
}
|
|
if err != nil {
|
|
log.Error("querylog: %s", err)
|
|
}
|
|
}
|
|
|
|
// parseDNSRewriteResultIPs fills logEntry's DNSRewriteResult response records
|
|
// with the IP addresses parsed from the raw strings.
|
|
func (e *logEntry) parseDNSRewriteResultIPs() {
|
|
for rrType, rrValues := range e.Result.DNSRewriteResult.Response {
|
|
switch rrType {
|
|
case dns.TypeA, dns.TypeAAAA:
|
|
for i, v := range rrValues {
|
|
s, _ := v.(string)
|
|
rrValues[i] = net.ParseIP(s)
|
|
}
|
|
default:
|
|
// Go on.
|
|
}
|
|
}
|
|
}
|