| 1 | // DNS server implementation. |
| 2 | |
| 3 | package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ |
| 4 | |
| 5 | import ( |
| 6 | "contextscip-go gomod github.com/golang/go/src go1.25.0 context/" |
| 7 | "crypto/tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/" |
| 8 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/" |
| 9 | "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/" |
| 10 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 11 | "netscip-go gomod github.com/golang/go/src go1.25.0 net/" |
| 12 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 13 | "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/" |
| 14 | "timescip-go gomod github.com/golang/go/src go1.25.0 time/" |
| 15 | ) |
| 16 | |
| 17 | // Default maximum number of TCP queries before we close the socket. |
| 18 | const maxTCPQueriesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxTCPQueries. = 128 |
| 19 | |
| 20 | // aLongTimeAgo is a non-zero time, far in the past, used for |
| 21 | // immediate cancellation of network operations. |
| 22 | var aLongTimeAgoscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/aLongTimeAgo. = timescip-go gomod github.com/golang/go/src go1.25.0 time/.Unixscip-go gomod github.com/golang/go/src go1.25.0 time/Unix().(1, 0) |
| 23 | |
| 24 | // Handler is implemented by any value that implements ServeDNS. |
| 25 | type Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler# interface { |
| 26 | ServeDNSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#ServeDNS.(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, r *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 27 | } |
| 28 | |
| 29 | // The HandlerFunc type is an adapter to allow the use of |
| 30 | // ordinary functions as DNS handlers. If f is a function |
| 31 | // with the appropriate signature, HandlerFunc(f) is a |
| 32 | // Handler object that calls f. |
| 33 | type HandlerFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandlerFunc# func(ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 34 | |
| 35 | // ServeDNS calls f(w, r). |
| 36 | func (f HandlerFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandlerFunc#) ServeDNSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandlerFunc#ServeDNS().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, r *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 37 | f(w, r) |
| 38 | } |
| 39 | |
| 40 | // A ResponseWriter interface is used by an DNS handler to |
| 41 | // construct an DNS response. |
| 42 | type ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter# interface { |
| 43 | // LocalAddr returns the net.Addr of the server |
| 44 | LocalAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#LocalAddr.() netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr# |
| 45 | // RemoteAddr returns the net.Addr of the client that sent the current request. |
| 46 | RemoteAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#RemoteAddr.() netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr# |
| 47 | // WriteMsg writes a reply back to the client. |
| 48 | WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(*Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) error |
| 49 | // Write writes a raw buffer back to the client. |
| 50 | Writescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#Write.([]byte) (int, error) |
| 51 | // Close closes the connection. |
| 52 | Closescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#Close.() error |
| 53 | // TsigStatus returns the status of the Tsig. |
| 54 | TsigStatusscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#TsigStatus.() error |
| 55 | // TsigTimersOnly sets the tsig timers only boolean. |
| 56 | TsigTimersOnlyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#TsigTimersOnly.(bool) |
| 57 | // Hijack lets the caller take over the connection. |
| 58 | // After a call to Hijack(), the DNS package will not do anything with the connection. |
| 59 | Hijackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#Hijack.() |
| 60 | } |
| 61 | |
| 62 | // A ConnectionStater interface is used by a DNS Handler to access TLS connection state |
| 63 | // when available. |
| 64 | type ConnectionStaterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ConnectionStater# interface { |
| 65 | ConnectionStatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ConnectionStater#ConnectionState.() *tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.ConnectionStatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/ConnectionState# |
| 66 | } |
| 67 | |
| 68 | type responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response# struct { |
| 69 | closedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#closed. bool // connection has been closed |
| 70 | hijackedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#hijacked. bool // connection has been hijacked by handler |
| 71 | tsigTimersOnlyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigTimersOnly. bool |
| 72 | tsigStatusscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigStatus. error |
| 73 | tsigRequestMACscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigRequestMAC. string |
| 74 | tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigProvider. TsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TsigProvider# |
| 75 | udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp. netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn# // i/o connection if UDP was used |
| 76 | tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp. netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn# // i/o connection if TCP was used |
| 77 | udpSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udpSession. *SessionUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SessionUDP# // oob data to get egress interface right |
| 78 | pcSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#pcSession. netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr# // address to use when writing to a generic net.PacketConn |
| 79 | writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#writer. Writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Writer# // writer to output the raw DNS bits |
| 80 | } |
| 81 | |
| 82 | // handleRefused returns a HandlerFunc that returns REFUSED for every request it gets. |
| 83 | func handleRefusedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/handleRefused().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, r *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 84 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 85 | m.SetRcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetRcode().(r, RcodeRefusedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RcodeRefused.) |
| 86 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 87 | } |
| 88 | |
| 89 | // HandleFailed returns a HandlerFunc that returns SERVFAIL for every request it gets. |
| 90 | // Deprecated: This function is going away. |
| 91 | func HandleFailedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/HandleFailed().(w ResponseWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#, r *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) { |
| 92 | m := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 93 | m.SetRcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetRcode().(r, RcodeServerFailurescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RcodeServerFailure.) |
| 94 | // does not matter if this write fails |
| 95 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ResponseWriter#WriteMsg.(m) |
| 96 | } |
| 97 | |
| 98 | // ListenAndServe Starts a server on address and network specified Invoke handler |
| 99 | // for incoming queries. |
| 100 | func ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ListenAndServe().(addr string, network string, handler Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#) error { |
| 101 | server := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr.: addr, Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net.: network, Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Handler.: handler} |
| 102 | return server.ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ListenAndServe().() |
| 103 | } |
| 104 | |
| 105 | // ListenAndServeTLS acts like http.ListenAndServeTLS, more information in |
| 106 | // http://golang.org/pkg/net/http/#ListenAndServeTLS |
| 107 | func ListenAndServeTLSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ListenAndServeTLS().(addr, certFile, keyFile string, handler Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#) error { |
| 108 | cert, err := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.LoadX509KeyPairscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/LoadX509KeyPair().(certFile, keyFile) |
| 109 | if err != nil { |
| 110 | return err |
| 111 | } |
| 112 | |
| 113 | config := tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#{ |
| 114 | Certificatesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#Certificates.: []tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Certificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Certificate#{cert}, |
| 115 | } |
| 116 | |
| 117 | server := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{ |
| 118 | Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr.: addr, |
| 119 | Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net.: "tcp-tls", |
| 120 | TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TLSConfig.: &config, |
| 121 | Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Handler.: handler, |
| 122 | } |
| 123 | |
| 124 | return server.ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ListenAndServe().() |
| 125 | } |
| 126 | |
| 127 | // ActivateAndServe activates a server with a listener from systemd, |
| 128 | // l and p should not both be non-nil. |
| 129 | // If both l and p are not nil only p will be used. |
| 130 | // Invoke handler for incoming queries. |
| 131 | func ActivateAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ActivateAndServe().(l netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenerscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#, p netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#, handler Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#) error { |
| 132 | server := &Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#{Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener.: l, PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn.: p, Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Handler.: handler} |
| 133 | return server.ActivateAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ActivateAndServe().() |
| 134 | } |
| 135 | |
| 136 | // Writer writes raw DNS messages; each call to Write should send an entire message. |
| 137 | type Writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Writer# interface { |
| 138 | ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Writerscip-go gomod github.com/golang/go/src go1.25.0 io/Writer# |
| 139 | } |
| 140 | |
| 141 | // Reader reads raw DNS messages; each call to ReadTCP or ReadUDP should return an entire message. |
| 142 | type Readerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader# interface { |
| 143 | // ReadTCP reads a raw message from a TCP connection. Implementations may alter |
| 144 | // connection properties, for example the read-deadline. |
| 145 | ReadTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader#ReadTCP.(conn netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, error) |
| 146 | // ReadUDP reads a raw message from a UDP connection. Implementations may alter |
| 147 | // connection properties, for example the read-deadline. |
| 148 | ReadUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader#ReadUDP.(conn *netscip-go gomod github.com/golang/go/src go1.25.0 net/.UDPConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, *SessionUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SessionUDP#, error) |
| 149 | } |
| 150 | |
| 151 | // PacketConnReader is an optional interface that Readers can implement to support using generic net.PacketConns. |
| 152 | type PacketConnReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PacketConnReader# interface { |
| 153 | Readerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader# |
| 154 | |
| 155 | // ReadPacketConn reads a raw message from a generic net.PacketConn UDP connection. Implementations may |
| 156 | // alter connection properties, for example the read-deadline. |
| 157 | ReadPacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PacketConnReader#ReadPacketConn.(conn netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#, error) |
| 158 | } |
| 159 | |
| 160 | // defaultReader is an adapter for the Server struct that implements the Reader and |
| 161 | // PacketConnReader interfaces using the readTCP, readUDP and readPacketConn funcs |
| 162 | // of the embedded Server. |
| 163 | type defaultReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader# struct { |
| 164 | *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#Server. |
| 165 | } |
| 166 | |
| 167 | var _ PacketConnReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PacketConnReader# = defaultReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#{} |
| 168 | |
| 169 | func (dr defaultReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#) ReadTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#ReadTCP().(conn netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, error) { |
| 170 | return dr.readTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#readTCP().(conn, timeout) |
| 171 | } |
| 172 | |
| 173 | func (dr defaultReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#) ReadUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#ReadUDP().(conn *netscip-go gomod github.com/golang/go/src go1.25.0 net/.UDPConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, *SessionUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SessionUDP#, error) { |
| 174 | return dr.readUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#readUDP().(conn, timeout) |
| 175 | } |
| 176 | |
| 177 | func (dr defaultReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#) ReadPacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#ReadPacketConn().(conn netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#, error) { |
| 178 | return dr.readPacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#readPacketConn().(conn, timeout) |
| 179 | } |
| 180 | |
| 181 | // DecorateReader is a decorator hook for extending or supplanting the functionality of a Reader. |
| 182 | // Implementations should never return a nil Reader. |
| 183 | // Readers should also implement the optional PacketConnReader interface. |
| 184 | // PacketConnReader is required to use a generic net.PacketConn. |
| 185 | type DecorateReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DecorateReader# func(Readerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader#) Readerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader# |
| 186 | |
| 187 | // DecorateWriter is a decorator hook for extending or supplanting the functionality of a Writer. |
| 188 | // Implementations should never return a nil Writer. |
| 189 | type DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DecorateWriter# func(Writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Writer#) Writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Writer# |
| 190 | |
| 191 | // MsgInvalidFunc is a listener hook for observing incoming messages that were discarded |
| 192 | // because they could not be parsed. |
| 193 | // Every message that is read by a Reader will eventually be provided to the Handler, |
| 194 | // rejected (or ignored) by the MsgAcceptFunc, or passed to this function. |
| 195 | type MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgInvalidFunc# func(m []byte, err error) |
| 196 | |
| 197 | var DefaultMsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultMsgInvalidFunc. MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgInvalidFunc# = defaultMsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultMsgInvalidFunc(). |
| 198 | |
| 199 | func defaultMsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultMsgInvalidFunc().(m []byte, err error) {} |
| 200 | |
| 201 | // A Server defines parameters for running an DNS server. |
| 202 | type Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server# struct { |
| 203 | // Address to listen on, ":dns" if empty. |
| 204 | Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr. string |
| 205 | // if "tcp" or "tcp-tls" (DNS over TLS) it will invoke a TCP listener, otherwise an UDP one |
| 206 | Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net. string |
| 207 | // TCP Listener to use, this is to aid in systemd's socket activation. |
| 208 | Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener. netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenerscip-go gomod github.com/golang/go/src go1.25.0 net/Listener# |
| 209 | // TLS connection configuration |
| 210 | TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TLSConfig. *tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config# |
| 211 | // UDP "Listener" to use, this is to aid in systemd's socket activation. |
| 212 | PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn. netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn# |
| 213 | // Handler to invoke, dns.DefaultServeMux if nil. |
| 214 | Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Handler. Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler# |
| 215 | // Default buffer size to use to read incoming UDP messages. If not set |
| 216 | // it defaults to MinMsgSize (512 B). |
| 217 | UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize. int |
| 218 | // The net.Conn.SetReadTimeout value for new connections, defaults to 2 * time.Second. |
| 219 | ReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReadTimeout. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# |
| 220 | // The net.Conn.SetWriteTimeout value for new connections, defaults to 2 * time.Second. |
| 221 | WriteTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#WriteTimeout. timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# |
| 222 | // TCP idle timeout for multiple queries, if nil, defaults to 8 * time.Second (RFC 5966). |
| 223 | IdleTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#IdleTimeout. func() timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# |
| 224 | // An implementation of the TsigProvider interface. If defined it replaces TsigSecret and is used for all TSIG operations. |
| 225 | TsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TsigProvider. TsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TsigProvider# |
| 226 | // Secret(s) for Tsig map[<zonename>]<base64 secret>. The zonename must be in canonical form (lowercase, fqdn, see RFC 4034 Section 6.2). |
| 227 | TsigSecretscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TsigSecret. map[string]string |
| 228 | // If NotifyStartedFunc is set it is called once the server has started listening. |
| 229 | NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc. func() |
| 230 | // DecorateReader is optional, allows customization of the process that reads raw DNS messages. |
| 231 | // The decorated reader must not mutate the data read from the conn. |
| 232 | DecorateReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateReader. DecorateReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DecorateReader# |
| 233 | // DecorateWriter is optional, allows customization of the process that writes raw DNS messages. |
| 234 | DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateWriter. DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DecorateWriter# |
| 235 | // Maximum number of TCP queries before we close the socket. Default is maxTCPQueries (unlimited if -1). |
| 236 | MaxTCPQueriesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MaxTCPQueries. int |
| 237 | // Whether to set the SO_REUSEPORT socket option, allowing multiple listeners to be bound to a single address. |
| 238 | // It is only supported on certain GOOSes and when using ListenAndServe. |
| 239 | ReusePortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReusePort. bool |
| 240 | // Whether to set the SO_REUSEADDR socket option, allowing multiple listeners to be bound to a single address. |
| 241 | // Crucially this allows binding when an existing server is listening on `0.0.0.0` or `::`. |
| 242 | // It is only supported on certain GOOSes and when using ListenAndServe. |
| 243 | ReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReuseAddr. bool |
| 244 | // AcceptMsgFunc will check the incoming message and will reject it early in the process. |
| 245 | // By default DefaultMsgAcceptFunc will be used. |
| 246 | MsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgAcceptFunc. MsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAcceptFunc# |
| 247 | // MsgInvalidFunc is optional, will be called if a message is received but cannot be parsed. |
| 248 | MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgInvalidFunc. MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgInvalidFunc# |
| 249 | |
| 250 | // Shutdown handling |
| 251 | lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock. syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.RWMutexscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex# |
| 252 | startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. bool |
| 253 | shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#shutdown. chan struct{} |
| 254 | connsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#conns. map[netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#]struct{} |
| 255 | |
| 256 | // A pool for UDP message buffers. |
| 257 | udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool. syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Poolscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool# |
| 258 | } |
| 259 | |
| 260 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#tsigProvider().() TsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TsigProvider# { |
| 261 | if srv.TsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TsigProvider. != nil { |
| 262 | return srv.TsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TsigProvider. |
| 263 | } |
| 264 | if srv.TsigSecretscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TsigSecret. != nil { |
| 265 | return tsigSecretProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/tsigSecretProvider#(srv.TsigSecretscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TsigSecret.) |
| 266 | } |
| 267 | return nil |
| 268 | } |
| 269 | |
| 270 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) isStartedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#isStarted().() bool { |
| 271 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 272 | started := srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. |
| 273 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 274 | return started |
| 275 | } |
| 276 | |
| 277 | func makeUDPBufferscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/makeUDPBuffer().(size int) func() interface{} { |
| 278 | return func() interface{} { |
| 279 | return make([]byte, size) |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) initscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#init().() { |
| 284 | srv.shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#shutdown. = make(chan struct{}) |
| 285 | srv.connsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#conns. = make(map[netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#]struct{}) |
| 286 | |
| 287 | if srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize. == 0 { |
| 288 | srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize. = MinMsgSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MinMsgSize. |
| 289 | } |
| 290 | if srv.MsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgAcceptFunc. == nil { |
| 291 | srv.MsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgAcceptFunc. = DefaultMsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultMsgAcceptFunc. |
| 292 | } |
| 293 | if srv.MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgInvalidFunc. == nil { |
| 294 | srv.MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgInvalidFunc. = DefaultMsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultMsgInvalidFunc. |
| 295 | } |
| 296 | if srv.Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Handler. == nil { |
| 297 | srv.Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Handler. = DefaultServeMuxscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/DefaultServeMux. |
| 298 | } |
| 299 | |
| 300 | srv.udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool..Newscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#New. = makeUDPBufferscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/makeUDPBuffer().(srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize.) |
| 301 | } |
| 302 | |
| 303 | func unlockOncescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/unlockOnce().(l syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Lockerscip-go gomod github.com/golang/go/src go1.25.0 sync/Locker#) func() { |
| 304 | var once syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Oncescip-go gomod github.com/golang/go/src go1.25.0 sync/Once# |
| 305 | return func() { once.Doscip-go gomod github.com/golang/go/src go1.25.0 sync/Once#Do().(l.Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/Locker#Unlock().) } |
| 306 | } |
| 307 | |
| 308 | // ListenAndServe starts a nameserver on the configured address in *Server. |
| 309 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) ListenAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ListenAndServe().() error { |
| 310 | unlock := unlockOncescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/unlockOnce().(&srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock.) |
| 311 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 312 | defer unlock() |
| 313 | |
| 314 | if srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. { |
| 315 | return &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "server already started"} |
| 316 | } |
| 317 | |
| 318 | addr := srv.Addrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Addr. |
| 319 | if addr == "" { |
| 320 | addr = ":domain" |
| 321 | } |
| 322 | |
| 323 | srv.initscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#init().() |
| 324 | |
| 325 | switch srv.Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net. { |
| 326 | case "tcp", "tcp4", "tcp6": |
| 327 | l, err := listenTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/listenTCP().(srv.Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net., addr, srv.ReusePortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReusePort., srv.ReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReuseAddr.) |
| 328 | if err != nil { |
| 329 | return err |
| 330 | } |
| 331 | srv.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener. = l |
| 332 | srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. = true |
| 333 | unlock() |
| 334 | return srv.serveTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveTCP().(l) |
| 335 | case "tcp-tls", "tcp4-tls", "tcp6-tls": |
| 336 | if srv.TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TLSConfig. == nil || (len(srv.TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TLSConfig..Certificatesscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#Certificates.) == 0 && srv.TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TLSConfig..GetCertificatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/Config#GetCertificate. == nil) { |
| 337 | return errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("neither Certificates nor GetCertificate set in config") |
| 338 | } |
| 339 | network := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSuffix().(srv.Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net., "-tls") |
| 340 | l, err := listenTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/listenTCP().(network, addr, srv.ReusePortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReusePort., srv.ReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReuseAddr.) |
| 341 | if err != nil { |
| 342 | return err |
| 343 | } |
| 344 | l = tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.NewListenerscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/NewListener().(l, srv.TLSConfigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#TLSConfig.) |
| 345 | srv.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener. = l |
| 346 | srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. = true |
| 347 | unlock() |
| 348 | return srv.serveTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveTCP().(l) |
| 349 | case "udp", "udp4", "udp6": |
| 350 | l, err := listenUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/listenUDP().(srv.Netscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Net., addr, srv.ReusePortscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReusePort., srv.ReuseAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReuseAddr.) |
| 351 | if err != nil { |
| 352 | return err |
| 353 | } |
| 354 | u := l.(*netscip-go gomod github.com/golang/go/src go1.25.0 net/.UDPConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#) |
| 355 | if e := setUDPSocketOptionsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/setUDPSocketOptions().(u); e != nil { |
| 356 | u.Closescip-go gomod github.com/golang/go/src go1.25.0 net/conn#Close().() |
| 357 | return e |
| 358 | } |
| 359 | srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn. = l |
| 360 | srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. = true |
| 361 | unlock() |
| 362 | return srv.serveUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveUDP().(u) |
| 363 | } |
| 364 | return &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "bad network"} |
| 365 | } |
| 366 | |
| 367 | // ActivateAndServe starts a nameserver with the PacketConn or Listener |
| 368 | // configured in *Server. Its main use is to start a server from systemd. |
| 369 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) ActivateAndServescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ActivateAndServe().() error { |
| 370 | unlock := unlockOncescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/unlockOnce().(&srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock.) |
| 371 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 372 | defer unlock() |
| 373 | |
| 374 | if srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. { |
| 375 | return &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "server already started"} |
| 376 | } |
| 377 | |
| 378 | srv.initscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#init().() |
| 379 | |
| 380 | if srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn. != nil { |
| 381 | // Check PacketConn interface's type is valid and value |
| 382 | // is not nil |
| 383 | if t, ok := srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn..(*netscip-go gomod github.com/golang/go/src go1.25.0 net/.UDPConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#); ok && t != nil { |
| 384 | if e := setUDPSocketOptionsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/setUDPSocketOptions().(t); e != nil { |
| 385 | return e |
| 386 | } |
| 387 | } |
| 388 | srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. = true |
| 389 | unlock() |
| 390 | return srv.serveUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveUDP().(srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn.) |
| 391 | } |
| 392 | if srv.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener. != nil { |
| 393 | srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. = true |
| 394 | unlock() |
| 395 | return srv.serveTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveTCP().(srv.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener.) |
| 396 | } |
| 397 | return &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "bad listeners"} |
| 398 | } |
| 399 | |
| 400 | // Shutdown shuts down a server. After a call to Shutdown, ListenAndServe and |
| 401 | // ActivateAndServe will return. |
| 402 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) Shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Shutdown().() error { |
| 403 | return srv.ShutdownContextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ShutdownContext().(contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.25.0 context/Background().()) |
| 404 | } |
| 405 | |
| 406 | // ShutdownContext shuts down a server. After a call to ShutdownContext, |
| 407 | // ListenAndServe and ActivateAndServe will return. |
| 408 | // |
| 409 | // A context.Context may be passed to limit how long to wait for connections |
| 410 | // to terminate. |
| 411 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) ShutdownContextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ShutdownContext().(ctx contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Contextscip-go gomod github.com/golang/go/src go1.25.0 context/Context#) error { |
| 412 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 413 | if !srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. { |
| 414 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 415 | return &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "server not started"} |
| 416 | } |
| 417 | |
| 418 | srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. = false |
| 419 | |
| 420 | if srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn. != nil { |
| 421 | srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn..SetReadDeadlinescip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#SetReadDeadline().(aLongTimeAgoscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/aLongTimeAgo.) // Unblock reads |
| 422 | } |
| 423 | |
| 424 | if srv.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener. != nil { |
| 425 | srv.Listenerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Listener..Closescip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Close().() |
| 426 | } |
| 427 | |
| 428 | for rw := range srv.connsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#conns. { |
| 429 | rw.SetReadDeadlinescip-go gomod github.com/golang/go/src go1.25.0 net/Conn#SetReadDeadline().(aLongTimeAgoscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/aLongTimeAgo.) // Unblock reads |
| 430 | } |
| 431 | |
| 432 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 433 | |
| 434 | if testShutdownNotifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testShutdownNotify. != nil { |
| 435 | testShutdownNotifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testShutdownNotify..Broadcastscip-go gomod github.com/golang/go/src go1.25.0 sync/Cond#Broadcast().() |
| 436 | } |
| 437 | |
| 438 | var ctxErr error |
| 439 | select { |
| 440 | case <-srv.shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#shutdown.: |
| 441 | case <-ctx.Donescip-go gomod github.com/golang/go/src go1.25.0 context/Context#Done().(): |
| 442 | ctxErr = ctx.Errscip-go gomod github.com/golang/go/src go1.25.0 context/Context#Err().() |
| 443 | } |
| 444 | |
| 445 | if srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn. != nil { |
| 446 | srv.PacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#PacketConn..Closescip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#Close().() |
| 447 | } |
| 448 | |
| 449 | return ctxErr |
| 450 | } |
| 451 | |
| 452 | var testShutdownNotifyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/testShutdownNotify. *syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.Condscip-go gomod github.com/golang/go/src go1.25.0 sync/Cond# |
| 453 | |
| 454 | // getReadTimeout is a helper func to use system timeout if server did not intend to change it. |
| 455 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) getReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#getReadTimeout().() timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration# { |
| 456 | if srv.ReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReadTimeout. != 0 { |
| 457 | return srv.ReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#ReadTimeout. |
| 458 | } |
| 459 | return dnsTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/dnsTimeout. |
| 460 | } |
| 461 | |
| 462 | // serveTCP starts a TCP listener for the server. |
| 463 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) serveTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveTCP().(l netscip-go gomod github.com/golang/go/src go1.25.0 net/.Listenerscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#) error { |
| 464 | defer l.Closescip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Close().() |
| 465 | |
| 466 | if srv.NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc. != nil { |
| 467 | srv.NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc.() |
| 468 | } |
| 469 | |
| 470 | var wg syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup# |
| 471 | defer func() { |
| 472 | wg.Waitscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Wait().() |
| 473 | close(srv.shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#shutdown.) |
| 474 | }() |
| 475 | |
| 476 | for srv.isStartedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#isStarted().() { |
| 477 | rw, err := l.Acceptscip-go gomod github.com/golang/go/src go1.25.0 net/Listener#Accept().() |
| 478 | if err != nil { |
| 479 | if !srv.isStartedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#isStarted().() { |
| 480 | return nil |
| 481 | } |
| 482 | if neterr, ok := err.(netscip-go gomod github.com/golang/go/src go1.25.0 net/.Errorscip-go gomod github.com/golang/go/src go1.25.0 net/Error#); ok && neterr.Temporaryscip-go gomod github.com/golang/go/src go1.25.0 net/Error#Temporary().() { |
| 483 | continue |
| 484 | } |
| 485 | return err |
| 486 | } |
| 487 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 488 | // Track the connection to allow unblocking reads on shutdown. |
| 489 | srv.connsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#conns.[rw] = struct{}{} |
| 490 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 491 | wg.Addscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Add().(1) |
| 492 | go srv.serveTCPConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveTCPConn().(&wg, rw) |
| 493 | } |
| 494 | |
| 495 | return nil |
| 496 | } |
| 497 | |
| 498 | // serveUDP starts a UDP listener for the server. |
| 499 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) serveUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveUDP().(l netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#) error { |
| 500 | defer l.Closescip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#Close().() |
| 501 | |
| 502 | reader := Readerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader#(defaultReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#{srv}) |
| 503 | if srv.DecorateReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateReader. != nil { |
| 504 | reader = srv.DecorateReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateReader.(reader) |
| 505 | } |
| 506 | |
| 507 | lUDP, isUDP := l.(*netscip-go gomod github.com/golang/go/src go1.25.0 net/.UDPConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#) |
| 508 | readerPC, canPacketConn := reader.(PacketConnReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PacketConnReader#) |
| 509 | if !isUDP && !canPacketConn { |
| 510 | return &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "PacketConnReader was not implemented on Reader returned from DecorateReader but is required for net.PacketConn"} |
| 511 | } |
| 512 | |
| 513 | if srv.NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc. != nil { |
| 514 | srv.NotifyStartedFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#NotifyStartedFunc.() |
| 515 | } |
| 516 | |
| 517 | var wg syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup# |
| 518 | defer func() { |
| 519 | wg.Waitscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Wait().() |
| 520 | close(srv.shutdownscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#shutdown.) |
| 521 | }() |
| 522 | |
| 523 | rtimeout := srv.getReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#getReadTimeout().() |
| 524 | // deadline is not used here |
| 525 | for srv.isStartedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#isStarted().() { |
| 526 | var ( |
| 527 | m []byte |
| 528 | sPC netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr# |
| 529 | sUDP *SessionUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SessionUDP# |
| 530 | err error |
| 531 | ) |
| 532 | if isUDP { |
| 533 | m, sUDP, err = reader.ReadUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader#ReadUDP.(lUDP, rtimeout) |
| 534 | } else { |
| 535 | m, sPC, err = readerPC.ReadPacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/PacketConnReader#ReadPacketConn.(l, rtimeout) |
| 536 | } |
| 537 | if err != nil { |
| 538 | if !srv.isStartedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#isStarted().() { |
| 539 | return nil |
| 540 | } |
| 541 | if netErr, ok := err.(netscip-go gomod github.com/golang/go/src go1.25.0 net/.Errorscip-go gomod github.com/golang/go/src go1.25.0 net/Error#); ok && netErr.Temporaryscip-go gomod github.com/golang/go/src go1.25.0 net/Error#Temporary().() { |
| 542 | continue |
| 543 | } |
| 544 | return err |
| 545 | } |
| 546 | if len(m) < headerSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/headerSize. { |
| 547 | if cap(m) == srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize. { |
| 548 | srv.udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool..Putscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Put().(m[:srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize.]) |
| 549 | } |
| 550 | srv.MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgInvalidFunc.(m, ErrShortReadscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ErrShortRead.) |
| 551 | continue |
| 552 | } |
| 553 | wg.Addscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Add().(1) |
| 554 | go srv.serveUDPPacketscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveUDPPacket().(&wg, m, l, sUDP, sPC) |
| 555 | } |
| 556 | |
| 557 | return nil |
| 558 | } |
| 559 | |
| 560 | // Serve a new TCP connection. |
| 561 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) serveTCPConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveTCPConn().(wg *syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#, rw netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#) { |
| 562 | w := &responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#{tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigProvider.: srv.tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#tsigProvider().(), tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp.: rw} |
| 563 | if srv.DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateWriter. != nil { |
| 564 | w.writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#writer. = srv.DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateWriter.(w) |
| 565 | } else { |
| 566 | w.writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#writer. = w |
| 567 | } |
| 568 | |
| 569 | reader := Readerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader#(defaultReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/defaultReader#{srv}) |
| 570 | if srv.DecorateReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateReader. != nil { |
| 571 | reader = srv.DecorateReaderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateReader.(reader) |
| 572 | } |
| 573 | |
| 574 | idleTimeout := tcpIdleTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/tcpIdleTimeout. |
| 575 | if srv.IdleTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#IdleTimeout. != nil { |
| 576 | idleTimeout = srv.IdleTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#IdleTimeout.() |
| 577 | } |
| 578 | |
| 579 | timeout := srv.getReadTimeoutscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#getReadTimeout().() |
| 580 | |
| 581 | limit := srv.MaxTCPQueriesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MaxTCPQueries. |
| 582 | if limit == 0 { |
| 583 | limit = maxTCPQueriesscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/maxTCPQueries. |
| 584 | } |
| 585 | |
| 586 | for q := 0; (q < limit || limit == -1) && srv.isStartedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#isStarted().(); q++ { |
| 587 | m, err := reader.ReadTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Reader#ReadTCP.(w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp., timeout) |
| 588 | if err != nil { |
| 589 | // TODO(tmthrgd): handle error |
| 590 | break |
| 591 | } |
| 592 | srv.serveDNSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveDNS().(m, w) |
| 593 | if w.closedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#closed. { |
| 594 | break // Close() was called |
| 595 | } |
| 596 | if w.hijackedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#hijacked. { |
| 597 | break // client will call Close() themselves |
| 598 | } |
| 599 | // The first read uses the read timeout, the rest use the |
| 600 | // idle timeout. |
| 601 | timeout = idleTimeout |
| 602 | } |
| 603 | |
| 604 | if !w.hijackedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#hijacked. { |
| 605 | w.Closescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#Close().() |
| 606 | } |
| 607 | |
| 608 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().() |
| 609 | delete(srv.connsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#conns., w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp.) |
| 610 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().() |
| 611 | |
| 612 | wg.Donescip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Done().() |
| 613 | } |
| 614 | |
| 615 | // Serve a new UDP request. |
| 616 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) serveUDPPacketscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveUDPPacket().(wg *syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#, m []byte, u netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#, udpSession *SessionUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SessionUDP#, pcSession netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#) { |
| 617 | w := &responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#{tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigProvider.: srv.tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#tsigProvider().(), udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp.: u, udpSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udpSession.: udpSession, pcSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#pcSession.: pcSession} |
| 618 | if srv.DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateWriter. != nil { |
| 619 | w.writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#writer. = srv.DecorateWriterscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#DecorateWriter.(w) |
| 620 | } else { |
| 621 | w.writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#writer. = w |
| 622 | } |
| 623 | |
| 624 | srv.serveDNSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveDNS().(m, w) |
| 625 | wg.Donescip-go gomod github.com/golang/go/src go1.25.0 sync/WaitGroup#Done().() |
| 626 | } |
| 627 | |
| 628 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) serveDNSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#serveDNS().(m []byte, w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) { |
| 629 | dh, off, err := unpackMsgHdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/unpackMsgHdr().(m, 0) |
| 630 | if err != nil { |
| 631 | srv.MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgInvalidFunc.(m, err) |
| 632 | // Let client hang, they are sending crap; any reply can be used to amplify. |
| 633 | return |
| 634 | } |
| 635 | |
| 636 | req := new(Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) |
| 637 | req.setHdrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#setHdr().(dh) |
| 638 | |
| 639 | switch action := srv.MsgAcceptFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgAcceptFunc.(dh); action { |
| 640 | case MsgAcceptscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgAccept.: |
| 641 | err := req.unpackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#unpack().(dh, m, off) |
| 642 | if err == nil { |
| 643 | break |
| 644 | } |
| 645 | |
| 646 | srv.MsgInvalidFuncscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#MsgInvalidFunc.(m, err) |
| 647 | fallthrough |
| 648 | case MsgRejectscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgReject., MsgRejectNotImplementedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgRejectNotImplemented.: |
| 649 | opcode := req.Opcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Opcode. |
| 650 | req.SetRcodeFormatErrorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#SetRcodeFormatError().(req) |
| 651 | req.Zeroscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Zero. = false |
| 652 | if action == MsgRejectNotImplementedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgRejectNotImplemented. { |
| 653 | req.Opcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Opcode. = opcode |
| 654 | req.Rcodescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgHdr#Rcode. = RcodeNotImplementedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/RcodeNotImplemented. |
| 655 | } |
| 656 | |
| 657 | // Are we allowed to delete any OPT records here? |
| 658 | req.Nsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Ns., req.Answerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Answer., req.Extrascip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Extra. = nil, nil, nil |
| 659 | |
| 660 | w.WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#WriteMsg().(req) |
| 661 | fallthrough |
| 662 | case MsgIgnorescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MsgIgnore.: |
| 663 | if w.udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp. != nil && cap(m) == srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize. { |
| 664 | srv.udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool..Putscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Put().(m[:srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize.]) |
| 665 | } |
| 666 | |
| 667 | return |
| 668 | } |
| 669 | |
| 670 | w.tsigStatusscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigStatus. = nil |
| 671 | if w.tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigProvider. != nil { |
| 672 | if t := req.IsTsigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#IsTsig().(); t != nil { |
| 673 | w.tsigStatusscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigStatus. = TsigVerifyWithProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TsigVerifyWithProvider().(m, w.tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigProvider., "", false) |
| 674 | w.tsigTimersOnlyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigTimersOnly. = false |
| 675 | w.tsigRequestMACscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigRequestMAC. = t.MACscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TSIG#MAC. |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | if w.udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp. != nil && cap(m) == srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize. { |
| 680 | srv.udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool..Putscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Put().(m[:srv.UDPSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#UDPSize.]) |
| 681 | } |
| 682 | |
| 683 | srv.Handlerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#Handler..ServeDNSscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Handler#ServeDNS.(w, req) // Writes back to the client |
| 684 | } |
| 685 | |
| 686 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) readTCPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#readTCP().(conn netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, error) { |
| 687 | // If we race with ShutdownContext, the read deadline may |
| 688 | // have been set in the distant past to unblock the read |
| 689 | // below. We must not override it, otherwise we may block |
| 690 | // ShutdownContext. |
| 691 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 692 | if srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. { |
| 693 | conn.SetReadDeadlinescip-go gomod github.com/golang/go/src go1.25.0 net/Conn#SetReadDeadline().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Add().(timeout)) |
| 694 | } |
| 695 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 696 | |
| 697 | var length uint16 |
| 698 | if err := binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/.Readscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/Read().(conn, binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/BigEndian., &length); err != nil { |
| 699 | return nil, err |
| 700 | } |
| 701 | |
| 702 | m := make([]byte, length) |
| 703 | if _, err := ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ReadFullscip-go gomod github.com/golang/go/src go1.25.0 io/ReadFull().(conn, m); err != nil { |
| 704 | return nil, err |
| 705 | } |
| 706 | |
| 707 | return m, nil |
| 708 | } |
| 709 | |
| 710 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) readUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#readUDP().(conn *netscip-go gomod github.com/golang/go/src go1.25.0 net/.UDPConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, *SessionUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SessionUDP#, error) { |
| 711 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 712 | if srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. { |
| 713 | // See the comment in readTCP above. |
| 714 | conn.SetReadDeadlinescip-go gomod github.com/golang/go/src go1.25.0 net/conn#SetReadDeadline().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Add().(timeout)) |
| 715 | } |
| 716 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 717 | |
| 718 | m := srv.udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool..Getscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Get().().([]byte) |
| 719 | n, s, err := ReadFromSessionUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ReadFromSessionUDP().(conn, m) |
| 720 | if err != nil { |
| 721 | srv.udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool..Putscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Put().(m) |
| 722 | return nil, nil, err |
| 723 | } |
| 724 | m = m[:n] |
| 725 | return m, s, nil |
| 726 | } |
| 727 | |
| 728 | func (srv *Serverscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#) readPacketConnscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#readPacketConn().(conn netscip-go gomod github.com/golang/go/src go1.25.0 net/.PacketConnscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#, timeout timescip-go gomod github.com/golang/go/src go1.25.0 time/.Durationscip-go gomod github.com/golang/go/src go1.25.0 time/Duration#) ([]byte, netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr#, error) { |
| 729 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RLockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RLock().() |
| 730 | if srv.startedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#started. { |
| 731 | // See the comment in readTCP above. |
| 732 | conn.SetReadDeadlinescip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#SetReadDeadline().(timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().().Addscip-go gomod github.com/golang/go/src go1.25.0 time/Time#Add().(timeout)) |
| 733 | } |
| 734 | srv.lockscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#lock..RUnlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#RUnlock().() |
| 735 | |
| 736 | m := srv.udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool..Getscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Get().().([]byte) |
| 737 | n, addr, err := conn.ReadFromscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#ReadFrom().(m) |
| 738 | if err != nil { |
| 739 | srv.udpPoolscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Server#udpPool..Putscip-go gomod github.com/golang/go/src go1.25.0 sync/Pool#Put().(m) |
| 740 | return nil, nil, err |
| 741 | } |
| 742 | m = m[:n] |
| 743 | return m, addr, nil |
| 744 | } |
| 745 | |
| 746 | // WriteMsg implements the ResponseWriter.WriteMsg method. |
| 747 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) WriteMsgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#WriteMsg().(m *Msgscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#) (err error) { |
| 748 | if w.closedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#closed. { |
| 749 | return &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "WriteMsg called after Close"} |
| 750 | } |
| 751 | |
| 752 | var data []byte |
| 753 | if w.tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigProvider. != nil { // if no provider, dont check for the tsig (which is a longer check) |
| 754 | if t := m.IsTsigscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#IsTsig().(); t != nil { |
| 755 | data, w.tsigRequestMACscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigRequestMAC., err = TsigGenerateWithProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TsigGenerateWithProvider().(m, w.tsigProviderscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigProvider., w.tsigRequestMACscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigRequestMAC., w.tsigTimersOnlyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigTimersOnly.) |
| 756 | if err != nil { |
| 757 | return err |
| 758 | } |
| 759 | _, err = w.writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#writer..Writescip-go gomod github.com/golang/go/src go1.25.0 io/Writer#Write().(data) |
| 760 | return err |
| 761 | } |
| 762 | } |
| 763 | data, err = m.Packscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Msg#Pack().() |
| 764 | if err != nil { |
| 765 | return err |
| 766 | } |
| 767 | _, err = w.writerscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#writer..Writescip-go gomod github.com/golang/go/src go1.25.0 io/Writer#Write().(data) |
| 768 | return err |
| 769 | } |
| 770 | |
| 771 | // Write implements the ResponseWriter.Write method. |
| 772 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) Writescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#Write().(m []byte) (int, error) { |
| 773 | if w.closedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#closed. { |
| 774 | return 0, &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "Write called after Close"} |
| 775 | } |
| 776 | |
| 777 | switch { |
| 778 | case w.udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp. != nil: |
| 779 | if u, ok := w.udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp..(*netscip-go gomod github.com/golang/go/src go1.25.0 net/.UDPConnscip-go gomod github.com/golang/go/src go1.25.0 net/UDPConn#); ok { |
| 780 | return WriteToSessionUDPscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/WriteToSessionUDP().(u, m, w.udpSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udpSession.) |
| 781 | } |
| 782 | return w.udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp..WriteToscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#WriteTo().(m, w.pcSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#pcSession.) |
| 783 | case w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp. != nil: |
| 784 | if len(m) > MaxMsgSizescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/MaxMsgSize. { |
| 785 | return 0, &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "message too large"} |
| 786 | } |
| 787 | |
| 788 | msg := make([]byte, 2+len(m)) |
| 789 | binaryscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.25.0 `encoding/binary`/bigEndian#PutUint16().(msg, uint16(len(m))) |
| 790 | copy(msg[2:], m) |
| 791 | return w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp..Writescip-go gomod github.com/golang/go/src go1.25.0 net/Conn#Write().(msg) |
| 792 | default: |
| 793 | panic("dns: internal error: udp and tcp both nil") |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | // LocalAddr implements the ResponseWriter.LocalAddr method. |
| 798 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) LocalAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#LocalAddr().() netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr# { |
| 799 | switch { |
| 800 | case w.udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp. != nil: |
| 801 | return w.udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp..LocalAddrscip-go gomod github.com/golang/go/src go1.25.0 net/PacketConn#LocalAddr().() |
| 802 | case w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp. != nil: |
| 803 | return w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp..LocalAddrscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#LocalAddr().() |
| 804 | default: |
| 805 | panic("dns: internal error: udp and tcp both nil") |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | // RemoteAddr implements the ResponseWriter.RemoteAddr method. |
| 810 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) RemoteAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#RemoteAddr().() netscip-go gomod github.com/golang/go/src go1.25.0 net/.Addrscip-go gomod github.com/golang/go/src go1.25.0 net/Addr# { |
| 811 | switch { |
| 812 | case w.udpSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udpSession. != nil: |
| 813 | return w.udpSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udpSession..RemoteAddrscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/SessionUDP#RemoteAddr().() |
| 814 | case w.pcSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#pcSession. != nil: |
| 815 | return w.pcSessionscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#pcSession. |
| 816 | case w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp. != nil: |
| 817 | return w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp..RemoteAddrscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#RemoteAddr().() |
| 818 | default: |
| 819 | panic("dns: internal error: udpSession, pcSession and tcp are all nil") |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | // TsigStatus implements the ResponseWriter.TsigStatus method. |
| 824 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) TsigStatusscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#TsigStatus().() error { return w.tsigStatusscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigStatus. } |
| 825 | |
| 826 | // TsigTimersOnly implements the ResponseWriter.TsigTimersOnly method. |
| 827 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) TsigTimersOnlyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#TsigTimersOnly().(b bool) { w.tsigTimersOnlyscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tsigTimersOnly. = b } |
| 828 | |
| 829 | // Hijack implements the ResponseWriter.Hijack method. |
| 830 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) Hijackscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#Hijack().() { w.hijackedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#hijacked. = true } |
| 831 | |
| 832 | // Close implements the ResponseWriter.Close method |
| 833 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) Closescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#Close().() error { |
| 834 | if w.closedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#closed. { |
| 835 | return &Errorscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#{errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/Error#err.: "connection already closed"} |
| 836 | } |
| 837 | w.closedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#closed. = true |
| 838 | |
| 839 | switch { |
| 840 | case w.udpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#udp. != nil: |
| 841 | // Can't close the udp conn, as that is actually the listener. |
| 842 | return nil |
| 843 | case w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp. != nil: |
| 844 | return w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp..Closescip-go gomod github.com/golang/go/src go1.25.0 net/Conn#Close().() |
| 845 | default: |
| 846 | panic("dns: internal error: udp and tcp both nil") |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | // ConnectionState() implements the ConnectionStater.ConnectionState() interface. |
| 851 | func (w *responsescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#) ConnectionStatescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#ConnectionState().() *tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.ConnectionStatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/ConnectionState# { |
| 852 | type tlsConnectionStater interface { |
| 853 | ConnectionState() tlsscip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/.ConnectionStatescip-go gomod github.com/golang/go/src go1.25.0 `crypto/tls`/ConnectionState# |
| 854 | } |
| 855 | if v, ok := w.tcpscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/response#tcp..(tlsConnectionStater); ok { |
| 856 | t := v.ConnectionState() |
| 857 | return &t |
| 858 | } |
| 859 | return nil |
| 860 | } |