Skip to content

Commit

Permalink
Use 198.18.0.0/16 as default Fake IP Pool (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Han authored Mar 14, 2021
1 parent e0526c2 commit 3fe8544
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/dns/fakedns/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewFakeDNSHolder() (*Holder, error) {
if fkdns, err = NewFakeDNSHolderConfigOnly(nil); err != nil {
return nil, newError("Unable to create Fake Dns Engine").Base(err).AtError()
}
err = fkdns.initialize("240.0.0.0/8", 65535)
err = fkdns.initialize(dns.FakeIPPool, 65535)
if err != nil {
return nil, err
}
Expand Down
13 changes: 9 additions & 4 deletions app/dns/fakedns/fakedns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/uuid"
"github.com/xtls/xray-core/features/dns"
)

var (
ipPrefix = "198.18."
)

func TestNewFakeDnsHolder(_ *testing.T) {
Expand All @@ -20,18 +25,18 @@ func TestFakeDnsHolderCreateMapping(t *testing.T) {
common.Must(err)

addr := fkdns.GetFakeIPForDomain("fakednstest.example.com")
assert.Equal(t, "240.", addr[0].IP().String()[0:4])
assert.Equal(t, ipPrefix, addr[0].IP().String()[0:len(ipPrefix)])
}

func TestFakeDnsHolderCreateMappingMany(t *testing.T) {
fkdns, err := NewFakeDNSHolder()
common.Must(err)

addr := fkdns.GetFakeIPForDomain("fakednstest.example.com")
assert.Equal(t, "240.", addr[0].IP().String()[0:4])
assert.Equal(t, ipPrefix, addr[0].IP().String()[0:len(ipPrefix)])

addr2 := fkdns.GetFakeIPForDomain("fakednstest2.example.com")
assert.Equal(t, "240.", addr2[0].IP().String()[0:4])
assert.Equal(t, ipPrefix, addr2[0].IP().String()[0:len(ipPrefix)])
assert.NotEqual(t, addr[0].IP().String(), addr2[0].IP().String())
}

Expand Down Expand Up @@ -64,7 +69,7 @@ func TestFakeDnsHolderCreateMappingManySingleDomain(t *testing.T) {

func TestFakeDnsHolderCreateMappingAndRollOver(t *testing.T) {
fkdns, err := NewFakeDNSHolderConfigOnly(&FakeDnsPool{
IpPool: "240.0.0.0/12",
IpPool: dns.FakeIPPool,
LruSize: 256,
})
common.Must(err)
Expand Down
2 changes: 2 additions & 0 deletions features/dns/fakedns.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ type FakeDNSEngine interface {
GetDomainFromFakeDNS(ip net.Address) string
GetFakeIPRange() *gonet.IPNet
}

var FakeIPPool = "198.18.0.0/16"
3 changes: 2 additions & 1 deletion infra/conf/fakedns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package conf
import (
"github.com/golang/protobuf/proto"
"github.com/xtls/xray-core/app/dns/fakedns"
"github.com/xtls/xray-core/features/dns"
)

type FakeDNSConfig struct {
Expand Down Expand Up @@ -36,7 +37,7 @@ func (FakeDNSPostProcessingStage) Process(conf *Config) error {
if conf.FakeDNS == nil {
// Add a Fake DNS Config if there is none
conf.FakeDNS = &FakeDNSConfig{
IPPool: "240.0.0.0/8",
IPPool: dns.FakeIPPool,
LruSize: 65535,
}
}
Expand Down

0 comments on commit 3fe8544

Please sign in to comment.