Skip to content

Commit aaa12a8

Browse files
Fanglidingdragonbreath2000
authored andcommitted
DNS outbound: Add blockTypes (XTLS#3812)
1 parent 31077f6 commit aaa12a8

4 files changed

Lines changed: 39 additions & 16 deletions

File tree

infra/conf/dns_proxy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type DNSOutboundConfig struct {
1313
Port uint16 `json:"port"`
1414
UserLevel uint32 `json:"userLevel"`
1515
NonIPQuery string `json:"nonIPQuery"`
16+
BlockTypes []int32 `json:"blockTypes"`
1617
}
1718

1819
func (c *DNSOutboundConfig) Build() (proto.Message, error) {
@@ -34,5 +35,6 @@ func (c *DNSOutboundConfig) Build() (proto.Message, error) {
3435
return nil, errors.New(`unknown "nonIPQuery": `, c.NonIPQuery)
3536
}
3637
config.Non_IPQuery = c.NonIPQuery
38+
config.BlockTypes = c.BlockTypes
3739
return config, nil
3840
}

proxy/dns/config.pb.go

Lines changed: 24 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proxy/dns/config.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ message Config {
1414
xray.common.net.Endpoint server = 1;
1515
uint32 user_level = 2;
1616
string non_IP_query = 3;
17+
repeated int32 block_types = 4;
1718
}

proxy/dns/dns.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Handler struct {
4949
server net.Destination
5050
timeout time.Duration
5151
nonIPQuery string
52+
blockTypes []int32
5253
}
5354

5455
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
6364
h.server = config.Server.AsDestination()
6465
}
6566
h.nonIPQuery = config.Non_IPQuery
67+
h.blockTypes = config.BlockTypes
6668
return nil
6769
}
6870

@@ -84,12 +86,12 @@ func parseIPQuery(b []byte) (r bool, domain string, id uint16, qType dnsmessage.
8486
errors.LogInfoInner(context.Background(), err, "question")
8587
return
8688
}
89+
domain = q.Name.String()
8790
qType = q.Type
8891
if qType != dnsmessage.TypeA && qType != dnsmessage.TypeAAAA {
8992
return
9093
}
9194

92-
domain = q.Name.String()
9395
r = true
9496
return
9597
}
@@ -181,10 +183,18 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
181183

182184
if !h.isOwnLink(ctx) {
183185
isIPQuery, domain, id, qType := parseIPQuery(b.Bytes())
186+
if len(h.blockTypes) > 0 {
187+
for _, blocktype := range h.blockTypes {
188+
if blocktype == int32(qType) {
189+
errors.LogInfo(ctx, "blocked type ", qType, " query for domain ", domain)
190+
return nil
191+
}
192+
}
193+
}
184194
if isIPQuery {
185195
go h.handleIPQuery(id, qType, domain, writer)
186196
}
187-
if isIPQuery || h.nonIPQuery == "drop" || qType == 65 {
197+
if isIPQuery || h.nonIPQuery == "drop" {
188198
b.Release()
189199
continue
190200
}

0 commit comments

Comments
 (0)