@@ -289,37 +289,35 @@ func (pluginsState *PluginsState) ApplyQueryPlugins(
289289 dlog .Debugf ("Handling query for [%v]" , qName )
290290 pluginsState .qName = qName
291291 pluginsState .questionMsg = & msg
292- if len (* pluginsGlobals .queryPlugins ) == 0 && len (* pluginsGlobals .loggingPlugins ) == 0 {
293- return packet , nil
294- }
295- pluginsGlobals .RLock ()
296- defer pluginsGlobals .RUnlock ()
297- for _ , plugin := range * pluginsGlobals .queryPlugins {
298- if err := plugin .Eval (pluginsState , & msg ); err != nil {
299- dlog .Debugf ("Drops query: %v" , err )
300- pluginsState .action = PluginsActionDrop
301- return packet , err
302- }
303- if pluginsState .action == PluginsActionReject {
304- synth := RefusedResponseFromMessage (
305- & msg ,
306- pluginsGlobals .refusedCodeInResponses ,
307- pluginsGlobals .respondWithIPv4 ,
308- pluginsGlobals .respondWithIPv6 ,
309- pluginsState .rejectTTL ,
310- )
311- pluginsState .synthResponse = synth
312- }
313- if pluginsState .action != PluginsActionContinue {
314- break
292+ if len (* pluginsGlobals .queryPlugins ) > 0 {
293+ pluginsGlobals .RLock ()
294+ for _ , plugin := range * pluginsGlobals .queryPlugins {
295+ if err := plugin .Eval (pluginsState , & msg ); err != nil {
296+ dlog .Debugf ("Dropping query: %v" , err )
297+ pluginsState .action = PluginsActionDrop
298+ pluginsGlobals .RUnlock ()
299+ return packet , err
300+ }
301+ if pluginsState .action == PluginsActionReject {
302+ synth := RefusedResponseFromMessage (
303+ & msg ,
304+ pluginsGlobals .refusedCodeInResponses ,
305+ pluginsGlobals .respondWithIPv4 ,
306+ pluginsGlobals .respondWithIPv6 ,
307+ pluginsState .rejectTTL ,
308+ )
309+ pluginsState .synthResponse = synth
310+ }
311+ if pluginsState .action != PluginsActionContinue {
312+ break
313+ }
315314 }
315+ pluginsGlobals .RUnlock ()
316316 }
317-
318317 packet2 , err := msg .PackBuffer (packet )
319318 if err != nil {
320319 return packet , err
321320 }
322-
323321 // Only get server info if we're continuing and need padding
324322 if pluginsState .action == PluginsActionContinue && getServerInfo != nil {
325323 _ , needsEDNS0Padding := getServerInfo ()
@@ -330,7 +328,6 @@ func (pluginsState *PluginsState) ApplyQueryPlugins(
330328 }
331329 }
332330 }
333-
334331 return packet2 , nil
335332}
336333
@@ -356,28 +353,31 @@ func (pluginsState *PluginsState) ApplyResponsePlugins(
356353 pluginsState .returnCode = PluginsReturnCodeResponseError
357354 }
358355 removeEDNS0Options (& msg )
359- pluginsGlobals .RLock ()
360- defer pluginsGlobals .RUnlock ()
361- for _ , plugin := range * pluginsGlobals .responsePlugins {
362- if err := plugin .Eval (pluginsState , & msg ); err != nil {
363- dlog .Debugf ("Drops response: %v" , err )
364- pluginsState .action = PluginsActionDrop
365- return packet , err
366- }
367- if pluginsState .action == PluginsActionReject {
368- synth := RefusedResponseFromMessage (
369- & msg ,
370- pluginsGlobals .refusedCodeInResponses ,
371- pluginsGlobals .respondWithIPv4 ,
372- pluginsGlobals .respondWithIPv6 ,
373- pluginsState .rejectTTL ,
374- )
375- pluginsState .synthResponse = synth
376- }
377- if pluginsState .action != PluginsActionContinue {
378- break
356+ if len (* pluginsGlobals .responsePlugins ) > 0 {
357+ pluginsGlobals .RLock ()
358+ for _ , plugin := range * pluginsGlobals .responsePlugins {
359+ if err := plugin .Eval (pluginsState , & msg ); err != nil {
360+ dlog .Debugf ("Dropping response: %v" , err )
361+ pluginsState .action = PluginsActionDrop
362+ pluginsGlobals .RUnlock ()
363+ return packet , err
364+ }
365+ if pluginsState .action == PluginsActionReject {
366+ synth := RefusedResponseFromMessage (
367+ & msg ,
368+ pluginsGlobals .refusedCodeInResponses ,
369+ pluginsGlobals .respondWithIPv4 ,
370+ pluginsGlobals .respondWithIPv6 ,
371+ pluginsState .rejectTTL ,
372+ )
373+ pluginsState .synthResponse = synth
374+ }
375+ if pluginsState .action != PluginsActionContinue {
376+ break
377+ }
379378 }
380379 }
380+ pluginsGlobals .RUnlock ()
381381 packet2 , err := msg .PackBuffer (packet )
382382 if err != nil {
383383 return packet , err
0 commit comments