56static const int drop_freq[] = { 500, 100, 50 };
61static const int corrupt_freq[] = { 500, 100, 50 };
67static const int up_low[] = { 60, 10, 5 };
68static const int up_high[] = { 600, 60, 10 };
74static const int down_low[] = { 5, 10, 10 };
75static const int down_high[] = { 10, 60, 120 };
81static const struct packet_flood_parms packet_flood_data[] = { { 10, 100 },
85struct packet_flood_parms
86get_packet_flood_parms(int level)
88 ASSERT(level > 0 && level < 4);
89 return packet_flood_data[level - 1];
101#if defined(__GNUC__) || defined(__clang__)
102#pragma GCC diagnostic push
103#pragma GCC diagnostic ignored "-Wconversion"
111roll(
int low,
int high)
115 ret = low + (
get_random() % (high - low + 1));
116 ASSERT(ret >= low && ret <= high);
120static bool initialized;
128ask_gremlin(
int flags)
130 const int up_down_level = GREMLIN_UP_DOWN_LEVEL(flags);
131 const int drop_level = GREMLIN_DROP_LEVEL(flags);
156 delta = roll(down_low[up_down_level - 1], down_high[up_down_level - 1]);
161 delta = roll(up_low[up_down_level - 1], up_high[up_down_level - 1]);
165 msg(
D_GREMLIN,
"GREMLIN: CONNECTION GOING %s FOR %d SECONDS", (up ?
"UP" :
"DOWN"),
173 if (up && flip(drop_freq[drop_level - 1]))
187corrupt_gremlin(
struct buffer *buf,
int flags)
189 const int corrupt_level = GREMLIN_CORRUPT_LEVEL(flags);
192 if (flip(corrupt_freq[corrupt_level - 1]))
198 uint8_t r = roll(0, 255);
199 int method = roll(0, 5);
208 *(
BPTR(buf) + buf->
len - 1) = r;
212 *(
BPTR(buf) + roll(0, buf->
len - 1)) = r;
224 buf->
len -= roll(0, buf->
len - 1);
238#if defined(__GNUC__) || defined(__clang__)
239#pragma GCC diagnostic pop
static bool buf_write(struct buffer *dest, const void *src, size_t size)
long int get_random(void)
Data Channel Cryptography Module.
#define D_GREMLIN_VERBOSE
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.