]> git.ipfire.org Git - thirdparty/xtables-addons.git/commitdiff
compat_xtables: move to 2.6.35 API for matches
authorJan Engelhardt <jengelh@medozas.de>
Sat, 27 Mar 2010 22:22:58 +0000 (23:22 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Sun, 4 Apr 2010 22:43:47 +0000 (00:43 +0200)
extensions/compat_xtables.c
extensions/compat_xtables.h
extensions/ipset/ipt_set.c
extensions/pknock/xt_pknock.c
extensions/xt_condition.c
extensions/xt_fuzzy.c
extensions/xt_geoip.c
extensions/xt_lscan.c
extensions/xt_quota2.c

index dbf5c1106d7f741129ccb10d991b055693289ea6..7244d90c5ca97e30fba32935f318090ebd37601a 100644 (file)
@@ -85,6 +85,20 @@ static bool xtnu_match_check(const char *table, const void *entry,
 }
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28) && \
+    LINUX_VERSION_CODE <  KERNEL_VERSION(2, 6, 34)
+static bool xtnu_match_check(const struct xt_mtchk_param *par)
+{
+       struct xtnu_match *nm = xtcompat_numatch(cm);
+
+       if (nm == NULL)
+               return false;
+       if (nm->checkentry == NULL)
+               return true;
+       return nm->checkentry(par);
+}
+#endif
+
 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18)
 static void xtnu_match_destroy(const struct xt_match *cm, void *matchinfo,
     unsigned int matchinfosize)
@@ -105,7 +119,7 @@ static void xtnu_match_destroy(const struct xt_match *cm, void *matchinfo)
 }
 #endif
 
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 27)
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 34)
 int xtnu_register_match(struct xtnu_match *nt)
 {
        struct xt_match *ct;
index 343fca6240e871f4b8aad23b9486a8e78ddb804f..92748a8208edfa35de9349e9f3d7f1348e498cf0 100644 (file)
@@ -60,7 +60,7 @@
 #      define init_net__proc_net     init_net.proc_net
 #endif
 
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 27)
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 34)
 #      define xt_match              xtnu_match
 #      define xt_register_match     xtnu_register_match
 #      define xt_unregister_match   xtnu_unregister_match
index c8af290825e7559dfd50d61938bba79dee5b1fbd..ec1a40f2012bf5aad5dc382a2e27646bf6cf7d60 100644 (file)
@@ -47,7 +47,7 @@ match(const struct sk_buff *skb, const struct xt_match_param *par)
                         info->match_set.flags[0] & IPSET_MATCH_INV);
 }
 
-static bool
+static int
 checkentry(const struct xt_mtchk_param *par)
 {
        struct ipt_set_info_match *info = par->matchinfo;
@@ -56,7 +56,7 @@ checkentry(const struct xt_mtchk_param *par)
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
        if (matchsize != IPT_ALIGN(sizeof(struct ipt_set_info_match))) {
                ip_set_printk("invalid matchsize %d", matchsize);
-               return 0;
+               return -EINVAL;
        }
 #endif
 
@@ -65,14 +65,14 @@ checkentry(const struct xt_mtchk_param *par)
        if (index == IP_SET_INVALID_ID) {
                ip_set_printk("Cannot find set indentified by id %u to match",
                              info->match_set.index);
-               return 0;       /* error */
+               return -ENOENT;
        }
        if (info->match_set.flags[IP_SET_MAX_BINDINGS] != 0) {
                ip_set_printk("That's nasty!");
-               return 0;       /* error */
+               return -EINVAL;
        }
 
-       return 1;
+       return 0;
 }
 
 static void destroy(const struct xt_mtdtor_param *par)
index 842654e31240659ec4cb771733889d365f9c6281..a700041d054b15c2b38e5978a91882f72bd24a35 100644 (file)
@@ -1064,9 +1064,9 @@ out:
        return ret;
 }
 
-#define RETURN_ERR(err) do { printk(KERN_ERR PKNOCK err); return false; } while (false)
+#define RETURN_ERR(err) do { printk(KERN_ERR PKNOCK err); return -EINVAL; } while (false)
 
-static bool pknock_mt_check(const struct xt_mtchk_param *par)
+static int pknock_mt_check(const struct xt_mtchk_param *par)
 {
        struct xt_pknock_mtinfo *info = par->matchinfo;
 
@@ -1124,9 +1124,10 @@ static bool pknock_mt_check(const struct xt_mtchk_param *par)
        }
 
        if (!add_rule(info))
+               /* should ENOMEM here */
                RETURN_ERR("add_rule() error in checkentry() function.\n");
 
