MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ip_randomid

Function ip_randomid

freebsd/netinet/ip_id.c:215–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215static uint16_t
216ip_randomid(void)
217{
218 uint16_t new_id;
219
220 mtx_lock(&V_ip_id_mtx);
221 /*
222 * To avoid a conflict with the zeros that the array is initially
223 * filled with, we never hand out an id of zero.
224 */
225 new_id = 0;
226 do {
227 if (new_id != 0)
228 V_random_id_collisions++;
229 arc4rand(&new_id, sizeof(new_id), 0);
230 } while (bit_test(V_id_bits, new_id) || new_id == 0);
231 bit_clear(V_id_bits, V_id_array[V_array_ptr]);
232 bit_set(V_id_bits, new_id);
233 V_id_array[V_array_ptr] = new_id;
234 V_array_ptr++;
235 if (V_array_ptr == V_array_size)
236 V_array_ptr = 0;
237 V_random_id_total++;
238 mtx_unlock(&V_ip_id_mtx);
239 return (new_id);
240}
241
242void
243ip_fillid(struct ip *ip)

Callers 1

ip_fillidFunction · 0.85

Calls 6

bit_testFunction · 0.85
bit_clearFunction · 0.85
bit_setFunction · 0.85
mtx_lockFunction · 0.50
arc4randFunction · 0.50
mtx_unlockFunction · 0.50

Tested by

no test coverage detected