]> err.no Git - linux-2.6/blobdiff - net/ipv4/netfilter/arp_tables.c
Pull pnpacpi into acpica branch
[linux-2.6] / net / ipv4 / netfilter / arp_tables.c
index a7969286e6e721ecf371aaed4ca242c92eaa07b7..bba15630469599b7a4d93d32baf03f86b93d1e20 100644 (file)
@@ -68,19 +68,14 @@ struct arpt_table_info {
        unsigned int initial_entries;
        unsigned int hook_entry[NF_ARP_NUMHOOKS];
        unsigned int underflow[NF_ARP_NUMHOOKS];
-       char entries[0] __attribute__((aligned(SMP_CACHE_BYTES)));
+       void *entries[NR_CPUS];
 };
 
 static LIST_HEAD(arpt_target);
 static LIST_HEAD(arpt_tables);
+#define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
 #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
 
-#ifdef CONFIG_SMP
-#define TABLE_OFFSET(t,p) (SMP_ALIGN((t)->size)*(p))
-#else
-#define TABLE_OFFSET(t,p) 0
-#endif
-
 static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap,
                                      char *hdr_addr, int len)
 {
@@ -269,9 +264,7 @@ unsigned int arpt_do_table(struct sk_buff **pskb,
        outdev = out ? out->name : nulldevname;
 
        read_lock_bh(&table->lock);
-       table_base = (void *)table->private->entries
-               + TABLE_OFFSET(table->private,
-                              smp_processor_id());
+       table_base = (void *)table->private->entries[smp_processor_id()];
        e = get_entry(table_base, table->private->hook_entry[hook]);
        back = get_entry(table_base, table->private->underflow[hook]);
 
@@ -347,58 +340,106 @@ unsigned int arpt_do_table(struct sk_buff **pskb,
                return verdict;
 }
 
-static inline void *find_inlist_lock_noload(struct list_head *head,
-                                           const char *name,
-                                           int *error,
-                                           struct semaphore *mutex)
+/*
+ * These are weird, but module loading must not be done with mutex
+ * held (since they will register), and we have to have a single
+ * function to use try_then_request_module().
+ */
+
+/* Find table by name, grabs mutex & ref.  Returns ERR_PTR() on error. */
+static inline struct arpt_table *find_table_lock(const char *name)
 {
-       void *ret;
+       struct arpt_table *t;
 
-       *error = down_interruptible(mutex);
-       if (*error != 0)
-               return NULL;
+       if (down_interruptible(&arpt_mutex) != 0)
+               return ERR_PTR(-EINTR);
 
-       ret = list_named_find(head, name);
-       if (!ret) {
-               *error = -ENOENT;
-               up(mutex);
-       }
-       return ret;
+       list_for_each_entry(t, &arpt_tables, list)
+               if (strcmp(t->name, name) == 0 && try_module_get(t->me))
+                       return t;
+       up(&arpt_mutex);
+       return NULL;
 }
 
-#ifndef CONFIG_KMOD
-#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
-#else
-static void *
-find_inlist_lock(struct list_head *head,
-                const char *name,
-                const char *prefix,
-                int *error,
-                struct semaphore *mutex)
+
+/* Find target, grabs ref.  Returns ERR_PTR() on error. */
+static inline struct arpt_target *find_target(const char *name, u8 revision)
 {
-       void *ret;
+       struct arpt_target *t;
+       int err = 0;
 
-       ret = find_inlist_lock_noload(head, name, error, mutex);
-       if (!ret) {
-               duprintf("find_inlist: loading `%s%s'.\n", prefix, name);
-               request_module("%s%s", prefix, name);
-               ret = find_inlist_lock_noload(head, name, error, mutex);
+       if (down_interruptible(&arpt_mutex) != 0)
+               return ERR_PTR(-EINTR);
+
+       list_for_each_entry(t, &arpt_target, list) {
+               if (strcmp(t->name, name) == 0) {
+                       if (t->revision == revision) {
+                               if (try_module_get(t->me)) {
+                                       up(&arpt_mutex);
+                                       return t;
+                               }
+                       } else
+                               err = -EPROTOTYPE; /* Found something. */
+               }
        }
+       up(&arpt_mutex);
+       return ERR_PTR(err);
+}
 
-       return ret;
+struct arpt_target *arpt_find_target(const char *name, u8 revision)
+{
+       struct arpt_target *target;
+
+       target = try_then_request_module(find_target(name, revision),
+                                        "arpt_%s", name);
+       if (IS_ERR(target) || !target)
+               return NULL;
+       return target;
 }
-#endif
 
-static inline struct arpt_table *arpt_find_table_lock(const char *name, int *error, struct semaphore *mutex)
+static int target_revfn(const char *name, u8 revision, int *bestp)
 {
-       return find_inlist_lock(&arpt_tables, name, "arptable_", error, mutex);
+       struct arpt_target *t;
+       int have_rev = 0;
+
+       list_for_each_entry(t, &arpt_target, list) {
+               if (strcmp(t->name, name) == 0) {
+                       if (t->revision > *bestp)
+                               *bestp = t->revision;
+                       if (t->revision == revision)
+                               have_rev =1;
+               }
+       }
+       return have_rev;
 }
 
-static struct arpt_target *arpt_find_target_lock(const char *name, int *error, struct semaphore *mutex)
+/* Returns true or false (if no such extension at all) */
+static inline int find_revision(const char *name, u8 revision,
+                               int (*revfn)(const char *, u8, int *),
+                               int *err)
 {
-       return find_inlist_lock(&arpt_target, name, "arpt_", error, mutex);
+       int have_rev, best = -1;
+
+       if (down_interruptible(&arpt_mutex) != 0) {
+               *err = -EINTR;
+               return 1;
+       }
+       have_rev = revfn(name, revision, &best);
+       up(&arpt_mutex);
+
+       /* Nothing at all?  Return 0 to try loading module. */
+       if (best == -1) {
+               *err = -ENOENT;
+               return 0;
+       }
+
+       *err = best;
+       if (!have_rev)
+               *err = -EPROTONOSUPPORT;
+       return 1;
 }
 
+
 /* All zeroes == unconditional rule. */
 static inline int unconditional(const struct arpt_arp *arp)
 {
@@ -414,7 +455,8 @@ static inline int unconditional(const struct arpt_arp *arp)
 /* Figures out from what hook each rule can be called: returns 0 if
  * there are loops.  Puts hook bitmask in comefrom.
  */
-static int mark_source_chains(struct arpt_table_info *newinfo, unsigned int valid_hooks)
+static int mark_source_chains(struct arpt_table_info *newinfo,
+                             unsigned int valid_hooks, void *entry0)
 {
        unsigned int hook;
 
@@ -424,7 +466,7 @@ static int mark_source_chains(struct arpt_table_info *newinfo, unsigned int vali
        for (hook = 0; hook < NF_ARP_NUMHOOKS; hook++) {
                unsigned int pos = newinfo->hook_entry[hook];
                struct arpt_entry *e
-                       = (struct arpt_entry *)(newinfo->entries + pos);
+                       = (struct arpt_entry *)(entry0 + pos);
 
                if (!(valid_hooks & (1 << hook)))
                        continue;
@@ -466,13 +508,13 @@ static int mark_source_chains(struct arpt_table_info *newinfo, unsigned int vali
                                                goto next;
 
                                        e = (struct arpt_entry *)
-                                               (newinfo->entries + pos);
+                                               (entry0 + pos);
                                } while (oldpos == pos + e->next_offset);
 
                                /* Move along one */
                                size = e->next_offset;
                                e = (struct arpt_entry *)
-                                       (newinfo->entries + pos + size);
+                                       (entry0 + pos + size);
                                e->counters.pcnt = pos;
                                pos += size;
                        } else {
@@ -489,7 +531,7 @@ static int mark_source_chains(struct arpt_table_info *newinfo, unsigned int vali
                                        newpos = pos + e->next_offset;
                                }
                                e = (struct arpt_entry *)
-                                       (newinfo->entries + newpos);
+                                       (entry0 + newpos);
                                e->counters.pcnt = pos;
                                pos = newpos;
                        }
@@ -544,17 +586,15 @@ static inline int check_entry(struct arpt_entry *e, const char *name, unsigned i
        }
 
        t = arpt_get_target(e);
-       target = arpt_find_target_lock(t->u.user.name, &ret, &arpt_mutex);
-       if (!target) {
+       target = try_then_request_module(find_target(t->u.user.name,
+                                                    t->u.user.revision),
+                                        "arpt_%s", t->u.user.name);
+       if (IS_ERR(target) || !target) {
                duprintf("check_entry: `%s' not found\n", t->u.user.name);
+               ret = target ? PTR_ERR(target) : -ENOENT;
                goto out;
        }
-       if (!try_module_get((target->me))) {
-               ret = -ENOENT;
-               goto out_unlock;
-       }
        t->u.kernel.target = target;
-       up(&arpt_mutex);
 
        if (t->u.kernel.target == &arpt_standard_target) {
                if (!standard_check(t, size)) {
@@ -576,8 +616,6 @@ static inline int check_entry(struct arpt_entry *e, const char *name, unsigned i
        (*i)++;
        return 0;
 
-out_unlock:
-       up(&arpt_mutex);
 out:
        return ret;
 }
@@ -645,6 +683,7 @@ static inline int cleanup_entry(struct arpt_entry *e, unsigned int *i)
 static int translate_table(const char *name,
                           unsigned int valid_hooks,
                           struct arpt_table_info *newinfo,
+                          void *entry0,
                           unsigned int size,
                           unsigned int number,
                           const unsigned int *hook_entries,
@@ -666,11 +705,11 @@ static int translate_table(const char *name,
        i = 0;
 
        /* Walk through entries, checking offsets. */
-       ret = ARPT_ENTRY_ITERATE(newinfo->entries, newinfo->size,
+       ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size,
                                 check_entry_size_and_hooks,
                                 newinfo,
-                                newinfo->entries,
-                                newinfo->entries + size,
+                                entry0,
+                                entry0 + size,
                                 hook_entries, underflows, &i);
        duprintf("translate_table: ARPT_ENTRY_ITERATE gives %d\n", ret);
        if (ret != 0)
@@ -699,29 +738,26 @@ static int translate_table(const char *name,
                }
        }
 
-       if (!mark_source_chains(newinfo, valid_hooks)) {
+       if (!mark_source_chains(newinfo, valid_hooks, entry0)) {
                duprintf("Looping hook\n");
                return -ELOOP;
        }
 
        /* Finally, each sanity check must pass */
        i = 0;
-       ret = ARPT_ENTRY_ITERATE(newinfo->entries, newinfo->size,
+       ret = ARPT_ENTRY_ITERATE(entry0, newinfo->size,
                                 check_entry, name, size, &i);
 
        if (ret != 0) {
-               ARPT_ENTRY_ITERATE(newinfo->entries, newinfo->size,
+               ARPT_ENTRY_ITERATE(entry0, newinfo->size,
                                   cleanup_entry, &i);
                return ret;
        }
 
        /* And one copy for every other CPU */
        for_each_cpu(i) {
-               if (i == 0)
-                       continue;
-               memcpy(newinfo->entries + SMP_ALIGN(newinfo->size) * i,
-                      newinfo->entries,
-                      SMP_ALIGN(newinfo->size));
+               if (newinfo->entries[i] && newinfo->entries[i] != entry0)
+                       memcpy(newinfo->entries[i], entry0, newinfo->size);
        }
 
        return ret;
@@ -763,15 +799,42 @@ static inline int add_entry_to_counter(const struct arpt_entry *e,
        return 0;
 }
 
+static inline int set_entry_to_counter(const struct arpt_entry *e,
+                                      struct arpt_counters total[],
+                                      unsigned int *i)
+{
+       SET_COUNTER(total[*i], e->counters.bcnt, e->counters.pcnt);
+
+       (*i)++;
+       return 0;
+}
+
 static void get_counters(const struct arpt_table_info *t,
                         struct arpt_counters counters[])
 {
        unsigned int cpu;
        unsigned int i;
+       unsigned int curcpu;
+
+       /* Instead of clearing (by a previous call to memset())
+        * the counters and using adds, we set the counters
+        * with data used by 'current' CPU
+        * We dont care about preemption here.
+        */
+       curcpu = raw_smp_processor_id();
+
+       i = 0;
+       ARPT_ENTRY_ITERATE(t->entries[curcpu],
+                          t->size,
+                          set_entry_to_counter,
+                          counters,
+                          &i);
 
        for_each_cpu(cpu) {
+               if (cpu == curcpu)
+                       continue;
                i = 0;
-               ARPT_ENTRY_ITERATE(t->entries + TABLE_OFFSET(t, cpu),
+               ARPT_ENTRY_ITERATE(t->entries[cpu],
                                   t->size,
                                   add_entry_to_counter,
                                   counters,
@@ -787,6 +850,7 @@ static int copy_entries_to_user(unsigned int total_size,
        struct arpt_entry *e;
        struct arpt_counters *counters;
        int ret = 0;
+       void *loc_cpu_entry;
 
        /* We need atomic snapshot of counters: rest doesn't change
         * (other than comefrom, which userspace doesn't care
@@ -799,13 +863,13 @@ static int copy_entries_to_user(unsigned int total_size,
                return -ENOMEM;
 
        /* First, sum counters... */
-       memset(counters, 0, countersize);
        write_lock_bh(&table->lock);
        get_counters(table->private, counters);
        write_unlock_bh(&table->lock);
 
-       /* ... then copy entire thing from CPU 0... */
-       if (copy_to_user(userptr, table->private->entries, total_size) != 0) {
+       loc_cpu_entry = table->private->entries[raw_smp_processor_id()];
+       /* ... then copy entire thing ... */
+       if (copy_to_user(userptr, loc_cpu_entry, total_size) != 0) {
                ret = -EFAULT;
                goto free_counters;
        }
@@ -815,7 +879,7 @@ static int copy_entries_to_user(unsigned int total_size,
        for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
                struct arpt_entry_target *t;
 
-               e = (struct arpt_entry *)(table->private->entries + off);
+               e = (struct arpt_entry *)(loc_cpu_entry + off);
                if (copy_to_user(userptr + off
                                 + offsetof(struct arpt_entry, counters),
                                 &counters[num],
@@ -846,8 +910,8 @@ static int get_entries(const struct arpt_get_entries *entries,
        int ret;
        struct arpt_table *t;
 
-       t = arpt_find_table_lock(entries->name, &ret, &arpt_mutex);
-       if (t) {
+       t = find_table_lock(entries->name);
+       if (t || !IS_ERR(t)) {
                duprintf("t->private->number = %u\n",
                         t->private->number);
                if (entries->size == t->private->size)
@@ -859,14 +923,55 @@ static int get_entries(const struct arpt_get_entries *entries,
                                 entries->size);
                        ret = -EINVAL;
                }
+               module_put(t->me);
                up(&arpt_mutex);
        } else
-               duprintf("get_entries: Can't find %s!\n",
-                        entries->name);
+               ret = t ? PTR_ERR(t) : -ENOENT;
 
        return ret;
 }
 
+static void free_table_info(struct arpt_table_info *info)
+{
+       int cpu;
+       for_each_cpu(cpu) {
+               if (info->size <= PAGE_SIZE)
+                       kfree(info->entries[cpu]);
+               else
+                       vfree(info->entries[cpu]);
+       }
+       kfree(info);
+}
+
+static struct arpt_table_info *alloc_table_info(unsigned int size)
+{
+       struct arpt_table_info *newinfo;
+       int cpu;
+       
+       newinfo = kzalloc(sizeof(struct arpt_table_info), GFP_KERNEL);
+       if (!newinfo)
+               return NULL;
+
+       newinfo->size = size;
+
+       for_each_cpu(cpu) {
+               if (size <= PAGE_SIZE)
+                       newinfo->entries[cpu] = kmalloc_node(size,
+                                                       GFP_KERNEL,
+                                                       cpu_to_node(cpu));
+               else
+                       newinfo->entries[cpu] = vmalloc_node(size,
+                                                            cpu_to_node(cpu));
+
+               if (newinfo->entries[cpu] == NULL) {
+                       free_table_info(newinfo);
+                       return NULL;
+               }
+       }
+
+       return newinfo;
+}
+
 static int do_replace(void __user *user, unsigned int len)
 {
        int ret;
@@ -874,6 +979,7 @@ static int do_replace(void __user *user, unsigned int len)
        struct arpt_table *t;
        struct arpt_table_info *newinfo, *oldinfo;
        struct arpt_counters *counters;
+       void *loc_cpu_entry, *loc_cpu_old_entry;
 
        if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
                return -EFAULT;
@@ -886,13 +992,13 @@ static int do_replace(void __user *user, unsigned int len)
        if ((SMP_ALIGN(tmp.size) >> PAGE_SHIFT) + 2 > num_physpages)
                return -ENOMEM;
 
-       newinfo = vmalloc(sizeof(struct arpt_table_info)
-                         + SMP_ALIGN(tmp.size) *
-                                       (highest_possible_processor_id()+1));
+       newinfo = alloc_table_info(tmp.size);
        if (!newinfo)
                return -ENOMEM;
 
-       if (copy_from_user(newinfo->entries, user + sizeof(tmp),
+       /* choose the copy that is on our node/cpu */
+       loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
+       if (copy_from_user(loc_cpu_entry, user + sizeof(tmp),
                           tmp.size) != 0) {
                ret = -EFAULT;
                goto free_newinfo;
@@ -903,32 +1009,28 @@ static int do_replace(void __user *user, unsigned int len)
                ret = -ENOMEM;
                goto free_newinfo;
        }
-       memset(counters, 0, tmp.num_counters * sizeof(struct arpt_counters));
 
        ret = translate_table(tmp.name, tmp.valid_hooks,
-                             newinfo, tmp.size, tmp.num_entries,
+                             newinfo, loc_cpu_entry, tmp.size, tmp.num_entries,
                              tmp.hook_entry, tmp.underflow);
        if (ret != 0)
                goto free_newinfo_counters;
 
        duprintf("arp_tables: Translated table\n");
 
-       t = arpt_find_table_lock(tmp.name, &ret, &arpt_mutex);
-       if (!t)
+       t = try_then_request_module(find_table_lock(tmp.name),
+                                   "arptable_%s", tmp.name);
+       if (!t || IS_ERR(t)) {
+               ret = t ? PTR_ERR(t) : -ENOENT;
                goto free_newinfo_counters_untrans;
+       }
 
        /* You lied! */
        if (tmp.valid_hooks != t->valid_hooks) {
                duprintf("Valid hook crap: %08X vs %08X\n",
                         tmp.valid_hooks, t->valid_hooks);
                ret = -EINVAL;
-               goto free_newinfo_counters_untrans_unlock;
-       }
-
-       /* Get a reference in advance, we're not allowed fail later */
-       if (!try_module_get(t->me)) {
-               ret = -EBUSY;
-               goto free_newinfo_counters_untrans_unlock;
+               goto put_module;
        }
 
        oldinfo = replace_table(t, tmp.num_counters, newinfo, &ret);
@@ -948,8 +1050,10 @@ static int do_replace(void __user *user, unsigned int len)
        /* Get the old counters. */
        get_counters(oldinfo, counters);
        /* Decrease module usage counts and free resource */
-       ARPT_ENTRY_ITERATE(oldinfo->entries, oldinfo->size, cleanup_entry,NULL);
-       vfree(oldinfo);
+       loc_cpu_old_entry = oldinfo->entries[raw_smp_processor_id()];
+       ARPT_ENTRY_ITERATE(loc_cpu_old_entry, oldinfo->size, cleanup_entry,NULL);
+
+       free_table_info(oldinfo);
        if (copy_to_user(tmp.counters, counters,
                         sizeof(struct arpt_counters) * tmp.num_counters) != 0)
                ret = -EFAULT;
@@ -959,14 +1063,13 @@ static int do_replace(void __user *user, unsigned int len)
 
  put_module:
        module_put(t->me);
- free_newinfo_counters_untrans_unlock:
        up(&arpt_mutex);
  free_newinfo_counters_untrans:
-       ARPT_ENTRY_ITERATE(newinfo->entries, newinfo->size, cleanup_entry, NULL);
+       ARPT_ENTRY_ITERATE(loc_cpu_entry, newinfo->size, cleanup_entry, NULL);
  free_newinfo_counters:
        vfree(counters);
  free_newinfo:
-       vfree(newinfo);
+       free_table_info(newinfo);
        return ret;
 }
 
@@ -989,7 +1092,8 @@ static int do_add_counters(void __user *user, unsigned int len)
        unsigned int i;
        struct arpt_counters_info tmp, *paddc;
        struct arpt_table *t;
-       int ret;
+       int ret = 0;
+       void *loc_cpu_entry;
 
        if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
                return -EFAULT;
@@ -1006,9 +1110,11 @@ static int do_add_counters(void __user *user, unsigned int len)
                goto free;
        }
 
-       t = arpt_find_table_lock(tmp.name, &ret, &arpt_mutex);
-       if (!t)
+       t = find_table_lock(tmp.name);
+       if (!t || IS_ERR(t)) {
+               ret = t ? PTR_ERR(t) : -ENOENT;
                goto free;
+       }
 
        write_lock_bh(&t->lock);
        if (t->private->number != paddc->num_counters) {
@@ -1017,7 +1123,9 @@ static int do_add_counters(void __user *user, unsigned int len)
        }
 
        i = 0;
-       ARPT_ENTRY_ITERATE(t->private->entries,
+       /* Choose the copy that is on our node */
+       loc_cpu_entry = t->private->entries[smp_processor_id()];
+       ARPT_ENTRY_ITERATE(loc_cpu_entry,
                           t->private->size,
                           add_counter_to_entry,
                           paddc->counters,
@@ -1025,6 +1133,7 @@ static int do_add_counters(void __user *user, unsigned int len)
  unlock_up_free:
        write_unlock_bh(&t->lock);
        up(&arpt_mutex);
+       module_put(t->me);
  free:
        vfree(paddc);
 
@@ -1079,8 +1188,10 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
                        break;
                }
                name[ARPT_TABLE_MAXNAMELEN-1] = '\0';
-               t = arpt_find_table_lock(name, &ret, &arpt_mutex);
-               if (t) {
+
+               t = try_then_request_module(find_table_lock(name),
+                                           "arptable_%s", name);
+               if (t && !IS_ERR(t)) {
                        struct arpt_getinfo info;
 
                        info.valid_hooks = t->valid_hooks;
@@ -1096,9 +1207,10 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
                                ret = -EFAULT;
                        else
                                ret = 0;
-
                        up(&arpt_mutex);
-               }
+                       module_put(t->me);
+               } else
+                       ret = t ? PTR_ERR(t) : -ENOENT;
        }
        break;
 
@@ -1119,6 +1231,24 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
                break;
        }
 
+       case ARPT_SO_GET_REVISION_TARGET: {
+               struct arpt_get_revision rev;
+
+               if (*len != sizeof(rev)) {
+                       ret = -EINVAL;
+                       break;
+               }
+               if (copy_from_user(&rev, user, sizeof(rev)) != 0) {
+                       ret = -EFAULT;
+                       break;
+               }
+
+               try_then_request_module(find_revision(rev.name, rev.revision,
+                                                     target_revfn, &ret),
+                                       "arpt_%s", rev.name);
+               break;
+       }
+
        default:
                duprintf("do_arpt_get_ctl: unknown request %i\n", cmd);
                ret = -EINVAL;
@@ -1136,12 +1266,9 @@ int arpt_register_target(struct arpt_target *target)
        if (ret != 0)
                return ret;
 
-       if (!list_named_insert(&arpt_target, target)) {
-               duprintf("arpt_register_target: `%s' already in list!\n",
-                        target->name);
-               ret = -EINVAL;
-       }
+       list_add(&target->list, &arpt_target);
        up(&arpt_mutex);
+
        return ret;
 }
 
@@ -1159,30 +1286,32 @@ int arpt_register_table(struct arpt_table *table,
        struct arpt_table_info *newinfo;
        static struct arpt_table_info bootstrap
                = { 0, 0, 0, { 0 }, { 0 }, { } };
+       void *loc_cpu_entry;
 
-       newinfo = vmalloc(sizeof(struct arpt_table_info)
-                         + SMP_ALIGN(repl->size) *
-                                       (highest_possible_processor_id()+1));
+       newinfo = alloc_table_info(repl->size);
        if (!newinfo) {
                ret = -ENOMEM;
                return ret;
        }
-       memcpy(newinfo->entries, repl->entries, repl->size);
+
+       /* choose the copy on our node/cpu */
+       loc_cpu_entry = newinfo->entries[raw_smp_processor_id()];
+       memcpy(loc_cpu_entry, repl->entries, repl->size);
 
        ret = translate_table(table->name, table->valid_hooks,
-                             newinfo, repl->size,
+                             newinfo, loc_cpu_entry, repl->size,
                              repl->num_entries,
                              repl->hook_entry,
                              repl->underflow);
        duprintf("arpt_register_table: translate table gives %d\n", ret);
        if (ret != 0) {
-               vfree(newinfo);
+               free_table_info(newinfo);
                return ret;
        }
 
        ret = down_interruptible(&arpt_mutex);
        if (ret != 0) {
-               vfree(newinfo);
+               free_table_info(newinfo);
                return ret;
        }
 
@@ -1211,20 +1340,23 @@ int arpt_register_table(struct arpt_table *table,
        return ret;
 
  free_unlock:
-       vfree(newinfo);
+       free_table_info(newinfo);
        goto unlock;
 }
 
 void arpt_unregister_table(struct arpt_table *table)
 {
+       void *loc_cpu_entry;
+
        down(&arpt_mutex);
        LIST_DELETE(&arpt_tables, table);
        up(&arpt_mutex);
 
        /* Decrease module usage counts and free resources */
-       ARPT_ENTRY_ITERATE(table->private->entries, table->private->size,
+       loc_cpu_entry = table->private->entries[raw_smp_processor_id()];
+       ARPT_ENTRY_ITERATE(loc_cpu_entry, table->private->size,
                           cleanup_entry, NULL);
-       vfree(table->private);
+       free_table_info(table->private);
 }
 
 /* The built-in targets: standard (NULL) and error. */