mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Fix linter errors
This commit is contained in:
parent
12b0ff973d
commit
af056780fc
5 changed files with 21 additions and 14 deletions
|
@ -28,7 +28,7 @@ type Queue struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New opens a new nfQueue.
|
// New opens a new nfQueue.
|
||||||
func New(qid uint16, v6 bool) (*Queue, error) {
|
func New(qid uint16, v6 bool) (*Queue, error) { //nolint:gocognit
|
||||||
afFamily := unix.AF_INET
|
afFamily := unix.AF_INET
|
||||||
if v6 {
|
if v6 {
|
||||||
afFamily = unix.AF_INET6
|
afFamily = unix.AF_INET6
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (br ListBlockReason) MarshalJSON() ([]byte, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExtraRR implements the nsutil.RRProvider interface
|
// GetExtraRRs implements the nsutil.RRProvider interface
|
||||||
// and adds additional TXT records justifying the reason
|
// and adds additional TXT records justifying the reason
|
||||||
// the request was blocked.
|
// the request was blocked.
|
||||||
func (br ListBlockReason) GetExtraRRs(ctx context.Context, _ *dns.Msg) []dns.RR {
|
func (br ListBlockReason) GetExtraRRs(ctx context.Context, _ *dns.Msg) []dns.RR {
|
||||||
|
|
|
@ -79,6 +79,7 @@ func ZeroIP(msg string) ResponderFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Localhost is a ResponderFunc than replies with localhost IP addresses.
|
||||||
func Localhost(msg string) ResponderFunc {
|
func Localhost(msg string) ResponderFunc {
|
||||||
return func(ctx context.Context, request *dns.Msg) *dns.Msg {
|
return func(ctx context.Context, request *dns.Msg) *dns.Msg {
|
||||||
reply := new(dns.Msg)
|
reply := new(dns.Msg)
|
||||||
|
@ -145,7 +146,9 @@ func ServerFailure(msg string) ResponderFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeMessageRecord(level log.Severity, msg string) (dns.RR, error) {
|
// MakeMessageRecord creates an informational resource record that can be added
|
||||||
|
// to the extra section of a reply.
|
||||||
|
func MakeMessageRecord(level log.Severity, msg string) (dns.RR, error) { //nolint:interfacer
|
||||||
return dns.NewRR(fmt.Sprintf(
|
return dns.NewRR(fmt.Sprintf(
|
||||||
`%s.portmaster. 0 IN TXT "%s"`,
|
`%s.portmaster. 0 IN TXT "%s"`,
|
||||||
strings.ToLower(level.String()),
|
strings.ToLower(level.String()),
|
||||||
|
@ -153,6 +156,10 @@ func MakeMessageRecord(level log.Severity, msg string) (dns.RR, error) {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddMessageToReply creates an information resource records using
|
||||||
|
// MakeMessageRecord and immediately adds it the the extra section of the given
|
||||||
|
// reply. If an error occurs, the resource record will not be added, and the
|
||||||
|
// error will be logged.
|
||||||
func AddMessageToReply(ctx context.Context, reply *dns.Msg, level log.Severity, msg string) {
|
func AddMessageToReply(ctx context.Context, reply *dns.Msg, level log.Severity, msg string) {
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
rr, err := MakeMessageRecord(level, msg)
|
rr, err := MakeMessageRecord(level, msg)
|
||||||
|
|
|
@ -239,7 +239,7 @@ func (mgr *tcpResolverConnMgr) run(workerCtx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create connection
|
// create connection
|
||||||
conn, connClosing, connCtx, cancelConnCtx := mgr.establishConnection(workerCtx)
|
conn, connClosing, connCtx, cancelConnCtx := mgr.establishConnection()
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
mgr.failCnt++
|
mgr.failCnt++
|
||||||
continue
|
continue
|
||||||
|
@ -324,7 +324,7 @@ func (mgr *tcpResolverConnMgr) waitForWork(workerCtx context.Context) (proceed b
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *tcpResolverConnMgr) establishConnection(workerCtx context.Context) (
|
func (mgr *tcpResolverConnMgr) establishConnection() (
|
||||||
conn *dns.Conn,
|
conn *dns.Conn,
|
||||||
connClosing *abool.AtomicBool,
|
connClosing *abool.AtomicBool,
|
||||||
connCtx context.Context,
|
connCtx context.Context,
|
||||||
|
|
|
@ -274,35 +274,35 @@ func (rrCache *RRCache) ReplyWithDNS(ctx context.Context, request *dns.Msg) *dns
|
||||||
func (rrCache *RRCache) GetExtraRRs(ctx context.Context, query *dns.Msg) (extra []dns.RR) {
|
func (rrCache *RRCache) GetExtraRRs(ctx context.Context, query *dns.Msg) (extra []dns.RR) {
|
||||||
// Add cache status and source of data.
|
// Add cache status and source of data.
|
||||||
if rrCache.servedFromCache {
|
if rrCache.servedFromCache {
|
||||||
extra = addExtra(ctx, extra, log.InfoLevel, "served from cache, resolved by "+rrCache.ServerInfo)
|
extra = addExtra(ctx, extra, "served from cache, resolved by "+rrCache.ServerInfo)
|
||||||
} else {
|
} else {
|
||||||
extra = addExtra(ctx, extra, log.InfoLevel, "freshly resolved by "+rrCache.ServerInfo)
|
extra = addExtra(ctx, extra, "freshly resolved by "+rrCache.ServerInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add expiry and cache information.
|
// Add expiry and cache information.
|
||||||
if rrCache.Expired() {
|
if rrCache.Expired() {
|
||||||
extra = addExtra(ctx, extra, log.InfoLevel, fmt.Sprintf("record expired since %s, requesting new", time.Since(time.Unix(rrCache.TTL, 0))))
|
extra = addExtra(ctx, extra, fmt.Sprintf("record expired since %s, requesting new", time.Since(time.Unix(rrCache.TTL, 0))))
|
||||||
} else {
|
} else {
|
||||||
extra = addExtra(ctx, extra, log.InfoLevel, fmt.Sprintf("record valid for %s", time.Until(time.Unix(rrCache.TTL, 0))))
|
extra = addExtra(ctx, extra, fmt.Sprintf("record valid for %s", time.Until(time.Unix(rrCache.TTL, 0))))
|
||||||
}
|
}
|
||||||
if rrCache.requestingNew {
|
if rrCache.requestingNew {
|
||||||
extra = addExtra(ctx, extra, log.InfoLevel, "async request to refresh the cache has been started")
|
extra = addExtra(ctx, extra, "async request to refresh the cache has been started")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add information about filtered entries.
|
// Add information about filtered entries.
|
||||||
if rrCache.Filtered {
|
if rrCache.Filtered {
|
||||||
if len(rrCache.FilteredEntries) > 1 {
|
if len(rrCache.FilteredEntries) > 1 {
|
||||||
extra = addExtra(ctx, extra, log.InfoLevel, fmt.Sprintf("%d records have been filtered", len(rrCache.FilteredEntries)))
|
extra = addExtra(ctx, extra, fmt.Sprintf("%d records have been filtered", len(rrCache.FilteredEntries)))
|
||||||
} else {
|
} else {
|
||||||
extra = addExtra(ctx, extra, log.InfoLevel, fmt.Sprintf("%d record has been filtered", len(rrCache.FilteredEntries)))
|
extra = addExtra(ctx, extra, fmt.Sprintf("%d record has been filtered", len(rrCache.FilteredEntries)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return extra
|
return extra
|
||||||
}
|
}
|
||||||
|
|
||||||
func addExtra(ctx context.Context, extra []dns.RR, level log.Severity, msg string) []dns.RR {
|
func addExtra(ctx context.Context, extra []dns.RR, msg string) []dns.RR {
|
||||||
rr, err := nsutil.MakeMessageRecord(level, msg)
|
rr, err := nsutil.MakeMessageRecord(log.InfoLevel, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Tracer(ctx).Warningf("resolver: failed to add informational record to reply: %s", err)
|
log.Tracer(ctx).Warningf("resolver: failed to add informational record to reply: %s", err)
|
||||||
return extra
|
return extra
|
||||||
|
|
Loading…
Add table
Reference in a new issue