All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: netfilter-devel@vger.kernel.org
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH 3/7] netfilter: ebtables: split update_counters into two functions
Date: Mon, 15 Feb 2010 22:05:35 +0100	[thread overview]
Message-ID: <1266267939-7736-4-git-send-email-fw@strlen.de> (raw)
In-Reply-To: <1266267939-7736-1-git-send-email-fw@strlen.de>

allows to call do_update_counters() from upcoming CONFIG_COMPAT
code instead of copy&pasting the same code.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/bridge/netfilter/ebtables.c |   40 +++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index 8f3529a..495b2ea 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1241,38 +1241,31 @@ void ebt_unregister_table(struct net *net, struct ebt_table *table)
 }
 
 /* userspace just supplied us with counters */
-static int update_counters(struct net *net, const void __user *user,
-			   unsigned int len)
+static int do_update_counters(struct net *net, const char *name,
+                              struct ebt_counter __user *counters, unsigned int num_counters,
+                              const void __user *user, unsigned int len)
 {
 	int i, ret;
 	struct ebt_counter *tmp;
-	struct ebt_replace hlp;
 	struct ebt_table *t;
 
-	if (copy_from_user(&hlp, user, sizeof(hlp)))
-		return -EFAULT;
-
-	if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
-		return -EINVAL;
-	if (hlp.num_counters == 0)
+	if (num_counters == 0)
 		return -EINVAL;
 
-	if (!(tmp = vmalloc(hlp.num_counters * sizeof(*tmp))))
+	if (!(tmp = vmalloc(num_counters * sizeof(*tmp))))
 		return -ENOMEM;
 
-	t = find_table_lock(net, hlp.name, &ret, &ebt_mutex);
+	t = find_table_lock(net, name, &ret, &ebt_mutex);
 	if (!t)
 		goto free_tmp;
 
-	if (hlp.num_counters != t->private->nentries) {
+	if (num_counters != t->private->nentries) {
 		BUGPRINT("Wrong nr of counters\n");
 		ret = -EINVAL;
 		goto unlock_mutex;
 	}
 
-	if ( copy_from_user(tmp, hlp.counters,
-	   hlp.num_counters * sizeof(struct ebt_counter)) ) {
-		BUGPRINT("Updata_counters && !cfu\n");
+	if (copy_from_user(tmp, counters, num_counters * sizeof(*counters))) {
 		ret = -EFAULT;
 		goto unlock_mutex;
 	}
@@ -1281,7 +1274,7 @@ static int update_counters(struct net *net, const void __user *user,
 	write_lock_bh(&t->lock);
 
 	/* we add to the counters of the first cpu */
-	for (i = 0; i < hlp.num_counters; i++) {
+	for (i = 0; i < num_counters; i++) {
 		t->private->counters[i].pcnt += tmp[i].pcnt;
 		t->private->counters[i].bcnt += tmp[i].bcnt;
 	}
@@ -1295,6 +1288,21 @@ free_tmp:
 	return ret;
 }
 
+static int update_counters(struct net *net, const void __user *user,
+                           unsigned int len)
+{
+	struct ebt_replace hlp;
+
+	if (copy_from_user(&hlp, user, sizeof(hlp)))
+		return -EFAULT;
+
+	if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
+		return -EINVAL;
+
+	return do_update_counters(net, hlp.name, hlp.counters,
+				hlp.num_counters, user, len);
+}
+
 static inline int ebt_make_matchname(const struct ebt_entry_match *m,
     const char *base, char __user *ubase)
 {
-- 
1.6.4.4


  parent reply	other threads:[~2010-02-15 21:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-15 21:05 [Patch v3] netfilter: ebtables: CONFIG_COMPAT support Florian Westphal
2010-02-15 21:05 ` [PATCH 1/7] netfilter: ebtables: split do_replace into two functions Florian Westphal
2010-02-15 21:05 ` [PATCH 2/7] netfilter: ebtables: split copy_everything_to_user " Florian Westphal
2010-02-15 21:05 ` Florian Westphal [this message]
2010-02-15 21:05 ` [PATCH 4/7] netfilter: ebtables: add CONFIG_COMPAT support Florian Westphal
2010-02-15 21:05 ` [PATCH 5/7] netfilter: ebtables: try native set/getsockopt handlers, too Florian Westphal
2010-02-15 21:05 ` [PATCH 6/7] netfilter: ebt_limit: add CONFIG_COMPAT support Florian Westphal
2010-02-15 21:05 ` [PATCH 7/7] netfilter: ebtables: mark: " Florian Westphal
2010-02-16 14:39 ` [Patch v3] netfilter: ebtables: " Patrick McHardy
2010-02-16 14:41   ` Florian Westphal
  -- strict thread matches above, loose matches on Subject: below --
2010-02-16 16:39 [PATCH v4] " Florian Westphal
2010-02-16 16:39 ` [PATCH 3/7] netfilter: ebtables: split update_counters into two functions Florian Westphal

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=1266267939-7736-4-git-send-email-fw@strlen.de \
    --to=fw@strlen.de \
    --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 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.