All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: davem@davemloft.net
Cc: netfilter-devel@lists.netfilter.org, Patrick McHardy <kaber@trash.net>
Subject: [NETFILTER 10/39]: ctnetlink: simplify the code to dump the conntrack table
Date: Wed, 20 Sep 2006 10:24:04 +0200 (MEST)	[thread overview]
Message-ID: <20060920082455.14636.33754.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20060920082442.14636.6806.sendpatchset@localhost.localdomain>

[NETFILTER]: ctnetlink: simplify the code to dump the conntrack table

Merge the bits to dump the conntrack table and the ones to dump and
zero counters in a single piece of code. This patch does not change
the default behaviour if accounting is not enabled.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>

---
commit 2d7b5900c6ec411811c3ec01ea7caf75dc694f3e
tree 9f54c5119b690be9c524e590257138f6e4a1569d
parent ac65877cea178bc9100074a0f778e01761be8634
author Pablo Neira Ayuso <pablo@netfilter.org> Wed, 20 Sep 2006 09:28:35 +0200
committer Patrick McHardy <kaber@trash.net> Wed, 20 Sep 2006 09:28:35 +0200

 net/ipv4/netfilter/ip_conntrack_netlink.c |   63 ++++-----------------------
 net/netfilter/nf_conntrack_netlink.c      |   67 ++++-------------------------
 2 files changed, 20 insertions(+), 110 deletions(-)

diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c
index a20b0e3..52eddea 100644
--- a/net/ipv4/netfilter/ip_conntrack_netlink.c
+++ b/net/ipv4/netfilter/ip_conntrack_netlink.c
@@ -436,6 +436,11 @@ restart:
 				cb->args[1] = (unsigned long)ct;
 				goto out;
 			}
+#ifdef CONFIG_NF_CT_ACCT
+			if (NFNL_MSG_TYPE(cb->nlh->nlmsg_type) ==
+						IPCTNL_MSG_CT_GET_CTRZERO)
+				memset(&ct->counters, 0, sizeof(ct->counters));
+#endif
 		}
 		if (cb->args[1]) {
 			cb->args[1] = 0;
@@ -451,46 +456,6 @@ out:
 	return skb->len;
 }
 
-#ifdef CONFIG_IP_NF_CT_ACCT
-static int
-ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb)
-{
-	struct ip_conntrack *ct = NULL;
-	struct ip_conntrack_tuple_hash *h;
-	struct list_head *i;
-	u_int32_t *id = (u_int32_t *) &cb->args[1];
-
-	DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__, 
-			cb->args[0], *id);
-
-	write_lock_bh(&ip_conntrack_lock);
-	for (; cb->args[0] < ip_conntrack_htable_size; cb->args[0]++, *id = 0) {
-		list_for_each_prev(i, &ip_conntrack_hash[cb->args[0]]) {
-			h = (struct ip_conntrack_tuple_hash *) i;
-			if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
-				continue;
-			ct = tuplehash_to_ctrack(h);
-			if (ct->id <= *id)
-				continue;
-			if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
-		                        	cb->nlh->nlmsg_seq,
-						IPCTNL_MSG_CT_NEW,
-						1, ct) < 0)
-				goto out;
-			*id = ct->id;
-
-			memset(&ct->counters, 0, sizeof(ct->counters));
-		}
-	}
-out:	
-	write_unlock_bh(&ip_conntrack_lock);
-
-	DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
-
-	return skb->len;
-}
-#endif
-
 static const size_t cta_min_ip[CTA_IP_MAX] = {
 	[CTA_IP_V4_SRC-1]	= sizeof(u_int32_t),
 	[CTA_IP_V4_DST-1]	= sizeof(u_int32_t),
@@ -775,22 +740,14 @@ ctnetlink_get_conntrack(struct sock *ctn
 		if (msg->nfgen_family != AF_INET)
 			return -EAFNOSUPPORT;
 
-		if (NFNL_MSG_TYPE(nlh->nlmsg_type) ==
-					IPCTNL_MSG_CT_GET_CTRZERO) {
-#ifdef CONFIG_IP_NF_CT_ACCT
-			if ((*errp = netlink_dump_start(ctnl, skb, nlh,
-						ctnetlink_dump_table_w,
-						ctnetlink_done)) != 0)
-				return -EINVAL;
-#else
+#ifndef CONFIG_IP_NF_CT_ACCT
+		if (NFNL_MSG_TYPE(nlh->nlmsg_type) == IPCTNL_MSG_CT_GET_CTRZERO)
 			return -ENOTSUPP;
 #endif
-		} else {
-			if ((*errp = netlink_dump_start(ctnl, skb, nlh,
-		      		                        ctnetlink_dump_table,
-		                                	ctnetlink_done)) != 0)
+		if ((*errp = netlink_dump_start(ctnl, skb, nlh,
+	      		                        ctnetlink_dump_table,
+	                                	ctnetlink_done)) != 0)
 			return -EINVAL;
-		}
 
 		rlen = NLMSG_ALIGN(nlh->nlmsg_len);
 		if (rlen > skb->len)
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 8cd85cf..1721f7c 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -455,6 +455,11 @@ restart:
 				cb->args[1] = (unsigned long)ct;
 				goto out;
 			}
+#ifdef CONFIG_NF_CT_ACCT
+			if (NFNL_MSG_TYPE(cb->nlh->nlmsg_type) ==
+						IPCTNL_MSG_CT_GET_CTRZERO)
+				memset(&ct->counters, 0, sizeof(ct->counters));
+#endif
 		}
 		if (cb->args[1]) {
 			cb->args[1] = 0;
@@ -470,50 +475,6 @@ out:
 	return skb->len;
 }
 
