Feature: persistence fakeip (#1662)

This commit is contained in:
Dreamacro
2021-10-11 20:48:58 +08:00
committed by GitHub
parent a1c2478e74
commit 3d5681cffd
8 changed files with 364 additions and 73 deletions

View File

@ -80,6 +80,7 @@ type FallbackFilter struct {
// Profile config
type Profile struct {
StoreSelected bool `yaml:"store-selected"`
StoreFakeIP bool `yaml:"store-fakeip"`
}
// Experimental config
@ -226,7 +227,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
}
config.Hosts = hosts
dnsCfg, err := parseDNS(rawCfg.DNS, hosts)
dnsCfg, err := parseDNS(rawCfg, hosts)
if err != nil {
return nil, err
}
@ -541,7 +542,8 @@ func parseFallbackIPCIDR(ips []string) ([]*net.IPNet, error) {
return ipNets, nil
}
func parseDNS(cfg RawDNS, hosts *trie.DomainTrie) (*DNS, error) {
func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie) (*DNS, error) {
cfg := rawCfg.DNS
if cfg.Enable && len(cfg.NameServer) == 0 {
return nil, fmt.Errorf("if DNS configuration is turned on, NameServer cannot be empty")
}
@ -597,7 +599,12 @@ func parseDNS(cfg RawDNS, hosts *trie.DomainTrie) (*DNS, error) {
}
}
pool, err := fakeip.New(ipnet, 1000, host)
pool, err := fakeip.New(fakeip.Options{
IPNet: ipnet,
Size: 1000,
Host: host,
Persistence: rawCfg.Profile.StoreFakeIP,
})
if err != nil {
return nil, err
}