Respect proxy.mainProto in forward plugin (#1259)

* Respect proxy.mainProto in forward plugin

* Make the serverProtocol part of pluginsState instead
This commit is contained in:
Kiril Angov 2020-04-05 14:49:30 -04:00 committed by GitHub
parent f4631b9121
commit d2602fd142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -41,7 +41,10 @@ func (plugin *PluginForward) Init(proxy *Proxy) error {
}
domain, serversStr, ok := StringTwoFields(line)
if !ok {
return fmt.Errorf("Syntax error for a forwarding rule at line %d. Expected syntax: example.com: 9.9.9.9,8.8.8.8", 1+lineNo)
return fmt.Errorf(
"syntax error for a forwarding rule at line %d. Expected syntax: example.com 9.9.9.9,8.8.8.8",
1+lineNo,
)
}
domain = strings.ToLower(domain)
var servers []string
@ -56,7 +59,8 @@ func (plugin *PluginForward) Init(proxy *Proxy) error {
continue
}
plugin.forwardMap = append(plugin.forwardMap, PluginForwardEntry{
domain: domain, servers: servers,
domain: domain,
servers: servers,
})
}
return nil
@ -89,7 +93,7 @@ func (plugin *PluginForward) Eval(pluginsState *PluginsState, msg *dns.Msg) erro
}
server := servers[rand.Intn(len(servers))]
pluginsState.serverName = server
client := dns.Client{Net: "udp"}
client := dns.Client{Net: pluginsState.serverProto}
respMsg, _, err := client.Exchange(msg, server)
if err != nil {
return err

View File

@ -86,6 +86,7 @@ type PluginsState struct {
cacheHit bool
returnCode PluginsReturnCode
serverName string
serverProto string
}
func (proxy *Proxy) InitPluginsGlobals() error {
@ -222,7 +223,7 @@ type Plugin interface {
Eval(pluginsState *PluginsState, msg *dns.Msg) error
}
func NewPluginsState(proxy *Proxy, clientProto string, clientAddr *net.Addr, start time.Time) PluginsState {
func NewPluginsState(proxy *Proxy, clientProto string, clientAddr *net.Addr, serverProto string, start time.Time) PluginsState {
return PluginsState{
action: PluginsActionContinue,
returnCode: PluginsReturnCodePass,
@ -238,6 +239,7 @@ func NewPluginsState(proxy *Proxy, clientProto string, clientAddr *net.Addr, sta
questionMsg: nil,
qName: "",
serverName: "-",
serverProto: serverProto,
requestStart: start,
maxUnencryptedUDPSafePayloadSize: MaxDNSUDPSafePacketSize,
sessionData: make(map[string]interface{}),

View File

@ -443,7 +443,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
if len(query) < MinDNSPacketSize {
return
}
pluginsState := NewPluginsState(proxy, clientProto, clientAddr, start)
pluginsState := NewPluginsState(proxy, clientProto, clientAddr, serverProto, start)
serverName := "-"
needsEDNS0Padding := false
serverInfo := proxy.serversInfo.getOne()