Skip to content

Commit 9b2c674

Browse files
authored
Base on clientProto value explicitly to dereference clientAddr (#2393)
There are variants local_doh and trampoline for internal flow.
1 parent d381af5 commit 9b2c674

File tree

6 files changed

+44
-20
lines changed

6 files changed

+44
-20
lines changed

dnscrypt-proxy/plugin_allow_ip.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,14 @@ func (plugin *PluginAllowedIP) Eval(pluginsState *PluginsState, msg *dns.Msg) er
119119
if plugin.logger != nil {
120120
qName := pluginsState.qName
121121
var clientIPStr string
122-
if pluginsState.clientProto == "udp" {
122+
switch pluginsState.clientProto {
123+
case "udp":
123124
clientIPStr = (*pluginsState.clientAddr).(*net.UDPAddr).IP.String()
124-
} else {
125+
case "tcp", "local_doh":
125126
clientIPStr = (*pluginsState.clientAddr).(*net.TCPAddr).IP.String()
127+
default:
128+
// Ignore internal flow.
129+
return nil
126130
}
127131
var line string
128132
if plugin.format == "tsv" {

dnscrypt-proxy/plugin_allow_name.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ func (plugin *PluginAllowName) Eval(pluginsState *PluginsState, msg *dns.Msg) er
9696
pluginsState.sessionData["whitelisted"] = true
9797
if plugin.logger != nil {
9898
var clientIPStr string
99-
if pluginsState.clientProto == "udp" {
99+
switch pluginsState.clientProto {
100+
case "udp":
100101
clientIPStr = (*pluginsState.clientAddr).(*net.UDPAddr).IP.String()
101-
} else {
102+
case "tcp", "local_doh":
102103
clientIPStr = (*pluginsState.clientAddr).(*net.TCPAddr).IP.String()
104+
default:
105+
// Ignore internal flow.
106+
return nil
103107
}
104108
var line string
105109
if plugin.format == "tsv" {

dnscrypt-proxy/plugin_block_ip.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,14 @@ func (plugin *PluginBlockIP) Eval(pluginsState *PluginsState, msg *dns.Msg) erro
123123
if plugin.logger != nil {
124124
qName := pluginsState.qName
125125
var clientIPStr string
126-
if pluginsState.clientProto == "udp" {
126+
switch pluginsState.clientProto {
127+
case "udp":
127128
clientIPStr = (*pluginsState.clientAddr).(*net.UDPAddr).IP.String()
128-
} else {
129+
case "tcp", "local_doh":
129130
clientIPStr = (*pluginsState.clientAddr).(*net.TCPAddr).IP.String()
131+
default:
132+
// Ignore internal flow.
133+
return nil
130134
}
131135
var line string
132136
if plugin.format == "tsv" {

dnscrypt-proxy/plugin_block_name.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ func (blockedNames *BlockedNames) check(pluginsState *PluginsState, qName string
4444
pluginsState.returnCode = PluginsReturnCodeReject
4545
if blockedNames.logger != nil {
4646
var clientIPStr string
47-
if pluginsState.clientProto == "udp" {
47+
switch pluginsState.clientProto {
48+
case "udp":
4849
clientIPStr = (*pluginsState.clientAddr).(*net.UDPAddr).IP.String()
49-
} else {
50+
case "tcp", "local_doh":
5051
clientIPStr = (*pluginsState.clientAddr).(*net.TCPAddr).IP.String()
52+
default:
53+
// Ignore internal flow.
54+
return false, nil
5155
}
5256
var line string
5357
if blockedNames.format == "tsv" {

dnscrypt-proxy/plugin_nx_log.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,21 @@ func (plugin *PluginNxLog) Eval(pluginsState *PluginsState, msg *dns.Msg) error
4343
if msg.Rcode != dns.RcodeNameError {
4444
return nil
4545
}
46+
var clientIPStr string
47+
switch pluginsState.clientProto {
48+
case "udp":
49+
clientIPStr = (*pluginsState.clientAddr).(*net.UDPAddr).IP.String()
50+
case "tcp", "local_doh":
51+
clientIPStr = (*pluginsState.clientAddr).(*net.TCPAddr).IP.String()
52+
default:
53+
// Ignore internal flow.
54+
return nil
55+
}
4656
question := msg.Question[0]
4757
qType, ok := dns.TypeToString[question.Qtype]
4858
if !ok {
4959
qType = string(qType)
5060
}
51-
var clientIPStr string
52-
if pluginsState.clientProto == "udp" {
53-
clientIPStr = (*pluginsState.clientAddr).(*net.UDPAddr).IP.String()
54-
} else {
55-
clientIPStr = (*pluginsState.clientAddr).(*net.TCPAddr).IP.String()
56-
}
5761
qName := pluginsState.qName
5862

5963
var line string

dnscrypt-proxy/plugin_query_log.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ func (plugin *PluginQueryLog) Reload() error {
4343
}
4444

4545
func (plugin *PluginQueryLog) Eval(pluginsState *PluginsState, msg *dns.Msg) error {
46+
var clientIPStr string
47+
switch pluginsState.clientProto {
48+
case "udp":
49+
clientIPStr = (*pluginsState.clientAddr).(*net.UDPAddr).IP.String()
50+
case "tcp", "local_doh":
51+
clientIPStr = (*pluginsState.clientAddr).(*net.TCPAddr).IP.String()
52+
default:
53+
// Ignore internal flow.
54+
return nil
55+
}
4656
question := msg.Question[0]
4757
qType, ok := dns.TypeToString[question.Qtype]
4858
if !ok {
@@ -55,12 +65,6 @@ func (plugin *PluginQueryLog) Eval(pluginsState *PluginsState, msg *dns.Msg) err
5565
}
5666
}
5767
}
58-
var clientIPStr string
59-
if pluginsState.clientProto == "udp" {
60-
clientIPStr = (*pluginsState.clientAddr).(*net.UDPAddr).IP.String()
61-
} else {
62-
clientIPStr = (*pluginsState.clientAddr).(*net.TCPAddr).IP.String()
63-
}
6468
qName := pluginsState.qName
6569

6670
if pluginsState.cacheHit {

0 commit comments

Comments
 (0)