PIMD: Fix code to use srandom/random

pimd rolled it's own solution to random #'s, that was not
terribly random.  Rely on the underlying system to generate
random #'s for us

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2015-06-19 19:26:18 -04:00 committed by Donald Sharp
parent 6b629fe36b
commit 60b40924ea
6 changed files with 9 additions and 101 deletions

View File

@ -52,7 +52,7 @@ libpim_a_SOURCES = \
pim_igmpv3.c pim_str.c pim_mroute.c pim_util.c pim_time.c \
pim_oil.c pim_zlookup.c pim_pim.c pim_tlv.c pim_neighbor.c \
pim_hello.c pim_ifchannel.c pim_join.c pim_assert.c \
pim_msg.c pim_upstream.c pim_rpf.c pim_rand.c pim_macro.c \
pim_msg.c pim_upstream.c pim_rpf.c pim_macro.c \
pim_igmp_join.c pim_ssmpingd.c pim_int.c
noinst_HEADERS = \
@ -61,7 +61,7 @@ noinst_HEADERS = \
pim_igmpv3.h pim_str.h pim_mroute.h pim_util.h pim_time.h \
pim_oil.h pim_zlookup.h pim_pim.h pim_tlv.h pim_neighbor.h \
pim_hello.h pim_ifchannel.h pim_join.h pim_assert.h \
pim_msg.h pim_upstream.h pim_rpf.h pim_rand.h pim_macro.h \
pim_msg.h pim_upstream.h pim_rpf.h pim_macro.h \
pim_igmp_join.h pim_ssmpingd.h pim_int.h
pimd_SOURCES = \

View File

@ -37,7 +37,6 @@
#include "pim_pim.h"
#include "pim_neighbor.h"
#include "pim_ifchannel.h"
#include "pim_rand.h"
#include "pim_sock.h"
#include "pim_time.h"
#include "pim_ssmpingd.h"
@ -845,7 +844,7 @@ int pim_if_t_override_msec(struct interface *ifp)
effective_override_interval_msec =
pim_if_effective_override_interval_msec(ifp);
t_override_msec = pim_rand_next(0, effective_override_interval_msec);
t_override_msec = random() % (effective_override_interval_msec + 1);
return t_override_msec;
}
@ -908,6 +907,7 @@ long pim_if_t_suppressed_msec(struct interface *ifp)
{
struct pim_interface *pim_ifp;
long t_suppressed_msec;
uint32_t ramount = 0;
pim_ifp = ifp->info;
zassert(pim_ifp);
@ -917,8 +917,8 @@ long pim_if_t_suppressed_msec(struct interface *ifp)
return 0;
/* t_suppressed = t_periodic * rand(1.1, 1.4) */
t_suppressed_msec = qpim_t_periodic * pim_rand_next(1100, 1400);
ramount = 1100 + (random() % (1400 - 1100 + 1));
t_suppressed_msec = qpim_t_periodic * ramount;
return t_suppressed_msec;
}

View File

@ -39,7 +39,6 @@
#include "pim_join.h"
#include "pim_assert.h"
#include "pim_msg.h"
#include "pim_rand.h"
static int on_pim_hello_send(struct thread *t);
static int pim_hello_send(struct interface *ifp,
@ -686,7 +685,7 @@ void pim_hello_restart_triggered(struct interface *ifp)
}
zassert(!pim_ifp->t_pim_hello_timer);
random_msec = pim_rand_next(0, triggered_hello_delay_msec);
random_msec = random() % (triggered_hello_delay_msec + 1);
if (PIM_DEBUG_PIM_EVENTS) {
zlog_debug("Scheduling %d msec triggered hello on interface %s",
@ -724,7 +723,7 @@ int pim_sock_add(struct interface *ifp)
pim_ifp->t_pim_sock_read = 0;
pim_ifp->pim_sock_creation = pim_time_monotonic_sec();
pim_ifp->pim_generation_id = pim_rand() & (int64_t) 0xFFFFFFFF;
pim_ifp->pim_generation_id = random();
zlog_info("PIM INTERFACE UP: on interface %s ifindex=%d",
ifp->name, ifp->ifindex);

View File

@ -1,60 +0,0 @@
/*
PIM for Quagga
Copyright (C) 2008 Everton da Silva Marques
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301 USA
$QuaggaId: $Format:%an, %ai, %h$ $
*/
#include "pim_rand.h"
#include "pim_time.h"
/* Quick and dirty random number generator from NUMERICAL RECIPES IN C:
THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5). */
/* BEWARE: '_qseed_' is assigned! */
#define QRANDOM(_qseed_) ((_qseed_) = (((_qseed_) * 1664525L) + 1013904223L))
static long qpim_rand_seed;
void pim_rand_init()
{
qpim_rand_seed = pim_time_monotonic_sec() ^ getpid();
}
long pim_rand()
{
return QRANDOM(qpim_rand_seed);
}
int pim_rand_next(int min, int max)
{
long rand;
assert(min <= max);
/* FIXME better random generator ? */
rand = QRANDOM(qpim_rand_seed);
if (rand < 0)
rand = -rand;
rand = rand % (1 + max - min) + min;
assert(rand >= min);
assert(rand <= max);
return rand;
}

View File

@ -1,30 +0,0 @@
/*
PIM for Quagga
Copyright (C) 2008 Everton da Silva Marques
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301 USA
$QuaggaId: $Format:%an, %ai, %h$ $
*/
#ifndef PIM_RAND_H
#define PIM_RAND_H
void pim_rand_init(void);
long pim_rand(void);
int pim_rand_next(int min, int max);
#endif /* PIM_RAND_H */

View File

@ -33,7 +33,6 @@
#include "pim_oil.h"
#include "pim_pim.h"
#include "pim_upstream.h"
#include "pim_rand.h"
#include "pim_rpf.h"
#include "pim_ssmpingd.h"
@ -82,7 +81,7 @@ static void pim_free()
void pim_init()
{
pim_rand_init();
srandom(time(NULL));
if (!inet_aton(PIM_ALL_PIM_ROUTERS, &qpim_all_pim_routers_addr)) {
zlog_err("%s %s: could not solve %s to group address: errno=%d: %s",