Browse Source

Quagga: Fix code to use srandom/random

Quagga was using a mix of srand/rand and srandom/random.
Consolidate to use srandom/random which are the POSIX
versions of random number generators

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Donald Sharp 4 years ago
parent
commit
f31bab4fbf
8 changed files with 10 additions and 21 deletions
  1. 1 1
      bgpd/bgp_fsm.c
  2. 1 1
      bgpd/bgp_main.c
  3. 1 12
      bgpd/bgp_routemap.c
  4. 1 1
      isisd/isis_main.c
  5. 1 1
      isisd/isis_misc.c
  6. 1 1
      lib/command.c
  7. 2 2
      ripd/ripd.c
  8. 2 2
      ripngd/ripngd.c

+ 1 - 1
bgpd/bgp_fsm.c

@@ -65,7 +65,7 @@ static int bgp_start (struct peer *);
 static int
 bgp_start_jitter (int time)
 {
-  return ((rand () % (time + 1)) - (time / 2));
+  return ((random () % (time + 1)) - (time / 2));
 }
 
 /* Check if suppress start/restart of sessions to peer. */

+ 1 - 1
bgpd/bgp_main.c

@@ -420,7 +420,7 @@ main (int argc, char **argv)
   master = bm->master;
 
   /* Initializations. */
-  srand (time (NULL));
+  srandom (time (NULL));
   signal_init (master, array_size(bgp_signals), bgp_signals);
   zprivs_init (&bgpd_privs);
   cmd_init (1);

+ 1 - 12
bgpd/bgp_routemap.c

@@ -884,12 +884,7 @@ static route_map_result_t
 route_match_probability (void *rule, struct prefix *prefix,
 		    route_map_object_t type, void *object)
 {
-  long r;
-#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
-  r = random();
-#else
-  r = (long) rand();
-#endif
+  long r = random();
 
   switch (*(long *) rule)
   {
@@ -911,12 +906,6 @@ route_match_probability_compile (const char *arg)
   long *lobule;
   unsigned  perc;
 
-#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
-  srandom (time (NULL));
-#else
-  srand (time (NULL));
-#endif
-
   perc    = atoi (arg);
   lobule  = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (long));
 

+ 1 - 1
isisd/isis_main.c

@@ -320,7 +320,7 @@ main (int argc, char **argv, char **envp)
   master = thread_master_create ();
 
   /* random seed from time */
-  srand (time (NULL));
+  srandom (time (NULL));
 
   /*
    *  initializations

+ 1 - 1
isisd/isis_misc.c

@@ -510,7 +510,7 @@ isis_jitter (unsigned long timer, unsigned long jitter)
    * most IS-IS timers are no longer than 16 bit
    */
 
-  j = 1 + (int) ((RANDOM_SPREAD * rand ()) / (RAND_MAX + 1.0));
+  j = 1 + (int) ((RANDOM_SPREAD * random ()) / (RAND_MAX + 1.0));
 
   k = timer - (timer * (100 - jitter)) / 100;
 

+ 1 - 1
lib/command.c

@@ -4144,7 +4144,7 @@ cmd_init (int terminal)
       install_element (VIEW_NODE, &show_work_queues_cmd);
       install_element (ENABLE_NODE, &show_work_queues_cmd);
     }
-  srand(time(NULL));
+  srandom(time(NULL));
 }
 
 static void

+ 2 - 2
ripd/ripd.c

@@ -2859,7 +2859,7 @@ rip_update_jitter (unsigned long time)
   if (jitter_input < JITTER_BOUND)
     jitter_input = JITTER_BOUND;
   
-  jitter = (((rand () % ((jitter_input * 2) + 1)) - jitter_input));  
+  jitter = (((random () % ((jitter_input * 2) + 1)) - jitter_input));  
 
   return jitter/JITTER_BOUND;
 }
@@ -4132,7 +4132,7 @@ void
 rip_init (void)
 {
   /* Randomize for triggered update random(). */
-  srand (time (NULL));
+  srandom (time (NULL));
 
   /* Install top nodes. */
   install_node (&rip_node, config_write_rip);

+ 2 - 2
ripngd/ripngd.c

@@ -1936,7 +1936,7 @@ ripng_request (struct interface *ifp)
 static int
 ripng_update_jitter (int time)
 {
-  return ((rand () % (time + 1)) - (time / 2));
+  return ((random () % (time + 1)) - (time / 2));
 }
 
 void
@@ -3084,7 +3084,7 @@ void
 ripng_init ()
 {
   /* Randomize. */
-  srand (time (NULL));
+  srandom (time (NULL));
 
   /* Install RIPNG_NODE. */
   install_node (&cmd_ripng_node, ripng_config_write);