Skip to content

Commit

Permalink
Make ndots settable
Browse files Browse the repository at this point in the history
By default queries with single-label names are not forwarded to
upstream servers. In some environments this may not be the desired
behavior. For example if the upstream server is not a public DNS
resolver but an internal DNS server used for service discovery.
  • Loading branch information
Jan Broer committed Mar 24, 2016
1 parent 5441ad1 commit 4d2d720
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ DNS queries are resolved in the style of the GNU libc resolver:
| --default-resolver, -d | Update resolv.conf to make go-dnsmasq the host's nameserver | False | $DNSMASQ_DEFAULT |
| --nameservers, -n | Comma separated list of nameservers `host[:port]` | - | $DNSMASQ_SERVERS |
| --stubzones, -z | Use different nameservers for specific domains `domain[,domain]/host[:port]` | - | $DNSMASQ_STUB |
| --hostsfile, -f | Path to a hosts file (e.g. ‘/etc/hosts‘) | - | $DNSMASQ_HOSTSFILE |
| --hostsfile-poll, -p | How frequently to poll hosts file for changes (seconds, ‘0‘ to disable) | 0 | $DNSMASQ_POLL |
| --hostsfile, -f | Path to a hosts file (e.g. ‘/etc/hosts‘) | - | $DNSMASQ_HOSTSFILE |
| --hostsfile-poll, -p | How frequently to poll hosts file for changes (seconds, ‘0‘ to disable) | 0 | $DNSMASQ_POLL |
| --search-domains, -s | Specify search domains (overrides /etc/resolv.conf) `domain[,domain]` | - | $DNSMASQ_SEARCH |
| --append-search-domains, -a | Resolve queries using search domains | False | $DNSMASQ_APPEND |
| --rcache, -r | Capacity of the response cache (‘0‘ to disable cache) | 0 | $DNSMASQ_RCACHE |
| --rcache-ttl | TTL for entries in the response cache | 60 | $DNSMASQ_RCACHE_TTL |
| --no-rec | Disable recursion | False | $DNSMASQ_NOREC |
| --ndots | Minimum number of labels a name must have before the query is forwarded | 2 | $DNSMASQ_NDOTS |
| --round-robin | Enable round robin of A/AAAA records | False | $DNSMASQ_RR |
| --systemd | Bind to socket(s) activated by Systemd (ignores --listen) | False | $DNSMASQ_SYSTEMD |
| --verbose | Enable verbose logging | False | $DNSMASQ_VERBOSE |
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// var Version string
const Version = "1.0.2"
const Version = "1.0.3"

var (
nameservers = []string{}
Expand Down Expand Up @@ -100,6 +100,12 @@ func main() {
Usage: "Disable recursion",
EnvVar: "DNSMASQ_NOREC",
},
cli.IntFlag{
Name: "ndots",
Value: 2,
Usage: "Minimum number of labels a name must have before the query is forwarded",
EnvVar: "DNSMASQ_NDOTS",
},
cli.BoolFlag{
Name: "round-robin",
Usage: "Enable round robin of A/AAAA records",
Expand Down Expand Up @@ -194,6 +200,7 @@ func main() {
PollInterval: c.Int("hostsfile-poll"),
RoundRobin: c.Bool("round-robin"),
NoRec: c.Bool("no-rec"),
Ndots: c.Int("ndots"),
ReadTimeout: 0,
Verbose: c.Bool("verbose"),
}
Expand Down
3 changes: 1 addition & 2 deletions server/forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func (s *server) ServeDNSForward(w dns.ResponseWriter, req *dns.Msg) *dns.Msg {
}

Redo:
if dns.CountLabel(name) < 2 {
// Always qualify single-label names
if dns.CountLabel(name) < s.config.Ndots {
if !doingSearch && canSearch {
doingSearch = true
sdIndex = 0
Expand Down

0 comments on commit 4d2d720

Please sign in to comment.