Add Fake DNS support (#309)

Co-authored-by: Xiaokang Wang <xiaokangwang@outlook.com>
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Co-authored-by: kslr <kslrwang@gmail.com>
This commit is contained in:
yuhan6665 2021-03-06 23:39:50 -05:00 committed by GitHub
parent db32ce6fd9
commit f50eff5ebb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 1351 additions and 301 deletions

View file

@ -62,6 +62,7 @@ type SniffingConfig struct {
Enabled bool `json:"enabled"`
DestOverride *StringList `json:"destOverride"`
DomainsExcluded *StringList `json:"domainsExcluded"`
MetadataOnly bool `json:"metadataOnly"`
}
// Build implements Buildable.
@ -74,6 +75,8 @@ func (c *SniffingConfig) Build() (*proxyman.SniffingConfig, error) {
p = append(p, "http")
case "tls", "https", "ssl":
p = append(p, "tls")
case "fakedns":
p = append(p, "fakedns")
default:
return nil, newError("unknown protocol: ", protocol)
}
@ -91,6 +94,7 @@ func (c *SniffingConfig) Build() (*proxyman.SniffingConfig, error) {
Enabled: c.Enabled,
DestinationOverride: p,
DomainsExcluded: d,
MetadataOnly: c.MetadataOnly,
}, nil
}
@ -395,6 +399,7 @@ type Config struct {
API *APIConfig `json:"api"`
Stats *StatsConfig `json:"stats"`
Reverse *ReverseConfig `json:"reverse"`
FakeDNS *FakeDNSConfig `json:"fakeDns"`
}
func (c *Config) findInboundTag(tag string) int {
@ -448,6 +453,10 @@ func (c *Config) Override(o *Config, fn string) {
c.Reverse = o.Reverse
}
if o.FakeDNS != nil {
c.FakeDNS = o.FakeDNS
}
// deprecated attrs... keep them for now
if o.InboundConfig != nil {
c.InboundConfig = o.InboundConfig
@ -519,6 +528,10 @@ func applyTransportConfig(s *StreamConfig, t *TransportConfig) {
// Build implements Buildable.
func (c *Config) Build() (*core.Config, error) {
if err := PostProcessConfigureFile(c); err != nil {
return nil, err
}
config := &core.Config{
App: []*serial.TypedMessage{
serial.ToTypedMessage(&dispatcher.Config{}),
@ -585,6 +598,14 @@ func (c *Config) Build() (*core.Config, error) {
config.App = append(config.App, serial.ToTypedMessage(r))
}
if c.FakeDNS != nil {
r, err := c.FakeDNS.Build()
if err != nil {
return nil, err
}
config.App = append(config.App, serial.ToTypedMessage(r))
}
var inbounds []InboundDetourConfig
if c.InboundConfig != nil {