* Allocate an ifindex array entry; return 0 on success or an error on * failure. */
| 368 | * failure. |
| 369 | */ |
| 370 | static u_short |
| 371 | ifindex_alloc(void **old) |
| 372 | { |
| 373 | u_short idx; |
| 374 | |
| 375 | IFNET_WLOCK_ASSERT(); |
| 376 | /* |
| 377 | * Try to find an empty slot below V_if_index. If we fail, take the |
| 378 | * next slot. |
| 379 | */ |
| 380 | for (idx = 1; idx <= V_if_index; idx++) { |
| 381 | if (V_ifindex_table[idx] == NULL) |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | /* Catch if_index overflow. */ |
| 386 | if (idx >= V_if_indexlim) { |
| 387 | *old = if_grow(); |
| 388 | return (USHRT_MAX); |
| 389 | } |
| 390 | if (idx > V_if_index) |
| 391 | V_if_index = idx; |
| 392 | return (idx); |
| 393 | } |
| 394 | |
| 395 | static void |
| 396 | ifindex_free_locked(u_short idx) |
no test coverage detected