diff mbox

[v2] inetpeer: fix token initialization

Message ID 1348755060-3737-1-git-send-email-nicolas.dichtel@6wind.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Nicolas Dichtel Sept. 27, 2012, 2:11 p.m. UTC
When jiffies wraps around (for example, 5 minutes after the boot, see
INITIAL_JIFFIES) and peer has just been created, now - peer->rate_last can be
< XRLIM_BURST_FACTOR * timeout, so token is not set to the maximum value, thus
some icmp packets can be unexpectedly dropped.

Fix this case by initializing last_rate to 60 seconds in the past.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
v2: fix initialization of peer instead of adding some tests in
    inet_peer_xrlim_allow()

 net/ipv4/inetpeer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Eric Dumazet Sept. 27, 2012, 2:18 p.m. UTC | #1
On Thu, 2012-09-27 at 16:11 +0200, Nicolas Dichtel wrote:
> When jiffies wraps around (for example, 5 minutes after the boot, see
> INITIAL_JIFFIES) and peer has just been created, now - peer->rate_last can be
> < XRLIM_BURST_FACTOR * timeout, so token is not set to the maximum value, thus
> some icmp packets can be unexpectedly dropped.
> 
> Fix this case by initializing last_rate to 60 seconds in the past.
> 
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
> v2: fix initialization of peer instead of adding some tests in
>     inet_peer_xrlim_allow()
> 
>  net/ipv4/inetpeer.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
> index e1e0a4e..c7527f6 100644
> --- a/net/ipv4/inetpeer.c
> +++ b/net/ipv4/inetpeer.c
> @@ -510,7 +510,10 @@ relookup:
>  					secure_ipv6_id(daddr->addr.a6));
>  		p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
>  		p->rate_tokens = 0;
> -		p->rate_last = 0;
> +		/* 60*HZ is arbitrary, but chosen enough high so that the first
> +		 * calculation of tokens is at its maximum.
> +		 */
> +		p->rate_last = jiffies - 60*HZ;
>  		INIT_LIST_HEAD(&p->gc_list);
>  
>  		/* Link the node. */

Signed-off-by: Eric Dumazet <edumazet@google.com>

Thanks !


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Sept. 27, 2012, 11:28 p.m. UTC | #2
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 27 Sep 2012 16:18:36 +0200

> On Thu, 2012-09-27 at 16:11 +0200, Nicolas Dichtel wrote:
>> When jiffies wraps around (for example, 5 minutes after the boot, see
>> INITIAL_JIFFIES) and peer has just been created, now - peer->rate_last can be
>> < XRLIM_BURST_FACTOR * timeout, so token is not set to the maximum value, thus
>> some icmp packets can be unexpectedly dropped.
>> 
>> Fix this case by initializing last_rate to 60 seconds in the past.
>> 
>> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>> ---
>> v2: fix initialization of peer instead of adding some tests in
>>     inet_peer_xrlim_allow()
 ...
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied, thanks everyone.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index e1e0a4e..c7527f6 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -510,7 +510,10 @@  relookup:
 					secure_ipv6_id(daddr->addr.a6));
 		p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
 		p->rate_tokens = 0;
-		p->rate_last = 0;
+		/* 60*HZ is arbitrary, but chosen enough high so that the first
+		 * calculation of tokens is at its maximum.
+		 */
+		p->rate_last = jiffies - 60*HZ;
 		INIT_LIST_HEAD(&p->gc_list);
 
 		/* Link the node. */