netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 20/23] netfilter: labels: don't emit ct event if labels were not changed
Date: Fri, 22 Apr 2016 15:39:51 +0200	[thread overview]
Message-ID: <1461332394-3994-21-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1461332394-3994-1-git-send-email-pablo@netfilter.org>

From: Florian Westphal <fw@strlen.de>

make the replace function only send a ctnetlink event if the contents
of the new set is different.

Otherwise 'ct label set ct label | bar'

will cause netlink event storm since we "replace" labels for each packet.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_conntrack_labels.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/net/netfilter/nf_conntrack_labels.c b/net/netfilter/nf_conntrack_labels.c
index 3a30900..bd7f26b 100644
--- a/net/netfilter/nf_conntrack_labels.c
+++ b/net/netfilter/nf_conntrack_labels.c
@@ -33,14 +33,18 @@ int nf_connlabel_set(struct nf_conn *ct, u16 bit)
 }
 EXPORT_SYMBOL_GPL(nf_connlabel_set);
 
-static void replace_u32(u32 *address, u32 mask, u32 new)
+static int replace_u32(u32 *address, u32 mask, u32 new)
 {
 	u32 old, tmp;
 
 	do {
 		old = *address;
 		tmp = (old & mask) ^ new;
+		if (old == tmp)
+			return 0;
 	} while (cmpxchg(address, old, tmp) != old);
+
+	return 1;
 }
 
 int nf_connlabels_replace(struct nf_conn *ct,
@@ -49,6 +53,7 @@ int nf_connlabels_replace(struct nf_conn *ct,
 {
 	struct nf_conn_labels *labels;
 	unsigned int size, i;
+	int changed = 0;
 	u32 *dst;
 
 	labels = nf_ct_labels_find(ct);
@@ -60,16 +65,15 @@ int nf_connlabels_replace(struct nf_conn *ct,
 		words32 = size / sizeof(u32);
 
 	dst = (u32 *) labels->bits;
-	if (words32) {
-		for (i = 0; i < words32; i++)
-			replace_u32(&dst[i], mask ? ~mask[i] : 0, data[i]);
-	}
+	for (i = 0; i < words32; i++)
+		changed |= replace_u32(&dst[i], mask ? ~mask[i] : 0, data[i]);
 
 	size /= sizeof(u32);
 	for (i = words32; i < size; i++) /* pad */
 		replace_u32(&dst[i], 0, 0);
 
-	nf_conntrack_event_cache(IPCT_LABEL, ct);
+	if (changed)
+		nf_conntrack_event_cache(IPCT_LABEL, ct);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(nf_connlabels_replace);
-- 
2.1.4

  parent reply	other threads:[~2016-04-22 13:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-22 13:39 [PATCH 00/23] Netfilter updates for net-next Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 01/23] netfilter: x_tables: don't move to non-existent next rule Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 02/23] netfilter: x_tables: validate targets of jumps Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 03/23] netfilter: x_tables: add and use xt_check_entry_offsets Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 04/23] netfilter: x_tables: kill check_entry helper Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 05/23] netfilter: x_tables: assert minimum target size Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 06/23] netfilter: x_tables: add compat version of xt_check_entry_offsets Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 07/23] netfilter: x_tables: check standard target size too Pablo Neira Ayuso
2016-06-05 21:11   ` Andreas Schwab
2016-06-05 22:02     ` Florian Westphal
2016-06-06 11:20       ` Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 08/23] netfilter: x_tables: check for bogus target offset Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 09/23] netfilter: x_tables: validate all offsets and sizes in a rule Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 10/23] netfilter: ip_tables: simplify translate_compat_table args Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 11/23] netfilter: ip6_tables: " Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 12/23] netfilter: arp_tables: " Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 13/23] netfilter: x_tables: xt_compat_match_from_user doesn't need a retval Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 14/23] netfilter: x_tables: do compat validation via translate_table Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 15/23] netfilter: x_tables: remove obsolete overflow check for compat case too Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 16/23] netfilter: x_tables: remove obsolete check Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 17/23] netfilter: x_tables: introduce and use xt_copy_counters_from_user Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 18/23] netfilter: ctnetlink: remove unnecessary inlining Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 19/23] netfilter: connlabels: move helpers to xt_connlabel Pablo Neira Ayuso
2016-04-22 13:39 ` Pablo Neira Ayuso [this message]
2016-04-22 13:39 ` [PATCH 21/23] netfilter: connlabels: change nf_connlabels_get bit arg to 'highest used' Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 22/23] netfilter: ctnetlink: restore inlining for netlink message size calculation Pablo Neira Ayuso
2016-04-22 13:39 ` [PATCH 23/23] netfilter: conntrack: don't acquire lock during seq_printf Pablo Neira Ayuso
2016-04-24  4:26 ` [PATCH 00/23] Netfilter updates for net-next 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=1461332394-3994-21-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@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).