handler

package
v0.0.0-...-a012604 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2019 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NSecTypes = []uint16{dns.TypeRRSIG, dns.TypeNSEC}
)

Functions

func ChooseIp

func ChooseIp(ips []IP_RR, weighted bool) int

func GetSourceIp

func GetSourceIp(request *request.Request) net.IP

func GetSourceSubnet

func GetSourceSubnet(request *request.Request) string

func HandleHealthCheck

func HandleHealthCheck(h *Healthcheck) workerpool.JobHandler

func NSec

func NSec(name string, zone *Zone) dns.RR

func NewServer

func NewServer(config []ServerConfig) []dns.Server

func Sign

func Sign(rrs []dns.RR, qname string, record *Record) []dns.RR

Types

type ANAME_Record

type ANAME_Record struct {
	Location string `json:"location,omitempty"`
}

type CAA_RR

type CAA_RR struct {
	Tag   string `json:"tag"`
	Value string `json:"value"`
	Flag  uint8  `json:"flag"`
}

type CAA_RRSet

type CAA_RRSet struct {
	Ttl  uint32   `json:"ttl,omitempty"`
	Data []CAA_RR `json:"records,omitempty"`
}

type CNAME_RRSet

type CNAME_RRSet struct {
	Host string `json:"host"`
	Ttl  uint32 `json:"ttl,omitempty"`
}

type DnsRequestHandler

