mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	plugin/forward: Continue waiting after receiving malformed responses (#6014)
* forward: continue waiting after malformed responses Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * add test Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * fix test Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * clean up Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * clean up Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move test to /test/. Add build tag. Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * install libpcap-dev for e2e tests Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * sudo the test Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove stray err check Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * disable the test Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * use -exec flag to run test binary as root Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * run new test by itself in a new workflow Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * fix test name Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * only for udp Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove libpcap test workflow action Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * remove test, since it cant run in ci Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * and remove gopacket package Signed-off-by: Chris O'Haver <cohaver@infoblox.com> --------- Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
		| @@ -7,6 +7,7 @@ package proxy | |||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"io" | 	"io" | ||||||
|  | 	"net" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"sync/atomic" | 	"sync/atomic" | ||||||
| 	"time" | 	"time" | ||||||
| @@ -117,11 +118,20 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, opts Options | |||||||
| 	for { | 	for { | ||||||
| 		ret, err = pc.c.ReadMsg() | 		ret, err = pc.c.ReadMsg() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			pc.c.Close() // not giving it back | 			// For UDP, if the error is not a network error keep waiting for a valid response to prevent malformed | ||||||
|  | 			// spoofs from blocking the upstream response. | ||||||
|  | 			// In the case this is a legitimate malformed response from the upstream, this will result in a timeout. | ||||||
|  | 			if proto == "udp" { | ||||||
|  | 				if _, ok := err.(net.Error); !ok { | ||||||
|  | 					continue | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			pc.c.Close() // connection closed by peer, close the persistent connection | ||||||
| 			if err == io.EOF && cached { | 			if err == io.EOF && cached { | ||||||
| 				return nil, ErrCachedClosed | 				return nil, ErrCachedClosed | ||||||
| 			} | 			} | ||||||
| 			// recovery the origin Id after upstream. |  | ||||||
|  | 			// recover the origin Id after upstream. | ||||||
| 			if ret != nil { | 			if ret != nil { | ||||||
| 				ret.Id = originId | 				ret.Id = originId | ||||||
| 			} | 			} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user