| 180 | |
| 181 | #ifdef CONFIG_NETDEV_IFINDEX |
| 182 | static int get_ifindex(void) |
| 183 | { |
| 184 | uint32_t devset; |
| 185 | int ndx; |
| 186 | |
| 187 | /* Try to postpone reusing interface indices as long as possible */ |
| 188 | |
| 189 | devset = g_devset | g_devfreed; |
| 190 | if (devset == 0xffffffff) |
| 191 | { |
| 192 | /* Time start reusing interface indices */ |
| 193 | |
| 194 | devset = g_devset; |
| 195 | g_devfreed = 0; |
| 196 | } |
| 197 | |
| 198 | /* Search for an unused index */ |
| 199 | |
| 200 | for (ndx = 0; ndx < MAX_IFINDEX; ndx++) |
| 201 | { |
| 202 | uint32_t bit = 1UL << ndx; |
| 203 | if ((devset & bit) == 0) |
| 204 | { |
| 205 | /* Indicate that this index is in use */ |
| 206 | |
| 207 | g_devset |= bit; |
| 208 | |
| 209 | /* NOTE that the index + 1 is returned. Zero is reserved to |
| 210 | * mean no-index in the POSIX standards. |
| 211 | */ |
| 212 | |
| 213 | return ndx + 1; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return -ENOSPC; |
| 218 | } |
| 219 | #endif |
| 220 | |
| 221 | /**************************************************************************** |