netfilter: ebtables: split copy_everything_to_user into two functions
once CONFIG_COMPAT support is added to ebtables, the new copy_counters_to_user function can be called instead of duplicating code. Also remove last use of MEMPRINT, as requested by Bart De Schuymer. Signed-off-by: Florian Westphal <fw@strlen.de>
This commit is contained in:
parent
e788759f44
commit
837395aa86
1 changed files with 38 additions and 32 deletions
|
@ -33,11 +33,6 @@
|
||||||
#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
|
#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
|
||||||
"report to author: "format, ## args)
|
"report to author: "format, ## args)
|
||||||
/* #define BUGPRINT(format, args...) */
|
/* #define BUGPRINT(format, args...) */
|
||||||
#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
|
|
||||||
": out of memory: "format, ## args)
|
|
||||||
/* #define MEMPRINT(format, args...) */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each cpu has its own set of counters, so there is no need for write_lock in
|
* Each cpu has its own set of counters, so there is no need for write_lock in
|
||||||
|
@ -1263,10 +1258,8 @@ static int update_counters(struct net *net, const void __user *user,
|
||||||
if (hlp.num_counters == 0)
|
if (hlp.num_counters == 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (!(tmp = vmalloc(hlp.num_counters * sizeof(*tmp)))) {
|
if (!(tmp = vmalloc(hlp.num_counters * sizeof(*tmp))))
|
||||||
MEMPRINT("Update_counters && nomemory\n");
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
t = find_table_lock(net, hlp.name, &ret, &ebt_mutex);
|
t = find_table_lock(net, hlp.name, &ret, &ebt_mutex);
|
||||||
if (!t)
|
if (!t)
|
||||||
|
@ -1345,14 +1338,46 @@ ebt_make_names(struct ebt_entry *e, const char *base, char __user *ubase)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int copy_counters_to_user(struct ebt_table *t,
|
||||||
|
const 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)
|
||||||
|
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 */
|
/* called with ebt_mutex locked */
|
||||||
static int copy_everything_to_user(struct ebt_table *t, void __user *user,
|
static int copy_everything_to_user(struct ebt_table *t, void __user *user,
|
||||||
const int *len, int cmd)
|
const int *len, int cmd)
|
||||||
{
|
{
|
||||||
struct ebt_replace tmp;
|
struct ebt_replace tmp;
|
||||||
struct ebt_counter *counterstmp;
|
|
||||||
const struct ebt_counter *oldcounters;
|
const struct ebt_counter *oldcounters;
|
||||||
unsigned int entries_size, nentries;
|
unsigned int entries_size, nentries;
|
||||||
|
int ret;
|
||||||
char *entries;
|
char *entries;
|
||||||
|
|
||||||
if (cmd == EBT_SO_GET_ENTRIES) {
|
if (cmd == EBT_SO_GET_ENTRIES) {
|
||||||
|
@ -1388,29 +1413,10 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* userspace might not need the counters */
|
ret = copy_counters_to_user(t, oldcounters, tmp.counters,
|
||||||
if (tmp.num_counters) {
|
tmp.num_counters, nentries);
|
||||||
if (tmp.num_counters != nentries) {
|
if (ret)
|
||||||
BUGPRINT("Num_counters wrong\n");
|
return ret;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (copy_to_user(tmp.entries, entries, entries_size)) {
|
if (copy_to_user(tmp.entries, entries, entries_size)) {
|
||||||
BUGPRINT("Couldn't copy entries to userspace\n");
|
BUGPRINT("Couldn't copy entries to userspace\n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue