summaryrefslogtreecommitdiff
path: root/babeld
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2020-04-17 10:35:15 -0300
committerRafael Zalamena <rzalamena@opensourcerouting.org>2020-04-17 20:57:43 -0300
commit5920b3eb38a6cfd1c9b87106aa7403171408f0bd (patch)
treefe6c96488ab537bebfeb07f658b4d500ba20c446 /babeld
parent4110aa2cb342fb0f025746c4b7df7707f69334c5 (diff)
*: replace all random() calls
Replace all `random()` calls with a function called `frr_weak_random()` and make it clear that it is only supposed to be used for weak random applications. Use the annotation described by the Coverity Scan documentation to ignore `random()` call warnings. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'babeld')
-rw-r--r--babeld/babel_interface.c3
-rw-r--r--babeld/babeld.c3
-rw-r--r--babeld/util.c6
3 files changed, 8 insertions, 4 deletions
diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c
index 21fb481631..5d66e51fa7 100644
--- a/babeld/babel_interface.c
+++ b/babeld/babel_interface.c
@@ -28,6 +28,7 @@ THE SOFTWARE.
#include "vector.h"
#include "distribute.h"
#include "lib_errors.h"
+#include "network.h"
#include "babel_main.h"
#include "util.h"
@@ -1396,7 +1397,7 @@ babel_interface_allocate (void)
/* 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;
diff --git a/babeld/babeld.c b/babeld/babeld.c
index 906f48564d..09955cfbef 100644
--- a/babeld/babeld.c
+++ b/babeld/babeld.c
@@ -30,6 +30,7 @@ THE SOFTWARE.
#include "filter.h"
#include "plist.h"
#include "lib_errors.h"
+#include "network.h"
#include "babel_main.h"
#include "babeld.h"
@@ -213,7 +214,7 @@ babel_read_protocol (struct thread *thread)
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));
diff --git a/babeld/util.c b/babeld/util.c
index c6606e4f0e..e99bd861dc 100644
--- a/babeld/util.c
+++ b/babeld/util.c
@@ -39,6 +39,8 @@ THE SOFTWARE.
#include <netinet/in.h>
#include <arpa/inet.h>
+#include "lib/network.h"
+
#include "babel_main.h"
#include "babeld.h"
#include "util.h"
@@ -51,7 +53,7 @@ roughly(int value)
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 */
@@ -145,7 +147,7 @@ timeval_min_sec(struct timeval *d, time_t secs)
{
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;
}
}