Skip to content

Commit

Permalink
Merge branch 'master' into minimal
Browse files Browse the repository at this point in the history
  • Loading branch information
janeczku committed Jun 6, 2016
1 parent cb18b79 commit 281b073
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ DNS queries are resolved in the style of the GNU libc resolver:
| --listen, -l | Address to listen on `host[:port]` | 127.0.0.1:53 | $DNSMASQ_LISTEN |
| --default-resolver, -d | Update resolv.conf to make go-dnsmasq the host's nameserver | False | $DNSMASQ_DEFAULT |
| --nameservers, -n | Comma delimited list of nameservers `host[:port]`. IPv6 literal address must be enclosed in brackets. (supersedes etc/resolv.conf) | - | $DNSMASQ_SERVERS |
| --stubzones, -z | Use a different nameserver for specified domains. Can be passed multiple times. `domain[,domain]/host[:port]` | - |$DNSMASQ_STUB |
| --stubzones, -z | Use different nameservers for given domains. Can be passed multiple times. `domain[,domain]/host[:port][,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 |
| --search-domains, -s | Comma delimited list of search domains `domain[,domain]` (supersedes /etc/resolv.conf) | - | $DNSMASQ_SEARCH_DOMAINS |
Expand Down
53 changes: 27 additions & 26 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,41 +52,41 @@ func main() {
cli.StringFlag{
Name: "listen, l",
Value: "127.0.0.1:53",
Usage: "Address to listen on `host[:port]`",
Usage: "Listen on this `address` <host[:port]>",
EnvVar: "DNSMASQ_LISTEN",
},
cli.BoolFlag{
Name: "default-resolver, d",
Usage: "Update resolv.conf to make the host use go-dnsmasq as nameserver",
Usage: "Update /etc/resolv.conf with the address of go-dnsmasq as nameserver",
EnvVar: "DNSMASQ_DEFAULT",
},
cli.StringFlag{
Name: "nameservers, n",
Value: "",
Usage: "Comma delimited list of nameservers `host[:port]` (supersedes resolv.conf)",
Usage: "Comma delimited list of `nameservers` <host[:port][,host[:port]]> (supersedes resolv.conf)",
EnvVar: "DNSMASQ_SERVERS",
},
cli.StringSliceFlag{
Name: "stubzones, z",
Usage: "Use a different nameserver for specified domains `domain[,domain]/host[:port]`",
Usage: "Use different nameservers for given domains <domain[,domain]/host[:port][,host[:port]]>",
EnvVar: "DNSMASQ_STUB",
},
cli.StringFlag{
Name: "hostsfile, f",
Value: "",
Usage: "Path to a hosts file (e.g. /etc/hosts)",
Usage: "Path to a hosts `file` (e.g. /etc/hosts)",
EnvVar: "DNSMASQ_HOSTSFILE",
},
cli.IntFlag{
Name: "hostsfile-poll, p",
Value: 0,
Usage: "How frequently to poll hosts file for changes (seconds, ‘0‘ to disable)",
Usage: "How frequently to poll hosts file (`seconds`, '0' to disable)",
EnvVar: "DNSMASQ_POLL",
},
cli.StringFlag{
Name: "search-domains, s",
Value: "",
Usage: "List of search domains `domain[,domain]` (supersedes resolv.conf)",
Usage: "List of search domains <domain[,domain]> (supersedes resolv.conf)",
EnvVar: "DNSMASQ_SEARCH_DOMAINS,DNSMASQ_SEARCH,", // deprecated DNSMASQ_SEARCH
},
cli.BoolFlag{ // deprecated
Expand All @@ -108,13 +108,13 @@ func main() {
cli.IntFlag{
Name: "fwd-ndots",
Value: 0,
Usage: "Number of dots a name must have before the query is forwarded",
Usage: "Number of `dots` a name must have before the query is forwarded",
EnvVar: "DNSMASQ_FWD_NDOTS",
},
cli.IntFlag{
Name: "ndots",
Value: 1,
Usage: "Number of dots a name must have before making an initial absolute query (supersedes resolv.conf)",
Usage: "Number of `dots` a name must have before doing an initial absolute query (supersedes resolv.conf)",
EnvVar: "DNSMASQ_NDOTS",
},
cli.BoolFlag{
Expand Down Expand Up @@ -248,28 +248,29 @@ func main() {
log.Fatalf("The --stubzones argument is invalid")
}

hostPort = segments[1]
hostPort = strings.TrimSpace(hostPort)
if strings.HasSuffix(hostPort, "]") {
hostPort += ":53"
} else if !strings.Contains(hostPort, ":") {
hostPort += ":53"
}
hosts := strings.Split(segments[1], ",")
for _, hostPort := range hosts {
hostPort = strings.TrimSpace(hostPort)
if strings.HasSuffix(hostPort, "]") {
hostPort += ":53"
} else if !strings.Contains(hostPort, ":") {
hostPort += ":53"
}

if err := validateHostPort(hostPort); err != nil {
log.Fatalf("This stubzones server address invalid: %s", err)
}
if err := validateHostPort(hostPort); err != nil {
log.Fatalf("This stubzones server address invalid: %s", err)
}

for _, sdomain := range strings.Split(segments[0], ",") {
if dns.CountLabel(sdomain) < 1 {
log.Fatalf("This stubzones domain is not a FQDN: %s", sdomain)
for _, sdomain := range strings.Split(segments[0], ",") {
if dns.CountLabel(sdomain) < 1 {
log.Fatalf("This stubzones domain is not a FQDN: %s", sdomain)
}
sdomain = strings.TrimSpace(sdomain)
sdomain = dns.Fqdn(sdomain)
stubmap[sdomain] = append(stubmap[sdomain], hostPort)
}
sdomain = strings.TrimSpace(sdomain)
sdomain = dns.Fqdn(sdomain)
stubmap[sdomain] = append(stubmap[sdomain], hostPort)
}
}

config.Stub = &stubmap
}

Expand Down

0 comments on commit 281b073

Please sign in to comment.