Skip to content
Merged
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 @@ -13,6 +13,7 @@ type DNSOutboundConfig struct {
Port uint16 `json:"port"`
UserLevel uint32 `json:"userLevel"`
NonIPQuery string `json:"nonIPQuery"`
BlockTypes []int32 `json:"blockTypes"`
}

func (c *DNSOutboundConfig) Build() (proto.Message, error) {
Expand All @@ -34,5 +35,6 @@ func (c *DNSOutboundConfig) Build() (proto.Message, error) {
return nil, errors.New(`unknown "nonIPQuery": `, c.NonIPQuery)
}
config.Non_IPQuery = c.NonIPQuery
config.BlockTypes = c.BlockTypes
return config, nil
}
38 changes: 24 additions & 14 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 @@ -14,4 +14,5 @@ message Config {
xray.common.net.Endpoint server = 1;
uint32 user_level = 2;
string non_IP_query = 3;
repeated int32 block_types = 4;
}
14 changes: 12 additions & 2 deletions proxy/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down