Documentation ¶
Overview ¶
Package db is a generated GoMock package.
Index ¶
- Variables
- func AdditionalSectionForRecords(r Reader, a *dns.Msg, locID ID, qclass uint16, records []dns.RR) (weighted bool)
- func FindECS(m *dns.Msg) *dns.EDNS0_SUBNET
- func FindSOA(r Reader, zoneCut []byte, zoneCutString string, locID ID, a *dns.Msg)
- func GetNs(r Reader, q []byte, zonename string, class uint16, locID ID) (ns []dns.RR, err error)
- func HasRecord(msg *dns.Msg, record string, qtype uint16) bool
- func NewRand() *rand.Rand
- type ClosestKeyFinder
- type Context
- type DB
- type DBI
- type DataReader
- func (r *DataReader) Close()
- func (r *DataReader) Data(key []byte) ([]byte, error)
- func (r *DataReader) EcsLocation(q []byte, ecs *dns.EDNS0_SUBNET) (*Location, error)
- func (r *DataReader) Find(key []byte) ([]byte, error)
- func (r *DataReader) FindAnswer(q []byte, packedControlName []byte, qname string, qtype uint16, locID ID, ...) (bool, int)
- func (r *DataReader) FindLocation(qname []byte, ecs *dns.EDNS0_SUBNET, ip string) (loc *Location, err error)
- func (r *DataReader) ForEach(key []byte, f func(value []byte) error) (err error)
- func (r *DataReader) ForEachResourceRecord(domainName []byte, locID ID, parseRecord func(result []byte) error) error
- func (r *DataReader) IsAuthoritative(q []byte, locID ID) (ns bool, auth bool, zoneCut []byte, err error)
- func (r *DataReader) ResolverLocation(q []byte, ip string) (*Location, error)
- type ID
- type Location
- type MockClosestKeyFinder
- type MockClosestKeyFinderMockRecorder
- type MockContext
- type MockContextMockRecorder
- type MockDBI
- func (m *MockDBI) Close() error
- func (m *MockDBI) ClosestKeyFinder() ClosestKeyFinder
- func (m *MockDBI) EXPECT() *MockDBIMockRecorder
- func (m *MockDBI) Find(key []byte, context Context) ([]byte, error)
- func (m *MockDBI) FindMap(domain, mtype []byte, context Context) ([]byte, error)
- func (m *MockDBI) ForEach(key []byte, f func([]byte) error, context Context) error
- func (m *MockDBI) FreeContext(arg0 Context)
- func (m *MockDBI) GetLocationByMap(ipnet *net.IPNet, mapID []byte, context Context) ([]byte, uint8, error)
- func (m *MockDBI) GetStats() map[string]int64
- func (m *MockDBI) NewContext() Context
- func (m *MockDBI) Reload(path string) (DBI, error)
- type MockDBIMockRecorder
- func (mr *MockDBIMockRecorder) Close() *gomock.Call
- func (mr *MockDBIMockRecorder) ClosestKeyFinder() *gomock.Call
- func (mr *MockDBIMockRecorder) Find(key, context interface{}) *gomock.Call
- func (mr *MockDBIMockRecorder) FindMap(domain, mtype, context interface{}) *gomock.Call
- func (mr *MockDBIMockRecorder) ForEach(key, f, context interface{}) *gomock.Call
- func (mr *MockDBIMockRecorder) FreeContext(arg0 interface{}) *gomock.Call
- func (mr *MockDBIMockRecorder) GetLocationByMap(ipnet, mapID, context interface{}) *gomock.Call
- func (mr *MockDBIMockRecorder) GetStats() *gomock.Call
- func (mr *MockDBIMockRecorder) NewContext() *gomock.Call
- func (mr *MockDBIMockRecorder) Reload(path interface{}) *gomock.Call
- type MockReader
- func (m *MockReader) Close()
- func (m *MockReader) EXPECT() *MockReaderMockRecorder
- func (m *MockReader) EcsLocation(q []byte, ecs *dns.EDNS0_SUBNET) (*Location, error)
- func (m *MockReader) FindAnswer(q, packedControlName []byte, qname string, qtype uint16, loc Location, ...) (bool, bool)
- func (m_2 *MockReader) FindLocation(qname []byte, m *dns.Msg, ip string) (*dns.EDNS0_SUBNET, *Location, error)
- func (m *MockReader) ForEach(key []byte, f func([]byte) error) error
- func (m *MockReader) ForEachResourceRecord(domainName []byte, loc *Location, parseRecord func([]byte) error) error
- func (m *MockReader) IsAuthoritative(q []byte, loc *Location) (bool, bool, []byte, error)
- func (m *MockReader) ResolverLocation(q []byte, ip string) (*Location, error)
- type MockReaderMockRecorder
- func (mr *MockReaderMockRecorder) Close() *gomock.Call
- func (mr *MockReaderMockRecorder) EcsLocation(q, ecs interface{}) *gomock.Call
- func (mr *MockReaderMockRecorder) FindAnswer(q, packedControlName, qname, qtype, loc, a, maxAnswer interface{}) *gomock.Call
- func (mr *MockReaderMockRecorder) FindLocation(qname, m, ip interface{}) *gomock.Call
- func (mr *MockReaderMockRecorder) ForEach(key, f interface{}) *gomock.Call
- func (mr *MockReaderMockRecorder) ForEachResourceRecord(domainName, loc, parseRecord interface{}) *gomock.Call
- func (mr *MockReaderMockRecorder) IsAuthoritative(q, loc interface{}) *gomock.Call
- func (mr *MockReaderMockRecorder) ResolverLocation(q, ip interface{}) *gomock.Call
- type Reader
- type ResourceRecord
- type Wrs
- type WrsItem
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLocationMismatch is returned if the record is not matching the location ErrLocationMismatch = errors.New("Location mismatch") // ErrWildcardMismatch is returned if the record is a wildcard but we are not // looking for wildcard ErrWildcardMismatch = errors.New("Wildcard mismatch") )
var ErrReloadTimeout = errors.New("DB reload timeout")
ErrReloadTimeout - DB reload timeout
var ErrValidationKeyNotFound = errors.New("validation key not found in DB")
ErrValidationKeyNotFound - Key not found in DB file
var SeparateBitMap bool
Functions ¶
func AdditionalSectionForRecords ¶
func AdditionalSectionForRecords(r Reader, a *dns.Msg, locID ID, qclass uint16, records []dns.RR) (weighted bool)
AdditionalSectionForRecords given a list of records and a reader, add the required records to the Extra (additional) section. returns wether or not a weighted record was added to the additional section.
func FindECS ¶
func FindECS(m *dns.Msg) *dns.EDNS0_SUBNET
FindECS finds a EDNS0_SUBNET option in a DNS Msg. It returns a pointer to dns.EDNS0_SUBNET or nil when there is not such EDNS0 option.
func GetNs ¶
GetNs will find and return the authoritative NS for a specific domain `q`. `q` is in wire-format. This is not expecting that `q` is the actual qname which has NS records.
Types ¶
type ClosestKeyFinder ¶
type ClosestKeyFinder interface { // FindClosestKey checks DB if provided key exists or // closest smaller key FindClosestKey(key []byte, context Context) ([]byte, error) }
ClosestKeyFinder allows to search for closest smaller or equal key in the database
type Context ¶
type Context interface {
Reset()
}
Context interface is an ADT representing the state carried across queries to DBI like iterator state or potentially query cache
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB implements a customized db
func Open ¶
Open opens the named file read-only and returns a new db object. The file should exist and be a compatible (CDB or RDB) database file.
func (*DB) Destroy ¶
func (f *DB) Destroy()
Destroy destroys a DB. It marks it as destroyable. If there is no refCount it will close the db, if there is refcounts left, the last reference to call Reader.Close() will close the db.
func (*DB) Reload ¶
Reload reloads a DB. In case of immutable CDB it will return new DB and close the old one. In case of RocksDB, if path is the same as it was it tries to catch up with WAL and returns existing DB. If path is different it will return new DB and close the old one. The validationKey is used to verify that the format of the DB file is valid, by checking for the existence of a key that is known to exist. If the DB file is invalid, the old DB will continue to be used.
func (*DB) ValidateDbKey ¶
ValidateDbKey checks whether record of certain key is in db
type DBI ¶
type DBI interface { NewContext() Context Find(key []byte, context Context) ([]byte, error) ForEach(key []byte, f func(value []byte) error, context Context) error FreeContext(Context) FindMap(domain, mtype []byte, context Context) ([]byte, error) // GetLocationByMap returns the location ID, including the 2-byte header for long IDs. GetLocationByMap(ipnet *net.IPNet, mapID []byte, context Context) ([]byte, uint8, error) Close() error Reload(path string) (DBI, error) GetStats() map[string]int64 // Gets ClosestKeyFinder associated with DBI if it is supported, nil otherwise ClosestKeyFinder() ClosestKeyFinder }
DBI interface represents the pluggable API for the backing storage nolint:revive
type DataReader ¶
type DataReader struct {
// contains filtered or unexported fields
}
DataReader wraps an DB to carry a Context around. This structure will be able to perform DNS queries.
func (*DataReader) Close ¶
func (r *DataReader) Close()
Close close a reader. This puts back a context in the pool
func (*DataReader) Data ¶
func (r *DataReader) Data(key []byte) ([]byte, error)
Data returns the first data value for the given key. If no such record exists, it returns EOF.
func (*DataReader) EcsLocation ¶
func (r *DataReader) EcsLocation(q []byte, ecs *dns.EDNS0_SUBNET) (*Location, error)
EcsLocation find a Location ID that matches this Client Subnet. If we do not find a match, Location will be nil and ECS's SourceScope will be set to 0. If we find a match, Location will contain the matching LocationID and ECS option will have SourceScope set.
func (*DataReader) Find ¶
func (r *DataReader) Find(key []byte) ([]byte, error)
Find returns the first data value for the given key as a byte slice. Find is the same as FindStart followed by FindNext.
func (*DataReader) FindAnswer ¶
func (r *DataReader) FindAnswer(q []byte, packedControlName []byte, qname string, qtype uint16, locID ID, a *dns.Msg, maxAnswer int) (bool, int)
FindAnswer will find answers for a given query q
func (*DataReader) FindLocation ¶
func (r *DataReader) FindLocation(qname []byte, ecs *dns.EDNS0_SUBNET, ip string) (loc *Location, err error)
FindLocation find a Location given a wired format qname, *dns.Msg and a resolver IP First, it tries to find a matching location for a subnet client. Then, it tries to find a matching location for a resolver IP. return nil for Location if no location were found. error will be set on error.
func (*DataReader) ForEach ¶
func (r *DataReader) ForEach(key []byte, f func(value []byte) error) (err error)
ForEach calls a function for each key match. The function takes a byte slice as a value and return an error. if error is not nil, the loop will stop.
func (*DataReader) ForEachResourceRecord ¶
func (r *DataReader) ForEachResourceRecord(domainName []byte, locID ID, parseRecord func(result []byte) error) error
ForEachResourceRecord calls parseRecord for each RR record in DB in provided AND default location
func (*DataReader) IsAuthoritative ¶
func (r *DataReader) IsAuthoritative(q []byte, locID ID) (ns bool, auth bool, zoneCut []byte, err error)
IsAuthoritative find whether or not we are authoritative and have NS records for the given domain. Starting from the original qname, it iterates through every possible parent domain by removing 1 label at a time until it find a match, or there is no more labels. It returns a boolean if we have NS records, and if we are authoritative. And the packed zone cut for which we found NS/Auth.
If `ns` is True and `auth` is False: this is a delegation. If `ns` and `auth` are True, we are authoritative.
func (*DataReader) ResolverLocation ¶
func (r *DataReader) ResolverLocation(q []byte, ip string) (*Location, error)
ResolverLocation find the location associated with a client IP (resolver)
type ID ¶
type ID []byte
ID is an alias for []byte, used for Map IDs and Location IDs. It is always at least 2 bytes long. For long IDs, it contains the header and contents.
type Location ¶
type Location struct { MapID ID // The map in which we found the name. Mask uint8 // The subnet mask we found a match for. Used for ECS. LocID ID // The location ID. }
Location is a native representation of a DNS location representation. It holds: the MapID it belongs to For ECS MapID, the associated mask. The LocID, the location ID used to find matching records.
type MockClosestKeyFinder ¶
type MockClosestKeyFinder struct {
// contains filtered or unexported fields
}
MockClosestKeyFinder is a mock of ClosestKeyFinder interface
func NewMockClosestKeyFinder ¶
func NewMockClosestKeyFinder(ctrl *gomock.Controller) *MockClosestKeyFinder
NewMockClosestKeyFinder creates a new mock instance
func (*MockClosestKeyFinder) EXPECT ¶
func (m *MockClosestKeyFinder) EXPECT() *MockClosestKeyFinderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockClosestKeyFinder) FindClosestKey ¶
func (m *MockClosestKeyFinder) FindClosestKey(key []byte, context Context) ([]byte, error)
FindClosestKey mocks base method
type MockClosestKeyFinderMockRecorder ¶
type MockClosestKeyFinderMockRecorder struct {
// contains filtered or unexported fields
}
MockClosestKeyFinderMockRecorder is the mock recorder for MockClosestKeyFinder
func (*MockClosestKeyFinderMockRecorder) FindClosestKey ¶
func (mr *MockClosestKeyFinderMockRecorder) FindClosestKey(key, context interface{}) *gomock.Call
FindClosestKey indicates an expected call of FindClosestKey
type MockContext ¶
type MockContext struct {
// contains filtered or unexported fields
}
MockContext is a mock of Context interface
func NewMockContext ¶
func NewMockContext(ctrl *gomock.Controller) *MockContext
NewMockContext creates a new mock instance
func (*MockContext) EXPECT ¶
func (m *MockContext) EXPECT() *MockContextMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockContextMockRecorder ¶
type MockContextMockRecorder struct {
// contains filtered or unexported fields
}
MockContextMockRecorder is the mock recorder for MockContext
func (*MockContextMockRecorder) Reset ¶
func (mr *MockContextMockRecorder) Reset() *gomock.Call
Reset indicates an expected call of Reset
type MockDBI ¶
type MockDBI struct {
// contains filtered or unexported fields
}
MockDBI is a mock of DBI interface
func NewMockDBI ¶
func NewMockDBI(ctrl *gomock.Controller) *MockDBI
NewMockDBI creates a new mock instance
func (*MockDBI) ClosestKeyFinder ¶
func (m *MockDBI) ClosestKeyFinder() ClosestKeyFinder
ClosestKeyFinder mocks base method
func (*MockDBI) EXPECT ¶
func (m *MockDBI) EXPECT() *MockDBIMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockDBI) FreeContext ¶
FreeContext mocks base method
type MockDBIMockRecorder ¶
type MockDBIMockRecorder struct {
// contains filtered or unexported fields
}
MockDBIMockRecorder is the mock recorder for MockDBI
func (*MockDBIMockRecorder) Close ¶
func (mr *MockDBIMockRecorder) Close() *gomock.Call
Close indicates an expected call of Close
func (*MockDBIMockRecorder) ClosestKeyFinder ¶
func (mr *MockDBIMockRecorder) ClosestKeyFinder() *gomock.Call
ClosestKeyFinder indicates an expected call of ClosestKeyFinder
func (*MockDBIMockRecorder) Find ¶
func (mr *MockDBIMockRecorder) Find(key, context interface{}) *gomock.Call
Find indicates an expected call of Find
func (*MockDBIMockRecorder) FindMap ¶
func (mr *MockDBIMockRecorder) FindMap(domain, mtype, context interface{}) *gomock.Call
FindMap indicates an expected call of FindMap
func (*MockDBIMockRecorder) ForEach ¶
func (mr *MockDBIMockRecorder) ForEach(key, f, context interface{}) *gomock.Call
ForEach indicates an expected call of ForEach
func (*MockDBIMockRecorder) FreeContext ¶
func (mr *MockDBIMockRecorder) FreeContext(arg0 interface{}) *gomock.Call
FreeContext indicates an expected call of FreeContext
func (*MockDBIMockRecorder) GetLocationByMap ¶
func (mr *MockDBIMockRecorder) GetLocationByMap(ipnet, mapID, context interface{}) *gomock.Call
GetLocationByMap indicates an expected call of GetLocationByMap
func (*MockDBIMockRecorder) GetStats ¶
func (mr *MockDBIMockRecorder) GetStats() *gomock.Call
GetStats indicates an expected call of GetStats
func (*MockDBIMockRecorder) NewContext ¶
func (mr *MockDBIMockRecorder) NewContext() *gomock.Call
NewContext indicates an expected call of NewContext
func (*MockDBIMockRecorder) Reload ¶
func (mr *MockDBIMockRecorder) Reload(path interface{}) *gomock.Call
Reload indicates an expected call of Reload
type MockReader ¶
type MockReader struct {
// contains filtered or unexported fields
}
MockReader is a mock of Reader interface
func NewMockReader ¶
func NewMockReader(ctrl *gomock.Controller) *MockReader
NewMockReader creates a new mock instance
func (*MockReader) EXPECT ¶
func (m *MockReader) EXPECT() *MockReaderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockReader) EcsLocation ¶
func (m *MockReader) EcsLocation(q []byte, ecs *dns.EDNS0_SUBNET) (*Location, error)
EcsLocation mocks base method
func (*MockReader) FindAnswer ¶
func (m *MockReader) FindAnswer(q, packedControlName []byte, qname string, qtype uint16, loc Location, a *dns.Msg, maxAnswer int) (bool, bool)
FindAnswer mocks base method
func (*MockReader) FindLocation ¶
func (m_2 *MockReader) FindLocation(qname []byte, m *dns.Msg, ip string) (*dns.EDNS0_SUBNET, *Location, error)
FindLocation mocks base method
func (*MockReader) ForEach ¶
func (m *MockReader) ForEach(key []byte, f func([]byte) error) error
ForEach mocks base method
func (*MockReader) ForEachResourceRecord ¶
func (m *MockReader) ForEachResourceRecord(domainName []byte, loc *Location, parseRecord func([]byte) error) error
ForEachResourceRecord mocks base method
func (*MockReader) IsAuthoritative ¶
IsAuthoritative mocks base method
func (*MockReader) ResolverLocation ¶
func (m *MockReader) ResolverLocation(q []byte, ip string) (*Location, error)
ResolverLocation mocks base method
type MockReaderMockRecorder ¶
type MockReaderMockRecorder struct {
// contains filtered or unexported fields
}
MockReaderMockRecorder is the mock recorder for MockReader
func (*MockReaderMockRecorder) Close ¶
func (mr *MockReaderMockRecorder) Close() *gomock.Call
Close indicates an expected call of Close
func (*MockReaderMockRecorder) EcsLocation ¶
func (mr *MockReaderMockRecorder) EcsLocation(q, ecs interface{}) *gomock.Call
EcsLocation indicates an expected call of EcsLocation
func (*MockReaderMockRecorder) FindAnswer ¶
func (mr *MockReaderMockRecorder) FindAnswer(q, packedControlName, qname, qtype, loc, a, maxAnswer interface{}) *gomock.Call
FindAnswer indicates an expected call of FindAnswer
func (*MockReaderMockRecorder) FindLocation ¶
func (mr *MockReaderMockRecorder) FindLocation(qname, m, ip interface{}) *gomock.Call
FindLocation indicates an expected call of FindLocation
func (*MockReaderMockRecorder) ForEach ¶
func (mr *MockReaderMockRecorder) ForEach(key, f interface{}) *gomock.Call
ForEach indicates an expected call of ForEach
func (*MockReaderMockRecorder) ForEachResourceRecord ¶
func (mr *MockReaderMockRecorder) ForEachResourceRecord(domainName, loc, parseRecord interface{}) *gomock.Call
ForEachResourceRecord indicates an expected call of ForEachResourceRecord
func (*MockReaderMockRecorder) IsAuthoritative ¶
func (mr *MockReaderMockRecorder) IsAuthoritative(q, loc interface{}) *gomock.Call
IsAuthoritative indicates an expected call of IsAuthoritative
func (*MockReaderMockRecorder) ResolverLocation ¶
func (mr *MockReaderMockRecorder) ResolverLocation(q, ip interface{}) *gomock.Call
ResolverLocation indicates an expected call of ResolverLocation
type Reader ¶
type Reader interface { FindLocation(qname []byte, ecs *dns.EDNS0_SUBNET, ip string) (loc *Location, err error) IsAuthoritative(q []byte, locID ID) (ns bool, auth bool, zoneCut []byte, err error) FindAnswer(q []byte, packedControlName []byte, qname string, qtype uint16, locID ID, a *dns.Msg, maxAnswer int) (bool, int) EcsLocation(q []byte, ecs *dns.EDNS0_SUBNET) (*Location, error) ResolverLocation(q []byte, ip string) (*Location, error) ForEach(key []byte, f func(value []byte) error) (err error) ForEachResourceRecord(domainName []byte, locID ID, parseRecord func(result []byte) error) error Close() // contains filtered or unexported methods }
Reader will be able to perform DNS queries. It wraps DB to carry query context and properly count reference count to DB
type ResourceRecord ¶
ResourceRecord holds the representation of a row from DB
func ExtractRRFromRow ¶
func ExtractRRFromRow(row []byte, wildcard bool) (rr ResourceRecord, err error)
ExtractRRFromRow extracts a ResourceRecord from a DB row. A DB row contains data ResourceRecord information: qtype (2) ch (1) recordloc (2+)? ttl (4) ttd (8) weight (4)? rdata (vlen) recordloc is present only if ch == '+' + 1 or ch == '*' + 1 weight is only present if qtype is A or AAAA It returns a pointer to a ResourceRecord, nil when not a proper match. nil is returned when the row is not matching the specific filters (e.g Location or wildcard).
type Wrs ¶
Wrs Weighted Random Sample
func (*Wrs) AAAARecord ¶
AAAARecord returns the weighted random sample for AAAA qtype if there is any.
func (*Wrs) Add ¶
func (w *Wrs) Add(rec ResourceRecord, data []byte) error
Add adds a ResourceRecord to Wrs if its randomly computed weight is greater then the existing record.
func (*Wrs) WeightedAnswer ¶
WeightedAnswer returns true if the answer selected a subset of possible results.