| 
									
										
										
										
											2022-09-07 14:53:30 +01:00
										 |  |  | // Package bufsize implements a plugin that clamps EDNS0 buffer size preventing packet fragmentation.
 | 
					
						
							| 
									
										
										
										
											2019-11-10 08:10:12 +00:00
										 |  |  | package bufsize
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"context"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/coredns/coredns/plugin"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Bufsize implements bufsize plugin.
 | 
					
						
							|  |  |  | type Bufsize struct {
 | 
					
						
							|  |  |  | 	Next plugin.Handler
 | 
					
						
							|  |  |  | 	Size int
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ServeDNS implements the plugin.Handler interface.
 | 
					
						
							|  |  |  | func (buf Bufsize) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | 
					
						
							| 
									
										
										
										
											2022-09-07 14:53:30 +01:00
										 |  |  | 	if option := r.IsEdns0(); option != nil && int(option.UDPSize()) > buf.Size {
 | 
					
						
							| 
									
										
										
										
											2019-11-10 08:10:12 +00:00
										 |  |  | 		option.SetUDPSize(uint16(buf.Size))
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return plugin.NextOrFailure(buf.Name(), buf.Next, ctx, w, r)
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Name implements the Handler interface.
 | 
					
						
							|  |  |  | func (buf Bufsize) Name() string { return "bufsize" }
 |