DNS outbound: Add blockTypes (#3812)

This commit is contained in:
风扇滑翔翼 2024-09-15 12:21:51 +08:00 committed by GitHub
parent d7c5a0fc5f
commit 3fed0c773f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 16 deletions

View file

@ -49,6 +49,7 @@ type Handler struct {
server net.Destination
timeout time.Duration
nonIPQuery string
blockTypes []int32
}
func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager policy.Manager) error {
@ -63,6 +64,7 @@ func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager polic
h.server = config.Server.AsDestination()
}
h.nonIPQuery = config.Non_IPQuery
h.blockTypes = config.BlockTypes
return nil
}
@ -84,12 +86,12 @@ func parseIPQuery(b []byte) (r bool, domain string, id uint16, qType dnsmessage.
errors.LogInfoInner(context.Background(), err, "question")
return
}
domain = q.Name.String()
qType = q.Type
if qType != dnsmessage.TypeA && qType != dnsmessage.TypeAAAA {
return
}
domain = q.Name.String()
r = true
return
}
@ -181,10 +183,18 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
if !h.isOwnLink(ctx) {
isIPQuery, domain, id, qType := parseIPQuery(b.Bytes())
if len(h.blockTypes) > 0 {
for _, blocktype := range h.blockTypes {
if blocktype == int32(qType) {
errors.LogInfo(ctx, "blocked type ", qType, " query for domain ", domain)
return nil
}
}
}
if isIPQuery {
go h.handleIPQuery(id, qType, domain, writer)
}
if isIPQuery || h.nonIPQuery == "drop" || qType == 65 {
if isIPQuery || h.nonIPQuery == "drop" {
b.Release()
continue
}