@@ -54,6 +54,7 @@ func (plugin *PluginForward) Init(proxy *Proxy) error {
54
54
if err != nil {
55
55
return err
56
56
}
57
+ requiresDHCP := false
57
58
for lineNo , line := range strings .Split (lines , "\n " ) {
58
59
line = TrimAndStripInlineComments (line )
59
60
if len (line ) == 0 {
@@ -71,7 +72,6 @@ func (plugin *PluginForward) Init(proxy *Proxy) error {
71
72
)
72
73
}
73
74
domain = strings .ToLower (domain )
74
- requiresDHCP := false
75
75
var sequence []SearchSequenceItem
76
76
for _ , server := range strings .Split (serversStr , "," ) {
77
77
server = strings .TrimSpace (server )
@@ -120,36 +120,28 @@ func (plugin *PluginForward) Init(proxy *Proxy) error {
120
120
dlog .Infof ("Forwarding [%s] to [%s]" , domain , server )
121
121
}
122
122
}
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
- }
148
123
plugin .forwardMap = append (plugin .forwardMap , PluginForwardEntry {
149
124
domain : domain ,
150
125
sequence : sequence ,
151
126
})
152
127
}
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
+ }
153
145
return nil
154
146
}
155
147
0 commit comments