Skip to content

Commit

Permalink
fix: Use remote IP if EDNS subnet is not present
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmi Dyson <[email protected]>
  • Loading branch information
jimmidyson committed Oct 28, 2023
1 parent 659b497 commit acae460
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions service/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ func (gw *Gateway) ServeDNS(_ context.Context, w dns.ResponseWriter, r *dns.Msg)
qname := state.QName()
zone := plugin.Zones(gw.opts.zones).Matches(qname)
clientIP = netutils.ExtractEdnsSubnet(r)
if clientIP == nil {
ip, _, err := net.SplitHostPort(w.RemoteAddr().String())
if err != nil {
clientIP = net.ParseIP(w.RemoteAddr().String())
} else {
clientIP = net.ParseIP(ip)
}
}
log.Debugf("Using source address %v", clientIP)

if zone == "" {
log.Infof("Request %s has not matched any zones %v", qname, gw.opts.zones)
Expand Down

0 comments on commit acae460

Please sign in to comment.