mirror of
https://github.com/coredns/coredns.git
synced 2025-08-05 22:07:00 +02:00
* build(deps): bump github.com/miekg/dns from 1.1.66 to 1.1.67 Bumps [github.com/miekg/dns](https://github.com/miekg/dns) from 1.1.66 to 1.1.67. - [Changelog](https://github.com/miekg/dns/blob/master/Makefile.release) - [Commits](https://github.com/miekg/dns/compare/v1.1.66...v1.1.67) --- updated-dependencies: - dependency-name: github.com/miekg/dns dependency-version: 1.1.67 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Fix build failure Signed-off-by: Yong Tang <yong.tang.github@outlook.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Yong Tang <yong.tang.github@outlook.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Yong Tang <yong.tang.github@outlook.com>
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package dnsserver
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
"net"
|
|
|
|
"github.com/miekg/dns"
|
|
"github.com/quic-go/quic-go"
|
|
)
|
|
|
|
type DoQWriter struct {
|
|
localAddr net.Addr
|
|
remoteAddr net.Addr
|
|
stream *quic.Stream
|
|
Msg *dns.Msg
|
|
}
|
|
|
|
func (w *DoQWriter) Write(b []byte) (int, error) {
|
|
if w.stream == nil {
|
|
return 0, errors.New("stream is nil")
|
|
}
|
|
b = AddPrefix(b)
|
|
return w.stream.Write(b)
|
|
}
|
|
|
|
func (w *DoQWriter) WriteMsg(m *dns.Msg) error {
|
|
bytes, err := m.Pack()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = w.Write(bytes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return w.Close()
|
|
}
|
|
|
|
// Close sends the STREAM FIN signal.
|
|
// The server MUST send the response(s) on the same stream and MUST
|
|
// indicate, after the last response, through the STREAM FIN
|
|
// mechanism that no further data will be sent on that stream.
|
|
// See https://www.rfc-editor.org/rfc/rfc9250#section-4.2-7
|
|
func (w *DoQWriter) Close() error {
|
|
if w.stream == nil {
|
|
return errors.New("stream is nil")
|
|
}
|
|
return w.stream.Close()
|
|
}
|
|
|
|
// AddPrefix adds a 2-byte prefix with the DNS message length.
|
|
func AddPrefix(b []byte) (m []byte) {
|
|
m = make([]byte, 2+len(b))
|
|
binary.BigEndian.PutUint16(m, uint16(len(b)))
|
|
copy(m[2:], b)
|
|
|
|
return m
|
|
}
|
|
|
|
// These methods implement the dns.ResponseWriter interface from Go DNS.
|
|
func (w *DoQWriter) TsigStatus() error { return nil }
|
|
func (w *DoQWriter) TsigTimersOnly(b bool) {}
|
|
func (w *DoQWriter) Hijack() {}
|
|
func (w *DoQWriter) LocalAddr() net.Addr { return w.localAddr }
|
|
func (w *DoQWriter) RemoteAddr() net.Addr { return w.remoteAddr }
|
|
func (w *DoQWriter) Network() string { return "" }
|