| 
									
										
										
										
											2018-05-21 19:40:46 +01:00
										 |  |  | package dnsserver
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2018-05-23 13:50:27 +01:00
										 |  |  | 	"net"
 | 
					
						
							| 
									
										
										
										
											2021-02-17 20:45:04 +01:00
										 |  |  | 	"net/http"
 | 
					
						
							| 
									
										
										
										
											2018-05-21 19:40:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:33:34 +02:00
										 |  |  | 	"github.com/miekg/dns"
 | 
					
						
							| 
									
										
										
										
											2018-05-21 19:40:46 +01:00
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:33:34 +02:00
										 |  |  | // DoHWriter is a dns.ResponseWriter that adds more specific LocalAddr and RemoteAddr methods.
 | 
					
						
							| 
									
										
										
										
											2018-05-23 13:50:27 +01:00
										 |  |  | type DoHWriter struct {
 | 
					
						
							|  |  |  | 	// raddr is the remote's address. This can be optionally set.
 | 
					
						
							|  |  |  | 	raddr net.Addr
 | 
					
						
							|  |  |  | 	// laddr is our address. This can be optionally set.
 | 
					
						
							|  |  |  | 	laddr net.Addr
 | 
					
						
							| 
									
										
										
										
											2021-02-17 20:45:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// request is the HTTP request we're currently handling.
 | 
					
						
							|  |  |  | 	request *http.Request
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:33:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Msg is a response to be written to the client.
 | 
					
						
							|  |  |  | 	Msg *dns.Msg
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // WriteMsg stores the message to be written to the client.
 | 
					
						
							|  |  |  | func (d *DoHWriter) WriteMsg(m *dns.Msg) error {
 | 
					
						
							|  |  |  | 	d.Msg = m
 | 
					
						
							|  |  |  | 	return nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Write stores the message to be written to the client.
 | 
					
						
							|  |  |  | func (d *DoHWriter) Write(b []byte) (int, error) {
 | 
					
						
							|  |  |  | 	d.Msg = new(dns.Msg)
 | 
					
						
							|  |  |  | 	return len(b), d.Msg.Unpack(b)
 | 
					
						
							| 
									
										
										
										
											2018-05-23 13:50:27 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // RemoteAddr returns the remote address.
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:33:34 +02:00
										 |  |  | func (d *DoHWriter) RemoteAddr() net.Addr {
 | 
					
						
							|  |  |  | 	return d.raddr
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2018-05-23 13:50:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | // LocalAddr returns the local address.
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:33:34 +02:00
										 |  |  | func (d *DoHWriter) LocalAddr() net.Addr {
 | 
					
						
							|  |  |  | 	return d.laddr
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Request returns the HTTP request.
 | 
					
						
							|  |  |  | func (d *DoHWriter) Request() *http.Request {
 | 
					
						
							|  |  |  | 	return d.request
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Close no-op implementation.
 | 
					
						
							|  |  |  | func (d *DoHWriter) Close() error {
 | 
					
						
							|  |  |  | 	return nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TsigStatus no-op implementation.
 | 
					
						
							|  |  |  | func (d *DoHWriter) TsigStatus() error {
 | 
					
						
							|  |  |  | 	return nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TsigTimersOnly no-op implementation.
 | 
					
						
							|  |  |  | func (d *DoHWriter) TsigTimersOnly(_ bool) {}
 | 
					
						
							| 
									
										
										
										
											2021-02-17 20:45:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 15:33:34 +02:00
										 |  |  | // Hijack no-op implementation.
 | 
					
						
							|  |  |  | func (d *DoHWriter) Hijack() {}
 |