mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-04-02 07:15:39 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b63e86bab3 | ||
|
|
7c96cd4436 | ||
|
|
f5f1a8f3f4 | ||
|
|
4f46b89feb | ||
|
|
2c7e70466e | ||
|
|
88f9ef84d1 | ||
|
|
63bceea638 | ||
|
|
16120fdc11 | ||
|
|
0c878a6ad7 | ||
|
|
31ea7c520d |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ doh-server/doh-server
|
|||||||
.glide/
|
.glide/
|
||||||
|
|
||||||
.idea/
|
.idea/
|
||||||
|
vendor/
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ This Changelog records major changes between versions.
|
|||||||
|
|
||||||
Not all changes are recorded. Please check git log for details.
|
Not all changes are recorded. Please check git log for details.
|
||||||
|
|
||||||
|
## Version 2.2.3
|
||||||
|
|
||||||
|
- Use the library ipTree to determine whether an IP is global routable, improving the performance
|
||||||
|
- Google's 8.8.8.8 resolver is now marked as "Good ECS" in the example configuration file
|
||||||
|
|
||||||
## Version 2.2.2
|
## Version 2.2.2
|
||||||
|
|
||||||
- Allow client to opt-out EDNS0 Client Support
|
- Allow client to opt-out EDNS0 Client Support
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ import (
|
|||||||
|
|
||||||
"github.com/m13253/dns-over-https/doh-client/config"
|
"github.com/m13253/dns-over-https/doh-client/config"
|
||||||
"github.com/m13253/dns-over-https/doh-client/selector"
|
"github.com/m13253/dns-over-https/doh-client/selector"
|
||||||
jsonDNS "github.com/m13253/dns-over-https/json-dns"
|
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"golang.org/x/net/idna"
|
"golang.org/x/net/idna"
|
||||||
@@ -305,7 +305,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
|||||||
|
|
||||||
if len(r.Question) != 1 {
|
if len(r.Question) != 1 {
|
||||||
log.Println("Number of questions is not 1")
|
log.Println("Number of questions is not 1")
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeFormatError
|
reply.Rcode = dns.RcodeFormatError
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return
|
return
|
||||||
@@ -356,7 +356,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply = jsonDNS.PrepareReply(r)
|
reply = jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return
|
return
|
||||||
@@ -471,7 +471,7 @@ func (c *Client) findClientIP(w dns.ResponseWriter, r *dns.Msg) (ednsClientAddre
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ip := remoteAddr.IP; jsonDNS.IsGlobalIP(ip) {
|
if ip := remoteAddr.IP; jsondns.IsGlobalIP(ip) {
|
||||||
if ipv4 := ip.To4(); ipv4 != nil {
|
if ipv4 := ip.To4(); ipv4 != nil {
|
||||||
ednsClientAddress = ipv4.Mask(ipv4Mask24)
|
ednsClientAddress = ipv4.Mask(ipv4Mask24)
|
||||||
ednsClientNetmask = 24
|
ednsClientNetmask = 24
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ upstream_selector = "random"
|
|||||||
# bootstrap server, please make this list empty.
|
# bootstrap server, please make this list empty.
|
||||||
bootstrap = [
|
bootstrap = [
|
||||||
|
|
||||||
# Google's resolver, bad ECS, good DNSSEC
|
# Google's resolver, good ECS, good DNSSEC
|
||||||
"8.8.8.8:53",
|
"8.8.8.8:53",
|
||||||
"8.8.4.4:53",
|
"8.8.4.4:53",
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
questionName := question.Name
|
questionName := question.Name
|
||||||
questionClass := question.Qclass
|
questionClass := question.Qclass
|
||||||
if questionClass != dns.ClassINET {
|
if questionClass != dns.ClassINET {
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeRefused
|
reply.Rcode = dns.RcodeRefused
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -80,7 +80,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -111,7 +111,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -121,7 +121,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
|||||||
|
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
response: resp,
|
response: resp,
|
||||||
reply: jsonDNS.PrepareReply(r),
|
reply: jsondns.PrepareReply(r),
|
||||||
udpSize: udpSize,
|
udpSize: udpSize,
|
||||||
ednsClientAddress: ednsClientAddress,
|
ednsClientAddress: ednsClientAddress,
|
||||||
ednsClientNetmask: ednsClientNetmask,
|
ednsClientNetmask: ednsClientNetmask,
|
||||||
@@ -148,7 +148,7 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var respJSON jsonDNS.Response
|
var respJSON jsondns.Response
|
||||||
err = json.Unmarshal(body, &respJSON)
|
err = json.Unmarshal(body, &respJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -162,7 +162,7 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
|||||||
}
|
}
|
||||||
fixEmptyNames(&respJSON)
|
fixEmptyNames(&respJSON)
|
||||||
|
|
||||||
fullReply := jsonDNS.Unmarshal(req.reply, &respJSON, req.udpSize, req.ednsClientNetmask)
|
fullReply := jsondns.Unmarshal(req.reply, &respJSON, req.udpSize, req.ednsClientNetmask)
|
||||||
buf, err := fullReply.Pack()
|
buf, err := fullReply.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
@@ -185,7 +185,7 @@ func (c *Client) parseResponseGoogle(ctx context.Context, w dns.ResponseWriter,
|
|||||||
// Fix DNS response empty []RR.Name
|
// Fix DNS response empty []RR.Name
|
||||||
// Additional section won't be rectified
|
// Additional section won't be rectified
|
||||||
// see: https://stackoverflow.com/questions/52136176/what-is-additional-section-in-dns-and-how-it-works
|
// see: https://stackoverflow.com/questions/52136176/what-is-additional-section-in-dns-and-how-it-works
|
||||||
func fixEmptyNames(respJSON *jsonDNS.Response) {
|
func fixEmptyNames(respJSON *jsondns.Response) {
|
||||||
for i := range respJSON.Answer {
|
for i := range respJSON.Answer {
|
||||||
if respJSON.Answer[i].Name == "" {
|
if respJSON.Answer[i].Name == "" {
|
||||||
respJSON.Answer[i].Name = "."
|
respJSON.Answer[i].Name = "."
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/m13253/dns-over-https/doh-client/selector"
|
"github.com/m13253/dns-over-https/doh-client/selector"
|
||||||
jsonDNS "github.com/m13253/dns-over-https/json-dns"
|
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
requestBinary, err := r.Pack()
|
requestBinary, err := r.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeFormatError
|
reply.Rcode = dns.RcodeFormatError
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -107,7 +107,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
|
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -118,7 +118,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
req, err = http.NewRequest(http.MethodPost, upstream.URL, bytes.NewReader(requestBinary))
|
req, err = http.NewRequest(http.MethodPost, upstream.URL, bytes.NewReader(requestBinary))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -149,7 +149,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
reply := jsonDNS.PrepareReply(r)
|
reply := jsondns.PrepareReply(r)
|
||||||
reply.Rcode = dns.RcodeServerFailure
|
reply.Rcode = dns.RcodeServerFailure
|
||||||
w.WriteMsg(reply)
|
w.WriteMsg(reply)
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
@@ -159,7 +159,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
|||||||
|
|
||||||
return &DNSRequest{
|
return &DNSRequest{
|
||||||
response: resp,
|
response: resp,
|
||||||
reply: jsonDNS.PrepareReply(r),
|
reply: jsondns.PrepareReply(r),
|
||||||
udpSize: udpSize,
|
udpSize: udpSize,
|
||||||
ednsClientAddress: ednsClientAddress,
|
ednsClientAddress: ednsClientAddress,
|
||||||
ednsClientNetmask: ednsClientNetmask,
|
ednsClientNetmask: ednsClientNetmask,
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "2.2.2"
|
VERSION = "2.2.3"
|
||||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -170,11 +170,11 @@ func (s *Server) parseRequestGoogle(ctx context.Context, w http.ResponseWriter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) generateResponseGoogle(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
func (s *Server) generateResponseGoogle(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
||||||
respJSON := jsonDNS.Marshal(req.response)
|
respJSON := jsondns.Marshal(req.response)
|
||||||
respStr, err := json.Marshal(respJSON)
|
respStr, err := json.Marshal(respJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS packet parse failure (%s)", err.Error()), 500)
|
jsondns.FormatError(w, fmt.Sprintf("DNS packet parse failure (%s)", err.Error()), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
jsonDNS "github.com/m13253/dns-over-https/json-dns"
|
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -156,12 +156,12 @@ func (s *Server) parseRequestIETF(ctx context.Context, w http.ResponseWriter, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) generateResponseIETF(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
func (s *Server) generateResponseIETF(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
|
||||||
respJSON := jsonDNS.Marshal(req.response)
|
respJSON := jsondns.Marshal(req.response)
|
||||||
req.response.Id = req.transactionID
|
req.response.Id = req.transactionID
|
||||||
respBytes, err := req.response.Pack()
|
respBytes, err := req.response.Pack()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("DNS packet construct failure with upstream %s: %v\n", req.currentUpstream, err)
|
log.Printf("DNS packet construct failure with upstream %s: %v\n", req.currentUpstream, err)
|
||||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS packet construct failure (%s)", err.Error()), 500)
|
jsondns.FormatError(w, fmt.Sprintf("DNS packet construct failure (%s)", err.Error()), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
jsonDNS "github.com/m13253/dns-over-https/json-dns"
|
jsondns "github.com/m13253/dns-over-https/json-dns"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -216,14 +216,14 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else if contentType == "application/dns-udpwireformat" {
|
} else if contentType == "application/dns-udpwireformat" {
|
||||||
req = s.parseRequestIETF(ctx, w, r)
|
req = s.parseRequestIETF(ctx, w, r)
|
||||||
} else {
|
} else {
|
||||||
jsonDNS.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415)
|
jsondns.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.errcode == 444 {
|
if req.errcode == 444 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.errcode != 0 {
|
if req.errcode != 0 {
|
||||||
jsonDNS.FormatError(w, req.errtext, req.errcode)
|
jsondns.FormatError(w, req.errtext, req.errcode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
|||||||
var err error
|
var err error
|
||||||
req, err = s.doDNSQuery(ctx, req)
|
req, err = s.doDNSQuery(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
|
jsondns.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
|||||||
for _, addr := range strings.Split(XForwardedFor, ",") {
|
for _, addr := range strings.Split(XForwardedFor, ",") {
|
||||||
addr = strings.TrimSpace(addr)
|
addr = strings.TrimSpace(addr)
|
||||||
ip := net.ParseIP(addr)
|
ip := net.ParseIP(addr)
|
||||||
if jsonDNS.IsGlobalIP(ip) {
|
if jsondns.IsGlobalIP(ip) {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
|||||||
if XRealIP != "" {
|
if XRealIP != "" {
|
||||||
addr := strings.TrimSpace(XRealIP)
|
addr := strings.TrimSpace(XRealIP)
|
||||||
ip := net.ParseIP(addr)
|
ip := net.ParseIP(addr)
|
||||||
if jsonDNS.IsGlobalIP(ip) {
|
if jsondns.IsGlobalIP(ip) {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,7 +273,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if ip := remoteAddr.IP; jsonDNS.IsGlobalIP(ip) {
|
if ip := remoteAddr.IP; jsondns.IsGlobalIP(ip) {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -24,6 +24,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "2.2.2"
|
VERSION = "2.2.3"
|
||||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||||
)
|
)
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -5,6 +5,7 @@ go 1.12
|
|||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v0.3.1
|
||||||
github.com/gorilla/handlers v1.4.0
|
github.com/gorilla/handlers v1.4.0
|
||||||
|
github.com/infobloxopen/go-trees v0.0.0-20200715205103-96a057b8dfb9
|
||||||
github.com/miekg/dns v1.1.31
|
github.com/miekg/dns v1.1.31
|
||||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381
|
||||||
|
|||||||
29
go.sum
29
go.sum
@@ -2,23 +2,16 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZsA=
|
github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZsA=
|
||||||
github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
|
github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
|
||||||
github.com/miekg/dns v1.1.14 h1:wkQWn9wIp4mZbwW8XV6Km6owkvRPbOiV004ZM2CkGvA=
|
github.com/infobloxopen/go-trees v0.0.0-20200715205103-96a057b8dfb9 h1:w66aaP3c6SIQ0pi3QH1Tb4AMO3aWoEPxd1CNvLphbkA=
|
||||||
github.com/miekg/dns v1.1.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/infobloxopen/go-trees v0.0.0-20200715205103-96a057b8dfb9/go.mod h1:BaIJzjD2ZnHmx2acPF6XfGLPzNCMiBbMRqJr+8/8uRI=
|
||||||
github.com/miekg/dns v1.1.22 h1:Jm64b3bO9kP43ddLjL2EY3Io6bmy1qGb9Xxz6TqS6rc=
|
|
||||||
github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
|
||||||
github.com/miekg/dns v1.1.30 h1:Qww6FseFn8PRfw07jueqIXqodm0JKiiKuK0DeXSqfyo=
|
|
||||||
github.com/miekg/dns v1.1.30/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
|
||||||
github.com/miekg/dns v1.1.31 h1:sJFOl9BgwbYAWOGEwr61FU28pqsBNdpRBnhGXtO06Oo=
|
github.com/miekg/dns v1.1.31 h1:sJFOl9BgwbYAWOGEwr61FU28pqsBNdpRBnhGXtO06Oo=
|
||||||
github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
|
|
||||||
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg=
|
|
||||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
|
||||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
@@ -26,22 +19,14 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
|
|||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a h1:Yu34BogBivvmu7SAzHHaB9nZWH5D1C+z3F1jyIaYZSQ=
|
|
||||||
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190621203818-d432491b9138 h1:t8BZD9RDjkm9/h7yYN6kE8oaeov5r9aztkB7zKA5Tkg=
|
|
||||||
golang.org/x/sys v0.0.0-20190621203818-d432491b9138/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c h1:UIcGWL6/wpCfyGuJnRFJRurA+yj8RrW7Q6x2YMCXt6c=
|
|
||||||
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 h1:sIky/MyNRSHTrdxfsiUSS4WIAMvInbeXljJz+jDjeYE=
|
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 h1:sIky/MyNRSHTrdxfsiUSS4WIAMvInbeXljJz+jDjeYE=
|
||||||
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
@@ -49,7 +34,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|||||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -38,11 +38,11 @@ type dnsError struct {
|
|||||||
|
|
||||||
func FormatError(w http.ResponseWriter, comment string, errcode int) {
|
func FormatError(w http.ResponseWriter, comment string, errcode int) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
errJson := dnsError{
|
errJSON := dnsError{
|
||||||
Status: dns.RcodeServerFailure,
|
Status: dns.RcodeServerFailure,
|
||||||
Comment: comment,
|
Comment: comment,
|
||||||
}
|
}
|
||||||
errStr, err := json.Marshal(errJson)
|
errStr, err := json.Marshal(errJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,109 +21,111 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/infobloxopen/go-trees/iptree"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RFC6890
|
var defaultFilter *iptree.Tree
|
||||||
var localIPv4Nets = []net.IPNet{
|
|
||||||
// This host on this network
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{0, 0, 0, 0},
|
|
||||||
net.IPMask{255, 0, 0, 0},
|
|
||||||
},
|
|
||||||
// Private-Use Networks
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{10, 0, 0, 0},
|
|
||||||
net.IPMask{255, 0, 0, 0},
|
|
||||||
},
|
|
||||||
// Shared Address Space
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{100, 64, 0, 0},
|
|
||||||
net.IPMask{255, 192, 0, 0},
|
|
||||||
},
|
|
||||||
// Loopback
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{127, 0, 0, 0},
|
|
||||||
net.IPMask{255, 0, 0, 0},
|
|
||||||
},
|
|
||||||
// Link Local
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{169, 254, 0, 0},
|
|
||||||
net.IPMask{255, 255, 0, 0},
|
|
||||||
},
|
|
||||||
// Private-Use Networks
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{172, 16, 0, 0},
|
|
||||||
net.IPMask{255, 240, 0, 0},
|
|
||||||
},
|
|
||||||
// DS-Lite
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{192, 0, 0, 0},
|
|
||||||
net.IPMask{255, 255, 255, 248},
|
|
||||||
},
|
|
||||||
// 6to4 Relay Anycast
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{192, 88, 99, 0},
|
|
||||||
net.IPMask{255, 255, 255, 0},
|
|
||||||
},
|
|
||||||
// Private-Use Networks
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{192, 168, 0, 0},
|
|
||||||
net.IPMask{255, 255, 0, 0},
|
|
||||||
},
|
|
||||||
// Reserved for Future Use & Limited Broadcast
|
|
||||||
net.IPNet{
|
|
||||||
net.IP{240, 0, 0, 0},
|
|
||||||
net.IPMask{240, 0, 0, 0},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// RFC6890
|
func init() {
|
||||||
var localIPv6Nets = []net.IPNet{
|
defaultFilter = iptree.NewTree()
|
||||||
|
|
||||||
|
// RFC6890
|
||||||
|
// This host on this network
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{0, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 0, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Private-Use Networks
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{10, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 0, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Shared Address Space
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{100, 64, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 192, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Loopback
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{127, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 0, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Link Local
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{169, 254, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 255, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Private-Use Networks
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{172, 16, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 240, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// DS-Lite
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{192, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 255, 255, 248},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// 6to4 Relay Anycast
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{192, 88, 99, 0},
|
||||||
|
Mask: net.IPMask{255, 255, 255, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Private-Use Networks
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{192, 168, 0, 0},
|
||||||
|
Mask: net.IPMask{255, 255, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// Reserved for Future Use & Limited Broadcast
|
||||||
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
|
IP: net.IP{240, 0, 0, 0},
|
||||||
|
Mask: net.IPMask{240, 0, 0, 0},
|
||||||
|
}, struct{}{})
|
||||||
|
|
||||||
|
// RFC6890
|
||||||
// Unspecified & Loopback Address
|
// Unspecified & Loopback Address
|
||||||
net.IPNet{
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
IP: net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe},
|
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe},
|
||||||
},
|
}, struct{}{})
|
||||||
|
|
||||||
// Discard-Only Prefix
|
// Discard-Only Prefix
|
||||||
net.IPNet{
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
IP: net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
},
|
}, struct{}{})
|
||||||
|
|
||||||
// Unique-Local
|
// Unique-Local
|
||||||
net.IPNet{
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
net.IP{0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
IP: net.IP{0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
net.IPMask{0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
Mask: net.IPMask{0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
},
|
}, struct{}{})
|
||||||
|
|
||||||
// Linked-Scoped Unicast
|
// Linked-Scoped Unicast
|
||||||
net.IPNet{
|
defaultFilter.InplaceInsertNet(&net.IPNet{
|
||||||
net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
IP: net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
net.IPMask{0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
Mask: net.IPMask{0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||||
},
|
}, struct{}{})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsGlobalIP(ip net.IP) bool {
|
func IsGlobalIP(ip net.IP) bool {
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if ipv4 := ip.To4(); len(ipv4) == net.IPv4len {
|
_, contained := defaultFilter.GetByIP(ip)
|
||||||
for _, ipnet := range localIPv4Nets {
|
return !contained
|
||||||
if ipnet.Contains(ip) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if len(ip) == net.IPv6len {
|
|
||||||
for _, ipnet := range localIPv6Nets {
|
|
||||||
if ipnet.Contains(ip) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|||||||
34
json-dns/globalip_test.go
Normal file
34
json-dns/globalip_test.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package jsondns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleIsGlobalIP() {
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("127.0.0.1")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{192, 168, 1, 1}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("8.8.8.8")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{8, 8, 4, 4}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("::1")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("2001:4860:4860::8888")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x44}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("::ffff:127.0.0.1")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 192, 168, 1, 1}))
|
||||||
|
fmt.Println(IsGlobalIP(net.ParseIP("::ffff:808:808")))
|
||||||
|
fmt.Println(IsGlobalIP(net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 8, 8, 4, 4}))
|
||||||
|
// Output:
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
// false
|
||||||
|
// false
|
||||||
|
// true
|
||||||
|
// true
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -30,12 +30,12 @@ import (
|
|||||||
|
|
||||||
type QuestionList []Question
|
type QuestionList []Question
|
||||||
|
|
||||||
// Fix variant question response in Response.Question
|
|
||||||
//
|
|
||||||
// Solution taken from:
|
|
||||||
// https://engineering.bitnami.com/articles/dealing-with-json-with-non-homogeneous-types-in-go.html
|
|
||||||
// https://archive.is/NU4zR
|
|
||||||
func (ql *QuestionList) UnmarshalJSON(b []byte) error {
|
func (ql *QuestionList) UnmarshalJSON(b []byte) error {
|
||||||
|
// Fix variant question response in Response.Question
|
||||||
|
//
|
||||||
|
// Solution taken from:
|
||||||
|
// https://engineering.bitnami.com/articles/dealing-with-json-with-non-homogeneous-types-in-go.html
|
||||||
|
// https://archive.is/NU4zR
|
||||||
if len(b) > 0 && b[0] == '[' {
|
if len(b) > 0 && b[0] == '[' {
|
||||||
return json.Unmarshal(b, (*[]Question)(ql))
|
return json.Unmarshal(b, (*[]Question)(ql))
|
||||||
}
|
}
|
||||||
@@ -60,13 +60,13 @@ type Response struct {
|
|||||||
// FIXME: We don't have DNSSEC yet! This bit is not reliable!
|
// FIXME: We don't have DNSSEC yet! This bit is not reliable!
|
||||||
AD bool `json:"AD"`
|
AD bool `json:"AD"`
|
||||||
// Whether the client asked to disable DNSSEC
|
// Whether the client asked to disable DNSSEC
|
||||||
CD bool `json:"CD"`
|
CD bool `json:"CD"`
|
||||||
Question QuestionList `json:"Question"`
|
Question QuestionList `json:"Question"`
|
||||||
Answer []RR `json:"Answer,omitempty"`
|
Answer []RR `json:"Answer,omitempty"`
|
||||||
Authority []RR `json:"Authority,omitempty"`
|
Authority []RR `json:"Authority,omitempty"`
|
||||||
Additional []RR `json:"Additional,omitempty"`
|
Additional []RR `json:"Additional,omitempty"`
|
||||||
Comment string `json:"Comment,omitempty"`
|
Comment string `json:"Comment,omitempty"`
|
||||||
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
||||||
// Least time-to-live
|
// Least time-to-live
|
||||||
HaveTTL bool `json:"-"`
|
HaveTTL bool `json:"-"`
|
||||||
LeastTTL uint32 `json:"-"`
|
LeastTTL uint32 `json:"-"`
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jsonDNS
|
package jsondns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|||||||
Reference in New Issue
Block a user