Skip to content

Commit 3872a50

Browse files
committed
Allow disable cookie
1 parent 727bc89 commit 3872a50

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ Configuration file is "config.json" by default:
8585
"Timeout": 6,
8686
"EDNSClientSubnet": {
8787
"Policy": "disable",
88-
"ExternalIP": ""
88+
"ExternalIP": "",
89+
"NoCookie": true
8990
}
9091
}
9192
],
@@ -98,7 +99,8 @@ Configuration file is "config.json" by default:
9899
"Timeout": 6,
99100
"EDNSClientSubnet": {
100101
"Policy": "disable",
101-
"ExternalIP": ""
102+
"ExternalIP": "",
103+
"NoCookie": true
102104
}
103105
}
104106
],
@@ -135,6 +137,7 @@ IPv6). Overture will handle both TCP and UDP requests. Literal IPv6 addresses ar
135137
+ `manual`: Use external IP if this field is not empty, otherwise use client IP if it is not reserved IP.
136138
+ `disable`: Disable this feature.
137139
+ ExternalIP: If this field is empty, ECS will be disabled when the inbound IP is not an external IP.
140+
+ NoCookie: Disable cookie.
138141
+ OnlyPrimaryDNS: Disable dispatcher feature, use primary DNS only.
139142
+ IPv6UseAlternativeDNS: Redirect IPv6 DNS queries to alternative DNS servers.
140143
+ File: Absolute path like `/path/to/file` is allowed. For Windows users, please use properly escaped path like

config.sample.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"Timeout": 6,
1010
"EDNSClientSubnet": {
1111
"Policy": "disable",
12-
"ExternalIP": ""
12+
"ExternalIP": "",
13+
"NoCookie": true
1314
}
1415
}
1516
],
@@ -22,7 +23,8 @@
2223
"Timeout": 6,
2324
"EDNSClientSubnet": {
2425
"Policy": "disable",
25-
"ExternalIP": ""
26+
"ExternalIP": "",
27+
"NoCookie": true
2628
}
2729
}
2830
],

config.test.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"Timeout": 6,
1010
"EDNSClientSubnet": {
1111
"Policy": "disable",
12-
"ExternalIP": ""
12+
"ExternalIP": "",
13+
"NoCookie": true
1314
}
1415
}
1516
],
@@ -22,7 +23,8 @@
2223
"Timeout": 6,
2324
"EDNSClientSubnet": {
2425
"Policy": "disable",
25-
"ExternalIP": ""
26+
"ExternalIP": "",
27+
"NoCookie": true
2628
}
2729
}
2830
],

core/common/edns.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
type EDNSClientSubnetType struct {
1010
Policy string
1111
ExternalIP string
12+
NoCookie bool
1213
}
1314

14-
func SetEDNSClientSubnet(m *dns.Msg, ip string) {
15+
func SetEDNSClientSubnet(m *dns.Msg, ip string, isNoCookie bool) {
1516

1617
if ip == "" {
1718
return
@@ -40,6 +41,19 @@ func SetEDNSClientSubnet(m *dns.Msg, ip string) {
4041
}
4142
es.SourceScope = 0
4243
o.Option = append(o.Option, es)
44+
if isNoCookie {
45+
deleteCookie(o)
46+
}
47+
}
48+
}
49+
50+
func deleteCookie(o *dns.OPT) {
51+
52+
for i, e0 := range o.Option {
53+
switch e0.(type) {
54+
case *dns.EDNS0_COOKIE:
55+
o.Option = append(o.Option[:i], o.Option[i+1:]...)
56+
}
4357
}
4458
}
4559

core/outbound/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *Client) getEDNSClientSubnetIP() {
5555

5656
func (c *Client) ExchangeFromRemote(isCache bool, isLog bool) {
5757

58-
common.SetEDNSClientSubnet(c.QuestionMessage, c.EDNSClientSubnetIP)
58+
common.SetEDNSClientSubnet(c.QuestionMessage, c.EDNSClientSubnetIP, c.DNSUpstream.EDNSClientSubnet.NoCookie)
5959
c.EDNSClientSubnetIP = common.GetEDNSClientSubnetIP(c.QuestionMessage)
6060

6161
var conn net.Conn

0 commit comments

Comments
 (0)