Skip to content

Commit

Permalink
Revert "all: safesearch https"
Browse files Browse the repository at this point in the history
This reverts commit 1c9564b.
  • Loading branch information
Mizzick committed Apr 11, 2024
1 parent 1c9564b commit cd403a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
9 changes: 1 addition & 8 deletions internal/dnsforward/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *Server) genDNSFilterMessage(
) (resp *dns.Msg) {
req := dctx.Req
qt := req.Question[0].Qtype
if qt != dns.TypeA && qt != dns.TypeAAAA && qt != dns.TypeHTTPS {
if qt != dns.TypeA && qt != dns.TypeAAAA {
m, _, _ := s.dnsFilter.BlockingMode()
if m == filtering.BlockingModeNullIP {
return s.makeResponse(req)
Expand Down Expand Up @@ -97,13 +97,6 @@ func (s *Server) getCNAMEWithIPs(req *dns.Msg, ips []netip.Addr, cname string) (
ans = append(ans, s.genAnswerAAAA(req, ip))
}
}
case dns.TypeHTTPS:
ans = append(ans, s.genAnswersWithIPv4s(req, ips)...)
for _, ip := range ips {
if ip.Is6() {
ans = append(ans, s.genAnswerAAAA(req, ip))
}
}
default:
// Go on and return an empty response.
}
Expand Down
32 changes: 11 additions & 21 deletions internal/filtering/safesearch/safesearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ func (ss *Default) searchHost(host string, qtype rules.RRType) (res *rules.DNSRe
}

// newResult creates Result object from rewrite rule. qtype must be either
// [dns.TypeA] or [dns.TypeAAAA], or [dns.TypeHTTPS]. If err is nil, res is
// never nil, so that the empty result is converted into a NODATA response.
// [dns.TypeA] or [dns.TypeAAAA]. If err is nil, res is never nil, so that the
// empty result is converted into a NODATA response.
//
// TODO(a.garipov): Use the main rewrite result mechanism used in
// [dnsforward.Server.filterDNSRequest]. Now we resolve IPs for CNAME to save
Expand Down Expand Up @@ -286,11 +286,11 @@ func (ss *Default) newResult(
return res, nil
}

// qtypeToProto returns "ip4" for [dns.TypeA] or [dns.TypeHTTPS], and "ip6" for
// [dns.TypeAAAA]. It panics for other types.
// qtypeToProto returns "ip4" for [dns.TypeA] and "ip6" for [dns.TypeAAAA].
// It panics for other types.
func qtypeToProto(qtype rules.RRType) (proto string) {
switch qtype {
case dns.TypeA, dns.TypeHTTPS:
case dns.TypeA:
return "ip4"
case dns.TypeAAAA:
return "ip6"
Expand All @@ -300,31 +300,21 @@ func qtypeToProto(qtype rules.RRType) (proto string) {
}

// fitToProto returns a non-nil IP address if ip is the correct protocol version
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA], or
// [dns.TypeHTTPS].
// for qtype. qtype is expected to be either [dns.TypeA] or [dns.TypeAAAA].
func fitToProto(ip net.IP, qtype rules.RRType) (res netip.Addr) {
ip4 := ip.To4()
ip6 := ip.To16()

if qtype == dns.TypeA && ip4 != nil {
return netip.AddrFrom4([4]byte(ip4))
} else if ip6 != nil && qtype == dns.TypeAAAA {
return netip.AddrFrom16([16]byte(ip6))
}

if qtype == dns.TypeHTTPS {
if ip4 := ip.To4(); qtype == dns.TypeA {
if ip4 != nil {
return netip.AddrFrom4([4]byte(ip4))
} else if ip6 != nil {
return netip.AddrFrom16([16]byte(ip6))
}
} else if ip = ip.To16(); ip != nil && qtype == dns.TypeAAAA {
return netip.AddrFrom16([16]byte(ip))
}

return netip.Addr{}
}

// setCacheResult stores data in cache for host. qtype is expected to be either
// [dns.TypeA] or [dns.TypeAAAA], or [dns.TypeHTTPS].
// [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering.Result) {
expire := uint32(time.Now().Add(ss.cacheTTL).Unix())
exp := make([]byte, 4)
Expand All @@ -345,7 +335,7 @@ func (ss *Default) setCacheResult(host string, qtype rules.RRType, res filtering
}

// getCachedResult returns stored data from cache for host. qtype is expected
// to be either [dns.TypeA] or [dns.TypeAAAA], or [dns.TypeHTTPS].
// to be either [dns.TypeA] or [dns.TypeAAAA].
func (ss *Default) getCachedResult(
host string,
qtype rules.RRType,
Expand Down

0 comments on commit cd403a2

Please sign in to comment.