netfilter: xtables: symmetric COMPAT_XT_ALIGN definition
[safe/jmp/linux-2.6] / net / netfilter / x_tables.c
index 509a956..5c564ff 100644 (file)
@@ -329,6 +329,32 @@ int xt_find_revision(u8 af, const char *name, u8 revision, int target,
 }
 EXPORT_SYMBOL_GPL(xt_find_revision);
 
+static char *textify_hooks(char *buf, size_t size, unsigned int mask)
+{
+       static const char *const names[] = {
+               "PREROUTING", "INPUT", "FORWARD",
+               "OUTPUT", "POSTROUTING", "BROUTING",
+       };
+       unsigned int i;
+       char *p = buf;
+       bool np = false;
+       int res;
+
+       *p = '\0';
+       for (i = 0; i < ARRAY_SIZE(names); ++i) {
+               if (!(mask & (1 << i)))
+                       continue;
+               res = snprintf(p, size, "%s%s", np ? "/" : "", names[i]);
+               if (res > 0) {
+                       size -= res;
+                       p += res;
+               }
+               np = true;
+       }
+
+       return buf;
+}
+
 int xt_check_match(struct xt_mtchk_param *par,
                   unsigned int size, u_int8_t proto, bool inv_proto)
 {
@@ -338,26 +364,30 @@ int xt_check_match(struct xt_mtchk_param *par,
                 * ebt_among is exempt from centralized matchsize checking
                 * because it uses a dynamic-size data set.
                 */
-               printk("%s_tables: %s match: invalid size %Zu != %u\n",
+               pr_err("%s_tables: %s match: invalid size %u != %u\n",
                       xt_prefix[par->family], par->match->name,
                       XT_ALIGN(par->match->matchsize), size);
                return -EINVAL;
        }
        if (par->match->table != NULL &&
            strcmp(par->match->table, par->table) != 0) {
-               printk("%s_tables: %s match: only valid in %s table, not %s\n",
+               pr_err("%s_tables: %s match: only valid in %s table, not %s\n",
                       xt_prefix[par->family], par->match->name,
                       par->match->table, par->table);
                return -EINVAL;
        }
        if (par->match->hooks && (par->hook_mask & ~par->match->hooks) != 0) {
-               printk("%s_tables: %s match: bad hook_mask %#x/%#x\n",
+               char used[64], allow[64];
+
+               pr_err("%s_tables: %s match: used from hooks %s, but only "
+                      "valid from %s\n",
                       xt_prefix[par->family], par->match->name,
-                      par->hook_mask, par->match->hooks);
+                      textify_hooks(used, sizeof(used), par->hook_mask),
+                      textify_hooks(allow, sizeof(allow), par->match->hooks));
                return -EINVAL;
        }
        if (par->match->proto && (par->match->proto != proto || inv_proto)) {
-               printk("%s_tables: %s match: only valid for protocol %u\n",
+               pr_err("%s_tables: %s match: only valid for protocol %u\n",
                       xt_prefix[par->family], par->match->name,
                       par->match->proto);
                return -EINVAL;
@@ -484,26 +514,30 @@ int xt_check_target(struct xt_tgchk_param *par,
                    unsigned int size, u_int8_t proto, bool inv_proto)
 {
        if (XT_ALIGN(par->target->targetsize) != size) {
-               printk("%s_tables: %s target: invalid size %Zu != %u\n",
+               pr_err("%s_tables: %s target: invalid size %u != %u\n",
                       xt_prefix[par->family], par->target->name,
                       XT_ALIGN(par->target->targetsize), size);
                return -EINVAL;
        }
        if (par->target->table != NULL &&
            strcmp(par->target->table, par->table) != 0) {
-               printk("%s_tables: %s target: only valid in %s table, not %s\n",
+               pr_err("%s_tables: %s target: only valid in %s table, not %s\n",
                       xt_prefix[par->family], par->target->name,
                       par->target->table, par->table);
                return -EINVAL;
        }
        if (par->target->hooks && (par->hook_mask & ~par->target->hooks) != 0) {
-               printk("%s_tables: %s target: bad hook_mask %#x/%#x\n",
+               char used[64], allow[64];
+
+               pr_err("%s_tables: %s target: used from hooks %s, but only "
+                      "usable from %s\n",
                       xt_prefix[par->family], par->target->name,
-                      par->hook_mask, par->target->hooks);
+                      textify_hooks(used, sizeof(used), par->hook_mask),
+                      textify_hooks(allow, sizeof(allow), par->target->hooks));
                return -EINVAL;
        }
        if (par->target->proto && (par->target->proto != proto || inv_proto)) {
-               printk("%s_tables: %s target: only valid for protocol %u\n",
+               pr_err("%s_tables: %s target: only valid for protocol %u\n",
                       xt_prefix[par->family], par->target->name,
                       par->target->proto);
                return -EINVAL;
@@ -583,7 +617,7 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
        int cpu;
 
        /* Pedantry: prevent them from hitting BUG() in vmalloc.c --RR */
-       if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > num_physpages)
+       if ((SMP_ALIGN(size) >> PAGE_SHIFT) + 2 > totalram_pages)
                return NULL;
 
        newinfo = kzalloc(XT_TABLE_INFO_SZ, GFP_KERNEL);
@@ -625,20 +659,6 @@ void xt_free_table_info(struct xt_table_info *info)
 }
 EXPORT_SYMBOL(xt_free_table_info);
 
-void xt_table_entry_swap_rcu(struct xt_table_info *oldinfo,
-                            struct xt_table_info *newinfo)
-{
-       unsigned int cpu;
-
-       for_each_possible_cpu(cpu) {
-               void *p = oldinfo->entries[cpu];
-               rcu_assign_pointer(oldinfo->entries[cpu], newinfo->entries[cpu]);
-               newinfo->entries[cpu] = p;
-       }
-
-}
-EXPORT_SYMBOL_GPL(xt_table_entry_swap_rcu);
-
 /* Find table by name, grabs mutex & ref.  Returns ERR_PTR() on error. */
 struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
                                    const char *name)
@@ -676,45 +696,57 @@ void xt_compat_unlock(u_int8_t af)
 EXPORT_SYMBOL_GPL(xt_compat_unlock);
 #endif
 
+DEFINE_PER_CPU(struct xt_info_lock, xt_info_locks);
+EXPORT_PER_CPU_SYMBOL_GPL(xt_info_locks);
+
+
 struct xt_table_info *
 xt_replace_table(struct xt_table *table,
              unsigned int num_counters,
              struct xt_table_info *newinfo,
              int *error)
 {
-       struct xt_table_info *oldinfo, *private;
+       struct xt_table_info *private;
 
        /* Do the substitution. */
-       mutex_lock(&table->lock);
+       local_bh_disable();
        private = table->private;
+
        /* Check inside lock: is the old number correct? */
        if (num_counters != private->number) {
                duprintf("num_counters != table->private->number (%u/%u)\n",
                         num_counters, private->number);
-               mutex_unlock(&table->lock);
+               local_bh_enable();
                *error = -EAGAIN;
                return NULL;
        }
-       oldinfo = private;
-       rcu_assign_pointer(table->private, newinfo);
-       newinfo->initial_entries = oldinfo->initial_entries;
-       mutex_unlock(&table->lock);
 
-       synchronize_net();
-       return oldinfo;
+       table->private = newinfo;
+       newinfo->initial_entries = private->initial_entries;
+
+       /*
+        * Even though table entries have now been swapped, other CPU's
+        * may still be using the old entries. This is okay, because
+        * resynchronization happens because of the locking done
+        * during the get_counters() routine.
+        */
+       local_bh_enable();
+
+       return private;
 }
 EXPORT_SYMBOL_GPL(xt_replace_table);
 
-struct xt_table *xt_register_table(struct net *net, struct xt_table *table,
+struct xt_table *xt_register_table(struct net *net,
+                                  const struct xt_table *input_table,
                                   struct xt_table_info *bootstrap,
                                   struct xt_table_info *newinfo)
 {
        int ret;
        struct xt_table_info *private;
-       struct xt_table *t;
+       struct xt_table *t, *table;
 
        /* Don't add one object to multiple lists. */
-       table = kmemdup(table, sizeof(struct xt_table), GFP_KERNEL);
+       table = kmemdup(input_table, sizeof(struct xt_table), GFP_KERNEL);
        if (!table) {
                ret = -ENOMEM;
                goto out;
@@ -734,7 +766,6 @@ struct xt_table *xt_register_table(struct net *net, struct xt_table *table,
 
        /* Simplifies replace_table code. */
        table->private = bootstrap;
-       mutex_init(&table->lock);
 
        if (!xt_replace_table(table, 0, newinfo, &ret))
                goto unlock;
@@ -1147,7 +1178,14 @@ static struct pernet_operations xt_net_ops = {
 
 static int __init xt_init(void)
 {
-       int i, rv;
+       unsigned int i;
+       int rv;
+
+       for_each_possible_cpu(i) {
+               struct xt_info_lock *lock = &per_cpu(xt_info_locks, i);
+               spin_lock_init(&lock->lock);
+               lock->readers = 0;
+       }
 
        xt = kmalloc(sizeof(struct xt_af) * NFPROTO_NUMPROTO, GFP_KERNEL);
        if (!xt)