Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2340831imu; Sat, 8 Dec 2018 22:22:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/X1Go69BZ5GaZxAXl0ruKOtT/XuiBpCv1ZSGf9gZtTBKw2BPUpcDa/nqGL5USIEgIuVjxj5 X-Received: by 2002:a17:902:22f:: with SMTP id 44mr7790841plc.137.1544336556264; Sat, 08 Dec 2018 22:22:36 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2si6895852plt.101.2018.12.08.22.22.21; Sat, 08 Dec 2018 22:22:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@c0d3.blue header.s=2018 header.b=Hk0RX1IZ; arc=fail (DNS record missing); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726233AbeLIGVY (ORCPT + 99 others); Sun, 9 Dec 2018 01:21:24 -0500 Received: from mail.aperture-lab.de ([138.201.29.205]:44094 "EHLO mail.aperture-lab.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbeLIGVY (ORCPT ); Sun, 9 Dec 2018 01:21:24 -0500 X-Greylist: delayed 418 seconds by postgrey-1.27 at vger.kernel.org; Sun, 09 Dec 2018 01:21:21 EST From: =?UTF-8?q?Linus=20L=C3=BCssing?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c0d3.blue; s=2018; t=1544336062; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=oNHoiu42/t/ww87E46wJP16iwRyR74KseDxu5fVbDXM=; b=Hk0RX1IZ4A4xusHEMxXqrBC1ik1wUXrq5iAO73QOUgGmSK42RLv8EJlKW0rW1iZYPb05Iw xuopuq4ty3Hf3EzYLYhnZEErlIsFfT1XN05kQSN9Qul0q44SucWKNkiYvGvFSRaYKnyhGQ jETIYZnMMp8p4bgJ8v0NNC8u4C0V1mDIflyEmcNrgFqIQo17/WuvAcV6+T6BxrwtDU02HL JV56tJmf4TPTPbZll5qIqbGxTDUYGDHA5fkEtVxea/WpXAqBl3xgW5C6AGH9eg4UaN+KAL dbFCV8qlff9FuNWy6DX07M2vQI6PtLuQskrdu7oeoJ1nNKGfyhGeHeVPTlqozw== To: netfilter-devel@vger.kernel.org Cc: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , Roopa Prabhu , Nikolay Aleksandrov , "David S . Miller" , coreteam@netfilter.org, bridge@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Linus=20L=C3=BCssing?= Subject: [PATCH net-next v2] netfilter: ebtables: avoid resetting limit rule state Date: Sun, 9 Dec 2018 07:14:05 +0100 Message-Id: <20181209061405.15112-1-linus.luessing@c0d3.blue> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=c0d3.blue; s=2018; t=1544336062; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=oNHoiu42/t/ww87E46wJP16iwRyR74KseDxu5fVbDXM=; b=a/DSPdOcQJeJldAo9RRTvPiaBya/2nb1D7UgKe+2KuEifskLbZ7IzD6Dd7blpHW4gwrTae lq5+aMuXdxIO0tzUbcKqMHMNS9lQ6MsBGQK4+MFVQ7BW7T8tzixbbMsrXeS9uZ21Ipn+gz ekwRqufbSv8bDlDuDLieGPybBWoaPpsR9EMeBo5qcjZdQ/dfvQKir/FpbOuc8zV5GkhbMV g8stxjGQ0FfAke7SmXOUam2IoNqcLwy7+hK8onIw9hxzcGDb5WuoUNVPR5sVNckxlwyyqR 7oOIPkYa3l+dvzyyYhtyhZx/qQZVg3+vITSdK5F9iRiNXDP33L4wz7NiSCuQMg== ARC-Seal: i=1; s=2018; d=c0d3.blue; t=1544336062; a=rsa-sha256; cv=none; b=ZafTox+1Tboge3Mn7To8WKxfwn87ktKPdtIg76a1XaFSRI4yCmGEEfaxP8UVNHH2hvjOlK AUZceFPh9805kb2VuXN/nt3xAOTUZVx/KNKAec4XCunoCLuhdr1XTU1oyEdbfMrKkkL0SV +FkrKeUHbZmHs2NcWmZqTvR5j7YJoLGZ8gda1qpQq8OwvNvfShD4N9gxIeEy+/Au/dP5us TVtQE2EMMcPNcyvZ7MXh2JeNKwTDcNykQ9CVaGuqWUoRmDt30sopfQZG+y7gp1HvT/5GWp STutfZi3HZrZdpziQWeFHgDmV+jGL2as+OW3MqRNEgICZf6HgbAoucG8OvJNHg== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=linus.luessing@c0d3.blue smtp.mailfrom=linus.luessing@c0d3.blue Authentication-Results: ORIGINATING; auth=pass smtp.auth=linus.luessing@c0d3.blue smtp.mailfrom=linus.luessing@c0d3.blue Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org So far any changes with ebtables will reset the state of limit rules, leading to spikes in traffic. This is especially noticeable if changes are done frequently, for instance via a daemon. This patch fixes this by bailing out from (re)setting if the limit rule was initialized before. When sending packets every 250ms for 600s, with a "--limit 1/sec --limit-burst 50" rule and a command like this in the background: $ ebtables -N VOIDCHAIN $ while true; do ebtables -F VOIDCHAIN; sleep 30; done The results are: Before: ~1600 packets After: 650 packets This also aligns the behavior to "xtables-nft-multi ebtables" which uses nft_limit instead of ebt_limit. In tests nft_limit did not suffer from this issue and rate limited to 650 just fine. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Linus Lüssing --- Changelog v2: - Adjusted commit message (adjusted title, added test results with nft_limit for comparison) - Excluded rate limiting variables from zeroing when passed to userspace by increasing .usersize. This became necessary with 4.11 / commit ec2318904965 ("xtables: extend matches and targets with .usersize") - Retested with 4.20-rc4 and current net-next/master (83af01ba1c2d) v1 was: "[net-next] bridge: ebtables: Avoid resetting limit rule state" -> https://lore.kernel.org/patchwork/patch/854802/ --- net/bridge/netfilter/ebt_limit.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/bridge/netfilter/ebt_limit.c b/net/bridge/netfilter/ebt_limit.c index 165b9d678cf1..2cf9861c3bce 100644 --- a/net/bridge/netfilter/ebt_limit.c +++ b/net/bridge/netfilter/ebt_limit.c @@ -69,6 +69,10 @@ static int ebt_limit_mt_check(const struct xt_mtchk_param *par) { struct ebt_limit_info *info = par->matchinfo; + /* Do not reset state on unrelated table changes */ + if (info->prev) + return 0; + /* Check for overflow. */ if (info->burst == 0 || user2credits(info->avg * info->burst) < user2credits(info->avg)) { @@ -105,7 +109,7 @@ static struct xt_match ebt_limit_mt_reg __read_mostly = { .match = ebt_limit_mt, .checkentry = ebt_limit_mt_check, .matchsize = sizeof(struct ebt_limit_info), - .usersize = offsetof(struct ebt_limit_info, prev), + .usersize = sizeof(struct ebt_limit_info), #ifdef CONFIG_COMPAT .compatsize = sizeof(struct ebt_compat_limit_info), #endif -- 2.11.0