Feature: add fallback filters (#105)

This commit is contained in:
宋辰文
2019-09-15 13:36:45 +08:00
committed by Dreamacro
parent 09f435d928
commit b76737bdbb
5 changed files with 127 additions and 32 deletions

26
dns/filters.go Normal file
View File

@ -0,0 +1,26 @@
package dns
import "net"
type fallbackFilter interface {
Match(net.IP) bool
}
type geoipFilter struct{}
func (gf *geoipFilter) Match(ip net.IP) bool {
if mmdb == nil {
return false
}
record, _ := mmdb.Country(ip)
return record.Country.IsoCode == "CN" || record.Country.IsoCode == ""
}
type ipnetFilter struct {
ipnet *net.IPNet
}
func (inf *ipnetFilter) Match(ip net.IP) bool {
return inf.ipnet.Contains(ip)
}