Skip to content

Commit 667279a

Browse files
RPRXyuhan6665
authored andcommitted
Add "nonIPQuery" to DNS outbound ("drop" by default)
And fixed a memory leak And regenerated *.pb.go
1 parent 62e881b commit 667279a

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

common/protocol/headers.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/conf/dns_proxy.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
)
88

99
type DNSOutboundConfig struct {
10-
Network Network `json:"network"`
11-
Address *Address `json:"address"`
12-
Port uint16 `json:"port"`
13-
UserLevel uint32 `json:"userLevel"`
10+
Network Network `json:"network"`
11+
Address *Address `json:"address"`
12+
Port uint16 `json:"port"`
13+
UserLevel uint32 `json:"userLevel"`
14+
NonIPQuery string `json:"nonIPQuery"`
1415
}
1516

1617
func (c *DNSOutboundConfig) Build() (proto.Message, error) {
@@ -24,5 +25,12 @@ func (c *DNSOutboundConfig) Build() (proto.Message, error) {
2425
if c.Address != nil {
2526
config.Server.Address = c.Address.Build()
2627
}
28+
switch c.NonIPQuery {
29+
case "":
30+
c.NonIPQuery = "drop"
31+
case "drop", "skip":
32+
default:
33+
return nil, newError(`unknown "nonIPQuery": `, c.NonIPQuery)
34+
}
2735
return config, nil
2836
}

proxy/dns/config.pb.go

+19-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proxy/dns/config.proto

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ message Config {
1313
// original one.
1414
xray.common.net.Endpoint server = 1;
1515
uint32 user_level = 2;
16+
string non_IP_query = 3;
1617
}

proxy/dns/dns.go

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Handler struct {
4444
ownLinkVerifier ownLinkVerifier
4545
server net.Destination
4646
timeout time.Duration
47+
nonIPQuery string
4748
}
4849

4950
func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager policy.Manager) error {
@@ -57,6 +58,7 @@ func (h *Handler) Init(config *Config, dnsClient dns.Client, policyManager polic
5758
if config.Server != nil {
5859
h.server = config.Server.AsDestination()
5960
}
61+
h.nonIPQuery = config.Non_IPQuery
6062
return nil
6163
}
6264

@@ -175,6 +177,9 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
175177
isIPQuery, domain, id, qType := parseIPQuery(b.Bytes())
176178
if isIPQuery {
177179
go h.handleIPQuery(id, qType, domain, writer)
180+
}
181+
if isIPQuery || h.nonIPQuery == "drop" {
182+
b.Release()
178183
continue
179184
}
180185
}

0 commit comments

Comments
 (0)