| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | package file | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2019-08-30 13:47:27 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/file/tree" | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 	"github.com/coredns/coredns/plugin/transfer" | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | // Transfer implements the transfer.Transfer interface. | 
					
						
							|  |  |  | func (f File) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) { | 
					
						
							|  |  |  | 	z, ok := f.Zones.Z[zone] | 
					
						
							|  |  |  | 	if !ok || z == nil { | 
					
						
							|  |  |  | 		return nil, transfer.ErrNotAuthoritative | 
					
						
							| 
									
										
										
										
											2020-07-08 09:00:26 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 	return z.Transfer(serial) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-08 09:00:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | // Transfer transfers a zone with serial in the returned channel and implements IXFR fallback, by just | 
					
						
							|  |  |  | // sending a single SOA record. | 
					
						
							|  |  |  | func (z *Zone) Transfer(serial uint32) (<-chan []dns.RR, error) { | 
					
						
							| 
									
										
										
										
											2019-08-30 13:47:27 +01:00
										 |  |  | 	// get soa and apex | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 	apex, err := z.ApexIfDefined() | 
					
						
							| 
									
										
										
										
											2019-08-30 13:47:27 +01:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 		return nil, err | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 	ch := make(chan []dns.RR) | 
					
						
							| 
									
										
										
										
											2019-07-03 07:01:57 +01:00
										 |  |  | 	go func() { | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 		if serial != 0 && apex[0].(*dns.SOA).Serial == serial { // ixfr fallback, only send SOA | 
					
						
							|  |  |  | 			ch <- []dns.RR{apex[0]} | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 			close(ch) | 
					
						
							|  |  |  | 			return | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-08-30 13:47:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 		ch <- apex | 
					
						
							|  |  |  | 		z.Walk(func(e *tree.Elem, _ map[uint16][]dns.RR) error { ch <- e.All(); return nil }) | 
					
						
							|  |  |  | 		ch <- []dns.RR{apex[0]} | 
					
						
							| 
									
										
										
										
											2019-08-30 13:47:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 		close(ch) | 
					
						
							|  |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2020-07-08 09:00:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 11:30:39 -07:00
										 |  |  | 	return ch, nil | 
					
						
							| 
									
										
										
										
											2019-08-26 08:14:43 +00:00
										 |  |  | } |