fix(quic): Make DNS-over-QUIC work again
Some checks failed
Test / test (oldstable) (push) Failing after 57s
Test / test (stable) (push) Failing after 56s

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2024-10-15 16:25:39 +02:00
parent 08aed401c1
commit fe372324e3
Signed by: sam
GPG key ID: 4D8B07C18F31ACBD
3 changed files with 15 additions and 18 deletions

View file

@ -96,7 +96,7 @@ func TestCreateQ(t *testing.T) {
QUIC: true,
Request: util.Request{
Server: "dns.froth.zone",
Server: "zero.dns0.eu",
Port: 853,
Type: dns.TypeA,
Name: "example.com.",

View file

@ -5,6 +5,7 @@ package resolvers
import (
"context"
"crypto/tls"
"encoding/binary"
"fmt"
"io"
"strings"
@ -52,6 +53,7 @@ func (resolver *QUICResolver) LookUp(msg *dns.Msg) (resp util.Response, err erro
resolver.opts.Logger.Debug("quic: packing query")
msg.Id = 0
// Compress request to over-the-wire
buf, err := msg.Pack()
if err != nil {
@ -69,7 +71,7 @@ func (resolver *QUICResolver) LookUp(msg *dns.Msg) (resp util.Response, err erro
resolver.opts.Logger.Debug("quic: writing to stream")
_, err = stream.Write(buf)
_, err = stream.Write(rfc9250prefix(buf))
if err != nil {
return resp, fmt.Errorf("doq: quic stream write: %w", err)
}
@ -101,10 +103,19 @@ func (resolver *QUICResolver) LookUp(msg *dns.Msg) (resp util.Response, err erro
resolver.opts.Logger.Debug("quic: unpacking response")
err = resp.DNS.Unpack(fullRes)
// Unpack response and lop off the first two bytes (RFC 9250 moment)
err = resp.DNS.Unpack(fullRes[2:])
if err != nil {
return resp, fmt.Errorf("doq: unpack: %w", err)
}
return
}
// rfc9250prefix adds a two-byte prefix to the input data as per RFC 9250.
func rfc9250prefix(in []byte) []byte {
out := make([]byte, 2+len(in))
binary.BigEndian.PutUint16(out, uint16(len(in)))
copy(out[2:], in)
return out
}

View file

@ -35,21 +35,6 @@ func TestQuic(t *testing.T) {
},
},
},
{
"Valid, Froth",
&util.Options{
QUIC: true,
Logger: util.InitLogger(0),
Request: util.Request{
Server: "dns.froth.zone",
Type: dns.TypeA,
Name: "git.freecumextremist.com",
Port: 853,
Timeout: 750 * time.Millisecond,
Retries: 3,
},
},
},
{
"Bad domain",
&util.Options{
@ -107,6 +92,7 @@ func TestQuic(t *testing.T) {
res util.Response
err error
)
for i := 0; i <= test.opts.Request.Retries; i++ {
res, err = query.CreateQuery(test.opts)
if err == nil {