coredns plugin -- convert logic into switch, logging unexpected non-covered cases
This commit is contained in:
parent
fe397943d6
commit
c7a5275d42
|
@ -411,8 +411,9 @@ func (d *Plugin) serveDNSInternal(ctx context.Context, w dns.ResponseWriter, r *
|
||||||
return dns.RcodeServerFailure, fmt.Errorf("plugin/dnsfilter: %s", err), dnsfilter.Result{}
|
return dns.RcodeServerFailure, fmt.Errorf("plugin/dnsfilter: %s", err), dnsfilter.Result{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// safebrowsing
|
if result.IsFiltered {
|
||||||
if result.IsFiltered == true && result.Reason == dnsfilter.FilteredSafeBrowsing {
|
switch result.Reason {
|
||||||
|
case dnsfilter.FilteredSafeBrowsing:
|
||||||
// return cname safebrowsing.block.dns.adguard.com
|
// return cname safebrowsing.block.dns.adguard.com
|
||||||
val := d.SafeBrowsingBlockHost
|
val := d.SafeBrowsingBlockHost
|
||||||
rcode, err := d.replaceHostWithValAndReply(ctx, w, r, host, val, question)
|
rcode, err := d.replaceHostWithValAndReply(ctx, w, r, host, val, question)
|
||||||
|
@ -420,30 +421,34 @@ func (d *Plugin) serveDNSInternal(ctx context.Context, w dns.ResponseWriter, r *
|
||||||
return rcode, err, dnsfilter.Result{}
|
return rcode, err, dnsfilter.Result{}
|
||||||
}
|
}
|
||||||
return rcode, err, result
|
return rcode, err, result
|
||||||
}
|
case dnsfilter.FilteredParental:
|
||||||
|
// return cname family.block.dns.adguard.com
|
||||||
// parental
|
|
||||||
if result.IsFiltered == true && result.Reason == dnsfilter.FilteredParental {
|
|
||||||
// return cname
|
|
||||||
val := d.ParentalBlockHost
|
val := d.ParentalBlockHost
|
||||||
rcode, err := d.replaceHostWithValAndReply(ctx, w, r, host, val, question)
|
rcode, err := d.replaceHostWithValAndReply(ctx, w, r, host, val, question)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rcode, err, dnsfilter.Result{}
|
return rcode, err, dnsfilter.Result{}
|
||||||
}
|
}
|
||||||
return rcode, err, result
|
return rcode, err, result
|
||||||
}
|
case dnsfilter.FilteredBlackList:
|
||||||
|
// return NXdomain
|
||||||
// blacklist
|
|
||||||
if result.IsFiltered == true && result.Reason == dnsfilter.FilteredBlackList {
|
|
||||||
rcode, err := writeNXdomain(ctx, w, r)
|
rcode, err := writeNXdomain(ctx, w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rcode, err, dnsfilter.Result{}
|
return rcode, err, dnsfilter.Result{}
|
||||||
}
|
}
|
||||||
return rcode, err, result
|
return rcode, err, result
|
||||||
|
default:
|
||||||
|
log.Printf("SHOULD NOT HAPPEN -- got unknown reason for filtering: %T %v %s", result.Reason, result.Reason, result.Reason.String())
|
||||||
}
|
}
|
||||||
if result.IsFiltered == false && result.Reason == dnsfilter.NotFilteredWhiteList {
|
} else {
|
||||||
|
switch result.Reason {
|
||||||
|
case dnsfilter.NotFilteredWhiteList:
|
||||||
rcode, err := plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
|
rcode, err := plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
|
||||||
return rcode, err, result
|
return rcode, err, result
|
||||||
|
case dnsfilter.NotFilteredNotFound:
|
||||||
|
// do nothing, pass through to lower code
|
||||||
|
default:
|
||||||
|
log.Printf("SHOULD NOT HAPPEN -- got unknown reason for not filtering: %T %v %s", result.Reason, result.Reason, result.Reason.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rcode, err := plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
|
rcode, err := plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
|
||||||
|
|
Loading…
Reference in New Issue