[smokeping-users] non-uniqe DNS IDs with SmokePing and AnotherDNS

Gert Doering gert at space.net
Wed Oct 24 20:11:20 CEST 2012


Hi,

(copying in Olaf Kolkmann, who I harrassed with this as well, thus 
full-quoting)

On Wed, Oct 24, 2012 at 08:47:31PM +0300, Niko Tyni wrote:
> On Wed, Oct 24, 2012 at 07:07:18PM +0200, Gert Doering wrote:
>  
> > Specifically, every DNS probe SmokePing sends carries the very same
> > Query ID - which it shouldn't do from a DNS PoV, but even from staring
> > at the code involved, this should not happen (I have traces from various
> > versions of SmokePing and perl on FreeBSD and Linux that show this, so 
> > I claim it's not my local installation that is borked).
> 
> I think I see the problem. The main SmokePing process forks the probe
> subprocesses, which first call srand() in Smokeping::make_kid() to
> initialize the random number generator.  The AnotherDNS probe then
> starts one subprocess for each ping, but all of those inherit the state
> of the RNG.
> 
> Does the attached (untested) patch fix it for you? 
> 
> % perl -le 'srand; fork; print "pid $$ => " . rand()'
> pid 5039 => 0.712492274426953
> pid 5040 => 0.712492274426953
> 
> % perl -le 'fork; srand; print "pid $$ => " . rand()'
> pid 5250 => 0.967728406264545
> pid 5251 => 0.62419137808411

Indeed, this explanation is completely logical (phew) and I was missing
that extra fork() - I knew that the AnotherDNS probe is forked once
(well visible in "ps") but I didn't know that individual ping runs gets
forked as well.  I *did* search for srand() calls in the source :-)

With your patch, the behaviour changes to "the query ID is identical
for each batch of 5 probes belonging to the same 'target'", which is what
one *should* expect after reading the code.

Whether sending multiple queries with the same query ID is "right" according
to DNS lore, I leave to Olaf to answer - but it takes out most of the 
confusion.

thanks,

gert



> 
> Cheers,
> -- 
> Niko Tyni   ntyni at debian.org

> >From 9571093782e110a56007f91d96f5fcbfa3830ea0 Mon Sep 17 00:00:00 2001
> From: Niko Tyni <ntyni at debian.org>
> Date: Wed, 24 Oct 2012 20:34:07 +0300
> Subject: [PATCH] Reseed the random number generator for each pinger process
> 
> As spotted by Gert Doering, rand() gives the same results in each
> pinger subprocess. This is because they all inherit the same RNG state
> from their parent.
> 
> Fix this undesired behaviour by reseeding the RNG with the current time
> and the process ID.
> 
> The argument of srand() shouldn't really matter much on modern Perls,
> but we're not very concerned about the quality of the random numbers
> either, and time()+$$ should make sure it's different for each process.
> ---
>  lib/Smokeping/probes/basefork.pm |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/Smokeping/probes/basefork.pm b/lib/Smokeping/probes/basefork.pm
> index 0de7b6d..147c572 100644
> --- a/lib/Smokeping/probes/basefork.pm
> +++ b/lib/Smokeping/probes/basefork.pm
> @@ -201,6 +201,9 @@ sub ping {
>  				# we detach from the parent's process group
>  				setpgrp(0, $$);
>  
> +				# re-initialize the RNG for each subprocess
> +				srand(time()+$$);
> +
>  				my @times = $self->pingone($t);
>  				print join(" ", @times), "\n";
>  				exit;
> -- 
> 1.7.10.4
> 



Gert Doering
        -- NetMaster
-- 
have you enabled IPv6 on something today...?

SpaceNet AG                        Vorstand: Sebastian v. Bomhard
Joseph-Dollinger-Bogen 14          Aufsichtsratsvors.: A. Grundner-Culemann
D-80807 Muenchen                   HRB: 136055 (AG Muenchen)
Tel: +49 (89) 32356-444            USt-IdNr.: DE813185279
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 306 bytes
Desc: not available
Url : http://lists.oetiker.ch/pipermail/smokeping-users/attachments/20121024/97653c67/attachment.pgp 


More information about the smokeping-users mailing list