From: Eric Dumazet <eric.dumazet@gmail.com>
To: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net
Subject: Re: [PATCH] inetpeer: ensure to set the maximum tokens the first time
Date: Thu, 27 Sep 2012 14:53:25 +0200 [thread overview]
Message-ID: <1348750405.5093.1234.camel@edumazet-glaptop> (raw)
In-Reply-To: <1348749237-3919-1-git-send-email-nicolas.dichtel@6wind.com>
On Thu, 2012-09-27 at 14:33 +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.
>
> With this patch, it's still possible that last_rate and rate_tokens are 0 at the
> same time after jiffies wraps round, but the probability is very low and the
> only consequence is to let some ICMP packets bypass the filter.
>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
> net/ipv4/inetpeer.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
> index e1e0a4e..92fec02 100644
> --- a/net/ipv4/inetpeer.c
> +++ b/net/ipv4/inetpeer.c
> @@ -559,10 +559,14 @@ bool inet_peer_xrlim_allow(struct inet_peer *peer, int timeout)
>
> token = peer->rate_tokens;
> now = jiffies;
> - token += now - peer->rate_last;
> - peer->rate_last = now;
> - if (token > XRLIM_BURST_FACTOR * timeout)
> + if (!peer->rate_last && !token)
> token = XRLIM_BURST_FACTOR * timeout;
> + else {
> + token += now - peer->rate_last;
> + if (token > XRLIM_BURST_FACTOR * timeout)
> + token = XRLIM_BURST_FACTOR * timeout;
> + }
> + peer->rate_last = now;
> if (token >= timeout) {
> token -= timeout;
> rc = true;
I am sorry I dont understand your patch at all.
Why not init rate_last to a more sensible value ?
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index e1e0a4e..25ed555 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -510,7 +510,7 @@ relookup:
secure_ipv6_id(daddr->addr.a6));
p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
p->rate_tokens = 0;
- p->rate_last = 0;
+ p->rate_last = jiffies;
INIT_LIST_HEAD(&p->gc_list);
/* Link the node. */
next prev parent reply other threads:[~2012-09-27 12:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-27 12:33 [PATCH] inetpeer: ensure to set the maximum tokens the first time Nicolas Dichtel
2012-09-27 12:53 ` Eric Dumazet [this message]
2012-09-27 13:21 ` Nicolas Dichtel
2012-09-27 13:30 ` Eric Dumazet
2012-09-27 13:34 ` Eric Dumazet
2012-09-27 13:39 ` Nicolas Dichtel
2012-09-27 14:11 ` [PATCH v2] inetpeer: fix token initialization Nicolas Dichtel
2012-09-27 14:18 ` Eric Dumazet
2012-09-27 23:28 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1348750405.5093.1234.camel@edumazet-glaptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox