netfilter-devel.vger.kernel.org archive mirror
 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 05/10] netfilter: ebtables: split copy_everything_to_user into two functions
Date: Thu, 11 Feb 2010 15:12:35 +0100	[thread overview]
Message-ID: <1265897559-10610-6-git-send-email-fw@strlen.de> (raw)
In-Reply-To: <1265897559-10610-1-git-send-email-fw@strlen.de>

once CONFIG_COMPAT support is added to ebtables, the new
copy_counters_to_user function can be called instead of duplicating
code.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 patch was not present in v1 patch series.

 net/bridge/netfilter/ebtables.c |   62 ++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index c506581..c32ec11 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1340,14 +1340,47 @@ static inline int ebt_make_names(struct ebt_entry *e, char *base, char __user *u
 	return 0;
 }
 
+static int copy_counters_to_user(struct ebt_table *t, struct ebt_counter *oldcounters,
+                                 void __user *user, unsigned int num_counters,
+                                 unsigned int nentries)
+{
+	struct ebt_counter *counterstmp;
+	int ret = 0;
+
+	/* userspace might not need the counters */
+	if (num_counters == 0)
+		return 0;
+
+	if (num_counters != nentries) {
+		BUGPRINT("Num_counters wrong\n");
+		return -EINVAL;
+	}
+
+	counterstmp = vmalloc(nentries * sizeof(*counterstmp));
+	if (!counterstmp) {
+		MEMPRINT("Couldn't copy counters, out of memory\n");
+		return -ENOMEM;
+	}
+	write_lock_bh(&t->lock);
+	get_counters(oldcounters, counterstmp, nentries);
+	write_unlock_bh(&t->lock);
+
+	if (copy_to_user(user, counterstmp,
+	   nentries * sizeof(struct ebt_counter)))
+		ret = -EFAULT;
+	vfree(counterstmp);
+	return ret;
+}
+
 /* called with ebt_mutex locked */
 static int copy_everything_to_user(struct ebt_table *t, void __user *user,
    int *len, int cmd)
 {
 	struct ebt_replace tmp;
-	struct ebt_counter *counterstmp, *oldcounters;
+	struct ebt_counter *oldcounters;
 	unsigned int entries_size, nentries;
 	char *entries;
+	int ret;
 
 	if (cmd == EBT_SO_GET_ENTRIES) {
 		entries_size = t->private->entries_size;
@@ -1382,29 +1415,10 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
 		return -EINVAL;
 	}
 
-	/* userspace might not need the counters */
-	if (tmp.num_counters) {
-		if (tmp.num_counters != nentries) {
-			BUGPRINT("Num_counters wrong\n");
-			return -EINVAL;
-		}
-		counterstmp = vmalloc(nentries * sizeof(*counterstmp));
-		if (!counterstmp) {
-			MEMPRINT("Couldn't copy counters, out of memory\n");
-			return -ENOMEM;
-		}
-		write_lock_bh(&t->lock);
-		get_counters(oldcounters, counterstmp, nentries);
-		write_unlock_bh(&t->lock);
-
-		if (copy_to_user(tmp.counters, counterstmp,
-		   nentries * sizeof(struct ebt_counter))) {
-			BUGPRINT("Couldn't copy counters to userspace\n");
-			vfree(counterstmp);
-			return -EFAULT;
-		}
-		vfree(counterstmp);
-	}
+	ret = copy_counters_to_user(t, oldcounters, tmp.counters,
+					tmp.num_counters, nentries);
+	if (ret)
+		return ret;
 
 	if (copy_to_user(tmp.entries, entries, entries_size)) {
 		BUGPRINT("Couldn't copy entries to userspace\n");
-- 
1.6.3.3


  parent reply	other threads:[~2010-02-11 14:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-11 14:12 [PATCH v2 0/10] netfilter: ebtables: CONFIG_COMPAT support Florian Westphal
2010-02-11 14:12 ` [PATCH 01/10] netfilter: ebtables: abort if next_offset is too small Florian Westphal
2010-02-15 17:40   ` Patrick McHardy
2010-02-11 14:12 ` [PATCH 02/10] netfilter: ebtables: avoid explicit XT_ALIGN() in match/targets Florian Westphal
2010-02-15 17:40   ` Patrick McHardy
2010-02-11 14:12 ` [PATCH 03/10] netfilter: CONFIG_COMPAT: allow delta to exceed 32767 Florian Westphal
2010-02-15 16:33   ` Patrick McHardy
2010-02-15 16:37     ` Florian Westphal
2010-02-15 17:08       ` Patrick McHardy
2010-02-15 17:40   ` Patrick McHardy
2010-02-11 14:12 ` [PATCH 04/10] netfilter: ebtables: split do_replace into two functions Florian Westphal
2010-02-11 14:12 ` Florian Westphal [this message]
2010-02-11 14:12 ` [PATCH 06/10] netfilter: ebtables: split update_counters " Florian Westphal
2010-02-11 14:12 ` [PATCH 07/10] netfilter: ebtables: add CONFIG_COMPAT support Florian Westphal
2010-02-11 14:12 ` [PATCH 08/10] netfilter: ebtables: try native set/getsockopt handlers, too Florian Westphal
2010-02-11 17:40   ` Patrick McHardy
2010-02-11 21:50     ` Florian Westphal
2010-02-11 14:12 ` [PATCH 09/10] netfilter: ebt_limit: add CONFIG_COMPAT support Florian Westphal
2010-02-13 13:20 ` [PATCH v2 0/10] netfilter: ebtables: " Bart De Schuymer
2010-02-13 13:31   ` 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=1265897559-10610-6-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 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).