Fix minor bugs

This commit is contained in:
Daniel 2021-01-08 16:37:00 +01:00
parent 564928a97f
commit 3db7457d30
2 changed files with 16 additions and 12 deletions

View file

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

View file

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