Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
szolin committed Jun 22, 2020
1 parent 7c17992 commit 2fad354
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ type Server struct {
stats stats.Stats
access *accessCtx

tableReverse map[string]string // "IP -> hostname" table for reverse lookup
tablePTR map[string]string // "IP -> hostname" table for reverse lookup
tablePTRLock sync.Mutex

// DNS proxy instance for internal usage
// We don't Start() it and so no listen port is required.
Expand Down
15 changes: 11 additions & 4 deletions dnsforward/handle_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ func (s *Server) onDHCPLeaseChanged(flags int) {
m[l.IP.String()] = l.Hostname
}
log.Debug("DNS: added %d PTR entries from DHCP", len(m))
s.tableReverse = m
s.tablePTRLock.Lock()
s.tablePTR = m
s.tablePTRLock.Unlock()
}

// Respond to PTR requests if the target IP address is leased by our DHCP server
func processInternalIPAddrs(ctx *dnsContext) int {
s := ctx.srv
req := ctx.proxyCtx.Req
if req.Question[0].Qtype != dns.TypePTR ||
s.tableReverse == nil {
if req.Question[0].Qtype != dns.TypePTR {
return resultDone
}

Expand All @@ -131,7 +132,13 @@ func processInternalIPAddrs(ctx *dnsContext) int {
return resultDone
}

host, ok := s.tableReverse[ip.String()]
s.tablePTRLock.Lock()
if s.tablePTR == nil {
s.tablePTRLock.Unlock()
return resultDone
}
host, ok := s.tablePTR[ip.String()]
s.tablePTRLock.Unlock()
if !ok {
return resultDone
}
Expand Down

0 comments on commit 2fad354

Please sign in to comment.