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>
diff --git a/pimd/Makefile.am b/pimd/Makefile.am
index b82613a..cb525f7 100644
--- a/pimd/Makefile.am
+++ b/pimd/Makefile.am
@@ -52,7 +52,7 @@
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 @@
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 = \
diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c
index dc3e9a2..6f806a1 100644
--- a/pimd/pim_iface.c
+++ b/pimd/pim_iface.c
@@ -36,7 +36,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"
@@ -839,7 +838,7 @@
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;
}
@@ -902,6 +901,7 @@
{
struct pim_interface *pim_ifp;
long t_suppressed_msec;
+ uint32_t ramount = 0;
pim_ifp = ifp->info;
zassert(pim_ifp);
@@ -911,8 +911,8 @@
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;
}
diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c
index f8ac650..409972d 100644
--- a/pimd/pim_pim.c
+++ b/pimd/pim_pim.c
@@ -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 @@
}
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 @@
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);
diff --git a/pimd/pim_rand.c b/pimd/pim_rand.c
deleted file mode 100644
index df2a111..0000000
--- a/pimd/pim_rand.c
+++ /dev/null
@@ -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;
-}
diff --git a/pimd/pim_rand.h b/pimd/pim_rand.h
deleted file mode 100644
index a1df505..0000000
--- a/pimd/pim_rand.h
+++ /dev/null
@@ -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 */
diff --git a/pimd/pimd.c b/pimd/pimd.c
index 78c3ff5..3797d4f 100644
--- a/pimd/pimd.c
+++ b/pimd/pimd.c
@@ -34,7 +34,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"
@@ -83,7 +82,7 @@
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",