mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-27 08:14:18 -04:00 
			
		
		
		
	Remove the word middleware (#1067)
* Rename middleware to plugin first pass; mostly used 'sed', few spots where I manually changed text. This still builds a coredns binary. * fmt error * Rename AddMiddleware to AddPlugin * Readd AddMiddleware to remain backwards compat
This commit is contained in:
		
							
								
								
									
										46
									
								
								plugin/pkg/edns/edns.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								plugin/pkg/edns/edns.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| // Package edns provides function useful for adding/inspecting OPT records to/in messages. | ||||
| package edns | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
|  | ||||
| 	"github.com/miekg/dns" | ||||
| ) | ||||
|  | ||||
| // Version checks the EDNS version in the request. If error | ||||
| // is nil everything is OK and we can invoke the plugin. If non-nil, the | ||||
| // returned Msg is valid to be returned to the client (and should). For some | ||||
| // reason this response should not contain a question RR in the question section. | ||||
| func Version(req *dns.Msg) (*dns.Msg, error) { | ||||
| 	opt := req.IsEdns0() | ||||
| 	if opt == nil { | ||||
| 		return nil, nil | ||||
| 	} | ||||
| 	if opt.Version() == 0 { | ||||
| 		return nil, nil | ||||
| 	} | ||||
| 	m := new(dns.Msg) | ||||
| 	m.SetReply(req) | ||||
| 	// zero out question section, wtf. | ||||
| 	m.Question = nil | ||||
|  | ||||
| 	o := new(dns.OPT) | ||||
| 	o.Hdr.Name = "." | ||||
| 	o.Hdr.Rrtype = dns.TypeOPT | ||||
| 	o.SetVersion(0) | ||||
| 	o.SetExtendedRcode(dns.RcodeBadVers) | ||||
| 	m.Extra = []dns.RR{o} | ||||
|  | ||||
| 	return m, errors.New("EDNS0 BADVERS") | ||||
| } | ||||
|  | ||||
| // Size returns a normalized size based on proto. | ||||
| func Size(proto string, size int) int { | ||||
| 	if proto == "tcp" { | ||||
| 		return dns.MaxMsgSize | ||||
| 	} | ||||
| 	if size < dns.MinMsgSize { | ||||
| 		return dns.MinMsgSize | ||||
| 	} | ||||
| 	return size | ||||
| } | ||||
							
								
								
									
										37
									
								
								plugin/pkg/edns/edns_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								plugin/pkg/edns/edns_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| package edns | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/miekg/dns" | ||||
| ) | ||||
|  | ||||
| func TestVersion(t *testing.T) { | ||||
| 	m := ednsMsg() | ||||
| 	m.Extra[0].(*dns.OPT).SetVersion(2) | ||||
|  | ||||
| 	_, err := Version(m) | ||||
| 	if err == nil { | ||||
| 		t.Errorf("expected wrong version, but got OK") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestVersionNoEdns(t *testing.T) { | ||||
| 	m := ednsMsg() | ||||
| 	m.Extra = nil | ||||
|  | ||||
| 	_, err := Version(m) | ||||
| 	if err != nil { | ||||
| 		t.Errorf("expected no error, but got one: %s", err) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func ednsMsg() *dns.Msg { | ||||
| 	m := new(dns.Msg) | ||||
| 	m.SetQuestion("example.com.", dns.TypeA) | ||||
| 	o := new(dns.OPT) | ||||
| 	o.Hdr.Name = "." | ||||
| 	o.Hdr.Rrtype = dns.TypeOPT | ||||
| 	m.Extra = append(m.Extra, o) | ||||
| 	return m | ||||
| } | ||||
		Reference in New Issue
	
	Block a user