| 
									
										
										
										
											2019-08-25 19:00:59 +00:00
										 |  |  | // +build gofuzz | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package forward | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"github.com/coredns/coredns/plugin/pkg/dnstest" | 
					
						
							|  |  |  | 	"github.com/coredns/coredns/plugin/pkg/fuzz" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var f *Forward | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 20:19:45 +08:00
										 |  |  | // abuse init to setup an environment to test against. This start another server to that will | 
					
						
							| 
									
										
										
										
											2019-08-25 19:00:59 +00:00
										 |  |  | // reflect responses. | 
					
						
							|  |  |  | func init() { | 
					
						
							|  |  |  | 	f = New() | 
					
						
							|  |  |  | 	s := dnstest.NewServer(r{}.reflectHandler) | 
					
						
							|  |  |  | 	f.proxies = append(f.proxies, NewProxy(s.Addr, "tcp")) | 
					
						
							|  |  |  | 	f.proxies = append(f.proxies, NewProxy(s.Addr, "udp")) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Fuzz fuzzes forward. | 
					
						
							|  |  |  | func Fuzz(data []byte) int { | 
					
						
							| 
									
										
										
										
											2019-08-26 09:33:20 +00:00
										 |  |  | 	return fuzz.Do(f, data) | 
					
						
							| 
									
										
										
										
											2019-08-25 19:00:59 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type r struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (r r) reflectHandler(w dns.ResponseWriter, req *dns.Msg) { | 
					
						
							|  |  |  | 	m := new(dns.Msg) | 
					
						
							|  |  |  | 	m.SetReply(req) | 
					
						
							|  |  |  | 	w.WriteMsg(m) | 
					
						
							|  |  |  | } |