type DnsRequestHandler struct {
	Config         *HandlerConfig
	Zones          *iradix.Tree
	LastZoneUpdate time.Time
	Redis          *uperdis.Redis
	Logger         *logger.EventLogger
	RecordCache    *cache.Cache
	ZoneCache      *cache.Cache
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(config *HandlerConfig) *DnsRequestHandler

func (*DnsRequestHandler) A

func (h *DnsRequestHandler) A(name string, record *Record, ips []IP_RR) (answers []dns.RR)

func (*DnsRequestHandler) AAAA

func (h *DnsRequestHandler) AAAA(name string, record *Record, ips []IP_RR) (answers []dns.RR)

func (*DnsRequestHandler) CAA

func (h *DnsRequestHandler) CAA(name string, record *Record) (answers []dns.RR)

func (*DnsRequestHandler) CNAME

func (h *DnsRequestHandler) CNAME(name string, record *Record) (answers []dns.RR)

func (*DnsRequestHandler) FetchRecord

func (h *DnsRequestHandler) FetchRecord(qname string, logData map[string]interface{}) (*Record, int)

func (*DnsRequestHandler) Filter

func (h *DnsRequestHandler) Filter(request *request.Request, rrset *IP_RRSet, logData map[string]interface{}) []IP_RR

func (*DnsRequestHandler) FindCAA

func (h *DnsRequestHandler) FindCAA(record *Record) *Record

func (*DnsRequestHandler) GetRecord

func (h *DnsRequestHandler) GetRecord(qname string) (record *Record, rcode int)

func (*DnsRequestHandler) HandleRequest

func (h *DnsRequestHandler) HandleRequest(state *request.Request)

func (*DnsRequestHandler) LoadLocation

func (h *DnsRequestHandler) LoadLocation(location string, z *Zone) *Record

func (*DnsRequestHandler) LoadZone

func (h *DnsRequestHandler) LoadZone(zone string) *Zone

func (*DnsRequestHandler) LoadZones

func (h *DnsRequestHandler) LoadZones()

func (*DnsRequestHandler) LogRequest

func (h *DnsRequestHandler) LogRequest(data map[string]interface{}, startTime time.Time, responseCode int)

func (*DnsRequestHandler) MX

func (h *DnsRequestHandler) MX(name string, record *Record) (answers []dns.RR)

func (*DnsRequestHandler) Matches

func (h *DnsRequestHandler) Matches(qname string) string

func (*DnsRequestHandler) NS

func (h *DnsRequestHandler) NS(name string, record *Record) (answers []dns.RR)

func (*DnsRequestHandler) PTR

func (h *DnsRequestHandler) PTR(name string, record *Record) (answers []dns.RR)

func (*DnsRequestHandler) SRV

func (h *DnsRequestHandler) SRV(name string, record *Record) (answers []dns.RR)

func (*DnsRequestHandler) SetLocation

func (h *DnsRequestHandler) SetLocation(location string, z *Zone, val *Record)

func (*DnsRequestHandler) ShutDown

func (h *DnsRequestHandler) ShutDown()

func (*DnsRequestHandler) TLSA

func (h *DnsRequestHandler) TLSA(name string, record *Record) (answers []dns.RR)

func (*DnsRequestHandler) TXT

func (h *DnsRequestHandler) TXT(name string, record *Record) (answers []dns.RR)

type GeoIp

type GeoIp struct {
	Enable    bool
	CountryDB *maxminddb.Reader
	ASNDB     *maxminddb.Reader
}

func NewGeoIp

func NewGeoIp(config *GeoIpConfig) *GeoIp

func (*GeoIp) GetASN

func (g *GeoIp) GetASN(ip net.IP) (uint, error)

func (*GeoIp) GetGeoLocation

func (g *GeoIp) GetGeoLocation(ip net.IP) (latitude float64, longitude float64, country string, err error)

func (*GeoIp) GetMinimumDistance

func (g *GeoIp) GetMinimumDistance(sourceIp net.IP, ips []IP_RR, logData map[string]interface{}) []IP_RR

func (*GeoIp) GetSameASN

func (g *GeoIp) GetSameASN(sourceIp net.IP, ips []IP_RR, logData map[string]interface{}) []IP_RR

func (*GeoIp) GetSameCountry

func (g *GeoIp) GetSameCountry(sourceIp net.IP, ips []IP_RR, logData map[string]interface{}) []IP_RR

type GeoIpConfig

type GeoIpConfig struct {
	Enable    bool   `json:"enable,omitempty"`
	CountryDB string `json:"country_db,omitempty"`
	ASNDB     string `json:"asn_db,omitempty"`
}

type HandlerConfig

type HandlerConfig struct {
	Upstream          []UpstreamConfig    `json:"upstream,omitempty"`
	GeoIp             GeoIpConfig         `json:"geoip,omitempty"`
	HealthCheck       HealthcheckConfig   `json:"healthcheck,omitempty"`
	MaxTtl            int                 `json:"max_ttl,omitempty"`
	CacheTimeout      int                 `json:"cache_timeout,omitempty"`
	ZoneReload        int                 `json:"zone_reload,omitempty"`
	LogSourceLocation bool                `json:"log_source_location,omitempty"`
	UpstreamFallback  bool                `json:"upstream_fallback,omitempty"`
	Redis             uperdis.RedisConfig `json:"redis,omitempty"`
	Log               logger.LogConfig    `json:"log,omitempty"`
}

type HealthCheckItem

type HealthCheckItem struct {
	Protocol  string    `json:"protocol,omitempty"`
	Uri       string    `json:"uri,omitempty"`
	Port      int       `json:"port,omitempty"`
	Status    int       `json:"status,omitempty"`
	LastCheck time.Time `json:"lastcheck,omitempty"`
	Timeout   int       `json:"timeout,omitempty"`
	UpCount   int       `json:"up_count,omitempty"`
	DownCount int       `json:"down_count,omitempty"`
	Enable    bool      `json:"enable,omitempty"`
	DomainId  string    `json:"domain_uuid, omitempty"`
	Host      string    `json:"-"`
	Ip        string    `json:"-"`
	Error     error     `json:"-"`
}

type Healthcheck

type Healthcheck struct {
	Enable bool
	// contains filtered or unexported fields
}

func NewHealthcheck

func NewHealthcheck(config *HealthcheckConfig, redisConfigServer *uperdis.Redis) *Healthcheck

func (*Healthcheck) FilterHealthcheck

func (h *Healthcheck) FilterHealthcheck(qname string, rrset *IP_RRSet) []IP_RR

func (*Healthcheck) ShutDown

func (h *Healthcheck) ShutDown()

func (*Healthcheck) Start

func (h *Healthcheck) Start()

func (*Healthcheck) Transfer

func (h *Healthcheck) Transfer()

type HealthcheckConfig

type HealthcheckConfig struct {
	Enable             bool                `json:"enable,omitempty"`
	MaxRequests        int                 `json:"max_requests,omitempty"`
	MaxPendingRequests int                 `json:"max_pending_requests,omitempty"`
	UpdateInterval     int                 `json:"update_interval,omitempty"`
	CheckInterval      int                 `json:"check_interval,omitempty"`
	RedisStatusServer  uperdis.RedisConfig `json:"redis,omitempty"`
	Log                logger.LogConfig    `json:"log,omitempty"`
}

type IP_RR

type IP_RR struct {
	Weight  int      `json:"weight,omitempty"`
	Ip      net.IP   `json:"ip"`
	Country []string `json:"country,omitempty"`
	ASN     []uint   `json:"asn,omitempty"`
}

func (*IP_RR) UnmarshalJSON

func (iprr *IP_RR) UnmarshalJSON(data []byte) error

type IP_RRSet

type IP_RRSet struct {
	FilterConfig      IpFilterConfig      `json:"filter,omitempty"`
	HealthCheckConfig IpHealthCheckConfig `json:"health_check,omitempty"`
	Ttl               uint32              `json:"ttl,omitempty"`
	Data              []IP_RR             `json:"records,omitempty"`
}

type IpFilterConfig

type IpFilterConfig struct {
	Count     string `json:"count,omitempty"`      // "multi", "single"
	Order     string `json:"order,omitmpty"`       // "weighted", "rr", "none"
	GeoFilter string `json:"geo_filter,omitempty"` // "country", "location", "asn", "asn+country", "none"
}

type IpHealthCheckConfig

type IpHealthCheckConfig struct {
	Protocol  string `json:"protocol,omitempty"`
	Uri       string `json:"uri,omitempty"`
	Port      int    `json:"port,omitempty"`
	Timeout   int    `json:"timeout,omitempty"`
	UpCount   int    `json:"up_count,omitempty"`
	DownCount int    `json:"down_count,omitempty"`
	Enable    bool   `json:"enable,omitempty"`
}

type Limiter

type Limiter struct {
	Size       time.Duration
	LastUpdate time.Time
	Mutex      *sync.Mutex
}

type MX_RR

type MX_RR struct {
	Host       string `json:"host"`
	Preference uint16 `json:"preference"`
}

type MX_RRSet

type MX_RRSet struct {
	Ttl  uint32  `json:"ttl,omitempty"`
	Data []MX_RR `json:"records,omitempty"`
}

type NS_RR

type NS_RR struct {
	Host string `json:"host"`
}

type NS_RRSet

type NS_RRSet struct {
	Ttl  uint32  `json:"ttl,omitempty"`
	Data []NS_RR `json:"records,omitempty"`
}

type PTR_RRSet

type PTR_RRSet struct {
	Domain string `json:"domain"`
	Ttl    uint32 `json:"ttl,omitempty"`
}

type RRSets

type RRSets struct {
	A     IP_RRSet      `json:"a,omitempty"`
	AAAA  IP_RRSet      `json:"aaaa,omitempty"`
	TXT   TXT_RRSet     `json:"txt,omitempty"`
	CNAME *CNAME_RRSet  `json:"cname,omitempty"`
	NS    NS_RRSet      `json:"ns,omitempty"`
	MX    MX_RRSet      `json:"mx,omitempty"`
	SRV   SRV_RRSet     `json:"srv,omitempty"`
	CAA   CAA_RRSet     `json:"caa,omitempty"`
	PTR   *PTR_RRSet    `json:"ptr,omitempty"`
	TLSA  TLSA_RRSet    `json:"tlsa,omitempty"`
	ANAME *ANAME_Record `json:"aname,omitempty"`
}

type RateLimiter

type RateLimiter struct {
	Limiters  *cache.Cache
	MaxTime   time.Duration
	TimeStep  time.Duration
	Config    *RateLimiterConfig
	WhiteList map[string]interface{}
	BlackList map[string]interface{}
}

func NewRateLimiter

func NewRateLimiter(config *RateLimiterConfig) *RateLimiter

func (*RateLimiter) CanHandle

func (rl *RateLimiter) CanHandle(key string) bool

type RateLimiterConfig

type RateLimiterConfig struct {
	Enable    bool     `json:"enable"`
	Burst     int      `json:"burst"`
	Rate      int      `json:"rate"`
	WhiteList []string `json:"whitelist"`
	BlackList []string `json:"blacklist"`
}

type Record

type Record struct {
	RRSets
	Zone *Zone  `json:"-"`
	Name string `json:"-"`
}

type SOA_RRSet

type SOA_RRSet struct {
	Ns      string   `json:"ns"`
	MBox    string   `json:"MBox"`
	Data    *dns.SOA `json:"-"`
	Ttl     uint32   `json:"ttl,omitempty"`
	Refresh uint32   `json:"refresh"`
	Retry   uint32   `json:"retry"`
	Expire  uint32   `json:"expire"`
	MinTtl  uint32   `json:"minttl"`
	Serial  uint32   `json:"serial"`
}

type SRV_RR

type SRV_RR struct {
	Target   string `json:"target"`
	Priority uint16 `json:"priority"`
	Weight   uint16 `json:"weight"`
	Port     uint16 `json:"port"`
}

type SRV_RRSet

type SRV_RRSet struct {
	Ttl  uint32   `json:"ttl,omitempty"`
	Data []SRV_RR `json:"records,omitempty"`
}

type ServerConfig

type ServerConfig struct {
	Ip       string    `json:"ip,omitempty"`
	Port     int       `json:"port,omitempty"`
	Protocol string    `json:"protocol,omitempty"`
	Tls      TlsConfig `json:"tls,omitempty"`
}

type TLSA_RR

type TLSA_RR struct {
	Usage        uint8  `json:"usage"`
	Selector     uint8  `json:"selector"`
	MatchingType uint8  `json:"matching_type"`
	Certificate  string `json:"certificate"`
}

type TLSA_RRSet

type TLSA_RRSet struct {
	Ttl  uint32    `json:"ttl,omitempty"`
	Data []TLSA_RR `json:"records,omitempty"`
}

type TXT_RR

type TXT_RR struct {
	Text string `json:"text"`
}

type TXT_RRSet

type TXT_RRSet struct {
	Ttl  uint32   `json:"ttl,omitempty"`
	Data []TXT_RR `json:"records,omitempty"`
}

type TlsConfig

type TlsConfig struct {
	Enable   bool   `json:"enable"`
	CertPath string `json:"cert_path"`
	KeyPath  string `json:"key_path"`
	CaPath   string `json:"ca_path"`
}

type Upstream

type Upstream struct {
	// contains filtered or unexported fields
}

func NewUpstream

func NewUpstream(config []UpstreamConfig) *Upstream

func (*Upstream) Query

func (u *Upstream) Query(location string, qtype uint16) ([]dns.RR, int)

type UpstreamConfig

type UpstreamConfig struct {
	Ip       string `json:"ip,omitempty"`
	Port     int    `json:"port,omitempty"`
	Protocol string `json:"protocol,omitempty"`
	Timeout  int    `json:"timeout,omitempty"`
}

type UpstreamConnection

type UpstreamConnection struct {
	// contains filtered or unexported fields
}

type Zone

type Zone struct {
	Name      string
	Config    ZoneConfig
	Locations map[string]struct{}
	ZSK       *ZoneKey
	KSK       *ZoneKey
	DnsKeySig dns.RR
}

type ZoneConfig

type ZoneConfig struct {
	DomainId        string     `json:"domain_id,omitempty"`
	SOA             *SOA_RRSet `json:"soa,omitempty"`
	DnsSec          bool       `json:"dnssec,omitempty"`
	CnameFlattening bool       `json:"cname_flattening,omitempty"`
}

type ZoneKey

type ZoneKey struct {
	DnsKey        *dns.DNSKEY
	PrivateKey    crypto.PrivateKey
	KeyInception  uint32
	KeyExpiration uint32
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL