|
@@ -318,6 +318,7 @@ static void trace_packet(const struct sk_buff *skb,
|
|
|
const void *table_base;
|
|
|
const struct ip6t_entry *root;
|
|
|
const char *hookname, *chainname, *comment;
|
|
|
+ const struct ip6t_entry *iter;
|
|
|
unsigned int rulenum = 0;
|
|
|
|
|
|
table_base = private->entries[smp_processor_id()];
|
|
@@ -326,10 +327,10 @@ static void trace_packet(const struct sk_buff *skb,
|
|
|
hookname = chainname = hooknames[hook];
|
|
|
comment = comments[NF_IP6_TRACE_COMMENT_RULE];
|
|
|
|
|
|
- IP6T_ENTRY_ITERATE(root,
|
|
|
- private->size - private->hook_entry[hook],
|
|
|
- get_chainname_rulenum,
|
|
|
- e, hookname, &chainname, &comment, &rulenum);
|
|
|
+ xt_entry_foreach(iter, root, private->size - private->hook_entry[hook])
|
|
|
+ if (get_chainname_rulenum(iter, e, hookname,
|
|
|
+ &chainname, &comment, &rulenum) != 0)
|
|
|
+ break;
|
|
|
|
|
|
nf_log_packet(AF_INET6, hook, skb, in, out, &trace_loginfo,
|
|
|
"TRACE: %s:%s:%s:%u ",
|
|
@@ -392,16 +393,21 @@ ip6t_do_table(struct sk_buff *skb,
|
|
|
|
|
|
do {
|
|
|
const struct ip6t_entry_target *t;
|
|
|
+ const struct xt_entry_match *ematch;
|
|
|
|
|
|
IP_NF_ASSERT(e);
|
|
|
IP_NF_ASSERT(back);
|
|
|
if (!ip6_packet_match(skb, indev, outdev, &e->ipv6,
|
|
|
- &mtpar.thoff, &mtpar.fragoff, &hotdrop) ||
|
|
|
- IP6T_MATCH_ITERATE(e, do_match, skb, &mtpar) != 0) {
|
|
|
+ &mtpar.thoff, &mtpar.fragoff, &hotdrop)) {
|
|
|
+ no_match:
|
|
|
e = ip6t_next_entry(e);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ xt_ematch_foreach(ematch, e)
|
|
|
+ if (do_match(ematch, skb, &mtpar) != 0)
|
|
|
+ goto no_match;
|
|
|
+
|
|
|
ADD_COUNTER(e->counters,
|
|
|
ntohs(ipv6_hdr(skb)->payload_len) +
|
|
|
sizeof(struct ipv6hdr), 1);
|
|
@@ -597,14 +603,10 @@ mark_source_chains(const struct xt_table_info *newinfo,
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-static int
|
|
|
-cleanup_match(struct ip6t_entry_match *m, struct net *net, unsigned int *i)
|
|
|
+static void cleanup_match(struct ip6t_entry_match *m, struct net *net)
|
|
|
{
|
|
|
struct xt_mtdtor_param par;
|
|
|
|
|
|
- if (i && (*i)-- == 0)
|
|
|
- return 1;
|
|
|
-
|
|
|
par.net = net;
|
|
|
par.match = m->u.kernel.match;
|
|
|
par.matchinfo = m->data;
|
|
@@ -612,7 +614,6 @@ cleanup_match(struct ip6t_entry_match *m, struct net *net, unsigned int *i)
|
|
|
if (par.match->destroy != NULL)
|
|
|
par.match->destroy(&par);
|
|
|
module_put(par.match->me);
|
|
|
- return 0;
|
|
|
}
|
|
|
|
|
|
static int
|
|
@@ -636,8 +637,7 @@ check_entry(const struct ip6t_entry *e, const char *name)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par,
|
|
|
- unsigned int *i)
|
|
|
+static int check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par)
|
|
|
{
|
|
|
const struct ip6t_ip6 *ipv6 = par->entryinfo;
|
|
|
int ret;
|
|
@@ -652,13 +652,11 @@ static int check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par,
|
|
|
par.match->name);
|
|
|
return ret;
|
|
|
}
|
|
|
- ++*i;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
static int
|
|
|
-find_check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par,
|
|
|
- unsigned int *i)
|
|
|
+find_check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par)
|
|
|
{
|
|
|
struct xt_match *match;
|
|
|
int ret;
|
|
@@ -672,7 +670,7 @@ find_check_match(struct ip6t_entry_match *m, struct xt_mtchk_param *par,
|
|
|
}
|
|
|
m->u.kernel.match = match;
|
|
|
|
|
|
- ret = check_match(m, par, i);
|
|
|
+ ret = check_match(m, par);
|
|
|
if (ret)
|
|
|
goto err;
|
|
|
|
|
@@ -709,13 +707,14 @@ static int check_target(struct ip6t_entry *e, struct net *net, const char *name)
|
|
|
|
|
|
static int
|
|
|
find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
|
|
|
- unsigned int size, unsigned int *i)
|
|
|
+ unsigned int size)
|
|
|
{
|
|
|
struct ip6t_entry_target *t;
|
|
|
struct xt_target *target;
|
|
|
int ret;
|
|
|
unsigned int j;
|
|
|
struct xt_mtchk_param mtpar;
|
|
|
+ struct xt_entry_match *ematch;
|
|
|
|
|
|
ret = check_entry(e, name);
|
|
|
if (ret)
|
|
@@ -727,9 +726,12 @@ find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
|
|
|
mtpar.entryinfo = &e->ipv6;
|
|
|
mtpar.hook_mask = e->comefrom;
|
|
|
mtpar.family = NFPROTO_IPV6;
|
|
|
- ret = IP6T_MATCH_ITERATE(e, find_check_match, &mtpar, &j);
|
|
|
- if (ret != 0)
|
|
|
- goto cleanup_matches;
|
|
|
+ xt_ematch_foreach(ematch, e) {
|
|
|
+ ret = find_check_match(ematch, &mtpar);
|
|
|
+ if (ret != 0)
|
|
|
+ goto cleanup_matches;
|
|
|
+ ++j;
|
|
|
+ }
|
|
|
|
|
|
t = ip6t_get_target(e);
|
|
|
target = try_then_request_module(xt_find_target(AF_INET6,
|
|
@@ -746,13 +748,15 @@ find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
|
|
|
ret = check_target(e, net, name);
|
|
|
if (ret)
|
|
|
goto err;
|
|
|
-
|
|
|
- (*i)++;
|
|
|
return 0;
|
|
|
err:
|
|
|
module_put(t->u.kernel.target->me);
|
|
|
cleanup_matches:
|
|
|
- IP6T_MATCH_ITERATE(e, cleanup_match, net, &j);
|
|
|
+ xt_ematch_foreach(ematch, e) {
|
|
|
+ if (j-- == 0)
|
|
|
+ break;
|
|
|
+ cleanup_match(ematch, net);
|
|
|
+ }
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -778,8 +782,7 @@ check_entry_size_and_hooks(struct ip6t_entry *e,
|
|
|
const unsigned char *limit,
|
|
|
const unsigned int *hook_entries,
|
|
|
const unsigned int *underflows,
|
|
|
- unsigned int valid_hooks,
|
|
|
- unsigned int *i)
|
|
|
+ unsigned int valid_hooks)
|
|
|
{
|
|
|
unsigned int h;
|
|
|
|
|
@@ -816,22 +819,18 @@ check_entry_size_and_hooks(struct ip6t_entry *e,
|
|
|
/* Clear counters and comefrom */
|
|
|
e->counters = ((struct xt_counters) { 0, 0 });
|
|
|
e->comefrom = 0;
|
|
|
-
|
|
|
- (*i)++;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int
|
|
|
-cleanup_entry(struct ip6t_entry *e, struct net *net, unsigned int *i)
|
|
|
+static void cleanup_entry(struct ip6t_entry *e, struct net *net)
|
|
|
{
|
|
|
struct xt_tgdtor_param par;
|
|
|
struct ip6t_entry_target *t;
|
|
|
-
|
|
|
- if (i && (*i)-- == 0)
|
|
|
- return 1;
|
|
|
+ struct xt_entry_match *ematch;
|
|
|
|
|
|
/* Cleanup all matches */
|
|
|
- IP6T_MATCH_ITERATE(e, cleanup_match, net, NULL);
|
|
|
+ xt_ematch_foreach(ematch, e)
|
|
|
+ cleanup_match(ematch, net);
|
|
|
t = ip6t_get_target(e);
|
|
|
|
|
|
par.net = net;
|
|
@@ -841,27 +840,20 @@ cleanup_entry(struct ip6t_entry *e, struct net *net, unsigned int *i)
|
|
|
if (par.target->destroy != NULL)
|
|
|
par.target->destroy(&par);
|
|
|
module_put(par.target->me);
|
|
|
- return 0;
|
|
|
}
|
|
|
|
|
|
/* Checks and translates the user-supplied table segment (held in
|
|
|
newinfo) */
|
|
|
static int
|
|
|
-translate_table(struct net *net,
|
|
|
- const char *name,
|
|
|
- unsigned int valid_hooks,
|
|
|
- struct xt_table_info *newinfo,
|
|
|
- void *entry0,
|
|
|
- unsigned int size,
|
|
|
- unsigned int number,
|
|
|
- const unsigned int *hook_entries,
|
|
|
- const unsigned int *underflows)
|
|
|
+translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
|
|
|
+ const struct ip6t_replace *repl)
|
|
|
{
|
|
|
+ struct ip6t_entry *iter;
|
|
|
unsigned int i;
|
|
|
- int ret;
|
|
|
+ int ret = 0;
|
|
|
|
|
|
- newinfo->size = size;
|
|
|
- newinfo->number = number;
|
|
|
+ newinfo->size = repl->size;
|
|
|
+ newinfo->number = repl->num_entries;
|
|
|
|
|
|
/* Init all hooks to impossible value. */
|
|
|
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
|
|
@@ -872,49 +864,56 @@ translate_table(struct net *net,
|
|
|
duprintf("translate_table: size %u\n", newinfo->size);
|
|
|
i = 0;
|
|
|
/* Walk through entries, checking offsets. */
|
|
|
- ret = IP6T_ENTRY_ITERATE(entry0, newinfo->size,
|
|
|
- check_entry_size_and_hooks,
|
|
|
- newinfo,
|
|
|
- entry0,
|
|
|
- entry0 + size,
|
|
|
- hook_entries, underflows, valid_hooks, &i);
|
|
|
- if (ret != 0)
|
|
|
- return ret;
|
|
|
+ xt_entry_foreach(iter, entry0, newinfo->size) {
|
|
|
+ ret = check_entry_size_and_hooks(iter, newinfo, entry0,
|
|
|
+ entry0 + repl->size, repl->hook_entry, repl->underflow,
|
|
|
+ repl->valid_hooks);
|
|
|
+ if (ret != 0)
|
|
|
+ return ret;
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
|
|
|
- if (i != number) {
|
|
|
+ if (i != repl->num_entries) {
|
|
|
duprintf("translate_table: %u not %u entries\n",
|
|
|
- i, number);
|
|
|
+ i, repl->num_entries);
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
/* Check hooks all assigned */
|
|
|
for (i = 0; i < NF_INET_NUMHOOKS; i++) {
|
|
|
/* Only hooks which are valid */
|
|
|
- if (!(valid_hooks & (1 << i)))
|
|
|
+ if (!(repl->valid_hooks & (1 << i)))
|
|
|
continue;
|
|
|
if (newinfo->hook_entry[i] == 0xFFFFFFFF) {
|
|
|
duprintf("Invalid hook entry %u %u\n",
|
|
|
- i, hook_entries[i]);
|
|
|
+ i, repl->hook_entry[i]);
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
if (newinfo->underflow[i] == 0xFFFFFFFF) {
|
|
|
duprintf("Invalid underflow %u %u\n",
|
|
|
- i, underflows[i]);
|
|
|
+ i, repl->underflow[i]);
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!mark_source_chains(newinfo, valid_hooks, entry0))
|
|
|
+ if (!mark_source_chains(newinfo, repl->valid_hooks, entry0))
|
|
|
return -ELOOP;
|
|
|
|
|
|
/* Finally, each sanity check must pass */
|
|
|
i = 0;
|
|
|
- ret = IP6T_ENTRY_ITERATE(entry0, newinfo->size,
|
|
|
- find_check_entry, net, name, size, &i);
|
|
|
+ xt_entry_foreach(iter, entry0, newinfo->size) {
|
|
|
+ ret = find_check_entry(iter, net, repl->name, repl->size);
|
|
|
+ if (ret != 0)
|
|
|
+ break;
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
|
|
|
if (ret != 0) {
|
|
|
- IP6T_ENTRY_ITERATE(entry0, newinfo->size,
|
|
|
- cleanup_entry, net, &i);
|
|
|
+ xt_entry_foreach(iter, entry0, newinfo->size) {
|
|
|
+ if (i-- == 0)
|
|
|
+ break;
|
|
|
+ cleanup_entry(iter, net);
|
|
|
+ }
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -927,33 +926,11 @@ translate_table(struct net *net,
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-/* Gets counters. */
|
|
|
-static inline int
|
|
|
-add_entry_to_counter(const struct ip6t_entry *e,
|
|
|
- struct xt_counters total[],
|
|
|
- unsigned int *i)
|
|
|
-{
|
|
|
- ADD_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
|
|
|
-
|
|
|
- (*i)++;
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static inline int
|
|
|
-set_entry_to_counter(const struct ip6t_entry *e,
|
|
|
- struct ip6t_counters total[],
|
|
|
- unsigned int *i)
|
|
|
-{
|
|
|
- SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
|
|
|
-
|
|
|
- (*i)++;
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
static void
|
|
|
get_counters(const struct xt_table_info *t,
|
|
|
struct xt_counters counters[])
|
|
|
{
|
|
|
+ struct ip6t_entry *iter;
|
|
|
unsigned int cpu;
|
|
|
unsigned int i;
|
|
|
unsigned int curcpu;
|
|
@@ -969,22 +946,22 @@ get_counters(const struct xt_table_info *t,
|
|
|
curcpu = smp_processor_id();
|
|
|
|
|
|
i = 0;
|
|
|
- IP6T_ENTRY_ITERATE(t->entries[curcpu],
|
|
|
- t->size,
|
|
|
- set_entry_to_counter,
|
|
|
- counters,
|
|
|
- &i);
|
|
|
+ xt_entry_foreach(iter, t->entries[curcpu], t->size) {
|
|
|
+ SET_COUNTER(counters[i], iter->counters.bcnt,
|
|
|
+ iter->counters.pcnt);
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
if (cpu == curcpu)
|
|
|
continue;
|
|
|
i = 0;
|
|
|
xt_info_wrlock(cpu);
|
|
|
- IP6T_ENTRY_ITERATE(t->entries[cpu],
|
|
|
- t->size,
|
|
|
- add_entry_to_counter,
|
|
|
- counters,
|
|
|
- &i);
|
|
|
+ xt_entry_foreach(iter, t->entries[cpu], t->size) {
|
|
|
+ ADD_COUNTER(counters[i], iter->counters.bcnt,
|
|
|
+ iter->counters.pcnt);
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
xt_info_wrunlock(cpu);
|
|
|
}
|
|
|
local_bh_enable();
|
|
@@ -1103,24 +1080,19 @@ static int compat_standard_to_user(void __user *dst, const void *src)
|
|
|
return copy_to_user(dst, &cv, sizeof(cv)) ? -EFAULT : 0;
|
|
|
}
|
|
|
|
|
|
-static inline int
|
|
|
-compat_calc_match(const struct ip6t_entry_match *m, int *size)
|
|
|
-{
|
|
|
- *size += xt_compat_match_offset(m->u.kernel.match);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
static int compat_calc_entry(const struct ip6t_entry *e,
|
|
|
const struct xt_table_info *info,
|
|
|
const void *base, struct xt_table_info *newinfo)
|
|
|
{
|
|
|
+ const struct xt_entry_match *ematch;
|
|
|
const struct ip6t_entry_target *t;
|
|
|
unsigned int entry_offset;
|
|
|
int off, i, ret;
|
|
|
|
|
|
off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
|
|
|
entry_offset = (void *)e - base;
|
|
|
- IP6T_MATCH_ITERATE(e, compat_calc_match, &off);
|
|
|
+ xt_ematch_foreach(ematch, e)
|
|
|
+ off += xt_compat_match_offset(ematch->u.kernel.match);
|
|
|
t = ip6t_get_target_c(e);
|
|
|
off += xt_compat_target_offset(t->u.kernel.target);
|
|
|
newinfo->size -= off;
|
|
@@ -1142,7 +1114,9 @@ static int compat_calc_entry(const struct ip6t_entry *e,
|
|
|
static int compat_table_info(const struct xt_table_info *info,
|
|
|
struct xt_table_info *newinfo)
|
|
|
{
|
|
|
+ struct ip6t_entry *iter;
|
|
|
void *loc_cpu_entry;
|
|
|
+ int ret;
|
|
|
|
|
|
if (!newinfo || !info)
|
|
|
return -EINVAL;
|
|
@@ -1151,9 +1125,12 @@ static int compat_table_info(const struct xt_table_info *info,
|
|
|
memcpy(newinfo, info, offsetof(struct xt_table_info, entries));
|
|
|
newinfo->initial_entries = 0;
|
|
|
loc_cpu_entry = info->entries[raw_smp_processor_id()];
|
|
|
- return IP6T_ENTRY_ITERATE(loc_cpu_entry, info->size,
|
|
|
- compat_calc_entry, info, loc_cpu_entry,
|
|
|
- newinfo);
|
|
|
+ xt_entry_foreach(iter, loc_cpu_entry, info->size) {
|
|
|
+ ret = compat_calc_entry(iter, info, loc_cpu_entry, newinfo);
|
|
|
+ if (ret != 0)
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
@@ -1267,6 +1244,7 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
|
|
|
struct xt_table_info *oldinfo;
|
|
|
struct xt_counters *counters;
|
|
|
const void *loc_cpu_old_entry;
|
|
|
+ struct ip6t_entry *iter;
|
|
|
|
|
|
ret = 0;
|
|
|
counters = vmalloc_node(num_counters * sizeof(struct xt_counters),
|
|
@@ -1310,8 +1288,9 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
|
|
|
|
|
|
/* Decrease module usage counts and free resource */
|
|
|
loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
|
|
|
- IP6T_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,
|
|
|
- net, NULL);
|
|
|
+ xt_entry_foreach(iter, loc_cpu_old_entry, oldinfo->size)
|
|
|
+ cleanup_entry(iter, net);
|
|
|
+
|
|
|
xt_free_table_info(oldinfo);
|
|
|
if (copy_to_user(counters_ptr, counters,
|
|
|
sizeof(struct xt_counters) * num_counters) != 0)
|
|
@@ -1336,6 +1315,7 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
|
|
|
struct ip6t_replace tmp;
|
|
|
struct xt_table_info *newinfo;
|
|
|
void *loc_cpu_entry;
|
|
|
+ struct ip6t_entry *iter;
|
|
|
|
|
|
if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
|
|
|
return -EFAULT;
|
|
@@ -1356,9 +1336,7 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
|
|
|
goto free_newinfo;
|
|
|
}
|
|
|
|
|
|
- ret = translate_table(net, tmp.name, tmp.valid_hooks,
|
|
|
- newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
|
|
|
- tmp.hook_entry, tmp.underflow);
|
|
|
+ ret = translate_table(net, newinfo, loc_cpu_entry, &tmp);
|
|
|
if (ret != 0)
|
|
|
goto free_newinfo;
|
|
|
|
|
@@ -1371,25 +1349,13 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
|
|
|
return 0;
|
|
|
|
|
|
free_newinfo_untrans:
|
|
|
- IP6T_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, net, NULL);
|
|
|
+ xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
|
|
|
+ cleanup_entry(iter, net);
|
|
|
free_newinfo:
|
|
|
xt_free_table_info(newinfo);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-/* We're lazy, and add to the first CPU; overflow works its fey magic
|
|
|
- * and everything is OK. */
|
|
|
-static int
|
|
|
-add_counter_to_entry(struct ip6t_entry *e,
|
|
|
- const struct xt_counters addme[],
|
|
|
- unsigned int *i)
|
|
|
-{
|
|
|
- ADD_COUNTER(e->counters, addme[*i].bcnt, addme[*i].pcnt);
|
|
|
-
|
|
|
- (*i)++;
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
static int
|
|
|
do_add_counters(struct net *net, const void __user *user, unsigned int len,
|
|
|
int compat)
|
|
@@ -1405,6 +1371,7 @@ do_add_counters(struct net *net, const void __user *user, unsigned int len,
|
|
|
const struct xt_table_info *private;
|
|
|
int ret = 0;
|
|
|
const void *loc_cpu_entry;
|
|
|
+ struct ip6t_entry *iter;
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
struct compat_xt_counters_info compat_tmp;
|
|
|
|
|
@@ -1463,11 +1430,10 @@ do_add_counters(struct net *net, const void __user *user, unsigned int len,
|
|
|
curcpu = smp_processor_id();
|
|
|
xt_info_wrlock(curcpu);
|
|
|
loc_cpu_entry = private->entries[curcpu];
|
|
|
- IP6T_ENTRY_ITERATE(loc_cpu_entry,
|
|
|
- private->size,
|
|
|
- add_counter_to_entry,
|
|
|
- paddc,
|
|
|
- &i);
|
|
|
+ xt_entry_foreach(iter, loc_cpu_entry, private->size) {
|
|
|
+ ADD_COUNTER(iter->counters, paddc[i].bcnt, paddc[i].pcnt);
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
xt_info_wrunlock(curcpu);
|
|
|
|
|
|
unlock_up_free:
|
|
@@ -1496,45 +1462,40 @@ struct compat_ip6t_replace {
|
|
|
static int
|
|
|
compat_copy_entry_to_user(struct ip6t_entry *e, void __user **dstptr,
|
|
|
unsigned int *size, struct xt_counters *counters,
|
|
|
- unsigned int *i)
|
|
|
+ unsigned int i)
|
|
|
{
|
|
|
struct ip6t_entry_target *t;
|
|
|
struct compat_ip6t_entry __user *ce;
|
|
|
u_int16_t target_offset, next_offset;
|
|
|
compat_uint_t origsize;
|
|
|
- int ret;
|
|
|
+ const struct xt_entry_match *ematch;
|
|
|
+ int ret = 0;
|
|
|
|
|
|
- ret = -EFAULT;
|
|
|
origsize = *size;
|
|
|
ce = (struct compat_ip6t_entry __user *)*dstptr;
|
|
|
- if (copy_to_user(ce, e, sizeof(struct ip6t_entry)))
|
|
|
- goto out;
|
|
|
-
|
|
|
- if (copy_to_user(&ce->counters, &counters[*i], sizeof(counters[*i])))
|
|
|
- goto out;
|
|
|
+ if (copy_to_user(ce, e, sizeof(struct ip6t_entry)) != 0 ||
|
|
|
+ copy_to_user(&ce->counters, &counters[i],
|
|
|
+ sizeof(counters[i])) != 0)
|
|
|
+ return -EFAULT;
|
|
|
|
|
|
*dstptr += sizeof(struct compat_ip6t_entry);
|
|
|
*size -= sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
|
|
|
|
|
|
- ret = IP6T_MATCH_ITERATE(e, xt_compat_match_to_user, dstptr, size);
|
|
|
+ xt_ematch_foreach(ematch, e) {
|
|
|
+ ret = xt_compat_match_to_user(ematch, dstptr, size);
|
|
|
+ if (ret != 0)
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
target_offset = e->target_offset - (origsize - *size);
|
|
|
- if (ret)
|
|
|
- goto out;
|
|
|
t = ip6t_get_target(e);
|
|
|
ret = xt_compat_target_to_user(t, dstptr, size);
|
|
|
if (ret)
|
|
|
- goto out;
|
|
|
- ret = -EFAULT;
|
|
|
+ return ret;
|
|
|
next_offset = e->next_offset - (origsize - *size);
|
|
|
- if (put_user(target_offset, &ce->target_offset))
|
|
|
- goto out;
|
|
|
- if (put_user(next_offset, &ce->next_offset))
|
|
|
- goto out;
|
|
|
-
|
|
|
- (*i)++;
|
|
|
+ if (put_user(target_offset, &ce->target_offset) != 0 ||
|
|
|
+ put_user(next_offset, &ce->next_offset) != 0)
|
|
|
+ return -EFAULT;
|
|
|
return 0;
|
|
|
-out:
|
|
|
- return ret;
|
|
|
}
|
|
|
|
|
|
static int
|
|
@@ -1542,7 +1503,7 @@ compat_find_calc_match(struct ip6t_entry_match *m,
|
|
|
const char *name,
|
|
|
const struct ip6t_ip6 *ipv6,
|
|
|
unsigned int hookmask,
|
|
|
- int *size, unsigned int *i)
|
|
|
+ int *size)
|
|
|
{
|
|
|
struct xt_match *match;
|
|
|
|
|
@@ -1556,34 +1517,19 @@ compat_find_calc_match(struct ip6t_entry_match *m,
|
|
|
}
|
|
|
m->u.kernel.match = match;
|
|
|
*size += xt_compat_match_offset(match);
|
|
|
-
|
|
|
- (*i)++;
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int
|
|
|
-compat_release_match(struct ip6t_entry_match *m, unsigned int *i)
|
|
|
-{
|
|
|
- if (i && (*i)-- == 0)
|
|
|
- return 1;
|
|
|
-
|
|
|
- module_put(m->u.kernel.match->me);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int
|
|
|
-compat_release_entry(struct compat_ip6t_entry *e, unsigned int *i)
|
|
|
+static void compat_release_entry(struct compat_ip6t_entry *e)
|
|
|
{
|
|
|
struct ip6t_entry_target *t;
|
|
|
-
|
|
|
- if (i && (*i)-- == 0)
|
|
|
- return 1;
|
|
|
+ struct xt_entry_match *ematch;
|
|
|
|
|
|
/* Cleanup all matches */
|
|
|
- COMPAT_IP6T_MATCH_ITERATE(e, compat_release_match, NULL);
|
|
|
+ xt_ematch_foreach(ematch, e)
|
|
|
+ module_put(ematch->u.kernel.match->me);
|
|
|
t = compat_ip6t_get_target(e);
|
|
|
module_put(t->u.kernel.target->me);
|
|
|
- return 0;
|
|
|
}
|
|
|
|
|
|
static int
|
|
@@ -1594,9 +1540,9 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
|
|
|
const unsigned char *limit,
|
|
|
const unsigned int *hook_entries,
|
|
|
const unsigned int *underflows,
|
|
|
- unsigned int *i,
|
|
|
const char *name)
|
|
|
{
|
|
|
+ struct xt_entry_match *ematch;
|
|
|
struct ip6t_entry_target *t;
|
|
|
struct xt_target *target;
|
|
|
unsigned int entry_offset;
|
|
@@ -1625,10 +1571,13 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
|
|
|
off = sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
|
|
|
entry_offset = (void *)e - (void *)base;
|
|
|
j = 0;
|
|
|
- ret = COMPAT_IP6T_MATCH_ITERATE(e, compat_find_calc_match, name,
|
|
|
- &e->ipv6, e->comefrom, &off, &j);
|
|
|
- if (ret != 0)
|
|
|
- goto release_matches;
|
|
|
+ xt_ematch_foreach(ematch, e) {
|
|
|
+ ret = compat_find_calc_match(ematch, name,
|
|
|
+ &e->ipv6, e->comefrom, &off);
|
|
|
+ if (ret != 0)
|
|
|
+ goto release_matches;
|
|
|
+ ++j;
|
|
|
+ }
|
|
|
|
|
|
t = compat_ip6t_get_target(e);
|
|
|
target = try_then_request_module(xt_find_target(AF_INET6,
|
|
@@ -1660,14 +1609,16 @@ check_compat_entry_size_and_hooks(struct compat_ip6t_entry *e,
|
|
|
/* Clear counters and comefrom */
|
|
|
memset(&e->counters, 0, sizeof(e->counters));
|
|
|
e->comefrom = 0;
|
|
|
-
|
|
|
- (*i)++;
|
|
|
return 0;
|
|
|
|
|
|
out:
|
|
|
module_put(t->u.kernel.target->me);
|
|
|
release_matches:
|
|
|
- IP6T_MATCH_ITERATE(e, compat_release_match, &j);
|
|
|
+ xt_ematch_foreach(ematch, e) {
|
|
|
+ if (j-- == 0)
|
|
|
+ break;
|
|
|
+ module_put(ematch->u.kernel.match->me);
|
|
|
+ }
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -1681,6 +1632,7 @@ compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
|
|
|
struct ip6t_entry *de;
|
|
|
unsigned int origsize;
|
|
|
int ret, h;
|
|
|
+ struct xt_entry_match *ematch;
|
|
|
|
|
|
ret = 0;
|
|
|
origsize = *size;
|
|
@@ -1691,10 +1643,11 @@ compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
|
|
|
*dstptr += sizeof(struct ip6t_entry);
|
|
|
*size += sizeof(struct ip6t_entry) - sizeof(struct compat_ip6t_entry);
|
|
|
|
|
|
- ret = COMPAT_IP6T_MATCH_ITERATE(e, xt_compat_match_from_user,
|
|
|
- dstptr, size);
|
|
|
- if (ret)
|
|
|
- return ret;
|
|
|
+ xt_ematch_foreach(ematch, e) {
|
|
|
+ ret = xt_compat_match_from_user(ematch, dstptr, size);
|
|
|
+ if (ret != 0)
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
de->target_offset = e->target_offset - (origsize - *size);
|
|
|
t = compat_ip6t_get_target(e);
|
|
|
target = t->u.kernel.target;
|
|
@@ -1711,11 +1664,12 @@ compat_copy_entry_from_user(struct compat_ip6t_entry *e, void **dstptr,
|
|
|
}
|
|
|
|
|
|
static int compat_check_entry(struct ip6t_entry *e, struct net *net,
|
|
|
- const char *name, unsigned int *i)
|
|
|
+ const char *name)
|
|
|
{
|
|
|
unsigned int j;
|
|
|
- int ret;
|
|
|
+ int ret = 0;
|
|
|
struct xt_mtchk_param mtpar;
|
|
|
+ struct xt_entry_match *ematch;
|
|
|
|
|
|
j = 0;
|
|
|
mtpar.net = net;
|
|
@@ -1723,19 +1677,24 @@ static int compat_check_entry(struct ip6t_entry *e, struct net *net,
|
|
|
mtpar.entryinfo = &e->ipv6;
|
|
|
mtpar.hook_mask = e->comefrom;
|
|
|
mtpar.family = NFPROTO_IPV6;
|
|
|
- ret = IP6T_MATCH_ITERATE(e, check_match, &mtpar, &j);
|
|
|
- if (ret)
|
|
|
- goto cleanup_matches;
|
|
|
+ xt_ematch_foreach(ematch, e) {
|
|
|
+ ret = check_match(ematch, &mtpar);
|
|
|
+ if (ret != 0)
|
|
|
+ goto cleanup_matches;
|
|
|
+ ++j;
|
|
|
+ }
|
|
|
|
|
|
ret = check_target(e, net, name);
|
|
|
if (ret)
|
|
|
goto cleanup_matches;
|
|
|
-
|
|
|
- (*i)++;
|
|
|
return 0;
|
|
|
|
|
|
cleanup_matches:
|
|
|
- IP6T_MATCH_ITERATE(e, cleanup_match, net, &j);
|
|
|
+ xt_ematch_foreach(ematch, e) {
|
|
|
+ if (j-- == 0)
|
|
|
+ break;
|
|
|
+ cleanup_match(ematch, net);
|
|
|
+ }
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -1753,8 +1712,10 @@ translate_compat_table(struct net *net,
|
|
|
unsigned int i, j;
|
|
|
struct xt_table_info *newinfo, *info;
|
|
|
void *pos, *entry0, *entry1;
|
|
|
+ struct compat_ip6t_entry *iter0;
|
|
|
+ struct ip6t_entry *iter1;
|
|
|
unsigned int size;
|
|
|
- int ret;
|
|
|
+ int ret = 0;
|
|
|
|
|
|
info = *pinfo;
|
|
|
entry0 = *pentry0;
|
|
@@ -1771,13 +1732,14 @@ translate_compat_table(struct net *net,
|
|
|
j = 0;
|
|
|
xt_compat_lock(AF_INET6);
|
|
|
/* Walk through entries, checking offsets. */
|
|
|
- ret = COMPAT_IP6T_ENTRY_ITERATE(entry0, total_size,
|
|
|
- check_compat_entry_size_and_hooks,
|
|
|
- info, &size, entry0,
|
|
|
- entry0 + total_size,
|
|
|
- hook_entries, underflows, &j, name);
|
|
|
- if (ret != 0)
|
|
|
- goto out_unlock;
|
|
|
+ xt_entry_foreach(iter0, entry0, total_size) {
|
|
|
+ ret = check_compat_entry_size_and_hooks(iter0, info, &size,
|
|
|
+ entry0, entry0 + total_size, hook_entries, underflows,
|
|
|
+ name);
|
|
|
+ if (ret != 0)
|
|
|
+ goto out_unlock;
|
|
|
+ ++j;
|
|
|
+ }
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
if (j != number) {
|
|
@@ -1816,9 +1778,12 @@ translate_compat_table(struct net *net,
|
|
|
entry1 = newinfo->entries[raw_smp_processor_id()];
|
|
|
pos = entry1;
|
|
|
size = total_size;
|
|
|
- ret = COMPAT_IP6T_ENTRY_ITERATE(entry0, total_size,
|
|
|
- compat_copy_entry_from_user,
|
|
|
- &pos, &size, name, newinfo, entry1);
|
|
|
+ xt_entry_foreach(iter0, entry0, total_size) {
|
|
|
+ ret = compat_copy_entry_from_user(iter0, &pos,
|
|
|
+ &size, name, newinfo, entry1);
|
|
|
+ if (ret != 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
xt_compat_flush_offsets(AF_INET6);
|
|
|
xt_compat_unlock(AF_INET6);
|
|
|
if (ret)
|
|
@@ -1829,13 +1794,32 @@ translate_compat_table(struct net *net,
|
|
|
goto free_newinfo;
|
|
|
|
|
|
i = 0;
|
|
|
- ret = IP6T_ENTRY_ITERATE(entry1, newinfo->size, compat_check_entry,
|
|
|
- net, name, &i);
|
|
|
+ xt_entry_foreach(iter1, entry1, newinfo->size) {
|
|
|
+ ret = compat_check_entry(iter1, net, name);
|
|
|
+ if (ret != 0)
|
|
|
+ break;
|
|
|
+ ++i;
|
|
|
+ }
|
|
|
if (ret) {
|
|
|
+ /*
|
|
|
+ * The first i matches need cleanup_entry (calls ->destroy)
|
|
|
+ * because they had called ->check already. The other j-i
|
|
|
+ * entries need only release.
|
|
|
+ */
|
|
|
+ int skip = i;
|
|
|
j -= i;
|
|
|
- COMPAT_IP6T_ENTRY_ITERATE_CONTINUE(entry0, newinfo->size, i,
|
|
|
- compat_release_entry, &j);
|
|
|
- IP6T_ENTRY_ITERATE(entry1, newinfo->size, cleanup_entry, net, &i);
|
|
|
+ xt_entry_foreach(iter0, entry0, newinfo->size) {
|
|
|
+ if (skip-- > 0)
|
|
|
+ continue;
|
|
|
+ if (j-- == 0)
|
|
|
+ break;
|
|
|
+ compat_release_entry(iter0);
|
|
|
+ }
|
|
|
+ xt_entry_foreach(iter1, entry1, newinfo->size) {
|
|
|
+ if (i-- == 0)
|
|
|
+ break;
|
|
|
+ cleanup_entry(iter1, net);
|
|
|
+ }
|
|
|
xt_free_table_info(newinfo);
|
|
|
return ret;
|
|
|
}
|
|
@@ -1853,7 +1837,11 @@ translate_compat_table(struct net *net,
|
|
|
free_newinfo:
|
|
|
xt_free_table_info(newinfo);
|
|
|
out:
|
|
|
- COMPAT_IP6T_ENTRY_ITERATE(entry0, total_size, compat_release_entry, &j);
|
|
|
+ xt_entry_foreach(iter0, entry0, total_size) {
|
|
|
+ if (j-- == 0)
|
|
|
+ break;
|
|
|
+ compat_release_entry(iter0);
|
|
|
+ }
|
|
|
return ret;
|
|
|
out_unlock:
|
|
|
xt_compat_flush_offsets(AF_INET6);
|
|
@@ -1868,6 +1856,7 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
|
|
|
struct compat_ip6t_replace tmp;
|
|
|
struct xt_table_info *newinfo;
|
|
|
void *loc_cpu_entry;
|
|
|
+ struct ip6t_entry *iter;
|
|
|
|
|
|
if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
|
|
|
return -EFAULT;
|
|
@@ -1906,7 +1895,8 @@ compat_do_replace(struct net *net, void __user *user, unsigned int len)
|
|
|
return 0;
|
|
|
|
|
|
free_newinfo_untrans:
|
|
|
- IP6T_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, net, NULL);
|
|
|
+ xt_entry_foreach(iter, loc_cpu_entry, newinfo->size)
|
|
|
+ cleanup_entry(iter, net);
|
|
|
free_newinfo:
|
|
|
xt_free_table_info(newinfo);
|
|
|
return ret;
|
|
@@ -1955,6 +1945,7 @@ compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
|
|
|
int ret = 0;
|
|
|
const void *loc_cpu_entry;
|
|
|
unsigned int i = 0;
|
|
|
+ struct ip6t_entry *iter;
|
|
|
|
|
|
counters = alloc_counters(table);
|
|
|
if (IS_ERR(counters))
|
|
@@ -1967,9 +1958,12 @@ compat_copy_entries_to_user(unsigned int total_size, struct xt_table *table,
|
|
|
loc_cpu_entry = private->entries[raw_smp_processor_id()];
|
|
|
pos = userptr;
|
|
|
size = total_size;
|
|
|
- ret = IP6T_ENTRY_ITERATE(loc_cpu_entry, total_size,
|
|
|
- compat_copy_entry_to_user,
|
|
|
- &pos, &size, counters, &i);
|
|
|
+ xt_entry_foreach(iter, loc_cpu_entry, total_size) {
|
|
|
+ ret = compat_copy_entry_to_user(iter, &pos,
|
|
|
+ &size, counters, i++);
|
|
|
+ if (ret != 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
vfree(counters);
|
|
|
return ret;
|
|
@@ -2143,11 +2137,7 @@ struct xt_table *ip6t_register_table(struct net *net,
|
|
|
loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
|
|
|
memcpy(loc_cpu_entry, repl->entries, repl->size);
|
|
|
|
|
|
- ret = translate_table(net, table->name, table->valid_hooks,
|
|
|
- newinfo, loc_cpu_entry, repl->size,
|
|
|
- repl->num_entries,
|
|
|
- repl->hook_entry,
|
|
|
- repl->underflow);
|
|
|
+ ret = translate_table(net, newinfo, loc_cpu_entry, repl);
|
|
|
if (ret != 0)
|
|
|
goto out_free;
|
|
|
|
|
@@ -2169,12 +2159,14 @@ void ip6t_unregister_table(struct net *net, struct xt_table *table)
|
|
|
struct xt_table_info *private;
|
|
|
void *loc_cpu_entry;
|
|
|
struct module *table_owner = table->me;
|
|
|
+ struct ip6t_entry *iter;
|
|
|
|
|
|
private = xt_unregister_table(table);
|
|
|
|
|
|
/* Decrease module usage counts and free resources */
|
|
|
loc_cpu_entry = private->entries[raw_smp_processor_id()];
|
|
|
- IP6T_ENTRY_ITERATE(loc_cpu_entry, private->size, cleanup_entry, net, NULL);
|
|
|
+ xt_entry_foreach(iter, loc_cpu_entry, private->size)
|
|
|
+ cleanup_entry(iter, net);
|
|
|
if (private->number > private->initial_entries)
|
|
|
module_put(table_owner);
|
|
|
xt_free_table_info(private);
|