* [PATH] dev: reusing unregistered ifindex values in net_device
@ 2010-11-18 15:25 Daniel Turull
2010-11-18 15:37 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Turull @ 2010-11-18 15:25 UTC (permalink / raw)
To: netdev; +Cc: Voravit T., Robert Olsson
When a new index is going to be assigned in register_netdevice,
the dev_new_index starts to search possible values from the last index
given to a device although there might be some free ifindex that has been
previously unregistered. This behaviour may create gap(s) in the ifindex list.
This patch checks for unused values from 1 and gives to the new device the
first available value. This limits the maximum ifindex to a smaller value.
The ifindex will still be unique since the old value is no longer in use.
Reported-by: Voravit Tanyingyong <voravit@kth.se>
Signed-off-by: Daniel Turull <daniel.turull@gmail.com>
---
diff --git a/net/core/dev.c b/net/core/dev.c
index 381b8e2..a7babab 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4871,7 +4871,7 @@ int dev_ioctl(struct net *net, unsigned int cmd,
void __user *arg)
*/
static int dev_new_index(struct net *net)
{
- static int ifindex;
+ int ifindex;
for (;;) {
if (++ifindex <= 0)
ifindex = 1;
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATH] dev: reusing unregistered ifindex values in net_device
2010-11-18 15:25 [PATH] dev: reusing unregistered ifindex values in net_device Daniel Turull
@ 2010-11-18 15:37 ` Eric Dumazet
2010-11-18 15:43 ` Daniel Turull
2010-11-18 16:01 ` David Miller
0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2010-11-18 15:37 UTC (permalink / raw)
To: Daniel Turull; +Cc: netdev, Voravit T., Robert Olsson
Le jeudi 18 novembre 2010 à 16:25 +0100, Daniel Turull a écrit :
> When a new index is going to be assigned in register_netdevice,
> the dev_new_index starts to search possible values from the last index
> given to a device although there might be some free ifindex that has been
> previously unregistered. This behaviour may create gap(s) in the ifindex list.
>
> This patch checks for unused values from 1 and gives to the new device the
> first available value. This limits the maximum ifindex to a smaller value.
>
> The ifindex will still be unique since the old value is no longer in use.
>
> Reported-by: Voravit Tanyingyong <voravit@kth.se>
> Signed-off-by: Daniel Turull <daniel.turull@gmail.com>
>
> ---
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 381b8e2..a7babab 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -4871,7 +4871,7 @@ int dev_ioctl(struct net *net, unsigned int cmd,
> void __user *arg)
> */
> static int dev_new_index(struct net *net)
> {
> - static int ifindex;
> + int ifindex;
> for (;;) {
> if (++ifindex <= 0)
> ifindex = 1;
> --
NACK
Two bugs
1) ifindex is not initialized : you'll be suprised of random values
2) ifindex should not be reused. You'll be surprised so applications can
break. SNMP comes to mind.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATH] dev: reusing unregistered ifindex values in net_device
2010-11-18 15:37 ` Eric Dumazet
@ 2010-11-18 15:43 ` Daniel Turull
2010-11-18 16:01 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: Daniel Turull @ 2010-11-18 15:43 UTC (permalink / raw)
To: Eric Dumazet; +Cc: netdev, Voravit T., Robert Olsson
Ok,
thanks you for you quick response.
//Daniel
On Thu, Nov 18, 2010 at 16:37, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Le jeudi 18 novembre 2010 à 16:25 +0100, Daniel Turull a écrit :
>> When a new index is going to be assigned in register_netdevice,
>> the dev_new_index starts to search possible values from the last index
>> given to a device although there might be some free ifindex that has been
>> previously unregistered. This behaviour may create gap(s) in the ifindex list.
>>
>> This patch checks for unused values from 1 and gives to the new device the
>> first available value. This limits the maximum ifindex to a smaller value.
>>
>> The ifindex will still be unique since the old value is no longer in use.
>>
>> Reported-by: Voravit Tanyingyong <voravit@kth.se>
>> Signed-off-by: Daniel Turull <daniel.turull@gmail.com>
>>
>> ---
>> diff --git a/net/core/dev.c b/net/core/dev.c
>> index 381b8e2..a7babab 100644
>> --- a/net/core/dev.c
>> +++ b/net/core/dev.c
>> @@ -4871,7 +4871,7 @@ int dev_ioctl(struct net *net, unsigned int cmd,
>> void __user *arg)
>> */
>> static int dev_new_index(struct net *net)
>> {
>> - static int ifindex;
>> + int ifindex;
>> for (;;) {
>> if (++ifindex <= 0)
>> ifindex = 1;
>> --
>
> NACK
>
> Two bugs
>
> 1) ifindex is not initialized : you'll be suprised of random values
>
> 2) ifindex should not be reused. You'll be surprised so applications can
> break. SNMP comes to mind.
>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATH] dev: reusing unregistered ifindex values in net_device
2010-11-18 15:37 ` Eric Dumazet
2010-11-18 15:43 ` Daniel Turull
@ 2010-11-18 16:01 ` David Miller
2010-11-18 16:14 ` Stephen Hemminger
1 sibling, 1 reply; 5+ messages in thread
From: David Miller @ 2010-11-18 16:01 UTC (permalink / raw)
To: eric.dumazet; +Cc: daniel.turull, netdev, voravit, robert
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 18 Nov 2010 16:37:08 +0100
> Two bugs
>
> 1) ifindex is not initialized : you'll be suprised of random values
>
> 2) ifindex should not be reused. You'll be surprised so applications can
> break. SNMP comes to mind.
Right, the current algorithm is intentionally trying to avoid new
devices from using indexes that were used by another device in the
past.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATH] dev: reusing unregistered ifindex values in net_device
2010-11-18 16:01 ` David Miller
@ 2010-11-18 16:14 ` Stephen Hemminger
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2010-11-18 16:14 UTC (permalink / raw)
To: daniel.turull; +Cc: David Miller, eric.dumazet, netdev, voravit, robert
On Thu, 18 Nov 2010 08:01:39 -0800 (PST)
David Miller <davem@davemloft.net> wrote:
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Thu, 18 Nov 2010 16:37:08 +0100
>
> > Two bugs
> >
> > 1) ifindex is not initialized : you'll be suprised of random values
> >
> > 2) ifindex should not be reused. You'll be surprised so applications can
> > break. SNMP comes to mind.
>
> Right, the current algorithm is intentionally trying to avoid new
> devices from using indexes that were used by another device in the
> past.
Also think of the case of adding 10,000 VLAN's. If the search started from
beginning on each insertion dev_new_index would go from O(N) to O(N^2) which
really hurts.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-11-18 16:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-18 15:25 [PATH] dev: reusing unregistered ifindex values in net_device Daniel Turull
2010-11-18 15:37 ` Eric Dumazet
2010-11-18 15:43 ` Daniel Turull
2010-11-18 16:01 ` David Miller
2010-11-18 16:14 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).