From e203ad15909776aaef503186b118bcf4980c5260 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Sat, 4 Feb 2023 17:28:47 +0800 Subject: [PATCH] fix: CNAME ans should also be flipped --- component/control/dns.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/component/control/dns.go b/component/control/dns.go index a5859a7..9b10733 100644 --- a/component/control/dns.go +++ b/component/control/dns.go @@ -132,12 +132,18 @@ func (c *ControlPlane) DnsRespHandler(data []byte) (newData []byte, err error) { return nil, fmt.Errorf("unpack dns pkt: %w", err) } FlipDnsQuestionCase(&msg) - // Check healthy. + // Check healthy resp. if !msg.Response || msg.RCode != dnsmessage.RCodeSuccess || len(msg.Questions) == 0 { return data, nil } - // Check req type. q := msg.Questions[0] + // If first answer is CNAME type, replace the Name with flipping-backed Name. + if len(msg.Answers) > 0 && + msg.Answers[0].Header.Type == dnsmessage.TypeCNAME && + strings.EqualFold(msg.Answers[0].Header.Name.String(), q.Name.String()) { + msg.Answers[0].Header.Name.Data = q.Name.Data + } + // Check req type. switch q.Type { case dnsmessage.TypeA, dnsmessage.TypeAAAA: default: