Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Configuration:
* **`fallback_addresses`** (_list_)
* (_string_) addresses to use instead of group addresses if group is empty
* **`compress`** (_boolean_) compress DNS response message
* **`non_authoritative`** (_boolean_) if true, do not set AA bit for DNS response messages

#### `command`

Expand Down
40 changes: 23 additions & 17 deletions output/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@ type DNSMapping struct {
}

type DNSServerConfig struct {
BindAddress string `yaml:"bind_address"`
Mappings map[string]DNSMapping
Compress bool
BindAddress string `yaml:"bind_address"`
Mappings map[string]DNSMapping
Compress bool
NonAuthoritative bool `yaml:"non_authoritative"`
}

type DNSServer struct {
bridge iface.GroupBridge
bindAddress string
mappings map[string]DNSMapping
compress bool
tcpServer *dns.Server
udpServer *dns.Server
tcpDone chan struct{}
udpDone chan struct{}
rand *rand.Rand
bridge iface.GroupBridge
bindAddress string
mappings map[string]DNSMapping
compress bool
authoritative bool
tcpServer *dns.Server
udpServer *dns.Server
tcpDone chan struct{}
udpDone chan struct{}
rand *rand.Rand
}

func NewDNSServer(cfg *config.OutputConfig, bridge iface.GroupBridge) (*DNSServer, error) {
Expand All @@ -48,11 +50,12 @@ func NewDNSServer(cfg *config.OutputConfig, bridge iface.GroupBridge) (*DNSServe
mappings[name] = mapping
}
return &DNSServer{
bridge: bridge,
bindAddress: oc.BindAddress,
mappings: mappings,
compress: oc.Compress,
rand: rand.New(),
bridge: bridge,
bindAddress: oc.BindAddress,
mappings: mappings,
compress: oc.Compress,
authoritative: !oc.NonAuthoritative,
rand: rand.New(),
}, nil
}

Expand Down Expand Up @@ -112,13 +115,15 @@ func (o *DNSServer) Stop() error {
func (o *DNSServer) failDNSReq(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.Compress = o.compress
m.Authoritative = o.authoritative
m.SetRcode(r, dns.RcodeServerFailure)
w.WriteMsg(m)
}

func (o *DNSServer) serveEmptyResponse(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.Compress = o.compress
m.Authoritative = o.authoritative
m.SetReply(r)
w.WriteMsg(m)
}
Expand Down Expand Up @@ -160,6 +165,7 @@ func (o *DNSServer) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {

m := new(dns.Msg)
m.Compress = o.compress
m.Authoritative = o.authoritative

items := o.bridge.ListGroup(mapping.Group)
if len(items) == 0 {
Expand Down