diff --git a/doh-client/client.go b/doh-client/client.go index 2f25fa5..1eb30a7 100644 --- a/doh-client/client.go +++ b/doh-client/client.go @@ -156,7 +156,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) { return } - fullReply := jsonDNS.Unmarshal(reply, &respJson, udpSize) + fullReply := jsonDNS.Unmarshal(reply, &respJson, udpSize, ednsClientNetmask) buf, err := fullReply.Pack() if err != nil { log.Println(err) diff --git a/json-dns/unmarshal.go b/json-dns/unmarshal.go index 73e94cd..7f495ae 100644 --- a/json-dns/unmarshal.go +++ b/json-dns/unmarshal.go @@ -42,7 +42,7 @@ func PrepareReply(req *dns.Msg) *dns.Msg { return reply } -func Unmarshal(msg *dns.Msg, resp *Response, udpSize uint16) *dns.Msg { +func Unmarshal(msg *dns.Msg, resp *Response, udpSize uint16, ednsClientNetmask uint8) *dns.Msg { now := time.Now().UTC() reply := msg.Copy() @@ -110,10 +110,17 @@ func Unmarshal(msg *dns.Msg, resp *Response, udpSize uint16) *dns.Msg { } } if ednsClientAddress != nil { + if ednsClientNetmask == 255 { + if ednsClientFamily == 1 { + ednsClientNetmask = 24 + } else { + ednsClientNetmask = 48 + } + } edns0Subnet := new(dns.EDNS0_SUBNET) edns0Subnet.Code = dns.EDNS0SUBNET edns0Subnet.Family = ednsClientFamily - edns0Subnet.SourceNetmask = ednsClientScope + edns0Subnet.SourceNetmask = ednsClientNetmask edns0Subnet.SourceScope = ednsClientScope edns0Subnet.Address = ednsClientAddress opt.Option = append(opt.Option, edns0Subnet)