Feature: add geoip-code option

This commit is contained in:
Dreamacro
2021-08-25 15:15:13 +08:00
parent 121bc910f6
commit e0d3f926b7
4 changed files with 27 additions and 17 deletions

View File

@ -71,9 +71,10 @@ type DNS struct {
// FallbackFilter config
type FallbackFilter struct {
GeoIP bool `yaml:"geoip"`
IPCIDR []*net.IPNet `yaml:"ipcidr"`
Domain []string `yaml:"domain"`
GeoIP bool `yaml:"geoip"`
GeoIPCode string `yaml:"geoip-code"`
IPCIDR []*net.IPNet `yaml:"ipcidr"`
Domain []string `yaml:"domain"`
}
// Profile config
@ -113,9 +114,10 @@ type RawDNS struct {
}
type RawFallbackFilter struct {
GeoIP bool `yaml:"geoip"`
IPCIDR []string `yaml:"ipcidr"`
Domain []string `yaml:"domain"`
GeoIP bool `yaml:"geoip"`
GeoIPCode string `yaml:"geoip-code"`
IPCIDR []string `yaml:"ipcidr"`
Domain []string `yaml:"domain"`
}
type RawConfig struct {
@ -172,8 +174,9 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
UseHosts: true,
FakeIPRange: "198.18.0.1/16",
FallbackFilter: RawFallbackFilter{
GeoIP: true,
IPCIDR: []string{},
GeoIP: true,
GeoIPCode: "CN",
IPCIDR: []string{},
},
DefaultNameserver: []string{
"114.114.114.114",
@ -600,6 +603,7 @@ func parseDNS(cfg RawDNS, hosts *trie.DomainTrie) (*DNS, error) {
}
dnsCfg.FallbackFilter.GeoIP = cfg.FallbackFilter.GeoIP
dnsCfg.FallbackFilter.GeoIPCode = cfg.FallbackFilter.GeoIPCode
if fallbackip, err := parseFallbackIPCIDR(cfg.FallbackFilter.IPCIDR); err == nil {
dnsCfg.FallbackFilter.IPCIDR = fallbackip
}