-#ifdef CONFIG_NF_CT_ACCT
-static int
-ctnetlink_dump_table_w(struct sk_buff *skb, struct netlink_callback *cb)
-{
-	struct nf_conn *ct = NULL;
-	struct nf_conntrack_tuple_hash *h;
-	struct list_head *i;
-	u_int32_t *id = (u_int32_t *) &cb->args[1];
-	struct nfgenmsg *nfmsg = NLMSG_DATA(cb->nlh);
-	u_int8_t l3proto = nfmsg->nfgen_family;	
-
-	DEBUGP("entered %s, last bucket=%u id=%u\n", __FUNCTION__, 
-			cb->args[0], *id);
-
-	write_lock_bh(&nf_conntrack_lock);
-	for (; cb->args[0] < nf_conntrack_htable_size; cb->args[0]++, *id = 0) {
-		list_for_each_prev(i, &nf_conntrack_hash[cb->args[0]]) {
-			h = (struct nf_conntrack_tuple_hash *) i;
-			if (DIRECTION(h) != IP_CT_DIR_ORIGINAL)
-				continue;
-			ct = nf_ct_tuplehash_to_ctrack(h);
-			if (l3proto && L3PROTO(ct) != l3proto)
-				continue;
-			if (ct->id <= *id)
-				continue;
-			if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
-		                        	cb->nlh->nlmsg_seq,
-						IPCTNL_MSG_CT_NEW,
-						1, ct) < 0)
-				goto out;
-			*id = ct->id;
-
-			memset(&ct->counters, 0, sizeof(ct->counters));
-		}
-	}
-out:	
-	write_unlock_bh(&nf_conntrack_lock);
-
-	DEBUGP("leaving, last bucket=%lu id=%u\n", cb->args[0], *id);
-
-	return skb->len;
-}
-#endif
-
 static inline int
 ctnetlink_parse_tuple_ip(struct nfattr *attr, struct nf_conntrack_tuple *tuple)
 {
@@ -788,22 +749,14 @@ ctnetlink_get_conntrack(struct sock *ctn
 	if (nlh->nlmsg_flags & NLM_F_DUMP) {
 		u32 rlen;
 
-		if (NFNL_MSG_TYPE(nlh->nlmsg_type) ==
-					IPCTNL_MSG_CT_GET_CTRZERO) {
-#ifdef CONFIG_NF_CT_ACCT
-			if ((*errp = netlink_dump_start(ctnl, skb, nlh,
-						ctnetlink_dump_table_w,
-						ctnetlink_done)) != 0)
-				return -EINVAL;
-#else
+#ifndef CONFIG_NF_CT_ACCT
+		if (NFNL_MSG_TYPE(nlh->nlmsg_type) == IPCTNL_MSG_CT_GET_CTRZERO)
 			return -ENOTSUPP;
 #endif
-		} else {
-			if ((*errp = netlink_dump_start(ctnl, skb, nlh,
-		      		                        ctnetlink_dump_table,
-		                                	ctnetlink_done)) != 0)
+		if ((*errp = netlink_dump_start(ctnl, skb, nlh,
+						ctnetlink_dump_table,
+						ctnetlink_done)) != 0)
 			return -EINVAL;
-		}
 
 		rlen = NLMSG_ALIGN(nlh->nlmsg_len);
 		if (rlen > skb->len)

  parent reply	other threads:[~2006-09-20  8:24 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-20  8:23 [NETFILTER 00/39]: Netfilter update for 2.6.19 Patrick McHardy
2006-09-20  8:23 ` [NETFILTER 01/39]: remove unused include file Patrick McHardy
2006-09-20  8:23 ` [NETFILTER 02/39]: kill listhelp.h Patrick McHardy
2006-09-20 16:54   ` Patrick McHardy
2006-09-20  8:23 ` [NETFILTER 03/39]: xt_conntrack: clean up overly long lines Patrick McHardy
2006-09-20  8:23 ` [NETFILTER 04/39]: ipt_TCPMSS: reformat Patrick McHardy
2006-09-20 11:03   ` Roberto Nibali
2006-09-20 18:19     ` David Miller
2006-09-20 21:11       ` Willy Tarreau
2006-09-20  8:23 ` [NETFILTER 05/39]: ipt_TCPMSS: remove impossible condition Patrick McHardy
2006-09-20 11:07   ` Roberto Nibali
2006-09-20 11:27     ` Patrick McHardy
2006-09-20  8:23 ` [NETFILTER 06/39]: ipt_TCPMSS: misc cleanup Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 07/39]: xt_limit: don't reset state on unrelated rule updates Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 08/39]: ip6table_mangle: reroute when nfmark changes in NF_IP6_LOCAL_OUT Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 09/39]: x_tables: small check_entry & module_refcount cleanup Patrick McHardy
2006-09-20  8:24 ` Patrick McHardy [this message]
2006-09-20  8:24 ` [NETFILTER 11/39]: conntrack: fix race condition in early_drop Patrick McHardy
2006-09-20 11:26   ` Roberto Nibali
2006-09-20 11:30     ` Patrick McHardy
2006-09-20 11:35       ` Roberto Nibali
2006-09-20 11:39         ` Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 12/39]: ipt_TTL: fix checksum update bug Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 13/39]: ip6t_HL: remove write-only variable Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 14/39]: xt_policy: remove dups in .family Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 15/39]: TCP conntrack: improve dead connection detection Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 16/39]: make some netfilter globals __read_mostly Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 17/39]: ip_tables: fix module refcount leaks in compat error paths Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 18/39]: ip_tables: revision support for compat code Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 19/39]: x_tables: simplify compat API Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 20/39]: xt_mark: add compat conversion functions Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 21/39]: xt_MARK: " Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 22/39]: xt_connmark: " Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 23/39]: xt_CONNMARK: " Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 24/39]: xt_limit: " Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 25/39]: ipt_hashlimit: " Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 26/39]: PPTP conntrack: fix whitespace errors Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 27/39]: PPTP conntrack: get rid of unnecessary byte order conversions Patrick McHardy
2006-09-20 11:46   ` Jones Desougi
2006-09-20 11:50     ` Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 28/39]: PPTP conntrack: remove dead code Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 29/39]: PPTP conntrack: remove more " Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 30/39]: PPTP conntrack: fix header definitions Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 31/39]: PPTP conntrack: remove unnecessary cid/pcid header pointers Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 32/39]: PPTP conntrack: simplify expectation handling Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 33/39]: PPTP conntrack: consolidate header size checks Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 34/39]: PPTP conntrack: consolidate header parsing Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 35/39]: PPTP conntrack: clean up debugging cruft Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 36/39]: PPTP conntrack: check call ID before changing state Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 37/39]: PPTP conntrack: fix PPTP_IN_CALL message types Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 38/39]: PPTP conntrack: fix GRE keymap leak Patrick McHardy
2006-09-20  8:24 ` [NETFILTER 39/39]: PPTP conntrack: fix another " Patrick McHardy
2006-09-20 19:11 ` [NETFILTER 00/39]: Netfilter update for 2.6.19 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=20060920082455.14636.33754.sendpatchset@localhost.localdomain \
    --to=kaber@trash.net \
    --cc=davem@davemloft.net \
    --cc=netfilter-devel@lists.netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.