github.com/eagleql/xray-core@v1.4.4/infra/conf/fakedns.go (about) 1 package conf 2 3 import ( 4 "github.com/eagleql/xray-core/app/dns/fakedns" 5 "github.com/eagleql/xray-core/features/dns" 6 "github.com/golang/protobuf/proto" 7 ) 8 9 type FakeDNSConfig struct { 10 IPPool string `json:"ipPool"` 11 LruSize int64 `json:"poolSize"` 12 } 13 14 func (f FakeDNSConfig) Build() (proto.Message, error) { 15 return &fakedns.FakeDnsPool{ 16 IpPool: f.IPPool, 17 LruSize: f.LruSize, 18 }, nil 19 } 20 21 type FakeDNSPostProcessingStage struct{} 22 23 func (FakeDNSPostProcessingStage) Process(conf *Config) error { 24 var fakeDNSInUse bool 25 26 if conf.DNSConfig != nil { 27 for _, v := range conf.DNSConfig.Servers { 28 if v.Address.Family().IsDomain() { 29 if v.Address.Domain() == "fakedns" { 30 fakeDNSInUse = true 31 } 32 } 33 } 34 } 35 36 if fakeDNSInUse { 37 if conf.FakeDNS == nil { 38 // Add a Fake DNS Config if there is none 39 conf.FakeDNS = &FakeDNSConfig{ 40 IPPool: dns.FakeIPPool, 41 LruSize: 65535, 42 } 43 } 44 found := false 45 // Check if there is a Outbound with necessary sniffer on 46 var inbounds []InboundDetourConfig 47 48 if len(conf.InboundConfigs) > 0 { 49 inbounds = append(inbounds, conf.InboundConfigs...) 50 } 51 for _, v := range inbounds { 52 if v.SniffingConfig != nil && v.SniffingConfig.Enabled && v.SniffingConfig.DestOverride != nil { 53 for _, dov := range *v.SniffingConfig.DestOverride { 54 if dov == "fakedns" { 55 found = true 56 } 57 } 58 } 59 } 60 if !found { 61 newError("Defined Fake DNS but haven't enabled fake dns sniffing at any inbound.").AtWarning().WriteToLog() 62 } 63 } 64 65 return nil 66 }