[NETFILTER]: ip_tables: reformat compat code

The compat code has some very odd formating, clean it up before porting
it to ip6_tables.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Patrick McHardy 2007-12-17 21:46:15 -08:00 committed by David S. Miller
parent ac8e27fd89
commit 4b4782486d
1 changed files with 92 additions and 89 deletions

View File

@ -600,8 +600,8 @@ check_entry(struct ipt_entry *e, const char *name)
} }
static inline int check_match(struct ipt_entry_match *m, const char *name, static inline int check_match(struct ipt_entry_match *m, const char *name,
const struct ipt_ip *ip, unsigned int hookmask, const struct ipt_ip *ip,
unsigned int *i) unsigned int hookmask, unsigned int *i)
{ {
struct xt_match *match; struct xt_match *match;
int ret; int ret;
@ -624,10 +624,10 @@ static inline int check_match(struct ipt_entry_match *m, const char *name,
static inline int static inline int
find_check_match(struct ipt_entry_match *m, find_check_match(struct ipt_entry_match *m,
const char *name, const char *name,
const struct ipt_ip *ip, const struct ipt_ip *ip,
unsigned int hookmask, unsigned int hookmask,
unsigned int *i) unsigned int *i)
{ {
struct xt_match *match; struct xt_match *match;
int ret; int ret;
@ -663,8 +663,8 @@ static inline int check_target(struct ipt_entry *e, const char *name)
name, e->comefrom, e->ip.proto, name, e->comefrom, e->ip.proto,
e->ip.invflags & IPT_INV_PROTO); e->ip.invflags & IPT_INV_PROTO);
if (!ret && t->u.kernel.target->checkentry if (!ret && t->u.kernel.target->checkentry
&& !t->u.kernel.target->checkentry(name, e, target, && !t->u.kernel.target->checkentry(name, e, target, t->data,
t->data, e->comefrom)) { e->comefrom)) {
duprintf("ip_tables: check failed for `%s'.\n", duprintf("ip_tables: check failed for `%s'.\n",
t->u.kernel.target->name); t->u.kernel.target->name);
ret = -EINVAL; ret = -EINVAL;
@ -674,7 +674,7 @@ static inline int check_target(struct ipt_entry *e, const char *name)
static inline int static inline int
find_check_entry(struct ipt_entry *e, const char *name, unsigned int size, find_check_entry(struct ipt_entry *e, const char *name, unsigned int size,
unsigned int *i) unsigned int *i)
{ {
struct ipt_entry_target *t; struct ipt_entry_target *t;
struct xt_target *target; struct xt_target *target;
@ -687,14 +687,14 @@ find_check_entry(struct ipt_entry *e, const char *name, unsigned int size,
j = 0; j = 0;
ret = IPT_MATCH_ITERATE(e, find_check_match, name, &e->ip, ret = IPT_MATCH_ITERATE(e, find_check_match, name, &e->ip,
e->comefrom, &j); e->comefrom, &j);
if (ret != 0) if (ret != 0)
goto cleanup_matches; goto cleanup_matches;
t = ipt_get_target(e); t = ipt_get_target(e);
target = try_then_request_module(xt_find_target(AF_INET, target = try_then_request_module(xt_find_target(AF_INET,
t->u.user.name, t->u.user.name,
t->u.user.revision), t->u.user.revision),
"ipt_%s", t->u.user.name); "ipt_%s", t->u.user.name);
if (IS_ERR(target) || !target) { if (IS_ERR(target) || !target) {
duprintf("find_check_entry: `%s' not found\n", t->u.user.name); duprintf("find_check_entry: `%s' not found\n", t->u.user.name);
@ -1020,7 +1020,7 @@ struct compat_delta {
short delta; short delta;
}; };
static struct compat_delta *compat_offsets = NULL; static struct compat_delta *compat_offsets;
static int compat_add_offset(unsigned int offset, short delta) static int compat_add_offset(unsigned int offset, short delta)
{ {
@ -1046,7 +1046,7 @@ static void compat_flush_offsets(void)
struct compat_delta *tmp, *next; struct compat_delta *tmp, *next;
if (compat_offsets) { if (compat_offsets) {
for(tmp = compat_offsets; tmp; tmp = next) { for (tmp = compat_offsets; tmp; tmp = next) {
next = tmp->next; next = tmp->next;
kfree(tmp); kfree(tmp);
} }
@ -1059,7 +1059,7 @@ static short compat_calc_jump(unsigned int offset)
struct compat_delta *tmp; struct compat_delta *tmp;
short delta; short delta;
for(tmp = compat_offsets, delta = 0; tmp; tmp = tmp->next) for (tmp = compat_offsets, delta = 0; tmp; tmp = tmp->next)
if (tmp->offset < offset) if (tmp->offset < offset)
delta += tmp->delta; delta += tmp->delta;
return delta; return delta;
@ -1084,15 +1084,15 @@ static int compat_standard_to_user(void __user *dst, void *src)
} }
static inline int static inline int
compat_calc_match(struct ipt_entry_match *m, int * size) compat_calc_match(struct ipt_entry_match *m, int *size)
{ {
*size += xt_compat_match_offset(m->u.kernel.match); *size += xt_compat_match_offset(m->u.kernel.match);
return 0; return 0;
} }
static int compat_calc_entry(struct ipt_entry *e, static int compat_calc_entry(struct ipt_entry *e,
const struct xt_table_info *info, const struct xt_table_info *info,
void *base, struct xt_table_info *newinfo) void *base, struct xt_table_info *newinfo)
{ {
struct ipt_entry_target *t; struct ipt_entry_target *t;
unsigned int entry_offset; unsigned int entry_offset;
@ -1109,18 +1109,18 @@ static int compat_calc_entry(struct ipt_entry *e,
return ret; return ret;
for (i = 0; i < NF_INET_NUMHOOKS; i++) { for (i = 0; i < NF_INET_NUMHOOKS; i++) {
if (info->hook_entry[i] && (e < (struct ipt_entry *) if (info->hook_entry[i] &&
(base + info->hook_entry[i]))) (e < (struct ipt_entry *)(base + info->hook_entry[i])))
newinfo->hook_entry[i] -= off; newinfo->hook_entry[i] -= off;
if (info->underflow[i] && (e < (struct ipt_entry *) if (info->underflow[i] &&
(base + info->underflow[i]))) (e < (struct ipt_entry *)(base + info->underflow[i])))
newinfo->underflow[i] -= off; newinfo->underflow[i] -= off;
} }
return 0; return 0;
} }
static int compat_table_info(const struct xt_table_info *info, static int compat_table_info(const struct xt_table_info *info,
struct xt_table_info *newinfo) struct xt_table_info *newinfo)
{ {
void *loc_cpu_entry; void *loc_cpu_entry;
@ -1132,7 +1132,8 @@ static int compat_table_info(const struct xt_table_info *info,
newinfo->initial_entries = 0; newinfo->initial_entries = 0;
loc_cpu_entry = info->entries[raw_smp_processor_id()]; loc_cpu_entry = info->entries[raw_smp_processor_id()];
return IPT_ENTRY_ITERATE(loc_cpu_entry, info->size, return IPT_ENTRY_ITERATE(loc_cpu_entry, info->size,
compat_calc_entry, info, loc_cpu_entry, newinfo); compat_calc_entry, info, loc_cpu_entry,
newinfo);
} }
#endif #endif
@ -1157,7 +1158,7 @@ static int get_info(void __user *user, int *len, int compat)
xt_compat_lock(AF_INET); xt_compat_lock(AF_INET);
#endif #endif
t = try_then_request_module(xt_find_table_lock(AF_INET, name), t = try_then_request_module(xt_find_table_lock(AF_INET, name),
"iptable_%s", name); "iptable_%s", name);
if (t && !IS_ERR(t)) { if (t && !IS_ERR(t)) {
struct ipt_getinfo info; struct ipt_getinfo info;
struct xt_table_info *private = t->private; struct xt_table_info *private = t->private;
@ -1167,14 +1168,14 @@ static int get_info(void __user *user, int *len, int compat)
struct xt_table_info tmp; struct xt_table_info tmp;
ret = compat_table_info(private, &tmp); ret = compat_table_info(private, &tmp);
compat_flush_offsets(); compat_flush_offsets();
private = &tmp; private = &tmp;
} }
#endif #endif
info.valid_hooks = t->valid_hooks; info.valid_hooks = t->valid_hooks;
memcpy(info.hook_entry, private->hook_entry, memcpy(info.hook_entry, private->hook_entry,
sizeof(info.hook_entry)); sizeof(info.hook_entry));
memcpy(info.underflow, private->underflow, memcpy(info.underflow, private->underflow,
sizeof(info.underflow)); sizeof(info.underflow));
info.num_entries = private->number; info.num_entries = private->number;
info.size = private->size; info.size = private->size;
strcpy(info.name, name); strcpy(info.name, name);
@ -1240,8 +1241,8 @@ get_entries(struct ipt_get_entries __user *uptr, int *len)
static int static int
__do_replace(const char *name, unsigned int valid_hooks, __do_replace(const char *name, unsigned int valid_hooks,
struct xt_table_info *newinfo, unsigned int num_counters, struct xt_table_info *newinfo, unsigned int num_counters,
void __user *counters_ptr) void __user *counters_ptr)
{ {
int ret; int ret;
struct xt_table *t; struct xt_table *t;
@ -1289,7 +1290,8 @@ __do_replace(const char *name, unsigned int valid_hooks,
get_counters(oldinfo, counters); get_counters(oldinfo, counters);
/* Decrease module usage counts and free resource */ /* Decrease module usage counts and free resource */
loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()]; loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
IPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,NULL); IPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,
NULL);
xt_free_table_info(oldinfo); xt_free_table_info(oldinfo);
if (copy_to_user(counters_ptr, counters, if (copy_to_user(counters_ptr, counters,
sizeof(struct xt_counters) * num_counters) != 0) sizeof(struct xt_counters) * num_counters) != 0)
@ -1346,9 +1348,8 @@ do_replace(void __user *user, unsigned int len)
duprintf("ip_tables: Translated table\n"); duprintf("ip_tables: Translated table\n");
ret = __do_replace(tmp.name, tmp.valid_hooks, ret = __do_replace(tmp.name, tmp.valid_hooks, newinfo,
newinfo, tmp.num_counters, tmp.num_counters, tmp.counters);
tmp.counters);
if (ret) if (ret)
goto free_newinfo_untrans; goto free_newinfo_untrans;
return 0; return 0;
@ -1523,19 +1524,19 @@ out:
static inline int static inline int
compat_find_calc_match(struct ipt_entry_match *m, compat_find_calc_match(struct ipt_entry_match *m,
const char *name, const char *name,
const struct ipt_ip *ip, const struct ipt_ip *ip,
unsigned int hookmask, unsigned int hookmask,
int *size, int *i) int *size, int *i)
{ {
struct xt_match *match; struct xt_match *match;
match = try_then_request_module(xt_find_match(AF_INET, m->u.user.name, match = try_then_request_module(xt_find_match(AF_INET, m->u.user.name,
m->u.user.revision), m->u.user.revision),
"ipt_%s", m->u.user.name); "ipt_%s", m->u.user.name);
if (IS_ERR(match) || !match) { if (IS_ERR(match) || !match) {
duprintf("compat_check_calc_match: `%s' not found\n", duprintf("compat_check_calc_match: `%s' not found\n",
m->u.user.name); m->u.user.name);
return match ? PTR_ERR(match) : -ENOENT; return match ? PTR_ERR(match) : -ENOENT;
} }
m->u.kernel.match = match; m->u.kernel.match = match;
@ -1572,14 +1573,14 @@ compat_release_entry(struct ipt_entry *e, unsigned int *i)
static inline int static inline int
check_compat_entry_size_and_hooks(struct ipt_entry *e, check_compat_entry_size_and_hooks(struct ipt_entry *e,
struct xt_table_info *newinfo, struct xt_table_info *newinfo,
unsigned int *size, unsigned int *size,
unsigned char *base, unsigned char *base,
unsigned char *limit, unsigned char *limit,
unsigned int *hook_entries, unsigned int *hook_entries,
unsigned int *underflows, unsigned int *underflows,
unsigned int *i, unsigned int *i,
const char *name) const char *name)
{ {
struct ipt_entry_target *t; struct ipt_entry_target *t;
struct xt_target *target; struct xt_target *target;
@ -1594,7 +1595,7 @@ check_compat_entry_size_and_hooks(struct ipt_entry *e,
} }
if (e->next_offset < sizeof(struct compat_ipt_entry) + if (e->next_offset < sizeof(struct compat_ipt_entry) +
sizeof(struct compat_xt_entry_target)) { sizeof(struct compat_xt_entry_target)) {
duprintf("checking: element %p size %u\n", duprintf("checking: element %p size %u\n",
e, e->next_offset); e, e->next_offset);
return -EINVAL; return -EINVAL;
@ -1608,18 +1609,18 @@ check_compat_entry_size_and_hooks(struct ipt_entry *e,
entry_offset = (void *)e - (void *)base; entry_offset = (void *)e - (void *)base;
j = 0; j = 0;
ret = IPT_MATCH_ITERATE(e, compat_find_calc_match, name, &e->ip, ret = IPT_MATCH_ITERATE(e, compat_find_calc_match, name, &e->ip,
e->comefrom, &off, &j); e->comefrom, &off, &j);
if (ret != 0) if (ret != 0)
goto release_matches; goto release_matches;
t = ipt_get_target(e); t = ipt_get_target(e);
target = try_then_request_module(xt_find_target(AF_INET, target = try_then_request_module(xt_find_target(AF_INET,
t->u.user.name, t->u.user.name,
t->u.user.revision), t->u.user.revision),
"ipt_%s", t->u.user.name); "ipt_%s", t->u.user.name);
if (IS_ERR(target) || !target) { if (IS_ERR(target) || !target) {
duprintf("check_compat_entry_size_and_hooks: `%s' not found\n", duprintf("check_compat_entry_size_and_hooks: `%s' not found\n",
t->u.user.name); t->u.user.name);
ret = target ? PTR_ERR(target) : -ENOENT; ret = target ? PTR_ERR(target) : -ENOENT;
goto release_matches; goto release_matches;
} }
@ -1653,17 +1654,20 @@ release_matches:
return ret; return ret;
} }
static inline int compat_copy_match_from_user(struct ipt_entry_match *m, static inline int
void **dstptr, compat_uint_t *size, const char *name, compat_copy_match_from_user(struct ipt_entry_match *m,
const struct ipt_ip *ip, unsigned int hookmask) void **dstptr, compat_uint_t *size,
const char *name, const struct ipt_ip *ip,
unsigned int hookmask)
{ {
xt_compat_match_from_user(m, dstptr, size); xt_compat_match_from_user(m, dstptr, size);
return 0; return 0;
} }
static int compat_copy_entry_from_user(struct ipt_entry *e, void **dstptr, static int
unsigned int *size, const char *name, compat_copy_entry_from_user(struct ipt_entry *e, void **dstptr,
struct xt_table_info *newinfo, unsigned char *base) unsigned int *size, const char *name,
struct xt_table_info *newinfo, unsigned char *base)
{ {
struct ipt_entry_target *t; struct ipt_entry_target *t;
struct xt_target *target; struct xt_target *target;
@ -1678,7 +1682,7 @@ static int compat_copy_entry_from_user(struct ipt_entry *e, void **dstptr,
*dstptr += sizeof(struct compat_ipt_entry); *dstptr += sizeof(struct compat_ipt_entry);
ret = IPT_MATCH_ITERATE(e, compat_copy_match_from_user, dstptr, size, ret = IPT_MATCH_ITERATE(e, compat_copy_match_from_user, dstptr, size,
name, &de->ip, de->comefrom); name, &de->ip, de->comefrom);
if (ret) if (ret)
return ret; return ret;
de->target_offset = e->target_offset - (origsize - *size); de->target_offset = e->target_offset - (origsize - *size);
@ -1697,7 +1701,7 @@ static int compat_copy_entry_from_user(struct ipt_entry *e, void **dstptr,
} }
static inline int compat_check_entry(struct ipt_entry *e, const char *name, static inline int compat_check_entry(struct ipt_entry *e, const char *name,
unsigned int *i) unsigned int *i)
{ {
int j, ret; int j, ret;
@ -1720,13 +1724,13 @@ static inline int compat_check_entry(struct ipt_entry *e, const char *name,
static int static int
translate_compat_table(const char *name, translate_compat_table(const char *name,
unsigned int valid_hooks, unsigned int valid_hooks,
struct xt_table_info **pinfo, struct xt_table_info **pinfo,
void **pentry0, void **pentry0,
unsigned int total_size, unsigned int total_size,
unsigned int number, unsigned int number,
unsigned int *hook_entries, unsigned int *hook_entries,
unsigned int *underflows) unsigned int *underflows)
{ {
unsigned int i, j; unsigned int i, j;
struct xt_table_info *newinfo, *info; struct xt_table_info *newinfo, *info;
@ -1793,10 +1797,10 @@ translate_compat_table(const char *name,
} }
entry1 = newinfo->entries[raw_smp_processor_id()]; entry1 = newinfo->entries[raw_smp_processor_id()];
pos = entry1; pos = entry1;
size = total_size; size = total_size;
ret = IPT_ENTRY_ITERATE(entry0, total_size, ret = IPT_ENTRY_ITERATE(entry0, total_size,
compat_copy_entry_from_user, &pos, &size, compat_copy_entry_from_user, &pos, &size,
name, newinfo, entry1); name, newinfo, entry1);
compat_flush_offsets(); compat_flush_offsets();
xt_compat_unlock(AF_INET); xt_compat_unlock(AF_INET);
if (ret) if (ret)
@ -1808,11 +1812,11 @@ translate_compat_table(const char *name,
i = 0; i = 0;
ret = IPT_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry, ret = IPT_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry,
name, &i); name, &i);
if (ret) { if (ret) {
j -= i; j -= i;
IPT_ENTRY_ITERATE_CONTINUE(entry1, newinfo->size, i, IPT_ENTRY_ITERATE_CONTINUE(entry1, newinfo->size, i,
compat_release_entry, &j); compat_release_entry, &j);
IPT_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, &i); IPT_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, &i);
xt_free_table_info(newinfo); xt_free_table_info(newinfo);
return ret; return ret;
@ -1873,22 +1877,22 @@ compat_do_replace(void __user *user, unsigned int len)
} }
ret = translate_compat_table(tmp.name, tmp.valid_hooks, ret = translate_compat_table(tmp.name, tmp.valid_hooks,
&newinfo, &loc_cpu_entry, tmp.size, &newinfo, &loc_cpu_entry, tmp.size,
tmp.num_entries, tmp.hook_entry, tmp.underflow); tmp.num_entries, tmp.hook_entry,
tmp.underflow);
if (ret != 0) if (ret != 0)
goto free_newinfo; goto free_newinfo;
duprintf("compat_do_replace: Translated table\n"); duprintf("compat_do_replace: Translated table\n");
ret = __do_replace(tmp.name, tmp.valid_hooks, ret = __do_replace(tmp.name, tmp.valid_hooks, newinfo,
newinfo, tmp.num_counters, tmp.num_counters, compat_ptr(tmp.counters));
compat_ptr(tmp.counters));
if (ret) if (ret)
goto free_newinfo_untrans; goto free_newinfo_untrans;
return 0; return 0;
free_newinfo_untrans: free_newinfo_untrans:
IPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry,NULL); IPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL);
free_newinfo: free_newinfo:
xt_free_table_info(newinfo); xt_free_table_info(newinfo);
return ret; return ret;
@ -1896,7 +1900,7 @@ compat_do_replace(void __user *user, unsigned int len)
static int static int
compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user, compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user,
unsigned int len) unsigned int len)
{ {
int ret; int ret;
@ -1920,15 +1924,15 @@ compat_do_ipt_set_ctl(struct sock *sk, int cmd, void __user *user,
return ret; return ret;
} }
struct compat_ipt_get_entries struct compat_ipt_get_entries {
{
char name[IPT_TABLE_MAXNAMELEN]; char name[IPT_TABLE_MAXNAMELEN];
compat_uint_t size; compat_uint_t size;
struct compat_ipt_entry entrytable[0]; struct compat_ipt_entry entrytable[0];
}; };
static int compat_copy_entries_to_user(unsigned int total_size, static int
struct xt_table *table, void __user *userptr) compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
void __user *userptr)
{ {
struct xt_counters *counters; struct xt_counters *counters;
struct xt_table_info *private = table->private; struct xt_table_info *private = table->private;
@ -1964,10 +1968,9 @@ compat_get_entries(struct compat_ipt_get_entries __user *uptr, int *len)
struct compat_ipt_get_entries get; struct compat_ipt_get_entries get;
struct xt_table *t; struct xt_table *t;
if (*len < sizeof(get)) { if (*len < sizeof(get)) {
duprintf("compat_get_entries: %u < %u\n", duprintf("compat_get_entries: %u < %u\n",
*len, (unsigned int)sizeof(get)); *len, (unsigned int)sizeof(get));
return -EINVAL; return -EINVAL;
} }
@ -1976,8 +1979,8 @@ compat_get_entries(struct compat_ipt_get_entries __user *uptr, int *len)
if (*len != sizeof(struct compat_ipt_get_entries) + get.size) { if (*len != sizeof(struct compat_ipt_get_entries) + get.size) {
duprintf("compat_get_entries: %u != %u\n", *len, duprintf("compat_get_entries: %u != %u\n", *len,
(unsigned int)(sizeof(struct compat_ipt_get_entries) + (unsigned int)(sizeof(struct compat_ipt_get_entries) +
get.size)); get.size));
return -EINVAL; return -EINVAL;
} }
@ -1991,7 +1994,7 @@ compat_get_entries(struct compat_ipt_get_entries __user *uptr, int *len)
ret = compat_table_info(private, &info); ret = compat_table_info(private, &info);
if (!ret && get.size == info.size) { if (!ret && get.size == info.size) {
ret = compat_copy_entries_to_user(private->size, ret = compat_copy_entries_to_user(private->size,
t, uptr->entrytable); t, uptr->entrytable);
} else if (!ret) { } else if (!ret) {
duprintf("compat_get_entries: I've got %u not %u!\n", duprintf("compat_get_entries: I've got %u not %u!\n",
private->size, private->size,