DoH: use 0 as a transaction ID
Reject short TCP queries early by the way
This commit is contained in:
parent
2eed62f1e2
commit
458da8fa77
|
@ -59,6 +59,9 @@ func ReadPrefixed(conn *net.TCPConn) ([]byte, error) {
|
|||
if packetLength > MaxDNSPacketSize-1 {
|
||||
return buf, errors.New("Packet too large")
|
||||
}
|
||||
if packetLength < MinDNSPacketSize {
|
||||
return buf, errors.New("Packet too short")
|
||||
}
|
||||
}
|
||||
if pos >= 2+packetLength {
|
||||
return buf[2:pos], nil
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -43,6 +44,14 @@ func HasTCFlag(packet []byte) bool {
|
|||
return packet[2]&2 == 2
|
||||
}
|
||||
|
||||
func TransactionID(packet []byte) uint16 {
|
||||
return binary.BigEndian.Uint16(packet[0:2])
|
||||
}
|
||||
|
||||
func SetTransactionID(packet []byte, tid uint16) {
|
||||
binary.BigEndian.PutUint16(packet[0:2], tid)
|
||||
}
|
||||
|
||||
func NormalizeName(name *[]byte) {
|
||||
for i, c := range *name {
|
||||
if c >= 65 && c <= 90 {
|
||||
|
|
|
@ -279,7 +279,10 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
|
|||
return
|
||||
}
|
||||
} else if serverInfo.Proto == StampProtoTypeDoH {
|
||||
tid := TransactionID(query)
|
||||
SetTransactionID(query, 0)
|
||||
resp, _, err := proxy.xTransport.Post(serverInfo.URL, "application/dns-udpwireformat", "application/dns-udpwireformat", query, proxy.timeout)
|
||||
SetTransactionID(query, tid)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -287,6 +290,9 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(response) >= MinDNSPacketSize {
|
||||
SetTransactionID(response, tid)
|
||||
}
|
||||
} else {
|
||||
dlog.Fatal("Unsupported protocol")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue