Pull request: * dnsforward, querylog: set client_proto for logs correctly

Merge in DNS/adguard-home from 2241-doq-logs to master

Squashed commit of the following:

commit a15cab05358e3c0b97f8257f8b9628fa590e7e7d
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Nov 3 14:22:25 2020 +0300

    * all: update dnsproxy

commit 5fb0919a7528dc6ee7a433a8096b550f3691771c
Merge: b22b1dff4 64c1a68fb
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Nov 3 14:22:15 2020 +0300

    Merge branch 'master' into 2241-doq-logs

commit b22b1dff43e541d77160fd5c234483bbf0f6d8de
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Nov 3 12:37:23 2020 +0300

    * dnsforward, querylog: set client_proto for logs correctly
This commit is contained in:
Ainar Garipov
2020-11-03 15:39:55 +03:00
parent 64c1a68fb9
commit df34ee5c09
9 changed files with 108 additions and 45 deletions

View File

@@ -1,6 +1,8 @@
// Package querylog provides query log functions and interfaces.
package querylog
import (
"fmt"
"os"
"path/filepath"
"strings"
@@ -29,6 +31,33 @@ type queryLog struct {
fileWriteLock sync.Mutex
}
// ClientProto values are names of the client protocols.
type ClientProto string
// Client protocol names.
const (
ClientProtoDOH ClientProto = "doh"
ClientProtoDOQ ClientProto = "doq"
ClientProtoDOT ClientProto = "dot"
ClientProtoPlain ClientProto = ""
)
// NewClientProto validates that the client protocol name is valid and returns
// the name as a ClientProto.
func NewClientProto(s string) (cp ClientProto, err error) {
switch cp = ClientProto(s); cp {
case
ClientProtoDOH,
ClientProtoDOQ,
ClientProtoDOT,
ClientProtoPlain:
return cp, nil
default:
return "", fmt.Errorf("invalid client proto: %q", s)
}
}
// logEntry - represents a single log entry
type logEntry struct {
IP string `json:"IP"` // Client IP
@@ -38,7 +67,7 @@ type logEntry struct {
QType string `json:"QT"`
QClass string `json:"QC"`
ClientProto string `json:"CP"` // "" or "doh"
ClientProto ClientProto `json:"CP"`
Answer []byte `json:",omitempty"` // sometimes empty answers happen like binerdunt.top or rev2.globalrootservers.net
OrigAnswer []byte `json:",omitempty"`
@@ -158,7 +187,6 @@ func (l *queryLog) Add(params AddParams) {
// writing to file is disabled - just remove the oldest entry from array
l.buffer = l.buffer[1:]
}
} else if !l.flushPending {
needFlush = len(l.buffer) >= int(l.conf.MemSize)
if needFlush {