parent
cb022ece82
commit
a726a40dc5
|
@ -73,6 +73,7 @@ type Config struct {
|
||||||
NetprobeTimeout int `toml:"netprobe_timeout"`
|
NetprobeTimeout int `toml:"netprobe_timeout"`
|
||||||
OfflineMode bool `toml:"offline_mode"`
|
OfflineMode bool `toml:"offline_mode"`
|
||||||
HTTPProxyURL string `toml:"http_proxy"`
|
HTTPProxyURL string `toml:"http_proxy"`
|
||||||
|
RefusedCodeInResponses bool `toml:"refused_code_in_responses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConfig() Config {
|
func newConfig() Config {
|
||||||
|
@ -108,6 +109,7 @@ func newConfig() Config {
|
||||||
NetprobeAddress: "9.9.9.9:53",
|
NetprobeAddress: "9.9.9.9:53",
|
||||||
NetprobeTimeout: 60,
|
NetprobeTimeout: 60,
|
||||||
OfflineMode: false,
|
OfflineMode: false,
|
||||||
|
RefusedCodeInResponses: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,6 +280,7 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
|
||||||
|
|
||||||
proxy.xTransport.rebuildTransport()
|
proxy.xTransport.rebuildTransport()
|
||||||
|
|
||||||
|
proxy.refusedCodeInResponses = config.RefusedCodeInResponses
|
||||||
proxy.timeout = time.Duration(config.Timeout) * time.Millisecond
|
proxy.timeout = time.Duration(config.Timeout) * time.Millisecond
|
||||||
proxy.maxClients = config.MaxClients
|
proxy.maxClients = config.MaxClients
|
||||||
proxy.mainProto = "udp"
|
proxy.mainProto = "udp"
|
||||||
|
|
|
@ -31,12 +31,16 @@ func EmptyResponseFromMessage(srcMsg *dns.Msg) (*dns.Msg, error) {
|
||||||
return dstMsg, nil
|
return dstMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RefusedResponseFromMessage(srcMsg *dns.Msg) (*dns.Msg, error) {
|
func RefusedResponseFromMessage(srcMsg *dns.Msg, refusedCode bool) (*dns.Msg, error) {
|
||||||
dstMsg, err := EmptyResponseFromMessage(srcMsg)
|
dstMsg, err := EmptyResponseFromMessage(srcMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dstMsg, err
|
return dstMsg, err
|
||||||
}
|
}
|
||||||
dstMsg.Rcode = dns.RcodeRefused
|
if refusedCode {
|
||||||
|
dstMsg.Rcode = dns.RcodeRefused
|
||||||
|
} else {
|
||||||
|
dstMsg.Rcode = dns.RcodeSuccess
|
||||||
|
}
|
||||||
return dstMsg, nil
|
return dstMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,10 @@ const (
|
||||||
|
|
||||||
type PluginsGlobals struct {
|
type PluginsGlobals struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
queryPlugins *[]Plugin
|
queryPlugins *[]Plugin
|
||||||
responsePlugins *[]Plugin
|
responsePlugins *[]Plugin
|
||||||
loggingPlugins *[]Plugin
|
loggingPlugins *[]Plugin
|
||||||
|
refusedCodeInResponses bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type PluginsReturnCode int
|
type PluginsReturnCode int
|
||||||
|
@ -127,6 +128,7 @@ func InitPluginsGlobals(pluginsGlobals *PluginsGlobals, proxy *Proxy) error {
|
||||||
(*pluginsGlobals).queryPlugins = queryPlugins
|
(*pluginsGlobals).queryPlugins = queryPlugins
|
||||||
(*pluginsGlobals).responsePlugins = responsePlugins
|
(*pluginsGlobals).responsePlugins = responsePlugins
|
||||||
(*pluginsGlobals).loggingPlugins = loggingPlugins
|
(*pluginsGlobals).loggingPlugins = loggingPlugins
|
||||||
|
(*pluginsGlobals).refusedCodeInResponses = proxy.refusedCodeInResponses
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +177,7 @@ func (pluginsState *PluginsState) ApplyQueryPlugins(pluginsGlobals *PluginsGloba
|
||||||
return packet, ret
|
return packet, ret
|
||||||
}
|
}
|
||||||
if pluginsState.action == PluginsActionReject {
|
if pluginsState.action == PluginsActionReject {
|
||||||
synth, err := RefusedResponseFromMessage(&msg)
|
synth, err := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -223,7 +225,7 @@ func (pluginsState *PluginsState) ApplyResponsePlugins(pluginsGlobals *PluginsGl
|
||||||
return packet, ret
|
return packet, ret
|
||||||
}
|
}
|
||||||
if pluginsState.action == PluginsActionReject {
|
if pluginsState.action == PluginsActionReject {
|
||||||
synth, err := RefusedResponseFromMessage(&msg)
|
synth, err := RefusedResponseFromMessage(&msg, pluginsGlobals.refusedCodeInResponses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ type Proxy struct {
|
||||||
logMaxSize int
|
logMaxSize int
|
||||||
logMaxAge int
|
logMaxAge int
|
||||||
logMaxBackups int
|
logMaxBackups int
|
||||||
|
refusedCodeInResponses bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (proxy *Proxy) StartProxy() {
|
func (proxy *Proxy) StartProxy() {
|
||||||
|
|
Loading…
Reference in New Issue