| 213 | } |
| 214 | |
| 215 | static uint16_t |
| 216 | ip_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 | |
| 242 | void |
| 243 | ip_fillid(struct ip *ip) |