Merge pull request #229 from safing/feature/switch-to-localhost-nameserver

Switch to localhost nameserver
This commit is contained in:
Daniel
2021-01-19 15:13:10 +01:00
committed by GitHub
8 changed files with 305 additions and 126 deletions

View File

@@ -292,6 +292,7 @@ func (e *Entity) getDomainLists(ctx context.Context) {
return
}
var err error
e.loadDomainListOnce.Do(func() {
var domainsToInspect = []string{domain}
@@ -314,10 +315,10 @@ func (e *Entity) getDomainLists(ctx context.Context) {
for _, d := range domains {
log.Tracer(ctx).Tracef("intel: loading domain list for %s", d)
list, err := filterlists.LookupDomain(d)
var list []string
list, err = filterlists.LookupDomain(d)
if err != nil {
log.Tracer(ctx).Errorf("intel: failed to get domain blocklists for %s: %s", d, err)
e.loadDomainListOnce = sync.Once{}
return
}
@@ -325,6 +326,10 @@ func (e *Entity) getDomainLists(ctx context.Context) {
}
e.domainListLoaded = true
})
if err != nil {
e.loadDomainListOnce = sync.Once{}
}
}
func splitDomain(domain string) []string {

View File

@@ -2,9 +2,7 @@ package filterlists
import (
"errors"
"fmt"
"net"
"strings"
"github.com/safing/portbase/database"
"github.com/safing/portbase/log"
@@ -55,15 +53,16 @@ func LookupCountry(country string) ([]string, error) {
// LookupDomain returns a list of sources that mark the domain
// as blocked. If domain is not stored in the cache database
// a nil slice is returned.
// a nil slice is returned. The caller is responsible for making
// sure that the given domain is valid and canonical.
func LookupDomain(domain string) ([]string, error) {
// make sure we only fully qualified domains
// ending in a dot.
domain = strings.ToLower(domain)
if domain[len(domain)-1] != '.' {
domain += "."
switch domain {
case "", ".":
// Return no lists for empty domains and the root zone.
return nil, nil
default:
return lookupBlockLists("domain", domain)
}
return lookupBlockLists("domain", domain)
}
// LookupASNString returns a list of sources that mark the ASN
@@ -89,7 +88,7 @@ func LookupIP(ip net.IP) ([]string, error) {
func LookupIPString(ipStr string) ([]string, error) {
ip := net.ParseIP(ipStr)
if ip == nil {
return nil, fmt.Errorf("invalid IP")
return nil, errors.New("invalid IP")
}
return LookupIP(ip)