4 Commits

Author SHA1 Message Date
afdea7e64f up block TTL 2021-02-25 13:25:19 +01:00
4394d6078d changed regex for parsing host format 2021-02-25 13:24:57 +01:00
ebce605863 dont handle missing rr with nxdomain 2021-02-24 14:09:28 +01:00
7255fc02c8 Revert "added debug messages"
This reverts commit 00a82aca87.
2021-02-24 13:50:13 +01:00
4 changed files with 12 additions and 55 deletions

View File

@@ -121,10 +121,16 @@ func handleRequest(w dns.ResponseWriter, r *dns.Msg, zone zoneView) {
} }
if len(m.Answer) == 0 { if len(m.Answer) == 0 {
m.SetRcode(m, dns.RcodeNameError) var soa dns.RR
for _, v := range zone.rr[dns.TypeSOA] {
if len(v) == 1 {
soa = v[0]
}
}
if soa != nil {
m.Extra = append(m.Extra, soa)
}
} }
debugResponse(m)
w.WriteMsg(m) w.WriteMsg(m)
} }

View File

@@ -12,7 +12,7 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
) )
const blockTTL uint32 = 300 const blockTTL uint32 = 604800
var nullIPv4 = net.IPv4(0, 0, 0, 0) var nullIPv4 = net.IPv4(0, 0, 0, 0)
var nullIPv6 = net.ParseIP("::/0") var nullIPv6 = net.ParseIP("::/0")
@@ -86,12 +86,10 @@ func parseRawBlacklist(blacklist configBlacklist, raw string) []string {
// parseHostFormat parse the string in the format of a hostfile // parseHostFormat parse the string in the format of a hostfile
func parseHostFormat(raw string) []string { func parseHostFormat(raw string) []string {
finalList := make([]string, 0) finalList := make([]string, 0)
reg := regexp.MustCompile(`(?mi)^\s*(#*)\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-zA-Z0-9\.\- ]+)$`) reg := regexp.MustCompile(`(?m)^\s*(0\.0\.0\.0) ([a-zA-Z0-9-.]*)`)
matches := reg.FindAllStringSubmatch(raw, -1) matches := reg.FindAllStringSubmatch(raw, -1)
for _, match := range matches { for _, match := range matches {
if match[1] != "#" { finalList = append(finalList, dns.Fqdn(match[2]))
finalList = append(finalList, dns.Fqdn(match[3]))
}
} }
return finalList return finalList

View File

@@ -18,13 +18,6 @@ type zoneMap map[string][]zoneView
// Start starts cooldns // Start starts cooldns
func Start(configPath string) { func Start(configPath string) {
debug := os.Getenv("COOLDNS_DEBUG")
if len(debug) != 0 {
debugFlag = true
debugLog("Enabled debug")
}
config, err := loadConfig(configPath) config, err := loadConfig(configPath)
if err != nil { if err != nil {
log.Fatalf("Failed to load config: %s\n", err.Error()) log.Fatalf("Failed to load config: %s\n", err.Error())
@@ -87,8 +80,6 @@ func createServer(zones zoneMap, config config, aclList map[string]*net.IPNet, b
return return
} }
debugRequest(r, ip)
// Check if it is a ACME DNS-01 challange // Check if it is a ACME DNS-01 challange
if config.Lego.Enable && handleACMERequest(w, r, acmeList) { if config.Lego.Enable && handleACMERequest(w, r, acmeList) {
return return
@@ -105,7 +96,6 @@ func createServer(zones zoneMap, config config, aclList map[string]*net.IPNet, b
handleBlockedDomain(w, r) handleBlockedDomain(w, r)
} else { } else {
// Forward request // Forward request
debugLog("Forwarded request")
in, _, err := c.Exchange(r, config.Forward.Server) in, _, err := c.Exchange(r, config.Forward.Server)
if err != nil { if err != nil {
@@ -177,8 +167,6 @@ func createHandler(zones []zoneView, config config, aclList map[string]*net.IPNe
return return
} }
debugRequest(r, ip)
// Check if it is a ACME DNS-01 challange // Check if it is a ACME DNS-01 challange
if config.Lego.Enable && handleACMERequest(w, r, acmeList) { if config.Lego.Enable && handleACMERequest(w, r, acmeList) {
return return

View File

@@ -1,35 +0,0 @@
package cooldns
import (
"fmt"
"log"
"net"
"github.com/miekg/dns"
)
var debugFlag = false
func debugLog(msg string) {
if !debugFlag {
return
}
log.Printf("DEBUG: %s", msg)
}
func debugRequest(r *dns.Msg, ip net.IP) {
if !debugFlag {
return
}
debugLog(fmt.Sprintf("Request from %s: %s", ip, r.String()))
}
func debugResponse(m *dns.Msg) {
if !debugFlag {
return
}
debugLog(fmt.Sprintf("Response send: %s", m.String()))
}