-       return true;
+       return 0;
 }
 
 static void pknock_mt_destroy(const struct xt_mtdtor_param *par)
index 3aed62c4ec2d1f858c85407303d35e7222fd4aad..f5fb98d67e6b8bc55c78ea84e08835ed5b29295c 100644 (file)
@@ -109,7 +109,7 @@ condition_mt(const struct sk_buff *skb, const struct xt_match_param *par)
        return x ^ info->invert;
 }
 
-static bool condition_mt_check(const struct xt_mtchk_param *par)
+static int condition_mt_check(const struct xt_mtchk_param *par)
 {
        struct xt_condition_mtinfo *info = par->matchinfo;
        struct condition_variable *var;
@@ -121,21 +121,21 @@ static bool condition_mt_check(const struct xt_mtchk_param *par)
                printk(KERN_INFO KBUILD_MODNAME ": name not allowed or too "
                       "long: \"%.*s\"\n", (unsigned int)sizeof(info->name),
                       info->name);
-               return false;
+               return -EINVAL;
        }
        /*
         * Let's acquire the lock, check for the condition and add it
         * or increase the reference counter.
         */
        if (mutex_lock_interruptible(&proc_lock) != 0)
-               return false;
+               return -EINTR;
 
        list_for_each_entry(var, &conditions_list, list) {
                if (strcmp(info->name, var->status_proc->name) == 0) {
                        var->refcount++;
                        mutex_unlock(&proc_lock);
                        info->condvar = var;
-                       return true;
+                       return 0;
                }
        }
 
@@ -143,7 +143,7 @@ static bool condition_mt_check(const struct xt_mtchk_param *par)
        var = kmalloc(sizeof(struct condition_variable), GFP_KERNEL);
        if (var == NULL) {
                mutex_unlock(&proc_lock);
-               return false;
+               return -ENOMEM;
        }
 
        /* Create the condition variable's proc file entry. */
@@ -152,7 +152,7 @@ static bool condition_mt_check(const struct xt_mtchk_param *par)
        if (var->status_proc == NULL) {
                kfree(var);
                mutex_unlock(&proc_lock);
-               return false;
+               return -ENOMEM;
        }
 
        var->refcount = 1;
@@ -169,7 +169,7 @@ static bool condition_mt_check(const struct xt_mtchk_param *par)
        var->status_proc->gid = condition_gid_perms;
        mutex_unlock(&proc_lock);
        info->condvar = var;
-       return true;
+       return 0;
 }
 
 static void condition_mt_destroy(const struct xt_mtdtor_param *par)
index 0775cf219cf464a5c6696e97a36315f0ab948e56..83903b291a2a9e1a35663fa23b039454b881da6d 100644 (file)
@@ -125,7 +125,7 @@ fuzzy_mt(const struct sk_buff *skb, const struct xt_match_param *par)
        return false;
 }
 
-static bool fuzzy_mt_check(const struct xt_mtchk_param *par)
+static int fuzzy_mt_check(const struct xt_mtchk_param *par)
 {
        const struct xt_fuzzy_mtinfo *info = par->matchinfo;
 
@@ -133,10 +133,10 @@ static bool fuzzy_mt_check(const struct xt_mtchk_param *par)
            info->maximum_rate > FUZZY_MAX_RATE ||
            info->minimum_rate >= info->maximum_rate) {
                printk(KERN_INFO KBUILD_MODNAME ": bad values, please check.\n");
-               return false;
+               return -EDOM;
        }
 
-       return true;
+       return 0;
 }
 
 static struct xt_match fuzzy_mt_reg[] __read_mostly = {
index 8b9420d6e0d336a49a37db2d6f2d50765442b694..76c643c557d7532df6d3a7f8cfda3587585a3c48 100644 (file)
@@ -46,23 +46,28 @@ geoip_add_node(const struct geoip_country_user __user *umem_ptr)
        struct geoip_country_user umem;
        struct geoip_country_kernel *p;
        struct geoip_subnet *s;
+       int ret;
 
        if (copy_from_user(&umem, umem_ptr, sizeof(umem)) != 0)
-               return NULL;
+               return ERR_PTR(-EFAULT);
 
        p = kmalloc(sizeof(struct geoip_country_kernel), GFP_KERNEL);
        if (p == NULL)
-               return NULL;
+               return ERR_PTR(-ENOMEM);
 
        p->count   = umem.count;
        p->cc      = umem.cc;
 
        s = vmalloc(p->count * sizeof(struct geoip_subnet));
-       if (s == NULL)
+       if (s == NULL) {
+               ret = -ENOMEM;
                goto free_p;
+       }
        if (copy_from_user(s, (const void __user *)(unsigned long)umem.subnets,
-           p->count * sizeof(struct geoip_subnet)) != 0)
+           p->count * sizeof(struct geoip_subnet)) != 0) {
+               ret = -EFAULT;
                goto free_s;
+       }
 
        p->subnets = s;
        atomic_set(&p->ref, 1);
