dns: send nil response instead of dropping it when dnsnoaaaa is enabled

This commit is contained in:
nadoo committed 2022-01-22 13:13:20 +08:00
1 parent 2754fdeb60
commit a919ac3469
4 files changed
+16 -12

No files matched your search

+4 -3
View File
@@ -67,7 +67,8 @@ func (c *Client) Exchange(reqBytes []byte, clientAddr string, preferTCP bool) ([
}
if c.config.NoAAAA && req.Question.QTYPE == QTypeAAAA {
return nil, errors.New("AAAA query is disabled, qname: " + req.Question.QNAME)
reqBytes[2] |= uint8(Response) << 7
return reqBytes, nil
}
if req.Question.QTYPE == QTypeA || req.Question.QTYPE == QTypeAAAA {
@@ -283,7 +284,7 @@ func (c *Client) AddHandler(h AnswerHandler) {
func (c *Client) AddRecord(record string) error {
r := strings.Split(record, "/")
domain, ip := r[0], r[1]
m, err := c.MakeResponse(domain, ip, uint32(c.config.MaxTTL))
m, err := MakeResponse(domain, ip, uint32(c.config.MaxTTL))
if err != nil {
return err
}
@@ -303,7 +304,7 @@ func (c *Client) AddRecord(record string) error {
// MakeResponse makes a dns response message for the given domain and ip address.
// Note: you should make sure ttl > 0.
func (c *Client) MakeResponse(domain, ip string, ttl uint32) (*Message, error) {
func MakeResponse(domain, ip string, ttl uint32) (*Message, error) {
ipb := net.ParseIP(ip)
if ipb == nil {
return nil, errors.New("MakeResponse: invalid ip format")
+2 -2
View File
@@ -80,13 +80,13 @@ func (s *Server) ServePacket(pc net.PacketConn, caddr net.Addr, reqBytes []byte)
}()
if err != nil {
log.F("[dns] error in exchange: %s", err)
log.F("[dns] error in exchange for %s: %s", caddr, err)
return
}
_, err = pc.WriteTo(respBytes, caddr)
if err != nil {
log.F("[dns] error in local write: %s", err)
log.F("[dns] error in local write to %s: %s", caddr, err)
return
}
}