mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-29 01:04:15 -04:00 
			
		
		
		
	Add state.SizeAndDo()
This methods returns an OPT record which can be used to create a new message with the same bufsize and Do bit as the original one.
This commit is contained in:
		| @@ -55,8 +55,10 @@ func New(hosts []string) Proxy { | |||||||
| func (p Proxy) Lookup(state middleware.State, name string, tpe uint16) (*dns.Msg, error) { | func (p Proxy) Lookup(state middleware.State, name string, tpe uint16) (*dns.Msg, error) { | ||||||
| 	req := new(dns.Msg) | 	req := new(dns.Msg) | ||||||
| 	req.SetQuestion(name, tpe) | 	req.SetQuestion(name, tpe) | ||||||
| 	// TODO(miek): |  | ||||||
| 	// USE STATE FOR DNSSEC ETCD BUFSIZE BLA BLA | 	opt := state.SizeAndDo() | ||||||
|  | 	req.Extra = []dns.RR{opt} | ||||||
|  |  | ||||||
| 	return p.lookup(state, req) | 	return p.lookup(state, req) | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,6 @@ type ReverseProxy struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| func (p ReverseProxy) ServeDNS(w dns.ResponseWriter, r *dns.Msg, extra []dns.RR) error { | func (p ReverseProxy) ServeDNS(w dns.ResponseWriter, r *dns.Msg, extra []dns.RR) error { | ||||||
| 	// TODO(miek): use extra to EDNS0. |  | ||||||
| 	var ( | 	var ( | ||||||
| 		reply *dns.Msg | 		reply *dns.Msg | ||||||
| 		err   error | 		err   error | ||||||
|   | |||||||
| @@ -19,17 +19,12 @@ type State struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| // Now returns the current timestamp in the specified format. | // Now returns the current timestamp in the specified format. | ||||||
| func (s State) Now(format string) string { | func (s State) Now(format string) string { return time.Now().Format(format) } | ||||||
| 	return time.Now().Format(format) |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // NowDate returns the current date/time that can be used | // NowDate returns the current date/time that can be used in other time functions. | ||||||
| // in other time functions. | func (s State) NowDate() time.Time { return time.Now() } | ||||||
| func (s State) NowDate() time.Time { |  | ||||||
| 	return time.Now() |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // Header gets the value of a header. | // Header gets the heaser of the request in State. | ||||||
| func (s State) Header() *dns.RR_Header { | func (s State) Header() *dns.RR_Header { | ||||||
| 	// TODO(miek) | 	// TODO(miek) | ||||||
| 	return nil | 	return nil | ||||||
| @@ -107,36 +102,41 @@ func (s State) Size() int { | |||||||
| 	return dns.MinMsgSize | 	return dns.MinMsgSize | ||||||
| } | } | ||||||
|  |  | ||||||
| // Type returns the type of the question as a string. | // SizeAndDo returns a ready made OPT record that the reflects the intent | ||||||
| func (s State) Type() string { | // from the state. This can be added to upstream requests that will then | ||||||
| 	return dns.Type(s.Req.Question[0].Qtype).String() | // hopefully return a message that is understandable by the original client. | ||||||
|  | func (s State) SizeAndDo() *dns.OPT { | ||||||
|  | 	size := s.Size() | ||||||
|  | 	Do := s.Do() | ||||||
|  |  | ||||||
|  | 	o := new(dns.OPT) | ||||||
|  | 	o.Hdr.Name = "." | ||||||
|  | 	o.Hdr.Rrtype = dns.TypeOPT | ||||||
|  | 	o.SetUDPSize(uint16(size)) | ||||||
|  | 	if Do { | ||||||
|  | 		o.SetDo() | ||||||
|  | 	} | ||||||
|  | 	return o | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Type returns the type of the question as a string. | ||||||
|  | func (s State) Type() string { return dns.Type(s.Req.Question[0].Qtype).String() } | ||||||
|  |  | ||||||
| // QType returns the type of the question as a uint16. | // QType returns the type of the question as a uint16. | ||||||
| func (s State) QType() uint16 { | func (s State) QType() uint16 { return s.Req.Question[0].Qtype } | ||||||
| 	return s.Req.Question[0].Qtype |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // Name returns the name of the question in the request. Note | // Name returns the name of the question in the request. Note | ||||||
| // this name will always have a closing dot and will be lower cased. | // this name will always have a closing dot and will be lower cased. | ||||||
| func (s State) Name() string { | func (s State) Name() string { return strings.ToLower(dns.Name(s.Req.Question[0].Name).String()) } | ||||||
| 	return strings.ToLower(dns.Name(s.Req.Question[0].Name).String()) |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // QName returns the name of the question in the request. | // QName returns the name of the question in the request. | ||||||
| func (s State) QName() string { | func (s State) QName() string { return dns.Name(s.Req.Question[0].Name).String() } | ||||||
| 	return dns.Name(s.Req.Question[0].Name).String() |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // Class returns the class of the question in the request. | // Class returns the class of the question in the request. | ||||||
| func (s State) Class() string { | func (s State) Class() string { return dns.Class(s.Req.Question[0].Qclass).String() } | ||||||
| 	return dns.Class(s.Req.Question[0].Qclass).String() |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // QClass returns the class of the question in the request. | // QClass returns the class of the question in the request. | ||||||
| func (s State) QClass() uint16 { | func (s State) QClass() uint16 { return s.Req.Question[0].Qclass } | ||||||
| 	return s.Req.Question[0].Qclass |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // ErrorMessage returns an error message suitable for sending | // ErrorMessage returns an error message suitable for sending | ||||||
| // back to the client. | // back to the client. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user