Closed tarko closed 2 years ago
thanks to report that, the error is generated because of the following check:
// RFC 6891 says "When an OPT RR is included within any DNS message, it MUST be the
// only OPT RR in that message."
if ednsFound {
return edns, offset, ErrDecodeEdnsTooManyOpts
}
I will check why the log-malformed
is not properly take in account in this case.
issue fixed in the new beta release v0.18.0-b3 available
New release v0.18.0 available :)
Thanks, works fine. I'm still puzzled by the multiple OPT RR issue as if you dump the logged DNS packet then there is just single OPT RR present there (as expected).
There is indeed a bug in EDNS parsing which causes EDNS parsing to return invalid error about multiple OPT RR's being present.
I'll add PR fixing this shortly.
Nice, looking at the patch is seems fairly obvious. I was actually testing this with the problematic payload from the log but was unable to trigger this, something like this:
func TestDecodeEdns_MultipleOpts2(t *testing.T) {
payload := []byte{
0x7B, 0x97, 0x84, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x05, 0x0F, 0x6F, 0x63, 0x63, 0x2D, 0x30, 0x2D, 0x31, 0x35, 0x30, 0x30, 0x2D, 0x31, 0x35, 0x30, 0x31, 0x01, 0x31, 0x06, 0x6E, 0x66, 0x6C, 0x78, 0x73, 0x6F, 0x03, 0x6E, 0x65, 0x74, 0x00, 0x00, 0x01, 0x00, 0x01, 0xC0, 0x0C, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x04, 0x2D, 0x39, 0x24, 0x97, 0xC0, 0x0C, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x04, 0x2D, 0x39, 0x24, 0x94, 0xC0, 0x1E, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00, 0x07, 0x01, 0x65, 0x02, 0x6E, 0x73, 0xC0, 0x1E, 0xC0, 0x1E, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00, 0x04, 0x01, 0x66, 0xC0, 0x5C, 0x00, 0x00, 0x29, 0x04, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x5A, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00, 0x04, 0x2D, 0x39, 0x08, 0x01, 0xC0, 0x5A, 0x00, 0x1C, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00, 0x10, 0x2A, 0x00, 0x86, 0xC0, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC0, 0x6D, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00, 0x04, 0x2D, 0x39, 0x09, 0x01, 0xC0, 0x6D, 0x00, 0x1C, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00, 0x10, 0x2A, 0x00, 0x86, 0xC0, 0x20, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
}
_, _, offsset_rr, err := DecodeQuestion(1, payload)
if err != nil {
t.Errorf("Unable to decode question: %v", err)
}
_, _, erra := DecodeAnswer(1, offsset_rr, payload)
if erra != nil {
t.Errorf("Unable to decode question: %v", erra)
}
_, _, erre := DecodeEDNS(2, offsset_rr, payload)
if erre != nil {
t.Errorf("bad error received: %v", erre)
}
}
The test data you were using contained 2 Answers, 2 Authority Records and 5 Additional RR's (one of which was the EDNS OPT RR), thus the test code did not give DecodeEDNS()
the right offset_rr
as parameter (and invalid record count) and due to this failed the trigger the bug.
To ensure right amount of records are parsed, you could do
dm := dnsutils.DnsMessage{}
dm.DNS.Payload = payload
dm.DNS.Length = len(payload)
header, err := dnsutils.DecodeDns(payload)
if err != nil {
t.Errorf("error when deocoding header: %v", err)
}
if err := decodePayload(&dm, &header, dnsutils.GetFakeConfig()); err != nil {
t.Errorf("unexpected error while decoding payload: %v", err)
}
this would mimic the actual parsing of the data and hit the bug.
Yeah, as said, now that the fix is there it seems pretty obvious :)
Binaries v0.19.0 released!
hey,
EDNS decoder seems to be bit optimistic about the OPT RRs, go-dns-collector produces a lot of log like this:
Mostly originated by certain auth NSes:
It would probably also make sense to handle this as malformed packet. Currently, with
log-malformed
andverbose
set to false, those errors are still logged.