handleDNSRequest processes the context. The only error it returns is the one from the [Handler].
(ctx context.Context, d *DNSContext)
| 77 | // handleDNSRequest processes the context. The only error it returns is the one |
| 78 | // from the [Handler]. |
| 79 | func (p *Proxy) handleDNSRequest(ctx context.Context, d *DNSContext) (err error) { |
| 80 | p.logDNSMessage(ctx, d.Req) |
| 81 | |
| 82 | if d.Req.Response { |
| 83 | p.logger.DebugContext(ctx, "dropping incoming response packet", "addr", d.Addr) |
| 84 | |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | ip := d.Addr.Addr() |
| 89 | d.IsPrivateClient = p.privateNets.Contains(ip) |
| 90 | |
| 91 | // TODO(d.kolyshev): Consider moving validation to a new middleware. |
| 92 | d.Res = p.validateRequest(d) |
| 93 | if d.Res == nil { |
| 94 | err = p.requestHandler.ServeDNS(ctx, p, d) |
| 95 | if errors.Is(err, ErrDrop) { |
| 96 | // Don't reply to dropped clients. |
| 97 | return nil |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | p.logDNSMessage(ctx, d.Res) |
| 102 | p.respond(ctx, d) |
| 103 | |
| 104 | return err |
| 105 | } |
| 106 | |
| 107 | // isForbiddenARPA returns true if dctx contains a PTR, SOA, or NS request for |
| 108 | // some private address and client's address is not within the private network. |