From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYtEC-0006cD-7q for qemu-devel@nongnu.org; Wed, 23 Oct 2013 03:51:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VYtE0-0004ZF-TF for qemu-devel@nongnu.org; Wed, 23 Oct 2013 03:51:40 -0400 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]:34923) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VYtE0-0004Z3-MY for qemu-devel@nongnu.org; Wed, 23 Oct 2013 03:51:28 -0400 Received: by mail-wi0-f172.google.com with SMTP id ez12so6891961wid.5 for ; Wed, 23 Oct 2013 00:51:27 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <52677FF9.4030202@redhat.com> Date: Wed, 23 Oct 2013 08:51:21 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <20131020145406.GA17618@type> <1382280980-21676-1-git-send-email-samuel.thibault@ens-lyon.org> <1382280980-21676-4-git-send-email-samuel.thibault@ens-lyon.org> In-Reply-To: <1382280980-21676-4-git-send-email-samuel.thibault@ens-lyon.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 04/16] slirp: Adding IPv6, ICMPv6 Echo and NDP autoconfiguration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Samuel Thibault Cc: qemu-devel@nongnu.org, Guillaume Subiron Il 20/10/2013 15:56, Samuel Thibault ha scritto: > +#define rand_a_b(a, b)\ > + (rand()%(int)(b-a)+a) > +#define NDP_Interval rand_a_b(NDP_MinRtrAdvInterval, NDP_MaxRtrAdvInterval) > + > +static void ra_timer_handler(void *opaque) > +{ > + timer_mod(ra_timer, qemu_clock_get_s(QEMU_CLOCK_VIRTUAL) + NDP_Interval); > + ndp_send_ra((Slirp *)opaque); > +} > + > +void icmp6_init(Slirp *slirp) > +{ > + srand(time(NULL)); > + ra_timer = timer_new_s(QEMU_CLOCK_VIRTUAL, ra_timer_handler, slirp); > + timer_mod(ra_timer, qemu_clock_get_s(QEMU_CLOCK_VIRTUAL) + NDP_Interval); > +} Should the granularity of the timer really be seconds? Or should you use the existing milli/nanosecond interface and scale the interval, so that you really get a uniformly distributed random value, even for very small MaxRtrAdvInterval (e.g. for min=3, max=4 you won't get any other value than 3 or 4, which is not really uniformly distributed). Paolo