netfilter: nft_limit: fix packet ratelimiting
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 16 May 2018 20:58:33 +0000 (22:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 8 Jul 2018 13:30:51 +0000 (15:30 +0200)
commit27aa533f24e9951aff62b3b6a14c1feed8cbf624
treef0c954d80744f4f2172c236cba34b8ceecff91e1
parent510e1e8020a8a1b7cf53a84f18a7d03757daba55
netfilter: nft_limit: fix packet ratelimiting

[ Upstream commit 3e0f64b7dd3149f75e8652ff1df56cffeedc8fc1 ]

Credit calculations for the packet ratelimiting are not correct, as per
the applied ratelimit of 25/second and burst 8, a total of 33 packets
should have been accepted.  This is true in iptables(33) but not in
nftables (~65). For packet ratelimiting, use:

div_u64(limit->nsecs, limit->rate) * limit->burst;

to calculate credit, just like in iptables' xt_limit does.

Moreover, use default burst in iptables, users are expecting similar
behaviour.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netfilter/nft_limit.c