diff options
author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2020-04-17 15:35:15 +0200 |
---|---|---|
committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2020-04-18 01:57:43 +0200 |
commit | 5920b3eb38a6cfd1c9b87106aa7403171408f0bd (patch) | |
tree | fe6c96488ab537bebfeb07f658b4d500ba20c446 /pimd | |
parent | Merge pull request #6248 from donaldsharp/zebra_snmp (diff) | |
download | frr-5920b3eb38a6cfd1c9b87106aa7403171408f0bd.tar.xz frr-5920b3eb38a6cfd1c9b87106aa7403171408f0bd.zip |
*: 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 'pimd')
-rw-r--r-- | pimd/pim_iface.c | 6 | ||||
-rw-r--r-- | pimd/pim_pim.c | 3 | ||||
-rw-r--r-- | pimd/pim_upstream.c | 3 |
3 files changed, 8 insertions, 4 deletions
diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 95b81d5dc..b25b6eaa8 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -28,6 +28,7 @@ #include "plist.h" #include "hash.h" #include "ferr.h" +#include "network.h" #include "pimd.h" #include "pim_instance.h" @@ -1103,7 +1104,8 @@ int pim_if_t_override_msec(struct interface *ifp) 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; } @@ -1181,7 +1183,7 @@ long pim_if_t_suppressed_msec(struct interface *ifp) 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; diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index f37c140bf..3976b262e 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -23,6 +23,7 @@ #include "thread.h" #include "memory.h" #include "if.h" +#include "network.h" #include "pimd.h" #include "pim_pim.h" @@ -878,7 +879,7 @@ int pim_sock_add(struct interface *ifp) 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); diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 982fb7e5a..1e78f4135 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -29,6 +29,7 @@ #include "hash.h" #include "jhash.h" #include "wheel.h" +#include "network.h" #include "pimd.h" #include "pim_pim.h" @@ -1762,7 +1763,7 @@ void pim_upstream_start_register_stop_timer(struct pim_upstream *up, 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; |