diff options
| -rw-r--r-- | net/ipv4/multipath_random.c | 18 | ||||
| -rw-r--r-- | net/ipv4/multipath_wrandom.c | 15 |
2 files changed, 4 insertions, 29 deletions
diff --git a/net/ipv4/multipath_random.c b/net/ipv4/multipath_random.c index 57f481498fbb..c312785d14d0 100644 --- a/net/ipv4/multipath_random.c +++ b/net/ipv4/multipath_random.c | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
| 33 | #include <linux/mroute.h> | 33 | #include <linux/mroute.h> |
| 34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
| 35 | #include <linux/random.h> | ||
| 35 | #include <net/ip.h> | 36 | #include <net/ip.h> |
| 36 | #include <net/protocol.h> | 37 | #include <net/protocol.h> |
| 37 | #include <linux/skbuff.h> | 38 | #include <linux/skbuff.h> |
| @@ -48,21 +49,6 @@ | |||
| 48 | 49 | ||
| 49 | #define MULTIPATH_MAX_CANDIDATES 40 | 50 | #define MULTIPATH_MAX_CANDIDATES 40 |
| 50 | 51 | ||
| 51 | /* interface to random number generation */ | ||
| 52 | static unsigned int RANDOM_SEED = 93186752; | ||
| 53 | |||
| 54 | static inline unsigned int random(unsigned int ubound) | ||
| 55 | { | ||
| 56 | static unsigned int a = 1588635695, | ||
| 57 | q = 2, | ||
| 58 | r = 1117695901; | ||
| 59 | |||
| 60 | RANDOM_SEED = a*(RANDOM_SEED % q) - r*(RANDOM_SEED / q); | ||
| 61 | |||
| 62 | return RANDOM_SEED % ubound; | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | static void random_select_route(const struct flowi *flp, | 52 | static void random_select_route(const struct flowi *flp, |
| 67 | struct rtable *first, | 53 | struct rtable *first, |
| 68 | struct rtable **rp) | 54 | struct rtable **rp) |
| @@ -84,7 +70,7 @@ static void random_select_route(const struct flowi *flp, | |||
| 84 | if (candidate_count > 1) { | 70 | if (candidate_count > 1) { |
| 85 | unsigned char i = 0; | 71 | unsigned char i = 0; |
| 86 | unsigned char candidate_no = (unsigned char) | 72 | unsigned char candidate_no = (unsigned char) |
| 87 | random(candidate_count); | 73 | (random32() % candidate_count); |
| 88 | 74 | ||
| 89 | /* find chosen candidate and adjust GC data for all candidates | 75 | /* find chosen candidate and adjust GC data for all candidates |
| 90 | * to ensure they stay in cache | 76 | * to ensure they stay in cache |
diff --git a/net/ipv4/multipath_wrandom.c b/net/ipv4/multipath_wrandom.c index 2bdbb92b450a..57c503694539 100644 --- a/net/ipv4/multipath_wrandom.c +++ b/net/ipv4/multipath_wrandom.c | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
| 33 | #include <linux/mroute.h> | 33 | #include <linux/mroute.h> |
| 34 | #include <linux/init.h> | 34 | #include <linux/init.h> |
| 35 | #include <linux/random.h> | ||
| 35 | #include <net/ip.h> | 36 | #include <net/ip.h> |
| 36 | #include <net/protocol.h> | 37 | #include <net/protocol.h> |
| 37 | #include <linux/skbuff.h> | 38 | #include <linux/skbuff.h> |
| @@ -84,18 +85,6 @@ struct multipath_route { | |||
| 84 | /* state: primarily weight per route information */ | 85 | /* state: primarily weight per route information */ |
| 85 | static struct multipath_bucket state[MULTIPATH_STATE_SIZE]; | 86 | static struct multipath_bucket state[MULTIPATH_STATE_SIZE]; |
| 86 | 87 | ||
| 87 | /* interface to random number generation */ | ||
| 88 | static unsigned int RANDOM_SEED = 93186752; | ||
| 89 | |||
| 90 | static inline unsigned int random(unsigned int ubound) | ||
| 91 | { | ||
| 92 | static unsigned int a = 1588635695, | ||
| 93 | q = 2, | ||
| 94 | r = 1117695901; | ||
| 95 | RANDOM_SEED = a*(RANDOM_SEED % q) - r*(RANDOM_SEED / q); | ||
| 96 | return RANDOM_SEED % ubound; | ||
| 97 | } | ||
| 98 | |||
| 99 | static unsigned char __multipath_lookup_weight(const struct flowi *fl, | 88 | static unsigned char __multipath_lookup_weight(const struct flowi *fl, |
| 100 | const struct rtable *rt) | 89 | const struct rtable *rt) |
| 101 | { | 90 | { |
| @@ -193,7 +182,7 @@ static void wrandom_select_route(const struct flowi *flp, | |||
| 193 | 182 | ||
| 194 | /* choose a weighted random candidate */ | 183 | /* choose a weighted random candidate */ |
| 195 | decision = first; | 184 | decision = first; |
| 196 | selector = random(power); | 185 | selector = random32() % power; |
| 197 | last_power = 0; | 186 | last_power = 0; |
| 198 | 187 | ||
| 199 | /* select candidate, adjust GC data and cleanup local state */ | 188 | /* select candidate, adjust GC data and cleanup local state */ |
