Skip to content

Commit 8a4a479

Browse files
authored
Merge pull request #2814 from lifenjoiner/dhcp
Reduce DHCP DNS detector instances
2 parents 67c1213 + 19f240f commit 8a4a479

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

dnscrypt-proxy/plugin_forward.go

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (plugin *PluginForward) Init(proxy *Proxy) error {
5454
if err != nil {
5555
return err
5656
}
57+
requiresDHCP := false
5758
for lineNo, line := range strings.Split(lines, "\n") {
5859
line = TrimAndStripInlineComments(line)
5960
if len(line) == 0 {
@@ -71,7 +72,6 @@ func (plugin *PluginForward) Init(proxy *Proxy) error {
7172
)
7273
}
7374
domain = strings.ToLower(domain)
74-
requiresDHCP := false
7575
var sequence []SearchSequenceItem
7676
for _, server := range strings.Split(serversStr, ",") {
7777
server = strings.TrimSpace(server)
@@ -120,36 +120,28 @@ func (plugin *PluginForward) Init(proxy *Proxy) error {
120120
dlog.Infof("Forwarding [%s] to [%s]", domain, server)
121121
}
122122
}
123-
if requiresDHCP {
124-
if len(proxy.userName) > 0 {
125-
dlog.Warn("DHCP/DNS detection may not work when 'user_name' is set or when starting as a non-root user")
126-
}
127-
if proxy.SourceIPv6 {
128-
dlog.Notice("Starting a DHCP/DNS detector for IPv6")
129-
d6 := &dhcpdns.Detector{RemoteIPPort: "[2001:DB8::53]:80"}
130-
if err := d6.Detect(); err != nil {
131-
dlog.Criticalf("Failed to start the DHCP/DNS IPv6 server: %s", err)
132-
continue
133-
}
134-
go d6.Serve(9, 10)
135-
plugin.dhcpdns = append(plugin.dhcpdns, d6)
136-
}
137-
if proxy.SourceIPv4 {
138-
dlog.Notice("Starting a DHCP/DNS detector for IPv4")
139-
d4 := &dhcpdns.Detector{RemoteIPPort: "192.0.2.53:80"}
140-
if err := d4.Detect(); err != nil {
141-
dlog.Criticalf("Failed to start the DHCP/DNS IPv4 server: %s", err)
142-
continue
143-
}
144-
go d4.Serve(9, 10)
145-
plugin.dhcpdns = append(plugin.dhcpdns, d4)
146-
}
147-
}
148123
plugin.forwardMap = append(plugin.forwardMap, PluginForwardEntry{
149124
domain: domain,
150125
sequence: sequence,
151126
})
152127
}
128+
if requiresDHCP {
129+
if len(proxy.userName) > 0 {
130+
dlog.Warn("DHCP/DNS detection may not work when 'user_name' is set or when starting as a non-root user")
131+
}
132+
if proxy.SourceIPv6 {
133+
dlog.Notice("Starting a DHCP/DNS detector for IPv6")
134+
d6 := &dhcpdns.Detector{RemoteIPPort: "[2001:DB8::53]:80"}
135+
go d6.Serve(9, 10)
136+
plugin.dhcpdns = append(plugin.dhcpdns, d6)
137+
}
138+
if proxy.SourceIPv4 {
139+
dlog.Notice("Starting a DHCP/DNS detector for IPv4")
140+
d4 := &dhcpdns.Detector{RemoteIPPort: "192.0.2.53:80"}
141+
go d4.Serve(9, 10)
142+
plugin.dhcpdns = append(plugin.dhcpdns, d4)
143+
}
144+
}
153145
return nil
154146
}
155147

0 commit comments

Comments
 (0)