| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | package file
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 	"github.com/miekg/coredns/middleware"
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | 	"github.com/miekg/coredns/middleware/file/tree"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Zone struct {
 | 
					
						
							|  |  |  | 	SOA  *dns.SOA
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 	SIG  []dns.RR
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | 	name string
 | 
					
						
							|  |  |  | 	*tree.Tree
 | 
					
						
							| 
									
										
										
										
											2016-04-03 09:02:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	TransferTo   []string
 | 
					
						
							|  |  |  | 	TransferFrom []string
 | 
					
						
							|  |  |  | 	Expired      *bool
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-02 16:56:16 +01:00
										 |  |  | // NewZone returns a new zone.
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | func NewZone(name string) *Zone {
 | 
					
						
							| 
									
										
										
										
											2016-04-03 09:02:34 +01:00
										 |  |  | 	z := &Zone{name: dns.Fqdn(name), Tree: &tree.Tree{}, Expired: new(bool)}
 | 
					
						
							|  |  |  | 	*z.Expired = false
 | 
					
						
							|  |  |  | 	return z
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 10:53:23 +01:00
										 |  |  | // Copy copies a zone *without* copying the zone's content. It is not a deep copy.
 | 
					
						
							|  |  |  | func (z *Zone) Copy() *Zone {
 | 
					
						
							|  |  |  | 	z1 := NewZone(z.name)
 | 
					
						
							|  |  |  | 	z1.TransferTo = z.TransferTo
 | 
					
						
							|  |  |  | 	z1.TransferFrom = z.TransferFrom
 | 
					
						
							|  |  |  | 	z1.Expired = z.Expired
 | 
					
						
							| 
									
										
										
										
											2016-04-07 07:42:58 +01:00
										 |  |  | 	z1.SOA = z.SOA
 | 
					
						
							|  |  |  | 	z1.SIG = z.SIG
 | 
					
						
							| 
									
										
										
										
											2016-04-05 10:53:23 +01:00
										 |  |  | 	return z1
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-02 16:56:16 +01:00
										 |  |  | // Insert inserts r into z.
 | 
					
						
							|  |  |  | func (z *Zone) Insert(r dns.RR) { z.Tree.Insert(r) }
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-02 16:56:16 +01:00
										 |  |  | // Delete deletes r from z.
 | 
					
						
							|  |  |  | func (z *Zone) Delete(r dns.RR) { z.Tree.Delete(r) }
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 09:02:34 +01:00
										 |  |  | // TransferAllowed checks if incoming request for transferring the zone is allowed according to the ACLs.
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | func (z *Zone) TransferAllowed(state middleware.State) bool {
 | 
					
						
							| 
									
										
										
										
											2016-04-03 09:02:34 +01:00
										 |  |  | 	for _, t := range z.TransferTo {
 | 
					
						
							|  |  |  | 		if t == "*" {
 | 
					
						
							|  |  |  | 			return true
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2016-04-05 07:37:05 +01:00
										 |  |  | 	// TODO(miek): future matching against IP/CIDR notations
 | 
					
						
							| 
									
										
										
										
											2016-04-03 09:02:34 +01:00
										 |  |  | 	return false
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // All returns all records from the zone, the first record will be the SOA record,
 | 
					
						
							|  |  |  | // otionally followed by all RRSIG(SOA)s.
 | 
					
						
							|  |  |  | func (z *Zone) All() []dns.RR {
 | 
					
						
							|  |  |  | 	records := []dns.RR{}
 | 
					
						
							|  |  |  | 	allNodes := z.Tree.All()
 | 
					
						
							|  |  |  | 	for _, a := range allNodes {
 | 
					
						
							|  |  |  | 		records = append(records, a.All()...)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if len(z.SIG) > 0 {
 | 
					
						
							|  |  |  | 		records = append(z.SIG, records...)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return append([]dns.RR{z.SOA}, records...)
 | 
					
						
							|  |  |  | }
 |