Skip to content

Commit

Permalink
Fix EDNS Clinet Subnet bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shawn1m committed May 5, 2017
1 parent 5134622 commit 1fc90f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/outbound/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (c *Client) ExchangeFromRemote(isCache bool, isLog bool) {

if err != nil {
if err == dns.ErrTruncated {
log.Warn("Maybe " + c.DNSUpstream.Name + " Fail: does not support edns client subnet and it need to be replaced")
log.Warn(c.DNSUpstream.Name + " Fail: Maybe this server does not support EDNS Client Subnet")
return
}
}
Expand Down
24 changes: 12 additions & 12 deletions core/outbound/edns.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ func setEDNSClientSubnet(m *dns.Msg, ip string) {
o := m.IsEdns0()
if o == nil {
o = new(dns.OPT)
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT
m.Extra = append(m.Extra, o)
}
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT

es := isEDNSClientSubnet(o)
if es == nil {
es = new(dns.EDNS0_SUBNET)
es.Code = dns.EDNS0SUBNET
es.Address = net.ParseIP(ip)
if es.Address.To4() != nil {
es.Family = 1 // 1 for IPv4 source address, 2 for IPv6
es.SourceNetmask = 32 // 32 for IPV4, 128 for IPv6
} else {
es.Family = 2 // 1 for IPv4 source address, 2 for IPv6
es.SourceNetmask = 128 // 32 for IPV4, 128 for IPv6
}
es.SourceScope = 0
o.Option = append(o.Option, es)
}
es.Code = dns.EDNS0SUBNET
es.Address = net.ParseIP(ip)
if es.Address.To4() != nil {
es.Family = 1 // 1 for IPv4 source address, 2 for IPv6
es.SourceNetmask = 32 // 32 for IPV4, 128 for IPv6
} else {
es.Family = 2 // 1 for IPv4 source address, 2 for IPv6
es.SourceNetmask = 128 // 32 for IPV4, 128 for IPv6
}
es.SourceScope = 0
}

func isEDNSClientSubnet(o *dns.OPT) *dns.EDNS0_SUBNET {
Expand Down

0 comments on commit 1fc90f7

Please sign in to comment.