Mark servers as failing more aggressively
This commit is contained in:
parent
358481d728
commit
4ec5461b2f
|
@ -52,6 +52,10 @@ func SetTransactionID(packet []byte, tid uint16) {
|
|||
binary.BigEndian.PutUint16(packet[0:2], tid)
|
||||
}
|
||||
|
||||
func Rcode(packet []byte) uint8 {
|
||||
return packet[3] & 0xf
|
||||
}
|
||||
|
||||
func NormalizeName(name *[]byte) {
|
||||
for i, c := range *name {
|
||||
if c >= 65 && c <= 90 {
|
||||
|
|
|
@ -289,10 +289,12 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
|
|||
resp, _, err := proxy.xTransport.DoHQuery(serverInfo.useGet, serverInfo.URL, query, proxy.timeout)
|
||||
SetTransactionID(query, tid)
|
||||
if err != nil {
|
||||
serverInfo.noticeFailure(proxy)
|
||||
return
|
||||
}
|
||||
response, err = ioutil.ReadAll(io.LimitReader(resp.Body, int64(MaxDNSPacketSize)))
|
||||
if err != nil {
|
||||
serverInfo.noticeFailure(proxy)
|
||||
return
|
||||
}
|
||||
if len(response) >= MinDNSPacketSize {
|
||||
|
@ -302,17 +304,21 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
|
|||
} else {
|
||||
dlog.Fatal("Unsupported protocol")
|
||||
}
|
||||
if err != nil {
|
||||
serverInfo.noticeFailure(proxy)
|
||||
return
|
||||
}
|
||||
response, _ = pluginsState.ApplyResponsePlugins(&proxy.pluginsGlobals, response, ttl)
|
||||
}
|
||||
if len(response) < MinDNSPacketSize || len(response) > MaxDNSPacketSize {
|
||||
serverInfo.noticeFailure(proxy)
|
||||
return
|
||||
}
|
||||
response, err = pluginsState.ApplyResponsePlugins(&proxy.pluginsGlobals, response, ttl)
|
||||
if err != nil {
|
||||
serverInfo.noticeFailure(proxy)
|
||||
return
|
||||
}
|
||||
if rcode := Rcode(response); rcode == 2 || rcode == 5 { // SERVFAIL / REFUSED
|
||||
serverInfo.noticeFailure(proxy)
|
||||
} else {
|
||||
serverInfo.noticeSuccess(proxy)
|
||||
}
|
||||
}
|
||||
if clientProto == "udp" {
|
||||
if len(response) > MaxDNSUDPPacketSize {
|
||||
response, err = TruncatedResponse(response)
|
||||
|
|
|
@ -201,6 +201,8 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
|
|||
candidate = rand.Intn(Min(serversCount, 2))
|
||||
}
|
||||
serverInfo := &serversInfo.inner[candidate]
|
||||
dlog.Debugf("Using candidate %v: [%v]", candidate, serverInfo.Name)
|
||||
|
||||
return serverInfo
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue