#include "vector.h"
#include "distribute.h"
#include "lib_errors.h"
+#include "network.h"
#include "babel_main.h"
#include "util.h"
/* All flags are unset */
babel_ifp->bucket_time = babel_now.tv_sec;
babel_ifp->bucket = BUCKET_TOKENS_MAX;
- babel_ifp->hello_seqno = (random() & 0xFFFF);
+ babel_ifp->hello_seqno = (frr_weak_random() & 0xFFFF);
babel_ifp->rtt_min = 10000;
babel_ifp->rtt_max = 120000;
babel_ifp->max_rtt_penalty = 150;
#include "filter.h"
#include "plist.h"
#include "lib_errors.h"
+#include "network.h"
#include "babel_main.h"
#include "babeld.h"
static int
babel_init_routing_process(struct thread *thread)
{
- myseqno = (random() & 0xFFFF);
+ myseqno = (frr_weak_random() & 0xFFFF);
babel_get_myid();
babel_load_state_file();
debugf(BABEL_DEBUG_COMMON, "My ID is : %s.", format_eui64(myid));
#include <netinet/in.h>
#include <arpa/inet.h>
+#include "lib/network.h"
+
#include "babel_main.h"
#include "babeld.h"
#include "util.h"
else if(value <= 1)
return value;
else
- return value * 3 / 4 + random() % (value / 2);
+ return value * 3 / 4 + frr_weak_random() % (value / 2);
}
/* d = s1 - s2 */
{
if(d->tv_sec == 0 || d->tv_sec > secs) {
d->tv_sec = secs;
- d->tv_usec = random() % 1000000;
+ d->tv_usec = frr_weak_random() % 1000000;
}
}
#include <zebra.h>
#include "lib/jhash.h"
+#include "lib/network.h"
#include "bfd.h"
* random session identification numbers.
*/
do {
- session_id = ((random() << 16) & 0xFFFF0000)
- | (random() & 0x0000FFFF);
+ session_id = ((frr_weak_random() << 16) & 0xFFFF0000)
+ | (frr_weak_random() & 0x0000FFFF);
} while (session_id == 0 || bfd_id_lookup(session_id) != NULL);
return session_id;
* between 75% and 90%.
*/
maxpercent = (bfd->detect_mult == 1) ? 16 : 26;
- jitter = (xmt_TO * (75 + (random() % maxpercent))) / 100;
+ jitter = (xmt_TO * (75 + (frr_weak_random() % maxpercent))) / 100;
/* XXX remove that division above */
if (is_echo)
#include "hash.h"
#include "queue.h"
#include "frrstr.h"
+#include "network.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
route_match_probability(void *rule, const struct prefix *prefix,
route_map_object_t type, void *object)
{
- long r = random();
+ long r = frr_weak_random();
switch (*(long *)rule) {
case 0:
#include "hash.h"
#include "if.h"
#include "command.h"
+#include "network.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
* most IS-IS timers are no longer than 16 bit
*/
- j = 1 + (int)((RANDOM_SPREAD * random()) / (RAND_MAX + 1.0));
+ j = 1 + (int)((RANDOM_SPREAD * frr_weak_random()) / (RAND_MAX + 1.0));
k = timer - (timer * (100 - jitter)) / 100;
#include "hook.h"
#include "lib_errors.h"
#include "northbound_cli.h"
+#include "network.h"
DEFINE_MTYPE_STATIC(LIB, HOST, "Host config")
DEFINE_MTYPE(LIB, COMPLETION, "Completion item")
gettimeofday(&tv, 0);
- to64(&salt[0], random(), 3);
+ to64(&salt[0], frr_weak_random(), 3);
to64(&salt[3], tv.tv_usec, 3);
salt[5] = '\0';
{
return htonf(net);
}
+
+/**
+ * Helper function that returns a random long value. The main purpose of
+ * this function is to hide a `random()` call that gets flagged by coverity
+ * scan and put it into one place.
+ *
+ * The main usage of this function should be for generating jitter or weak
+ * random values for simple purposes.
+ *
+ * See 'man 3 random' for more information.
+ *
+ * \returns random long integer.
+ */
+long frr_weak_random(void)
+{
+ /* coverity[dont_call] */
+ return random();
+}
extern float htonf(float);
extern float ntohf(float);
+extern long frr_weak_random(void);
+
#ifdef __cplusplus
}
#endif
#include "log.h"
#include "qobj.h"
#include "jhash.h"
+#include "network.h"
static uint32_t qobj_hash(const struct qobj_node *node)
{
node->type = type;
pthread_rwlock_wrlock(&nodes_lock);
do {
- node->nid = (uint64_t)random();
- node->nid ^= (uint64_t)random() << 32;
+ node->nid = (uint64_t)frr_weak_random();
+ node->nid ^= (uint64_t)frr_weak_random() << 32;
} while (!node->nid || qobj_nodes_find(&nodes, node));
qobj_nodes_add(&nodes, node);
pthread_rwlock_unlock(&nodes_lock);
#include "vty.h"
#include "skiplist.h"
#include "lib_errors.h"
+#include "network.h"
DEFINE_MTYPE_STATIC(LIB, SKIP_LIST, "Skip List")
DEFINE_MTYPE_STATIC(LIB, SKIP_LIST_NODE, "Skip Node")
do {
if (randomsLeft <= 0) {
- randomBits = random();
+ randomBits = frr_weak_random();
randomsLeft = BitsInRandom / 2;
}
b = randomBits & 3;
#include "typesafe.h"
#include "memory.h"
+#include "network.h"
DEFINE_MTYPE_STATIC(LIB, TYPEDHASH_BUCKET, "Typed-hash bucket")
DEFINE_MTYPE_STATIC(LIB, SKIPLIST_OFLOW, "Skiplist overflow")
int cmpval;
/* level / newlevel are 1-counted here */
- newlevel = __builtin_ctz(random()) + 1;
+ newlevel = __builtin_ctz(frr_weak_random()) + 1;
if (newlevel > SKIPLIST_MAXDEPTH)
newlevel = SKIPLIST_MAXDEPTH;
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "checksum.h"
+#include "network.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
* 1680s
* and 1740s.
*/
- delay = (random() % (max_delay - min_delay)) + min_delay;
+ delay = (frr_weak_random() % (max_delay - min_delay))
+ + min_delay;
current_index = ospf->lsa_refresh_queue.index
+ (monotime(NULL) - ospf->lsa_refresher_started)
#include "table.h"
#include "log.h"
#include "command.h"
+#include "network.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
/* Start DD exchange protocol */
if (state == NSM_ExStart) {
if (nbr->dd_seqnum == 0)
- nbr->dd_seqnum = (uint32_t)random();
+ nbr->dd_seqnum = (uint32_t)frr_weak_random();
else
nbr->dd_seqnum++;
#include "plist.h"
#include "hash.h"
#include "ferr.h"
+#include "network.h"
#include "pimd.h"
#include "pim_instance.h"
effective_override_interval_msec =
pim_if_effective_override_interval_msec(ifp);
- t_override_msec = random() % (effective_override_interval_msec + 1);
+ t_override_msec =
+ frr_weak_random() % (effective_override_interval_msec + 1);
return t_override_msec;
}
return 0;
/* t_suppressed = t_periodic * rand(1.1, 1.4) */
- ramount = 1100 + (random() % (1400 - 1100 + 1));
+ ramount = 1100 + (frr_weak_random() % (1400 - 1100 + 1));
t_suppressed_msec = router->t_periodic * ramount;
return t_suppressed_msec;
#include "thread.h"
#include "memory.h"
#include "if.h"
+#include "network.h"
#include "pimd.h"
#include "pim_pim.h"
old_genid = pim_ifp->pim_generation_id;
while (old_genid == pim_ifp->pim_generation_id)
- pim_ifp->pim_generation_id = random();
+ pim_ifp->pim_generation_id = frr_weak_random();
zlog_info("PIM INTERFACE UP: on interface %s ifindex=%d", ifp->name,
ifp->ifindex);
#include "hash.h"
#include "jhash.h"
#include "wheel.h"
+#include "network.h"
#include "pimd.h"
#include "pim_pim.h"
if (!null_register) {
uint32_t lower = (0.5 * PIM_REGISTER_SUPPRESSION_PERIOD);
uint32_t upper = (1.5 * PIM_REGISTER_SUPPRESSION_PERIOD);
- time = lower + (random() % (upper - lower + 1))
+ time = lower + (frr_weak_random() % (upper - lower + 1))
- PIM_REGISTER_PROBE_PERIOD;
} else
time = PIM_REGISTER_PROBE_PERIOD;
#include "privs.h"
#include "lib_errors.h"
#include "northbound_cli.h"
+#include "network.h"
#include "ripd/ripd.h"
#include "ripd/rip_nb.h"
random interval between 1 and 5 seconds. If other changes that
would trigger updates occur before the timer expires, a single
update is triggered when the timer expires. */
- interval = (random() % 5) + 1;
+ interval = (frr_weak_random() % 5) + 1;
rip->t_triggered_interval = NULL;
thread_add_timer(master, rip_triggered_interval, rip, interval,
if (jitter_input < JITTER_BOUND)
jitter_input = JITTER_BOUND;
- jitter = (((random() % ((jitter_input * 2) + 1)) - jitter_input));
+ jitter = (((frr_weak_random() % ((jitter_input * 2) + 1))
+ - jitter_input));
return jitter / JITTER_BOUND;
}
#include "privs.h"
#include "lib_errors.h"
#include "northbound_cli.h"
+#include "network.h"
#include "ripngd/ripngd.h"
#include "ripngd/ripng_route.h"
random interval between 1 and 5 seconds. If other changes that
would trigger updates occur before the timer expires, a single
update is triggered when the timer expires. */
- interval = (random() % 5) + 1;
+ interval = (frr_weak_random() % 5) + 1;
ripng->t_triggered_interval = NULL;
thread_add_timer(master, ripng_triggered_interval, ripng, interval,
static int ripng_update_jitter(int time)
{
- return ((random() % (time + 1)) - (time / 2));
+ return ((frr_weak_random() % (time + 1)) - (time / 2));
}
void ripng_event(struct ripng *ripng, enum ripng_event event, int sock)
#include <time.h>
#include "checksum.h"
+#include "network.h"
struct thread_master *master;
exercise %= MAXDATALEN;
for (i = 0; i < exercise; i += sizeof(long int)) {
- long int rand = random();
+ long int rand = frr_weak_random();
for (j = sizeof(long int); j > 0; j--)
buffer[i + (sizeof(long int) - j)] =
#include <zebra.h>
#include <memory.h>
#include "log.h"
+#include "network.h"
/* maximum amount of data to hexdump */
#define MAXDATA 16384
uint8_t d[nl];
for (unsigned int i = 0; i < nl; i++)
- d[i] = random();
+ d[i] = frr_weak_random();
zlog_hexdump(d, nl - 1);
nl += 1 + (nl / 2);
#include "libfrr.h"
#include "lib_errors.h"
#include "zlog_targets.h"
+#include "network.h"
#include <getopt.h>
#include <sys/un.h>
#endif
/* Macros to help randomize timers. */
-#define JITTER(X) ((random() % ((X)+1))-((X)/2))
+#define JITTER(X) ((frr_weak_random() % ((X)+1))-((X)/2))
#define FUZZY(X) ((X)+JITTER((X)/20))
#define DEFAULT_PERIOD 5
#include "if.h"
#include "sockunion.h"
#include "log.h"
+#include "network.h"
extern int irdp_sock;
}
srandom(seed);
- timer = (random() % IRDP_DEFAULT_INTERVAL) + 1;
+ timer = (frr_weak_random() % IRDP_DEFAULT_INTERVAL) + 1;
irdp->AdvPrefList = list_new();
irdp->AdvPrefList->del = (void (*)(void *))Adv_free; /* Destructor */
#include "if.h"
#include "sockunion.h"
#include "log.h"
+#include "network.h"
/* GLOBAL VARS */
}
tmp = irdp->MaxAdvertInterval - irdp->MinAdvertInterval;
- timer = random() % (tmp + 1);
+ timer = frr_weak_random() % (tmp + 1);
timer = irdp->MinAdvertInterval + timer;
if (irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS
thread_cancel(irdp->t_advertise);
irdp->t_advertise = NULL;
- timer = (random() % MAX_RESPONSE_DELAY) + 1;
+ timer = (frr_weak_random() % MAX_RESPONSE_DELAY) + 1;
irdp->t_advertise = NULL;
thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer,