| 
									
										
										
										
											2022-03-18 14:11:14 +00:00
										 |  |  | //go:build gofuzz
 | 
					
						
							| 
									
										
										
										
											2019-08-25 19:00:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | package forward
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"github.com/coredns/coredns/plugin/pkg/dnstest"
 | 
					
						
							|  |  |  | 	"github.com/coredns/coredns/plugin/pkg/fuzz"
 | 
					
						
							| 
									
										
										
										
											2023-05-25 15:09:56 +02:00
										 |  |  | 	"github.com/coredns/coredns/plugin/pkg/proxy"
 | 
					
						
							| 
									
										
										
										
											2019-08-25 19:00:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"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)
 | 
					
						
							| 
									
										
										
										
											2024-10-24 19:33:58 +01:00
										 |  |  | 	f.SetProxy(proxy.NewProxy("FuzzForwardPlugin1", s.Addr, "tcp"))
 | 
					
						
							|  |  |  | 	f.SetProxy(proxy.NewProxy("FuzzForwardPlugin2", s.Addr, "udp"))
 | 
					
						
							| 
									
										
										
										
											2019-08-25 19:00:59 +00:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 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)
 | 
					
						
							|  |  |  | }
 |