mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-30 05:19:56 +00:00
Implement IETF protocol
This commit is contained in:
@@ -154,7 +154,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
||||
}
|
||||
numServers := len(c.conf.UpstreamGoogle) + len(c.conf.UpstreamIETF)
|
||||
random := rand.Intn(numServers)
|
||||
if random <= len(c.conf.UpstreamGoogle) {
|
||||
if random < len(c.conf.UpstreamGoogle) {
|
||||
c.handlerFuncGoogle(w, r, isTCP)
|
||||
} else {
|
||||
c.handlerFuncIETF(w, r, isTCP)
|
||||
|
||||
@@ -88,22 +88,23 @@ func (c *Client) handlerFuncIETF(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
||||
if edns0Subnet == nil {
|
||||
ednsClientFamily := uint16(0)
|
||||
ednsClientAddress, ednsClientNetmask := c.findClientIP(w, r)
|
||||
if ednsClientAddress == nil {
|
||||
} else if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
||||
ednsClientFamily = 1
|
||||
ednsClientAddress = ipv4
|
||||
ednsClientNetmask = 24
|
||||
} else {
|
||||
ednsClientFamily = 2
|
||||
ednsClientNetmask = 48
|
||||
if ednsClientAddress != nil {
|
||||
if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
||||
ednsClientFamily = 1
|
||||
ednsClientAddress = ipv4
|
||||
ednsClientNetmask = 24
|
||||
} else {
|
||||
ednsClientFamily = 2
|
||||
ednsClientNetmask = 48
|
||||
}
|
||||
edns0Subnet = new(dns.EDNS0_SUBNET)
|
||||
edns0Subnet.Code = dns.EDNS0SUBNET
|
||||
edns0Subnet.Family = ednsClientFamily
|
||||
edns0Subnet.SourceNetmask = ednsClientNetmask
|
||||
edns0Subnet.SourceScope = 0
|
||||
edns0Subnet.Address = ednsClientAddress
|
||||
opt.Option = append(opt.Option, edns0Subnet)
|
||||
}
|
||||
edns0Subnet = new(dns.EDNS0_SUBNET)
|
||||
edns0Subnet.Code = dns.EDNS0SUBNET
|
||||
edns0Subnet.Family = ednsClientFamily
|
||||
edns0Subnet.SourceNetmask = ednsClientNetmask
|
||||
edns0Subnet.SourceScope = 0
|
||||
edns0Subnet.Address = ednsClientAddress
|
||||
opt.Option = append(opt.Option, edns0Subnet)
|
||||
}
|
||||
|
||||
requestBinary, err := r.Pack()
|
||||
|
||||
@@ -90,23 +90,23 @@ func (s *Server) parseRequestIETF(w http.ResponseWriter, r *http.Request) *DNSRe
|
||||
ednsClientFamily := uint16(0)
|
||||
ednsClientAddress := s.findClientIP(r)
|
||||
ednsClientNetmask := uint8(255)
|
||||
if ednsClientAddress == nil {
|
||||
ednsClientNetmask = 0
|
||||
} else if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
||||
ednsClientFamily = 1
|
||||
ednsClientAddress = ipv4
|
||||
ednsClientNetmask = 24
|
||||
} else {
|
||||
ednsClientFamily = 2
|
||||
ednsClientNetmask = 48
|
||||
if ednsClientAddress != nil {
|
||||
if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
||||
ednsClientFamily = 1
|
||||
ednsClientAddress = ipv4
|
||||
ednsClientNetmask = 24
|
||||
} else {
|
||||
ednsClientFamily = 2
|
||||
ednsClientNetmask = 48
|
||||
}
|
||||
edns0Subnet = new(dns.EDNS0_SUBNET)
|
||||
edns0Subnet.Code = dns.EDNS0SUBNET
|
||||
edns0Subnet.Family = ednsClientFamily
|
||||
edns0Subnet.SourceNetmask = ednsClientNetmask
|
||||
edns0Subnet.SourceScope = 0
|
||||
edns0Subnet.Address = ednsClientAddress
|
||||
opt.Option = append(opt.Option, edns0Subnet)
|
||||
}
|
||||
edns0Subnet = new(dns.EDNS0_SUBNET)
|
||||
edns0Subnet.Code = dns.EDNS0SUBNET
|
||||
edns0Subnet.Family = ednsClientFamily
|
||||
edns0Subnet.SourceNetmask = ednsClientNetmask
|
||||
edns0Subnet.SourceScope = 0
|
||||
edns0Subnet.Address = ednsClientAddress
|
||||
opt.Option = append(opt.Option, edns0Subnet)
|
||||
}
|
||||
|
||||
return &DNSRequest{
|
||||
|
||||
Reference in New Issue
Block a user