mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-08-29 07:48:21 +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)
|
numServers := len(c.conf.UpstreamGoogle) + len(c.conf.UpstreamIETF)
|
||||||
random := rand.Intn(numServers)
|
random := rand.Intn(numServers)
|
||||||
if random <= len(c.conf.UpstreamGoogle) {
|
if random < len(c.conf.UpstreamGoogle) {
|
||||||
c.handlerFuncGoogle(w, r, isTCP)
|
c.handlerFuncGoogle(w, r, isTCP)
|
||||||
} else {
|
} else {
|
||||||
c.handlerFuncIETF(w, r, isTCP)
|
c.handlerFuncIETF(w, r, isTCP)
|
||||||
|
|||||||
+16
-15
@@ -88,22 +88,23 @@ func (c *Client) handlerFuncIETF(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
|||||||
if edns0Subnet == nil {
|
if edns0Subnet == nil {
|
||||||
ednsClientFamily := uint16(0)
|
ednsClientFamily := uint16(0)
|
||||||
ednsClientAddress, ednsClientNetmask := c.findClientIP(w, r)
|
ednsClientAddress, ednsClientNetmask := c.findClientIP(w, r)
|
||||||
if ednsClientAddress == nil {
|
if ednsClientAddress != nil {
|
||||||
} else if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
||||||
ednsClientFamily = 1
|
ednsClientFamily = 1
|
||||||
ednsClientAddress = ipv4
|
ednsClientAddress = ipv4
|
||||||
ednsClientNetmask = 24
|
ednsClientNetmask = 24
|
||||||
} else {
|
} else {
|
||||||
ednsClientFamily = 2
|
ednsClientFamily = 2
|
||||||
ednsClientNetmask = 48
|
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()
|
requestBinary, err := r.Pack()
|
||||||
|
|||||||
+16
-16
@@ -90,23 +90,23 @@ func (s *Server) parseRequestIETF(w http.ResponseWriter, r *http.Request) *DNSRe
|
|||||||
ednsClientFamily := uint16(0)
|
ednsClientFamily := uint16(0)
|
||||||
ednsClientAddress := s.findClientIP(r)
|
ednsClientAddress := s.findClientIP(r)
|
||||||
ednsClientNetmask := uint8(255)
|
ednsClientNetmask := uint8(255)
|
||||||
if ednsClientAddress == nil {
|
if ednsClientAddress != nil {
|
||||||
ednsClientNetmask = 0
|
if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
||||||
} else if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
ednsClientFamily = 1
|
||||||
ednsClientFamily = 1
|
ednsClientAddress = ipv4
|
||||||
ednsClientAddress = ipv4
|
ednsClientNetmask = 24
|
||||||
ednsClientNetmask = 24
|
} else {
|
||||||
} else {
|
ednsClientFamily = 2
|
||||||
ednsClientFamily = 2
|
ednsClientNetmask = 48
|
||||||
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{
|
return &DNSRequest{
|
||||||
|
|||||||
Reference in New Issue
Block a user