diff --git a/dns-over-https-proxy.go b/dns-over-https-proxy.go index b4ac26f..ccb6437 100644 --- a/dns-over-https-proxy.go +++ b/dns-over-https-proxy.go @@ -13,12 +13,12 @@ import ( "os/signal" "syscall" - "github.com/wrouesnel/go.log" - "github.com/miekg/dns" - "net/http" "encoding/json" "fmt" + "github.com/miekg/dns" + "github.com/wrouesnel/go.log" "net" + "net/http" ) var ( @@ -41,30 +41,30 @@ var ( // Rough translation of the Google DNS over HTTP API type DNSResponseJson struct { - Status int32 `json:"Status,omitempty"` - TC bool `json:"TC,omitempty"` - RD bool `json:"RD,omitempty"` - RA bool `json:"RA,omitempty"` - AD bool `json:"AD,omitempty"` - CD bool `json:"CD,omitempty"` - Question []DNSQuestion `json:"Question,omitempty"` - Answer []DNSRR `json:"Answer,omitempty"` - Authority []DNSRR `json:"Authority,omitempty"` - Additional []DNSRR `json:"Additional,omitempty"` - Edns_client_subnet string `json:"edns_client_subnet,omitempty"` - Comment string `json:"Comment,omitempty"` + Status int32 `json:"Status,omitempty"` + TC bool `json:"TC,omitempty"` + RD bool `json:"RD,omitempty"` + RA bool `json:"RA,omitempty"` + AD bool `json:"AD,omitempty"` + CD bool `json:"CD,omitempty"` + Question []DNSQuestion `json:"Question,omitempty"` + Answer []DNSRR `json:"Answer,omitempty"` + Authority []DNSRR `json:"Authority,omitempty"` + Additional []DNSRR `json:"Additional,omitempty"` + Edns_client_subnet string `json:"edns_client_subnet,omitempty"` + Comment string `json:"Comment,omitempty"` } type DNSQuestion struct { - Name string `json:"name,omitempty"` - Type int32 `json:"type,omitempty"` + Name string `json:"name,omitempty"` + Type int32 `json:"type,omitempty"` } type DNSRR struct { - Name string `json:"name,omitempty"` - Type int32 `json:"type,omitempty"` - TTL int32 `json:"TTL,omitempty"` - Data string `json:"data,omitempty"` + Name string `json:"name,omitempty"` + Type int32 `json:"type,omitempty"` + TTL int32 `json:"TTL,omitempty"` + Data string `json:"data,omitempty"` } // Initialize a new RRGeneric from a DNSRR @@ -73,10 +73,10 @@ func NewRR(a DNSRR) dns.RR { // Build an RR header rrhdr := dns.RR_Header{ - Name: a.Name, - Rrtype: uint16(a.Type), - Class: dns.ClassINET, - Ttl: uint32(a.TTL), + Name: a.Name, + Rrtype: uint16(a.Type), + Class: dns.ClassINET, + Ttl: uint32(a.TTL), Rdlength: uint16(len(a.Data)), } @@ -93,7 +93,7 @@ func NewRR(a DNSRR) dns.RR { } } else { rr = dns.RR(&dns.RFC3597{ - Hdr: rrhdr, + Hdr: rrhdr, Rdata: a.Data, }) } @@ -250,8 +250,8 @@ func proxy(addr string, w dns.ResponseWriter, req *dns.Msg) { questions := []dns.Question{} for idx, c := range dnsResp.Question { questions = append(questions, dns.Question{ - Name: c.Name, - Qtype: uint16(c.Type), + Name: c.Name, + Qtype: uint16(c.Type), Qclass: req.Question[idx].Qclass, }) } @@ -276,23 +276,23 @@ func proxy(addr string, w dns.ResponseWriter, req *dns.Msg) { resp := dns.Msg{ MsgHdr: dns.MsgHdr{ - Id: req.Id, - Response: (dnsResp.Status == 0), - Opcode: dns.OpcodeQuery, - Authoritative: false, - Truncated: dnsResp.TC, - RecursionDesired: dnsResp.RD, + Id: req.Id, + Response: (dnsResp.Status == 0), + Opcode: dns.OpcodeQuery, + Authoritative: false, + Truncated: dnsResp.TC, + RecursionDesired: dnsResp.RD, RecursionAvailable: dnsResp.RA, //Zero: false, AuthenticatedData: dnsResp.AD, - CheckingDisabled: dnsResp.CD, - Rcode: int(dnsResp.Status), + CheckingDisabled: dnsResp.CD, + Rcode: int(dnsResp.Status), }, Compress: req.Compress, Question: questions, - Answer: answers, - Ns: authorities, - Extra: extras, + Answer: answers, + Ns: authorities, + Extra: extras, } // Write the response