net/netdev: Add an algorithm to prevent an interface index from being reused until all network interfaces have by assigned once. The prevents removable devices from being removed, unregistered and re-installed, re-registered and keeping the same interface index.
This commit is contained in:
parent
c65e1aa3df
commit
5a0cf3c9a8
@ -89,6 +89,14 @@ EXTERN struct net_driver_s *g_netdevices;
|
||||
*/
|
||||
|
||||
EXTERN uint32_t g_devset;
|
||||
|
||||
/* The set of network devices that have been freed. The purpose of this
|
||||
* set is to postpone reuse of a interface index for as long as possible,
|
||||
* i.e., don't reuse an interface index until all of the possible indices
|
||||
* have been used.
|
||||
*/
|
||||
|
||||
EXTERN uint32_t g_devfreed;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -104,6 +104,14 @@ struct net_driver_s *g_netdevices = NULL;
|
||||
*/
|
||||
|
||||
uint32_t g_devset;
|
||||
|
||||
/* The set of network devices that have been freed. The purpose of this
|
||||
* set is to postpone reuse of a interface index for as long as possible,
|
||||
* i.e., don't reuse an interface index until all of the possible indices
|
||||
* have been used.
|
||||
*/
|
||||
|
||||
uint32_t g_devfreed;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@ -175,14 +183,26 @@ static int find_devnum(FAR const char *devfmt)
|
||||
#ifdef CONFIG_NETDEV_IFINDEX
|
||||
static int get_ifindex(void)
|
||||
{
|
||||
uint32_t devset;
|
||||
int ndx;
|
||||
|
||||
/* Try to postpone re-using interface indices as long as possible */
|
||||
|
||||
devset = g_devset | g_devfreed;
|
||||
if (devset == 0xffffffff)
|
||||
{
|
||||
/* Time start re-using interface indices */
|
||||
|
||||
devset = g_devset;
|
||||
g_devfreed = 0;
|
||||
}
|
||||
|
||||
/* Search for an unused index */
|
||||
|
||||
for (ndx = 0; ndx < MAX_IFINDEX; ndx++)
|
||||
{
|
||||
uint32_t bit = 1L << ndx;
|
||||
if ((g_devset & bit) == 0)
|
||||
if ((devset & bit) == 0)
|
||||
{
|
||||
/* Indicate that this index is in use */
|
||||
|
||||
|
@ -97,8 +97,9 @@ static inline void free_ifindex(int ndx)
|
||||
|
||||
/* The bit should be in the set state */
|
||||
|
||||
DEBUGASSERT((g_devset & bit) != 0);
|
||||
DEBUGASSERT((g_devset & bit) != 0 && (g_devfreed & bit) == 0);
|
||||
g_devset &= ~bit;
|
||||
g_devfreed |= bit;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user