Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions dnscrypt-proxy/example-forwarding-rules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
## The following keywords can also be used instead of a server address:
## $BOOTSTRAP to use the default bootstrap resolvers
## $DHCP to use the default DNS resolvers provided by the DHCP server
## $RESOLVCONF:<file> to use the resolvers specified in <file> (with
## resolv.conf syntax); name of <file> mustn't contain any commas (,)

## In order to enable this feature, the "forwarding_rules" property needs to
## be set to this file name inside the main configuration file.
Expand All @@ -27,10 +29,14 @@
## Forward *.local to the resolvers provided by the DHCP server
# local $DHCP

## Forward *.localnet to the resolvers specified in '/etc/resolv.conf'
# localnet $RESOLVCONF:/etc/resolv.conf

## Forward *.internal to 192.168.1.1, and if it doesn't work, to the
## DNS from the local DHCP server, and if it still doesn't work, to the
## bootstrap resolvers
# internal 192.168.1.1,$DHCP,$BOOTSTRAP
## DNS from the local DHCP server, and if it that doesn't work, to the
## bootstrap resolvers, and if it still doesn't work, to the resolvers
## specified in '/etc/resolv.conf'
# internal 192.168.1.1,$DHCP,$BOOTSTRAP,$RESOLVCONF:/etc/resolv.conf

## Forward queries for example.com and *.example.com to 9.9.9.9 and 8.8.8.8
# example.com 9.9.9.9,8.8.8.8
Expand Down
35 changes: 33 additions & 2 deletions dnscrypt-proxy/plugin_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"fmt"
"math/rand"
"net"
"path"
"strings"
"sync"

"codeberg.org/miekg/dns"
"codeberg.org/miekg/dns/dnsconf"
"github.com/jedisct1/dlog"
"github.com/lifenjoiner/dhcpdns"
)
Expand All @@ -20,11 +22,13 @@ const (
Explicit SearchSequenceItemType = iota
Bootstrap
DHCP
Resolvconf
)

type SearchSequenceItem struct {
typ SearchSequenceItemType
servers []string
typ SearchSequenceItemType
servers []string
resolvconf string
}

type PluginForwardEntry struct {
Expand Down Expand Up @@ -140,6 +144,17 @@ func (plugin *PluginForward) parseForwardFile(lines string) (bool, []PluginForwa
}
requiresDHCP = true
default:
const resolvconfPrexix = "$RESOLVCONF:"
if strings.HasPrefix(server, resolvconfPrexix) {
file := server[len(resolvconfPrexix):]
if len(file) == 0 {
dlog.Criticalf("File needs to be specified for $RESOLVCONF in line %d", 1+lineNo)
continue
}
sequence = append(sequence, SearchSequenceItem{typ: Resolvconf, resolvconf: path.Clean(file)})
dlog.Infof("Forwarding [%s] to the servers specified in '%s'", domain, file)
continue
}
if strings.HasPrefix(server, "$") {
dlog.Criticalf("Unknown keyword [%s] at line %d", server, 1+lineNo)
continue
Expand Down Expand Up @@ -295,6 +310,22 @@ func (plugin *PluginForward) Eval(pluginsState *PluginsState, msg *dns.Msg) erro
dlog.Infof("DHCP didn't provide any DNS server to forward [%s]", qName)
continue
}
case Resolvconf:
resolvconf, err := dnsconf.FromFile(item.resolvconf)
if err != nil {
dlog.Warnf("Failed to open '%s' while resolving [%s]: %v", item.resolvconf, qName, err)
continue
}
if len(resolvconf.Servers) == 0 {
dlog.Warnf("No nameservers specificied in '%s' while resolving [%s]", item.resolvconf, qName)
continue
}
server = resolvconf.Servers[rand.Intn(len(resolvconf.Servers))]
server, err = normalizeIPAndOptionalPort(server, "53")
if err != nil {
dlog.Warnf("Syntax error in address '%s' while resolving [%s]: %v", item.resolvconf, qName, err)
continue
}
}
pluginsState.serverName = server
if len(server) == 0 {
Expand Down
139 changes: 139 additions & 0 deletions vendor/codeberg.org/miekg/dns/dnsconf/clientconfig.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions vendor/codeberg.org/miekg/dns/dnsutil/common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions vendor/codeberg.org/miekg/dns/dnsutil/compat.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions vendor/codeberg.org/miekg/dns/dnsutil/dnsutil.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/codeberg.org/miekg/dns/dnsutil/labels.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading