Skip to content

Commit

Permalink
filtering: imp cognit
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Dec 5, 2023
1 parent 563aa45 commit b232209
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions internal/filtering/filtering.go
Expand Up @@ -651,32 +651,14 @@ func hostsRewrites(
host string,
hs hostsfile.Storage,
) (vals []rules.RRValue, rs []*ResultRule) {
var isValidProto func(netip.Addr) (ok bool)
switch qtype {
case dns.TypeA:
for _, addr := range hs.ByName(host) {
if !addr.Is4() {
continue
}

vals = append(vals, addr)
rs = append(rs, &ResultRule{
Text: fmt.Sprintf("%s %s", addr, host),
FilterListID: SysHostsListID,
})
}
isValidProto = netip.Addr.Is4
case dns.TypeAAAA:
for _, addr := range hs.ByName(host) {
if !addr.Is6() {
continue
}

vals = append(vals, addr)
rs = append(rs, &ResultRule{
Text: fmt.Sprintf("%s %s", addr, host),
FilterListID: SysHostsListID,
})
}
isValidProto = netip.Addr.Is6
case dns.TypePTR:
// TODO(e.burkov): Add some [netip]-aware alternative to [netutil].
ip, err := netutil.IPFromReversedAddr(host)
if err != nil {
log.Debug("filtering: failed to parse PTR record %q: %s", host, err)
Expand All @@ -693,8 +675,22 @@ func hostsRewrites(
FilterListID: SysHostsListID,
})
}

return vals, rs
default:
log.Debug("filtering: unsupported qtype %d", qtype)

return nil, nil
}

for _, addr := range hs.ByName(host) {
if isValidProto(addr) {
vals = append(vals, addr)
rs = append(rs, &ResultRule{
Text: fmt.Sprintf("%s %s", addr, host),
FilterListID: SysHostsListID,
})
}
}

return vals, rs
Expand Down

0 comments on commit b232209

Please sign in to comment.