Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions infra/conf/dns_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type DNSOutboundConfig struct {
UserLevel uint32 `json:"userLevel"`
NonIPQuery string `json:"nonIPQuery"`
BlockTypes []int32 `json:"blockTypes"`
SkipRCodes []uint32 `json:"skipRCodes"`
}

func (c *DNSOutboundConfig) Build() (proto.Message, error) {
Expand All @@ -36,5 +37,6 @@ func (c *DNSOutboundConfig) Build() (proto.Message, error) {
}
config.Non_IPQuery = c.NonIPQuery
config.BlockTypes = c.BlockTypes
config.Skip_RCodes = c.SkipRCodes
return config, nil
}
24 changes: 17 additions & 7 deletions proxy/dns/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proxy/dns/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ message Config {
uint32 user_level = 2;
string non_IP_query = 3;
repeated int32 block_types = 4;
repeated uint32 skip_R_codes = 5;
}
19 changes: 16 additions & 3 deletions proxy/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Handler struct {
timeout time.Duration
nonIPQuery string
blockTypes []int32
skipRCodes []uint32
}

func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager policy.Manager) error {
Expand All @@ -66,6 +67,7 @@ func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager polic
}
h.nonIPQuery = config.Non_IPQuery
h.blockTypes = config.BlockTypes
h.skipRCodes = config.Skip_RCodes
return nil
}

Expand Down Expand Up @@ -193,9 +195,10 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
}
}
if isIPQuery {
go h.handleIPQuery(id, qType, domain, writer)
go h.handleIPQuery(id, qType, domain, writer, connWriter, b)
continue
}
if isIPQuery || h.nonIPQuery == "drop" {
if h.nonIPQuery == "drop" {
b.Release()
continue
}
Expand Down Expand Up @@ -233,7 +236,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
return nil
}

func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string, writer dns_proto.MessageWriter) {
func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string, writer, conWriter dns_proto.MessageWriter, msg *buf.Buffer) {
var ips []net.IP
var err error

Expand All @@ -256,6 +259,16 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
}

rcode := dns.RCodeFromError(err)
if rcode > 0 && len(h.skipRCodes) > 0 {
for _, skip := range h.skipRCodes {
if uint16(skip) == rcode {
conWriter.WriteMessage(msg)
errors.LogInfo(context.Background(), "skipped IP query with rcode ", rcode, " for domain ", domain)
return
}
}
}
msg.Release()
if rcode == 0 && len(ips) == 0 && !go_errors.Is(err, dns.ErrEmptyResponse) {
errors.LogInfoInner(context.Background(), err, "ip query")
return
Expand Down
Loading