From: Joe Perches <joe@perches.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: David Miller <davem@davemloft.net>, netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next] icmp: add a global rate limitation
Date: Fri, 19 Sep 2014 07:56:53 -0700 [thread overview]
Message-ID: <1411138613.24444.13.camel@joe-AO725> (raw)
In-Reply-To: <1411137520.26859.13.camel@edumazet-glaptop2.roam.corp.google.com>
On Fri, 2014-09-19 at 07:38 -0700, Eric Dumazet wrote:
> Current ICMP rate limiting uses inetpeer cache, which is an RBL tree
> protected by a lock, meaning that hosts can be stuck hard if all cpus
> want to check ICMP limits.
>
> When say a DNS or NTP server process is restarted, inetpeer tree grows
> quick and machine comes to its knees.
>
> iptables can not help because the bottleneck happens before ICMP
> messages are even cooked and sent.
>
> This patch adds a new global limitation, using a token bucket filter,
> controlled by two new sysctl :
>
> icmp_msgs_per_sec - INTEGER
> Limit maximal number of ICMP packets sent per second from this host.
> Only messages whose type matches icmp_ratemask are
> controlled by this limit.
> Default: 1000
>
> icmp_msgs_burst - INTEGER
> icmp_msgs_per_sec controls number of ICMP packets sent per second,
> while icmp_msgs_burst controls the burst size of these packets.
> Default: 50
nice.
> diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
[]
> @@ -231,12 +231,62 @@ static inline void icmp_xmit_unlock(struct sock *sk)
> spin_unlock_bh(&sk->sk_lock.slock);
> }
>
> +int sysctl_icmp_msgs_per_sec __read_mostly = 1000;
> +int sysctl_icmp_msgs_burst __read_mostly = 50;
> +
> +static struct {
> + spinlock_t lock;
> + u32 credit;
> + u32 stamp;
> +} icmp_global = {
> + .lock = __SPIN_LOCK_UNLOCKED(icmp_global.lock),
> +};
Is there any real benefit using a u32 stamp
instead of unsigned long?
The stamp comparisons are to jiffies and now
have slightly odd (u32) casts.
> +
> +/**
> + * icmp_global_allow - Are we allowed to send one more ICMP message ?
> + *
> + * Uses a token bucket to limit our ICMP messages to sysctl_icmp_msgs_per_sec.
> + * Returns false if we reached the limit and can not send another packet.
> + * Note: called with BH disabled
> + */
> +bool icmp_global_allow(void)
> +{
> + u32 credit, delta, incr = 0, now = (u32)jiffies;
Doesn't casting jiffies costs a couple cycles
on a 64 bit machine?
next prev parent reply other threads:[~2014-09-19 14:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-19 14:38 [PATCH net-next] icmp: add a global rate limitation Eric Dumazet
2014-09-19 14:56 ` Joe Perches [this message]
2014-09-19 15:11 ` Eric Dumazet
2014-09-22 20:09 ` David Miller
2014-09-22 20:25 ` Eric Dumazet
2014-09-23 16:48 ` 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=1411138613.24444.13.camel@joe-AO725 \
--to=joe@perches.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).