@@ -78,7 +83,7 @@ geoip_add_node(const struct geoip_country_user __user *umem_ptr)
        vfree(s);
  free_p:
        kfree(p);
-       return NULL;
+       return ERR_PTR(ret);
 }
 
 static void geoip_try_remove_node(struct geoip_country_kernel *p)
@@ -168,7 +173,7 @@ xt_geoip_mt(const struct sk_buff *skb, const struct xt_match_param *par)
        return info->flags & XT_GEOIP_INV;
 }
 
-static bool xt_geoip_mt_checkentry(const struct xt_mtchk_param *par)
+static int xt_geoip_mt_checkentry(const struct xt_mtchk_param *par)
 {
        struct xt_geoip_match_info *info = par->matchinfo;
        struct geoip_country_kernel *node;
@@ -176,13 +181,15 @@ static bool xt_geoip_mt_checkentry(const struct xt_mtchk_param *par)
 
        for (i = 0; i < info->count; i++) {
                node = find_node(info->cc[i]);
-               if (node == NULL)
-                       if ((node = geoip_add_node((const void __user *)(unsigned long)info->mem[i].user)) == NULL) {
+               if (node == NULL) {
+                       node = geoip_add_node((const void __user *)(unsigned long)info->mem[i].user);
+                       if (IS_ERR(node)) {
                                printk(KERN_ERR
-                                               "xt_geoip: unable to load '%c%c' into memory\n",
-                                               COUNTRY(info->cc[i]));
-                               return false;
+                                               "xt_geoip: unable to load '%c%c' into memory: %ld\n",
+                                               COUNTRY(info->cc[i]), PTR_ERR(node));
+                               return PTR_ERR(node);
                        }
+               }
 
                /* Overwrite the now-useless pointer info->mem[i] with
                 * a pointer to the node's kernelspace structure.
@@ -192,7 +199,7 @@ static bool xt_geoip_mt_checkentry(const struct xt_mtchk_param *par)
                info->mem[i].kernel = node;
        }
 
-       return true;
+       return 0;
 }
 
 static void xt_geoip_mt_destroy(const struct xt_mtdtor_param *par)
index cf63a90c28c016933ef530d1b04aac4bae62ee9f..1f51f82f58b1c949590781f54fc259b97e22436e 100644 (file)
@@ -216,16 +216,16 @@ lscan_mt(const struct sk_buff *skb, const struct xt_match_param *par)
               (info->match_gr && ctdata->mark == mark_grscan);
 }
 
-static bool lscan_mt_check(const struct xt_mtchk_param *par)
+static int lscan_mt_check(const struct xt_mtchk_param *par)
 {
        const struct xt_lscan_mtinfo *info = par->matchinfo;
 
        if ((info->match_stealth & ~1) || (info->match_syn & ~1) ||
            (info->match_cn & ~1) || (info->match_gr & ~1)) {
                printk(KERN_WARNING PFX "Invalid flags\n");
-               return false;
+               return -EINVAL;
        }
-       return true;
+       return 0;
 }
 
 static struct xt_match lscan_mt_reg[] __read_mostly = {
index f530b8bbbd69c3f4f3f7d50fd868adff0abed055..ab9cb0823463026ddf2f72573919d75fee300985 100644 (file)
@@ -144,28 +144,28 @@ q2_get_counter(const struct xt_quota_mtinfo2 *q)
        return NULL;
 }
 
-static bool quota_mt2_check(const struct xt_mtchk_param *par)
+static int quota_mt2_check(const struct xt_mtchk_param *par)
 {
        struct xt_quota_mtinfo2 *q = par->matchinfo;
 
        if (q->flags & ~XT_QUOTA_MASK)
-               return false;
+               return -EINVAL;
 
        q->name[sizeof(q->name)-1] = '\0';
        if (*q->name == '.' || strchr(q->name, '/') != NULL) {
                printk(KERN_ERR "xt_quota<%u>: illegal name\n",
                       par->match->revision);
-               return false;
+               return -EINVAL;
        }
 
        q->master = q2_get_counter(q);
        if (q->master == NULL) {
                printk(KERN_ERR "xt_quota<%u>: memory alloc failure\n",
                       par->match->revision);
-               return false;
+               return -ENOMEM;
        }
 
-       return true;
+       return 0;
 }
 
 static void quota_mt2_destroy(const struct xt_mtdtor_param *par)