Skip to content

Commit

Permalink
group blocking section
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Nov 14, 2023
1 parent a3d8a60 commit a31fbd0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
66 changes: 33 additions & 33 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,32 @@ var ConfigVersion = "1.3.0"
// Config holds the configuration parameters
type Config struct {
Version string
Sources []string
SourceDirs []string
LogConfig string
Bind string
API string
NXDomain bool
Nullroute string
Nullroutev6 string
Interval int
Timeout int
QuestionCacheCap int
TTL uint32
Blocklist []string
Whitelist []string
CustomDNSRecords []string
APIDebug bool
Blocking Blocking
Upstream Upstream
Metrics Metrics `toml:"metrics"`
DnsOverHttpServer DnsOverHttpServer
FollowCnameDepth uint32
}

type Blocking struct {
Sources []string
SourceDirs []string
Blocklist []string
Whitelist []string
NXDomain bool
Nullroute string
Nullroutev6 string
}

type Upstream struct {
DoH string
Nameservers []string
Expand Down Expand Up @@ -81,19 +85,6 @@ var defaultConfig = `
# version this config was generated from
version = "%s"
# list of sources to pull blocklists from, stores them in ./sources
sources = [
"https://mirror1.malwaredomains.com/files/justdomains",
"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts",
"https://sysctl.org/cameleon/hosts",
"https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt",
"https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt",
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt"
]
# list of locations to recursively read blocklists from (warning, every file found is assumed to be a hosts-file or domain list)
sourcedirs = ["sources"]
# log configuration
# format: comma separated list of options, where options is one of
# file:<filename>@<loglevel>
Expand All @@ -112,25 +103,12 @@ bind = "0.0.0.0:53"
# address to bind to for the API server
api = "127.0.0.1:8080"
# response to blocked queries with a NXDOMAIN
nxdomain = false
# ipv4 address to forward blocked queries to
nullroute = "0.0.0.0"
# ipv6 address to forward blocked queries to
nullroutev6 = "0:0:0:0:0:0:0:0"
# concurrency interval for lookups in milliseconds
interval = 200
# question cache capacity, 0 for infinite but not recommended (this is used for storing logs)
questioncachecap = 5000
# manual blocklist entries
blocklist = []
# manual whitelist entries - comments for reference
whitelist = [
# "getsentry.com",
Expand All @@ -149,6 +127,28 @@ customdnsrecords = [
# see https://github.com/Cottand/leng/wiki/CNAME%E2%80%90following-DNS
followCnameDepth = 12
[Blocking]
# response to blocked queries with a NXDOMAIN
nxdomain = false
# ipv4 address to forward blocked queries to
nullroute = "0.0.0.0"
# ipv6 address to forward blocked queries to
nullroutev6 = "0:0:0:0:0:0:0:0"
# manual blocklist entries
blocklist = []
# list of sources to pull blocklists from, stores them in ./sources
sources = [
"https://mirror1.malwaredomains.com/files/justdomains",
"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts",
"https://sysctl.org/cameleon/hosts",
"https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt",
"https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt",
"https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt"
]
# list of locations to recursively read blocklists from (warning, every file found is assumed to be a hosts-file or domain list)
sourcedirs = ["sources"]
[Upstream]
# Dns over HTTPS provider to use.
DoH = "https://cloudflare-dns.com/dns-query"
Expand Down
4 changes: 2 additions & 2 deletions grimd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func integrationTest(changeConfig func(c *Config), test func(client *dns.Client,

// BlockCache contains all blocked domains
blockCache := &MemoryBlockCache{Backend: make(map[string]bool)}
for _, blocked := range config.Blocklist {
for _, blocked := range config.Blocking.Blocklist {
_ = blockCache.Set(blocked, true)
}
// QuestionCache contains all queries to the dns server
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestCnameFollowWithBlocked(t *testing.T) {
"first.com IN CNAME second.com ",
"second.com IN CNAME example.com ",
}
c.Blocklist = []string{"example.com"}
c.Blocking.Blocklist = []string{"example.com"}

},
func(client *dns.Client, target string) {
Expand Down
6 changes: 3 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ func (h *EventLoop) responseFor(Net string, req *dns.Msg, _local net.Addr, _remo
m := new(dns.Msg)
m.SetReply(req)

if h.config.NXDomain {
if h.config.Blocking.NXDomain {
m.SetRcode(req, dns.RcodeNameError)
} else {
nullroute := net.ParseIP(h.config.Nullroute)
nullroutev6 := net.ParseIP(h.config.Nullroutev6)
nullroute := net.ParseIP(h.config.Blocking.Nullroute)
nullroutev6 := net.ParseIP(h.config.Blocking.Nullroutev6)

switch IPQuery {
case _IP4Query:
Expand Down
4 changes: 2 additions & 2 deletions updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ func parseHostFile(fileName string, blockCache *MemoryBlockCache) error {
func PerformUpdate(config *Config, forceUpdate bool) *MemoryBlockCache {
newBlockCache := &MemoryBlockCache{Backend: make(map[string]bool), Special: make(map[string]*regexp.Regexp)}
if _, err := os.Stat("lists"); os.IsNotExist(err) || forceUpdate {
if err := update(newBlockCache, config.Whitelist, config.Blocklist, config.Sources); err != nil {
if err := update(newBlockCache, config.Blocking.Whitelist, config.Blocking.Blocklist, config.Blocking.Sources); err != nil {
logger.Fatal(err)
}
}
if err := updateBlockCache(newBlockCache, config.SourceDirs); err != nil {
if err := updateBlockCache(newBlockCache, config.Blocking.SourceDirs); err != nil {
logger.Fatal(err)
}

Expand Down

0 comments on commit a31fbd0

Please sign in to comment.